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 updateContextParam: function(contextName, value) {
24 _.pairs(this.definition.params).forEach(function(pair) {
25 var paramName = pair[0],
27 if(paramDesc.type === 'context' && paramDesc.name === contextName) {
28 this.params[paramName] = value;
34 this.trigger('paramsChanged');
37 updateKeyParam: function(keyName, toggled) {
39 _.pairs(this.definition.params).forEach(function(pair) {
40 var paramName = pair[0],
42 if(paramDesc.type === 'key' && paramDesc.key === keyName) {
43 this.params[paramName] = toggled;
50 this.trigger('paramsChanged');
53 updateWidgetParam: function(name, value) {
54 var paramDesc = this.definition.params[name];
55 if(paramDesc.type === 'context' || paramDesc.type === 'key') {
58 this.params[name] = value;
60 this.trigger('paramsChanged');
62 getState: function() {
65 gotState = this.definition.getState.call(this, this.params);
66 if(typeof gotState === 'boolean') {
67 gotState = {allowed: gotState};
69 this._cache = _.extend({}, this.definition.stateDefaults || {}, gotState);
71 if(this._cache === false) {
72 this._cache = {allowed: false};
77 var state = this.getState();
79 return state.execute.call(this, this.params, this.appObject);
81 throw new Error('Execution not allowed');