From 23e1855e94d4d5ca90c3635f47a5e19e317913f6 Mon Sep 17 00:00:00 2001 From: Alasdair Campbell Date: Wed, 4 Nov 2015 14:46:37 +0000 Subject: [PATCH] PATCH: Mass link/unlink with Target List --- .../Espo/Resources/i18n/en_US/Global.json | 4 + frontend/client/src/views/record/list.js | 86 ++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/application/Espo/Resources/i18n/en_US/Global.json b/application/Espo/Resources/i18n/en_US/Global.json index 7b7f9ee79c6..2f354c251d9 100644 --- a/application/Espo/Resources/i18n/en_US/Global.json +++ b/application/Espo/Resources/i18n/en_US/Global.json @@ -200,6 +200,8 @@ "removeRecordConfirmation": "Are you sure you want to remove the record?", "unlinkRecordConfirmation": "Are you sure you want to unlink the related record?", "removeSelectedRecordsConfirmation": "Are you sure you want to remove selected records?", + "linkSelectedRecordsConfirmation": "Are you sure you want to link the record(s)?", + "unlinkSelectedRecordsConfirmation": "Are you sure you want to unlink the record(s)?", "massUpdateResult": "{count} records have been updated", "massUpdateResultSingle": "{count} record has been updated", "noRecordsUpdated": "No records were updated", @@ -224,6 +226,8 @@ "remove": "Remove", "merge": "Merge", "massUpdate": "Mass Update", + "massLink": "Link to Target List", + "massUnLink": "Unlink from Target List", "export": "Export" }, "fields": { diff --git a/frontend/client/src/views/record/list.js b/frontend/client/src/views/record/list.js index 69f25dc0858..5731b3cc0b7 100644 --- a/frontend/client/src/views/record/list.js +++ b/frontend/client/src/views/record/list.js @@ -214,7 +214,7 @@ Espo.define('views/record/list', 'view', function (Dep) { showMore: true, - massActionList: ['remove', 'merge', 'massUpdate', 'export'], + massActionList: ['remove', 'merge', 'massUpdate', 'massLink', 'massUnLink', 'export'], checkAllResultMassActionList: ['remove', 'massUpdate', 'export'], @@ -224,6 +224,10 @@ Espo.define('views/record/list', 'view', function (Dep) { massUpdateAction: true, + massLinkAction: false, + + massUnLinkAction: false, + exportAction: true, quickDetailDisabled: false, @@ -498,6 +502,86 @@ Espo.define('views/record/list', 'view', function (Dep) { }.bind(this)); }, + massActionMassLink: function () { + if (!this.getAcl().check(this.scope, 'edit')) { + this.notify('Access denied', 'error'); + return false; + } + + this.notify('Loading...'); + var ids = false; + + var allResultIsChecked = this.allResultIsChecked; + if (!allResultIsChecked) { + ids = this.checkedList; + } + + this.createView('dialog', 'Modals.SelectRecords', { + scope: 'TargetList', + multiple: false, + createButton: true, + filters: null + }, function (dialog) { + dialog.render(); + this.notify(false); + dialog.once('select', function (selectObj) { + if (confirm(this.translate('linkSelectedRecordsConfirmation', 'messages'))) { + $.ajax({ + url: 'TargetList' + '/' + selectObj.id + '/' + this.scope.toLowerCase() + 's', + type: 'POST', + data: JSON.stringify({ ids: ids }), + success: function () { + Espo.Ui.success('Added to list(s)'); + }, + error: function () { + Espo.Ui.warning('Unknown error occurred'); + }, + }); + } + }.bind(this)); + }.bind(this)); + }, + + massActionMassUnLink: function () { + if (!this.getAcl().check(this.scope, 'edit')) { + this.notify('Access denied', 'error'); + return false; + } + + this.notify('Loading...'); + var ids = false; + + var allResultIsChecked = this.allResultIsChecked; + if (!allResultIsChecked) { + ids = this.checkedList; + } + + this.createView('dialog', 'Modals.SelectRecords', { + scope: 'TargetList', + multiple: false, + createButton: true, + filters: null + }, function (dialog) { + dialog.render(); + this.notify(false); + dialog.once('select', function (selectObj) { + if (confirm(this.translate('unlinkSelectedRecordsConfirmation', 'messages'))) { + $.ajax({ + url: 'TargetList' + '/' + selectObj.id + '/' + this.scope.toLowerCase() + 's', + type: 'DELETE', + data: JSON.stringify({ ids: ids }), + success: function () { + Espo.Ui.success('Removed from list(s)'); + }, + error: function () { + Espo.Ui.warning('Unknown error occurred'); + }, + }); + } + }.bind(this)); + }.bind(this)); + }, + massActionExport: function () { if (!this.getConfig().get('exportDisabled') || this.getUser().get('isAdmin')) { this.export();