X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2Fxoslib%2FxosHelper.js;h=76254f6d16605456145fc802addc9c608325b69d;hb=753a13edfd39603fbdc59747c4d7c2b59a2d06b9;hp=9f9964c42a85f7d751b9621f8026915418a05263;hpb=dae1b82ff0077b6ad3365c34d53e34ea5e7adbf5;p=plstackapi.git diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js index 9f9964c..76254f6 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js +++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js @@ -20,6 +20,7 @@ SliceSelectorView = Marionette.CompositeView.extend({ template: "#xos-sliceselector-select", childViewContainer: "select", childView: SliceSelectorOption, + caption: "Slice", events: {"change select": "onSliceChanged"}, @@ -34,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( { @@ -80,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. @@ -467,7 +475,7 @@ XOSDetailView = Marionette.ItemView.extend({ */ initialize: function() { - this.on("saveSuccess", this.onAfterSave); + this.on("saveSuccess", this.onSaveSuccess); this.synchronous = false; }, @@ -477,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) { @@ -498,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); @@ -519,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; @@ -548,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; @@ -647,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 || {}, }}, }); @@ -863,6 +883,7 @@ XOSDataTableView = Marionette.View.extend( { render: function() { var view = this; + var fieldDisplayNames = view.options.fieldDisplayNames || view.fieldDisplayNames || {}; view.columnsByIndex = []; view.columnsByFieldName = {}; @@ -870,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); }; @@ -901,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) { @@ -993,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,