From ce35f68584d8cf270c2eacc4b0480a18caa802b1 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 24 Aug 2022 11:20:07 +0300 Subject: [PATCH] quick view middle click --- .../crm/src/views/contact/fields/accounts.js | 32 +++++---- .../fields/link-multiple-with-columns.js | 1 + .../views/fields/link-multiple-with-role.js | 1 + client/src/views/fields/link-multiple.js | 67 +++++++++++++++++++ client/src/views/fields/link-parent.js | 64 ++++++++++++++++++ client/src/views/fields/link.js | 65 ++++++++++++++++++ client/src/views/user/fields/teams.js | 1 + 7 files changed, 214 insertions(+), 17 deletions(-) diff --git a/client/modules/crm/src/views/contact/fields/accounts.js b/client/modules/crm/src/views/contact/fields/accounts.js index bc13875d6c..71ae8646a3 100644 --- a/client/modules/crm/src/views/contact/fields/accounts.js +++ b/client/modules/crm/src/views/contact/fields/accounts.js @@ -30,8 +30,20 @@ define('crm:views/contact/fields/accounts', ['views/fields/link-multiple-with-co return Dep.extend({ - events: { - 'click [data-action="switchPrimary"]': function (e) { + getAttributeList: function () { + var list = Dep.prototype.getAttributeList.call(this); + + list.push('accountId'); + list.push('accountName'); + list.push('title'); + + return list; + }, + + setup: function () { + Dep.prototype.setup.call(this); + + this.events['click [data-action="switchPrimary"]'] = e => { let $target = $(e.currentTarget); let id = $target.data('id'); @@ -47,21 +59,7 @@ define('crm:views/contact/fields/accounts', ['views/fields/link-multiple-with-co this.setPrimaryId(id); } - } - }, - - getAttributeList: function () { - var list = Dep.prototype.getAttributeList.call(this); - - list.push('accountId'); - list.push('accountName'); - list.push('title'); - - return list; - }, - - setup: function () { - Dep.prototype.setup.call(this); + }; this.primaryIdFieldName = 'accountId'; this.primaryNameFieldName = 'accountName'; diff --git a/client/src/views/fields/link-multiple-with-columns.js b/client/src/views/fields/link-multiple-with-columns.js index f15bbbaa30..db7f98610e 100644 --- a/client/src/views/fields/link-multiple-with-columns.js +++ b/client/src/views/fields/link-multiple-with-columns.js @@ -173,6 +173,7 @@ function (Dep, RegExpPattern) { .append( $('') .attr('href', '#' + this.foreignScope + '/view/' + id) + .attr('data-id', id) .text(name) ); diff --git a/client/src/views/fields/link-multiple-with-role.js b/client/src/views/fields/link-multiple-with-role.js index 6b43184704..a998d0f688 100644 --- a/client/src/views/fields/link-multiple-with-role.js +++ b/client/src/views/fields/link-multiple-with-role.js @@ -127,6 +127,7 @@ define('views/fields/link-multiple-with-role', ['views/fields/link-multiple'], f .append( $('') .attr('href', '#' + this.foreignScope + '/view/' + id) + .attr('data-id', id) .text(name) ); diff --git a/client/src/views/fields/link-multiple.js b/client/src/views/fields/link-multiple.js index 2ceae66f4b..dccbb94b47 100644 --- a/client/src/views/fields/link-multiple.js +++ b/client/src/views/fields/link-multiple.js @@ -189,6 +189,38 @@ define('views/fields/link-multiple', ['views/fields/base'], function (Dep) { */ iconHtml: '', + /** + * @inheritDoc + */ + events: { + /** + * @param {JQueryMouseEventObject} e + * @this module:views/fields/link-multiple.Class + */ + 'auxclick a[href]:not([role="button"])': function (e) { + if (!this.isReadMode()) { + return; + } + + let isCombination = e.button === 1 && (e.ctrlKey || e.metaKey); + + if (!isCombination) { + return; + } + + let id = $(e.currentTarget).attr('data-id'); + + if (!id) { + return; + } + + e.preventDefault(); + e.stopPropagation(); + + this.quickView(id); + }, + }, + /** * @inheritDoc */ @@ -664,6 +696,7 @@ define('views/fields/link-multiple', ['views/fields/base'], function (Dep) { let $a = $('') .attr('href', this.getUrl(id)) + .attr('data-id', id) .text(name); if (iconHtml) { @@ -853,5 +886,39 @@ define('views/fields/link-multiple', ['views/fields/base'], function (Dep) { this.searchParams.typeFront || this.searchParams.type || 'anyOf'; }, + + /** + * @protected + * @param {string} id + */ + quickView: function (id) { + let entityType = this.foreignScope; + + if (!this.getAcl().checkScope(entityType, 'read')) { + return; + } + + let viewName = this.getMetadata().get(['clientDefs', entityType, 'modalViews', 'detail']) || + 'views/modals/detail'; + + Espo.Ui.notify(this.translate('loading', 'messages')); + + let options = { + scope: entityType, + 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'); + }); + }); + }, }); }); diff --git a/client/src/views/fields/link-parent.js b/client/src/views/fields/link-parent.js index 6d0619b52d..d9fc498a31 100644 --- a/client/src/views/fields/link-parent.js +++ b/client/src/views/fields/link-parent.js @@ -174,6 +174,32 @@ define('views/fields/link-parent', ['views/fields/base'], function (Dep) { */ initialSearchIsNotIdle: true, + /** + * @inheritDoc + */ + events: { + /** + * @param {JQueryMouseEventObject} e + * @this module:views/fields/link-parent.Class + */ + 'auxclick a[href]:not([role="button"])': function (e) { + if (!this.isReadMode()) { + return; + } + + let isCombination = e.button === 1 && (e.ctrlKey || e.metaKey); + + if (!isCombination) { + return; + } + + e.preventDefault(); + e.stopPropagation(); + + this.quickView(); + }, + }, + data: function () { var nameValue = this.model.get(this.nameName); @@ -684,5 +710,43 @@ define('views/fields/link-parent', ['views/fields/base'], function (Dep) { getSearchType: function () { return this.getSearchParamsData().type || this.searchParams.typeFront; }, + + /** + * @protected + */ + quickView: function () { + let id = this.model.get(this.idName); + let entityType = this.model.get(this.typeName); + + if (!id || !entityType) { + return; + } + + if (!this.getAcl().checkScope(entityType, 'read')) { + return; + } + + let viewName = this.getMetadata().get(['clientDefs', entityType, 'modalViews', 'detail']) || + 'views/modals/detail'; + + Espo.Ui.notify(this.translate('loading', 'messages')); + + let options = { + scope: entityType, + 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'); + }); + }); + }, }); }); diff --git a/client/src/views/fields/link.js b/client/src/views/fields/link.js index db8563b2f6..655ee4e61f 100644 --- a/client/src/views/fields/link.js +++ b/client/src/views/fields/link.js @@ -169,6 +169,32 @@ define('views/fields/link', ['views/fields/base'], function (Dep) { */ mandatorySelectAttributeList: null, + /** + * @inheritDoc + */ + events: { + /** + * @param {JQueryMouseEventObject} e + * @this module:views/fields/link.Class + */ + 'auxclick a[href]:not([role="button"])': function (e) { + if (!this.isReadMode()) { + return; + } + + let isCombination = e.button === 1 && (e.ctrlKey || e.metaKey); + + if (!isCombination) { + return; + } + + e.preventDefault(); + e.stopPropagation(); + + this.quickView(); + }, + }, + /** * @inheritDoc */ @@ -939,5 +965,44 @@ define('views/fields/link', ['views/fields/base'], function (Dep) { this.searchParams.typeFront || this.searchParams.type; }, + + /** + * @protected + */ + quickView: function () { + let id = this.model.get(this.idName); + + if (!id) { + return; + } + + let entityType = this.foreignScope; + + if (!this.getAcl().checkScope(entityType, 'read')) { + return; + } + + let viewName = this.getMetadata().get(['clientDefs', entityType, 'modalViews', 'detail']) || + 'views/modals/detail'; + + Espo.Ui.notify(this.translate('loading', 'messages')); + + let options = { + scope: entityType, + 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'); + }); + }); + }, }); }); diff --git a/client/src/views/user/fields/teams.js b/client/src/views/user/fields/teams.js index 095e188ad2..98014f8308 100644 --- a/client/src/views/user/fields/teams.js +++ b/client/src/views/user/fields/teams.js @@ -104,6 +104,7 @@ define('views/user/fields/teams', ['views/fields/link-multiple-with-role'], func .append( $('') .attr('href', '#' + this.foreignScope + '/view/' + id) + .attr('data-id', id) .text(name) );