UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

100 lines 4.8 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { Command } from './Command'; import * as Usermessages from '../user-messages'; import map from 'lodash/map'; import forEach from 'lodash/forEach'; import reduce from 'lodash/reduce'; var Action = (function (_super) { __extends(Action, _super); function Action() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.shortCommand = "ac"; _this.fullCommand = Usermessages.actionCommand; _this.helpText = Usermessages.actionHelp; _this.minArguments = 0; _this.maxArguments = 2; return _this; } Action.prototype.isAvailableInCurrentContext = function () { return (this.isMenu() || this.isObject() || this.isForm()) && !this.isDialog() && !this.isEdit(); //TODO add list }; Action.prototype.doExecute = function (args, chained, result) { var _this = this; var match = this.argumentAsString(args, 0); var details = this.argumentAsString(args, 1, true); if (details && details !== "?") { return this.returnResult("", Usermessages.mustbeQuestionMark); } if (this.isObject()) { return this.getObject().then(function (obj) { return _this.processActions(match, obj.actionMembers(), details); }); } else if (this.isMenu()) { return this.getMenu().then(function (menu) { return _this.processActions(match, menu.actionMembers(), details); }); } //TODO: handle list - CCAs return Promise.reject("TODO: handle list - CCAs"); }; Action.prototype.processActions = function (match, actionsMap, details) { var actions = map(actionsMap, function (action) { return action; }); if (actions.length === 0) { return this.returnResult("", Usermessages.noActionsAvailable); } if (match) { actions = this.matchFriendlyNameAndOrMenuPath(actions, match); } switch (actions.length) { case 0: return this.returnResult("", Usermessages.doesNotMatchActions(match)); case 1: var action = actions[0]; if (details) { return this.returnResult("", this.renderActionDetails(action)); } else if (action.disabledReason()) { return this.returnResult("", this.disabledAction(action)); } else { return this.openActionDialog(action); } default: var output = match ? Usermessages.matchingActions : Usermessages.actionsMessage; output += this.listActions(actions); return this.returnResult("", output); } }; Action.prototype.disabledAction = function (action) { return Usermessages.actionPrefix + " " + action.extensions().friendlyName() + " " + Usermessages.isDisabled + " " + action.disabledReason(); }; Action.prototype.listActions = function (actions) { return reduce(actions, function (s, t) { var menupath = t.extensions().menuPath() ? t.extensions().menuPath() + " - " : ""; var disabled = t.disabledReason() ? " (" + Usermessages.disabledPrefix + " " + t.disabledReason() + ")" : ""; return s + menupath + t.extensions().friendlyName() + disabled + "\n"; }, ""); }; Action.prototype.openActionDialog = function (action) { var _this = this; return this.context.getInvokableAction(action). then(function (invokable) { _this.context.clearDialogCachedValues(); _this.urlManager.setDialog(action.actionId()); forEach(invokable.parameters(), function (p) { return _this.setFieldValueInContext(p, p.default()); }); return _this.returnResult("", ""); }); }; Action.prototype.renderActionDetails = function (action) { return Usermessages.descriptionPrefix + " " + action.extensions().friendlyName() + "\n" + (action.extensions().description() || Usermessages.noDescription); }; return Action; }(Command)); export { Action }; //# sourceMappingURL=action.js.map