(function(){var j={idField:"acaid",treeCellIndex:0,template:'<tr id="acarow_{acaid}">\t<td class="t_l">\t\t<label><input type="checkbox" class="checkbox_style" name="acaid[]" value="{acaid}" /> {name}</label>\t</td></tr>',rowIdPrefix:"acarow_",collapsed:1,baseUrl:"?app=system&controller=role&action=acatree",rowReady:function(b,a,c){b=a.find("input:checkbox");if(c.disabled)b.remove();else{b.click(function(){this.checked?a.getDescendants().find("input:checkbox").attr("disabled","disabled").attr("checked",
true):a.getDescendants().find("input:checkbox").removeAttr("disabled")});c.checked&&b.attr("checked",true);(c=a.data("parentTr"))&&c.find("input:checkbox").is(":checked,:disabled")&&b.attr("disabled","disabled")}}},h=function(){return false},e=null,f={edit:function(b){ct.form("\u7f16\u8f91\u90e8\u95e8","?app=system&controller=department&action=edit&departmentid="+b,350,200,function(a){if(a.state){e.updateRow(b,a.data);return true}})},add:function(b){ct.form("\u6dfb\u52a0\u90e8\u95e8","?app=system&controller=department&action=add&parentid="+
b,350,200,function(a){if(a.state){e.addRow(a.data);return true}})},del:function(b){ct.form("\u5220\u9664\u90e8\u95e8","?app=system&controller=department&action=delete&departmentid="+b,400,220,function(a){if(a.state){if(a.data&&a.data.length)for(var c=0,d;d=a.data[c++];e.updateRow(d.departmentid,d));e.deleteRow(b)}return true})},editRole:function(b){ct.form("\u7f16\u8f91\u89d2\u8272","?app=system&controller=role&action=edit&roleid="+b,420,"95%",function(a){if(a.state){e.updateRow(b,a.data);return true}},
function(a,c){var d=c.find("table.treeTable");(new ct.treeTable(d,j)).load("roleid="+b)})},delRole:function(b,a,c){var d="?app=system&controller=role&action=mydelete&id="+b;ct.confirm('\u786e\u5b9a\u5220\u9664\u89d2\u8272<b style="color:red">'+c.name+"</b>\u5417\uff1f",function(){$.getJSON(d,function(g){if(g.state){ct.tips("\u5220\u9664\u5b8c\u6bd5","success");e.deleteRow(b)}else ct.warn(g.error)})})},setRole:function(b,a){ct.form("\u8bbe\u7f6e\u89d2\u8272","?app=system&controller=department&action=setRole&departmentid="+
b,340,420,function(c){a.getChildren().filter(".role").remove();if(c&&c.length)for(var d=0,g;g=c[d++];)e.addRow(g);return true})},init:function(){e=new ct.treeTable("#treeTable",{idField:"departmentid",treeCellIndex:0,template:'<tr id="row_{departmentid}">\t<td><a class="clickable" href="javascript:;">{name}</a></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="\u6dfb\u52a0" />\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>',
baseUrl:"?app=system&controller=department&action=tree",rowReady:function(b,a,c){if(c.isrole){var d=function(){f.editRole(b,a,c)};a.addClass("role");a.find("img.edit, a.clickable").click(function(){f.editRole(b,a)}).dblclick(h);a.find("img.hand:first").remove();a.find("img.del").click(function(){f.delRole(b,a,c)}).dblclick(h);a.dblclick(d);a.contextMenu("#role_menu",function(i){f[i](b,a,c)})}else{d=function(){f.edit(b,a,c)};a.find("a.clickable").click(d);var g=a.find("img.edit").click(d);g.prev().click(function(){f.add(b,
a,c)}).dblclick(h);g.next().click(function(){f.del(b,a,c)}).dblclick(h);a.dblclick(d);a.contextMenu("#department_menu",function(i){f[i](b,a,c)})}}});e.load()}};window.app=f})();
