|
|
@@ -0,0 +1,119 @@
|
|
|
+/**
|
|
|
+ * Created by zhouy on 2018/11/12.
|
|
|
+ */
|
|
|
+Ext.define('saas.view.core.form.field.Month', {
|
|
|
+ extend:'Ext.form.field.Picker',
|
|
|
+ alias: 'widget.monthdatefield',
|
|
|
+ requires: ['Ext.picker.Month'],
|
|
|
+ format : "m/Y",
|
|
|
+ disabledDaysText : "Disabled",
|
|
|
+ disabledDatesText : "Disabled",
|
|
|
+ triggerCls : Ext.baseCSSPrefix + 'form-date-trigger',
|
|
|
+ matchFieldWidth: false,
|
|
|
+ componentCls: Ext.baseCSSPrefix + 'form-field-date',
|
|
|
+ ariaRole: 'combobox',
|
|
|
+ validateOnFocusLeave: true,
|
|
|
+ hideOnSelect:true,
|
|
|
+ editable:false,
|
|
|
+ autoValue:true,
|
|
|
+ initComponent: function() {
|
|
|
+ var me = this,
|
|
|
+ isString = Ext.isString,
|
|
|
+ min, max;
|
|
|
+
|
|
|
+ min = me.minValue;
|
|
|
+ max = me.maxValue;
|
|
|
+ if(isString(min)){
|
|
|
+ me.minValue = me.parseDate(min);
|
|
|
+ }
|
|
|
+ if(isString(max)){
|
|
|
+ me.maxValue = me.parseDate(max);
|
|
|
+ }
|
|
|
+ me.disabledDatesRE = null;
|
|
|
+ if(Ext.isEmpty(me.value)){
|
|
|
+ me.value=me.getCurrentVal();
|
|
|
+ }
|
|
|
+ me.callParent();
|
|
|
+ },
|
|
|
+ createPicker: function() {
|
|
|
+ var me = this,
|
|
|
+ picker = me.monthPicker,
|
|
|
+ format = Ext.String.format;
|
|
|
+ return me.monthPicker=picker=new Ext.picker.Month({
|
|
|
+ id: me.id + '-picker',
|
|
|
+ pickerField: me,
|
|
|
+ floating: true,
|
|
|
+ preventRefocus: true,
|
|
|
+ value:me.getPickerValues(),
|
|
|
+ format: me.format,
|
|
|
+ ownerCmp: me,
|
|
|
+ listeners: {
|
|
|
+ scope:me,
|
|
|
+ cancelclick: me.onCancelClick,
|
|
|
+ okclick: me.onOkClick,
|
|
|
+ yeardblclick: me.onOkClick,
|
|
|
+ monthdblclick: me.onOkClick
|
|
|
+ },
|
|
|
+ keyNavConfig: {
|
|
|
+ esc: function() {
|
|
|
+ me.inputEl.focus();
|
|
|
+ me.collapse();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ getActive: function(){
|
|
|
+ return this.activeDate || this.value;
|
|
|
+ },
|
|
|
+ onOkClick: function(picker, value) {
|
|
|
+ var me = this,
|
|
|
+ month = value[0],
|
|
|
+ year = value[1];
|
|
|
+ if (value.length == 2) {
|
|
|
+ month = month == null ? new Date().getMonth() : month;
|
|
|
+ month = Number(month) + 1;
|
|
|
+ month = month < 10 ? '0' + month : month;
|
|
|
+ year = year == null ? new Date().getFullYear() : year;
|
|
|
+ if (this.minValue) {
|
|
|
+ if (Number(year + '' + month) < this.minYearMonth) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (this.maxValue) {
|
|
|
+ if (Number(year + '' + month) > this.maxYearMonth) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.setValue(year + '' + month);
|
|
|
+ }
|
|
|
+ me.onSelect();
|
|
|
+ },
|
|
|
+ getCurrentVal:function(){
|
|
|
+ return Ext.Date.format(new Date(),'Ym');
|
|
|
+ },
|
|
|
+ onCancelClick: function() {
|
|
|
+ this.onSelect();
|
|
|
+ },
|
|
|
+ getPickerValues:function() {
|
|
|
+ var val = this.value, year, month;
|
|
|
+ if (val && val.length == 6) {
|
|
|
+ year = Ext.Number.from(val.substring(0, 4), 0);
|
|
|
+ month = Ext.Number.from(val.substring(4, 6), 0);
|
|
|
+ month = month-1;
|
|
|
+ } else {
|
|
|
+ year = new Date().getFullYear();
|
|
|
+ month = new Date().getMonth();
|
|
|
+ }
|
|
|
+ return [month, year];
|
|
|
+ },
|
|
|
+ setValue : function(value) {
|
|
|
+ if (Ext.isEmpty(value)) {
|
|
|
+ value =me.getCurrentVal();
|
|
|
+ }
|
|
|
+ this.callParent(arguments);
|
|
|
+ },
|
|
|
+ onSelect: function() {
|
|
|
+ this.monthPicker.hide();
|
|
|
+ }
|
|
|
+
|
|
|
+});
|