Main.js 9.6 KB

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