提交 | 用户 | 时间
|
58d006
|
1 |
/** |
A |
2 |
* exam:data-bind="datepicker:stime,datepickerOptions:{dateFmt:'yyyy-MM-dd'}" |
|
3 |
* |
|
4 |
* |
|
5 |
*/ |
|
6 |
|
|
7 |
ko.bindingHandlers.datepicker = { |
|
8 |
init: function(element, valueAccessor, allBindingsAccessor) { |
|
9 |
//initialize datepicker with some optional options |
|
10 |
var options = allBindingsAccessor().datepickerOptions || {}, |
|
11 |
$el = $(element); |
|
12 |
$el.click(function(event) { |
|
13 |
/* Act on the event */ |
|
14 |
var fmt="yyyy-MM-dd"; |
|
15 |
if(options.dateFmt!=null&&options.dateFmt!='') |
|
16 |
fmt=options.dateFmt; |
|
17 |
WdatePicker({dateFmt:fmt,onpicked:function(fp){ |
|
18 |
var value=fp.cal.getNewDateStr(); |
|
19 |
var observable = valueAccessor(); |
|
20 |
observable(value); |
|
21 |
return true; |
|
22 |
}}); |
|
23 |
}); |
|
24 |
$el.blur(function(){ |
|
25 |
var $this=$(this); |
|
26 |
var str=$this.val(); |
|
27 |
if(str==null||str==='') |
|
28 |
{ |
|
29 |
var observable = valueAccessor(); |
|
30 |
observable(undefined); |
|
31 |
} |
|
32 |
return true; |
|
33 |
}); |
|
34 |
// //handle the field changing |
|
35 |
// ko.utils.registerEventHandler(element, "change", function () { |
|
36 |
// var observable = valueAccessor(); |
|
37 |
// observable($el.val()); |
|
38 |
// }); |
|
39 |
}, |
|
40 |
update: function(element, valueAccessor) { |
|
41 |
var value = ko.utils.unwrapObservable(valueAccessor()), |
|
42 |
$el = $(element); |
|
43 |
|
|
44 |
//handle date data coming via json from Microsoft |
|
45 |
if (String(value).indexOf('/Date(') == 0) { |
|
46 |
value = new Date(parseInt(value.replace(/\/Date\((.*?)\)\//gi, "$1"))); |
|
47 |
} |
|
48 |
|
|
49 |
var current = $el.val(); |
|
50 |
|
|
51 |
if (value != current) { |
|
52 |
$el.val(value); |
|
53 |
} |
|
54 |
} |
|
55 |
}; |
|
56 |
|
|
57 |
/* |
|
58 |
2015-01-03,mengly:添加了三个关于时间转换和有效期判断的方法,getdate,cpm_jinxq,isjinxiao, |
|
59 |
同时修改getlist里面,近效期的只有重点养护,锁定的只能有锁定养护 |
|
60 |
*/ |
|
61 |
|
|
62 |
function getdate(date_str) |
|
63 |
{ |
|
64 |
try{ |
|
65 |
if(date_str==undefined) |
|
66 |
return null; |
|
67 |
var ds=date_str.split('-'); |
|
68 |
if(ds.length<3) |
|
69 |
return null; |
|
70 |
var y=parseInt(ds[0]); |
|
71 |
var m=parseInt(ds[1])-1; |
|
72 |
var d=parseInt(ds[2]); |
|
73 |
var date1=new Date(y,m,d); |
|
74 |
return date1; |
|
75 |
}catch(e){ |
|
76 |
return undefined; |
|
77 |
} |
|
78 |
} |
|
79 |
//false:非近效期,true:近效期 |
|
80 |
function cpm_jinxq(nowdate,validdate) |
|
81 |
{ |
|
82 |
try{ |
|
83 |
if(nowdate==undefined||validdate==undefined) |
|
84 |
return true; |
|
85 |
nowdate.setDate(nowdate.getDate()+30); |
|
86 |
if(nowdate>=validdate) |
|
87 |
return true; |
|
88 |
}catch(e){ |
|
89 |
} |
|
90 |
return false; |
|
91 |
} |
|
92 |
function isjinxiao(datestr) |
|
93 |
{ |
|
94 |
var date=getdate(datestr); |
|
95 |
if(date==undefined) |
|
96 |
return true; |
|
97 |
return cpm_jinxq(new Date(),date); |
|
98 |
} |