From f29be8faf4d5f8cb07937b412b46b50763bca8e0 Mon Sep 17 00:00:00 2001 From: shital Date: Thu, 15 Nov 2018 15:16:13 +0530 Subject: [PATCH] =?UTF-8?q?=20Widget,=20Dashboard=20:=20Require=20?= =?UTF-8?q?=E2=80=98Save=E2=80=99,=20'Save=20&=20New'=20button=20currently?= =?UTF-8?q?=20there=20is=20=E2=80=98save=20&=20close=E2=80=99=20=E2=80=98c?= =?UTF-8?q?ancel=E2=80=99=20button=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../administrator/libraries/widget.php | 2 ++ .../administrator/models/dashboard.php | 2 +- .../views/dashboard/view.html.php | 19 +++++++++++-------- .../administrator/views/widget/view.html.php | 12 ++++++++---- .../com_tjdashboard/site/models/widget.php | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/components/com_tjdashboard/administrator/libraries/widget.php b/src/components/com_tjdashboard/administrator/libraries/widget.php index ba6f8dd9..295525a8 100644 --- a/src/components/com_tjdashboard/administrator/libraries/widget.php +++ b/src/components/com_tjdashboard/administrator/libraries/widget.php @@ -162,6 +162,8 @@ public function save() return false; } + $this->dashboard_widget_id = $table->dashboard_widget_id; + return $result; } diff --git a/src/components/com_tjdashboard/administrator/models/dashboard.php b/src/components/com_tjdashboard/administrator/models/dashboard.php index 0ec17c2a..abf2b506 100644 --- a/src/components/com_tjdashboard/administrator/models/dashboard.php +++ b/src/components/com_tjdashboard/administrator/models/dashboard.php @@ -107,7 +107,7 @@ public function save($data) return false; } - $this->setState('dashboard.dashboard_id', $dashboard->dashboard_id); + $this->setState('dashboard.id', $dashboard->dashboard_id); return true; } diff --git a/src/components/com_tjdashboard/administrator/views/dashboard/view.html.php b/src/components/com_tjdashboard/administrator/views/dashboard/view.html.php index a6aea14b..59882320 100644 --- a/src/components/com_tjdashboard/administrator/views/dashboard/view.html.php +++ b/src/components/com_tjdashboard/administrator/views/dashboard/view.html.php @@ -95,10 +95,13 @@ protected function addToolbar() JLoader::import('administrator.components.com_tjdashboard.helpers.dashboard', JPATH_SITE); $this->tjdashboardHelper = new DashboardHelper; + + // Check permission + $canDo = $this->canDo; $checkedOut = $this->isCheckedOut($userId); + $itemEditable = $this->isEditable($canDo, $userId); // Built the actions for new and existing records. - $canDo = $this->canDo; $layout = JFactory::getApplication()->input->get("layout"); $this->sidebar = JHtmlSidebar::render(); @@ -113,17 +116,17 @@ protected function addToolbar() 'pencil-2 dashboard-add' ); - if ($isNew) + // If not checked out, can save the item. + if (!$checkedOut && $itemEditable) { - JToolbarHelper::save('dashboard.save'); + JToolBarHelper::apply('dashboard.apply'); + JToolBarHelper::save('dashboard.save'); + JToolBarHelper::save2new('dashboard.save2new'); + JToolbarHelper::cancel('dashboard.cancel'); } else { - $itemEditable = $this->isEditable($canDo, $userId); - - // Can't save the record if it's checked out and editable - $this->canSave($checkedOut, $itemEditable); JToolbarHelper::cancel('dashboard.cancel', 'JTOOLBAR_CLOSE'); } } @@ -176,7 +179,7 @@ protected function canSave($checkedOut, $itemEditable) protected function isEditable($canDo, $userId) { // Since it's an existing record, check the edit permission, or fall back to edit own if the owner. - return $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId); + return ($canDo->get('core.create') || $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId)); } /** diff --git a/src/components/com_tjdashboard/administrator/views/widget/view.html.php b/src/components/com_tjdashboard/administrator/views/widget/view.html.php index 4f45cad5..643a03a3 100644 --- a/src/components/com_tjdashboard/administrator/views/widget/view.html.php +++ b/src/components/com_tjdashboard/administrator/views/widget/view.html.php @@ -14,7 +14,7 @@ /** * View to edit * - * @since 1.0.0 + * @since 1.0.0 */ class TjdashboardViewWidget extends JViewLegacy { @@ -91,6 +91,7 @@ protected function addToolbar() // Built the actions for new and existing records. $canDo = $this->canDo; + $itemEditable = $this->isEditable($canDo, $userId); JToolbarHelper::title( JText::_('COM_TJDASHBOARD_PAGE_' . ($checkedOut ? 'VIEW_WIDGET' : ($isNew ? 'ADD_WIDGET' : 'EDIT_WIDGET'))), @@ -98,9 +99,12 @@ protected function addToolbar() ); // For new records, check the create permission. - if ($isNew) + if (!$checkedOut && $itemEditable) { - JToolbarHelper::save('widget.save'); + JToolBarHelper::apply('widget.apply'); + JToolBarHelper::save('widget.save'); + JToolBarHelper::save2new('widget.save2new'); + JToolbarHelper::cancel('widget.cancel'); } else @@ -146,7 +150,7 @@ protected function canSave($checkedOut, $itemEditable) protected function isEditable($canDo, $userId) { // Since it's an existing record, check the edit permission, or fall back to edit own if the owner. - return $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId); + return ($canDo->get('core.create') || $canDo->get('core.edit') || ($canDo->get('core.edit.own') && $this->item->created_by == $userId)); } /** diff --git a/src/components/com_tjdashboard/site/models/widget.php b/src/components/com_tjdashboard/site/models/widget.php index ba004efe..1757d456 100644 --- a/src/components/com_tjdashboard/site/models/widget.php +++ b/src/components/com_tjdashboard/site/models/widget.php @@ -126,7 +126,7 @@ public function save($data) return false; } - $this->setState('widget.dashboard_widget_id', $widget->dashboard_widget_id); + $this->setState('widget.id', $widget->dashboard_widget_id); return true; }