From: Scott Baker Date: Tue, 2 Dec 2014 18:49:04 +0000 (-0800) Subject: replace the onclick itemview handler with a naviation/template based one X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=2b2a83ed83c3081961e24181c5b2e91f92dc93d6;p=plstackapi.git replace the onclick itemview handler with a naviation/template based one --- diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js index 918e4a2..e5ca413 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-backbone.js @@ -70,6 +70,14 @@ if (! window.XOSLIB_LOADED ) { return res; }, + /* If a 'validate' method is supplied, then it will be called + automatically on save. Unfortunately, save calls neither the + 'error' nor the 'success' callback if the validator fails. + + For now, we're calling our validator 'xosValidate' so this + autoamtic validation doesn't occur. + */ + xosValidate: function(attrs, options) { errors = {}; foundErrors = false; @@ -88,7 +96,15 @@ if (! window.XOSLIB_LOADED ) { return errors; } // backbone.js semantics -- on successful validate, return nothing - } + }, + + /* uncommenting this would make validate() call xosValidate() + validate: function(attrs, options) { + r = this.xosValidate(attrs, options); + console.log("validate"); + console.log(r); + return r; + }, */ }); XOSCollection = Backbone.Collection.extend({ @@ -295,10 +311,10 @@ if (! window.XOSLIB_LOADED ) { for (key in attrs) { value = attrs[key]; - if ($.inArray(key, ["urlRoot", "modelName", "validate"])>=0) { + if ($.inArray(key, ["urlRoot", "modelName", "collectionName", "validate"])>=0) { modelAttrs[key] = value; } - if ($.inArray(key, ["urlRoot", "modelName", "relatedCollections", "foreignCollections"])>=0) { + if ($.inArray(key, ["urlRoot", "modelName", "collectionName", "relatedCollections", "foreignCollections"])>=0) { collectionAttrs[key] = value; } } diff --git a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js index 2eb3e42..28f85fd 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xosHelper.js +++ b/planetstack/core/xoslib/static/js/xoslib/xosHelper.js @@ -231,6 +231,7 @@ XOSDetailView = Marionette.ItemView.extend({ }, saveError: function(model, result, xhr, infoMsgId) { + console.log("saveError"); result["what"] = "save " + model.modelName + " " + model.attributes.humanReadableName; result["infoMsgId"] = infoMsgId; this.app.showError(result); @@ -306,7 +307,6 @@ XOSDetailView = Marionette.ItemView.extend({ 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);}, - 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); @@ -420,15 +420,9 @@ XOSItemView = Marionette.ItemView.extend({ tagName: 'tr', className: 'test-tablerow', - events: {"click": "changeItem"}, - - changeItem: function(e) { - this.app.hideError(); - e.preventDefault(); - e.stopPropagation(); - - this.app.navigateToModel(this.app, this.detailClass, this.detailNavLink, this.model); - }, + templateHelpers: function() { return { modelName: this.model.modelName, + collectionName: this.model.collectionName, + }}, }); /* XOSListView: diff --git a/planetstack/core/xoslib/templates/xosAdmin.html b/planetstack/core/xoslib/templates/xosAdmin.html index 8e0448d..b032e00 100644 --- a/planetstack/core/xoslib/templates/xosAdmin.html +++ b/planetstack/core/xoslib/templates/xosAdmin.html @@ -90,6 +90,18 @@ + + + + + + @@ -376,7 +390,7 @@ @@ -410,8 +424,8 @@