1 define(function(require) {
5 var _ = require('libs/underscore'),
6 Backbone = require('libs/backbone');
8 var Action = function(fqName, definition, config, appObject) {
10 this.definition = definition;
13 this.appObject = appObject;
18 _.extend(Action.prototype, Backbone.Events, {
19 getPluginName: function() {
20 return this.fqName.split('.')[0];
22 updateParam: function(filter, value) {
24 _.pairs(this.definition.params).forEach(function(pair) {
25 var paramName = pair[0],
27 if(filter(paramDesc, paramName)) {
28 this.params[paramName] = value;
34 this.trigger('paramsChanged');
37 updateContextParam: function(contextName, value) {
38 this.updateParam(function(paramDesc) {
39 return paramDesc.type === 'context' && paramDesc.name === contextName;
42 updateKeyParam: function(keyName, toggled) {
43 this.updateParam(function(paramDesc) {
44 return paramDesc.type === 'key' && paramDesc.key === keyName;
47 updateWidgetParam: function(name, value) {
48 this.updateParam(function(paramDesc, paramName) {
49 return !_.contains(['context', 'key'], paramDesc.type) && paramName === name;
52 getState: function() {
55 gotState = this.definition.getState.call(this, this.params);
56 if(typeof gotState === 'boolean') {
57 gotState = {allowed: gotState};
59 this._cache = _.extend({}, this.definition.stateDefaults || {}, gotState);
61 if(this._cache === false) {
62 this._cache = {allowed: false};
67 var state = this.getState();
69 return state.execute.call(this, this.params, this.appObject);
71 throw new Error('Execution not allowed');