window.I = {} var basic=getpath(); var modelview=function() { var self=this; self.groupid=ko.observable($('#groupid').val()); self.filter=ko.observable(); self.type=ko.observable(); self.ops=ko.observableArray(); self.res=ko.observable({ url:ko.observable() }); self.ress1=ko.observableArray(); self.change=function(item){ ress(0,15,self.type(),self.filter(),self.groupid(),1); }; self.opsel1=function(item){ var groupid=self.groupid(); var resid=item.id(); md.res(item); var oval=parseInt(item.ov()); jQuery.each(self.ops(), function(index, val) { val.value=parseInt(val.value); var tt=oval&(val.value); if(tt>0) val.check(true); else val.check(false); }); $('#modal1').modal('show'); }; self.ressel=function(item){ var groupid=self.groupid(); var resid=item.id(); var op=item.perm(); jQuery.post(basic+'/admin/grouppermcon/ressel.htm', {groupid:groupid,resid:resid,op:op}, function(data, textStatus, xhr) { if(data==null) return; if(data.code>0) { alert(data.errmsg); item.perm(op==true?false:true); item.ov(0); }else{ item.perm(op); } },'json'); return true; }; }; jQuery(document).ready(function($) { var md=window.md=new modelview(); ko.applyBindings(md); var pagesize=15; ress(0,pagesize,md.type(),md.filter(),md.groupid(),1); ops(); $('#tjbtn').click(function(){ var obj={}; obj.groupid=md.groupid(); obj.resid=md.res().id; obj.op=0; jQuery.each(md.ops(), function(index, val) { if(val.check()==true) { obj.op=obj.op+val.value; } }); jQuery.post(basic+'/admin/grouppermcon/valueset.htm', obj, function(data, textStatus, xhr) { if(data==null) return; if(data.code>0) { alert(data.errmsg); }else{ md.res().perm(true); md.res().ov(obj.op); } $('#modal1').modal('hide'); },'json'); }); }); function ress(page,pagesize,type,filter,groupid,pages) { jQuery.post(basic+'/admin/grouppermcon/ress.htm', {page:page,pagesize:pagesize,type:type,filter:filter,groupid:groupid}, function(data, textStatus, xhr) { if(data==null) return; if(data.pages!=null) { $('#pagdiv').unbind('page').empty(); if(data.pages>1) { $('#pagdiv').bootpag({total:data.pages,maxVisible:10,page:page+1}).on('page',function(event,num){ ress(num-1,pagesize,type,filter,groupid,0); }); } } if(data.items!=null) { //ress:id,url,value(0,1,..,NULL) window.md.ress1.removeAll(); jQuery.each(data.items, function(index, val) { var obj={}; obj.id=val[0]; obj.url=val[1]; if(val[2]==null||val[2]=='null'||val[2]<0) { obj.perm=false; }else{ obj.perm=true; } obj.ov=val[2] window.md.ress1.push(ko.mapping.fromJS(obj)); }); } },'json'); } function ops() { jQuery.post(basic+'/admin/opercon/opers.htm', {}, function(data, textStatus, xhr) { if(data==null) return; window.md.ops.removeAll(); jQuery.each(data.items, function(index, val) { val.check=ko.observable(false); window.md.ops.push(val); }); },'json'); }