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?
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.
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?
<action type="save"> <models> <model>rfqCentral</model> </models> <onerroractions> <action type="blockUI" message="There was an error saving" timeout="3000"/> </onerroractions> </action>
yea… tried that and its not working… thanks anyway…
Wait. The page include has to be open, otherwise it won’t work.
when i try this, i get an error at the top of the page that says the model cannot be found…
strange. this has worked for me.
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.
Correct, use multiple actions and have the same model structure (names/fields) in all pages.
We use this:
// Global Save Buttons Javascript<br />(function (skuid){<br />// NOTE: Requires a ui-only Model named ChangeTracker <br />// Do not load on pageload, 0 rows, create row if none,<br />// Do not prevent leaving with unsaved changes,<br />// And a ui-only checkbox field called ModelChanges.<br />// Set global buttons to run snippets<br />// "saveAllSnippet' and 'cancelAllSnippet' <br />// and conditionally enable when ModelChanges is true.<br />//////////////////////////////////////////////<br />// Shortcuts & Global Variables //<br />//////////////////////////////////////////////<br />var $ = skuid.$,<br /> $e = skuid.events.subscribe,<br /> ChangeTracker;<br />//////////////////////////////////////////////<br />// Helper Functions //<br />//////////////////////////////////////////////<br />var checkForChanges = function(){<br /> if (!ChangeTracker) ChangeTracker = skuid.$M('ChangeTracker');<br /> var trackerRow = ChangeTracker && ChangeTracker.getFirstRow();<br /> if (trackerRow) {<br /> var changes = false;<br /> $.each(skuid.model.map(),function(){<br /> if (this.hasChanged && this.preventUnloadIfUnsavedChanges && (this.id !== 'ChangeTracker')) {<br /> changes = true;<br /> }<br /> });<br /> ChangeTracker.updateRow(trackerRow, {'ModelChanges': changes});<br /> }<br />};<br />//////////////////////////////////////////////<br />// Subscriptions //<br />//////////////////////////////////////////////<br />$e('models.cancelled', checkForChanges);<br />$e('models.saved', checkForChanges);<br />$e('row.created', checkForChanges);<br />$e('row.updated', checkForChanges);<br />$e('row.deleted', checkForChanges);<br />$e('row.undeleted', checkForChanges);<br />//////////////////////////////////////////////<br />// Pageload //<br />//////////////////////////////////////////////<br />$(document.body).one('pageload',function(){<br /> ChangeTracker = skuid.$M('ChangeTracker');<br />}); <br />})(skuid);
And here are the snippets:
'saveAllSnippet': function () { var modelsToSave = [],<br />modelsToExclude = ['AddTests','ProcessLog','ChangeTracker','ShowTabs','UI_Model','DefaultTo','ChartAudit'],<br />dfd = new $.Deferred();<br />$.each(skuid.model.map(), function(){<br />if (this.hasChanged && (modelsToExclude.indexOf(this.id) === -1) && this.preventUnloadIfUnsavedChanges) {<br />modelsToSave.push(this);<br />}<br />});<br />$.when(skuid.model.save(modelsToSave))<br />.done(function(result){<br />console.log('All Models Saved.');<br />dfd.resolve(result);<br />})<br />.fail(function(result){<br />console.log('All Model Save Failed.');<br />dfd.reject(result);<br />});<br />return dfd.promise();<br />},<br />'cancelAllSnippet': function(){<br />var modelsToCancel = [];<br />$.each(skuid.model.map(), function(){<br />if (this.hasChanged && this.preventUnloadIfUnsavedChanges) {<br />modelsToCancel.push(this);<br />}<br />});<br />skuid.model.cancel(modelsToCancel);<br />}
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.
Right. You can only use a page include once per page.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.