Access.js 6.6 KB

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