Permalink
Browse files

Add new checkbox widget, update onsubmit-callback

  • Loading branch information...
1 parent c42021a commit c96dcbfc5b3026fb26a2fc4c6c84f856620b1ea3 @stefanheimes stefanheimes committed May 2, 2012
@@ -0,0 +1,76 @@
+<?php if (!defined('TL_ROOT')) die('You cannot access this file directly!');
+
+/**
+ * Contao Open Source CMS
+ * Copyright (C) 2005-2010 Leo Feyer
+ *
+ * Formerly known as TYPOlight Open Source CMS.
+ *
+ * This program is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation, either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this program. If not, please visit the Free
+ * Software Foundation website at <http://www.gnu.org/licenses/>.
+ *
+ * PHP version 5
+ * @copyright MEN AT WORK 2012
+ * @package syncCto
+ * @license GNU/LGPL
+ * @filesource
+ */
+
+/**
+ * Class SyncCtoCheckBox
+ *
+ * Provide methods to handle check boxes.
+ */
+class SyncCtoCheckBox extends CheckBox
+{
+
+ /**
+ * Generate the widget and return it as string
+ * @return string
+ */
+ public function generate()
+ {
+ if (!$this->multiple && count($this->arrOptions) > 1)
+ {
+ $this->arrOptions = array($this->arrOptions[0]);
+ }
+
+ $state = $this->Session->get('checkbox_groups');
+
+ if ($this->Input->get('cbc'))
+ {
+ $state[$this->Input->get('cbc')] = (isset($state[$this->Input->get('cbc')]) && $state[$this->Input->get('cbc')] == 1) ? 0 : 1;
+ }
+
+ $arrOptionsKeys = array_keys($this->arrOptions);
+
+ if (is_array($this->state))
+ {
+ foreach ($this->state AS $key => $value)
+ {
+ if (isset($arrOptionsKeys[$key]))
+ {
+ $id = 'cbc_' . $this->strId . '_' . standardize($arrOptionsKeys[$key]);
+ $state[$id] = $value;
+ }
+ }
+ }
+ $this->Session->set('checkbox_groups', $state);
+
+ return parent::generate();
+ }
+
+}
+
+?>
@@ -359,7 +359,7 @@ public function onsubmit_callback(DataContainer $dc)
$arrTables = $this->Input->post("database_tables_recommended");
}
- if (is_array($this->Input->post("database_tables_none_recommended")) && count($this->Input->post("database_tables_recommended")) != 0)
+ if (is_array($this->Input->post("database_tables_none_recommended")) && count($this->Input->post("database_tables_none_recommended")) != 0)
{
$arrTables = array_merge($arrTables, $this->Input->post("database_tables_none_recommended"));
}
@@ -84,20 +84,22 @@
),
'database_tables_recommended' => array(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_clients_syncTo']['database_tables_recommended'],
- 'inputType' => 'checkbox',
+ 'inputType' => 'syncctocheckbox',
'exclude' => true,
'eval' => array(
- 'multiple' => true
+ 'multiple' => true,
+ 'state' => array(1 => 0)
),
'options_callback' => array('tl_syncCto_clients_syncTo', 'databaseTablesRecommended'),
'reference' => &$GLOBALS['TL_LANG']['SYC']['syncCto']
),
'database_tables_none_recommended' => array(
'label' => &$GLOBALS['TL_LANG']['tl_syncCto_clients_syncTo']['database_tables_none_recommended'],
- 'inputType' => 'checkbox',
+ 'inputType' => 'syncctocheckbox',
'exclude' => true,
'eval' => array(
- 'multiple' => true
+ 'multiple' => true,
+ 'state' => array(1 => 0)
),
'options_callback' => array('tl_syncCto_clients_syncTo', 'databaseTablesNoneRecommended'),
'reference' => &$GLOBALS['TL_LANG']['SYC']['syncCto']
@@ -305,7 +307,7 @@ public function checkVersion(DataContainer $dc)
* @return array
*/
public function onsubmit_callback(DataContainer $dc)
- {
+ {
$arrSyncSettings = array();
// Synchronization type
@@ -328,9 +330,10 @@ public function onsubmit_callback(DataContainer $dc)
$arrTables = $this->Input->post("database_tables_recommended");
}
- if (is_array($this->Input->post("database_tables_none_recommended")) && count($this->Input->post("database_tables_recommended")) != 0)
- {
+ if (is_array($this->Input->post("database_tables_none_recommended")) && count($this->Input->post("database_tables_none_recommended")) != 0)
+ {
$arrTables = array_merge($arrTables, $this->Input->post("database_tables_none_recommended"));
+
}
$arrSyncSettings["syncCto_SyncTables"] = $arrTables;

0 comments on commit c96dcbf

Please sign in to comment.