/**
|
* exam:data-bind="datepicker:stime,datepickerOptions:{dateFmt:'yyyy-MM-dd'}"
|
*
|
*
|
*/
|
|
ko.bindingHandlers.datepicker = {
|
init: function(element, valueAccessor, allBindingsAccessor) {
|
//initialize datepicker with some optional options
|
var options = allBindingsAccessor().datepickerOptions || {},
|
$el = $(element);
|
$el.click(function(event) {
|
/* Act on the event */
|
var fmt="yyyy-MM-dd";
|
if(options.dateFmt!=null&&options.dateFmt!='')
|
fmt=options.dateFmt;
|
WdatePicker({dateFmt:fmt,onpicked:function(fp){
|
var value=fp.cal.getNewDateStr();
|
var observable = valueAccessor();
|
observable(value);
|
return true;
|
}});
|
});
|
$el.blur(function(){
|
var $this=$(this);
|
var str=$this.val();
|
if(str==null||str==='')
|
{
|
var observable = valueAccessor();
|
observable(undefined);
|
}
|
return true;
|
});
|
// //handle the field changing
|
// ko.utils.registerEventHandler(element, "change", function () {
|
// var observable = valueAccessor();
|
// observable($el.val());
|
// });
|
},
|
update: function(element, valueAccessor) {
|
var value = ko.utils.unwrapObservable(valueAccessor()),
|
$el = $(element);
|
|
//handle date data coming via json from Microsoft
|
if (String(value).indexOf('/Date(') == 0) {
|
value = new Date(parseInt(value.replace(/\/Date\((.*?)\)\//gi, "$1")));
|
}
|
|
var current = $el.val();
|
|
if (value != current) {
|
$el.val(value);
|
}
|
}
|
};
|
|
/*
|
2015-01-03,mengly:添加了三个关于时间转换和有效期判断的方法,getdate,cpm_jinxq,isjinxiao,
|
同时修改getlist里面,近效期的只有重点养护,锁定的只能有锁定养护
|
*/
|
|
function getdate(date_str)
|
{
|
try{
|
if(date_str==undefined)
|
return null;
|
var ds=date_str.split('-');
|
if(ds.length<3)
|
return null;
|
var y=parseInt(ds[0]);
|
var m=parseInt(ds[1])-1;
|
var d=parseInt(ds[2]);
|
var date1=new Date(y,m,d);
|
return date1;
|
}catch(e){
|
return undefined;
|
}
|
}
|
//false:非近效期,true:近效期
|
function cpm_jinxq(nowdate,validdate)
|
{
|
try{
|
if(nowdate==undefined||validdate==undefined)
|
return true;
|
nowdate.setDate(nowdate.getDate()+30);
|
if(nowdate>=validdate)
|
return true;
|
}catch(e){
|
}
|
return false;
|
}
|
function isjinxiao(datestr)
|
{
|
var date=getdate(datestr);
|
if(date==undefined)
|
return true;
|
return cpm_jinxq(new Date(),date);
|
}
|