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

modals for menus (3.7x branch) #74

Closed
wants to merge 16 commits into from
Closed
308 changes: 148 additions & 160 deletions administrator/components/com_menus/models/fields/modal/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,111 +34,61 @@ class JFormFieldModal_Menu extends JFormField
*/
protected function getInput()
{
$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_menus', JPATH_ADMINISTRATOR);

// The active article id field.
$value = (int) $this->value > 0 ? (int) $this->value : '';

// Build the script.
$script = array();
// Create the modal id.
$modalId = 'Item_' . $this->id;

// Select button script
$script[] = ' function jSelectMenu_' . $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 == "' . $value . '") {';
$script[] = ' jQuery("#' . $this->id . '_edit").removeClass("hidden");';
$script[] = ' } else {';
$script[] = ' jQuery("#' . $this->id . '_edit").addClass("hidden");';
$script[] = ' }';
}

if ($allowClear)
{
$script[] = ' jQuery("#' . $this->id . '_clear").removeClass("hidden");';
}

$script[] = ' jQuery("#menuSelect' . $this->id . 'Modal").modal("hide");';

if ($this->required)
{
$script[] = ' document.formvalidator.validate(document.getElementById("' . $this->id . '_id"));';
$script[] = ' document.formvalidator.validate(document.getElementById("' . $this->id . '_name"));';
}

$script[] = ' }';

// Edit button script
$script[] = ' function jEditMenu_' . $value . '(title) {';
$script[] = ' document.getElementById("' . $this->id . '_name").value = title;';
$script[] = ' }';

// Clear button script
static $scriptClear;

if ($allowClear && !$scriptClear)
// Script to proxy the select modal function to the modal-fields.js file.
if ($allowSelect)
{
$scriptClear = true;
static $scriptSelect = null;

if (isset($this->element['language']))
{
$clearField = JText::_('COM_MENUS_SELECT_A_MENUITEM', true);
}
elseif ((string) $this->element->option['value'] == '')
if (is_null($scriptSelect))
{
$clearField = JText::_($this->element->option, true);
}
else
{
$clearField = JText::_('JDEFAULT', true);
$scriptSelect = array();
}

$clearField = htmlspecialchars($clearField, ENT_QUOTES, 'UTF-8');
if (!isset($scriptSelect[$this->id]))
{
JFactory::getDocument()->addScriptDeclaration("
function jSelectMenu_" . $this->id . "(id, title, object) {
window.processModalSelect('Item', '" . $this->id . "', id, title, '', object);
}
");

$script[] = ' function jClearMenu(id) {';
$script[] = ' document.getElementById(id + "_id").value = "";';
$script[] = ' document.getElementById(id + "_name").value = "' . $clearField . '";';
$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();

$linkItems = 'index.php?option=com_menus&view=items&layout=modal&tmpl=component'
. '&function=jSelectMenu_' . $this->id;

$linkItem = 'index.php?option=com_menus&view=item&layout=modal&tmpl=component'
. '&task=item.edit'
. '&function=jEditMenu_' . $value;
$linkItems = 'index.php?option=com_menus&view=items&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
$linkItem = 'index.php?option=com_menus&view=item&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
$modalTitle = JText::_('COM_MENUS_CHANGE_MENUITEM');

if (isset($this->element['language']))
{
$linkItems .= '&forcedLanguage=' . $this->element['language'];
$linkItem .= '&forcedLanguage=' . $this->element['language'];
$modalTitle = JText::_('COM_MENUS_CHANGE_MENUITEM') . ' — ' . $this->element['label'];
}
else
{
$modalTitle = JText::_('COM_MENUS_CHANGE_MENUITEM');
$linkItems .= '&forcedLanguage=' . $this->element['language'];
$linkItem .= '&forcedLanguage=' . $this->element['language'];
$modalTitle .= ' — ' . $this->element['label'];
}

$urlSelect = $linkItems . '&' . JSession::getFormToken() . '=1';
$urlEdit = $linkItem . '&id=' . $value . '&' . JSession::getFormToken() . '=1';
$urlSelect = $linkItems . '&function=jSelectMenu_' . $this->id;
$urlEdit = $linkItem . '&task=item.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \'';
$urlNew = $linkItem . '&task=item.add';

if ($value)
{
Expand All @@ -160,113 +110,151 @@ protected function getInput()
}
}

if (empty($title))
{
if (isset($this->element['language']))
{
$title = JText::_('COM_MENUS_SELECT_A_MENUITEM', true);
}
elseif ((string) $this->element->option['value'] == '')
{
$title = JText::_($this->element->option, true);
}
else
{
$title = JText::_('JDEFAULT');
}
}

$title = htmlspecialchars($title, ENT_QUOTES, 'UTF-8');
$title = empty($title) ? JText::_('COM_MENUS_SELECT_A_MENUITEM') : htmlspecialchars($title, ENT_QUOTES, 'UTF-8');

// The current menuitem display field.
$html[] = '<span class="input-append">';
$html[] = '<input class="input-medium" id="' . $this->id . '_name" type="text" value="' . $title . '" disabled="disabled" size="35" />';
// The current menu item 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 menu item button
$html[] = '<a'
. ' class="btn hasTooltip"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#menuSelect' . $this->id . 'Modal"'
. ' title="' . JHtml::tooltipText('COM_MENUS_CHANGE_MENUITEM') . '">'
. '<span class="icon-file"></span> ' . JText::_('JSELECT')
. '</a>';
if ($allowSelect)
{
$html .= '<a'
. ' class="btn hasTooltip' . ($value ? ' hidden' : '') . '"'
. ' id="' . $this->id . '_select"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#ModalSelect' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_MENUS_CHANGE_MENUITEM') . '">'
. '<span class="icon-file"></span> ' . JText::_('JSELECT')
. '</a>';
}

// Edit menuitem button
// New menu item 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_MENUS_NEW_MENUITEM') . '">'
. '<span class="icon-new"></span> ' . JText::_('JACTION_CREATE')
. '</a>';
}

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

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

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

// Select menuitem modal
$html[] = JHtml::_(
'bootstrap.renderModal',
'menuSelect' . $this->id . 'Modal',
array(
'title' => $modalTitle,
'url' => $urlSelect,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<button type="button" class="btn" data-dismiss="modal" aria-hidden="true">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</button>',
)
);
// Select menu item 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>',
)
);
}

// Edit menuitem modal
$html[] = JHtml::_(
'bootstrap.renderModal',
'menuEdit' . $value . 'Modal',
array(
'title' => JText::_('COM_MENUS_EDIT_MENUITEM'),
'backdrop' => 'static',
'keyboard' => false,
'closeButton' => false,
'url' => $urlEdit,
'height' => '400px',
'width' => '800px',
'bodyHeight' => '70',
'modalWidth' => '80',
'footer' => '<button type="button" class="btn" data-dismiss="modal" aria-hidden="true"'
. ' onclick="jQuery(\'#menuEdit' . $value . 'Modal iframe\').contents().find(\'#closeBtn\').click();">'
. JText::_("JLIB_HTML_BEHAVIOR_CLOSE") . '</button>'
. '<button type="button" class="btn btn-primary" aria-hidden="true"'
. ' onclick="jQuery(\'#menuEdit' . $value . 'Modal iframe\').contents().find(\'#saveBtn\').click();">'
. JText::_("JSAVE") . '</button>'
. '<button type="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="jQuery(\'#menuEdit' . $value . 'Modal iframe\').contents().find(\'#applyBtn\').click();">'
. JText::_("JAPPLY") . '</button>',
)
);
// New menu item modal
if ($allowNew)
{
$html .= JHtml::_(
'bootstrap.renderModal',
'ModalNew' . $modalId,
array(
'title' => JText::_('COM_MENUS_NEW_MENUITEM'),
'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\', \'item\', \'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\', \'item\', \'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\', \'item\', \'apply\', \'item-form\'); return false;">'
. JText::_("JAPPLY") . '</a>',
)
);
}

// Edit menu item modal
if ($allowEdit)
{
$html .= JHtml::_(
'bootstrap.renderModal',
'ModalEdit' . $modalId,
array(
'title' => JText::_('COM_MENUS_EDIT_MENUITEM'),
'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\', \'item\', \'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\', \'item\', \'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\', \'item\', \'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_MENUS_SELECT_A_MENUITEM', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />';

return implode("\n", $html);
return $html;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
description="COM_MENUS_ITEM_FIELD_ALIAS_MENU_DESC"
label="COM_MENUS_ITEM_FIELD_ALIAS_MENU_LABEL"
required="true"
select="true"
new="true"
edit="true"
clear="false"
clear="true"
/>
</fieldset>

Expand Down
2 changes: 2 additions & 0 deletions administrator/components/com_menus/models/item.php
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,8 @@ protected function preprocessForm(JForm $form, $data, $group = 'content')
$field->addAttribute('language', $tag);
$field->addAttribute('label', $language->title);
$field->addAttribute('translate_label', 'false');
$field->addAttribute('select', 'true');
$field->addAttribute('new', 'true');
$field->addAttribute('edit', 'true');
$field->addAttribute('clear', 'true');
$option = $field->addChild('option', 'COM_MENUS_ITEM_FIELD_ASSOCIATION_NO_VALUE');
Expand Down
Loading