rolemain.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**
  2. * 角色管理
  3. *
  4. */
  5. $.namespace("role.main");
  6. role.main.init = function() {
  7. // 把form传入,构造翻页控件
  8. pageinfo($("#roleform"));
  9. }
  10. // 查询
  11. role.main.search = function() {
  12. $("#currentpage").val(1);
  13. //console.log($("#roleform").serialize());
  14. $("#roleform").submit();
  15. }
  16. // 删除
  17. role.main.del = function(roleid) {
  18. $.confirm({
  19. title : '提示',
  20. content : '确认删除?',
  21. confirm : function() {
  22. $.ajax({
  23. url : basePath + '/role/delOneRole.html',
  24. type : "post",
  25. data : {
  26. roleId : roleid
  27. },
  28. dataType : "json",
  29. success : function(data) {// ajax返回的数据
  30. if (data.success) {
  31. location.href = basePath + '/role/querylist.html';
  32. } else {
  33. $.alert({
  34. title : '提示',
  35. content : '删除失败',
  36. });
  37. }
  38. }
  39. });
  40. }
  41. });
  42. }
  43. //清空新增输入
  44. role.main.clear = function() {
  45. $("#htitle").html('角色新增');
  46. $("#editid").val("");
  47. $("#editroleName").val("");
  48. $("#editroleCode").val("");
  49. /*$("#editroleSort").val("");*/
  50. }
  51. // 获取编辑对象内容
  52. role.main.edit = function(data) {
  53. $.post(basePath + "/role/edit.html", {
  54. id : data
  55. }, function(data) {
  56. $("#htitle").html('角色修改');
  57. if (data) {
  58. for ( var a in data) {
  59. if ($("#edit" + a)) {
  60. $("#edit" + a).val(data[a]);
  61. }
  62. }
  63. }
  64. }, "json");
  65. }
  66. // 编辑和新增保存
  67. role.main.save = function save() {
  68. var rolename=$("#editroleName").val();
  69. if(rolename==''){
  70. $.alert({
  71. title : '提示',
  72. content : '角色名不能为空'
  73. });
  74. return;
  75. }
  76. var rolecode=$("#editroleCode").val();
  77. if(rolecode==''){
  78. $.alert({
  79. title : '提示',
  80. content : '角色编码不能为空'
  81. });
  82. return;
  83. }
  84. $.ajax({
  85. url : basePath + "/role/saveRole.html",
  86. data : $("#addform").serialize(),
  87. type : "post",
  88. dataType : "json",
  89. success : function(data) {// ajax返回的数据
  90. if (data.success) {
  91. $.alert({
  92. title : '提示',
  93. content : '保存成功',
  94. confirm : function() {
  95. location.href = basePath + '/role/querylist.html';
  96. }
  97. });
  98. } else {
  99. $.alert({
  100. title : '提示',
  101. content : data.message,
  102. confirm : function() {
  103. }
  104. });
  105. }
  106. }
  107. });
  108. }
  109. role.main.grant = function(data) {
  110. location.href = basePath + "/role/rolegrant.html?roleId=" + data;
  111. }