element['extension']) { $extension = (string) $this->element['extension']; } else { $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; // Load language JFactory::getLanguage()->load('com_categories', JPATH_ADMINISTRATOR); // Load the modal behavior script. JHtml::_('behavior.modal', 'a.modal'); // Build the script. $script = array(); // 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;'; if ($allowEdit) { $script[] = ' jQuery("#' . $this->id . '_edit").removeClass("hidden");'; } if ($allowClear) { $script[] = ' jQuery("#' . $this->id . '_clear").removeClass("hidden");'; } $script[] = ' jModalClose();'; $script[] = ' }'; // Clear button script static $scriptClear; 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[] = ' }'; } // Add the script to the document head. JFactory::getDocument()->addScriptDeclaration(implode("\n", $script)); // Setup variables for display. $html = array(); $link = 'index.php?option=com_categories&view=categories&layout=modal&tmpl=component&extension=' . $extension . '&function=jSelectCategory_' . $this->id; if (isset($this->element['language'])) { $link .= '&forcedLanguage=' . $this->element['language']; } if ((int) $this->value > 0) { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('title')) ->from($db->quoteName('#__categories')) ->where($db->quoteName('id') . ' = ' . (int) $this->value); $db->setQuery($query); try { $title = $db->loadResult(); } catch (RuntimeException $e) { JError::raiseWarning(500, $e->getMessage()); } } if (empty($title)) { $title = JText::_('COM_CATEGORIES_SELECT_A_CATEGORY'); } $title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8'); // The active category id field. if (0 == (int) $this->value) { $value = ''; } else { $value = (int) $this->value; } // The current category display field. $html[] = ''; $html[] = ''; $html[] = '' . ' ' . JText::_('JSELECT') . ''; // Edit category button if ($allowEdit) { $html[] = '' . '' . JText::_('JACTION_EDIT') . ''; } // Clear category button if ($allowClear) { $html[] = '' . '' . JText::_('JCLEAR') . ''; } $html[] = ''; // Note: class='required' for client side validation $class = ''; if ($this->required) { $class = ' class="required modal-value"'; } $html[] = ''; return implode("\n", $html); } }