EditController.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. var app = angular.module('app',['baseServices','SysObjRightsService','commonListService','arrayToolService']);
  2. app.controller("EditController",['$scope','BaseService','SysObjRights','CommonListService','ArrayToolService',function($scope,BaseService,SysObjRights,CommonListService,ArrayToolService){
  3. $scope.CommonList=CommonListService;
  4. $scope.ArrayTool=ArrayToolService;
  5. //对象
  6. $scope.prop={};
  7. //页面用到的参数或临时变量
  8. $scope.param={};
  9. SysObjRights.getRightType(beanId,function(typeList){
  10. $scope.param.typeList=typeList;
  11. if(objectId!=""&&objType!=""){
  12. SysObjRights.getByObjTypeAndObjectId(objType,objectId,function(data){
  13. //console.info(data);
  14. for(var i=0;i<data.length;i++){
  15. var item=data[i];
  16. if(item.rightType=="all"){
  17. $scope.param.selectAll=true;
  18. break;
  19. }
  20. var temp=getItemByKey(item.rightType);
  21. if(!temp.ids) temp.ids="";
  22. if(!temp.names) temp.names="";
  23. if(temp.ids!=""){
  24. temp.ids+=",";
  25. }
  26. temp.ids+=item.ownerId;
  27. if(temp.names!=""){
  28. temp.names+=",";
  29. }
  30. temp.names+=item.owner;
  31. }
  32. });
  33. }
  34. });
  35. //保存
  36. $scope.save=function(){
  37. var frm=$('#frmSubmit').form();
  38. if(!frm.valid()) return;
  39. var sysObjRights=explainType();//把typeList解释成一个一个的right
  40. var json={};
  41. json.sysObjRights=JSON.stringify(sysObjRights);
  42. json.objType=objType;
  43. json.objectId=objectId;
  44. SysObjRights.save(json,function(data){
  45. if(data.result==1){
  46. $.ligerDialog.confirm(data.message+",是否继续操作", "提示信息",
  47. function(rtn) {
  48. if (rtn) {
  49. window.location.reload();
  50. } else {
  51. frameElement.dialog.close();
  52. }
  53. });
  54. }else{
  55. $.ligerDialog.err("提示信息","保存出错了",data.message );
  56. }
  57. });
  58. }
  59. $scope.showSeletor=function(item){
  60. $scope.param.selectItem=item;
  61. switch(item.key)
  62. {
  63. case "all":
  64. break;
  65. case "user":
  66. UserDialog({
  67. selectUserIds:item.ids,
  68. selectUserNames:item.names,
  69. callback:selectorCallBack
  70. });
  71. break;
  72. case "org":
  73. OrgDialog({
  74. ids:item.ids,
  75. names:item.names,
  76. callback:selectorCallBack
  77. });
  78. break;
  79. case "orgSub":
  80. OrgDialog({
  81. ids:item.ids,
  82. names:item.names,
  83. callback:selectorCallBack
  84. });
  85. break;
  86. case "role":
  87. RoleDialog({
  88. ids:item.ids,
  89. names:item.names,
  90. callback:selectorCallBack
  91. });
  92. break;
  93. case "pos":
  94. PosDialog({
  95. ids:item.ids,
  96. names:item.names,
  97. callback:selectorCallBack
  98. });
  99. break;
  100. }
  101. }
  102. //选择器的回调函数
  103. function selectorCallBack(ids,names){
  104. //立即生效
  105. $scope.$apply(function(){
  106. $scope.param.selectItem.names=names;
  107. });
  108. $scope.param.selectItem.ids=ids;
  109. }
  110. //把typeList解释成一个一个的right
  111. function explainType(){
  112. var sysObjRights=[];//把typeList解释成一个一个的right
  113. if(!$scope.param.selectAll){
  114. for(var i=0;i<$scope.param.typeList.length;i++){
  115. var type=$scope.param.typeList[i];
  116. if(!type.ids||!type.names) continue;
  117. var ids = type.ids.split(",");
  118. var names = type.names.split(",");
  119. for(var j=0;j<ids.length;j++){
  120. var right={};
  121. right.objType=objType;
  122. right.objectId=objectId;
  123. right.rightType=type.key;
  124. right.ownerId=ids[j];
  125. right.owner=names[j];
  126. sysObjRights.push(right);
  127. }
  128. }
  129. }else{
  130. var right={};
  131. right.objType=objType;
  132. right.objectId=objectId;
  133. right.rightType="all";
  134. right.ownerId="1";
  135. right.owner="";
  136. sysObjRights.push(right);
  137. }
  138. return sysObjRights;
  139. }
  140. function getItemByKey(key){
  141. var list=$scope.param.typeList;
  142. for(var i=0;i<list.length;i++){
  143. if(list[i].key==key){
  144. return list[i];
  145. }
  146. }
  147. return null;
  148. }
  149. }]);