UNPKG

nakedobjects.spa

Version:

Single Page Application client for a Naked Objects application.

200 lines 9.13 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 __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; import { Component, ViewChildren, QueryList } from '@angular/core'; import { PaneComponent } from '../pane/pane'; import { ParametersComponent } from '../parameters/parameters.component'; import { ViewModelFactoryService } from '../view-model-factory.service'; import { ActivatedRoute } from '@angular/router'; import { UrlManagerService } from '../url-manager.service'; import { ContextService } from '../context.service'; import { ErrorService } from '../error.service'; import { FormBuilder } from '@angular/forms'; import { ConfigService } from '../config.service'; import * as Msg from '../user-messages'; import * as Models from '../models'; import find from 'lodash/find'; import forEach from 'lodash/forEach'; import map from 'lodash/map'; import some from 'lodash/some'; import each from 'lodash/each'; import { safeUnsubscribe, createForm } from '../helpers-components'; var MultiLineDialogComponent = (function (_super) { __extends(MultiLineDialogComponent, _super); function MultiLineDialogComponent(activatedRoute, urlManager, viewModelFactory, context, error, formBuilder, configService) { var _this = _super.call(this, activatedRoute, urlManager, context) || this; _this.viewModelFactory = viewModelFactory; _this.error = error; _this.formBuilder = formBuilder; _this.configService = configService; _this.form = function (i) { var rowData = _this.rowData[i]; return rowData.form; }; _this.parameters = function (row) { return row.parameters; }; _this.rowSubmitted = function (row) { return row.submitted; }; _this.rowTooltip = function (row) { return row.tooltip(); }; _this.rowMessage = function (row) { return row.submitted ? Msg.submittedMessage : row.getMessage(); }; _this.rowDisabled = function (row) { return !row.clientValid() || row.submitted; }; _this.close = function () { _this.urlManager.popUrlState(); }; return _this; } Object.defineProperty(MultiLineDialogComponent.prototype, "objectFriendlyName", { get: function () { return this.dialog.objectFriendlyName; }, enumerable: true, configurable: true }); Object.defineProperty(MultiLineDialogComponent.prototype, "objectTitle", { get: function () { return this.dialog.objectTitle; }, enumerable: true, configurable: true }); Object.defineProperty(MultiLineDialogComponent.prototype, "dialogTitle", { get: function () { return this.dialog.title; }, enumerable: true, configurable: true }); Object.defineProperty(MultiLineDialogComponent.prototype, "header", { get: function () { return this.dialog.header(); }, enumerable: true, configurable: true }); Object.defineProperty(MultiLineDialogComponent.prototype, "rows", { get: function () { return this.dialog.dialogs; }, enumerable: true, configurable: true }); Object.defineProperty(MultiLineDialogComponent.prototype, "count", { get: function () { return Msg.submittedCount(this.dialog.submittedCount()); }, enumerable: true, configurable: true }); MultiLineDialogComponent.prototype.invokeAndAdd = function (index) { var _this = this; var parms = this.rowData[index].parms; forEach(parms, function (p) { var newValue = _this.rowData[index].form.value[p.id]; p.setValueFromControl(newValue); }); var addedIndex = this.dialog.invokeAndAdd(index); if (addedIndex) { this.rowData.push(this.createForm(this.dialog.dialogs[addedIndex])); } }; MultiLineDialogComponent.prototype.createForm = function (dialog) { return createForm(dialog, this.formBuilder); }; MultiLineDialogComponent.prototype.setMultiLineDialog = function (holder, newDialogId, routeData, actionViewModel) { var _this = this; var action = holder.actionMember(newDialogId); this.context.getInvokableAction(action). then(function (details) { if (actionViewModel) { actionViewModel.makeInvokable(details); } _this.dialog = _this.viewModelFactory.multiLineDialogViewModel(routeData, details, holder); _this.rowData = map(_this.dialog.dialogs, function (d) { return _this.createForm(d); }); }). catch(function (reject) { return _this.error.handleError(reject); }); }; MultiLineDialogComponent.prototype.setup = function (routeData) { var _this = this; if (routeData.menuId) { this.context.getMenu(routeData.menuId) .then(function (menu) { _this.setMultiLineDialog(menu, routeData.dialogId, routeData); }) .catch(function (reject) { _this.error.handleError(reject); }); } else if (routeData.objectId) { var oid = Models.ObjectIdWrapper.fromObjectId(routeData.objectId, this.configService.config.keySeparator); this.context.getObject(routeData.paneId, oid, routeData.interactionMode). then(function (object) { var ovm = _this.viewModelFactory.domainObjectViewModel(object, routeData, false); var newDialogId = routeData.dialogId; var lcaCollection = find(ovm.collections, function (c) { return c.hasMatchingLocallyContributedAction(newDialogId); }); if (lcaCollection) { var actionViewModel = find(lcaCollection.actions, function (a) { return a.actionRep.actionId() === newDialogId; }); _this.setMultiLineDialog(lcaCollection, newDialogId, routeData, actionViewModel); } else { _this.setMultiLineDialog(object, newDialogId, routeData); } }). catch(function (reject) { _this.error.handleError(reject); }); } }; MultiLineDialogComponent.prototype.focus = function (parms) { if (parms && parms.length > 0) { some(parms.toArray(), function (p) { return p.focus(); }); } }; MultiLineDialogComponent.prototype.ngAfterViewInit = function () { var _this = this; this.sub = this.parmComponents.changes.subscribe(function (ql) { return _this.focus(ql); }); }; MultiLineDialogComponent.prototype.ngOnDestroy = function () { safeUnsubscribe(this.sub); each(this.rowData, function (rd) { return safeUnsubscribe(rd.sub); }); _super.prototype.ngOnDestroy.call(this); }; return MultiLineDialogComponent; }(PaneComponent)); __decorate([ ViewChildren(ParametersComponent), __metadata("design:type", QueryList) ], MultiLineDialogComponent.prototype, "parmComponents", void 0); MultiLineDialogComponent = __decorate([ Component({ selector: 'nof-multi-line-dialog', template: require('./multi-line-dialog.component.html'), styles: [require('./multi-line-dialog.component.css')] }), __metadata("design:paramtypes", [ActivatedRoute, UrlManagerService, ViewModelFactoryService, ContextService, ErrorService, FormBuilder, ConfigService]) ], MultiLineDialogComponent); export { MultiLineDialogComponent }; //# sourceMappingURL=multi-line-dialog.component.js.map