function add() { $("#dialog") .find(".dlg-content").panel({ href: "/SysRole/Edit/", queryParams: {} }).end() .find(".dlg-footer .dlg-btn-save").unbind("click").bind("click", save).end() .dialog({ title: lang.NewRole, width: 350, height: 500 }) .dialog("open"); } function getSelectedItem() { var data = $("#rolelist tr.selected").data("role"); if (data == undefined) { data = null; } return data; } function edit() { var row = getSelectedItem(); if (row) { if (row.ID === 1) {//Name === "超级管理员") { $.tools.alert(lang.CNESAR); return; } $("#dialog") .find(".dlg-content").panel({ href: "/SysRole/Edit/", queryParams: { ID: row.ID} }).end() .find(".dlg-footer .dlg-btn-save").unbind("click").bind("click", save).end() .dialog({ title: lang.EditRole, width: 350, height: 500 }) .dialog("open"); } else { $.tools.alert(lang.PleaseSelectTheData); } } //删除数据 function delData() { var selectedRow = getSelectedItem(); if (selectedRow) { if (selectedRow.ID === 1) {//Name === "超级管理员") { $.tools.alert(lang.CNDTSAR); return; } $.tools.delPost("id=" + selectedRow.ID, "/SysRole/Delete/", function () { loadRoles(); }, this); } else { $.tools.alert(lang.PleaseSelectTheData); } } function save() { var form = $("#dialog").find("form"); if (form.form("enableValidation").form("validate")) { var params = form.serialize(); var authorityNodes = $('#treeAuthority').tree('getChecked'); // $("#dialog .authorities").tree("getChecked", ["checked", "indeterminate"]); if (authorityNodes.length == 0) { $.tools.alert(lang.PleaseSelectTheData); return; } $.each(authorityNodes, function (i, n) { params += "&Authorities=" + n.id; }); $.tools.post(params, "/SysRole/Save/", function () { loadRoles(); $("#dialog").window('close'); }, this); } } function itemClick() { $(".role-list tr").removeClass("selected"); $(this).addClass("selected"); } function itemDblClick() { edit(); } function appendItem(obj) { var td1 = $("").append(""); var td2 = $("").append("

").find("h3").text(obj.Name).end() .append("").find("span").text(obj.Authorities).end(); var tr = $("").data("role", obj).append(td1, td2).bind("click", itemClick).bind("dblclick", itemDblClick); $("#rolelist").append(tr); } function loadData(data) { $("#rolelist tbody").remove(); if (data instanceof Array) { for (var i in data) { appendItem(data[i]); } } } function loadRoles() { $.tools.post({}, "/SysRole/LoadAll2", function (result) { loadData(result.data); }, this, true); } $(function () { loadRoles(); });