Просмотр исходного кода

Ticket #290 - Uploaders chooser in Forms engine. Applied to Albums, Posts, Market.

AntonLV 10 лет назад
Родитель
Сommit
b71f792b34

+ 1 - 1
modules/base/text/classes/BxBaseModTextFormEntry.php

@@ -29,7 +29,7 @@ class BxBaseModTextFormEntry extends BxBaseModGeneralFormEntry
 
         if (isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
             $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE'];
-            $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = $CNF['OBJECT_UPLOADERS'];
+            $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
             $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
             $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
             $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;

+ 1 - 1
modules/boonex/albums/install/sql/install.sql

@@ -265,7 +265,7 @@ INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `ch
 ('bx_albums', 'bx_albums', 'do_submit', '_bx_albums_form_entry_input_do_submit', '', 0, 'submit', '_bx_albums_form_entry_input_sys_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_albums', 'bx_albums', 'title', '', '', 0, 'text', '_bx_albums_form_entry_input_sys_title', '_bx_albums_form_entry_input_title', '', 1, 0, 0, '', '', '', 'avail', '', '_bx_albums_form_entry_input_title_err', 'Xss', '', 1, 0),
 ('bx_albums', 'bx_albums', 'text', '', '', 0, 'textarea', '_bx_albums_form_entry_input_sys_text', '_bx_albums_form_entry_input_text', '', 0, 0, 2, '', '', '', '', '', '', 'XssHtml', '', 1, 0),
-('bx_albums', 'bx_albums', 'pictures', '', '', 0, 'files', '_bx_albums_form_entry_input_sys_pictures', '_bx_albums_form_entry_input_pictures', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
+('bx_albums', 'bx_albums', 'pictures', 'a:1:{i:0;s:15:"bx_albums_html5";}', 'a:2:{s:16:"bx_albums_simple";s:26:"_sys_uploader_simple_title";s:15:"bx_albums_html5";s:25:"_sys_uploader_html5_title";}', 0, 'files', '_bx_albums_form_entry_input_sys_pictures', '_bx_albums_form_entry_input_pictures', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_albums', 'bx_albums', 'allow_view_to', '', '', 0, 'custom', '_bx_albums_form_entry_input_sys_allow_view_to', '_bx_albums_form_entry_input_allow_view_to', '', 1, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
 ('bx_albums', 'bx_albums', 'location', '', '', 0, 'custom', '_sys_form_input_sys_location', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0);
 

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -779,6 +779,7 @@
 	<string name="_adm_form_txt_field_value_checkbox"><![CDATA[Value]]></string>
 	<string name="_adm_form_txt_field_value_custom_text"><![CDATA[Custom text]]></string>
 	<string name="_adm_form_txt_field_value_default"><![CDATA[Default value]]></string>
+	<string name="_adm_form_txt_field_value_files"><![CDATA[Enabled uploaders]]></string>
 	<string name="_adm_form_txt_field_value_select_value"><![CDATA[Select value...]]></string>
 	<string name="_adm_form_txt_field_values"><![CDATA[Values]]></string>
 	<string name="_adm_form_txt_field_values_manage"><![CDATA[Manage values]]></string>

+ 1 - 1
modules/boonex/market/classes/BxMarketFormEntry.php

@@ -30,7 +30,7 @@ class BxMarketFormEntry extends BxBaseModTextFormEntry
 
 	    if(isset($this->aInputs[$CNF['FIELD_FILE']])) {
             $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $CNF['OBJECT_STORAGE_FILES'];
-            $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = $CNF['OBJECT_UPLOADERS'];
+            $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] =  !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $CNF['OBJECT_UPLOADERS'];
             $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = '';
             $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 1;
             $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true;

+ 2 - 2
modules/boonex/market/install/sql/install.sql

@@ -250,8 +250,8 @@ INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `ch
 ('bx_market', 'bx_market', 'do_publish', '_bx_market_form_entry_input_do_publish', '', 0, 'submit', '_bx_market_form_entry_input_sys_do_publish', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_market', 'bx_market', 'do_submit', '_bx_market_form_entry_input_do_submit', '', 0, 'submit', '_bx_market_form_entry_input_sys_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_market', 'bx_market', 'location', '', '', 0, 'custom', '_sys_form_input_sys_location', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
-('bx_market', 'bx_market', 'pictures', '', '', 0, 'files', '_bx_market_form_entry_input_sys_pictures', '_bx_market_form_entry_input_pictures', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
-('bx_market', 'bx_market', 'files', '', '', 0, 'files', '_bx_market_form_entry_input_sys_files', '_bx_market_form_entry_input_files', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
+('bx_market', 'bx_market', 'pictures', 'a:1:{i:0;s:15:"bx_market_html5";}', 'a:2:{s:16:"bx_market_simple";s:26:"_sys_uploader_simple_title";s:15:"bx_market_html5";s:25:"_sys_uploader_html5_title";}', 0, 'files', '_bx_market_form_entry_input_sys_pictures', '_bx_market_form_entry_input_pictures', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
+('bx_market', 'bx_market', 'files', 'a:1:{i:0;s:15:"bx_market_html5";}', 'a:2:{s:16:"bx_market_simple";s:26:"_sys_uploader_simple_title";s:15:"bx_market_html5";s:25:"_sys_uploader_html5_title";}', 0, 'files', '_bx_market_form_entry_input_sys_files', '_bx_market_form_entry_input_files', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_market', 'bx_market', 'text', '', '', 0, 'textarea', '_bx_market_form_entry_input_sys_text', '_bx_market_form_entry_input_text', '', 1, 0, 2, '', '', '', 'Avail', '', '_bx_market_form_entry_input_text_err', 'XssHtml', '', 1, 0),
 ('bx_market', 'bx_market', 'title', '', '', 0, 'text', '_bx_market_form_entry_input_sys_title', '_bx_market_form_entry_input_title', '', 1, 0, 0, '', '', '', 'Avail', '', '_bx_market_form_entry_input_title_err', 'Xss', '', 1, 0),
 ('bx_market', 'bx_market', 'name', '', '', 0, 'text', '_bx_market_form_entry_input_sys_name', '_bx_market_form_entry_input_name', '', 1, 0, 0, '', '', '', 'Avail', '', '_bx_market_form_entry_input_name_err', 'Xss', '', 1, 0),

+ 1 - 1
modules/boonex/posts/install/sql/install.sql

@@ -176,7 +176,7 @@ INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `ch
 ('bx_posts', 'bx_posts', 'do_publish', '_bx_posts_form_entry_input_do_publish', '', 0, 'submit', '_bx_posts_form_entry_input_sys_do_publish', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_posts', 'bx_posts', 'do_submit', '_bx_posts_form_entry_input_do_submit', '', 0, 'submit', '_bx_posts_form_entry_input_sys_do_submit', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_posts', 'bx_posts', 'location', '', '', 0, 'custom', '_sys_form_input_sys_location', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
-('bx_posts', 'bx_posts', 'pictures', '', '', 0, 'files', '_bx_posts_form_entry_input_sys_pictures', '_bx_posts_form_entry_input_pictures', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
+('bx_posts', 'bx_posts', 'pictures', 'a:1:{i:0;s:9:"sys_html5";}', 'a:2:{s:10:"sys_simple";s:26:"_sys_uploader_simple_title";s:9:"sys_html5";s:25:"_sys_uploader_html5_title";}', 0, 'files', '_bx_posts_form_entry_input_sys_pictures', '_bx_posts_form_entry_input_pictures', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0),
 ('bx_posts', 'bx_posts', 'text', '', '', 0, 'textarea', '_bx_posts_form_entry_input_sys_text', '_bx_posts_form_entry_input_text', '', 1, 0, 2, '', '', '', 'Avail', '', '_bx_posts_form_entry_input_text_err', 'XssHtml', '', 1, 0),
 ('bx_posts', 'bx_posts', 'title', '', '', 0, 'text', '_bx_posts_form_entry_input_sys_title', '_bx_posts_form_entry_input_title', '', 1, 0, 0, '', '', '', 'Avail', '', '_bx_posts_form_entry_input_title_err', 'Xss', '', 1, 0),
 ('bx_posts', 'bx_posts', 'cat', '', '#!bx_posts_cats', 0, 'select', '_bx_posts_form_entry_input_sys_cat', '_bx_posts_form_entry_input_cat', '', 1, 0, 0, '', '', '', 'avail', '', '_bx_posts_form_entry_input_cat_err', 'Xss', '', 1, 0);

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -779,6 +779,7 @@
 	<string name="_adm_form_txt_field_value_checkbox"><![CDATA[Значение]]></string>
 	<string name="_adm_form_txt_field_value_custom_text"><![CDATA[Индивидуальный текст]]></string>
 	<string name="_adm_form_txt_field_value_default"><![CDATA[Значение по умолчанию]]></string>
+	<string name="_adm_form_txt_field_value_files"><![CDATA[Активные загрузчики]]></string>
 	<string name="_adm_form_txt_field_value_select_value"><![CDATA[Выбрать значение...]]></string>
 	<string name="_adm_form_txt_field_values"><![CDATA[Значения]]></string>
 	<string name="_adm_form_txt_field_values_manage"><![CDATA[Управление значениями]]></string>

+ 109 - 5
studio/template/scripts/BxBaseStudioFormsField.php

@@ -183,6 +183,7 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
                     case 'value':
                         $aForm['inputs'][$sKey]['value'] = $this->aField[$sKey];
 
+                        //--- Select, Multi Select, Radio Set and Checkbox Set
                         if(in_array($aForm['inputs']['type']['value'], array('select', 'select_multiple', 'radio_set', 'checkbox_set'))) {
                             $sList = trim($this->getFieldValues($this->aField), BX_DATA_LISTS_KEY_PREFIX . ' ');
 
@@ -198,7 +199,22 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
                             foreach($aPreValues as $mixedValue => $sTitle)
                                  $aForm['inputs'][$sKey]['values'][] = array('key' => $mixedValue, 'value' => $sTitle);
                         }
+
+                        //--- Files
+                        if(in_array($aForm['inputs']['type']['value'], array('files'))) {
+                        	if(!empty($aForm['inputs'][$sKey]['value']))
+                        		$aForm['inputs'][$sKey]['value'] = unserialize($aForm['inputs'][$sKey]['value']);
+
+                        	$aValues = unserialize($this->getFieldValues($this->aField));
+                        	if(!empty($aValues) && is_array($aValues)) {
+                        		$aForm['inputs'][$sKey]['values'] = array();
+
+	                        	foreach($aValues as $mixedValue => $sTitle)
+									$aForm['inputs'][$sKey]['values'][$mixedValue] = _t($sTitle);
+                        	}
+                        }
                         break;
+
                     case 'values':
                         if(!empty($this->aField[$sKey]))
                             $aForm['inputs'][$sKey]['value'] = $this->getFieldValues($this->aField);
@@ -218,17 +234,21 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
                             unset($aForm['inputs'][$sKey]['values'], $aForm['inputs'][$sKey]['db']);
                         }
                         break;
+
                     case 'checked':
                         $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
                         break;
+
                     case 'collapsed':
                         $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
                         break;
+
                     case 'required':
                         $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
                         if($aForm['inputs'][$sKey]['checked'] == 1 && isset($aForm['inputs']['checker_func']))
                             unset($aForm['inputs']['checker_func']['tr_attrs']['style'], $aForm['inputs']['checker_error']['tr_attrs']['style']);
                         break;
+
                     case 'checker_func':
                         $aForm['inputs'][$sKey]['value'] = strtolower($this->aField[$sKey]);
                         switch($aForm['inputs'][$sKey]['value']) {
@@ -240,40 +260,50 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
                                 break;
                         }
                         break;
+
                     case 'checker_params_length_min':
                         $aParams = unserialize($this->aField['checker_params']);
                         $aForm['inputs'][$sKey]['value'] = isset($aParams['min']) ? (int)$aParams['min'] : 0;
                         break;
+
                     case 'checker_params_length_max':
                         $aParams = unserialize($this->aField['checker_params']);
                         $aForm['inputs'][$sKey]['value'] = isset($aParams['max']) ? (int)$aParams['max'] : 0;
                         break;
+
                     case 'checker_params_preg':
                         $aParams = unserialize($this->aField['checker_params']);
                         $aForm['inputs'][$sKey]['value'] = isset($aParams['preg']) ? $aParams['preg'] : '';
                         break;
+
                     case 'attrs_min':
                         $aParams = unserialize($this->aField['attrs']);
                         $aForm['inputs'][$sKey]['value'] = isset($aParams['min']) ? (int)$aParams['min'] : 0;
                         break;
+
                     case 'attrs_max':
                         $aParams = unserialize($this->aField['attrs']);
                         $aForm['inputs'][$sKey]['value'] = isset($aParams['max']) ? (int)$aParams['max'] : 100;
                         break;
+
                     case 'attrs_step':
                         $aParams = unserialize($this->aField['attrs']);
                         $aForm['inputs'][$sKey]['value'] = isset($aParams['step']) ? (int)$aParams['step'] : 1;
                         break;
+
                     case 'attrs_src':
                         $aParams = unserialize($this->aField['attrs']);
                         $aForm['inputs'][$sKey]['value'] = isset($aParams['src']) ? $aParams['src'] : '';
                         break;
+
                     case 'editable':
                         $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
                         break;
+
 					case 'deletable':
                         $aForm['inputs'][$sKey]['checked'] = (int)$this->aField[$sKey];
                         break;
+
                     default:
                         $aForm['inputs'][$sKey]['value'] = $this->aField[$sKey];
                 }
@@ -368,8 +398,13 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
             case 'radio_set':
                 $mixedResult = $this->aField['values'];
                 break;
+
             case 'input_set':
                 $mixedResult = $this->aField['values'];
+                break;
+
+			case 'files':
+                $mixedResult = $this->aField['values'];
                 break;
         }
 
@@ -563,11 +598,8 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
     protected function onSubmitField(&$oForm)
     {
         //--- Process field values.
-        if(isset($oForm->aInputs['values']['db'])) {
-            $sValues = $oForm->getCleanValue('values');
-            if(is_string($sValues) && strpos($sValues, BX_DATA_LISTS_KEY_PREFIX) === false)
-                BxDolForm::setSubmittedValue('values', serialize(explode("\n", $sValues)), $oForm->aFormAttrs['method']);
-        }
+        if(isset($oForm->aInputs['values']['db'])) 
+        	$this->onSubmitFieldValues($oForm);
 
         //--- Process field 'html' flag.
         if(isset($oForm->aInputs['html'])) {
@@ -599,6 +631,13 @@ class BxBaseStudioFormsField extends BxDolStudioFormsField
         unset($oForm->aInputs['attrs_min'], $oForm->aInputs['attrs_max'], $oForm->aInputs['attrs_step'], $oForm->aInputs['attrs_src']);
         BxDolForm::setSubmittedValue('attrs', serialize($aAttrs), $oForm->aFormAttrs['method']);
     }
+
+    protected function onSubmitFieldValues(&$oForm)
+    {
+    	$sValues = $oForm->getCleanValue('values');
+		if(is_string($sValues) && strpos($sValues, BX_DATA_LISTS_KEY_PREFIX) === false)
+        	BxDolForm::setSubmittedValue('values', serialize(explode("\n", $sValues)), $oForm->aFormAttrs['method']);
+    }
 }
 
 class BxBaseStudioFormsFieldBlockHeader extends BxBaseStudioFormsField
@@ -965,6 +1004,71 @@ class BxBaseStudioFormsFieldFiles extends BxBaseStudioFormsFieldFile
     function __construct($aParams = array(), $aField = array())
     {
         parent::__construct($aParams, $aField);
+
+        $aFields = array(
+        	'values' => array(
+                'type' => 'hidden',
+                'name' => 'values',
+                'value' => '',
+                'db' => array (
+                    'pass' => 'Xss',
+                )
+            ),
+        	'value' => array(
+                'type' => 'checkbox_set',
+                'name' => 'value',
+                'caption' => _t('_adm_form_txt_field_value_files'),
+                'info' => '',
+                'value' => array(),
+            	'values' => array(),
+                'required' => '0',
+                'db' => array (
+                    'pass' => 'Xss',
+                )
+            )
+        );
+
+        $aUploaders = array(
+        	'sys_simple' => '_sys_uploader_simple_title', 
+        	'sys_html5' => '_sys_uploader_html5_title'
+        );
+        foreach($aUploaders as $sObject => $sTitle) {
+        	$aUploader = BxDolUploaderQuery::getUploaderObject($sObject);
+        	if(empty($aUploader) || !is_array($aUploader) || (int)$aUploader['active'] == 0)
+        		continue;
+
+			$aFields['values']['value'][$sObject] = $sTitle;
+        	$aFields['value']['values'][$sObject] = _t($sTitle);
+        }
+
+        if(!empty($aFields['values']['value']) && is_array($aFields['values']['value']))
+        	$aFields['values']['value'] = serialize($aFields['values']['value']);
+
+        $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'required', $aFields);
+    }
+
+    protected function onSubmitField(&$oForm)
+    {
+    	//--- Process field value.
+        if(isset($oForm->aInputs['value']['db'])) 
+        	$this->onSubmitFieldValue($oForm);
+
+		parent::onSubmitField($oForm);
+    }
+
+	protected function onSubmitFieldValue(&$oForm)
+    {
+    	$mixedValue = $oForm->getCleanValue('value');
+		if(is_array($mixedValue))
+			BxDolForm::setSubmittedValue('value', serialize($mixedValue), $oForm->aFormAttrs['method']);
+    }
+
+    /*
+     * Note. Value of Values should be saved as is in case of 'Files' field.
+     */
+	protected function onSubmitFieldValues(&$oForm)
+    {
+		return;
     }
 }