diff --git a/administrator/components/com_categories/controllers/ajax.json.php b/administrator/components/com_categories/controllers/ajax.json.php new file mode 100644 index 0000000000000..24f69cc569a94 --- /dev/null +++ b/administrator/components/com_categories/controllers/ajax.json.php @@ -0,0 +1,88 @@ +input; + $extension = $input->get('extension'); + + $assocId = $input->getInt('assocId', 0); + + if ($assocId == 0) + { + echo new JResponseJson(null, JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true); + + return; + } + + $excludeLang = $input->get('excludeLang', '', 'STRING'); + + $associations = JLanguageAssociations::getAssociations($extension, '#__categories', 'com_categories.item', (int) $assocId, 'id', 'alias', ''); + + unset($associations[$excludeLang]); + + // Add the title to each of the associated records + JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_categories/tables'); + $categoryTable = JTable::getInstance('Category', 'JTable'); + + foreach ($associations as $lang => $association) + { + $categoryTable->load($association->id); + $associations[$lang]->title = $categoryTable->title; + } + + $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1))); + + if (count($associations) == 0) + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE'); + } + elseif ($countContentLanguages > count($associations) + 2) + { + $tags = implode(', ', array_keys($associations)); + $message = JText::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags); + } + else + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL'); + } + + echo new JResponseJson($associations, $message); + } + } +} diff --git a/administrator/components/com_categories/models/category.php b/administrator/components/com_categories/models/category.php index 458b01eb22740..ae048938ec937 100644 --- a/administrator/components/com_categories/models/category.php +++ b/administrator/components/com_categories/models/category.php @@ -455,6 +455,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') $field->addAttribute('new', 'true'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); + $field->addAttribute('propagate', 'true'); } $form->load($addform, false); diff --git a/administrator/components/com_categories/models/fields/modal/category.php b/administrator/components/com_categories/models/fields/modal/category.php index 0b77986150697..5bef5ec0ae392 100644 --- a/administrator/components/com_categories/models/fields/modal/category.php +++ b/administrator/components/com_categories/models/fields/modal/category.php @@ -9,6 +9,8 @@ defined('JPATH_BASE') or die; +use Joomla\CMS\Language\LanguageHelper; + /** * Supports a modal category picker. * @@ -42,10 +44,13 @@ protected function getInput() $extension = (string) JFactory::getApplication()->input->get('extension', 'com_content'); } - $allowNew = ((string) $this->element['new'] == 'true'); - $allowEdit = ((string) $this->element['edit'] == 'true'); - $allowClear = ((string) $this->element['clear'] != 'false'); - $allowSelect = ((string) $this->element['select'] != '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'); + $allowPropagate = ((string) $this->element['propagate'] == 'true'); + + $languages = LanguageHelper::getContentLanguages(array(0, 1)); // Load language. JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR); @@ -78,6 +83,8 @@ function jSelectCategory_" . $this->id . "(id, title, object) { } "); + JText::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); + $scriptSelect[$this->id] = true; } } @@ -179,6 +186,23 @@ function jSelectCategory_" . $this->id . "(id, title, object) { . ''; } + // Propagate category button + if ($allowPropagate && count($languages) > 2) + { + // Strip off language tag at the end + $tagLength = (int) strlen($this->element['language']); + $callbackFunctionStem = substr("jSelectCategory_" . $this->id, 0, -$tagLength); + + $html .= '' + . '' . JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON') + . ''; + } + $html .= ''; // Select category modal. diff --git a/administrator/components/com_contact/controllers/ajax.json.php b/administrator/components/com_contact/controllers/ajax.json.php new file mode 100644 index 0000000000000..a832a3c7a9fad --- /dev/null +++ b/administrator/components/com_contact/controllers/ajax.json.php @@ -0,0 +1,87 @@ +input; + + $assocId = $input->getInt('assocId', 0); + + if ($assocId == 0) + { + echo new JResponseJson(null, JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true); + + return; + } + + $excludeLang = $input->get('excludeLang', '', 'STRING'); + + $associations = JLanguageAssociations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', (int) $assocId); + + unset($associations[$excludeLang]); + + // Add the title to each of the associated records + JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_contact/tables'); + $contactTable = JTable::getInstance('Contact', 'ContactTable'); + + foreach ($associations as $lang => $association) + { + $contactTable->load($association->id); + $associations[$lang]->title = $contactTable->name; + } + + $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1))); + + if (count($associations) == 0) + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE'); + } + elseif ($countContentLanguages > count($associations) + 2) + { + $tags = implode(', ', array_keys($associations)); + $message = JText::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags); + } + else + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL'); + } + + echo new JResponseJson($associations, $message); + } + } +} diff --git a/administrator/components/com_contact/models/contact.php b/administrator/components/com_contact/models/contact.php index 936591f4979d9..5c2fbfc0058c6 100644 --- a/administrator/components/com_contact/models/contact.php +++ b/administrator/components/com_contact/models/contact.php @@ -560,6 +560,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') $field->addAttribute('new', 'true'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); + $field->addAttribute('propagate', 'true'); } $form->load($addform, false); diff --git a/administrator/components/com_contact/models/fields/modal/contact.php b/administrator/components/com_contact/models/fields/modal/contact.php index e03511d6855c3..a68420170e2c4 100644 --- a/administrator/components/com_contact/models/fields/modal/contact.php +++ b/administrator/components/com_contact/models/fields/modal/contact.php @@ -9,6 +9,8 @@ defined('JPATH_BASE') or die; +use Joomla\CMS\Language\LanguageHelper; + /** * Supports a modal contact picker. * @@ -33,10 +35,13 @@ class JFormFieldModal_Contact extends JFormField */ protected function getInput() { - $allowNew = ((string) $this->element['new'] == 'true'); - $allowEdit = ((string) $this->element['edit'] == 'true'); - $allowClear = ((string) $this->element['clear'] != 'false'); - $allowSelect = ((string) $this->element['select'] != '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'); + $allowPropagate = ((string) $this->element['propagate'] == 'true'); + + $languages = LanguageHelper::getContentLanguages(array(0, 1)); // Load language JFactory::getLanguage()->load('com_contact', JPATH_ADMINISTRATOR); @@ -69,6 +74,8 @@ function jSelectContact_" . $this->id . "(id, title, object) { } "); + JText::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); + $scriptSelect[$this->id] = true; } } @@ -168,6 +175,23 @@ function jSelectContact_" . $this->id . "(id, title, object) { . ''; } + // Propagate contact button + if ($allowPropagate && count($languages) > 2) + { + // Strip off language tag at the end + $tagLength = (int) strlen($this->element['language']); + $callbackFunctionStem = substr("jSelectContact_" . $this->id, 0, -$tagLength); + + $html .= '' + . '' . JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON') + . ''; + } + $html .= ''; // Select contact modal diff --git a/administrator/components/com_content/controllers/ajax.json.php b/administrator/components/com_content/controllers/ajax.json.php new file mode 100644 index 0000000000000..0a6385acdcdb5 --- /dev/null +++ b/administrator/components/com_content/controllers/ajax.json.php @@ -0,0 +1,86 @@ +input; + + $assocId = $input->getInt('assocId', 0); + + if ($assocId == 0) + { + echo new JResponseJson(null, JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true); + + return; + } + + $excludeLang = $input->get('excludeLang', '', 'STRING'); + + $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', (int) $assocId); + + unset($associations[$excludeLang]); + + // Add the title to each of the associated records + $contentTable = JTable::getInstance('Content', 'JTable'); + + foreach ($associations as $lang => $association) + { + $contentTable->load($association->id); + $associations[$lang]->title = $contentTable->title; + } + + $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1))); + + if (count($associations) == 0) + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE'); + } + elseif ($countContentLanguages > count($associations) + 2) + { + $tags = implode(', ', array_keys($associations)); + $message = JText::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags); + } + else + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL'); + } + + echo new JResponseJson($associations, $message); + } + } +} diff --git a/administrator/components/com_content/models/article.php b/administrator/components/com_content/models/article.php index 868182bd67f2e..01ef41113ff76 100644 --- a/administrator/components/com_content/models/article.php +++ b/administrator/components/com_content/models/article.php @@ -913,6 +913,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') $field->addAttribute('new', 'true'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); + $field->addAttribute('propagate', 'true'); } $form->load($addform, false); diff --git a/administrator/components/com_content/models/fields/modal/article.php b/administrator/components/com_content/models/fields/modal/article.php index 28934a3cc7131..e8608a3521bd3 100644 --- a/administrator/components/com_content/models/fields/modal/article.php +++ b/administrator/components/com_content/models/fields/modal/article.php @@ -9,6 +9,8 @@ defined('JPATH_BASE') or die; +use Joomla\CMS\Language\LanguageHelper; + /** * Supports a modal article picker. * @@ -33,10 +35,13 @@ class JFormFieldModal_Article extends JFormField */ protected function getInput() { - $allowNew = ((string) $this->element['new'] == 'true'); - $allowEdit = ((string) $this->element['edit'] == 'true'); - $allowClear = ((string) $this->element['clear'] != 'false'); - $allowSelect = ((string) $this->element['select'] != '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'); + $allowPropagate = ((string) $this->element['propagate'] == 'true'); + + $languages = LanguageHelper::getContentLanguages(array(0, 1)); // Load language JFactory::getLanguage()->load('com_content', JPATH_ADMINISTRATOR); @@ -69,6 +74,8 @@ function jSelectArticle_" . $this->id . "(id, title, catid, object, url, languag } "); + JText::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); + $scriptSelect[$this->id] = true; } } @@ -171,6 +178,23 @@ function jSelectArticle_" . $this->id . "(id, title, catid, object, url, languag . ''; } + // Propagate article button + if ($allowPropagate && count($languages) > 2) + { + // Strip off language tag at the end + $tagLength = (int) strlen($this->element['language']); + $callbackFunctionStem = substr("jSelectArticle_" . $this->id, 0, -$tagLength); + + $html .= '' + . '' . JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON') + . ''; + } + $html .= ''; // Select article modal diff --git a/administrator/components/com_menus/controllers/ajax.json.php b/administrator/components/com_menus/controllers/ajax.json.php new file mode 100644 index 0000000000000..0b5c4d552fd18 --- /dev/null +++ b/administrator/components/com_menus/controllers/ajax.json.php @@ -0,0 +1,88 @@ +input; + $extension = $input->get('extension'); + + $assocId = $input->getInt('assocId', 0); + + if ($assocId == 0) + { + echo new JResponseJson(null, JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true); + + return; + } + + $excludeLang = $input->get('excludeLang', '', 'STRING'); + + $associations = JLanguageAssociations::getAssociations('com_menus', '#__menu', 'com_menus.item', (int) $assocId, 'id', '', ''); + + unset($associations[$excludeLang]); + + // Add the title to each of the associated records + JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_menus/tables'); + $menuTable = JTable::getInstance('Menu', 'JTable', array()); + + foreach ($associations as $lang => $association) + { + $menuTable->load($association->id); + $associations[$lang]->title = $menuTable->title; + } + + $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1))); + + if (count($associations) == 0) + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE'); + } + elseif ($countContentLanguages > count($associations) + 2) + { + $tags = implode(', ', array_keys($associations)); + $message = JText::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags); + } + else + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL'); + } + + echo new JResponseJson($associations, $message); + } + } +} diff --git a/administrator/components/com_menus/models/fields/modal/menu.php b/administrator/components/com_menus/models/fields/modal/menu.php index 58c5ed4d17f22..7f1bc95f95f0f 100644 --- a/administrator/components/com_menus/models/fields/modal/menu.php +++ b/administrator/components/com_menus/models/fields/modal/menu.php @@ -8,6 +8,9 @@ */ defined('JPATH_BASE') or die; + +use Joomla\CMS\Language\LanguageHelper; + JHtml::_('bootstrap.tooltip', '.hasTooltip'); /** @@ -57,6 +60,14 @@ class JFormFieldModal_Menu extends JFormField */ protected $allowEdit = false; + /** + * Determinate, if the propagate button is shown + * + * @var boolean + * @since __DEPLOY_VERSION__ + */ + protected $allowPropagate = false; + /** * Method to get certain otherwise inaccessible properties from the form field object. * @@ -74,6 +85,7 @@ public function __get($name) case 'allowClear': case 'allowNew': case 'allowEdit': + case 'allowPropagate': return $this->$name; } @@ -98,6 +110,7 @@ public function __set($name, $value) case 'allowClear': case 'allowNew': case 'allowEdit': + case 'allowPropagate': $value = (string) $value; $this->$name = !($value === 'false' || $value === 'off' || $value === '0'); break; @@ -131,6 +144,7 @@ public function setup(SimpleXMLElement $element, $value, $group = null) $this->allowClear = ((string) $this->element['clear']) !== 'false'; $this->allowNew = ((string) $this->element['new']) === 'true'; $this->allowEdit = ((string) $this->element['edit']) === 'true'; + $this->allowPropagate = ((string) $this->element['propagate']) === 'true'; } return $return; @@ -146,6 +160,7 @@ public function setup(SimpleXMLElement $element, $value, $group = null) protected function getInput() { $clientId = (int) $this->element['clientid']; + $languages = LanguageHelper::getContentLanguages(array(0, 1)); // Load language JFactory::getLanguage()->load('com_menus', JPATH_ADMINISTRATOR); @@ -179,6 +194,8 @@ function jSelectMenu_" . $this->id . "(id, title, object) { " ); + JText::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); + $scriptSelect[$this->id] = true; } } @@ -293,8 +310,26 @@ function jSelectMenu_" . $this->id . "(id, title, object) { . ''; } + // Propagate menu item button + if ($this->allowPropagate && count($languages) > 2) + { + // Strip off language tag at the end + $tagLength = (int) strlen($this->element['language']); + $callbackFunctionStem = substr("jSelectMenu_" . $this->id, 0, -$tagLength); + + $html .= '' + . '' . JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON') + . ''; + } + $html .= ''; + // Select menu item modal if ($this->allowSelect) { diff --git a/administrator/components/com_menus/models/item.php b/administrator/components/com_menus/models/item.php index 0a131deefce75..98cb5a00c23be 100644 --- a/administrator/components/com_menus/models/item.php +++ b/administrator/components/com_menus/models/item.php @@ -1242,6 +1242,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') $field->addAttribute('new', 'true'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); + $field->addAttribute('propagate', 'true'); $option = $field->addChild('option', 'COM_MENUS_ITEM_FIELD_ASSOCIATION_NO_VALUE'); $option->addAttribute('value', ''); } diff --git a/administrator/components/com_newsfeeds/controllers/ajax.json.php b/administrator/components/com_newsfeeds/controllers/ajax.json.php new file mode 100644 index 0000000000000..f9107ed0fe360 --- /dev/null +++ b/administrator/components/com_newsfeeds/controllers/ajax.json.php @@ -0,0 +1,87 @@ +input; + + $assocId = $input->getInt('assocId', 0); + + if ($assocId == 0) + { + echo new JResponseJson(null, JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', 'assocId'), true); + + return; + } + + $excludeLang = $input->get('excludeLang', '', 'STRING'); + + $associations = JLanguageAssociations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', (int) $assocId); + + unset($associations[$excludeLang]); + + // Add the title to each of the associated records + JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_newsfeeds/tables'); + $newsfeedsTable = JTable::getInstance('Newsfeed', 'NewsfeedsTable'); + + foreach ($associations as $lang => $association) + { + $newsfeedsTable->load($association->id); + $associations[$lang]->title = $newsfeedsTable->name; + } + + $countContentLanguages = count(LanguageHelper::getContentLanguages(array(0, 1))); + + if (count($associations) == 0) + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE'); + } + elseif ($countContentLanguages > count($associations) + 2) + { + $tags = implode(', ', array_keys($associations)); + $message = JText::sprintf('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME', $tags); + } + else + { + $message = JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL'); + } + + echo new JResponseJson($associations, $message); + } + } +} diff --git a/administrator/components/com_newsfeeds/models/fields/modal/newsfeed.php b/administrator/components/com_newsfeeds/models/fields/modal/newsfeed.php index 050c040bbf7bc..a4056f4b613f7 100644 --- a/administrator/components/com_newsfeeds/models/fields/modal/newsfeed.php +++ b/administrator/components/com_newsfeeds/models/fields/modal/newsfeed.php @@ -9,6 +9,8 @@ defined('JPATH_BASE') or die; +use Joomla\CMS\Language\LanguageHelper; + /** * Supports a modal newsfeeds picker. * @@ -33,10 +35,13 @@ class JFormFieldModal_Newsfeed extends JFormField */ protected function getInput() { - $allowNew = ((string) $this->element['new'] == 'true'); - $allowEdit = ((string) $this->element['edit'] == 'true'); - $allowClear = ((string) $this->element['clear'] != 'false'); - $allowSelect = ((string) $this->element['select'] != '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'); + $allowPropagate = ((string) $this->element['propagate'] == 'true'); + + $languages = LanguageHelper::getContentLanguages(array(0, 1)); // Load language JFactory::getLanguage()->load('com_newsfeeds', JPATH_ADMINISTRATOR); @@ -70,6 +75,8 @@ function jSelectNewsfeed_" . $this->id . "(id, title, object) { " ); + JText::script('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'); + $scriptSelect[$this->id] = true; } } @@ -169,6 +176,23 @@ function jSelectNewsfeed_" . $this->id . "(id, title, object) { . ''; } + // Propagate newsfeed button + if ($allowPropagate && count($languages) > 2) + { + // Strip off language tag at the end + $tagLength = (int) strlen($this->element['language']); + $callbackFunctionStem = substr("jSelectNewsfeed_" . $this->id, 0, -$tagLength); + + $html .= '' + . '' . JText::_('JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON') + . ''; + } + $html .= ''; // Select newsfeed modal diff --git a/administrator/components/com_newsfeeds/models/newsfeed.php b/administrator/components/com_newsfeeds/models/newsfeed.php index 97ee58633890d..9e6da29806f46 100644 --- a/administrator/components/com_newsfeeds/models/newsfeed.php +++ b/administrator/components/com_newsfeeds/models/newsfeed.php @@ -536,6 +536,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') $field->addAttribute('new', 'true'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); + $field->addAttribute('propagate', 'true'); } $form->load($addform, false); diff --git a/administrator/language/en-GB/en-GB.ini b/administrator/language/en-GB/en-GB.ini index 2942c6c28820d..1f8647e459f13 100644 --- a/administrator/language/en-GB/en-GB.ini +++ b/administrator/language/en-GB/en-GB.ini @@ -108,7 +108,7 @@ JPUBLISHED="Published" JRECORD_NUMBER="Record Number" JREGISTER="Register" JORDERINGDISABLED="Please sort by order to enable reordering" - +JPROPAGATE="Propagate" JSAVE="Save & Close" JSELECT="Select" JSTATUS="Status" @@ -281,6 +281,12 @@ JGLOBAL_ARTICLE_ORDER_DESC="The order that articles will show in." JGLOBAL_ARTICLE_ORDER_LABEL="Article Order" JGLOBAL_ARTICLES="Articles" JGLOBAL_ASSOC_NOT_POSSIBLE="To define associations, please make sure the item language is not set to 'All'." +JGLOBAL_ASSOCIATIONS_PROPAGATE_BUTTON="Propagate" +JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED="Failed propagating associations. You may have to select or create them manually." +JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_ALL="All existing associations have been set." +JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_NONE="No associations exist to propagate." +JGLOBAL_ASSOCIATIONS_PROPAGATE_MESSAGE_SOME="Associations have been set for: %s" +JGLOBAL_ASSOCIATIONS_PROPAGATE_TIP="Propagates this item's existing associations." JGLOBAL_ASSOCIATIONS_RESET_WARNING="The language has been changed. If you save this item again it will reset the available associations. If this was not intended, close the item." JGLOBAL_AUTH_ACCESS_DENIED="Access Denied" JGLOBAL_AUTH_ACCESS_GRANTED="Access Granted" diff --git a/media/system/js/associations-edit-uncompressed.js b/media/system/js/associations-edit-uncompressed.js index 08257989a4963..6961791ba7f6d 100644 --- a/media/system/js/associations-edit-uncompressed.js +++ b/media/system/js/associations-edit-uncompressed.js @@ -30,6 +30,104 @@ window.showAssociationMessage = function() jQuery('#associations').prepend('
' + Joomla.JText._('JGLOBAL_ASSOC_NOT_POSSIBLE') + '
'); } + /** + * Inject associations into other association fields + * + * This function is called whenever the Ajax request within propagateAssociation() completes successfully. + * Its purpose is to inject the associations which have been returned in the Ajax response into the other + * association fields in the form. + * It does this by invoking the various callback functions of those association fields (i.e. the function which + * gets called whenever the administrator selects an association via the modal), and passing the appropriate + * associated record details. + * + * @param js object result The response from the Ajax request. + * Its structure is that generated by the JResponseJson class, + * with the data field containing the associations + * @param string fieldPrefix The stem of the html ids for the elements comprising the modal field + * @param string callbackFunctionPrefix The name of the callback function which the modal window uses to set the + * selected item as the association, but minus the language tag at the end + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + Joomla.injectAssociations = function(result, callbackFunctionPrefix) + { + var functionName; + + if (result.success) + { + if (result.data.length !== 0) + { + for (var lang in result.data) + { + functionName = callbackFunctionPrefix + lang.replace("-","_"); + + window[functionName](result.data[lang].id, result.data[lang].title, result.data[lang].catid, null, null, lang); + } + } + + if (result.message) + { + Joomla.renderMessages({"notice":[result.message]}); + } + } + else + { + Joomla.renderMessages({"warning":[(Joomla.JText._('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'))]}); + } + } + + /** + * Propagate associations from this field into other association fields + * + * This function is called whenever an administrator populates an association (in the association modal field) + * and then clicks on the Propagate button. + * The purpose of this function is to find what other records (if any) are associated with the one which the + * administrator has selected, and populate the other association fields with these records. (Otherwise, if the + * administrator just clicks on Save without clicking on Propagate, those other associations will be deleted). + * It does this by finding the id of the selected associated record (from a hidden field) and makes an Ajax call + * to the server to find the other associations, also passing up the language of the record currently being edited, + * as it should be excluded. + * Once it has received from the server the other associations it calls injectAssociations to inject them into + * the other association fields within the form. + * + * @param string fieldPrefix The stem of the html ids for the elements comprising the modal field + * @param string callbackFunctionPrefix The name of the callback function which the modal window uses to set the + * selected item as the association, but minus the language tag at the end + * + * @return boolean + * + * @since __DEPLOY_VERSION__ + */ + Joomla.propagateAssociation = function(fieldPrefix, callbackFunctionPrefix) + { + // Find the id of the record which has been set as an assocation + var assocId = jQuery("#" + fieldPrefix + "_id").val(); + + // Find the language of the record being edited + var currentLang = jQuery('#jform_language').find(":selected").val(); + + // Find the token so that it can be sent in the Ajax request as well + var token = Joomla.getOptions('csrf.token', ''); + + // Find the action url associated with the form - we need to add the token to this + var url = jQuery("form[name='adminForm']").attr("action"); + url += '&' + token + '=1'; + + jQuery.ajax( + { + url: url, + data: { task: "ajax.fetchAssociations", format: "json", assocId: assocId, excludeLang: currentLang }, + + success: function(result, status, xhr) { Joomla.injectAssociations(result, callbackFunctionPrefix); }, + + error: function() { Joomla.renderMessages({"warning":[(Joomla.JText._('JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED'))]}); }, + }); + + return false; + } + !(function() { jQuery(document).ready(function($) diff --git a/media/system/js/associations-edit.js b/media/system/js/associations-edit.js index ea17b04783700..a4b70bc16a550 100644 --- a/media/system/js/associations-edit.js +++ b/media/system/js/associations-edit.js @@ -1 +1 @@ -window.hideAssociation=function(o,i){jQuery("#associations .control-group").each(function(){jQuery(this).find(".control-label label").attr("for").replace("_id","")==o+"_associations_"+i.replace("-","_")&&jQuery(this).hide()})},window.showAssociationMessage=function(){jQuery("#associations .control-group").hide(),jQuery("#associations").prepend('
'+Joomla.JText._("JGLOBAL_ASSOC_NOT_POSSIBLE")+"
")},!function(){jQuery(document).ready(function(o){var i=Joomla.getOptions("system.associations.edit"),s=i.formControl||"jform";1==i.hidden?window.showAssociationMessage():window.hideAssociation(s,o("#"+s+"_language").val()),o("#"+s+"_language").on("change",function(){Joomla.removeMessages(),o("#associations-notice").remove();var i=!1;o("#associations .control-group").each(function(){var a=o(this).find(".control-label label").attr("for").replace("_id","").replace("jform_associations_","");o(this).show(),i||""===o("#"+s+"_associations_"+a+"_id").val()||(i=!0),o("#"+s+"_associations_"+a+"_clear").click()}),i&&Joomla.renderMessages({warning:[Joomla.JText._("JGLOBAL_ASSOCIATIONS_RESET_WARNING")]});var a=o(this).val();"*"==a?window.showAssociationMessage():window.hideAssociation(s,a)})})}(window,document,Joomla); +window.hideAssociation=function(o,a){jQuery("#associations .control-group").each(function(){jQuery(this).find(".control-label label").attr("for").replace("_id","")==o+"_associations_"+a.replace("-","_")&&jQuery(this).hide()})},window.showAssociationMessage=function(){jQuery("#associations .control-group").hide(),jQuery("#associations").prepend('
'+Joomla.JText._("JGLOBAL_ASSOC_NOT_POSSIBLE")+"
")},Joomla.injectAssociations=function(o,a){var s;if(o.success){if(0!==o.data.length)for(var e in o.data)s=a+e.replace("-","_"),window[s](o.data[e].id,o.data[e].title,o.data[e].catid,null,null,e);o.message&&Joomla.renderMessages({notice:[o.message]})}else Joomla.renderMessages({warning:[Joomla.JText._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})},Joomla.propagateAssociation=function(o,a){var s=jQuery("#"+o+"_id").val(),e=jQuery("#jform_language").find(":selected").val(),i=Joomla.getOptions("csrf.token",""),n=jQuery("form[name='adminForm']").attr("action");return n+="&"+i+"=1",jQuery.ajax({url:n,data:{task:"ajax.fetchAssociations",format:"json",assocId:s,excludeLang:e},success:function(o,s,e){Joomla.injectAssociations(o,a)},error:function(){Joomla.renderMessages({warning:[Joomla.JText._("JGLOBAL_ASSOCIATIONS_PROPAGATE_FAILED")]})}}),!1},window,document,Joomla,jQuery(document).ready(function(o){var a=Joomla.getOptions("system.associations.edit"),s=a.formControl||"jform";1==a.hidden?window.showAssociationMessage():window.hideAssociation(s,o("#"+s+"_language").val()),o("#"+s+"_language").on("change",function(a){Joomla.removeMessages(),o("#associations-notice").remove();var e=!1;o("#associations .control-group").each(function(){var a=o(this).find(".control-label label").attr("for").replace("_id","").replace("jform_associations_","");o(this).show(),e||""===o("#"+s+"_associations_"+a+"_id").val()||(e=!0),o("#"+s+"_associations_"+a+"_clear").click()}),e&&Joomla.renderMessages({warning:[Joomla.JText._("JGLOBAL_ASSOCIATIONS_RESET_WARNING")]});var i=o(this).val();"*"==i?window.showAssociationMessage():window.hideAssociation(s,i)})}); \ No newline at end of file diff --git a/media/system/js/modal-fields-uncompressed.js b/media/system/js/modal-fields-uncompressed.js index a8e3e8f45fe77..685664979ece0 100644 --- a/media/system/js/modal-fields-uncompressed.js +++ b/media/system/js/modal-fields-uncompressed.js @@ -54,6 +54,10 @@ { jQuery('#' + fieldPrefix + '_clear').removeClass('hidden'); } + if (document.getElementById(fieldPrefix + '_propagate')) + { + jQuery('#' + fieldPrefix + '_propagate').removeClass('hidden'); + } } else { @@ -76,6 +80,10 @@ { jQuery('#' + fieldPrefix + '_clear').addClass('hidden'); } + if (document.getElementById(fieldPrefix + '_propagate')) + { + jQuery('#' + fieldPrefix + '_propagate').addClass('hidden'); + } } if (fieldId.getAttribute('data-required') == '1') @@ -188,4 +196,4 @@ return false; } -}()); +}()); \ No newline at end of file diff --git a/media/system/js/modal-fields.js b/media/system/js/modal-fields.js index 1c916aba32857..7e4efdf5ce0c1 100644 --- a/media/system/js/modal-fields.js +++ b/media/system/js/modal-fields.js @@ -1 +1 @@ -(function(){"use strict";window.processModalParent=function(fieldPrefix,id,title,catid,url,language,object){var fieldId=document.getElementById(fieldPrefix+"_id"),fieldTitle=document.getElementById(fieldPrefix+"_name");id=id||"";title=title||"";catid=catid||"";object=object||"";url=url||"";language=language||"";if(id){fieldId.value=id;fieldTitle.value=title;if(document.getElementById(fieldPrefix+"_select")){jQuery("#"+fieldPrefix+"_select").addClass("hidden")}if(document.getElementById(fieldPrefix+"_new")){jQuery("#"+fieldPrefix+"_new").addClass("hidden")}if(document.getElementById(fieldPrefix+"_edit")){jQuery("#"+fieldPrefix+"_edit").removeClass("hidden")}if(document.getElementById(fieldPrefix+"_clear")){jQuery("#"+fieldPrefix+"_clear").removeClass("hidden")}}else{fieldId.value="";fieldTitle.value=fieldId.getAttribute("data-text");if(document.getElementById(fieldPrefix+"_select")){jQuery("#"+fieldPrefix+"_select").removeClass("hidden")}if(document.getElementById(fieldPrefix+"_new")){jQuery("#"+fieldPrefix+"_new").removeClass("hidden")}if(document.getElementById(fieldPrefix+"_edit")){jQuery("#"+fieldPrefix+"_edit").addClass("hidden")}if(document.getElementById(fieldPrefix+"_clear")){jQuery("#"+fieldPrefix+"_clear").addClass("hidden")}}if(fieldId.getAttribute("data-required")=="1"){document.formvalidator.validate(fieldId);document.formvalidator.validate(fieldTitle)}return false};window.processModalEdit=function(element,fieldPrefix,action,itemType,task,formId,idFieldId,titleFieldId){formId=formId||itemType.toLowerCase()+"-form";idFieldId=idFieldId||"jform_id";titleFieldId=titleFieldId||"jform_title";var modalId=element.parentNode.parentNode.id,submittedTask=task;jQuery("#"+modalId+" iframe").get(0).id="Frame_"+modalId;var iframeDocument=jQuery("#Frame_"+modalId).contents().get(0);if(task==="cancel"){document.getElementById("Frame_"+modalId).contentWindow.Joomla.submitbutton(itemType.toLowerCase()+"."+task);jQuery("#"+modalId).modal("hide")}else{jQuery("#Frame_"+modalId).on("load",function(){iframeDocument=jQuery(this).contents().get(0);if(iframeDocument.getElementById(idFieldId)&&iframeDocument.getElementById(idFieldId).value!="0"){window.processModalParent(fieldPrefix,iframeDocument.getElementById(idFieldId).value,iframeDocument.getElementById(titleFieldId).value);if(task==="save"){window.processModalEdit(element,fieldPrefix,"edit",itemType,"cancel",formId,idFieldId,titleFieldId)}}jQuery("#"+modalId+" iframe").removeClass("hidden")});if(iframeDocument.formvalidator.isValid(iframeDocument.getElementById(formId))){if(task==="save"){submittedTask="apply"}document.getElementById("Frame_"+modalId).contentWindow.Joomla.submitbutton(itemType.toLowerCase()+"."+submittedTask)}}return false};window.processModalSelect=function(itemType,fieldPrefix,id,title,catid,object,url,language){window.processModalParent(fieldPrefix,id,title,catid,url,language,object);jQuery("#ModalSelect"+itemType+"_"+fieldPrefix).modal("hide");return false}})(); \ No newline at end of file +!function(){"use strict";window.processModalParent=function(e,t,d,n,a,o,r){var l=document.getElementById(e+"_id"),m=document.getElementById(e+"_name");return t=t||"",d=d||"",n=n||"",r=r||"",a=a||"",o=o||"",t?(l.value=t,m.value=d,document.getElementById(e+"_select")&&jQuery("#"+e+"_select").addClass("hidden"),document.getElementById(e+"_new")&&jQuery("#"+e+"_new").addClass("hidden"),document.getElementById(e+"_edit")&&jQuery("#"+e+"_edit").removeClass("hidden"),document.getElementById(e+"_clear")&&jQuery("#"+e+"_clear").removeClass("hidden"),document.getElementById(e+"_propagate")&&jQuery("#"+e+"_propagate").removeClass("hidden")):(l.value="",m.value=l.getAttribute("data-text"),document.getElementById(e+"_select")&&jQuery("#"+e+"_select").removeClass("hidden"),document.getElementById(e+"_new")&&jQuery("#"+e+"_new").removeClass("hidden"),document.getElementById(e+"_edit")&&jQuery("#"+e+"_edit").addClass("hidden"),document.getElementById(e+"_clear")&&jQuery("#"+e+"_clear").addClass("hidden"),document.getElementById(e+"_propagate")&&jQuery("#"+e+"_propagate").addClass("hidden")),"1"==l.getAttribute("data-required")&&(document.formvalidator.validate(l),document.formvalidator.validate(m)),!1},window.processModalEdit=function(e,t,d,n,a,o,r,l){o=o||n.toLowerCase()+"-form",r=r||"jform_id",l=l||"jform_title";var m=e.parentNode.parentNode.id,u=a;jQuery("#"+m+" iframe").get(0).id="Frame_"+m;var i=jQuery("#Frame_"+m).contents().get(0);return"cancel"===a?(document.getElementById("Frame_"+m).contentWindow.Joomla.submitbutton(n.toLowerCase()+"."+a),jQuery("#"+m).modal("hide")):(jQuery("#Frame_"+m).on("load",function(){(i=jQuery(this).contents().get(0)).getElementById(r)&&"0"!=i.getElementById(r).value&&(window.processModalParent(t,i.getElementById(r).value,i.getElementById(l).value),"save"===a&&window.processModalEdit(e,t,"edit",n,"cancel",o,r,l)),jQuery("#"+m+" iframe").removeClass("hidden")}),i.formvalidator.isValid(i.getElementById(o))&&("save"===a&&(u="apply"),document.getElementById("Frame_"+m).contentWindow.Joomla.submitbutton(n.toLowerCase()+"."+u))),!1},window.processModalSelect=function(e,t,d,n,a,o,r,l){return window.processModalParent(t,d,n,a,r,l,o),jQuery("#ModalSelect"+e+"_"+t).modal("hide"),!1}}(); \ No newline at end of file