Improved the Admin Fields Relations area to allow more custom coding without the need of selecting Join Field/s. Improved the dynamic get string fixing implementation to avoid conflict when the same field name is used in multiple joined tables requiering string fixing. Fixed gh-322 to insure ID is always readonly even if override detected. Added new feature to control access and view/hide control per/field.

This commit is contained in:
2018-07-21 09:10:37 +02:00
parent 0a7b91829f
commit 6dd654c745
18 changed files with 469 additions and 329 deletions

View File

@ -428,7 +428,7 @@ class ComponentbuilderModelAjax extends JModelList
'search' => 'setYesNo',
'filter' => 'setYesNo',
'link' => 'setYesNo',
'permission' => 'setYesNo',
'permission' => 'setPermissions',
'tab' => 'setTabName',
'alignment' => 'setAlignmentName',
'target_field' => 'setItemNames',
@ -852,6 +852,42 @@ class ComponentbuilderModelAjax extends JModelList
return JText::_('COM_COMPONENTBUILDER_NO_ITEM_FOUND');
}
protected function setPermissions($header, $values)
{
// check if value is array
if (!ComponentbuilderHelper::checkArray($values))
{
$values = array($values);
}
// check if value is array
if (ComponentbuilderHelper::checkArray($values))
{
// Editing, Access, View
$bucket = array();
foreach ($values as $value)
{
switch ($value)
{
case 1:
$bucket[] = JText::_('COM_COMPONENTBUILDER_EDITING');
break;
case 2:
$bucket[] = JText::_('COM_COMPONENTBUILDER_ACCESS');
break;
case 3:
$bucket[] = JText::_('COM_COMPONENTBUILDER_VIEW');
break;
}
}
// check if value is array
if (ComponentbuilderHelper::checkArray($bucket))
{
return implode(', ', $bucket);
}
}
return JText::_('COM_COMPONENTBUILDER_NONE');
}
protected function setJoinType($header, $value)
{
switch ($value)
@ -2625,11 +2661,18 @@ class ComponentbuilderModelAjax extends JModelList
elseif ($type == 2)
{
// build fields array
$fields = array_map( function ($id) {
return (int) $id;
}, (array) explode(',', $joinfields));
// add the list field to array
array_unshift($fields, (int) $listfield);
if ('none' !== $joinfields)
{
$fields = array_map( function ($id) {
return (int) $id;
}, (array) explode(',', $joinfields));
// add the list field to array
array_unshift($fields, (int) $listfield);
}
else
{
$fields = array((int) $listfield);
}
// get field names
$names = array_map( function ($id) {
return '[' . $id . ']=> ' . ComponentbuilderHelper::getVar('field', $id, 'id', 'name');

View File

@ -88,6 +88,7 @@ class JFormFieldListfields extends JFormFieldList
$options = array();
if ($items)
{
$options[] = JHtml::_('select.option', '', JText::_('COM_COMPONENTBUILDER_SELECT_AN_OPTION'));
foreach($items as $item)
{
$options[] = JHtml::_('select.option', $item->id, $item->name);

View File

@ -373,70 +373,6 @@ class ComponentbuilderModelFieldtype extends JModelAdmin
// Disable fields while saving.
$form->setFieldAttribute('created', 'filter', 'unset');
}
// Modify the form based on Edit Name access controls.
if ($id != 0 && (!$user->authorise('fieldtype.edit.name', 'com_componentbuilder.fieldtype.' . (int) $id))
|| ($id == 0 && !$user->authorise('fieldtype.edit.name', 'com_componentbuilder')))
{
// Disable fields for display.
$form->setFieldAttribute('name', 'disabled', 'true');
// Disable fields for display.
$form->setFieldAttribute('name', 'readonly', 'true');
if (!$form->getValue('name'))
{
// Disable fields while saving.
$form->setFieldAttribute('name', 'filter', 'unset');
// Disable fields while saving.
$form->setFieldAttribute('name', 'required', 'false');
}
}
// Modify the form based on Edit Properties access controls.
if ($id != 0 && (!$user->authorise('fieldtype.edit.properties', 'com_componentbuilder.fieldtype.' . (int) $id))
|| ($id == 0 && !$user->authorise('fieldtype.edit.properties', 'com_componentbuilder')))
{
// Disable fields for display.
$form->setFieldAttribute('properties', 'disabled', 'true');
// Disable fields for display.
$form->setFieldAttribute('properties', 'readonly', 'true');
if (!$form->getValue('properties'))
{
// Disable fields while saving.
$form->setFieldAttribute('properties', 'filter', 'unset');
// Disable fields while saving.
$form->setFieldAttribute('properties', 'required', 'false');
}
}
// Modify the form based on Edit Description access controls.
if ($id != 0 && (!$user->authorise('fieldtype.edit.description', 'com_componentbuilder.fieldtype.' . (int) $id))
|| ($id == 0 && !$user->authorise('fieldtype.edit.description', 'com_componentbuilder')))
{
// Disable fields for display.
$form->setFieldAttribute('description', 'disabled', 'true');
// Disable fields for display.
$form->setFieldAttribute('description', 'readonly', 'true');
if (!$form->getValue('description'))
{
// Disable fields while saving.
$form->setFieldAttribute('description', 'filter', 'unset');
// Disable fields while saving.
$form->setFieldAttribute('description', 'required', 'false');
}
}
// Modify the form based on Edit Short Description access controls.
if ($id != 0 && (!$user->authorise('fieldtype.edit.short_description', 'com_componentbuilder.fieldtype.' . (int) $id))
|| ($id == 0 && !$user->authorise('fieldtype.edit.short_description', 'com_componentbuilder')))
{
// Disable fields for display.
$form->setFieldAttribute('short_description', 'disabled', 'true');
// Disable fields for display.
$form->setFieldAttribute('short_description', 'readonly', 'true');
if (!$form->getValue('short_description'))
{
// Disable fields while saving.
$form->setFieldAttribute('short_description', 'filter', 'unset');
// Disable fields while saving.
$form->setFieldAttribute('short_description', 'required', 'false');
}
}
// Only load these values if no id is found
if (0 == $id)
{

View File

@ -270,14 +270,16 @@
name="permission"
label="COM_COMPONENTBUILDER_ADMIN_FIELDS_PERMISSION_LABEL"
description="COM_COMPONENTBUILDER_ADMIN_FIELDS_PERMISSION_DESCRIPTION"
class="fieldMid"
multiple="false"
class="fieldMedium"
multiple="true"
required="false">
<!-- Option Set. -->
<option value="0">
COM_COMPONENTBUILDER_ADMIN_FIELDS_NONE</option>
<option value=" 1">
<option value="1">
COM_COMPONENTBUILDER_ADMIN_FIELDS_EDITING</option>
<option value="2">
COM_COMPONENTBUILDER_ADMIN_FIELDS_ACCESS</option>
<option value="3">
COM_COMPONENTBUILDER_ADMIN_FIELDS_VIEW</option>
</field>
</form>
</field>

View File

@ -20,14 +20,14 @@ function getCodeGlueOptions(field) {
var subID = target[0]+'__'+target[1];
// get listfield value
var listfield = jQuery('#'+subID+'__listfield').val();
// get joinfields values
var joinfields = jQuery('#'+subID+'__joinfields').val();
// get type value
var type = jQuery('#'+subID+'__join_type').val();
// get area value
var area = jQuery('#'+subID+'__area').val();
// check that values are set
if (_isSet(listfield) && _isSet(joinfields) && _isSet(type) && _isSet(area)) {
if (_isSet(listfield) && _isSet(type) && _isSet(area)) {
// get joinfields values
var joinfields = jQuery('#'+subID+'__joinfields').val();
// get codeGlueOptions
getCodeGlueOptions_server(listfield, joinfields, type, area).done(function(result) {
if(result){
@ -43,7 +43,11 @@ function getCodeGlueOptions(field) {
function getCodeGlueOptions_server(listfield, joinfields, type, area){
var getUrl = "index.php?option=com_componentbuilder&task=ajax.getCodeGlueOptions&format=json";
if(token.length > 0 && listfield > 0 && joinfields.length >= 1 && type > 0 && area > 0) {
// make sure the joinfields are set
if (!_isSet(joinfields)) {
joinfields = 'none';
}
if(token.length > 0 && listfield > 0 && type > 0 && area > 0) {
var request = 'token='+token+'&listfield='+listfield+'&type='+type+'&area='+area+'&joinfields='+joinfields;
}
return jQuery.ajax({

View File

@ -107,9 +107,6 @@ class ComponentbuilderModelGet_snippets extends JModelList
// Insure all item fields are adapted where needed.
if (ComponentbuilderHelper::checkArray($items))
{
// Load the JEvent Dispatcher
JPluginHelper::importPlugin('content');
$this->_dispatcher = JEventDispatcher::getInstance();
foreach ($items as $nr => &$item)
{
// Always create a slug for sef URL's