From fbee00d9210aec6f8aba8a17dd6adbbfd7f0cf45 Mon Sep 17 00:00:00 2001 From: Mark Hamstra Date: Thu, 24 Oct 2019 15:12:28 +0200 Subject: [PATCH] Attempt adding a multi checkbox field #143 --- .../clientconfig/js/mgr/sections/home.js | 24 +++++++++++++++++++ .../clientconfig/js/mgr/widgets/combos.js | 1 + .../js/mgr/widgets/window.settings.js | 4 ++-- .../clientconfig/controllers/home.class.php | 2 +- .../clientconfig/lexicon/en/default.inc.php | 1 + 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/assets/components/clientconfig/js/mgr/sections/home.js b/assets/components/clientconfig/js/mgr/sections/home.js index cc9b6c3..b7a315e 100755 --- a/assets/components/clientconfig/js/mgr/sections/home.js +++ b/assets/components/clientconfig/js/mgr/sections/home.js @@ -128,6 +128,30 @@ Ext.extend(ClientConfig.page.Home,MODx.Component,{ field.value = 1; field.checked = (value.value); } + if (field.xtype === 'multi-checkbox') { + field.xtype = 'checkboxgroup'; + field.columns = 1; + field.items = [{xtype: 'checkbox', boxLabel: 'foo', 'name': 'foo'}]; + + var options = value.options.split('||'); + Ext.each(options, function(option, index) { + option = option.split('=='); + if (option[1]) { + field.items.push({ + boxLabel: option[0], + value: option[1], + name: field.name + '[]' + }) + } else { + field.items.push({ + boxLabel: option[0], + value: option[0], + name: field.name + '[]' + }) + } + }); + console.log(field); + } if (field.xtype == 'datefield') { field.format = MODx.config.manager_date_format; diff --git a/assets/components/clientconfig/js/mgr/widgets/combos.js b/assets/components/clientconfig/js/mgr/widgets/combos.js index de1ba3f..6eba997 100755 --- a/assets/components/clientconfig/js/mgr/widgets/combos.js +++ b/assets/components/clientconfig/js/mgr/widgets/combos.js @@ -44,6 +44,7 @@ ClientConfig.combo.FieldTypes = function(config) { ['colorpickerfield', _('clientconfig.xtype.colorpalette')], ['email', _('clientconfig.xtype.email')], ['xcheckbox', _('clientconfig.xtype.xcheckbox')], + ['multi-checkbox', _('clientconfig.xtype.multi-checkbox')], ['datefield', _('clientconfig.xtype.datefield')], ['timefield', _('clientconfig.xtype.timefield')], ['password', _('clientconfig.xtype.password')], diff --git a/assets/components/clientconfig/js/mgr/widgets/window.settings.js b/assets/components/clientconfig/js/mgr/widgets/window.settings.js index f56b802..d68d5e7 100755 --- a/assets/components/clientconfig/js/mgr/widgets/window.settings.js +++ b/assets/components/clientconfig/js/mgr/widgets/window.settings.js @@ -71,7 +71,7 @@ ClientConfig.window.Setting = function(config) { anchor: '100%', listeners: { select: {fn: function(field, record) { - if (record.data.xtype == 'modx-combo') { + if (['modx-combo', 'multi-checkbox'].indexOf(record.data.xtype) !== -1) { Ext.getCmp(config.id + '-options').show(); Ext.getCmp(config.id + '-process_options').show(); } else { @@ -97,7 +97,7 @@ ClientConfig.window.Setting = function(config) { fieldLabel: _('clientconfig.options'), description: _('clientconfig.options.desc'), anchor: '100%', - hidden: (config.record && (config.record.xtype === 'modx-combo')) ? false : true + hidden: (config.record && (['modx-combo', 'multi-checkbox'].indexOf(config.record.xtype) !== -1)) ? false : true },{ xtype: 'checkbox', id: config.id + '-process_options', diff --git a/core/components/clientconfig/controllers/home.class.php b/core/components/clientconfig/controllers/home.class.php index 209e72d..bb3cdb2 100755 --- a/core/components/clientconfig/controllers/home.class.php +++ b/core/components/clientconfig/controllers/home.class.php @@ -41,7 +41,7 @@ public function process(array $scriptProperties = array()) { $googleFontsApiKey = $this->modx->getOption('clientconfig.google_fonts_api_key', null, ''); $sa['xtype'] = empty($googleFontsApiKey) ? 'textfield' : $sa['xtype']; } - elseif ($sa['xtype'] === 'modx-combo' && $setting->get('process_options')) { + elseif ($setting->get('process_options') && in_array($sa['xtype'], ['modx-combo', 'multi-checkbox'], true)) { $inputOpts = $setting->get('options'); $this->modx->getParser(); $this->modx->parser->processElementTags('', $inputOpts, true, true); diff --git a/core/components/clientconfig/lexicon/en/default.inc.php b/core/components/clientconfig/lexicon/en/default.inc.php index d253686..324389e 100755 --- a/core/components/clientconfig/lexicon/en/default.inc.php +++ b/core/components/clientconfig/lexicon/en/default.inc.php @@ -113,3 +113,4 @@ $_lang['clientconfig.xtype.line'] = 'Line (divider)'; $_lang['clientconfig.xtype.code'] = 'Code (requires Ace editor installed)'; $_lang['clientconfig.xtype.email'] = 'Email'; +$_lang['clientconfig.xtype.multi-checkbox'] = 'Multiple checkboxes';