add raw error dialog support, only add model to collection once it has been saved
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xosHelper.js
index 2fa9554..2eb3e42 100644 (file)
@@ -68,9 +68,23 @@ XOSApplication = Marionette.Application.extend({
     },
 
     popupErrorDialog: function(responseText) {
-        $("#xos-error-dialog").html(templateFromId("#xos-error-response")($.parseJSON(responseText)));
+        try {
+            parsed_error=$.parseJSON(responseText);
+            width=300;
+        }
+        catch(err) {
+            parsed_error=undefined;
+            width=640;    // django stacktraces like wide width
+        }
+        if (parsed_error) {
+            $("#xos-error-dialog").html(templateFromId("#xos-error-response")(json));
+        } else {
+            $("#xos-error-dialog").html(templateFromId("#xos-error-rawresponse")({responseText: responseText}))
+        }
+
         $("#xos-error-dialog").dialog({
             modal: true,
+            width: width,
             buttons: {
                 Ok: function() { $(this).dialog("close"); }
             }
@@ -222,7 +236,12 @@ XOSDetailView = Marionette.ItemView.extend({
                 this.app.showError(result);\r
             },\r
 \r
-            saveSuccess: function(model, result, xhr, infoMsgId) {\r
+            saveSuccess: function(model, result, xhr, infoMsgId, isNew) {\r
+                console.log("saveSuccess");\r
+                if (isNew) {\r
+                    this.collection.add(model);\r
+                    this.collection.sort();\r
+                }\r
                 result = {status: xhr.xhr.status, statusText: xhr.xhr.statusText};\r
                 result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName;\r
                 result["infoMsgId"] = infoMsgId;\r
@@ -274,21 +293,25 @@ XOSDetailView = Marionette.ItemView.extend({
                    model.save, we call it ourselves, so we can throw up our\r
                    validation error before creating the infoMsg in the log\r
                 */\r
-                errors =  this.model.validate(data);\r
+                errors =  this.model.xosValidate(data);\r
                 if (errors) {\r
                     this.onFormDataInvalid(errors);\r
                     return;\r
                 }\r
 \r
+                if (isNew) {\r
+                    this.model.attributes.humanReadableName = "new " + model.modelName;\r
+                }\r
+\r
                 var infoMsgId = this.app.showInformational( {what: "save " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} );\r
 \r
                 this.model.save(data, {error: function(model, result, xhr) { that.saveError(model,result,xhr,infoMsgId);},\r
-                                       success: function(model, result, xhr) { that.saveSuccess(model,result,xhr,infoMsgId);}});\r
-                if (isNew) {\r
-                    console.log(this.model);\r
+                                       invalid: function(model, result, xhr) { console.log("invalid!"); that.saveError(model,result,xhr,infoMsgId);},\r
+                                       success: function(model, result, xhr) { that.saveSuccess(model,result,xhr,infoMsgId, isNew);}});\r
+                /*if (isNew) {\r
                     this.collection.add(this.model);\r
                     this.collection.sort();\r
-                }\r
+                }*/\r
                 this.dirty = false;\r
             },