X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2Fxoslib%2FxosHelper.js;h=76254f6d16605456145fc802addc9c608325b69d;hb=753a13edfd39603fbdc59747c4d7c2b59a2d06b9;hp=0cadf79033c902e20a95b7ea920a4dbfb7906067;hpb=ceb262824337cffd6cf83f035849e32c8aa414e5;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js index 0cadf79..76254f6 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js +++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js @@ -8,9 +8,6 @@ SliceSelectorOption = Marionette.ItemView.extend({ template: "#xos-sliceselector-option", tagName: "option", attributes: function() { - console.log("XXX"); - console.log(this.options.selectedID); - console.log(this.model.get("id")); if (this.options.selectedID == this.model.get("id")) { return { value: this.model.get("id"), selected: 1 }; } else { @@ -23,6 +20,7 @@ SliceSelectorView = Marionette.CompositeView.extend({ template: "#xos-sliceselector-select", childViewContainer: "select", childView: SliceSelectorOption, + caption: "Slice", events: {"change select": "onSliceChanged"}, @@ -37,6 +35,8 @@ SliceSelectorView = Marionette.CompositeView.extend({ sliceChanged: function(id) { console.log("sliceChanged " + id); }, + + templateHelpers: function() { return {caption: this.options.caption || this.caption }; }, }); FilteredCompositeView = Marionette.CompositeView.extend( { @@ -83,8 +83,13 @@ XOSRouter = Marionette.AppRouter.extend({ Marionette.AppRouter.prototype.navigate.call(this, href, options); }, }); - -Backbone.Syphon.InputReaders.register('select', function(el) { + +// XXX - We import backbone multiple times (BAD!) since the import happens +// inside of the view's html. The second time it's imported (developer +// view), it wipes out Backbone.Syphon. So, save it as Backbone_Syphon for +// now. +Backbone_Syphon = Backbone.Syphon +Backbone_Syphon.InputReaders.register('select', function(el) { // Modify syphon so that if a select has "syphonall" in the class, then // the value of every option will be returned, regardless of whether of // not it is selected. @@ -403,6 +408,8 @@ XOSApplication = Marionette.Application.extend({ that.destroyModel(model); if (afterDelete=="list") { that.navigate("list", modelName); + } else if (afterDelete) { + afterDelete(); } }); }, @@ -468,7 +475,7 @@ XOSDetailView = Marionette.ItemView.extend({ */ initialize: function() { - this.on("saveSuccess", this.onAfterSave); + this.on("saveSuccess", this.onSaveSuccess); this.synchronous = false; }, @@ -478,11 +485,20 @@ XOSDetailView = Marionette.ItemView.extend({ }); }, + saveSuccess: function(e) { + // always called after a save succeeds + }, + afterSave: function(e) { + // if this.synchronous, then called after the save succeeds + // if !this.synchronous, then called after save is initiated }, - onAfterSave: function(e) { - this.afterSave(e); + onSaveSuccess: function(e) { + this.saveSuccess(e); + if (this.synchronous) { + this.afterSave(e); + } }, inputChanged: function(e) { @@ -499,6 +515,9 @@ XOSDetailView = Marionette.ItemView.extend({ submitLeaveClicked: function(e) { console.log("saveLeave"); e.preventDefault(); + if (this.options.noSubmitButton || this.noSubmitButton) { + return; + } var that=this; this.afterSave = function() { that.app.navigate("list", that.model.modelName); @@ -520,7 +539,7 @@ XOSDetailView = Marionette.ItemView.extend({ save: function() { this.app.hideError(); - var data = Backbone.Syphon.serialize(this); + var data = Backbone_Syphon.serialize(this); var that = this; var isNew = !this.model.id; @@ -549,9 +568,7 @@ XOSDetailView = Marionette.ItemView.extend({ this.model.save(data, {error: function(model, result, xhr) { that.app.saveError(model,result,xhr,infoMsgId);}, success: function(model, result, xhr) { that.app.saveSuccess(model,result,xhr,infoMsgId); - if (that.synchronous) { - that.trigger("saveSuccess"); - } + that.trigger("saveSuccess"); }}); this.dirty = false; @@ -648,12 +665,14 @@ XOSDetailView = Marionette.ItemView.extend({ addFields: this.model.addFields, listFields: this.model.listFields, detailFields: this.options.detailFields || this.detailFields || this.model.detailFields, + fieldDisplayNames: this.options.fieldDisplayNames || this.fieldDisplayNames || this.model.fieldDisplayNames || {}, foreignFields: this.model.foreignFields, detailLinkFields: this.model.detailLinkFields, inputType: this.model.inputType, model: this.model, detailView: this, choices: this.options.choices || this.choices || this.model.choices || {}, + helpText: this.options.helpText || this.helpText || this.model.helpText || {}, }}, }); @@ -864,6 +883,7 @@ XOSDataTableView = Marionette.View.extend( { render: function() { var view = this; + var fieldDisplayNames = view.options.fieldDisplayNames || view.fieldDisplayNames || {}; view.columnsByIndex = []; view.columnsByFieldName = {}; @@ -871,7 +891,7 @@ XOSDataTableView = Marionette.View.extend( { inputType = view.options.inputType || view.inputType || {}; mRender = undefined; mSearchText = undefined; - sTitle = fieldNameToHumanReadable(fieldName); + sTitle = fieldName in fieldDisplayNames ? fieldDisplayNames[fieldName] : fieldNameToHumanReadable(fieldName); bSortable = true; if (fieldName=="backend_status") { mRender = function(x,y,z) { return xosBackendStatusIconTemplate(z); }; @@ -881,7 +901,7 @@ XOSDataTableView = Marionette.View.extend( { var foreignCollection = view.collection.foreignFields[fieldName]; mSearchText = function(x) { return idToName(x, foreignCollection, "humanReadableName"); }; } else if (inputType[fieldName] == "spinner") { - mRender = function(x,y,z) { return xosDataTableSpinnerTemplate( {value: x, collectionName: view.collection.collectionName, fieldName: fieldName, id: z.id} ); }; + mRender = function(x,y,z) { return xosDataTableSpinnerTemplate( {value: x, collectionName: view.collection.collectionName, fieldName: fieldName, id: z.id, app: view.app} ); }; } if ($.inArray(fieldName, view.collection.detailLinkFields)>=0) { var collectionName = view.collection.collectionName; @@ -902,6 +922,8 @@ XOSDataTableView = Marionette.View.extend( { "bJQueryUI": true, "bStateSave": true, "bServerSide": true, + "bFilter": ! (view.options.disableFilter || view.disableFilter), + "bPaginate": ! (view.options.disablePaginate || view.disablePaginate), "aoColumns": view.columnsByIndex, fnServerData: function(sSource, aoData, fnCallback, settings) { @@ -994,7 +1016,9 @@ XOSDataTableView = Marionette.View.extend( { aaData.sort(function(a,b) { return compareColumns(sortCols, sortDirs, a, b); }); // slice it for pagination - aaData = aaData.slice(iDisplayStart, iDisplayStart+iDisplayLength); + if (iDisplayLength >= 0) { + aaData = aaData.slice(iDisplayStart, iDisplayStart+iDisplayLength); + } return fnCallback({iTotalRecords: totalSize, iTotalDisplayRecords: filteredSize,