From 5ee5bf0efe4488521e5be4bcaeadb0bfd3371da9 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Mon, 29 Aug 2016 21:42:19 +0100 Subject: [PATCH 1/6] modals for categories --- .../com_categories/models/category.php | 2 + .../models/fields/modal/category.php | 277 ++++++++++-------- .../views/category/tmpl/edit.php | 2 + .../views/category/tmpl/modal.php | 1 + .../views/category/view.html.php | 15 +- .../language/en-GB/en-GB.com_categories.ini | 1 + 6 files changed, 168 insertions(+), 130 deletions(-) diff --git a/administrator/components/com_categories/models/category.php b/administrator/components/com_categories/models/category.php index 1fdd3ba12b93e..85a0796327f55 100644 --- a/administrator/components/com_categories/models/category.php +++ b/administrator/components/com_categories/models/category.php @@ -449,6 +449,8 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') $field->addAttribute('label', $language->title); $field->addAttribute('translate_label', 'false'); $field->addAttribute('extension', $extension); + $field->addAttribute('select', 'true'); + $field->addAttribute('new', 'true'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); } diff --git a/administrator/components/com_categories/models/fields/modal/category.php b/administrator/components/com_categories/models/fields/modal/category.php index 034920dabb716..a1b4453f4afa7 100644 --- a/administrator/components/com_categories/models/fields/modal/category.php +++ b/administrator/components/com_categories/models/fields/modal/category.php @@ -42,8 +42,10 @@ protected function getInput() $extension = (string) JFactory::getApplication()->input->get('extension', 'com_content'); } - $allowEdit = ((string) $this->element['edit'] == 'true') ? true : false; - $allowClear = ((string) $this->element['clear'] != 'false') ? true : false; + $allowNew = ((string) $this->element['new'] == 'true'); + $allowEdit = ((string) $this->element['edit'] == 'true'); + $allowClear = ((string) $this->element['clear'] != 'false'); + $allowSelect = ((string) $this->element['select'] != 'false'); // Load language JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR); @@ -51,82 +53,52 @@ protected function getInput() // The active category id field. $value = (int) $this->value > 0 ? (int) $this->value : ''; - // Build the script. - $script = array(); + // Create the modal id. + $modalId = 'Category_' . $this->id; - // Select button script - $script[] = ' function jSelectCategory_' . $this->id . '(id, title, object) {'; - $script[] = ' document.getElementById("' . $this->id . '_id").value = id;'; - $script[] = ' document.getElementById("' . $this->id . '_name").value = title;'; + // Add the modal field script to the document head. + JHtml::_('jquery.framework'); + JHtml::_('script', 'system/modal-fields.js', false, true); - if ($allowEdit) - { - $script[] = ' if (id == "' . (int) $this->value . '") {'; - $script[] = ' jQuery("#' . $this->id . '_edit").removeClass("hidden");'; - $script[] = ' } else {'; - $script[] = ' jQuery("#' . $this->id . '_edit").addClass("hidden");'; - $script[] = ' }'; - } - - if ($allowClear) + // Script to proxy the select modal function to the modal-fields.js file. + if ($allowSelect) { - $script[] = ' jQuery("#' . $this->id . '_clear").removeClass("hidden");'; - } + static $scriptSelect = null; - $script[] = ' jQuery("#categorySelect' . $this->id . 'Modal").modal("hide");'; - $script[] = ' }'; - - // Edit button script - $script[] = ' function jEditCategory_' . $value . '(title) {'; - $script[] = ' document.getElementById("' . $this->id . '_name").value = title;'; - $script[] = ' }'; + if (is_null($scriptSelect)) + { + $scriptSelect = array(); + } - // Clear button script - static $scriptClear; + if (!isset($scriptSelect[$this->id])) + { + JFactory::getDocument()->addScriptDeclaration(" + function jSelectCategory_" . $this->id . "(id, title, object) { + window.processModalSelect('Category', '" . $this->id . "', id, title, '', object); + } + "); - if ($allowClear && !$scriptClear) - { - $scriptClear = true; - - $script[] = ' function jClearCategory(id) {'; - $script[] = ' document.getElementById(id + "_id").value = "";'; - $script[] = ' document.getElementById(id + "_name").value = "' - . htmlspecialchars(JText::_('COM_CATEGORIES_SELECT_A_CATEGORY', true), ENT_COMPAT, 'UTF-8') . '";'; - $script[] = ' jQuery("#"+id + "_clear").addClass("hidden");'; - $script[] = ' if (document.getElementById(id + "_edit")) {'; - $script[] = ' jQuery("#"+id + "_edit").addClass("hidden");'; - $script[] = ' }'; - $script[] = ' return false;'; - $script[] = ' }'; + $scriptSelect[$this->id] = true; + } } - // Add the script to the document head. - JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); - // Setup variables for display. - $html = array(); - - $linkCategories = 'index.php?option=com_categories&view=categories&layout=modal&tmpl=component' - . '&extension=' . $extension - . '&function=jSelectCategory_' . $this->id; - - $linkCategory = 'index.php?option=com_categories&view=category&layout=modal&tmpl=component' - . '&task=category.edit' - . '&function=jEditCategory_' . $value; + $linkCategories = 'index.php?option=com_categories&view=categories&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1' + . '&extension=' . $extension; + $linkCategory = 'index.php?option=com_categories&view=category&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1' + . '&extension=' . $extension; + $modalTitle = JText::_('COM_CATEGORIES_CHANGE_CATEGORY'); if (isset($this->element['language'])) { $linkCategories .= '&forcedLanguage=' . $this->element['language']; $linkCategory .= '&forcedLanguage=' . $this->element['language']; - $modalTitle = JText::_('COM_CATEGORIES_CHANGE_CATEGORY') . ' — ' . $this->element['label']; - } - else - { - $modalTitle = JText::_('COM_CATEGORIES_CHANGE_CATEGORY'); + $modalTitle .= ' — ' . $this->element['label']; } - $urlSelect = $linkCategories . '&' . JSession::getFormToken() . '=1'; - $urlEdit = $linkCategory . '&id=' . $value . '&' . JSession::getFormToken() . '=1'; + $urlSelect = $linkCategories . '&function=jSelectCategory_' . $this->id; + $urlEdit = $linkCategory . '&task=category.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \''; + $urlNew = $linkCategory . '&task=category.add'; if ($value) { @@ -147,36 +119,49 @@ protected function getInput() } } - if (empty($title)) - { - $title = JText::_('COM_CATEGORIES_SELECT_A_CATEGORY', true); - } - - $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); + $title = empty($title) ? JText::_('COM_CATEGORIES_SELECT_A_CATEGORY') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); // The current category display field. - $html[] = ''; - $html[] = ''; + $html = ''; + $html .= ''; // Select category button - $html[] = '' - . ' ' . JText::_('JSELECT') - . ''; - - // Edit category button + if ($allowSelect) + { + $html .= '' + . ' ' . JText::_('JSELECT') + . ''; + } + + // New article button + if ($allowNew) + { + $html .= '' + . ' ' . JText::_('JACTION_CREATE') + . ''; + } + + // Edit article button if ($allowEdit) { - $html[] = '' . ' ' . JText::_('JACTION_EDIT') . ''; @@ -185,63 +170,99 @@ protected function getInput() // Clear category button if ($allowClear) { - $html[] = '' + . ' href="#"' + . ' onclick="window.processModalParent(\'' . $this->id . '\'); return false;">' . '' . JText::_('JCLEAR') - . ''; + . ''; } - $html[] = ''; + $html .= ''; // Select category modal - $html[] = JHtml::_( - 'bootstrap.renderModal', - 'categorySelect' . $this->id . 'Modal', - array( - 'title' => $modalTitle, - 'url' => $urlSelect, - 'height' => '400px', - 'width' => '800px', - 'bodyHeight' => '70', - 'modalWidth' => '80', - 'footer' => '', - ) - ); - - // Edit category modal - $html[] = JHtml::_( - 'bootstrap.renderModal', - 'categoryEdit' . $value . 'Modal', - array( - 'title' => JText::_('COM_CATEGORIES_EDIT_CATEGORY'), - 'backdrop' => 'static', - 'keyboard' => false, - 'closeButton' => false, - 'url' => $urlEdit, - 'height' => '400px', - 'width' => '800px', - 'bodyHeight' => '70', - 'modalWidth' => '80', - 'footer' => '' - . '' - . '', - ) - ); + if ($allowSelect) + { + $html .= JHtml::_( + 'bootstrap.renderModal', + 'ModalSelect' . $modalId, + array( + 'title' => $modalTitle, + 'url' => $urlSelect, + 'height' => '400px', + 'width' => '800px', + 'bodyHeight' => '70', + 'modalWidth' => '80', + 'footer' => '', + ) + ); + } + + // New category modal + if ($allowNew) + { + $html .= JHtml::_( + 'bootstrap.renderModal', + 'ModalNew' . $modalId, + array( + 'title' => JText::_('COM_CATEGORIES_NEW_CATEGORY'), + 'backdrop' => 'static', + 'keyboard' => false, + 'closeButton' => false, + 'url' => $urlNew, + 'height' => '400px', + 'width' => '800px', + 'bodyHeight' => '70', + 'modalWidth' => '80', + 'footer' => '' + . '' + . '', + ) + ); + } + + // Edit category modal. + if ($allowEdit) + { + $html .= JHtml::_( + 'bootstrap.renderModal', + 'ModalEdit' . $modalId, + array( + 'title' => JText::_('COM_CATEGORIES_EDIT_CATEGORY'), + 'backdrop' => 'static', + 'keyboard' => false, + 'closeButton' => false, + 'url' => $urlEdit, + 'height' => '400px', + 'width' => '800px', + 'bodyHeight' => '70', + 'modalWidth' => '80', + 'footer' => '' + . '' + . '', + ) + ); + } // Note: class='required' for client side validation $class = $this->required ? ' class="required modal-value"' : ''; - $html[] = ''; + $html .= ''; - return implode("\n", $html); + return $html; } } diff --git a/administrator/components/com_categories/views/category/tmpl/edit.php b/administrator/components/com_categories/views/category/tmpl/edit.php index f354d814381fc..10eeb20451bc1 100644 --- a/administrator/components/com_categories/views/category/tmpl/edit.php +++ b/administrator/components/com_categories/views/category/tmpl/edit.php @@ -32,6 +32,7 @@ ' . $this->form->getField("description")->save() . ' Joomla.submitform(task, document.getElementById("item-form")); + // @deprecated 4.0 The following js is not needed since __DEPLOY_VERSION__. if (task !== "category.apply") { window.parent.jQuery("#categoryEdit' . $this->item->id . 'Modal").modal("hide"); @@ -99,6 +100,7 @@ form->getInput('extension'); ?> + diff --git a/administrator/components/com_categories/views/category/tmpl/modal.php b/administrator/components/com_categories/views/category/tmpl/modal.php index 28203343ec637..54256456f031c 100644 --- a/administrator/components/com_categories/views/category/tmpl/modal.php +++ b/administrator/components/com_categories/views/category/tmpl/modal.php @@ -11,6 +11,7 @@ JHtml::_('bootstrap.tooltip', '.hasTooltip', array('placement' => 'bottom')); +// @deprecated 4.0 the function parameter, the inline js and the buttons are not needed since __DEPLOY_VERSION__. $function = JFactory::getApplication()->input->getCmd('function', 'jEditCategory_' . (int) $this->item->id); // Function to update input title when changed diff --git a/administrator/components/com_categories/views/category/view.html.php b/administrator/components/com_categories/views/category/view.html.php index 6ca4f8ca972fe..0823a171fdcba 100644 --- a/administrator/components/com_categories/views/category/view.html.php +++ b/administrator/components/com_categories/views/category/view.html.php @@ -82,8 +82,19 @@ public function display($tpl = null) if ($this->getLayout() == 'modal') { - $this->form->setFieldAttribute('language', 'readonly', 'true'); - $this->form->setFieldAttribute('parent_id', 'readonly', 'true'); + // If we are forcing a language in modal (used for associations). + if ($forcedLanguage = JFactory::getApplication()->input->get('forcedLanguage', '', 'cmd')) + { + // Set the language field to the forcedLanguage and disable changing it. + $this->form->setValue('language', null, $forcedLanguage); + $this->form->setFieldAttribute('language', 'readonly', 'true'); + + // Only allow to select categories with All language or with the forced language. + $this->form->setFieldAttribute('parent_id', 'language', '*,' . $forcedLanguage); + + // Only allow to select tags with All language or with the forced language. + $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage); + } } $this->addToolbar(); diff --git a/administrator/language/en-GB/en-GB.com_categories.ini b/administrator/language/en-GB/en-GB.com_categories.ini index 047e1705ff281..2d9d3ece8f95a 100644 --- a/administrator/language/en-GB/en-GB.com_categories.ini +++ b/administrator/language/en-GB/en-GB.com_categories.ini @@ -67,6 +67,7 @@ COM_CATEGORIES_N_ITEMS_TRASHED="%d categories successfully trashed." COM_CATEGORIES_N_ITEMS_TRASHED_1="%d category successfully trashed." COM_CATEGORIES_N_ITEMS_UNPUBLISHED="%d categories successfully unpublished." COM_CATEGORIES_N_ITEMS_UNPUBLISHED_1="%d category successfully unpublished." +COM_CATEGORIES_NEW_CATEGORY="New Category" COM_CATEGORIES_NO_ITEM_SELECTED="Please first make a selection from the list." COM_CATEGORIES_PATH_LABEL="Category Path" COM_CATEGORIES_REBUILD_FAILURE="Failed rebuilding Categories tree data." From a3941d7895a71c9874ddf50092303955dd4903d1 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Mon, 29 Aug 2016 22:10:28 +0100 Subject: [PATCH 2/6] Update category.php --- .../models/fields/modal/category.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/administrator/components/com_categories/models/fields/modal/category.php b/administrator/components/com_categories/models/fields/modal/category.php index a1b4453f4afa7..29bd801d08c28 100644 --- a/administrator/components/com_categories/models/fields/modal/category.php +++ b/administrator/components/com_categories/models/fields/modal/category.php @@ -47,7 +47,7 @@ protected function getInput() $allowClear = ((string) $this->element['clear'] != 'false'); $allowSelect = ((string) $this->element['select'] != 'false'); - // Load language + // Load language. JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR); // The active category id field. @@ -125,7 +125,7 @@ function jSelectCategory_" . $this->id . "(id, title, object) { $html = ''; $html .= ''; - // Select category button + // Select category button. if ($allowSelect) { $html .= 'id . "(id, title, object) { . ''; } - // New article button + // New category button. if ($allowNew) { $html .= 'id . "(id, title, object) { . ''; } - // Edit article button + // Edit category button. if ($allowEdit) { $html .= 'id . "(id, title, object) { . ''; } - // Clear category button + // Clear category button. if ($allowClear) { $html .= 'id . "(id, title, object) { $html .= ''; - // Select category modal + // Select category modal. if ($allowSelect) { $html .= JHtml::_( @@ -199,7 +199,7 @@ function jSelectCategory_" . $this->id . "(id, title, object) { ); } - // New category modal + // New category modal. if ($allowNew) { $html .= JHtml::_( From 0993340949c3c24900bc60795b360052e708d43b Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Mon, 29 Aug 2016 22:36:06 +0100 Subject: [PATCH 3/6] add form --- .../com_categories/models/fields/modal/category.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/administrator/components/com_categories/models/fields/modal/category.php b/administrator/components/com_categories/models/fields/modal/category.php index 29bd801d08c28..84d8ef50a6edf 100644 --- a/administrator/components/com_categories/models/fields/modal/category.php +++ b/administrator/components/com_categories/models/fields/modal/category.php @@ -216,13 +216,13 @@ function jSelectCategory_" . $this->id . "(id, title, object) { 'bodyHeight' => '70', 'modalWidth' => '80', 'footer' => '' . '' . '', ) ); @@ -245,13 +245,13 @@ function jSelectCategory_" . $this->id . "(id, title, object) { 'bodyHeight' => '70', 'modalWidth' => '80', 'footer' => '' . '' . '', ) ); From b0508ef0d1b3f4ef1ea45c719f96eb6f24fb41b2 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Tue, 30 Aug 2016 11:38:51 +0100 Subject: [PATCH 4/6] Update view.html.php --- .../components/com_categories/views/category/view.html.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/administrator/components/com_categories/views/category/view.html.php b/administrator/components/com_categories/views/category/view.html.php index 0823a171fdcba..8fca28bc76d99 100644 --- a/administrator/components/com_categories/views/category/view.html.php +++ b/administrator/components/com_categories/views/category/view.html.php @@ -96,6 +96,11 @@ public function display($tpl = null) $this->form->setFieldAttribute('tags', 'language', '*,' . $forcedLanguage); } } + // If not in associations modal, block the language change if in edit modal, language not All and associations enabled. + else if ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled()) + { + $this->form->setFieldAttribute('language', 'readonly', 'true'); + } $this->addToolbar(); From 5e663cde529caa8d2d7f2605bf1a51a309b4dbd8 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Wed, 31 Aug 2016 00:19:26 +0100 Subject: [PATCH 5/6] Update category.php --- .../com_categories/models/fields/modal/category.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/administrator/components/com_categories/models/fields/modal/category.php b/administrator/components/com_categories/models/fields/modal/category.php index 84d8ef50a6edf..f1ae9a2d9d82f 100644 --- a/administrator/components/com_categories/models/fields/modal/category.php +++ b/administrator/components/com_categories/models/fields/modal/category.php @@ -215,13 +215,13 @@ function jSelectCategory_" . $this->id . "(id, title, object) { 'width' => '800px', 'bodyHeight' => '70', 'modalWidth' => '80', - 'footer' => '' - . '' - . '', ) @@ -244,13 +244,13 @@ function jSelectCategory_" . $this->id . "(id, title, object) { 'width' => '800px', 'bodyHeight' => '70', 'modalWidth' => '80', - 'footer' => '' - . '' - . '', ) From 0ee474fbb941dd197158d5feb3c76017bca9e933 Mon Sep 17 00:00:00 2001 From: andrepereiradasilva Date: Wed, 31 Aug 2016 14:14:43 +0100 Subject: [PATCH 6/6] minor cs --- .../components/com_categories/views/category/view.html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/administrator/components/com_categories/views/category/view.html.php b/administrator/components/com_categories/views/category/view.html.php index 8fca28bc76d99..445c1a14250ca 100644 --- a/administrator/components/com_categories/views/category/view.html.php +++ b/administrator/components/com_categories/views/category/view.html.php @@ -97,7 +97,7 @@ public function display($tpl = null) } } // If not in associations modal, block the language change if in edit modal, language not All and associations enabled. - else if ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled()) + elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled()) { $this->form->setFieldAttribute('language', 'readonly', 'true'); }