(function(){var i=function(){return false},f,g={edit:function(c){ct.form("\u7f16\u8f91\u90e8\u95e8","?app=system&controller=department&action=myedit&departmentid="+c,350,200,function(a){if(a.state){f.updateRow(c,a.data);return true}})},add:function(c){ct.form("\u6dfb\u52a0\u90e8\u95e8","?app=system&controller=department&action=myadd&parentid="+c,350,200,function(a){if(a.state){f.addRow(a.data);return true}})},adduser:function(c){User.add(c)},delRole:function(c,a,b){var d="?app=system&controller=role&action=mydelete&id="+
c;ct.confirm('\u786e\u5b9a\u5220\u9664\u89d2\u8272<b style="color:red">'+b.name+"</b>\u5417\uff1f",function(){$.getJSON(d,function(e){if(e.state){ct.tips("\u5220\u9664\u5b8c\u6bd5","success");f.deleteRow(c)}else ct.warn(e.error)})})},setRole:function(c,a){ct.form("\u8bbe\u7f6e\u89d2\u8272","?app=system&controller=department&action=mySetRole&departmentid="+c,420,300,function(b){a.getChildren().filter(".role").remove();if(b&&b.length)for(var d=0,e;e=b[d++];)f.addRow(e);return true})},del:function(c){ct.form("\u5220\u9664\u90e8\u95e8",
"?app=system&controller=department&action=mydelete&departmentid="+c,400,220,function(a){if(a.state){if(a.data&&a.data.length)for(var b=0,d;d=a.data[b++];f.updateRow(d.departmentid,d));f.deleteRow(c)}return true})},init:function(){f=new ct.treeTable("#treeTable",{idField:"departmentid",treeCellIndex:0,template:'<tr id="departmentrow_{departmentid}">\t<td>{name}</td>\t<td>{rolename}</td>\t<td class="t_r">{numpeople}</td>\t<td class="t_r">\t\t<img class="hand" height="16" width="16" src="images/add_1.gif" alt="\u7f16\u8f91" />\t\t<img class="hand edit" height="16" width="16" src="images/edit.gif" alt="\u7f16\u8f91" />\t\t<img class="hand del" height="16" width="16" src="images/delete.gif" alt="\u5220\u9664" />\t</td></tr>',
rowIdPrefix:"departmentrow_",baseUrl:"?app=system&controller=department&action=mytree",rowReady:function(c,a,b){if(b.isrole){var d=function(){g.editRole(c,a,b)};a.addClass("role");a.find("img.hand:lt(2)").remove();a.find("img.del").click(function(){g.delRole(c,a,b)}).dblclick(i);a.contextMenu("#role_menu",function(h){g[h](c,a,b)})}else{d=function(){g.edit(c,a,b)};a.find("a.clickable").click(d);var e=a.find("img.edit").click(d);e.prev().click(function(){g.add(c,a,b)}).dblclick(i);e.next().click(function(){g.del(c,
a,b)}).dblclick(i);a.dblclick(d);a.contextMenu("#department_menu",function(h){g[h](c,a,b)})}},rowsPrepared:function(c){c.find("tr:first img.del").remove()}});f.load()}};window.app=g})();
var User=function(){var i=function(b,d){d.find(">td>img.edit").click(function(){a.edit(b,d)});d.find(">td>img.delete").click(function(){a.del(b)})},f,g,c,a={table:null,init:function(b){f=b+"&action=myedit";c=b+"&action=myadd";g=b+"&action=mydelete";a.table=new ct.table("#user_list",{pageSize:15,dblclickHandler:a.edit,rowCallback:i,template:'<tr id="user_{userid}">\t<td class="t_c">\t   <input type="checkbox" class="checkbox_style" value="{userid}" />\t</td>\t<td class="t_r">{userid}</td>\t<td><a href="javascript: url.member({userid});">{username}</a></td>\t<td>{name}</td>\t<td class="t_c">{role}</td>\t<td class="t_c">{department}</td>\t<td class="t_c">{state}</td>\t<td class="t_c">\t   <img class="manage edit" height="16" width="16" alt="\u7f16\u8f91" src="images/edit.gif"/>       <img class="manage delete" height="16" width="16" alt="\u5220\u9664" src="images/delete.gif"/>\t</td></tr>',
rowIdPrefix:"user_",rightMenuId:"user_menu",pagerId:"user_pager",baseUrl:b+"&action=mypage"});a.table.load()},edit:function(b,d){var e=f+"&userid="+b;d.trigger("check");ct.form("\u7f16\u8f91\u7ba1\u7406\u5458",e,400,460,function(h){if(h.state){a.table.updateRow(b,h.data);return true}})},add:function(b){ct.form("\u6dfb\u52a0\u7ba1\u7406\u5458",c+"&departmentid="+b,400,480,function(d){if(d.state){a.table.addRow(d.data);return true}},function(d,e){e.find("select[name=departmentid]").change(function(){e.find("select[name=roleid]").parent().load("?app=system&controller=role&action=dropdown&departmentid="+
this.value)})})},del:function(b){var d;if(b===undefined){b=a.table.checkedIds();if(!b.length){ct.warn("\u8bf7\u9009\u4e2d\u8981\u5220\u9664\u9879");return}d='\u786e\u5b9a\u5220\u9664\u9009\u4e2d\u7684<b style="color:red">'+b.length+"</b>\u6761\u8bb0\u5f55\u5417\uff1f"}else d='\u786e\u5b9a\u5220\u9664\u7f16\u53f7\u4e3a<b style="color:red">'+b+"</b>\u7684\u8bb0\u5f55\u5417\uff1f";ct.confirm(d,function(){$.post(g,"id="+b,function(e){e.state?(ct.warn("\u5220\u9664\u5b8c\u6bd5"),a.table.deleteRow(b)):
ct.warn(e.error)},"json")})}};return a}();
