Access.js 6.3 KB

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