record modal refactor

This commit is contained in:
Yuri Kuznetsov
2022-08-24 16:39:59 +03:00
parent 313a2874cd
commit f9e3953f68
6 changed files with 140 additions and 150 deletions
+98
View File
@@ -0,0 +1,98 @@
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM - Open Source CRM application.
* Copyright (C) 2014-2022 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* EspoCRM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EspoCRM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU General Public License version 3.
*
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
/**
* @module helpers/record-modal
*/
define(() => {
/**
* @memberOf module:helpers/record-modal
*/
class Class {
/**
* @param {module:metadata.Class} metadata
* @param {module:acl-manager.Class} acl
*/
constructor(metadata, acl) {
this.metadata = metadata;
this.acl = acl;
}
/**
* @param {module:view.Class} view
* @param {{
* id: string,
* scope: string,
* model?: module:model.Class,
* editDisabled?: boolean,
* rootUrl?: string,
* }} params
* @return {Promise}
*/
showDetail(view, params) {
let id = params.id;
let scope = params.scope;
let model = params.model;
if (!id || !scope) {
console.error("Bad data.");
return Promise.reject();
}
if (!this.acl.checkScope(scope, 'read')) {
return Promise.reject();
}
let viewName = this.metadata.get(['clientDefs', scope, 'modalViews', 'detail']) ||
'views/modals/detail';
Espo.Ui.notify(view.translate('loading', 'messages'));
let options = {
scope: scope,
model: model,
id: id,
quickEditDisabled: params.editDisabled,
rootUrl: params.rootUrl,
};
return view.createView('modal', viewName, options, modalView => {
modalView.render()
.then(() => Espo.Ui.notify(false));
view.listenToOnce(modalView, 'remove', () => {
view.clearView('modal');
});
});
}
}
return Class;
});
@@ -28,8 +28,8 @@
define(
'views/email/fields/from-address-varchar',
['views/fields/base', 'views/email/fields/email-address'],
function (Dep, EmailAddress) {
['views/fields/base', 'views/email/fields/email-address', 'helpers/record-modal'],
function (Dep, EmailAddress, RecordModal) {
return Dep.extend({
@@ -515,43 +515,11 @@ define(
},
quickView: function (data) {
data = data || {};
let helper = new RecordModal(this.getMetadata(), this.getAcl());
let id = data.id;
let scope = data.scope;
if (!id) {
console.error("No id.");
return;
}
if (!scope) {
console.error("No scope.");
return;
}
let viewName = this.getMetadata().get(['clientDefs', scope, 'modalViews', 'detail']) ||
'views/modals/detail';
Espo.Ui.notify(this.translate('loading', 'messages'));
let options = {
scope: scope,
id: id,
};
this.createView('modal', viewName, options, view => {
this.listenToOnce(view, 'after:render', () => {
Espo.Ui.notify(false);
});
view.render();
this.listenToOnce(view, 'remove', () => {
this.clearView('modal');
});
helper.showDetail(this, {
id: data.id,
scope: data.scope,
});
},
});
+4 -23
View File
@@ -26,7 +26,7 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/fields/link-multiple', ['views/fields/base'], function (Dep) {
define('views/fields/link-multiple', ['views/fields/base', 'helpers/record-modal'], function (Dep, RecordModal) {
/**
* A link-multiple field (has-many relation).
@@ -894,30 +894,11 @@ define('views/fields/link-multiple', ['views/fields/base'], function (Dep) {
quickView: function (id) {
let entityType = this.foreignScope;
if (!this.getAcl().checkScope(entityType, 'read')) {
return;
}
let helper = new RecordModal(this.getMetadata(), this.getAcl());
let viewName = this.getMetadata().get(['clientDefs', entityType, 'modalViews', 'detail']) ||
'views/modals/detail';
Espo.Ui.notify(this.translate('loading', 'messages'));
let options = {
scope: entityType,
helper.showDetail(this, {
id: id,
};
this.createView('dialog', viewName, options, view => {
this.listenToOnce(view, 'after:render', () => {
Espo.Ui.notify(false);
});
view.render();
this.listenToOnce(view, 'remove', () => {
this.clearView('dialog');
});
scope: entityType,
});
},
});
+4 -23
View File
@@ -26,7 +26,7 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/fields/link-parent', ['views/fields/base'], function (Dep) {
define('views/fields/link-parent', ['views/fields/base', 'helpers/record-modal'], function (Dep, RecordModal) {
/**
* A link-parent field (belongs-to-parent relation).
@@ -722,30 +722,11 @@ define('views/fields/link-parent', ['views/fields/base'], function (Dep) {
return;
}
if (!this.getAcl().checkScope(entityType, 'read')) {
return;
}
let helper = new RecordModal(this.getMetadata(), this.getAcl());
let viewName = this.getMetadata().get(['clientDefs', entityType, 'modalViews', 'detail']) ||
'views/modals/detail';
Espo.Ui.notify(this.translate('loading', 'messages'));
let options = {
scope: entityType,
helper.showDetail(this, {
id: id,
};
this.createView('dialog', viewName, options, view => {
this.listenToOnce(view, 'after:render', () => {
Espo.Ui.notify(false);
});
view.render();
this.listenToOnce(view, 'remove', () => {
this.clearView('dialog');
});
scope: entityType,
});
},
});
+4 -23
View File
@@ -26,7 +26,7 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/fields/link', ['views/fields/base'], function (Dep) {
define('views/fields/link', ['views/fields/base', 'helpers/record-modal'], function (Dep, RecordModal) {
/**
* A link field (belongs-to relation).
@@ -978,30 +978,11 @@ define('views/fields/link', ['views/fields/base'], function (Dep) {
let entityType = this.foreignScope;
if (!this.getAcl().checkScope(entityType, 'read')) {
return;
}
let helper = new RecordModal(this.getMetadata(), this.getAcl());
let viewName = this.getMetadata().get(['clientDefs', entityType, 'modalViews', 'detail']) ||
'views/modals/detail';
Espo.Ui.notify(this.translate('loading', 'messages'));
let options = {
scope: entityType,
helper.showDetail(this, {
id: id,
};
this.createView('dialog', viewName, options, view => {
this.listenToOnce(view, 'after:render', () => {
Espo.Ui.notify(false);
});
view.render();
this.listenToOnce(view, 'remove', () => {
this.clearView('dialog');
});
scope: entityType,
});
},
});
+24 -43
View File
@@ -26,8 +26,8 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
define('views/record/list', ['view', 'helpers/mass-action', 'helpers/export'],
function (Dep, MassActionHelper, ExportHelper) {
define('views/record/list', ['view', 'helpers/mass-action', 'helpers/export', 'helpers/record-modal'],
function (Dep, MassActionHelper, ExportHelper, RecordModal) {
/**
* A record-list view. Renders and processes list items, actions.
@@ -2879,51 +2879,32 @@ function (Dep, MassActionHelper, ExportHelper) {
return;
}
let viewName = this.getMetadata().get(['clientDefs', scope, 'modalViews', 'detail']) ||
'views/modals/detail';
if (!this.quickDetailDisabled) {
Espo.Ui.notify(this.translate('loading', 'messages'));
let options = {
scope: scope,
model: model,
id: id,
quickEditDisabled: this.quickEditDisabled,
};
if (this.options.keepCurrentRootUrl) {
options.rootUrl = this.getRouter().getCurrentUrl();
}
this.createView('modal', viewName, options, view => {
this.listenToOnce(view, 'after:render', () => {
Espo.Ui.notify(false);
});
view.render();
this.listenToOnce(view, 'remove', () => {
this.clearView('modal');
});
if (!model) {
return;
}
/*this.listenToOnce(view, 'after:edit-cancel', () => {
this.actionQuickView({id: view.model.id, scope: view.model.name});
});*/
this.listenToOnce(view, 'after:save', (model) => {
this.trigger('after:save', model);
});
});
if (this.quickDetailDisabled) {
this.getRouter().navigate('#' + scope + '/view/' + id, {trigger: true});
return;
}
this.getRouter().navigate('#' + scope + '/view/' + id, {trigger: true});
let helper = new RecordModal(this.getMetadata(), this.getAcl());
helper
.showDetail(this, {
id: id,
scope: scope,
model: model,
rootUrl: this.options.keepCurrentRootUrl ?
this.getRouter().getCurrentUrl() : null,
editDisabled: this.quickEditDisabled,
})
.then(view => {
if (!model) {
return;
}
this.listenTo(view, 'after:save', model => {
this.trigger('after:save', model);
});
});
},
actionQuickEdit: function (data) {