Refactored the compiler list view body builder, in preparation of the relation fields. Added more options to the relation admin fields. gh-287
This commit is contained in:
@ -87,26 +87,6 @@ class ComponentbuilderModelAdmin_fields_relations extends JModelAdmin
|
||||
$addrelations = new Registry;
|
||||
$addrelations->loadString($item->addrelations);
|
||||
$item->addrelations = $addrelations->toArray();
|
||||
}
|
||||
|
||||
// check what type of conditions array we have here (should be subform... but just incase)
|
||||
// This could happen due to huge data sets
|
||||
if (isset($item->addconditions) && isset($item->addconditions['target_field']))
|
||||
{
|
||||
$bucket = array();
|
||||
foreach($item->addconditions as $option => $values)
|
||||
{
|
||||
foreach($values as $nr => $value)
|
||||
{
|
||||
$bucket['addconditions'.$nr][$option] = $value;
|
||||
}
|
||||
}
|
||||
$item->addconditions = $bucket;
|
||||
// update the fields
|
||||
$conditionsUpdate = new stdClass();
|
||||
$conditionsUpdate->id = (int) $item->id;
|
||||
$conditionsUpdate->addconditions = json_encode($bucket);
|
||||
$this->_db->updateObject('#__componentbuilder_admin_fields_conditions', $conditionsUpdate, 'id');
|
||||
}
|
||||
|
||||
if (!empty($item->id))
|
||||
|
@ -1092,7 +1092,7 @@ class ComponentbuilderModelAjax extends JModelList
|
||||
{
|
||||
$result = $this->_db->loadObject();
|
||||
$result->name = strtolower($result->name);
|
||||
if (ComponentbuilderHelper::typeField($result->name,'list'))
|
||||
if (ComponentbuilderHelper::fieldCheck($result->name,'list'))
|
||||
{
|
||||
// load the values form params
|
||||
$xml = json_decode($result->xml);
|
||||
@ -1136,15 +1136,15 @@ class ComponentbuilderModelAjax extends JModelList
|
||||
// return found field options
|
||||
return $optionSet;
|
||||
}
|
||||
elseif (ComponentbuilderHelper::typeField($result->name,'text'))
|
||||
elseif (ComponentbuilderHelper::fieldCheck($result->name,'text'))
|
||||
{
|
||||
return "keywords=\"\"\nlength=\"\"";
|
||||
}
|
||||
elseif (ComponentbuilderHelper::typeField($result->name,'dynamic'))
|
||||
elseif (ComponentbuilderHelper::fieldCheck($result->name,'dynamic'))
|
||||
{
|
||||
return 'dynamic_list';
|
||||
}
|
||||
elseif (ComponentbuilderHelper::typeField($result->name))
|
||||
elseif (ComponentbuilderHelper::fieldCheck($result->name))
|
||||
{
|
||||
return 'match field type not supported. Select another!';
|
||||
}
|
||||
@ -2567,6 +2567,52 @@ class ComponentbuilderModelAjax extends JModelList
|
||||
return $xml;
|
||||
}
|
||||
|
||||
// Used in admin_fields_relations
|
||||
public function getCodeGlueOptions($listfield, $joinfields, $type, $area)
|
||||
{
|
||||
// CONCATENATE GLUE
|
||||
if ($type == 1)
|
||||
{
|
||||
// MODEL
|
||||
if ($area == 1)
|
||||
{
|
||||
return ', ';
|
||||
}
|
||||
// VIEW
|
||||
elseif ($area == 2)
|
||||
{
|
||||
return '<br />';
|
||||
}
|
||||
}
|
||||
// CUSTOM CODE
|
||||
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);
|
||||
// get field names
|
||||
$names = array_map( function ($id) {
|
||||
return '[' . $id . ']=> ' . ComponentbuilderHelper::getVar('field', $id, 'id', 'name');
|
||||
}, $fields);
|
||||
// create note
|
||||
$note = "// ". implode('; ', $names);
|
||||
// MODEL
|
||||
if ($area == 1)
|
||||
{
|
||||
return $note . PHP_EOL . PHP_EOL . '$item->[' . implode("] . ', ' . \$item->[", $fields) . '];';
|
||||
}
|
||||
// VIEW
|
||||
elseif ($area == 2)
|
||||
{
|
||||
return '$this->escape($item->[' . implode("]) . '<br />' . \$this->escape(\$item->[", $fields). ']);' . PHP_EOL . PHP_EOL . $note;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Used in get_snippets
|
||||
|
||||
public function getSnippets($libraries)
|
||||
|
@ -123,6 +123,8 @@ class ComponentbuilderModelDynamic_gets extends JModelList
|
||||
$item->main_source = $this->selectionTranslation($item->main_source, 'main_source');
|
||||
// convert gettype
|
||||
$item->gettype = $this->selectionTranslation($item->gettype, 'gettype');
|
||||
// convert addcalculation
|
||||
$item->addcalculation = $this->selectionTranslation($item->addcalculation, 'addcalculation');
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,6 +170,19 @@ class ComponentbuilderModelDynamic_gets extends JModelList
|
||||
return $gettypeArray[$value];
|
||||
}
|
||||
}
|
||||
// Array of addcalculation language strings
|
||||
if ($name === 'addcalculation')
|
||||
{
|
||||
$addcalculationArray = array(
|
||||
1 => 'COM_COMPONENTBUILDER_DYNAMIC_GET_YES',
|
||||
0 => 'COM_COMPONENTBUILDER_DYNAMIC_GET_NO'
|
||||
);
|
||||
// Now check if value is found in this array
|
||||
if (isset($addcalculationArray[$value]) && ComponentbuilderHelper::checkString($addcalculationArray[$value]))
|
||||
{
|
||||
return $addcalculationArray[$value];
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
@ -190,6 +205,10 @@ class ComponentbuilderModelDynamic_gets extends JModelList
|
||||
// From the componentbuilder_item table
|
||||
$query->from($db->quoteName('#__componentbuilder_dynamic_get', 'a'));
|
||||
|
||||
// From the componentbuilder_admin_view table.
|
||||
$query->select($db->quoteName('h.system_name','view_table_main_system_name'));
|
||||
$query->join('LEFT', $db->quoteName('#__componentbuilder_admin_view', 'h') . ' ON (' . $db->quoteName('a.view_table_main') . ' = ' . $db->quoteName('h.id') . ')');
|
||||
|
||||
// Filter by published state
|
||||
$published = $this->getState('filter.published');
|
||||
if (is_numeric($published))
|
||||
|
@ -64,28 +64,36 @@ class JFormFieldAliasbuilder extends JFormFieldList
|
||||
}
|
||||
}
|
||||
}
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array('a.id','a.name','b.name'),array('id','name','type')));
|
||||
$query->from($db->quoteName('#__componentbuilder_field', 'a'));
|
||||
$query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'b') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('b.id') . ')');
|
||||
$query->where($db->quoteName('a.published') . ' >= 1');
|
||||
// filter by fields linked
|
||||
if (ComponentbuilderHelper::checkArray($fieldIds))
|
||||
{
|
||||
// get list of field types that does not work in list views (note, spacer)
|
||||
$spacers = ComponentbuilderHelper::getSpacerIds();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array('a.id','a.name','b.name'),array('id','name','type')));
|
||||
$query->from($db->quoteName('#__componentbuilder_field', 'a'));
|
||||
$query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 'b') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('b.id') . ')');
|
||||
$query->where($db->quoteName('a.published') . ' >= 1');
|
||||
// only load these fields
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $fieldIds) . ')');
|
||||
}
|
||||
$query->order('a.name ASC');
|
||||
$db->setQuery((string)$query);
|
||||
$items = $db->loadObjectList();
|
||||
$options = array();
|
||||
if ($items)
|
||||
{
|
||||
foreach($items as $item)
|
||||
// none of these field types
|
||||
if (ComponentbuilderHelper::checkArray($spacers))
|
||||
{
|
||||
$options[] = JHtml::_('select.option', $item->id, $item->name . ' [' . $item->type . ']');
|
||||
$query->where($db->quoteName('a.fieldtype') . ' NOT IN (' . implode(',', $spacers) . ')');
|
||||
}
|
||||
$query->order('a.name ASC');
|
||||
$db->setQuery((string)$query);
|
||||
$items = $db->loadObjectList();
|
||||
$options = array();
|
||||
if ($items)
|
||||
{
|
||||
foreach($items as $item)
|
||||
{
|
||||
$options[] = JHtml::_('select.option', $item->id, $item->name . ' [' . $item->type . ']');
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
return array(JHtml::_('select.option', '', JText::_('COM_COMPONENTBUILDER_ADD_MORE_FIELDS_TO_THIS_ADMIN_VIEW')));
|
||||
}
|
||||
}
|
||||
|
@ -76,12 +76,20 @@ class JFormFieldJoinfields extends JFormFieldList
|
||||
// filter by fields linked
|
||||
if (ComponentbuilderHelper::checkArray($fieldIds))
|
||||
{
|
||||
// get list of field types that does not work in list views (note, spacer)
|
||||
$spacers = ComponentbuilderHelper::getSpacerIds();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array('a.id','a.name'),array('id','name')));
|
||||
$query->select($db->quoteName(array('a.id','a.name','t.name'),array('id','name','type')));
|
||||
$query->from($db->quoteName('#__componentbuilder_field', 'a'));
|
||||
$query->join('LEFT', $db->quoteName('#__componentbuilder_fieldtype', 't') . ' ON (' . $db->quoteName('a.fieldtype') . ' = ' . $db->quoteName('t.id') . ')');
|
||||
$query->where($db->quoteName('a.published') . ' >= 1');
|
||||
// only load these fields
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $fieldIds) . ')');
|
||||
// none of these field types
|
||||
if (ComponentbuilderHelper::checkArray($spacers))
|
||||
{
|
||||
$query->where($db->quoteName('a.fieldtype') . ' NOT IN (' . implode(',', $spacers) . ')');
|
||||
}
|
||||
$query->order('a.name ASC');
|
||||
$db->setQuery((string)$query);
|
||||
$items = $db->loadObjectList();
|
||||
@ -90,12 +98,12 @@ class JFormFieldJoinfields extends JFormFieldList
|
||||
{
|
||||
foreach($items as $item)
|
||||
{
|
||||
$options[] = JHtml::_('select.option', $item->id, $item->name);
|
||||
$options[] = JHtml::_('select.option', $item->id, $item->name . ' [' . $item->type . ']');
|
||||
}
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return array(JHtml::_('select.option', '', JText::_('COM_COMPONENTBUILDER_ADD_MORE_FIELDS_TO_THIS_ADMIN_VIEW')));
|
||||
}
|
||||
}
|
||||
|
@ -11,10 +11,33 @@
|
||||
|
||||
|
||||
|
||||
function getFieldSelectOptions_server(fieldId){
|
||||
var getUrl = "index.php?option=com_componentbuilder&task=ajax.fieldSelectOptions&format=json";
|
||||
if(token.length > 0 && fieldId > 0){
|
||||
var request = 'token='+token+'&id='+fieldId;
|
||||
// little script to set the value
|
||||
function getCodeGlueOptions(field) {
|
||||
// get the ID
|
||||
var id = jQuery(field).attr('id');
|
||||
var target = id.split('__');
|
||||
//set the subID
|
||||
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();
|
||||
// get codeGlueOptions
|
||||
getCodeGlueOptions_server(listfield, joinfields, type, area).done(function(result) {
|
||||
if(result){
|
||||
jQuery('#'+subID+'__set').val(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
var request = 'token='+token+'&listfield='+listfield+'&type='+type+'&area='+area+'&joinfields='+joinfields;
|
||||
}
|
||||
return jQuery.ajax({
|
||||
type: 'GET',
|
||||
@ -25,20 +48,4 @@ function getFieldSelectOptions_server(fieldId){
|
||||
});
|
||||
}
|
||||
|
||||
function getFieldSelectOptions(fieldKey){
|
||||
// first check if the field is set
|
||||
if(jQuery("#jform_addconditions__addconditions"+fieldKey+"__match_field").length) {
|
||||
var fieldId = jQuery("#jform_addconditions__addconditions"+fieldKey+"__match_field option:selected").val();
|
||||
getFieldSelectOptions_server(fieldId).done(function(result) {
|
||||
if(result){
|
||||
jQuery('textarea#jform_addconditions__addconditions'+fieldKey+'__match_options').val(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
jQuery('textarea#jform_addconditions__addconditions'+fieldKey+'__match_options').val('');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -116,6 +116,7 @@
|
||||
class="fieldMedium"
|
||||
multiple="false"
|
||||
required="false"
|
||||
onchange="getCodeGlueOptions(this)"
|
||||
button="false"
|
||||
/>
|
||||
<!-- Joinfields Field. Type: Joinfields. (custom) -->
|
||||
@ -127,8 +128,26 @@
|
||||
class="fieldMedium"
|
||||
multiple="true"
|
||||
required="false"
|
||||
onchange="getCodeGlueOptions(this)"
|
||||
button="false"
|
||||
/>
|
||||
<!-- Area Field. Type: List. (joomla) -->
|
||||
<field
|
||||
type="list"
|
||||
name="area"
|
||||
label="COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_AREA_LABEL"
|
||||
class="list_class"
|
||||
multiple="false"
|
||||
required="false"
|
||||
validate="int"
|
||||
default="1"
|
||||
onchange="getCodeGlueOptions(this)">
|
||||
<!-- Option Set. -->
|
||||
<option value="1">
|
||||
COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_MODEL</option>
|
||||
<option value="2">
|
||||
COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_VIEW</option>
|
||||
</field>
|
||||
<!-- Join_type Field. Type: List. (joomla) -->
|
||||
<field
|
||||
type="list"
|
||||
@ -138,26 +157,26 @@
|
||||
multiple="false"
|
||||
required="false"
|
||||
validate="int"
|
||||
default="1">
|
||||
default="1"
|
||||
onchange="getCodeGlueOptions(this)">
|
||||
<!-- Option Set. -->
|
||||
<option value="1">
|
||||
COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_CONCATENATE</option>
|
||||
COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_CONCATENATE_RAQUO_GLUE</option>
|
||||
<option value="2">
|
||||
COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_CUSTOM_CODE</option>
|
||||
COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_CUSTOM_RAQUO_CODE</option>
|
||||
</field>
|
||||
<!-- Set Field. Type: Text. (joomla) -->
|
||||
<!-- Set Field. Type: Textarea. (joomla) -->
|
||||
<field
|
||||
type="text"
|
||||
type="textarea"
|
||||
name="set"
|
||||
label="COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_SET_LABEL"
|
||||
size="150"
|
||||
maxlength="150"
|
||||
rows="4"
|
||||
cols="5"
|
||||
description="COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_SET_DESCRIPTION"
|
||||
class="text_area"
|
||||
required="false"
|
||||
filter="RAW"
|
||||
class="text_area codefield"
|
||||
filter="raw"
|
||||
hint="COM_COMPONENTBUILDER_ADMIN_FIELDS_RELATIONS_SET_HINT"
|
||||
autocomplete="on"
|
||||
required="false"
|
||||
/>
|
||||
</form>
|
||||
</field>
|
||||
|
Reference in New Issue
Block a user