1 XOSApplication = Marionette.Application.extend({
2 errorBoxId: "#errorBox",
3 errorCloseButtonId: "#close-error-box",
4 successBoxId: "#successBox",
5 successCloseButtonId: "#close-success-box",
6 errorTemplate: "#xos-error-template",
7 successTemplate: "#xos-success-template",
9 hideError: function(result) {
10 $(this.errorBoxId).hide();
11 $(this.successBoxId).hide();
14 showSuccess: function(result) {
15 $(this.successBoxId).show();
16 $(this.successBoxId).html(_.template($(this.successTemplate).html())(result));
17 $(this.successCloseButtonId).unbind().bind('click', function() {
18 $(this.successBoxId).hide();
22 showError: function(result) {
23 $(this.errorBoxId).show();
24 $(this.errorBoxId).html(_.template($(this.errorTemplate).html())(result));
25 $(this.errorCloseButtonId).unbind().bind('click', function() {
26 $(this.errorBoxId).hide();
31 /* Give an id, the name of a collection, and the name of a field for models
32 within that collection, lookup the id and return the value of the field.
35 idToName = function(id, collectionName, fieldName) {
36 linkedObject = xos[collectionName].get(id);
37 if (linkedObject == undefined) {
40 return linkedObject.attributes[fieldName];
44 /* Constructs lists of <option> html blocks for items in a collection.
46 selectedId = the id of an object that should be selected, if any
47 collectionName = name of collection
48 fieldName = name of field within models of collection that will be displayed
51 idToOptions = function(selectedId, collectionName, fieldName) {
53 for (index in xos[collectionName].models) {
54 linkedObject = xos[collectionName].models[index];
55 linkedId = linkedObject["id"];
56 linkedName = linkedObject.attributes[fieldName];
57 if (linkedId == selectedId) {
58 selected = " selected";
62 result = result + '<option value="' + linkedId + '"' + selected + '>' + linkedName + '</option>';
67 /* Constructs an html <select> and the <option>s to go with it.
69 variable = variable name to return to form
70 selectedId = the id of an object that should be selected, if any
71 collectionName = name of collection
72 fieldName = name of field within models of collection that will be displayed
75 idToSelect = function(variable, selectedId, collectionName, fieldName) {
76 result = '<select name="' + variable + '">' +
77 idToOptions(selectedId, collectionName, fieldName) +