Przeglądaj źródła

#31 - Reverse checkbox list in Settings.

AntonLV 12 lat temu
rodzic
commit
1ac4dbe00c

+ 1 - 1
install/sql/system.sql

@@ -161,7 +161,7 @@ CREATE TABLE `sys_options` (
   `name` varchar(64) NOT NULL default '',
   `caption` varchar(255) NOT NULL default '',
   `value` mediumtext NOT NULL,
-  `type` enum('digit','text','checkbox','select','combobox','file','list') NOT NULL default 'digit',
+  `type` enum('digit','text','checkbox','select','combobox','file','list','rlist') NOT NULL default 'digit',
   `extra` text NOT NULL default '',
   `check` varchar(32) NOT NULL,
   `check_params` text NOT NULL,

+ 17 - 0
studio/classes/BxDolStudioForm.php

@@ -88,6 +88,23 @@ class BxDolStudioForm extends BxBaseFormView
         return (int)$iId;
     }
 
+	function getCleanValue ($sName)
+    {
+        $oChecker = new BxDolFormChecker($this->_sCheckerHelper);
+        $oChecker->setFormMethod($this->aFormAttrs['method']);
+
+        $a = isset($this->aInputs[$sName]) ? $this->aInputs[$sName] : false;
+        if($a && isset($a['db']['pass']))
+			$aResult = $oChecker->get($a['name'], $a['db']['pass'], isset($a['db']['params']) && $a['db']['params'] ? $a['db']['params'] : array());
+        else
+			$aResult = $oChecker->get($sName);
+
+		if(!empty($a['reverse']) && !empty($a['values']))
+			$aResult = array_diff(array_keys($a['values']), (is_array($aResult) ? $aResult : array()));
+
+		return $aResult;
+    }
+
     protected function processTranslations($sType = 'insert')
     {
         $aType2Method = array(

+ 18 - 0
studio/template/scripts/BxBaseStudioFormView.php

@@ -199,6 +199,24 @@ class BxBaseStudioFormView extends BxDolStudioForm
 
         return $sInput . $sControl;
     }
+
+    /**
+     * Generate Reverse Checkbox Set Element
+     *
+     * @param  array  $aInput
+     * @return string
+     */
+    function genInputCheckboxSet(&$aInput)
+    {
+        $aCurValues = array();
+        if (isset($aInput['value']) && $aInput['value'])
+            $aCurValues = is_array($aInput['value']) ? $aInput['value'] : array();
+
+		if(!empty($aInput['reverse']))
+			$aCurValues = array_diff(array_keys($aInput['values']), $aCurValues);
+
+        return $this->_genInputsSet($aInput, 'checkbox', $aCurValues, '_isSelectedMultiple', '[]');
+    }
 }
 
 /** @} */

+ 3 - 2
studio/template/scripts/BxBaseStudioSettings.php

@@ -198,11 +198,13 @@ class BxBaseStudioSettings extends BxDolStudioSettings
                 );
                 break;
             case 'list':
+            case 'rlist':
                 $aField = array(
                     'type' => 'checkbox_set',
                     'name' => $aItem['name'],
                     'caption' => _t($aItem['caption']),
-                    'value' => explode(',', $aItem['value']),
+                    'value' => !empty($aItem['value']) ? explode(',', $aItem['value']) : array(),
+                	'reverse' => $aItem['type'] == 'rlist',
                     'db' => array (
                         'pass' => 'Xss',
                     ),
@@ -213,7 +215,6 @@ class BxBaseStudioSettings extends BxDolStudioSettings
                 else
                     foreach(explode(',', $aItem['extra']) as $sValue)
                         $aField['values'][$sValue] = $sValue;
-
                 break;
             case 'select':
                 $aField = array(