Administrator
2022-10-09 23f93897d618a5253a18b65b124196f95891f240
提交 | 用户 | 时间
58d006 1 window.I = {}
A 2 var basic=getpath();
3 var modelview=function() {
4     var self=this;
5     self.opers=ko.observableArray();
6     self.oper=ko.observable({
7             id:ko.observable(0),
8             title:ko.observable(),
9             name:ko.observable(),
10             exp:ko.observable(0),
11             value:ko.observable(0)
12     });
13     self.rm=function(item){
14         jQuery.post(basic+'/admin/opercon/rm.htm', {id:item.id}, function(data, textStatus, xhr) {
15             if(data==null)
16                 return;
17             if(data.code==0)
18             {
19                 self.opers.remove(item);
20             }else{
21                 alert(data.errmsg);
22             }
23         },'json');
24     };
25     self.edit=function(item){
26         self.oper(item);
27         $('#modal1').modal('show');
28     };
29 }
30 jQuery(document).ready(function($) {
31     window.mtype=$('#mtype').val();
32     var md=window.md=new modelview();
33     ko.applyBindings(md);
34     var pagesize=15;
35     opers();
36     var fm1=$('#fm1');
37     fm1.validate({
38         rules:{
39             title:{
40                 required:true
41             },
42             name:{
43                 required:true
44             }
45         },
46         messages:{
47             title:{
48                 required:'不能为空'
49             },
50             name:{
51                 required:'不能为空'
52             }
53         }
54     });
55     $('#ctbtn').click(function(){
56         md.oper({
57             id:ko.observable(0),
58             title:ko.observable(),
59             name:ko.observable(),
60             exp:ko.observable(0),
61             value:ko.observable(0)
62         });
63         $('#modal1').modal('show');
64     });
65     $('#tjbtn').click(function(){
66         if(fm1.valid()==false)
67             return;
68         if(window.save==1)
69             return;
70         window.save=1;
71         var tt=md.oper();
72         var oper=ko.mapping.toJS(md.oper());
73         jQuery.post(basic+'/admin/opercon/save.htm', oper, function(data, textStatus, xhr) {
74             $('#modal1').modal('hide');
75             window.save=0;
76             if(data==null)
77                 return;
78             if(data.code==1)
79             {
80                 alert("无法保存!");
81             }else{
82                 if(oper.id==0)
83                 {
84                     window.md.opers.push(ko.mapping.fromJS(data.oper));
85                 }
86             }
87         },'json');
88     });
89 });
90 function opers()
91 {
92     jQuery.post(basic+'/admin/opercon/opers.htm', {}, function(data, textStatus, xhr) {
93         if(data==null)
94             return;
95         window.md.opers.removeAll();
96         if(data.items!=null)
97         {
98             jQuery.each(data.items, function(index, val) {
99                 var oper=ko.mapping.fromJS(val);
100                 window.md.opers.push(oper);    
101             });
102         }
103     },'json');
104 }