Created
October 17, 2016 19:52
-
-
Save anonymous/a557119c0fc9547a9f126d25843e4713 to your computer and use it in GitHub Desktop.
This script syncs conditions on models of a common object type.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var params = arguments[0], | |
$ = skuid.$; | |
var triggerModel = params.model; | |
var triggerConditions = triggerModel.conditions; | |
var allModels = skuid.model.getModelsList(); | |
//iterate though all the page models | |
$.each(allModels, function(i, model) { | |
if (triggerModel.objectName == model.objectName) { //make sure we're only concerning ourselves with like-typed models | |
$.each(triggerConditions, function(j, condition) { //iterate through all the triggering model's conditions | |
var conditionToUpdate = model.getConditionByName(condition.name); | |
if (conditionToUpdate && (conditionToUpdate.inactive != condition.inactive || conditionToUpdate.values != condition.values)) { | |
if (conditionToUpdate.type == 'multiple') { //use values | |
model.setCondition(conditionToUpdate, JSON.parse(JSON.stringify(condition.values))); //deep clone via JSON stringify | |
} else { | |
model.setCondition(conditionToUpdate, JSON.parse(JSON.stringify(condition.value))); //deep clone via JSON stringify | |
} | |
conditionToUpdate.inactive = condition.inactive; //sync the active/inactive | |
model.updateData() | |
} | |
}); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment