1 define(function(require) {
5 var _ = require('libs/underscore'),
6 Backbone = require('libs/backbone'),
7 logging = require('fnpjs/logging/logging');
9 var logger = logging.getLogger('fnpjs.actions');
12 var Action = function(fqName, definition, config, appObject) {
14 this.definition = definition;
17 this.appObject = appObject;
22 _.extend(Action.prototype, Backbone.Events, {
23 getPluginName: function() {
24 return this.fqName.split('.')[0];
26 updateParam: function(filter, value) {
28 _.pairs(this.definition.params).forEach(function(pair) {
29 var paramName = pair[0],
31 if(filter(paramDesc, paramName)) {
32 this.params[paramName] = value;
38 this.trigger('paramsChanged');
41 updateContextParam: function(contextName, value) {
42 this.updateParam(function(paramDesc) {
43 return paramDesc.type === 'context' && paramDesc.name === contextName;
46 updateKeyParam: function(keyName, toggled) {
47 this.updateParam(function(paramDesc) {
48 return paramDesc.type === 'key' && paramDesc.key === keyName;
51 updateWidgetParam: function(name, value) {
52 this.updateParam(function(paramDesc, paramName) {
53 return !_.contains(['context', 'key'], paramDesc.type) && paramName === name;
56 getState: function() {
60 gotState = this.definition.getState.call(this, this.params);
65 if(typeof gotState === 'boolean') {
66 gotState = {allowed: gotState};
68 this._cache = _.extend({}, this.definition.stateDefaults || {}, gotState);
70 if(this._cache === false) {
71 this._cache = {allowed: false};
76 var state = this.getState();
78 var callback = function(ret) {
79 this.trigger('actionExecuted', ret);
83 return state.execute.call(this, callback, this.params, this.appObject);
85 throw new Error('Execution not allowed');