Skip to content
Permalink
Browse files

Fixes all issues Bruno17#9

- create alternative class with shorter name
- fixed x-form trigger buttons
- fixed connector url
- fixed saving multiple values to DB
- fixed load values
  • Loading branch information...
nico
nico committed Sep 18, 2018
1 parent b5f0d69 commit 62caff3c3f842efc4f21b123195238a411783207
@@ -0,0 +1,81 @@
<?php
/**
* DynamicDropdownTV
*
* Copyright 2012-2013 by Bruno Perner <b.perner@gmx.de>
*
* DynamicDropdownTV is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option) any
* later version.
*
* DynamicDropdownTV is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* DynamicDropdownTV; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package dynamicdropdowntv
* @subpackage input render
*
* Input Render for DynamicDropdownTV Multiple
*/
if (!class_exists('DynamicDropdownMultipleInputRender')) {
class DynamicDropdownMultipleInputRender extends modTemplateVarInputRender {
public function getTemplate() {
$corePath = $this->modx->getOption('dynamicdropdowntv.core_path', null, $this->modx->getOption('core_path') . 'components/dynamicdropdowntv/');
return $corePath . 'tv/input/tpl/dynamicdropdown_mlti.tpl';
}
public function process($value, array $params = array()) {
$corePath = $this->modx->getOption('dynamicdropdowntv.core_path', null, $this->modx->getOption('core_path') . 'components/dynamicdropdowntv/');
// fetch only the tv lexicon
$this->modx->lexicon->load('tv_widget');
$this->modx->lexicon->load('dynamicdropdowntv:inputoptions');
$lang = $this->modx->lexicon->fetch();
foreach ($lang as $k => $v) {
if (strpos($k, 'dynamicdropdowntv.') !== false) {
$k = str_replace('dynamicdropdowntv.', '', $k);
$k = str_replace('.', '_', $k);
}
$this->setPlaceholder('lang_' . $k, $v);
}
$this->setPlaceholder('params', $params);
$resource = is_object($this->modx->resource) ? $this->modx->resource->toArray() : array();
$ddId = $this->tv->get('name');
$groupPath = 'mgr/' . $params['group'];
$defaultPath = 'mgr/default';
$actionPath = file_exists($corePath . 'processors/' . $groupPath) ? $groupPath . '/' : $defaultPath . '/';
if ($this->tv->get('elements') == '') {
$default_processor = 'getoptions.default';
$ddProcessor = 'getoptions.' . $ddId;
} else {
$default_processor = 'getelements.default';
$ddProcessor = 'getelements.' . $ddId;
}
$action = file_exists($corePath . 'processors/' . $actionPath . $ddProcessor . '.php') ? $actionPath . $ddProcessor : $actionPath . $default_processor;
$this->setPlaceholder('connector_path', "'" . $this->modx->getOption('dynamicdropdowntv.assets_path', NULL, "' + MODx.config.assets_url + 'components/dynamicdropdowntv/") . "connector.php'");
$this->setPlaceholder('resource', $resource);
$this->setPlaceholder('object_id', $this->modx->getOption('object_id', $_REQUEST, ''));
$this->setPlaceholder('params', $params);
$this->setPlaceholder('action', $action);
$this->setPlaceholder('children', $this->modx->toJson(explode(',', $params['childs'])));
$this->setPlaceholder('parents', $this->modx->toJson(explode(',', $params['parents'])));
$this->setPlaceholder('ddId', $ddId);
}
}
}
return 'DynamicDropdownMultipleInputRender';
@@ -0,0 +1,148 @@
<input type="hidden" id="original{$ddId}" name="original{$tv->id}" value="{$tv->get('value')|escape}" />

<div id="div_{$ddId}">

</div>


<script type="text/javascript">
// <![CDATA[
{literal}
MODx.combo.{/literal}{$ddId}{literal} = function(config) {
config = config || {};
Ext.applyIf(config,{{/literal}
name: '{$ddId}'
,id: 'select_{$ddId}'
,width: 400
,hiddenName: 'tv{$tv->id}[]'
,renderTo: 'div_{$ddId}'
,triggerAction: 'all'
,mode: 'remote'
,children: Ext.util.JSON.decode('{$children}')
,parents: Ext.util.JSON.decode('{$parents}')
,clearBtnCls: 'x-form-trigger'
,expandBtnCls: 'x-form-trigger'
{if $params.title},title: '{$params.title}'{/if}
{if $params.listWidth},listWidth: {$params.listWidth}{/if}
,maxHeight: {if $params.maxHeight}{$params.maxHeight}{else}300{/if}
{if $params.typeAhead}
,editable: true
,typeAhead: true
,typeAheadDelay: {if $params.typeAheadDelay && $params.typeAheadDelay != ''}{$params.typeAheadDelay}{else}250{/if}
{else}
,editable: false
,typeAhead: false
{/if}
{if $params.listEmptyText}
,listEmptyText: '{$params.listEmptyText}'
{/if}
,forceSelection: {if $params.forceSelection && $params.forceSelection != 'false'}true{else}false{/if}
,initiated: false
,allowBlank: {if $params.allowBlank == 1 || $params.allowBlank == 'true'}true{else}false{/if}
,resizable: false
,pageSize: 0
,url: {$connector_path}
,fields: ['id','name']
,displayField: 'name'
,valueField: 'id'
{if $params.valueDelimiter}
,valueDelimiter: '{$params.valueDelimiter}'
{/if}
,clearOnRefresh: {if $params.clearOnRefresh == 1 || $params.clearOnRefresh == 'true'}true{else}false{/if}
{literal}
,baseParams: {
{/literal}
action: '{$action}'
,resource_id: '{$resource.id}'
,object_id: '{$object_id}'
,tvname: '{{$tv->name}}'
{literal}
}
,store: new Ext.data.JsonStore({
id:'id',
autoLoad: true,
root:'results',
fields: ['name', 'id'],
remoteSort: true,
url: {/literal}{$connector_path}{literal},
baseParams:{
action: '{/literal}{$action}{literal}'
,resource_id: '{/literal}{$resource.id}{literal}'
,object_id : '{/literal}{$object_id}{literal}'
,tvname : '{/literal}{{$tv->name}}{literal}'
}
})
,listeners: {
'select': {fn:this.selectOption,scope:this}
,'additem': {fn:this.selectOption,scope:this}
,'removeitem': {fn:this.selectOption,scope:this}
,'render': {fn:this.initSelect,scope:this}
}
});
MODx.combo.{/literal}{$ddId}{literal}.superclass.constructor.call(this,config);
};
Ext.extend(MODx.combo.{/literal}{$ddId}{literal},Ext.ux.form.SuperBoxSelect,{
selectOption: function() {
if(this.children.length >= 1 && typeof(Ext.getCmp('select_'+this.children[0])) != "undefined") {
this.refreshChildren(true);
}
MODx.fireResourceFormChange();
}
,reload: function() {
this.store.load({
callback: function() {
if (this.clearOnRefresh){
this.setValue('');
}
this.refreshChildren(true);
},scope:this
});
}
,refreshChildren: function(reload) {
var ddSelect = null;
for(i = 0; i < this.children.length; i++) {
child = this.children[i];
ddSelect = Ext.getCmp('select_'+child);
if(typeof(ddSelect) != "undefined"){
ddSelect.baseParams.{/literal}{$ddId}{literal} = this.getValue();
if (reload){
ddSelect.reload();
}
}
}
}
,initSelect: function() {
var parent_field = null;
for(i = 0; i < this.parents.length; i++) {
parent = this.parents[i];
parent_field = Ext.get('original'+parent);
if (parent_field){
this.store.baseParams[parent] = parent_field.dom.value;
}
}
var original_values = Ext.get('{/literal}original{$ddId}{literal}').dom.value;
this.setValue(original_values);
// Separate store .. won't fire ever
this.store.load({
callback: function() {
this.setValue(Ext.get('{/literal}original{$ddId}{literal}').dom.value);
},scope:this
});
}
});
Ext.reg('modx-combo-{/literal}{$ddId}{literal}',MODx.combo.{/literal}{$ddId}{literal});
Ext.onReady(function() {
var fld = MODx.load({
xtype: 'modx-combo-{/literal}{$ddId}{literal}'
});
Ext.getCmp('modx-panel-resource').getForm().add(fld);
{/literal}
});
// ]]>
</script>
@@ -0,0 +1,46 @@
<?php
/**
* DynamicDropdownTV
*
* Copyright 2012-2013 by Bruno Perner <b.perner@gmx.de>
*
* DynamicDropdownTV is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option) any
* later version.
*
* DynamicDropdownTV is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* DynamicDropdownTV; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @package dynamicdropdowntv
* @subpackage input render properties
*
* Input Render for DynamicDropdownTV Properties Multiple
*/
$modx->lexicon->load('tv_widget', 'dynamicdropdowntv:inputoptions');
$lang = $modx->lexicon->fetch('dynamicdropdowntv.', true);
// get list of dynamic dropdown template variables to select parent dropdown
$c = $modx->newQuery('modTemplateVar');
$c->where(array('type:LIKE' => 'dynamicdropdown%'));
$list[] = array('', $lang['noParent']);
if ($collection = $modx->getCollection('modTemplateVar', $c)) {
foreach ($collection as $object) {
if ($_REQUEST['tv'] != $object->get('id')) {
$list[] = array($object->get('name'), $object->get('name'));
}
}
}
$list = json_encode($list);
$modx->smarty->assign('tvlist', $list);
$modx->smarty->assign('dynamicdropdowntv', $lang);
$corePath = $modx->getOption('dynamicdropdowntv.core_path', null, $modx->getOption('core_path') . 'components/dynamicdropdowntv/');
return $modx->smarty->fetch($corePath . 'tv/inputoptions/tpl/dynamicdropdown_multiple.tpl');

0 comments on commit 62caff3

Please sign in to comment.
You can’t perform that action at this time.