Main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. MWF.xApplication.OKR = MWF.xApplication.OKR || {};
  2. MWF.require("MWF.widget.Identity", null,false);
  3. MWF.xDesktop.requireApp("OKR", "Actions.RestActions", null, false);
  4. MWF.xApplication.OKR.options = {
  5. multitask: true,
  6. executable: true
  7. }
  8. MWF.xApplication.OKR.Main = new Class({
  9. Extends: MWF.xApplication.Common.Main,
  10. Implements: [Options, Events],
  11. options: {
  12. "style": "default",
  13. "name": "OKR",
  14. "icon": "icon.png",
  15. "width": "1200",
  16. "height": "700",
  17. "isResize": false,
  18. "isMax": true,
  19. "title": MWF.xApplication.OKR.LP.title
  20. },
  21. onQueryLoad: function(){
  22. this.lp = MWF.xApplication.OKR.LP;
  23. this.user = layout.desktop.session.user.name;
  24. this.userGender = layout.desktop.session.user.genderType;
  25. },
  26. loadApplication: function(callback){
  27. this.manageDepartments =[];
  28. this.manageCompanys = [];
  29. this.restActions = new MWF.xApplication.OKR.Actions.RestActions();
  30. this.createNode();
  31. this.loadApplicationContent();
  32. },
  33. isAdmin: function(){
  34. return this.isCompanyManager() || MWF.AC.isAdministrator()
  35. },
  36. isDepartmentManager : function(){
  37. return this.manageDepartments.length > 0;
  38. },
  39. isCompanyManager : function(){
  40. return this.manageCompanys.length > 0;
  41. },
  42. loadController: function(callback){
  43. //this.restActions.listPermission( function( json ){
  44. // json.data.each(function(item){
  45. // if( item.adminLevel == "COMPANY" && item.adminName == layout.desktop.session.user.name){
  46. // this.manageCompanys.push( item.organizationName )
  47. // }else if( item.adminLevel == "DEPT" && item.adminName == layout.desktop.session.user.name ){
  48. // this.manageDepartments.push( item.organizationName )
  49. // }
  50. // }.bind(this))
  51. // if(callback)callback(json);
  52. //}.bind(this));
  53. if(callback)callback();
  54. },
  55. createNode: function(){
  56. this.content.setStyle("overflow", "hidden");
  57. this.node = new Element("div", {
  58. "styles": {"width": "100%", "height": "100%", "overflow": "hidden"}
  59. }).inject(this.content);
  60. },
  61. loadApplicationContent: function(){
  62. this.loadController(function(){
  63. this.loaNavi();
  64. }.bind(this))
  65. //this.loadApplicationLayout();
  66. },
  67. loaNavi: function(callback){
  68. this.naviNode = new Element("div.naviNode", {
  69. "styles": this.css.naviNode
  70. }).inject(this.node);
  71. var curNavi = { "id" : "" }
  72. if( this.status ){
  73. curNavi.id = this.status.id
  74. }
  75. this.navi = new MWF.xApplication.OKR.Navi(this, this.naviNode, curNavi );
  76. },
  77. clearContent: function(){
  78. if (this.explorerContent){
  79. if (this.explorer) delete this.explorer;
  80. this.explorerContent.destroy();
  81. this.explorerContent = null;
  82. }
  83. },
  84. openMinder : function(){
  85. MWF.xDesktop.requireApp("OKR", "MinderExplorer", function(){
  86. this.clearContent();
  87. this.explorerContent = new Element("div", {
  88. "styles": this.css.rightContentNode
  89. }).inject(this.node);
  90. this.explorer = new MWF.xApplication.OKR.MinderExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  91. this.explorer.load();
  92. }.bind(this));
  93. },
  94. opeCoreWork : function(){
  95. MWF.xDesktop.requireApp("Execution", "CenterWorkDeployer", function(){
  96. //this.clearContent();
  97. //this.explorerContent = new Element("div", {
  98. // "styles": this.css.rightContentNode
  99. //}).inject(this.node);
  100. this.explorer = new MWF.xApplication.Execution.CenterWorkDeployer({"app":this}, this.restActions,{},{"isAdmin":this.isAdmin() } );
  101. this.explorer.load();
  102. }.bind(this));
  103. },
  104. opeWorkForm : function(){
  105. MWF.xDesktop.requireApp("Execution", "WorkForm", function(){
  106. //this.clearContent();
  107. //this.explorerContent = new Element("div", {
  108. // "styles": this.css.rightContentNode
  109. //}).inject(this.node);
  110. this.form = new MWF.xApplication.Execution.WorkForm({"app":this}, this.restActions,{},{
  111. "isNew": true,
  112. "isEdited": false
  113. });
  114. this.form.load();
  115. }.bind(this));
  116. },
  117. opeWorkDetail : function(){
  118. MWF.xDesktop.requireApp("Execution", "WorkDetail", function(){
  119. //this.clearContent();
  120. //this.explorerContent = new Element("div", {
  121. // "styles": this.css.rightContentNode
  122. //}).inject(this.node);
  123. this.form = new MWF.xApplication.Execution.WorkDetail({"app":this}, this.restActions,{},{
  124. "isNew": false,
  125. "isEdited": false
  126. });
  127. this.form.load();
  128. }.bind(this));
  129. },
  130. openImageCliper : function(){
  131. this.clearContent();
  132. this.explorerContent = new Element("div", {
  133. "styles": this.css.rightContentNode
  134. }).inject(this.node);
  135. MWF.require("MWF.widget.ImageClipper", function () {
  136. this.editor = new MWF.widget.ImageClipper(this.explorerContent, {})
  137. this.editor.load();
  138. }.bind(this))
  139. },
  140. //openExplorer : function(){
  141. // MWF.xDesktop.requireApp("Template", "Explorer", function(){
  142. // this.clearContent();
  143. // this.explorerContent = new Element("div", {
  144. // "styles": this.css.rightContentNode
  145. // }).inject(this.node);
  146. // this.explorer = new MWF.xApplication.Template.Explorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  147. // this.explorer.load();
  148. // }.bind(this));
  149. //},
  150. recordStatus: function(){
  151. return this.navi && this.navi.currentItem ? this.navi.currentItem.retrieve("data") : {};
  152. }
  153. });
  154. MWF.xApplication.OKR.Navi = new Class({
  155. Implements: [Options, Events],
  156. options : {
  157. "id" : ""
  158. },
  159. initialize: function(app, node, options){
  160. this.setOptions(options);
  161. this.app = app;
  162. this.node = $(node);
  163. this.css = this.app.css;
  164. this.currentMenu = null;
  165. this.currentItem = null;
  166. this.menus = {};
  167. this.items = {};
  168. this.elements = [];
  169. this.load();
  170. },
  171. load: function(){
  172. var naviUrl = this.app.path+"navi.json";
  173. MWF.getJSON(naviUrl, function(json){
  174. json.each(function(navi){
  175. if( navi.access && navi.access == "admin" ){
  176. if( this.app.isAdmin() )this.createNaviNode(navi);
  177. }else if( navi.access && navi.access == "admin_dept" ){
  178. if( this.app.isDepartmentManager() || this.app.isAdmin() )this.createNaviNode(navi);
  179. }else{
  180. this.createNaviNode(navi);
  181. }
  182. }.bind(this));
  183. if( this.options.id == "" )this.elements[0].click();
  184. }.bind(this));
  185. },
  186. createNaviNode :function(data){
  187. if( data.type == "sep" ){
  188. var flag = true;
  189. if( data.access == "admin" ){
  190. if( !this.app.isAdmin() )flag = false;
  191. }else if( data.access && data.access == "admin_dept" ){
  192. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )flag = false;
  193. }
  194. if( flag ){
  195. new Element("div", { "styles": this.css.viewNaviSepartorNode }).inject(this.node);
  196. }
  197. }else if( data.sub && data.sub.length > 0 ){
  198. this.createNaviMenuNode(data);
  199. }else{
  200. this.menus[data.id] = {};
  201. this.createNaviItemNode(data, data.id);
  202. }
  203. },
  204. createNaviMenuNode :function(data){
  205. if( data.access == "admin" ){
  206. if( !this.app.isAdmin() )return;
  207. }else if(data.access == "admin_dept"){
  208. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )return;
  209. }
  210. var _self = this;
  211. var menuNode = new Element("div", {
  212. "styles": this.css.naviMenuNode
  213. });
  214. menuNode.store("data", data);
  215. menuNode.store("type", "menu");
  216. var textNode = new Element("div", {
  217. "styles": this.css.naviMenuTextNode,
  218. "text": data.title
  219. });
  220. textNode.inject(menuNode);
  221. menuNode.inject(this.node);
  222. this.menus[data.id] = {};
  223. this.menus[data.id].node = menuNode;
  224. this.elements.push(menuNode);
  225. menuNode.addEvents({
  226. "mouseover": function(){ if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  227. "mouseout": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode);},
  228. "mousedown": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_down);},
  229. "mouseup": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  230. "click": function(){
  231. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  232. _self.clickMenu.apply(_self, [this]);
  233. }
  234. });
  235. data.sub.each(function( d ){
  236. this.createNaviItemNode( d, data.id, menuNode )
  237. }.bind(this))
  238. },
  239. clickMenu: function(naviNode) {
  240. var navi = naviNode.retrieve("data");
  241. var action = navi.action;
  242. this.closeCurrentMenu();
  243. if( this.menus[navi.id].itemNodes ) {
  244. this.menus[navi.id].itemNodes.each( function(itemNode){
  245. itemNode.setStyle("display","block");
  246. })
  247. }
  248. var type = naviNode.retrieve("type");
  249. if (!navi.target || navi.target != "_blank") {
  250. naviNode.setStyles( this.css.naviMenuNode_current );
  251. this.currentMenu = naviNode;
  252. }
  253. },
  254. closeCurrentMenu:function(){
  255. if( this.currentMenu ) {
  256. var data = this.currentMenu.retrieve("data");
  257. if (this.menus[data.id].itemNodes) {
  258. this.menus[data.id].itemNodes.each(function (itemNode) {
  259. itemNode.setStyle("display", "none");
  260. })
  261. }
  262. this.currentMenu.setStyles( this.css.naviMenuNode);
  263. }
  264. },
  265. createNaviItemNode : function( data,menuId ){
  266. if( data.access == "admin" ){
  267. if( !this.app.isAdmin() )return;
  268. }else if( data.access && data.access == "admin_dept" ){
  269. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )return;
  270. }
  271. var _self = this;
  272. var items = this.menus[menuId].itemNodes = this.menus[menuId].itemNodes || [];
  273. var itemNode = new Element("div", {
  274. "styles": this.css.naviItemNode
  275. });
  276. itemNode.setStyle("display","block");
  277. items.push(itemNode);
  278. itemNode.store("data", data);
  279. itemNode.store("type", "item");
  280. var textNode = new Element("div", {
  281. "styles": this.css.naviItemTextNode,
  282. "text": data.title
  283. });
  284. textNode.inject(itemNode);
  285. itemNode.inject(this.node);
  286. this.elements.push(itemNode);
  287. this.items[data.id] = itemNode;
  288. itemNode.addEvents({
  289. "mouseover": function(){ if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  290. "mouseout": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode);},
  291. "mousedown": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_down);},
  292. "mouseup": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  293. "click": function(){
  294. _self.clickItem.apply(_self, [this]);
  295. }
  296. });
  297. if( data.id == this.options.id ){
  298. itemNode.click();
  299. }
  300. },
  301. clickItem : function(naviNode) {
  302. var navi = naviNode.retrieve("data");
  303. var action = navi.action;
  304. var type = naviNode.retrieve("type");
  305. if (!navi.target || navi.target != "_blank") {
  306. if (this.currentItem) this.currentItem.setStyles(this.css.naviItemNode);
  307. naviNode.setStyles(this.css.naviItemNode_current);
  308. this.currentItem = naviNode;
  309. }
  310. if (navi.action && this.app[navi.action]) {
  311. this.app[navi.action].call(this.app, navi);
  312. }
  313. }
  314. });