window.I = {} var basic = getpath(); var modelview = function() { var self = this; self.filter = ko.observable(); self.roles = ko.observableArray(); self.role = ko.observable({ id : ko.observable(0), name : ko.observable(), description : ko.observable() }); self.edittitle = ko.observable('编辑角色'); self.rm = function(item) { if (confirm("确认要删除吗?")) { jQuery.post(basic + '/admin/rolecon/rm.htm', { id : item.id }, function(data, textStatus, xhr) { if (data == null) return; if (data.code == 0) { self.roles.remove(item); } else { alert(data.hint); } }, 'json'); } }; self.edit = function(item) { self.edittitle('编辑角色'); self.role(item); $('#modal1').modal('show'); }; self.stp = function(item) { window.open(basic + 'permission/roleperms.jsf?roleid=' + item.id(), '_self'); }; self.stm = function(item) { window.open(basic + 'rolemenus/rolemenus.jsf?roleid=' + item.id(), '_self'); }; self.rms = function(item) { window.open(basic + '/system/permission/rolemodules.jsf?roleid=' + item.id(), '_self'); }; } jQuery(document).ready( function($) { var md = window.md = new modelview(); ko.applyBindings(md); var pagesize = 15; roles(0, pagesize, 1, null, 0); var fm1 = $('#fm1'); fm1.validate({ rules : { name : { required : true, maxlength : 16, minlength : 2 }, notes : { required : true, maxlength : 16, minlength : 2 } }, messages : { name : { required : '不能为空', maxlength : '长度不能超过16', minlength : '长度不能小于2' }, notes : { required : '不能为空', maxlength : '长度不能超过16', minlength : '长度不能小于2' } } }); $('#searcha').click(function() { roles(0, pagesize, 1, md.filter(), 0); }); $('#ctbtn').click(function() { window.md.edittitle('新建角色'); md.role({ id : ko.observable(0), name : ko.observable(), description : ko.observable() }); $('#modal1').modal('show'); }); $('#tjbtn').click( function() { if (fm1.valid() == false) return; if (window.save == 1) return; window.save = 1; // var btn = $(this).button('loading'); var tt = md.role(); var role = ko.mapping.toJS(md.role()); jQuery.post(basic + '/admin/rolecon/save.htm', role, function(data, textStatus, xhr) { $('#modal1').modal('hide'); // btn.button('reset'); window.save = 0; if (data == null) return; if (data.code == 1) { alert("无法保存!"); } else { if (role.id == 0) { tt.id(data.nid); window.md.roles.push(tt); } } }, 'json'); }); }); function roles(page, pagesize, pages, filter, tid) { jQuery.post(basic + '/admin/rolecon/roles.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) { roles(num - 1, pagesize, 0, filter, tid); }); } } window.md.roles.removeAll(); if (data.items != null) { jQuery.each(data.items, function(index, val) { var role = ko.mapping.fromJS(val); window.md.roles.push(role); }); } }, 'json'); }