Save Button to Save all Modules in Page Include

  • 1
  • Question
  • Updated 2 years ago
I have 2 pages, a main page and a sub-page that is connected to the main page with a Page Include component.  Is there a way that I can add a button to the main page that will be able to save the modules from the sub-page?
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb

Posted 3 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Yup. Setup the Save action on a local model and hack the name of the model in the page include into it via the XML.
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb
thanks Pat - i've tried that, but i must be doing something wrong... the name of the model in the Page Include is "rfqCentral"... do i need to write is a certain way?
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
<action type="save">
                     <models>
                        <model>rfqCentral</model>
                     </models>
                     <onerroractions>
                        <action type="blockUI" message="There was an error saving" timeout="3000"/>
                     </onerroractions>
                  </action>
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb
yea... tried that and its not working... thanks anyway...
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Wait. The page include has to be open, otherwise it won't work.
Photo of Scott

Scott

  • 2,722 Points 2k badge 2x thumb
when i try this, i get an error at the top of the page that says the model cannot be found...
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
strange. this has worked for me.
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
Although I didn't get the error Scott describes, I was having issues with this as well when hackifying the standard save/cancel button. I was able to get this to work when I moved the save action into a multiple action framework action.
Photo of Don Souza

Don Souza, Employee

  • 1,160 Points 1k badge 2x thumb
Correct, use multiple actions and have the same model structure (names/fields) in all pages.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
We use this:

// Global Save Buttons Javascript
(function (skuid){
// NOTE: Requires a ui-only Model named ChangeTracker 
// Do not load on pageload, 0 rows, create row if none,
// Do not prevent leaving with unsaved changes,
//      And a ui-only checkbox field called ModelChanges.
// Set global buttons to run snippets
// "saveAllSnippet' and 'cancelAllSnippet'
//   and conditionally enable when ModelChanges is true.
//////////////////////////////////////////////
// Shortcuts & Global Variables //
//////////////////////////////////////////////
var $ = skuid.$,
$e = skuid.events.subscribe,
ChangeTracker;
//////////////////////////////////////////////
// Helper Functions //
//////////////////////////////////////////////
var checkForChanges = function(){
if (!ChangeTracker) ChangeTracker = skuid.$M('ChangeTracker');
var trackerRow = ChangeTracker && ChangeTracker.getFirstRow();
if (trackerRow) {
var changes = false;
$.each(skuid.model.map(),function(){
if (this.hasChanged && this.preventUnloadIfUnsavedChanges && (this.id !== 'ChangeTracker')) {
changes = true;
}
});
ChangeTracker.updateRow(trackerRow, {'ModelChanges': changes});
}
};
//////////////////////////////////////////////
// Subscriptions //
//////////////////////////////////////////////
$e('models.cancelled', checkForChanges);
$e('models.saved', checkForChanges);
$e('row.created', checkForChanges);
$e('row.updated', checkForChanges);
$e('row.deleted', checkForChanges);
$e('row.undeleted', checkForChanges);
//////////////////////////////////////////////
//    Pageload //
//////////////////////////////////////////////
$(document.body).one('pageload',function(){
ChangeTracker = skuid.$M('ChangeTracker');
});
})(skuid);

And here are the snippets:

'saveAllSnippet': function () {		var modelsToSave = [],
modelsToExclude = ['AddTests','ProcessLog','ChangeTracker','ShowTabs','UI_Model','DefaultTo','ChartAudit'],
dfd = new $.Deferred();
$.each(skuid.model.map(), function(){
if (this.hasChanged && (modelsToExclude.indexOf(this.id) === -1) && this.preventUnloadIfUnsavedChanges) {
modelsToSave.push(this);
}
});
$.when(skuid.model.save(modelsToSave))
.done(function(result){
console.log('All Models Saved.');
dfd.resolve(result);
})
.fail(function(result){
console.log('All Model Save Failed.');
dfd.reject(result);
});
return dfd.promise();
},
'cancelAllSnippet': function(){
var modelsToCancel = [];
$.each(skuid.model.map(), function(){
if (this.hasChanged && this.preventUnloadIfUnsavedChanges) {
modelsToCancel.push(this);
}
});
skuid.model.cancel(modelsToCancel);
}
(Edited)
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
Quite cool. I think this wouldn't work if you have the same page include on a host page more than once since the earlier model objects get dropped off the page when the latest page-include of a given skuid page has loaded.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Right. You can only use a page include once per page.