Skip to content

Commit

Permalink
TinyMCE builder: use usergroup instead of viewlevel for each set. Plu…
Browse files Browse the repository at this point in the history
…s fix some BC issue. (joomla#13387)

* Use user groups instead of view level for TinyMCE builder

* Preload an old parameters where it possible, for BC

* cs

* onDisplayLegacy for BC

* space to tabs

* Warning message about update

* Show warning only in the backend and only twice per session

* Allow to select the user group only once per the set

* Too much code 👽

* Update the warning message

* Update the warning message

* Update tinymce.php

Correcting B/C
  • Loading branch information
Fedik authored and rdeutz committed Dec 30, 2016
1 parent 0e48339 commit 0bb6c5c
Show file tree
Hide file tree
Showing 5 changed files with 961 additions and 43 deletions.
1 change: 1 addition & 0 deletions administrator/language/en-GB/en-GB.plg_editors_tinymce.ini
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ PLG_TINY_FIELD_VISUALCHARS_DESC="See invisible characters, specifically non-brea
PLG_TINY_FIELD_VISUALCHARS_LABEL="Visualchars"
PLG_TINY_FIELD_WORDCOUNT_DESC="Turn on/off Wordcount."
PLG_TINY_FIELD_WORDCOUNT_LABEL="Wordcount"
PLG_TINY_LEGACY_WARNING="The <a href="_QQ_"%s"_QQ_">TinyMCE Editor Plugin</a> has been updated. At the moment, it uses your legacy configuration. By editing the plugin, you can now assign various layouts to specific user groups."
PLG_TINY_SET_TITLE="Set %s"
PLG_TINY_SET_PRESET_BUTTON_ADVANCED="Use advanced preset"
PLG_TINY_SET_PRESET_BUTTON_MEDIUM="Use medium preset"
Expand Down
29 changes: 29 additions & 0 deletions media/editors/tinymce/js/tinymce-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,34 @@
event.preventDefault();
$(this).tab("show");
});

// Allow to select the group only once per the set
var $accessSelects = $('#joomla-tinymce-builder').find('.access-select');
toggleAvailableOption();
$accessSelects.on('change', function () {
toggleAvailableOption();
});

function toggleAvailableOption () {
$accessSelects.find('option[disabled]').removeAttr('disabled');

// Disable already selected options
$accessSelects.each(function () {
var $select = $(this), val = $select.val(), query = [],
$options = $accessSelects.not(this).find('option');

for (var i = 0, l = val.length; i < l; i++ ) {
if (!val[i]) continue;
query.push('[value="' + val[i] + '"]');
}

if (query.length) {
$options.filter(query.join(',')).attr('disabled', 'disabled');
}
});

// Update Chosen
$accessSelects.trigger('liszt:updated');
}
});
}(jQuery));
35 changes: 23 additions & 12 deletions plugins/editors/tinymce/field/tinymcebuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class JFormFieldTinymceBuilder extends JFormField
protected function getLayoutData()
{
$data = parent::getLayoutData();
$valueAll = (object) $this->form->getValue('params');
$setsAmount = empty($valueAll->sets_amount) ? 3 : $valueAll->sets_amount;
$paramsAll = (object) $this->form->getValue('params');
$setsAmount = empty($paramsAll->sets_amount) ? 3 : $paramsAll->sets_amount;

// Get the plugin
require_once JPATH_PLUGINS . '/editors/tinymce/tinymce.php';
Expand Down Expand Up @@ -78,11 +78,18 @@ protected function getLayoutData()
$setsForms = array();
$formsource = JPATH_PLUGINS . '/editors/tinymce/form/setoptions.xml';

// Check the old values for B/C
$valueOld = new stdClass;
if ($this->value && empty($this->value['setoptions']))
// Preload an old params for B/C
$setParams = new stdClass;
if (!empty($paramsAll->html_width) && empty($paramsAll->configuration['setoptions']))
{
$valueOld = $valueAll;
$plugin = JPluginHelper::getPlugin('editors', 'tinymce');

JFactory::getApplication()->enqueueMessage(JText::sprintf('PLG_TINY_LEGACY_WARNING', '#'), 'warning');

if (is_object($plugin) && !empty($plugin->params))
{
$setParams = (object) json_decode($plugin->params);
}
}

foreach (array_keys($data['setsNames']) as $num)
Expand All @@ -92,20 +99,24 @@ protected function getLayoutData()

$setsForms[$num] = JForm::getInstance($formname, $formsource, array('control' => $control));

// Bind the values

// Check whether we already have saved values or it first time or even old params
if (empty($this->value['setoptions'][$num]))
{
$formValues = $valueOld;

// Predefine access: 0 for special, 1 for registered, all else is public
$formValues->access = !$num ? 3 : ($num === 1 ? 2 : 1);
$formValues = $setParams;

/*
* Predefine group:
* Set 0: for Administrator, Editor, Super Users (4,7,8)
* Set 1: for Registered, Manager (2,6), all else are public
*/
$formValues->access = !$num ? array(4,7,8) : ($num === 1 ? array(2,6) : 1);
}
else
{
$formValues = $this->value['setoptions'][$num];
}

// Bind the values
$setsForms[$num]->bind($formValues);
}

Expand Down
4 changes: 3 additions & 1 deletion plugins/editors/tinymce/form/setoptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<form>
<field
name="access"
type="accesslevel"
type="usergrouplist"
multiple="true"
class="access-select"
label="JFIELD_ACCESS_LABEL"
description="JFIELD_ACCESS_DESC"
/>
Expand Down
Loading

0 comments on commit 0bb6c5c

Please sign in to comment.