////////////////////////////////////////////////////////////////// // GML ACTION RULES #INCLUDE[gml:defs.inc] Configure RULES var category = 'Actions'; $ENV.defineRule({ id:'getAllowedActions', category:category, description: 'This Rule is used for defining the allowed actions per Unit, Interactor and control.' + ' Where list is in-out parameter for collecting all the allowed actions.' + ' Each list item holds several properties, one of which is the "title" property, that must be unique.', parameters:'gml:Unit unit!, gml:Interactor interactor!, gml:Control control!, Collection list, gml:Action parent', additive:true }); $ENV.defineRule({ id:'isActionAllowed', category:category, description: 'This Rule is used for defining the allowed actions per action group,' + ' Where isAllowed is boolean determine if this button should be enabled.' + ' Note that actionId holds the allowed-action title.', parameters:'gml:Interactor interactor!, gml:Control control!, gml:Action actionGroup!, String actionId', returnValue:'Boolean', restrictive:true, behavior:function(){ return true; } }); $ENV.extendRule('definePropertyGroups', { constraint:'(object isa gml:ActionGroup)', behavior: function() { groups.push({id: 'compoundAction', type:'group', title:'#TEXT[XTIT_COMPOUND_ACTION_CONF]', toggle:'on', layout: 'absolute', height: 234, inner:4, priority:110, sortBy:'label'}); }, comments:'⇒ [General, Data, Drawing]' }); $ENV.extendRule('definePropertyEditor', { constraint:'object isa gml:ActionGroup', behavior: function() { var allowedActions = []; var elem1 = { id: 'allowedActions', group: 'compoundAction', type: 'combo', style: 'position:absolute;width:35%', label: 'Add Action:', top:0, left: 0, width: 200, data: {}, domain: function (context) { var res = []; allowedActions = []; var obj = context; var parent = context.parent; while (!parent.isa('core.gml:Interactor')) { obj = parent; parent = parent.parent; } var interactor = parent; var control = interactor.getControlByActionId(obj.id); RULE('getAllowedActions', unit, interactor, control, allowedActions, context); for (var k in allowedActions) { var allowed = RULE('isActionAllowed', interactor, control, context, allowedActions[k].title); if(allowed) res.push({text:allowedActions[k].title, value:allowedActions[k].title}); } return res; }, getter: function (data, def) { for (var k in def.data) { return def.data[k]; } }, setter: function(value, data, def){ def.data = {}; for (var k in allowedActions) { if(allowedActions[k].title == value) { def.data[value] = allowedActions[k].title; break; } } }, sideEffects:true }; elements.push(elem1); var elem2 = { id: 'btnAdd', group: 'compoundAction', type: 'btn', label: 'Add', top: 0, left: 210, signal: function(data, def){ var actions = data.getProperty("actions"), actionClassname, values; // get highest order +1 var newOrder = 0; for (var a in actions) { var order = actions[a].getProperty("order"); if (order >= newOrder) newOrder=order+1; } for(var k in elem1.data){ // get "action class" from "allowed actions" by matching the "action title" // // First, identify allowed action that matches the selected action for (var j in allowedActions) { if (elem1.data[allowedActions[j].title]) { // prepare info needed to create the action actionClassname = allowedActions[j].id; values = allowedActions[j].values || {}; values['name']= allowedActions[j].title; values['order']=newOrder; break; } if (actionClassname) break; } // Create the action data.createElement(actionClassname, 'actions', values); } // Clear action selection combo box elem1.data = {}; }, sideEffects:true }; elements.push(elem2); // Adding the input field editor var gridElem = { id: 'actions', type: 'gridedit', group: 'compoundAction', visible: 'ISA(data, "core.gml:ActionGroup")', domain: [ {id: 'actionId', type: 'str', caption: '#TEXT[XCOL_ACTION_ID]', readonly: true, width: '100', hide: true}, {id: 'actionName', type: 'str', caption: '#TEXT[XCOL_ACTION]', readonly: true, width: '100'}, {id: 'actionTitle', type: 'str', caption: '#TEXT[XCOL_ACTION_TITLE]', readonly: true, width: '100'}, {id: 'actionNotes', type: 'str', caption: '#TEXT[XTIT_COMMENTS]', readonly: true, width: '250'}], active: 'true', style: 'width:100%;height:100%', top:27, left:0, height: 169, getDataObject: function(data, def) { return data; }, getter: function(data, def) { return rule.getGroupActionItems(data, def); }, removeItem: function(lParam , data, def) { if(lParam != null) { var actions = data.getProperty("actions"); if(ISEMPTY(actions)) return; var aId = rule.getActionIdByIndex(data,lParam); var action=actions[aId]; if (action) if (!canDeleteStableIDs([action], true, true)) return; data.removeElement(action, 'actions'); } }, detailedView: function (data , def, lParam) { if(lParam != null) { var actions = data.getProperty("actions"); if(ISEMPTY(actions)) return; var aId = rule.getActionIdByIndex(data,lParam); var action=actions[aId]; var form = def.form; MODAL("#URL[dev:common.PropEditor.htm]",{'object':action, 'title':'Configure action item'},true); // refresh view def.form = form; if (form) form.repaintAll(); } }, itemsType: 'gml:ActionGroup', toolbar: true , sideEffects: true, notify: true }; elements.push(gridElem); }, comments:'⇒' }); // get list of action items in a compound action $ENV.defineRuleHelper('definePropertyEditor', 'getGroupActionItems', function(data, def) { var res = []; var row = 0; var actionGroup = data; if (ISA(actionGroup, "core.gml:ActionGroup")) { var items = actionGroup.getProperty("actions"); for (var i in items) { res[row] = { actionId: items[i].getProperty('id'), actionName: items[i].getAlias(), actionTitle: items[i].getProperty('name') || items[i].Class.metadata.title, actionNotes: items[i].getProperty('notes'), actionOrder: items[i].getProperty('order')}; row++; } SORTN(res,'actionOrder'); } return res; }); //get list of action items in a compound action $ENV.defineRuleHelper('definePropertyEditor', 'getActionIdByIndex', function(data, lParam) { var actions = data.getProperty("actions"); var res=[]; var row =0; for (var i in actions) { res[row] = { actionId: actions[i].getProperty('id'), actionOrder: actions[i].getProperty('order')}; row++; }//end for SORTN(res,'actionOrder'); var a = res[lParam].actionId; return a; });