diff --git a/application/Espo/Controllers/DashboardTemplate.php b/application/Espo/Controllers/DashboardTemplate.php new file mode 100644 index 0000000000..ada1511969 --- /dev/null +++ b/application/Espo/Controllers/DashboardTemplate.php @@ -0,0 +1,59 @@ +getUser()->isAdmin()) { + throw new Forbidden(); + } + } + + public function postActionDeployToUsers($params, $data) + { + if (empty($data->id)) throw new BadRequest(); + if (empty($data->userIdList)) throw new BadRequest(); + + return $this->getServiceFactory()->create('DashboardTemplate')->deployToUsers($data->id, $data->userIdList); + } + + public function postActionDeployToTeam($params, $data) + { + if (empty($data->id)) throw new BadRequest(); + if (empty($data->teamId)) throw new BadRequest(); + + return $this->getServiceFactory()->create('DashboardTemplate')->deployToTeam($data->id, $data->teamId); + } +} diff --git a/application/Espo/Entities/DashboardTemplate.php b/application/Espo/Entities/DashboardTemplate.php new file mode 100644 index 0000000000..9e6d18765b --- /dev/null +++ b/application/Espo/Entities/DashboardTemplate.php @@ -0,0 +1,35 @@ +getEntityManager()->fetchEntity('DashboardTemplate', $id); + if (!$template) throw new NotFount(); + + foreach ($userIdList as $userId) { + $preferences = $this->getEntityManager()->fetchEntity('Preferences', $userId); + if (!$preferences) continue; + $preferences->set([ + 'dashboardLayout' => $template->get('layout'), + 'dashletsOptions' => $template->get('dashletsOptions'), + ]); + $this->getEntityManager()->saveEntity($preferences); + } + + return true; + } + + public function deployToTeam(string $id, string $teamId) + { + $template = $this->getEntityManager()->fetchEntity('DashboardTemplate', $id); + if (!$template) throw new NotFount(); + + $team = $this->getEntityManager()->fetchEntity('Team', $teamId); + if (!$team) throw new NotFount(); + + $userList = $this->getEntityManager()->getRepository('User')->join(['teams'])->distinct()->where([ + 'teams.id' => $teamId, + ])->find(); + + foreach ($userList as $user) { + $preferences = $this->getEntityManager()->fetchEntity('Preferences', $user->id); + if (!$preferences) continue; + $preferences->set([ + 'dashboardLayout' => $template->get('layout'), + 'dashletsOptions' => $template->get('dashletsOptions'), + ]); + $this->getEntityManager()->saveEntity($preferences); + } + + return true; + } +} diff --git a/client/src/views/dashboard-template/detail.js b/client/src/views/dashboard-template/detail.js new file mode 100644 index 0000000000..ad36a0d7dd --- /dev/null +++ b/client/src/views/dashboard-template/detail.js @@ -0,0 +1,49 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy 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. + ************************************************************************/ + +define('views/dashboard-template/detail', 'views/detail', function (Dep) { + + return Dep.extend({ + + actionDeployToUsers: function () { + this.createView('dialog', 'views/dashboard-template/modals/deploy-to-users', { + model: this.model, + }, function (view) { + view.render(); + }, this); + }, + + actionDeployToTeam: function () { + this.createView('dialog', 'views/dashboard-template/modals/deploy-to-team', { + model: this.model, + }, function (view) { + view.render(); + }, this); + }, + }); +}); diff --git a/client/src/views/dashboard-template/modals/deploy-to-team.js b/client/src/views/dashboard-template/modals/deploy-to-team.js new file mode 100644 index 0000000000..7a4db18138 --- /dev/null +++ b/client/src/views/dashboard-template/modals/deploy-to-team.js @@ -0,0 +1,97 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy 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. + ************************************************************************/ + +define('views/dashboard-template/modals/deploy-to-team', ['views/modal', 'model'], function (Dep, Model) { + + return Dep.extend({ + + className: 'dialog dialog-record', + + templateContent: '
{{{record}}}
', + + setup: function () { + this.buttonList = [ + { + name: 'deploy', + html: this.translate('Deploy for Team', 'labels', 'DashboardTemplate'), + style: 'danger', + }, + { + name: 'cancel', + label: 'Cancel', + }, + ]; + + this.headerHtml = this.getHelper().escapeString(this.model.get('name')); + + this.formModel = new Model(); + this.formModel.name = 'None'; + + this.formModel.setDefs({ + fields: { + 'team': { + type: 'link', + entity: 'Team', + required: true + } + } + }); + + this.createView('record', 'views/record/edit-for-modal', { + scope: 'None', + model: this.formModel, + el: this.getSelector() + ' .record', + detailLayout: [ + { + rows: [ + [ + { + name: 'team', + fullWidth: true, + labelText: this.translate('team', 'links'), + } + ] + ] + } + ], + }); + }, + + actionDeploy: function () { + if (this.getView('record').processFetch()) { + Espo.Ajax.postRequest('DashboardTemplate/action/deployToTeam', { + id: this.model.id, + teamId: this.formModel.get('teamId'), + }).then(function () { + Espo.Ui.success(this.translate('Done')); + this.close(); + }.bind(this)); + } + }, + }); +}); diff --git a/client/src/views/dashboard-template/modals/deploy-to-users.js b/client/src/views/dashboard-template/modals/deploy-to-users.js new file mode 100644 index 0000000000..ad96b0c8d6 --- /dev/null +++ b/client/src/views/dashboard-template/modals/deploy-to-users.js @@ -0,0 +1,98 @@ +/************************************************************************ + * This file is part of EspoCRM. + * + * EspoCRM - Open Source CRM application. + * Copyright (C) 2014-2019 Yuri Kuznetsov, Taras Machyshyn, Oleksiy 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. + ************************************************************************/ + +define('views/dashboard-template/modals/deploy-to-users', ['views/modal', 'model'], function (Dep, Model) { + + return Dep.extend({ + + className: 'dialog dialog-record', + + templateContent: '
{{{record}}}
', + + setup: function () { + this.buttonList = [ + { + name: 'deploy', + html: this.translate('Deploy for Users', 'labels', 'DashboardTemplate'), + style: 'danger', + }, + { + name: 'cancel', + label: 'Cancel', + }, + ]; + + this.headerHtml = this.getHelper().escapeString(this.model.get('name')); + + this.formModel = new Model(); + this.formModel.name = 'None'; + + this.formModel.setDefs({ + fields: { + 'users': { + type: 'linkMultiple', + view: 'views/fields/users', + entity: 'User', + required: true + } + } + }); + + this.createView('record', 'views/record/edit-for-modal', { + scope: 'None', + model: this.formModel, + el: this.getSelector() + ' .record', + detailLayout: [ + { + rows: [ + [ + { + name: 'users', + fullWidth: true, + labelText: this.translate('users', 'links'), + } + ] + ] + } + ], + }); + }, + + actionDeploy: function () { + if (this.getView('record').processFetch()) { + Espo.Ajax.postRequest('DashboardTemplate/action/deployToUsers', { + id: this.model.id, + userIdList: this.formModel.get('usersIds'), + }).then(function () { + Espo.Ui.success(this.translate('Done')); + this.close(); + }.bind(this)); + } + }, + }); +});