Access.js 7.6 KB

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