Master "Save All" button

  • 1
  • Question
  • Updated 3 years ago
Hello,

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?

Thx
Photo of Dave

Dave

  • 5,538 Points 5k badge 2x thumb

Posted 3 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
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.
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
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.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Dave,

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

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

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.