prevent script tags inside of error popup
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xosHelper.js
index e8c1b10..384a7ed 100644 (file)
@@ -4,6 +4,21 @@ HTMLView = Marionette.ItemView.extend({
   },
 });
 
+FilteredCompositeView = Marionette.CompositeView.extend( {
+    showCollection: function() {
+      var ChildView;
+      this.collection.each(function(child, index) {
+        filterFunc = this.options.filter || this.filter;
+        if (filterFunc && !filterFunc(child)) {
+            return;
+        }
+        ChildView = this.getChildView(child);
+        this.addChild(child, ChildView, index);
+      }, this);
+
+    },
+});
+
 SliceSelectorOption = Marionette.ItemView.extend({
     template: "#xos-sliceselector-option",
     tagName: "option",
@@ -16,10 +31,11 @@ SliceSelectorOption = Marionette.ItemView.extend({
     },
 });
 
-SliceSelectorView = Marionette.CompositeView.extend({
+SliceSelectorView = FilteredCompositeView.extend({
     template: "#xos-sliceselector-select",
     childViewContainer: "select",
     childView: SliceSelectorOption,
+    caption: "Slice",
 
     events: {"change select": "onSliceChanged"},
 
@@ -34,20 +50,8 @@ SliceSelectorView = Marionette.CompositeView.extend({
     sliceChanged: function(id) {
         console.log("sliceChanged " + id);
     },
-});
 
-FilteredCompositeView = Marionette.CompositeView.extend( {
-    showCollection: function() {
-      var ChildView;
-      this.collection.each(function(child, index) {
-        if (this.filter && !this.filter(child)) {
-            return;
-        }
-        ChildView = this.getChildView(child);
-        this.addChild(child, ChildView, index);
-      }, this);
-
-    },
+    templateHelpers: function() { return {caption: this.options.caption || this.caption }; },
 });
 
 XOSRouter = Marionette.AppRouter.extend({
@@ -146,7 +150,7 @@ XOSApplication = Marionette.Application.extend({
         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({
@@ -472,7 +476,7 @@ XOSDetailView = Marionette.ItemView.extend({
             */
 
             initialize: function() {
-                this.on("saveSuccess", this.onAfterSave);
+                this.on("saveSuccess", this.onSaveSuccess);
                 this.synchronous = false;
             },
 
@@ -482,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) {
@@ -556,9 +569,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;
 
@@ -662,6 +673,7 @@ XOSDetailView = Marionette.ItemView.extend({
                                                     model: this.model,
                                                     detailView: this,
                                                     choices: this.options.choices || this.choices || this.model.choices || {},
+                                                    helpText: this.options.helpText || this.helpText || this.model.helpText || {},
                                          }},
 });
 
@@ -872,6 +884,7 @@ XOSDataTableView = Marionette.View.extend( {
 
     render: function() {
         var view = this;
+        var fieldDisplayNames = view.options.fieldDisplayNames || view.fieldDisplayNames || {};
 
         view.columnsByIndex = [];
         view.columnsByFieldName = {};
@@ -879,7 +892,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); };
@@ -910,6 +923,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) {
@@ -1002,7 +1017,9 @@ XOSDataTableView = Marionette.View.extend( {
                   aaData.sort(function(a,b) { return compareColumns(sortCols, sortDirs, a, b); });\r
 \r
                   // slice it for pagination\r
-                  aaData = aaData.slice(iDisplayStart, iDisplayStart+iDisplayLength);\r
+                  if (iDisplayLength >= 0) {\r
+                      aaData = aaData.slice(iDisplayStart, iDisplayStart+iDisplayLength);\r
+                  }\r
 \r
                   return fnCallback({iTotalRecords: totalSize,\r
                          iTotalDisplayRecords: filteredSize,\r