dynamic listen for model close

  • 2
  • Idea
  • Updated 3 years ago
  • Implemented
In a sharing mood today. :D

Similar to this blog but slightly updated code.

http://www.mblazonry.com/creating-a-new-opportunity-in-salesforce-using-only-one-model-2/

// Listen for popup close of new record using just one model.
// Snippet to be called after creating new row AND displaying popup
// Only downside to this is that saving the model in the popup also saves any 
// other edits in the model.
skuid.snippet.registerSnippet('listenForPopupClose',function(args) {
    var params = arguments[0],
    $ = skuid.$,
    row = params.context.row,
    model = params.context.model;
    

        skuid.$(".ui-dialog-content").dialog({
            "beforeClose" : function()
            {
                var numOfChanges = Object.keys(model.changes).length;    

                // if there is more than row that is currently changed (new, marked for deletion, edited) then this new row will be abandoned.
                if (numOfChanges > 1){
                    model.abandonRow(row);
                // otherwise just mark if for deletion and save
                } else if (numOfChanges == 1) {
                    model.deleteRow(row);
                    model.save();
                }
            }
        });
});
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb

Posted 3 years ago

  • 2
Photo of Anna Wiersema

Anna Wiersema

  • 10,890 Points 10k badge 2x thumb
How happy are the days when Pat's in a sharing mood! Thanks for all this good stuff!