Created
February 21, 2016 18:40
-
-
Save wabson/bacbe3a37558b4122655 to your computer and use it in GitHub Desktop.
Fix for Share rule definition UI in 4.0
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
<import resource="classpath:alfresco/site-webscripts/org/alfresco/components/rules/config/rule-config.lib.js"> | |
<import resource="classpath:alfresco/site-webscripts/org/alfresco/config.lib.js"> | |
function main() | |
{ | |
var c = new XML(config.script); | |
processScriptConfig(c); | |
processGlobalConfig(); | |
// Load rule config definitions, or in this case "ActionConditionDefinition:s" | |
var actionConditionDefinitions = loadRuleConfigDefinitions(c); | |
/** | |
* Remove the "compare-property-value" action condition definition from the list | |
* and put it as a dedicated variable since that condition is a special case | |
* and will be dynamically created on the page based on which property that is selected. | |
*/ | |
var i = 0; | |
var stdActionConditionDefinitions = []; | |
for (; i < actionConditionDefinitions.length; i++) | |
{ | |
if (actionConditionDefinitions[i].name == "compare-property-value") | |
{ | |
model.comparePropertyValueDefinition = jsonUtils.toJSONString(actionConditionDefinitions[i]); | |
} | |
else if (actionConditionDefinitions[i].name == "compare-mime-type") | |
{ | |
model.compareMimeTypeDefinition = jsonUtils.toJSONString(actionConditionDefinitions[i]); | |
} | |
else | |
{ | |
stdActionConditionDefinitions.push(actionConditionDefinitions[i]); | |
} | |
} | |
model.ruleConfigDefinitions = jsonUtils.toJSONString(stdActionConditionDefinitions); | |
// Load constraints for rule types | |
var conditionConstraints = loadRuleConstraints(c); | |
model.constraints = jsonUtils.toJSONString(conditionConstraints); | |
// Load filter for aspects, types and property evalurators that shall be visible | |
var constraintsFilter = {}; | |
constraintsFilter["ac-aspects"] = getDocumentLibraryAspects(); | |
constraintsFilter["ac-types"] = getDocumentLibraryTypes(); | |
// Save property-evaluator config as json | |
var propertyEvaluatorMap = {}, | |
propertyEvaluatorNodes = c.elements("property-evaluators"), | |
propertyEvaluatorNode = propertyEvaluatorNodes && propertyEvaluatorNodes.length() > 0 ? propertyEvaluatorNodes[0] : null, | |
evaluatorNode, | |
propertyNode, | |
propertyTypes; | |
if (propertyEvaluatorNode) | |
{ | |
for each (propertyNode in propertyEvaluatorNode.elements("property")) | |
{ | |
evaluatorNames = []; | |
for each (evaluatorNode in propertyNode.elements("evaluator")) | |
{ | |
evaluatorNames.push(evaluatorNode.@name.toString()); | |
} | |
propertyEvaluatorMap[propertyNode.@type.toString()] = evaluatorNames; | |
} | |
constraintsFilter["ac-compare-operations"] = propertyEvaluatorMap; | |
} | |
model.constraintsFilter = jsonUtils.toJSONString(constraintsFilter); | |
// Load user preferences for which proeprties to show in menu as default | |
var connector = remote.connect("alfresco"); | |
var result = connector.get("/api/people/" + encodeURIComponent(user.name) + "/preferences"); | |
if (result.status == 200) | |
{ | |
var prefs = eval('(' + result + ')'), | |
ruleProperties = {}; | |
// Get all default properties | |
if (c.defaults) | |
{ | |
for each (propertyNode in c.defaults.elements("property")) | |
{ | |
ruleProperties[propertyNode.text()] = "show"; | |
} | |
} | |
// Complete with user preferences | |
if (prefs && prefs.org && prefs.org.alfresco && prefs.org.alfresco.share && prefs.org.alfresco.share.rule && prefs.org.alfresco.share.rule.properties) | |
{ | |
var userProperties = prefs.org.alfresco.share.rule.properties; | |
for (propertyName in userProperties) | |
{ | |
// Will set value to "show" or "hide" | |
ruleProperties[propertyName] = userProperties[propertyName]; | |
} | |
} | |
// Get info such as type and display name about the properties to display | |
var propertiesParam = [], | |
transientPropertyInstructions = {}, | |
instructions, | |
propertyNameTokens, | |
basePropertyName; | |
for (propertyName in ruleProperties) | |
{ | |
if (ruleProperties[propertyName] == "show") | |
{ | |
propertyNameTokens = propertyName.split(":"); | |
basePropertyName = propertyNameTokens[0] + ":" + propertyNameTokens[1]; | |
instructions = transientPropertyInstructions[basePropertyName]; | |
if (!instructions) | |
{ | |
instructions = []; | |
transientPropertyInstructions[basePropertyName] = instructions; | |
} | |
propertiesParam.push(basePropertyName); | |
instructions.push(propertyNameTokens.length > 2 ? propertyName : basePropertyName); | |
} | |
} | |
var allProperties = [], | |
instruction; | |
if (propertiesParam.length > 0) | |
{ | |
result = connector.get("/api/properties?name=" + propertiesParam.join("&name=")); | |
if (result.status == 200) | |
{ | |
var properties = eval('(' + result + ')'); | |
for (var i = 0, il = properties.length; i < il; i++) | |
{ | |
property = properties[i]; | |
instructions = transientPropertyInstructions[property.name]; | |
for (var j = 0, jl = instructions ? instructions.length : 0; j < jl; j++) | |
{ | |
instruction = instructions[j]; | |
if (instruction == property.name) | |
{ | |
// It was a normal property, just add it | |
allProperties.push( | |
{ | |
name: property.name, | |
dataType: property.dataType, | |
title: property.title ? property.title : property.name | |
}); | |
} | |
else | |
{ | |
// It was a transient property, modify the id to represent the transient property | |
allProperties.push( | |
{ | |
name: instruction, | |
dataType: property.dataType, | |
title: null // will be set inside client js file instead | |
}); | |
} | |
} | |
} | |
} | |
} | |
model.properties = jsonUtils.toJSONString(allProperties); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment