Access.js 7.9 KB

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