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

Improvements to article modals (with Create Article button) #11830

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4ff484f
first commit
andrepereiradasilva Aug 28, 2016
4e3efa5
allow redirect with forcedLanguage
andrepereiradasilva Aug 28, 2016
6b6bf41
add forced languages to edit
andrepereiradasilva Aug 28, 2016
3ba901f
force language in view
andrepereiradasilva Aug 28, 2016
c2bc4d1
improve js
andrepereiradasilva Aug 28, 2016
729116d
tos article modal
andrepereiradasilva Aug 28, 2016
a68a7c8
Update article.php
andrepereiradasilva Aug 29, 2016
26370b8
Update article.php
andrepereiradasilva Aug 29, 2016
5850fb0
add deprecated message
andrepereiradasilva Aug 29, 2016
28d273c
add deprecated message
andrepereiradasilva Aug 29, 2016
6caec48
cs and minor changes
andrepereiradasilva Aug 29, 2016
f8272b9
ups
andrepereiradasilva Aug 29, 2016
6d063bc
button to a
andrepereiradasilva Aug 29, 2016
1e85cfd
Update modal-fields.js
andrepereiradasilva Aug 29, 2016
3d33b39
apply, not add
andrepereiradasilva Aug 29, 2016
f34796f
solve create issue
andrepereiradasilva Aug 29, 2016
782b331
hidden ...
andrepereiradasilva Aug 29, 2016
b976a41
an edit
andrepereiradasilva Aug 29, 2016
4b415ea
Merge branch 'staging' into new-article
andrepereiradasilva Aug 29, 2016
d837ffb
we need the forcedLanguage
andrepereiradasilva Aug 29, 2016
d2ff4ad
more improvements
andrepereiradasilva Aug 29, 2016
3c2e211
don't hide the button on edit
andrepereiradasilva Aug 29, 2016
94ecbcd
more improvements
andrepereiradasilva Aug 29, 2016
e7707f5
correct setValue
andrepereiradasilva Aug 29, 2016
01829b2
add js uncompressed version
andrepereiradasilva Aug 29, 2016
131e7a9
add js compressed version
andrepereiradasilva Aug 29, 2016
2f70a4f
cs: remove extra line
andrepereiradasilva Aug 29, 2016
2f7d5af
allow to filter categoryedit field by several languages
andrepereiradasilva Aug 29, 2016
77ea888
Update view.html.php
andrepereiradasilva Aug 29, 2016
325950e
allow to filter tags by several languages
andrepereiradasilva Aug 29, 2016
2c1f53d
do the same for tags
andrepereiradasilva Aug 29, 2016
00efe08
dawn the copy paste ...
andrepereiradasilva Aug 29, 2016
1a91ffe
grrr... tags not tag
andrepereiradasilva Aug 29, 2016
abd260a
improve js - more flexibility
andrepereiradasilva Aug 29, 2016
859a67d
minified
andrepereiradasilva Aug 29, 2016
c5c65ce
flexible form id
andrepereiradasilva Aug 29, 2016
32c510c
Merge remote-tracking branch 'refs/remotes/joomla/staging' into new-a…
andrepereiradasilva Aug 29, 2016
f38d89d
Update view.html.php
andrepereiradasilva Aug 30, 2016
b87df6d
cs ...
andrepereiradasilva Aug 30, 2016
344b626
direct save and close on create 1
andrepereiradasilva Aug 30, 2016
440c78a
direct save and close on create 2
andrepereiradasilva Aug 30, 2016
0d7c8ac
direct save and close on create final
andrepereiradasilva Aug 30, 2016
10fb5f4
Update modal-fields.js
andrepereiradasilva Aug 30, 2016
204d268
Update modal-fields-uncompressed.js
andrepereiradasilva Aug 30, 2016
17b958d
cleanup: remove now unneded custom button css classes
andrepereiradasilva Aug 30, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -161,7 +161,15 @@ protected function getOptions()
// Filter language
if (!empty($this->element['language']))
{
$subQuery->where('language = ' . $db->quote($this->element['language']));
if (strpos($this->element['language'], ',') !== false)
{
$language = implode(',', $db->quote(explode(',', $this->element['language'])));
}
else
{
$language = $db->quote($this->element['language']);
}
$subQuery->where($db->quoteName('language') . ' IN (' . $language . ')');
}

// Filter on the published state
Expand Down
2 changes: 2 additions & 0 deletions administrator/components/com_content/models/article.php
Expand Up @@ -765,6 +765,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');
}
Expand Down
266 changes: 141 additions & 125 deletions administrator/components/com_content/models/fields/modal/article.php
Expand Up @@ -33,83 +33,49 @@ class JFormFieldModal_Article 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_content', 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 = 'Article_' . $this->id;

// Select button script
$script[] = ' function jSelectArticle_' . $this->id . '(id, title, catid, 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 to proxy the select modal function to the modal-fields.js file.
if ($allowSelect)
{
$script[] = ' jQuery("#' . $this->id . '_clear").removeClass("hidden");';
}

$script[] = ' jQuery("#articleSelect' . $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[] = ' }';
static $scriptSelect = null;

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

// Clear button script
static $scriptClear;
if (is_null($scriptSelect))
{
$scriptSelect = array();
}

if ($allowClear && !$scriptClear)
{
$scriptClear = true;
if (!isset($scriptSelect[$this->id]))
{
JFactory::getDocument()->addScriptDeclaration("
function jSelectArticle_" . $this->id . "(id, title, catid, object, url, language) {
window.processModalSelect('Article', '" . $this->id . "', id, title, catid, object, url, language);
}
");

$script[] = ' function jClearArticle(id) {';
$script[] = ' document.getElementById(id + "_id").value = "";';
$script[] = ' document.getElementById(id + "_name").value = "' .
htmlspecialchars(JText::_('COM_CONTENT_SELECT_AN_ARTICLE', 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();

$linkArticles = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component'
. '&function=jSelectArticle_' . $this->id;

$linkArticle = 'index.php?option=com_content&view=article&layout=modal&tmpl=component'
. '&task=article.edit'
. '&function=jEditArticle_' . $value;
$linkArticles = 'index.php?option=com_content&view=articles&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';
$linkArticle = 'index.php?option=com_content&view=article&layout=modal&tmpl=component&' . JSession::getFormToken() . '=1';

if (isset($this->element['language']))
{
Expand All @@ -122,8 +88,9 @@ protected function getInput()
$modalTitle = JText::_('COM_CONTENT_CHANGE_ARTICLE');
}

$urlSelect = $linkArticles . '&' . JSession::getFormToken() . '=1';
$urlEdit = $linkArticle . '&id=' . $value . '&' . JSession::getFormToken() . '=1';
$urlSelect = $linkArticles . '&function=jSelectArticle_' . $this->id;
$urlEdit = $linkArticle . '&task=article.edit&id=\' + document.getElementById("' . $this->id . '_id").value + \'';
$urlNew = $linkArticle . '&task=article.add';

if ($value)
{
Expand All @@ -144,36 +111,49 @@ protected function getInput()
}
}

if (empty($title))
{
$title = JText::_('COM_CONTENT_SELECT_AN_ARTICLE');
}

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

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

// Select article button
$html[] = '<a'
. ' class="btn hasTooltip"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#articleSelect' . $this->id . 'Modal"'
. ' title="' . JHtml::tooltipText('COM_CONTENT_CHANGE_ARTICLE') . '">'
. '<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_CONTENT_CHANGE_ARTICLE') . '">'
. '<span class="icon-file"></span> ' . JText::_('JSELECT')
. '</a>';
}

// New article 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_CONTENT_NEW_ARTICLE') . '">'
. '<span class="icon-new"></span> ' . JText::_('JACTION_CREATE')
. '</a>';
}

// Edit article button
if ($allowEdit)
{
$html[] = '<a'
$html .= '<a'
. ' class="btn hasTooltip' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_edit"'
. ' data-toggle="modal"'
. ' role="button"'
. ' href="#articleEdit' . $value . 'Modal"'
. ' href="#ModalEdit' . $modalId . '"'
. ' title="' . JHtml::tooltipText('COM_CONTENT_EDIT_ARTICLE') . '">'
. '<span class="icon-edit"></span> ' . JText::_('JACTION_EDIT')
. '</a>';
Expand All @@ -182,64 +162,100 @@ protected function getInput()
// Clear article button
if ($allowClear)
{
$html[] = '<button'
$html .= '<a'
. ' class="btn' . ($value ? '' : ' hidden') . '"'
. ' id="' . $this->id . '_clear"'
. ' onclick="return jClearArticle(\'' . $this->id . '\')">'
. ' href="#"'
. ' onclick="window.processModalParent(\'' . $this->id . '\'); return false;">'
. '<span class="icon-remove"></span>' . JText::_('JCLEAR')
. '</button>';
. '</a>';
}

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

// Select article modal
$html[] = JHtml::_(
'bootstrap.renderModal',
'articleSelect' . $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>',
)
);
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 article modal
if ($allowNew)
{
$html .= JHtml::_(
'bootstrap.renderModal',
'ModalNew' . $modalId,
array(
'title' => JText::_('COM_CONTENT_NEW_ARTICLE'),
'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\', \'article\', \'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\', \'article\', \'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\', \'article\', \'apply\', \'item-form\'); return false;">'
. JText::_("JAPPLY") . '</a>',
)
);
}

// Edit article modal
$html[] = JHtml::_(
'bootstrap.renderModal',
'articleEdit' . $value . 'Modal',
array(
'title' => JText::_('COM_CONTENT_EDIT_ARTICLE'),
'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(\'#articleEdit' . $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(\'#articleEdit' . $value . 'Modal iframe\').contents().find(\'#saveBtn\').click();">'
. JText::_("JSAVE") . '</button>'
. '<button type="button" class="btn btn-success" aria-hidden="true"'
. ' onclick="jQuery(\'#articleEdit' . $value . 'Modal iframe\').contents().find(\'#applyBtn\').click();">'
. JText::_("JAPPLY") . '</button>',
)
);
if ($allowEdit)
{
$html .= JHtml::_(
'bootstrap.renderModal',
'ModalEdit' . $modalId,
array(
'title' => JText::_('COM_CONTENT_EDIT_ARTICLE'),
'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\', \'article\', \'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\', \'article\', \'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\', \'article\', \'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_CONTENT_SELECT_AN_ARTICLE', true), ENT_COMPAT, 'UTF-8') . '" value="' . $value . '" />';

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

/**
Expand Down
Expand Up @@ -70,6 +70,7 @@
' . $this->form->getField('articletext')->save() . '
Joomla.submitform(task, document.getElementById("item-form"));

// @deprecated 4.0 The following js is not needed since __DEPLOY_VERSION__.
if (task !== "article.apply")
{
window.parent.jQuery("#articleEdit' . (int) $this->item->id . 'Modal").modal("hide");
Expand Down Expand Up @@ -165,6 +166,7 @@

<input type="hidden" name="task" value="" />
<input type="hidden" name="return" value="<?php echo $input->getCmd('return'); ?>" />
<input type="hidden" name="forcedLanguage" value="<?php echo $input->get('forcedLanguage', '', 'cmd'); ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
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', 'jEditArticle_' . (int) $this->item->id);

// Function to update input title when changed
Expand Down