X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fcore%2Fxoslib%2Fstatic%2Fjs%2Fxoslib%2FxosHelper.js;h=384a7ede437878977d497bfe61367df4f4ab290f;hb=dee21fb114a2ece37982e47d7b304b92c109cdd6;hp=6c0c2f34ec9a8ddd9fd93524cbfc14189a223df8;hpb=e620317996ffd6600a702c30e74f475eafc26bd7;p=plstackapi.git
diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
index 6c0c2f3..384a7ed 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js
@@ -8,7 +8,8 @@ FilteredCompositeView = Marionette.CompositeView.extend( {
showCollection: function() {
var ChildView;
this.collection.each(function(child, index) {
- if (this.filter && !this.filter(child)) {
+ filterFunc = this.options.filter || this.filter;
+ if (filterFunc && !filterFunc(child)) {
return;
}
ChildView = this.getChildView(child);
@@ -18,6 +19,41 @@ FilteredCompositeView = Marionette.CompositeView.extend( {
},
});
+SliceSelectorOption = Marionette.ItemView.extend({
+ template: "#xos-sliceselector-option",
+ tagName: "option",
+ attributes: function() {
+ if (this.options.selectedID == this.model.get("id")) {
+ return { value: this.model.get("id"), selected: 1 };
+ } else {
+ return { value: this.model.get("id") };
+ }
+ },
+});
+
+SliceSelectorView = FilteredCompositeView.extend({
+ template: "#xos-sliceselector-select",
+ childViewContainer: "select",
+ childView: SliceSelectorOption,
+ caption: "Slice",
+
+ events: {"change select": "onSliceChanged"},
+
+ childViewOptions: function() {
+ return { selectedID: this.options.selectedID || this.selectedID || null };
+ },
+
+ onSliceChanged: function() {
+ this.sliceChanged(this.$el.find("select").val());
+ },
+
+ sliceChanged: function(id) {
+ console.log("sliceChanged " + id);
+ },
+
+ templateHelpers: function() { return {caption: this.options.caption || this.caption }; },
+});
+
XOSRouter = Marionette.AppRouter.extend({
initialize: function() {
this.routeStack=[];
@@ -25,6 +61,7 @@ XOSRouter = Marionette.AppRouter.extend({
onRoute: function(x,y,z) {
this.routeStack.push(Backbone.history.fragment);
+ this.routeStack = this.routeStack.slice(-32); // limit the size of routeStack to something reasonable
},
prevPage: function() {
@@ -33,8 +70,8 @@ XOSRouter = Marionette.AppRouter.extend({
showPreviousURL: function() {
prevPage = this.prevPage();
- console.log("showPreviousURL");
- console.log(this.routeStack);
+ //console.log("showPreviousURL");
+ //console.log(this.routeStack);
if (prevPage) {
this.navigate("#"+prevPage, {trigger: false, replace: true} );
}
@@ -47,8 +84,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.
@@ -103,10 +145,12 @@ XOSApplication = Marionette.Application.extend({
parsed_error=undefined;
width=640; // django stacktraces like wide width
}
+ console.log(responseText);
+ console.log(parsed_error);
if (parsed_error) {
$("#xos-error-dialog").html(templateFromId("#xos-error-response")(parsed_error));
} else {
- $("#xos-error-dialog").html(templateFromId("#xos-error-rawresponse")({responseText: responseText}))
+ $("#xos-error-dialog").html(templateFromId("#xos-error-rawresponse")({responseText: strip_scripts(responseText)}))
}
$("#xos-error-dialog").dialog({
@@ -365,6 +409,8 @@ XOSApplication = Marionette.Application.extend({
that.destroyModel(model);
if (afterDelete=="list") {
that.navigate("list", modelName);
+ } else if (afterDelete) {
+ afterDelete();
}
});
},
@@ -392,7 +438,7 @@ XOSButtonView = Marionette.ItemView.extend({
},
submitDeleteClicked: function(e) {
- this.options.linkedView.submitDeleteClicked.call(this.options.linkedView, e);
+ this.options.linkedView.deleteClicked.call(this.options.linkedView, e);
},
addClicked: function(e) {
@@ -430,7 +476,7 @@ XOSDetailView = Marionette.ItemView.extend({
*/
initialize: function() {
- this.on("saveSuccess", this.onAfterSave);
+ this.on("saveSuccess", this.onSaveSuccess);
this.synchronous = false;
},
@@ -440,11 +486,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) {
@@ -461,6 +516,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);
@@ -482,7 +540,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;
@@ -501,19 +559,17 @@ XOSDetailView = Marionette.ItemView.extend({
}
if (isNew) {
- this.model.attributes.humanReadableName = "new " + model.modelName;
+ this.model.attributes.humanReadableName = "new " + this.model.modelName;
this.model.addToCollection = this.collection;
} else {
this.model.addToCollection = undefined;
}
- var infoMsgId = this.app.showInformational( {what: "save " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} );
+ var infoMsgId = this.app.showInformational( {what: "save " + this.model.modelName + " " + this.model.attributes.humanReadableName, status: "", statusText: "in progress..."} );
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;
@@ -609,12 +665,15 @@ XOSDetailView = Marionette.ItemView.extend({
collectionName: this.model.collectionName,
addFields: this.model.addFields,
listFields: this.model.listFields,
- detailFields: this.model.detailFields,
+ 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 || {},
}},
});
@@ -825,13 +884,15 @@ XOSDataTableView = Marionette.View.extend( {
render: function() {
var view = this;
+ var fieldDisplayNames = view.options.fieldDisplayNames || view.fieldDisplayNames || {};
view.columnsByIndex = [];
view.columnsByFieldName = {};
_.each(this.collection.listFields, function(fieldName) {
+ 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); };
@@ -840,6 +901,8 @@ XOSDataTableView = Marionette.View.extend( {
} else if (fieldName in view.collection.foreignFields) {
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, app: view.app} ); };
}
if ($.inArray(fieldName, view.collection.detailLinkFields)>=0) {
var collectionName = view.collection.collectionName;
@@ -850,14 +913,18 @@ XOSDataTableView = Marionette.View.extend( {
view.columnsByFieldName[fieldName] = thisColumn;
});
- deleteColumn = {sTitle: "", bSortable: false, mRender: function(x,y,z) { return xosDeleteButtonTemplate({modelName: view.collection.modelName, id: z.id}); }, mData: function() { return "delete"; }};
- view.columnsByIndex.push(deleteColumn);
- view.columnsByFieldName["delete"] = deleteColumn;
+ if (!view.noDeleteColumn) {
+ deleteColumn = {sTitle: "", bSortable: false, mRender: function(x,y,z) { return xosDeleteButtonTemplate({modelName: view.collection.modelName, id: z.id}); }, mData: function() { return "delete"; }};
+ view.columnsByIndex.push(deleteColumn);
+ view.columnsByFieldName["delete"] = deleteColumn;
+ };
oTable = $(this.el).find("table").dataTable( {
"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) {
@@ -893,7 +960,7 @@ XOSDataTableView = Marionette.View.extend( {
// content of the collection
var populateTable = function()
{
- console.log("populatetable!");
+ //console.log("populatetable!");
// clear out old row views
rows = [];
@@ -950,7 +1017,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,
@@ -1044,3 +1113,25 @@ idToSelect = function(variable, selectedId, collectionName, fieldName, readOnly,
return result;
}
+choicesToOptions = function(selectedValue, choices) {
+ result="";
+ for (index in choices) {
+ choice = choices[index];
+ displayName = choice[0];
+ value = choice[1];
+ if (value == selectedValue) {
+ selected = " selected";
+ } else {
+ selected = "";
+ }
+ result = result + '';
+ }
+ return result;
+}
+
+choicesToSelect = function(variable, selectedValue, choices) {
+ result = '';
+ return result;
+}