Skip to content

Commit

Permalink
fixed bug of calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoqing.dongxq committed Jun 4, 2014
1 parent d832306 commit dfb2ff1
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 22 deletions.
6 changes: 3 additions & 3 deletions build/bui-min.js

Large diffs are not rendered by default.

30 changes: 24 additions & 6 deletions build/bui.js
Expand Up @@ -29019,7 +29019,9 @@ define('bui/calendar/calendar',['bui/picker','bui/calendar/monthpicker','bui/cal
for(var key in lockTime){
var noCls = _timePickerEnum[key.toLowerCase()];
_self.set(key,lockTime[key]);
_self.get('el').find("."+noCls).attr("disabled","");
if(!lockTime.editable){
_self.get('el').find("."+noCls).attr("disabled","");
}
}
}
var picker = new Picker({
Expand Down Expand Up @@ -29077,7 +29079,11 @@ define('bui/calendar/calendar',['bui/picker','bui/calendar/monthpicker','bui/cal
selectedDate = _self.get('selectedDate'),
date = selectedDate.getDate();
if(year !== selectedDate.getFullYear() || month !== selectedDate.getMonth()){
_self.set('selectedDate',new Date(year,month,date));
var newDate = new Date(year,month,date);
if(newDate.getMonth() != month){ //\u4e0b\u4e00\u4e2a\u6708\u6ca1\u6709\u5bf9\u5e94\u7684\u65e5\u671f,\u5b9a\u4f4d\u5230\u4e0b\u4e00\u4e2a\u6708\u6700\u540e\u4e00\u5929
newDate = DateUtil.addDay(-1,new Date(year,month + 1));
}
_self.set('selectedDate',newDate);
}
},
//\u521b\u5efa\u9009\u62e9\u6708\u7684\u63a7\u4ef6
Expand Down Expand Up @@ -29447,11 +29453,22 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
date = DateUtil.parse(val,_self.get("dateMask"));
date = date || _self.get('selectedDate');
calendar.set('selectedDate',DateUtil.getDate(date));

if(_self.get('showTime')){

var lockTime = this.get("lockTime"),
hour = lockTime&&lockTime['hour']?lockTime['hour']:date.getHours(),
minute = lockTime&&lockTime['minute']?lockTime['minute']:date.getMinutes(),
second = lockTime&&lockTime['second']?lockTime['second']:date.getSeconds();
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds();

if(lockTime){
if(!val || !lockTime.editable){
hour = lockTime&&lockTime['hour']?lockTime['hour']:hour,
minute = lockTime&&lockTime['minute']?lockTime['minute']:hour,
second = lockTime&&lockTime['second']?lockTime['second']:hour;
}
}

calendar.set('hour',hour);
calendar.set('minute',minute);
calendar.set('second',second);
Expand Down Expand Up @@ -29525,7 +29542,7 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
value:false
},
/**
* \u9501\u5b9a\u65f6\u95f4\u9009\u62e9
* \u9501\u5b9a\u65f6\u95f4\u9009\u62e9\uff0c\u9ed8\u8ba4\u9501\u5b9a\u7684\u65f6\u95f4\u4e0d\u80fd\u4fee\u6539\u53ef\u4ee5\u901a\u8fc7 editable : true \u6765\u5141\u8bb8\u4fee\u6539\u9501\u5b9a\u7684\u65f6\u95f4
*<pre><code>
* var calendar = new Calendar.Calendar({
* render:'#calendar',
Expand All @@ -29536,6 +29553,7 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
* @type {Object}
*/
lockTime :{

},
/**
* \u6700\u5927\u65e5\u671f
Expand Down
2 changes: 1 addition & 1 deletion build/calendar-min.js

Large diffs are not rendered by default.

30 changes: 24 additions & 6 deletions build/calendar.js
Expand Up @@ -1038,7 +1038,9 @@ define('bui/calendar/calendar',['bui/picker','bui/calendar/monthpicker','bui/cal
for(var key in lockTime){
var noCls = _timePickerEnum[key.toLowerCase()];
_self.set(key,lockTime[key]);
_self.get('el').find("."+noCls).attr("disabled","");
if(!lockTime.editable){
_self.get('el').find("."+noCls).attr("disabled","");
}
}
}
var picker = new Picker({
Expand Down Expand Up @@ -1096,7 +1098,11 @@ define('bui/calendar/calendar',['bui/picker','bui/calendar/monthpicker','bui/cal
selectedDate = _self.get('selectedDate'),
date = selectedDate.getDate();
if(year !== selectedDate.getFullYear() || month !== selectedDate.getMonth()){
_self.set('selectedDate',new Date(year,month,date));
var newDate = new Date(year,month,date);
if(newDate.getMonth() != month){ //下一个月没有对应的日期,定位到下一个月最后一天
newDate = DateUtil.addDay(-1,new Date(year,month + 1));
}
_self.set('selectedDate',newDate);
}
},
//创建选择月的控件
Expand Down Expand Up @@ -1466,11 +1472,22 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
date = DateUtil.parse(val,_self.get("dateMask"));
date = date || _self.get('selectedDate');
calendar.set('selectedDate',DateUtil.getDate(date));

if(_self.get('showTime')){

var lockTime = this.get("lockTime"),
hour = lockTime&&lockTime['hour']?lockTime['hour']:date.getHours(),
minute = lockTime&&lockTime['minute']?lockTime['minute']:date.getMinutes(),
second = lockTime&&lockTime['second']?lockTime['second']:date.getSeconds();
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds();

if(lockTime){
if(!val || !lockTime.editable){
hour = lockTime&&lockTime['hour']?lockTime['hour']:hour,
minute = lockTime&&lockTime['minute']?lockTime['minute']:hour,
second = lockTime&&lockTime['second']?lockTime['second']:hour;
}
}

calendar.set('hour',hour);
calendar.set('minute',minute);
calendar.set('second',second);
Expand Down Expand Up @@ -1544,7 +1561,7 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
value:false
},
/**
* 锁定时间选择
* 锁定时间选择,默认锁定的时间不能修改可以通过 editable : true 来允许修改锁定的时间
*<pre><code>
* var calendar = new Calendar.Calendar({
* render:'#calendar',
Expand All @@ -1555,6 +1572,7 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
* @type {Object}
*/
lockTime :{

},
/**
* 最大日期
Expand Down
10 changes: 8 additions & 2 deletions src/calendar/calendar.js
Expand Up @@ -148,7 +148,9 @@ define('bui/calendar/calendar',['bui/picker','bui/calendar/monthpicker','bui/cal
for(var key in lockTime){
var noCls = _timePickerEnum[key.toLowerCase()];
_self.set(key,lockTime[key]);
_self.get('el').find("."+noCls).attr("disabled","");
if(!lockTime.editable){
_self.get('el').find("."+noCls).attr("disabled","");
}
}
}
var picker = new Picker({
Expand Down Expand Up @@ -206,7 +208,11 @@ define('bui/calendar/calendar',['bui/picker','bui/calendar/monthpicker','bui/cal
selectedDate = _self.get('selectedDate'),
date = selectedDate.getDate();
if(year !== selectedDate.getFullYear() || month !== selectedDate.getMonth()){
_self.set('selectedDate',new Date(year,month,date));
var newDate = new Date(year,month,date);
if(newDate.getMonth() != month){ //下一个月没有对应的日期,定位到下一个月最后一天
newDate = DateUtil.addDay(-1,new Date(year,month + 1));
}
_self.set('selectedDate',newDate);
}
},
//创建选择月的控件
Expand Down
20 changes: 16 additions & 4 deletions src/calendar/datepicker.js
Expand Up @@ -82,11 +82,22 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
date = DateUtil.parse(val,_self.get("dateMask"));
date = date || _self.get('selectedDate');
calendar.set('selectedDate',DateUtil.getDate(date));

if(_self.get('showTime')){

var lockTime = this.get("lockTime"),
hour = lockTime&&lockTime['hour']?lockTime['hour']:date.getHours(),
minute = lockTime&&lockTime['minute']?lockTime['minute']:date.getMinutes(),
second = lockTime&&lockTime['second']?lockTime['second']:date.getSeconds();
hour = date.getHours(),
minute = date.getMinutes(),
second = date.getSeconds();

if(lockTime){
if(!val || !lockTime.editable){
hour = lockTime&&lockTime['hour']?lockTime['hour']:hour,
minute = lockTime&&lockTime['minute']?lockTime['minute']:hour,
second = lockTime&&lockTime['second']?lockTime['second']:hour;
}
}

calendar.set('hour',hour);
calendar.set('minute',minute);
calendar.set('second',second);
Expand Down Expand Up @@ -160,7 +171,7 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
value:false
},
/**
* 锁定时间选择
* 锁定时间选择,默认锁定的时间不能修改可以通过 editable : true 来允许修改锁定的时间
*<pre><code>
* var calendar = new Calendar.Calendar({
* render:'#calendar',
Expand All @@ -171,6 +182,7 @@ define('bui/calendar/datepicker',['bui/common','bui/picker','bui/calendar/calend
* @type {Object}
*/
lockTime :{

},
/**
* 最大日期
Expand Down

0 comments on commit dfb2ff1

Please sign in to comment.