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

#2706 Use simpler date inputs for some fields without datepicker, like date of birth

RomanL 4 лет назад
Родитель
Сommit
21b64ad9b2

+ 1 - 0
inc/classes/BxDolForm.php

@@ -92,6 +92,7 @@ bx_import('BxDolPrivacy');
  *      - doublerange - select range values within the range using slider control.
  *      - datepicker - date selection control.
  *      - datetime - date/time selection control.
+ *      - dateselect - date selection control (alternative).
  *      - captcha - image captcha.
  *      - hidden - hidden input field.
  *      - file - file upload input.

+ 13 - 1
inc/js/jquery.webForms.js

@@ -247,7 +247,7 @@
             }
 
 			// Date/Time pickers
-			if (this.getAttribute("type") == "date" || this.getAttribute("type") == "date_calendar" || this.getAttribute("type") == "datetime" || this.getAttribute("type") == "date_time" || this.getAttribute("type") == "datepicker") {
+			if (this.getAttribute("type") == "date" || this.getAttribute("type") == "date_calendar" || this.getAttribute("type") == "datetime" || this.getAttribute("type") == "date_time" || this.getAttribute("type") == "datepicker" || this.getAttribute("type") == "dateselect") {
                 if ($(this).hasClass('bx-form-datepicker-processed'))
                     return;
                 $(this).addClass('bx-form-datepicker-processed');
@@ -299,6 +299,18 @@
                     }
                     
                     $(this).datetimepicker(oPickerOptions);
+                } else if(this.getAttribute("type") == "dateselect") { // DateTime selector
+                    moment.locale(sLang);
+                    $(this).combodate({
+                        minYear: iYearMin,
+                        maxYear: iYearMax,
+                        format: 'YYYY-MM-DD',
+                        template: 'DD MMMM YYYY',
+                        firstItem: 'none',
+                        'smartDays': true,
+                        customClass: 'bx-def-font-inputs bx-form-input-select block w-full py-2 px-3 border border-gray-300 dark:border-gray-700 rounded-md shadow-sm bg-white dark:bg-gray-900 placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 focus:ring-2 focus:text-gray-900 dark:focus:text-gray-100 focus:ring-blue-500 focus:border-opacity-70 focus:ring-opacity-20 focus:border-blue-500 text-sm text-gray-700 dark:text-gray-300 appearance-none',
+                    });  
+                    console.log('xxxx'+iYearMin);
                 }
 
                 if (window.navigator.appVersion.search(/Chrome\/(.*?) /) == -1 || parseInt(window.navigator.appVersion.match(/Chrome\/(\d+)\./)[1], 10) < 24)

+ 10 - 0
modules/boonex/developer/classes/BxDevFormsField.php

@@ -109,6 +109,16 @@ class BxDevFormsFieldDatepicker extends BxTemplStudioFormsFieldDatepicker
     }
 }
 
+class BxDevFormsFieldDateselect extends BxTemplStudioFormsFieldDateselect
+{
+    public function init()
+	{
+		parent::init();
+
+        BxDevFunctions::changeFormField($this->aParams, $this->aForm['inputs'], $this->oDb);
+    }
+}
+
 class BxDevFormsFieldDatetime extends BxTemplStudioFormsFieldDatetime
 {
     public function init()

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

@@ -935,6 +935,7 @@
 	<string name="_adm_form_txt_field_type_checkbox_set"><![CDATA[checkbox set]]></string>
 	<string name="_adm_form_txt_field_type_custom"><![CDATA[custom]]></string>
 	<string name="_adm_form_txt_field_type_datepicker"><![CDATA[date]]></string>
+    <string name="_adm_form_txt_field_type_dateselect"><![CDATA[date select]]></string>
 	<string name="_adm_form_txt_field_type_datepicker_range"><![CDATA[date range]]></string>
 	<string name="_adm_form_txt_field_type_datepicker_range_age"><![CDATA[age range]]></string>
 	<string name="_adm_form_txt_field_type_datetime"><![CDATA[date time]]></string>

+ 3 - 2
studio/classes/BxDolStudioFormsField.php

@@ -68,8 +68,9 @@ class BxDolStudioFormsField extends BxDol
             'select' => array('types' => array('select', 'radio_set'), 'reload_on_change' => 0),
             'radio_set' => array('types' => array('select', 'radio_set'), 'reload_on_change' => 0),
 
-            'datepicker' => array('types' => array('datepicker', 'datetime'), 'reload_on_change' => 1),
-            'datetime' => array('types' => array('datepicker', 'datetime'), 'reload_on_change' => 1),
+            'datepicker' => array('types' => array('datepicker', 'datetime', 'dateselect'), 'reload_on_change' => 1),
+            'datetime' => array('types' => array('datepicker', 'datetime', 'dateselect'), 'reload_on_change' => 1),
+            'dateselect' => array('types' => array('datepicker', 'datetime', 'dateselect'), 'reload_on_change' => 1),
 
             'checkbox' => array('types' => array('checkbox', 'switcher'), 'reload_on_change' => 0),
             'switcher' => array('types' => array('checkbox', 'switcher'), 'reload_on_change' => 0),

+ 45 - 0
studio/template/scripts/BxBaseStudioFormsField.php

@@ -1406,6 +1406,51 @@ class BxBaseStudioFormsFieldDatepicker extends BxBaseStudioFormsFieldText
     }
 }
 
+class BxBaseStudioFormsFieldDateselect extends BxBaseStudioFormsFieldText
+{
+    protected $sType = 'dateselect';
+    protected $aCheckFunctions = array('date','date_range');
+    protected $sDbPass = 'DateTs';
+    protected $aDbPassDependency = array(
+        'Date' => array('alter' => 'date'),
+    	'DateTs' => array('alter' => 'int(11)'),
+    	'DateUtc' => array('alter' => 'int(11)'),
+    );
+
+    public function init()
+	{
+		parent::init();
+
+        $this->aParams['table_field_type'] = 'int(11)';
+
+        $this->aForm['inputs']['value']['type'] = $this->sType;
+        $this->aForm['inputs']['value']['db']['pass'] = $this->sDbPass;
+
+        $aFields = array(
+            'db_pass' => array(
+                'type' => 'select',
+                'name' => 'db_pass',
+                'caption' => _t('_adm_form_txt_field_db_pass'),
+                'info' => _t('_adm_form_dsc_field_db_pass'),
+                'value' => $this->sDbPass,
+                'values' => array(
+                    array('key' => '', 'value' => _t('_adm_form_txt_field_db_pass_select_value')),
+                    array('key' => 'Date', 'value' => _t('_adm_form_txt_field_db_pass_date')),
+                    array('key' => 'DateTs', 'value' => _t('_adm_form_txt_field_db_pass_date_ts')),
+                    array('key' => 'DateUtc', 'value' => _t('_adm_form_txt_field_db_pass_date_utc')),
+                ),
+                'required' => '0',
+                'db' => array (
+                    'pass' => 'Xss',
+                )
+            ),
+        );
+
+        unset($this->aForm['inputs']['db_pass']);
+        $this->aForm['inputs'] = $this->addInArray($this->aForm['inputs'], 'controls', $aFields, false);
+    }
+}
+
 class BxBaseStudioFormsFieldDatetime extends BxBaseStudioFormsFieldDatepicker
 {
     protected $sType = 'datetime';

+ 4 - 0
studio/template/scripts_templ/BxTemplStudioFormsField.php

@@ -53,6 +53,10 @@ class BxTemplStudioFormsFieldDatepicker extends BxBaseStudioFormsFieldDatepicker
 {
 }
 
+class BxTemplStudioFormsFieldDateselect extends BxBaseStudioFormsFieldDateselect
+{
+}
+
 class BxTemplStudioFormsFieldDatetime extends BxBaseStudioFormsFieldDatetime
 {
 }

+ 1 - 0
template/_header_js.html

@@ -1,5 +1,6 @@
 <script language="javascript">
     var sUrlRoot = '<bx_url_root />';
+    var sLang = '__lang_country__';
 
     $(document).ready(function () {
         bx_time('__lang_country__');

+ 7 - 0
template/css/forms.css

@@ -260,6 +260,13 @@
     width:7.5rem;
 }
 
+.bx-form-input-wrapper-dateselect select{
+    min-width:70px;
+}
+.bx-form-input-wrapper-dateselect select.month{
+    min-width:120px;
+}
+
 .bx-form-input-datetime {
     width:10.2rem;
 }

+ 7 - 0
template/scripts/BxBaseFormView.php

@@ -691,6 +691,7 @@ BLAH;
                 $sValue = $this->genViewRowValueForSelect($aInput);
             break;
 
+            case 'dateselect':    
             case 'datepicker':
                 $sValue = null;
                 if (empty($aInput['value']) || !$aInput['value'] || '0000-00-00' == $aInput['value'])
@@ -1017,6 +1018,7 @@ BLAH;
             // standard inputs (and non-standard, interpreted as standard)
             case 'text':
             case 'datepicker':
+            case 'dateselect':
             case 'date_time':
             case 'datetime':
             case 'number':
@@ -1203,6 +1205,11 @@ BLAH;
             case 'datepicker':
                 $this->addCssJsUi ();
                 break;
+            case 'dateselect':
+                $this->_addJs(array(
+                    'combodate/combodate.js',
+                ), "'undefined' === typeof($.combodate)");
+                break;
             case 'text':
                 if (isset($aAttrs['class']) && false !== strpos($aAttrs['class'], 'bx-form-input-rgb'))
                     $this->addCssJsMinicolors ();