Skip to content

Instantly share code, notes, and snippets.

Created October 17, 2016 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/a557119c0fc9547a9f126d25843e4713 to your computer and use it in GitHub Desktop.
Save anonymous/a557119c0fc9547a9f126d25843e4713 to your computer and use it in GitHub Desktop.
This script syncs conditions on models of a common object type.
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