Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[category modal field] Adds Create Category button and other improvements #11857

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions administrator/components/com_categories/models/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
285 changes: 153 additions & 132 deletions administrator/components/com_categories/models/fields/modal/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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 = '<span class="input-append">';
$html .= '<input class="input-medium" id="' . $this->id . '_name" type="text" value="' . $title . '" disabled="disabled" size="35" />';

// Select category button.
if ($allowSelect)
{
$title = JText::_('COM_CATEGORIES_SELECT_A_CATEGORY', true);
$html .= '<a'
. ' class="btn hasTooltip' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_select"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#ModalSelect' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_CATEGORIES_CHANGE_CATEGORY') . '">'
. '<span class="icon-file"></span> ' . JText::_('JSELECT')
. '</a>';
}

$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
// New category button.
if ($allowNew)
{
$html .= '<a'
. ' class="btn hasTooltip' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_new"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#ModalNew' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_CATEGORIES_NEW_CATEGORY') . '">'
. '<span class="icon-new"></span> ' . JText::_('JACTION_CREATE')
. '</a>';
}

// The current category display field.
$html[] = '<span class="input-append">';
$html[] = '<input class="input-medium" id="' . $this->id . '_name" type="text" value="' . $title . '" disabled="disabled" size="35" />';

// Select category button
$html[] = '<a'
. ' class="btn hasTooltip"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#categorySelect' . $this->id . 'Modal"'
. ' title="' . JHtml::tooltipText('COM_CATEGORIES_CHANGE_CATEGORY') . '">'
. '<span class="icon-file"></span> ' . JText::_('JSELECT')
. '</a>';

// Edit category button
// Edit category button.
if ($allowEdit)
{
$html[] = '<a'
$html .= '<a'
. ' class="btn hasTooltip' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_edit"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#categoryEdit' . $value . 'Modal"'
. ' href="#ModalEdit' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_CATEGORIES_EDIT_CATEGORY') . '">'
. '<span class="icon-edit"></span> ' . JText::_('JACTION_EDIT')
. '</a>';
}

// Clear category button
// Clear category button.
if ($allowClear)
{
$html[] = '<button'
$html .= '<a'
. ' class="btn' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_clear"'
. ' onclick="return jClearCategory(\'' . $this->id . '\')">'
. ' href="#"'
. ' onclick="window.processModalParent(\'' . $this->id . '\'); return false;">'
. '<span class="icon-remove"></span>' . JText::_('JCLEAR')
. '</button>';
. '</a>';
}

$html[] = '</span>';

// 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' => '<a type="button" class="btn" data-dismiss="modal" aria-hidden="true">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</a>',
)
);

// 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' => '<a type="button" class="btn" data-dismiss="modal" aria-hidden="true"'
. ' onclick="jQuery(\'#categoryEdit' . $value . 'Modal iframe\').contents().find(\'#closeBtn\').click();">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</a>'
. '<button type="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="jQuery(\'#categoryEdit' . $value . 'Modal iframe\').contents().find(\'#saveBtn\').click();">'
. JText::_("JSAVE") . '</button>'
. '<button type="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="jQuery(\'#categoryEdit' . $value . 'Modal iframe\').contents().find(\'#applyBtn\').click();">'
. JText::_("JAPPLY") . '</button>',
)
);
$html .= '</span>';

// 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' => '<a role="button" class="btn" data-dismiss="modal" aria-hidden="true">' . JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</a>',
)
);
}

// 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' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'add\', \'category\', \'cancel\', \'item-form\'); return false;">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'add\', \'category\', \'save\', \'item-form\'); return false;">'
. JText::_("JSAVE") . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'add\', \'category\', \'apply\', \'item-form\'); return false;">'
. JText::_("JAPPLY") . '</a>',
)
);
}

// 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' => '<a role="button" class="btn" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'edit\', \'category\', \'cancel\', \'item-form\'); return false;">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</a>'
. '<a role="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'edit\', \'category\', \'save\', \'item-form\'); return false;">'
. JText::_("JSAVE") . '</a>'
. '<a role="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="window.processModalEdit(this, \'' . $this->id . '\', \'edit\', \'category\', \'apply\', \'item-form\'); return false;">'
. JText::_("JAPPLY") . '</a>',
)
);
}

// Note: class='required' for client side validation
$class = $this->required ? ' class="required modal-value"' : '';

$html[] = '<input type="hidden" id="' . $this->id . '_id"' . $class . ' name="' . $this->name . '" value="' . $value . '" />';
$html .= '<input type="hidden" id="' . $this->id . '_id"' . $class . ' data-required="' . (int) $this->required . '" name="' . $this->name . '"'
. '" data-text="' . htmlspecialchars(JText::_('COM_CATEGORIES_SELECT_A_CATEGORY', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />';

return implode("\n", $html);
return $html;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -99,6 +100,7 @@

<?php echo $this->form->getInput('extension'); ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading