From 90af51b8b9e35f8b4aa42e48975d45276f1972ea Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 19 Aug 2024 10:03:49 +0300 Subject: [PATCH] ref --- .../src/views/record/panels/relationship.js | 5 + client/src/views/scheduled-job/fields/job.js | 74 ++++++----- .../views/scheduled-job/fields/scheduling.js | 122 +++++++++--------- client/src/views/scheduled-job/list.js | 69 +++++----- .../src/views/scheduled-job/record/detail.js | 9 +- client/src/views/scheduled-job/record/list.js | 16 +-- .../views/scheduled-job/record/panels/log.js | 19 ++- 7 files changed, 155 insertions(+), 159 deletions(-) diff --git a/client/src/views/record/panels/relationship.js b/client/src/views/record/panels/relationship.js index 79fd30ad46..0d81051e51 100644 --- a/client/src/views/record/panels/relationship.js +++ b/client/src/views/record/panels/relationship.js @@ -98,6 +98,11 @@ class RelationshipPanelView extends BottomPanelView { */ viewModalView = null + /** + * @protected + */ + listLayoutName + setup() { super.setup(); diff --git a/client/src/views/scheduled-job/fields/job.js b/client/src/views/scheduled-job/fields/job.js index 1977233a3f..e89a983f5f 100644 --- a/client/src/views/scheduled-job/fields/job.js +++ b/client/src/views/scheduled-job/fields/job.js @@ -26,49 +26,47 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/scheduled-job/fields/job', ['views/fields/enum'], function (Dep) { +import EnumFieldView from 'views/fields/enum'; - return Dep.extend({ +export default class extends EnumFieldView { - setup: function () { - Dep.prototype.setup.call(this); + setup() { + super.setup(); - if (this.isEditMode() || this.isDetailMode()) { - this.wait(true); + if (this.isEditMode() || this.isDetailMode()) { + this.wait(true); - Espo.Ajax - .getRequest('Admin/jobs') - .then(data => { - this.params.options = data.filter(item => { - return !this.getMetadata().get(['entityDefs', 'ScheduledJob', 'jobs', item, 'isSystem']); - }); - - this.params.options.unshift(''); - - this.wait(false); + Espo.Ajax.getRequest('Admin/jobs') + .then(data => { + this.params.options = data.filter(item => { + return !this.getMetadata().get(['entityDefs', 'ScheduledJob', 'jobs', item, 'isSystem']); }); - } - if (this.model.isNew()) { - this.on('change', () => { - const job = this.model.get('job'); + this.params.options.unshift(''); - if (job) { - const label = this.getLanguage().translateOption(job, 'job', 'ScheduledJob'); - const scheduling = - this.getMetadata().get(`entityDefs.ScheduledJob.jobSchedulingMap.${job}`) || - '*/10 * * * *'; - - this.model.set('name', label); - this.model.set('scheduling', scheduling); - - return; - } - - this.model.set('name', ''); - this.model.set('scheduling', ''); + this.wait(false); }); - } - }, - }); -}); + } + + if (this.model.isNew()) { + this.on('change', () => { + const job = this.model.get('job'); + + if (job) { + const label = this.getLanguage().translateOption(job, 'job', 'ScheduledJob'); + const scheduling = + this.getMetadata().get(`entityDefs.ScheduledJob.jobSchedulingMap.${job}`) || + '*/10 * * * *'; + + this.model.set('name', label); + this.model.set('scheduling', scheduling); + + return; + } + + this.model.set('name', ''); + this.model.set('scheduling', ''); + }); + } + } +} diff --git a/client/src/views/scheduled-job/fields/scheduling.js b/client/src/views/scheduled-job/fields/scheduling.js index aa717d1a22..07b68be593 100644 --- a/client/src/views/scheduled-job/fields/scheduling.js +++ b/client/src/views/scheduled-job/fields/scheduling.js @@ -26,82 +26,82 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/scheduled-job/fields/scheduling', ['views/fields/varchar'], function (Dep) { +import VarcharFieldView from 'views/fields/varchar'; - return Dep.extend({ +export default class extends VarcharFieldView { - setup: function () { - Dep.prototype.setup.call(this); + setup() { + super.setup(); - if (this.isEditMode() || this.isDetailMode()) { - this.wait( - Espo.loader.requirePromise('lib!cronstrue') - .then(Cronstrue => { - this.Cronstrue = Cronstrue; + if (this.isEditMode() || this.isDetailMode()) { + this.wait( + Espo.loader.requirePromise('lib!cronstrue') + .then(Cronstrue => { + this.Cronstrue = Cronstrue; - this.listenTo(this.model, 'change:' + this.name, () => this.showText()); - }) - ); - } - }, + this.listenTo(this.model, 'change:' + this.name, () => this.showText()); + }) + ); + } + } - afterRender: function () { - Dep.prototype.afterRender.call(this); + afterRender() { + super.afterRender(); - if (this.isEditMode() || this.isDetailMode()) { - let $text = this.$text = $('
'); + if (this.isEditMode() || this.isDetailMode()) { + const $text = this.$text = $('
'); - this.$el.append($text); - this.showText(); - } - }, + this.$el.append($text); + this.showText(); + } + } - showText: function () { - if (!this.$text || !this.$text.length) { - return; - } + /** + * @private + */ + showText() { + let text; + if (!this.$text || !this.$text.length) { + return; + } - if (!this.Cronstrue) { - return; - } + if (!this.Cronstrue) { + return; + } - var exp = this.model.get(this.name); + const exp = this.model.get(this.name); - if (!exp) { - this.$text.text(''); + if (!exp) { + this.$text.text(''); - return; - } + return; + } - if (exp === '* * * * *') { - this.$text.text(this.translate('As often as possible', 'labels', 'ScheduledJob')); + if (exp === '* * * * *') { + this.$text.text(this.translate('As often as possible', 'labels', 'ScheduledJob')); - return; - } + return; + } - var locale = 'en'; - var localeList = Object.keys(this.Cronstrue.default.locales); - var language = this.getLanguage().name; + let locale = 'en'; + const localeList = Object.keys(this.Cronstrue.default.locales); + const language = this.getLanguage().name; - if (~localeList.indexOf(language)) { - locale = language; - } - else if (~localeList.indexOf(language.split('_')[0])) { - locale = language.split('_')[0]; - } + if (~localeList.indexOf(language)) { + locale = language; + } else if (~localeList.indexOf(language.split('_')[0])) { + locale = language.split('_')[0]; + } - try { - var text = this.Cronstrue.toString(exp, { - use24HourTimeFormat: !this.getDateTime().hasMeridian(), - locale: locale, - }); + try { + text = this.Cronstrue.toString(exp, { + use24HourTimeFormat: !this.getDateTime().hasMeridian(), + locale: locale, + }); + } catch (e) { + text = this.translate('Not valid'); + } - } - catch (e) { - text = this.translate('Not valid'); - } - - this.$text.text(text); - }, - }); -}); + this.$text.text(text); + } +} diff --git a/client/src/views/scheduled-job/list.js b/client/src/views/scheduled-job/list.js index b408282025..d94e2f08e8 100644 --- a/client/src/views/scheduled-job/list.js +++ b/client/src/views/scheduled-job/list.js @@ -26,44 +26,43 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/scheduled-job/list', ['views/list'], function (Dep) { +import ListView from 'views/list'; - return Dep.extend({ +export default class extends ListView { - searchPanel: false, + searchPanel = false - setup: function () { - Dep.prototype.setup.call(this); + setup() { + super.setup(); - this.menu.buttons.push({ - link: '#Admin/jobs', - text: this.translate('Jobs', 'labels', 'Admin'), + this.addMenuItem('buttons', { + link: '#Admin/jobs', + text: this.translate('Jobs', 'labels', 'Admin'), + }); + + this.createView('search', 'views/base', { + fullSelector: '#main > .search-container', + template: 'scheduled-job/cronjob', + }); + } + + afterRender() { + super.afterRender(); + + Espo.Ajax + .getRequest('Admin/action/cronMessage') + .then(data => { + this.$el.find('.cronjob .message').html(data.message); + this.$el.find('.cronjob .command').html('' + data.command + ''); }); + } - this.createView('search', 'views/base', { - fullSelector: '#main > .search-container', - template: 'scheduled-job/cronjob', - }); - }, - - afterRender: function () { - Dep.prototype.afterRender.call(this); - - Espo.Ajax - .getRequest('Admin/action/cronMessage') - .then(data => { - this.$el.find('.cronjob .message').html(data.message); - this.$el.find('.cronjob .command').html('' + data.command + ''); - }); - }, - - getHeader: function () { - return this.buildHeaderHtml([ - $('') - .attr('href', '#Admin') - .text(this.translate('Administration', 'labels', 'Admin')), - this.getLanguage().translate(this.scope, 'scopeNamesPlural') - ]); - }, - }); -}); + getHeader() { + return this.buildHeaderHtml([ + $('') + .attr('href', '#Admin') + .text(this.translate('Administration', 'labels', 'Admin')), + this.getLanguage().translate(this.scope, 'scopeNamesPlural') + ]); + } +} diff --git a/client/src/views/scheduled-job/record/detail.js b/client/src/views/scheduled-job/record/detail.js index d612502f44..55e05fb74f 100644 --- a/client/src/views/scheduled-job/record/detail.js +++ b/client/src/views/scheduled-job/record/detail.js @@ -26,10 +26,9 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/scheduled-job/record/detail', ['views/record/detail'], function (Dep) { +import DetailRecordView from 'views/record/detail'; - return Dep.extend({ +export default class extends DetailRecordView { - duplicateAction: false, - }); -}); + duplicateAction = false +} diff --git a/client/src/views/scheduled-job/record/list.js b/client/src/views/scheduled-job/record/list.js index 59bb60d9a5..3d9886ce11 100644 --- a/client/src/views/scheduled-job/record/list.js +++ b/client/src/views/scheduled-job/record/list.js @@ -26,15 +26,11 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/scheduled-job/record/list', ['views/record/list'], function (Dep) { +import ListRecordView from 'views/record/list'; - return Dep.extend({ +export default class extends ListRecordView { - quickDetailDisabled: true, - - quickEditDisabled: true, - - massActionList: ['remove', 'massUpdate'], - - }); -}); + quickDetailDisabled = true + quickEditDisabled = true + massActionList = ['remove', 'massUpdate'] +} diff --git a/client/src/views/scheduled-job/record/panels/log.js b/client/src/views/scheduled-job/record/panels/log.js index 9640d17653..ae3303ddc2 100644 --- a/client/src/views/scheduled-job/record/panels/log.js +++ b/client/src/views/scheduled-job/record/panels/log.js @@ -26,16 +26,15 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -define('views/scheduled-job/record/panels/log', ['views/record/panels/relationship'], function (Dep) { +import RelationshipPanelView from 'views/record/panels/relationship'; - return Dep.extend({ +export default class extends RelationshipPanelView { - setupListLayout: function () { - var jobWithTargetList = this.getMetadata().get(['clientDefs', 'ScheduledJob', 'jobWithTargetList']) || []; + setupListLayout() { + const jobWithTargetList = this.getMetadata().get(['clientDefs', 'ScheduledJob', 'jobWithTargetList']) || []; - if (~jobWithTargetList.indexOf(this.model.get('job'))) { - this.listLayoutName = 'listSmallWithTarget' - } - }, - }); -}); + if (~jobWithTargetList.indexOf(this.model.get('job'))) { + this.listLayoutName = 'listSmallWithTarget' + } + } +}