nakedobjects.spa
Version:
Single Page Application client for a Naked Objects application.
218 lines • 9.24 kB
JavaScript
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, Input, ViewChildren, QueryList } from '@angular/core';
import { ViewModelFactoryService } from '../view-model-factory.service';
import { UrlManagerService } from '../url-manager.service';
import { ActivatedRoute } from '@angular/router';
import { ContextService } from '../context.service';
import { ErrorService } from '../error.service';
import { FormBuilder } from '@angular/forms';
import { ListViewModel } from '../view-models/list-view-model';
import { MenuViewModel } from '../view-models/menu-view-model';
import { DomainObjectViewModel } from '../view-models/domain-object-view-model';
import { CollectionViewModel } from '../view-models/collection-view-model';
import { ConfigService } from '../config.service';
import { ParametersComponent } from '../parameters/parameters.component';
import find from 'lodash/find';
import forEach from 'lodash/forEach';
import some from 'lodash/some';
import { safeUnsubscribe, createForm } from '../helpers-components';
var DialogComponent = (function () {
function DialogComponent(viewModelFactory, urlManager, activatedRoute, error, context, configService, formBuilder) {
var _this = this;
this.viewModelFactory = viewModelFactory;
this.urlManager = urlManager;
this.activatedRoute = activatedRoute;
this.error = error;
this.context = context;
this.configService = configService;
this.formBuilder = formBuilder;
this.close = function () {
if (_this.dialog) {
_this.dialog.doCloseReplaceHistory();
}
};
}
Object.defineProperty(DialogComponent.prototype, "parent", {
get: function () {
return this.parentViewModel;
},
set: function (parent) {
this.parentViewModel = parent;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DialogComponent.prototype, "selectedDialogId", {
get: function () {
return this.currentDialogId;
},
set: function (id) {
this.currentDialogId = id;
this.getDialog();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DialogComponent.prototype, "title", {
get: function () {
var dialog = this.dialog;
return dialog ? dialog.title : "";
},
enumerable: true,
configurable: true
});
Object.defineProperty(DialogComponent.prototype, "message", {
get: function () {
var dialog = this.dialog;
return dialog ? dialog.getMessage() : "";
},
enumerable: true,
configurable: true
});
Object.defineProperty(DialogComponent.prototype, "parameters", {
get: function () {
var dialog = this.dialog;
return dialog ? dialog.parameters : "";
},
enumerable: true,
configurable: true
});
Object.defineProperty(DialogComponent.prototype, "tooltip", {
get: function () {
var dialog = this.dialog;
return dialog ? dialog.tooltip() : "";
},
enumerable: true,
configurable: true
});
DialogComponent.prototype.onSubmit = function (right) {
var _this = this;
if (this.dialog) {
forEach(this.parms, function (p, k) {
var newValue = _this.form.value[p.id];
p.setValueFromControl(newValue);
});
this.dialog.doInvoke(right);
}
};
DialogComponent.prototype.createForm = function (dialog) {
var _this = this;
safeUnsubscribe(this.formSub);
safeUnsubscribe(this.createFormSub);
(_a = createForm(dialog, this.formBuilder), this.form = _a.form, this.dialog = _a.dialog, this.parms = _a.parms, this.createFormSub = _a.sub);
this.formSub = this.form.valueChanges.subscribe(function (data) { return _this.onValueChanged(); });
var _a;
};
DialogComponent.prototype.onValueChanged = function () {
if (this.dialog) {
// clear messages if dialog changes
this.dialog.resetMessage();
this.context.clearMessages();
this.context.clearWarnings();
}
};
DialogComponent.prototype.closeExistingDialog = function () {
if (this.dialog) {
this.dialog.doCloseKeepHistory();
this.dialog = null;
}
};
DialogComponent.prototype.getDialog = function () {
// if it's the same dialog just return
var _this = this;
if (this.parent && this.currentDialogId) {
if (this.dialog && this.dialog.id === this.currentDialogId) {
return;
}
var p = this.parent;
var action = null;
var actionViewModel_1 = null;
if (p instanceof MenuViewModel) {
action = p.menuRep.actionMember(this.currentDialogId);
}
if (p instanceof DomainObjectViewModel && p.domainObject.hasActionMember(this.currentDialogId)) {
action = p.domainObject.actionMember(this.currentDialogId);
}
if (p instanceof ListViewModel) {
action = p.actionMember(this.currentDialogId);
actionViewModel_1 = find(p.actions, function (a) { return a.actionRep.actionId() === _this.currentDialogId; }) || null;
}
if (p instanceof CollectionViewModel && p.hasMatchingLocallyContributedAction(this.currentDialogId)) {
action = p.actionMember(this.currentDialogId);
actionViewModel_1 = find(p.actions, function (a) { return a.actionRep.actionId() === _this.currentDialogId; }) || null;
}
if (action) {
this.context.getInvokableAction(action)
.then(function (details) {
// only if we still have a dialog (may have beenn removed while getting invokable action)
if (_this.currentDialogId) {
// must be a change
_this.closeExistingDialog();
var dialogViewModel = _this.viewModelFactory.dialogViewModel(_this.parent.routeData, details, actionViewModel_1, false);
_this.createForm(dialogViewModel);
}
})
.catch(function (reject) { return _this.error.handleError(reject); });
}
else {
this.closeExistingDialog();
}
}
else {
this.closeExistingDialog();
}
};
DialogComponent.prototype.focus = function (parms) {
if (parms && parms.length > 0) {
some(parms.toArray(), function (p) { return p.focus(); });
}
};
DialogComponent.prototype.ngAfterViewInit = function () {
var _this = this;
this.sub = this.parmComponents.changes.subscribe(function (ql) { return _this.focus(ql); });
};
DialogComponent.prototype.ngOnDestroy = function () {
safeUnsubscribe(this.createFormSub);
safeUnsubscribe(this.formSub);
safeUnsubscribe(this.sub);
};
return DialogComponent;
}());
__decorate([
Input(),
__metadata("design:type", Object),
__metadata("design:paramtypes", [Object])
], DialogComponent.prototype, "parent", null);
__decorate([
Input(),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], DialogComponent.prototype, "selectedDialogId", null);
__decorate([
ViewChildren(ParametersComponent),
__metadata("design:type", QueryList)
], DialogComponent.prototype, "parmComponents", void 0);
DialogComponent = __decorate([
Component({
selector: 'nof-dialog',
template: require('./dialog.component.html'),
styles: [require('./dialog.component.css')]
}),
__metadata("design:paramtypes", [ViewModelFactoryService,
UrlManagerService,
ActivatedRoute,
ErrorService,
ContextService,
ConfigService,
FormBuilder])
], DialogComponent);
export { DialogComponent };
//# sourceMappingURL=dialog.component.js.map