Master "Save All" button


My main account page, uses a lot of different page include in different tabs.

And at this point, each of my page include has it’s own save/cancel buttons + the save/cancel button from main page

that makes a lot of different save button for users

I would like to know if it’s possible for me to create some sort of master “save all” button on main page to save changes from all models including models in pages include

Preferably with Enabling condition (if one of the model has changes), but if possible without that would do as well

Any ideas?


You can manually add the model names via the XML. There are problems with this.

  • Not sure what happens if a model is missing when the page include is not open. ie. does it crash the page
  • The model in any absent page include certainly won’t save. At least I’m almost certain. You’d have to open and close the page include and see if you can still see the model in Console.

I have done the reverse where I needed to call a query of a model on the main page from a button in the page include. You do have to hack the XML to do it. Make sure all of your models have unique names or it will get you into trouble. As Pat points out, you may have issues if your page includes or tabs are set to lazy load, so you may have to set all tabs and page includes to load on page load which could slow down load times. An alternative idea would be to create “auto save” on all of your page includes using a model action on each model that saves the model every time any field is updated. That way your page includes will always have changed saved as they are made and your master page could be saved on demand. The option you probably don’t want to think about, but may have to pursue, would be to take those components and models out of the page includes and add them into the main page. That would be the definitive answer to your problem. If you are handy at cutting and pasting the XML, it may be your fastest, surest route to solving your problem. Otherwise, you will have to recreate the components one-by-one.


You can also have your save button just run a snippet like this:

<br>'saveAllSnippet': function () { var modelsToSave = [],<br>modelsToExclude = ['AddTests', 'ProcessLog'],<br>dfd = new $.Deferred();<br>$.each(, function(){<br>if (this.hasChanged &amp;&amp; (modelsToExclude.indexOf( {<br>modelsToSave.push(this);<br>}<br>});<br>$.when(<br>.done(function(){<br>console.log('All Models Saved.');<br>dfd.resolve();<br>})<br>.fail(function(){<br>console.log('All Model Save Failed.');<br>dfd.reject();<br>});<br>return dfd.promise();<br>}

The upside is that you get all your models without hacking any XML.
The downside is that you don’t get the nice “Saving…” message, and the enable/disable based on whether any of the models have changes.