window.I = {} var basic=getpath(); var modelview=function() { var self=this; self.filter=ko.observable(); self.groups=ko.observableArray(); self.pgroups=ko.observableArray(); self.group=ko.observable({ id:ko.observable(0), name:ko.observable(), note:ko.observable(), pgroup:ko.observable(0), pgroupname:ko.observable() }); self.rm=function(item){ jQuery.post(basic+'/admin/groupcon/rm.htm', {id:item.id}, function(data, textStatus, xhr) { if(data==null) return; if(data.code==0) { self.groups.remove(item); }else{ alert(data.errmsg); } },'json'); }; self.edit=function(item){ //pgroup jQuery.post(basic+'/admin/groupcon/pgroup.htm', {id:item.id()}, function(data, textStatus, xhr) { if(data.ug!=null) { item.pgroup=ko.observable(data.ug.id); item.pgroupname=ko.observable(data.ug.name); } },'json'); self.group(item); $('#modal1').modal('show'); }; self.stp=function(item){ window.open(basic+'/administrator/system'); }; self.psel=function(item){ $('#modal1').modal('show'); $('#modal2').modal('hide'); self.group().pgroup(item.id); self.group().pgroupname(item.name); $('#ptitle').text(item.name); $('#pid').val(item.id); } } jQuery(document).ready(function($) { var md=window.md=new modelview(); ko.applyBindings(md); var pagesize=15; groups(0,pagesize,1,null,0); var fm1=$('#fm1'); fm1.validate({ rules:{ name:{ required:true } }, messages:{ name:{ required:'不能为空' } } }); $('#searcha').click(function(){ groups(0,pagesize,1,md.filter(),0); }); $('#ctbtn').click(function(){ md.group({ id:ko.observable(0), name:ko.observable(), note:ko.observable(), pgroup:ko.observable(0), pgroupname:ko.observable() }); $('#modal1').modal('show'); }); $('#tjbtn').click(function(){ if(fm1.valid()==false) return; if(window.save==1) return; window.save=1; var tt=md.group(); var group=ko.mapping.toJS(md.group()); jQuery.post(basic+'/admin/groupcon/save.htm', group, function(data, textStatus, xhr) { $('#modal1').modal('hide'); window.save=0; if(data==null) return; if(data.code==1) { alert("无法保存!"); }else{ groups(0,pagesize,1,md.filter(),data.nid); } },'json'); }); $('#selparent').click(function(){ $('#modal1').modal('hide'); $('#modal2').modal('show'); pgroups(0,pagesize,1,md.group().id()); }); }); function groups(page,pagesize,pages,filter,tid) { jQuery.post(basic+'/admin/groupcon/groups.htm', {page:page,pagesize:pagesize,pages:pages,filter:filter,tid:tid}, function(data, textStatus, xhr) { if(data==null) return; if(data.page!=null) { page=data.page; } if(pages>0) { $('#pagdiv').unbind('page').empty(); if(data.pages>1) { $('#pagdiv').bootpag({total:data.pages,maxVisible:10,page:page+1}).on('page',function(event,num){ groups(num-1,pagesize,0,filter,tid); }); } } window.md.groups.removeAll(); if(data.items!=null) { jQuery.each(data.items, function(index, val) { var lev=''; for (var i = 1; i