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..f1ae9a2d9d82f 100644
--- a/administrator/components/com_categories/models/fields/modal/category.php
+++ b/administrator/components/com_categories/models/fields/modal/category.php
@@ -42,91 +42,63 @@ 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
+ // Load language.
JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR);
// 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,101 +119,150 @@ protected function getInput()
}
}
- if (empty($title))
+ $title = empty($title) ? JText::_('COM_CATEGORIES_SELECT_A_CATEGORY') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
+
+ // The current category display field.
+ $html = '';
+ $html .= '';
+
+ // Select category button.
+ if ($allowSelect)
{
- $title = JText::_('COM_CATEGORIES_SELECT_A_CATEGORY', true);
+ $html .= ''
+ . ' ' . JText::_('JSELECT')
+ . '';
}
- $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
+ // New category button.
+ if ($allowNew)
+ {
+ $html .= ''
+ . ' ' . JText::_('JACTION_CREATE')
+ . '';
+ }
- // The current category display field.
- $html[] = '';
- $html[] = '';
-
- // Select category button
- $html[] = ''
- . ' ' . JText::_('JSELECT')
- . '';
-
- // Edit category button
+ // Edit category button.
if ($allowEdit)
{
- $html[] = ''
. ' ' . JText::_('JACTION_EDIT')
. '';
}
- // Clear category button
+ // Clear category button.
if ($allowClear)
{
- $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' => ''
- . JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '',
- )
- );
-
- // 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' => ''
- . JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . ''
- . ''
- . '',
- )
- );
+ $html .= '';
+
+ // Select category modal.
+ if ($allowSelect)
+ {
+ $html .= JHtml::_(
+ 'bootstrap.renderModal',
+ 'ModalSelect' . $modalId,
+ array(
+ 'title' => $modalTitle,
+ 'url' => $urlSelect,
+ 'height' => '400px',
+ 'width' => '800px',
+ 'bodyHeight' => '70',
+ 'modalWidth' => '80',
+ 'footer' => '' . JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '',
+ )
+ );
+ }
+
+ // 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' => ''
+ . JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . ''
+ . ''
+ . JText::_("JSAVE") . ''
+ . ''
+ . JText::_("JAPPLY") . '',
+ )
+ );
+ }
+
+ // 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' => ''
+ . JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . ''
+ . ''
+ . JText::_("JSAVE") . ''
+ . ''
+ . JText::_("JAPPLY") . '',
+ )
+ );
+ }
// 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..445c1a14250ca 100644
--- a/administrator/components/com_categories/views/category/view.html.php
+++ b/administrator/components/com_categories/views/category/view.html.php
@@ -81,9 +81,25 @@ public function display($tpl = null)
JFactory::getApplication()->input->set('hidemainmenu', true);
if ($this->getLayout() == 'modal')
+ {
+ // 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);
+ }
+ }
+ // If not in associations modal, block the language change if in edit modal, language not All and associations enabled.
+ elseif ($this->item->id && $this->form->getValue('language', null, '*') != '*' && JLanguageAssociations::isEnabled())
{
$this->form->setFieldAttribute('language', 'readonly', 'true');
- $this->form->setFieldAttribute('parent_id', 'readonly', 'true');
}
$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."