hjg
2024-03-18 8d48c59d5d3bcc4148ef97dc6f98e3a8cf9ca436
提交 | 用户 | 时间
58d006 1 window.I = {}
A 2 var basic=getpath();
3 var modelview=function() {
4     var self=this;
5     self.filter=ko.observable();
6     self.groups=ko.observableArray();
7     self.pgroups=ko.observableArray();
8     self.group=ko.observable({
9             id:ko.observable(0),
10             name:ko.observable(),
11             note:ko.observable(),
12             pgroup:ko.observable(0),
13             pgroupname:ko.observable()
14         });
15     self.rm=function(item){
16         jQuery.post(basic+'/admin/groupcon/rm.htm', {id:item.id}, function(data, textStatus, xhr) {
17             if(data==null)
18                 return;
19             if(data.code==0)
20             {
21                 self.groups.remove(item);
22             }else{
23                 alert(data.errmsg);
24             }
25         },'json');
26     };
27     self.edit=function(item){
28         //pgroup
29         jQuery.post(basic+'/admin/groupcon/pgroup.htm', {id:item.id()}, function(data, textStatus, xhr) {
30             if(data.ug!=null)
31             {
32                 item.pgroup=ko.observable(data.ug.id);
33                 item.pgroupname=ko.observable(data.ug.name);
34             }
35         },'json');
36         self.group(item);
37         $('#modal1').modal('show');
38     };
39     self.stp=function(item){
40         window.open(basic+'/administrator/system');
41     };
42     self.psel=function(item){
43         $('#modal1').modal('show');
44         $('#modal2').modal('hide');
45         self.group().pgroup(item.id);
46         self.group().pgroupname(item.name);
47         $('#ptitle').text(item.name);
48         $('#pid').val(item.id);
49     }
50 }
51 jQuery(document).ready(function($) {
52     var md=window.md=new modelview();
53     ko.applyBindings(md);
54     var pagesize=15;
55     groups(0,pagesize,1,null,0);
56     var fm1=$('#fm1');
57     fm1.validate({
58         rules:{
59             name:{
60                 required:true
61             }
62         },
63         messages:{
64             name:{
65                 required:'不能为空'
66             }
67         }
68     });
69     $('#searcha').click(function(){
70         groups(0,pagesize,1,md.filter(),0);
71     });
72     $('#ctbtn').click(function(){
73         md.group({
74             id:ko.observable(0),
75             name:ko.observable(),
76             note:ko.observable(),
77             pgroup:ko.observable(0),
78             pgroupname:ko.observable()
79         });
80         $('#modal1').modal('show');
81     });
82     $('#tjbtn').click(function(){
83         if(fm1.valid()==false)
84             return;
85         if(window.save==1)
86             return;
87         window.save=1;
88         var tt=md.group();
89         var group=ko.mapping.toJS(md.group());
90         jQuery.post(basic+'/admin/groupcon/save.htm', group, function(data, textStatus, xhr) {
91             $('#modal1').modal('hide');
92             window.save=0;
93             if(data==null)
94                 return;
95             if(data.code==1)
96             {
97                 alert("无法保存!");
98             }else{
99                 groups(0,pagesize,1,md.filter(),data.nid);
100             }
101         },'json');
102     });
103
104     $('#selparent').click(function(){
105         $('#modal1').modal('hide');
106         $('#modal2').modal('show');
107         pgroups(0,pagesize,1,md.group().id());
108     });
109
110
111 });
112 function groups(page,pagesize,pages,filter,tid)
113 {
114     jQuery.post(basic+'/admin/groupcon/groups.htm', {page:page,pagesize:pagesize,pages:pages,filter:filter,tid:tid}, function(data, textStatus, xhr) {
115         if(data==null)
116             return;
117         if(data.page!=null)
118         {
119             page=data.page;
120         }
121         if(pages>0)
122         {
123             $('#pagdiv').unbind('page').empty();
124             if(data.pages>1)
125             {
126                 $('#pagdiv').bootpag({total:data.pages,maxVisible:10,page:page+1}).on('page',function(event,num){
127                       groups(num-1,pagesize,0,filter,tid);
128                 });
129             }
130         }
131         window.md.groups.removeAll();
132         if(data.items!=null)
133         {
134             jQuery.each(data.items, function(index, val) {
135                 var lev='';
136                 for (var i = 1; i<val.level; i++) {
137                     lev+='--';
138                 };
139                 val.level=lev;
140                 var group=ko.mapping.fromJS(val);
141                 window.md.groups.push(group);    
142             });
143         }
144     },'json');
145 }
146 function pgroups(page,pagesize,pages,tid){
147     jQuery.post(basic+'/admin/groupcon/pgroups.htm', {page:page,pagesize:pagesize,pages:pages,tid:tid}, function(data, textStatus, xhr) {
148         if(data==null)
149             return;
150         window.md.pgroups.removeAll();
151         jQuery.each(data.items, function(index, val) {
152             var lev='';
153             for (var i = 1; i<val.level; i++) {
154                 lev+='--';
155             };
156             //var group=ko.mapping.fromJS(val);
157             window.md.pgroups.push(val);
158         });
159         if(data.pages!=null)
160         {
161             $('#pagdiv2').unbind('page').empty();
162             $('#pagdiv2').bootpag({total:data.pages,maxVisible:10,page:page+1}).on('page',function(event,num){
163                       pgroups(num-1,pagesize,0,tid);
164             });
165         }
166     },'json');
167 }