[API] Show a custom view in dialog

This commit is contained in:
Victor Woeltjen 2016-07-28 16:16:22 -07:00
parent 14f30b2489
commit fe2ce91d50
2 changed files with 23 additions and 6 deletions

View File

@ -1,19 +1,26 @@
define([], function () { define([
'../../api/objects/object-utils'
], function (objectUtils) {
function ActionDialogDecorator(mct, newViews, actionService) { function ActionDialogDecorator(mct, newViews, actionService) {
this.actionService = actionService; this.actionService = actionService;
this.mct = mct; this.mct = mct;
this.propertiesViews = newViews.filter(function (propertiesView) { this.definitions = newViews.filter(function (newView) {
return propertiesView.region === mct.regions.properties; return newView.region === mct.regions.properties;
}).map(function (newView) {
return newView.factory;
}); });
} }
ActionDialogDecorator.prototype.getActions = function (context) { ActionDialogDecorator.prototype.getActions = function (context) {
var mct = this.mct; var mct = this.mct;
var definitions = this.propertiesViews; var definitions = this.definitions;
return this.actionService.getActions(context).map(function (action) { return this.actionService.getActions(context).map(function (action) {
if (action.dialogService) { if (action.dialogService) {
var domainObject = context.domainObject; var domainObject = objectUtils.toNewFormat(
context.domainObject.getModel(),
objectUtils.parseKeyString(context.domainObject.getId())
);
definitions = definitions.filter(function (definition) { definitions = definitions.filter(function (definition) {
return definition.canView(domainObject); return definition.canView(domainObject);
@ -22,7 +29,10 @@ define([], function () {
if (definitions.length > 0) { if (definitions.length > 0) {
action.dialogService = Object.create(action.dialogService); action.dialogService = Object.create(action.dialogService);
action.dialogService.getUserInput = function (form, value) { action.dialogService.getUserInput = function (form, value) {
mct.dialog(definitions[0].view(domainObject), form.title); mct.dialog(
definitions[0].view(context.domainObject),
form.title
);
return Promise.resolve(value); return Promise.resolve(value);
}; };
} }

View File

@ -221,6 +221,13 @@ define([
canView: todoType.check.bind(todoType) canView: todoType.check.bind(todoType)
}); });
mct.view(mct.regions.properties, {
view: function (domainObject) {
return new TodoToolbarView(domainObject);
},
canView: todoType.check.bind(todoType)
});
return mct; return mct;
}; };
}); });