UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

122 lines 6.38 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 { MessageViewModel } from './message-view-model'; import * as Msg from '../user-messages'; import * as Helpers from './helpers-view-models'; import each from 'lodash/each'; import every from 'lodash/every'; import forEach from 'lodash/forEach'; import map from 'lodash/map'; import pickBy from 'lodash/pickBy'; var DialogViewModel = (function (_super) { __extends(DialogViewModel, _super); function DialogViewModel(color, context, viewModelFactory, urlManager, error, routeData, action, actionViewModel, isMultiLineDialogRow, row) { var _this = _super.call(this) || this; _this.color = color; _this.context = context; _this.viewModelFactory = viewModelFactory; _this.urlManager = urlManager; _this.error = error; _this.routeData = routeData; _this.isMultiLineDialogRow = isMultiLineDialogRow; _this.actionMember = function () { return _this.actionViewModel.actionRep; }; _this.execute = function (right) { var pps = _this.parameters; return _this.actionViewModel.execute(pps, right); }; _this.submitted = false; _this.closed = false; // make sure we never close more than once _this.refresh = function () { var fields = _this.context.getDialogCachedValues(_this.actionMember().actionId(), _this.onPaneId); forEach(_this.parameters, function (p) { return p.refresh(fields[p.id]); }); }; _this.clientValid = function () { return every(_this.parameters, function (p) { return p.clientValid; }); }; _this.tooltip = function () { return Helpers.tooltip(_this, _this.parameters); }; _this.setParms = function () { return forEach(_this.parameters, function (p) { return _this.context.cacheFieldValue(_this.actionMember().actionId(), p.parameterRep.id(), p.getValue(), _this.onPaneId); }); }; _this.doInvoke = function (right) { return _this.execute(right) .then(function (actionResult) { if (actionResult.shouldExpectResult()) { _this.setMessage(actionResult.warningsOrMessages() || Msg.noResultMessage); } else if (actionResult.resultType() === "void") { // dialog staying on same page so treat as cancel // for url replacing purposes and have to explicitly close _this.doCloseReplaceHistory(); } else if (!_this.isQueryOnly) { // not query only and going to new page mark as complete // and have to explicitly close _this.doCloseKeepHistory(); } else { // query only - if on same pane will be replaced if on other pane // will stay open _this.doComplete(); } }) .catch(function (reject) { var display = function (em) { return Helpers.handleErrorResponse(em, _this, _this.parameters); }; _this.error.handleErrorAndDisplayMessages(reject, display); }); }; _this.doCloseKeepHistory = function () { _this.urlManager.closeDialogKeepHistory(_this.id, _this.onPaneId); _this.doComplete(); }; _this.doCloseReplaceHistory = function () { _this.urlManager.closeDialogReplaceHistory(_this.id, _this.onPaneId); _this.doComplete(); }; _this.clearMessages = function () { _this.resetMessage(); each(_this.actionViewModel.parameters, function (parm) { return parm.clearMessage(); }); }; _this.actionViewModel = actionViewModel || _this.viewModelFactory.actionViewModel(action, _this, routeData); _this.onPaneId = routeData.paneId; var fields = _this.context.getDialogCachedValues(_this.actionMember().actionId(), _this.onPaneId); var parameters = pickBy(_this.actionViewModel.invokableActionRep.parameters(), function (p) { return !p.isCollectionContributed(); }); _this.parameters = map(parameters, function (p) { return _this.viewModelFactory.parameterViewModel(p, fields[p.id()], _this.onPaneId); }); _this.title = _this.actionMember().extensions().friendlyName(); _this.isQueryOnly = _this.actionViewModel.invokableActionRep.isQueryOnly(); _this.resetMessage(); _this.id = _this.actionViewModel.actionRep.actionId(); _this.incrementPendingPotentAction(); if (_this.isMultiLineDialogRow) { _this.actionViewModel.gotoResult = false; _this.parameters.forEach(function (p) { return p.setAsRow(row); }); } return _this; } DialogViewModel.prototype.incrementPendingPotentAction = function () { if (!this.isMultiLineDialogRow) { Helpers.incrementPendingPotentAction(this.context, this.actionViewModel.invokableActionRep, this.onPaneId); } }; DialogViewModel.prototype.decrementPendingPotentAction = function () { if (!this.isMultiLineDialogRow && !this.closed) { Helpers.decrementPendingPotentAction(this.context, this.actionViewModel.invokableActionRep, this.onPaneId); } this.closed = true; }; DialogViewModel.prototype.submit = function () { if (this.isMultiLineDialogRow) { this.submitted = true; } }; DialogViewModel.prototype.doComplete = function () { this.submit(); this.decrementPendingPotentAction(); }; return DialogViewModel; }(MessageViewModel)); export { DialogViewModel }; //# sourceMappingURL=dialog-view-model.js.map