From: Scott Baker Date: Tue, 2 Dec 2014 01:06:31 +0000 (-0800) Subject: add raw error dialog support, only add model to collection once it has been saved X-Git-Url: http://git.onelab.eu/?p=plstackapi.git;a=commitdiff_plain;h=897e898d0dd84c6a10955c92287768ada7481803 add raw error dialog support, only add model to collection once it has been saved --- diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js index 2930014..918e4a2 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js @@ -70,7 +70,7 @@ if (! window.XOSLIB_LOADED ) { return res; }, - validate: function(attrs, options) { + xosValidate: function(attrs, options) { errors = {}; foundErrors = false; _.each(this.validators, function(validatorList, fieldName) { diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-util.js b/planetstack/core/xoslib/static/js/xoslib/xos-util.js index d03ab14..5e91a3d 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-util.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-util.js @@ -22,7 +22,7 @@ function limitTableRows(tableSelector, maxRows) { } } -function validateField(validatorName, value) { +function validateField(validatorName, value, obj) { if (validatorName=="notBlank") { if ((value==undefined) || (value=="")) { return "can not be blank"; @@ -41,5 +41,6 @@ function validateField(validatorName, value) { } break; } + return true; } diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js index 2fa9554..2eb3e42 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js +++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js @@ -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); }, - saveSuccess: function(model, result, xhr, infoMsgId) { + saveSuccess: function(model, result, xhr, infoMsgId, isNew) { + console.log("saveSuccess"); + if (isNew) { + this.collection.add(model); + this.collection.sort(); + } result = {status: xhr.xhr.status, statusText: xhr.xhr.statusText}; result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName; result["infoMsgId"] = infoMsgId; @@ -274,21 +293,25 @@ XOSDetailView = Marionette.ItemView.extend({ model.save, we call it ourselves, so we can throw up our validation error before creating the infoMsg in the log */ - errors = this.model.validate(data); + errors = this.model.xosValidate(data); if (errors) { this.onFormDataInvalid(errors); return; } + if (isNew) { + this.model.attributes.humanReadableName = "new " + model.modelName; + } + var infoMsgId = this.app.showInformational( {what: "save " + model.modelName + " " + model.attributes.humanReadableName, status: "", statusText: "in progress..."} ); this.model.save(data, {error: function(model, result, xhr) { that.saveError(model,result,xhr,infoMsgId);}, - success: function(model, result, xhr) { that.saveSuccess(model,result,xhr,infoMsgId);}}); - if (isNew) { - console.log(this.model); + invalid: function(model, result, xhr) { console.log("invalid!"); that.saveError(model,result,xhr,infoMsgId);}, + success: function(model, result, xhr) { that.saveSuccess(model,result,xhr,infoMsgId, isNew);}}); + /*if (isNew) { this.collection.add(this.model); this.collection.sort(); - } + }*/ this.dirty = false; }, diff --git a/planetstack/core/xoslib/templates/xosAdmin.html b/planetstack/core/xoslib/templates/xosAdmin.html index daccf88..8e0448d 100644 --- a/planetstack/core/xoslib/templates/xosAdmin.html +++ b/planetstack/core/xoslib/templates/xosAdmin.html @@ -16,6 +16,12 @@ + +