Access.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. MWF.xDesktop = MWF.xDesktop || {};
  2. MWF.xApplication = MWF.xApplication || {};
  3. //MWF.xDesktop.requireApp("Organization", "Actions.RestActions", null, false);
  4. MWF.xDesktop.Access = MWF.AC = {
  5. "companyList": null,
  6. "action": null,
  7. getRoleList: function(){
  8. if (!this.roleList){
  9. this.roleList = [];
  10. layout.desktop.session.user.roleList.each(function(role){
  11. this.roleList.push(role.substring(0, role.indexOf("@")).toLowerCase());
  12. }.bind(this));
  13. }
  14. },
  15. isAdministrator: function(){
  16. this.getRoleList();
  17. return (layout.desktop.session.user.name.toLowerCase() === "xadmin") || (this.roleList.indexOf("manager")!==-1);
  18. },
  19. isProcessManager: function(){
  20. if (!layout.desktop.session.user.roleList) return false;
  21. this.getRoleList();
  22. return this.isAdministrator() || (this.roleList.indexOf("processplatformmanager")!==-1);
  23. },
  24. isQueryManager: function(){
  25. if (!layout.desktop.session.user.roleList) return false;
  26. this.getRoleList();
  27. return this.isAdministrator() || (this.roleList.indexOf("querymanager")!==-1);
  28. },
  29. isOrganizationManager: function(){
  30. if (!layout.desktop.session.user.roleList) return false;
  31. this.getRoleList();
  32. return this.isAdministrator() || (this.roleList.indexOf("organizationmanager")!==-1);
  33. },
  34. isMessageManager: function(){
  35. if (!layout.desktop.session.user.roleList) return false;
  36. this.getRoleList();
  37. return this.isAdministrator() || (this.roleList.indexOf("messagemanager")!==-1);
  38. },
  39. isUnitManager: function(){
  40. if (!layout.desktop.session.user.roleList) return false;
  41. this.getRoleList();
  42. return this.isAdministrator() || (this.roleList.indexOf("unitmanager")!==-1);
  43. },
  44. isGroupManager: function(){
  45. if (!layout.desktop.session.user.roleList) return false;
  46. this.getRoleList();
  47. return this.isAdministrator() || (this.roleList.indexOf("groupmanager")!==-1);
  48. },
  49. isRoleManager: function(){
  50. if (!layout.desktop.session.user.roleList) return false;
  51. this.getRoleList();
  52. return this.isAdministrator() || (this.roleList.indexOf("rolemanager")!==-1);
  53. },
  54. isPersonManager: function(){
  55. if (!layout.desktop.session.user.roleList) return false;
  56. this.getRoleList();
  57. return this.isAdministrator() || (this.roleList.indexOf("personmanager")!==-1);
  58. },
  59. isGroupCreator: function(){
  60. if (!layout.desktop.session.user.roleList) return false;
  61. this.getRoleList();
  62. return (this.roleList.indexOf("groupcreator")!==-1);
  63. },
  64. isProcessPlatformCreator: function(){
  65. if (this.isAdministrator()) return true;
  66. if (this.isProcessManager()) return true;
  67. if (!layout.desktop.session.user.roleList) return false;
  68. this.getRoleList();
  69. return (this.roleList.indexOf("processplatformcreator")!==-1);
  70. },
  71. isQueryPlatformCreator: function(){
  72. if (this.isAdministrator()) return true;
  73. if (this.isQueryManager()) return true;
  74. if (!layout.desktop.session.user.roleList) return false;
  75. this.getRoleList();
  76. return (this.roleList.indexOf("querycreator")!==-1);
  77. },
  78. isApplicationManager: function(option){
  79. if (this.isAdministrator()) {
  80. if (option.yes) option.yes();
  81. }else{
  82. }
  83. },
  84. isCMSManager: function(){
  85. this.getRoleList();
  86. return this.isAdministrator() || (this.roleList.indexOf("cmsmanager")!==-1);
  87. },
  88. isBBSManager: function(){
  89. this.getRoleList();
  90. return this.isAdministrator() || (this.roleList.indexOf("bbsmanager")!==-1);
  91. },
  92. isOKRManager: function(){
  93. this.getRoleList();
  94. return this.isAdministrator() || (this.roleList.indexOf("okrmanager")!==-1);
  95. },
  96. isCRMManager: function(){
  97. this.getRoleList();
  98. return this.isAdministrator() || (this.roleList.indexOf("crmmanager")!==-1);
  99. },
  100. isAttendanceManager: function(){
  101. this.getRoleList();
  102. return this.isAdministrator() || (this.roleList.indexOf("attendancemanager")!==-1);
  103. },
  104. isMeetingAdministrator: function(){
  105. this.getRoleList();
  106. return this.isAdministrator() || (this.roleList.indexOf("meetingmanager")!==-1);
  107. },
  108. isHotPictureManager: function(){
  109. this.getRoleList();
  110. return this.isAdministrator() || (this.roleList.indexOf("hotpicturemanager")!==-1);
  111. },
  112. isPersonEditor: function(option){
  113. //{list: "idlist", "yes": trueFunction, "no": falseFunction}
  114. if (this.isAdministrator()) return true;
  115. if (this.isPersonManager()) return true;
  116. if (option.list && option.list.length){
  117. if (option.list.indexOf(layout.desktop.session.user.id)!==-1) return true;
  118. }
  119. return false;
  120. },
  121. isCompanyEditor: function(option) {
  122. //{id: "companyId", "yes": trueFunction, "no": falseFunction}
  123. if (this.isAdministrator()){
  124. if (option.yes) option.yes();
  125. }else if (this.isCompanyCreator()){
  126. if (option.yes) option.yes();
  127. }else{
  128. this.getCompanyList(function(){
  129. if (option.id){
  130. if (this.companyList.indexOf(option.id)!==-1){
  131. if (option.yes) option.yes();
  132. }else{
  133. if (option.no) option.no();
  134. }
  135. }else{
  136. if (this.companyList.length>0){
  137. if (option.yes) option.yes();
  138. }else{
  139. if (option.no) option.no();
  140. }
  141. }
  142. }.bind(this));
  143. }
  144. },
  145. isDepartmentEditor: function(option) {
  146. //{id: "superCompanyId", "yes": trueFunction, "no": falseFunction}
  147. if (this.isAdministrator()){
  148. if (option.yes) option.yes();
  149. }else if (this.isCompanyCreator()){
  150. if (option.yes) option.yes();
  151. }else{
  152. this.getCompanyList(function(){
  153. if (option.id){
  154. if (this.companyList.indexOf(option.id)!==-1){
  155. if (option.yes) option.yes();
  156. }else{
  157. if (option.no) option.no();
  158. }
  159. }else{
  160. if (option.no) option.no();
  161. }
  162. }.bind(this));
  163. }
  164. },
  165. getCompanyList: function(callback){
  166. if (this.companyList===null){
  167. this.getAction();
  168. this.action.getCompanyAccess(function(json){
  169. if (json.data){
  170. this.companyList = json.data;
  171. }else{
  172. this.companyList = [];
  173. }
  174. if (callback) callback();
  175. }.bind(this), null, layout.desktop.session.user.id);
  176. }else{
  177. if (callback) callback();
  178. }
  179. },
  180. getAction: function(){
  181. if (!this.action) this.action = MWF.Actions.get("x_organization_assemble_control");
  182. //if (!this.action) this.action = new MWF.xApplication.Organization.Actions.RestActions();
  183. }
  184. }