Main.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. MWF.Require("MWF.widget.Tablet", null, false);
  64. //this.loadApplicationLayout();
  65. },
  66. loaNavi: function(callback){
  67. this.naviNode = new Element("div.naviNode", {
  68. "styles": this.css.naviNode
  69. }).inject(this.node);
  70. var curNavi = { "id" : "" }
  71. if( this.status ){
  72. curNavi.id = this.status.id
  73. }
  74. this.navi = new MWF.xApplication.Template.Navi(this, this.naviNode, curNavi );
  75. },
  76. clearContent: function(){
  77. if (this.explorerContent){
  78. if (this.explorer) delete this.explorer;
  79. this.explorerContent.destroy();
  80. this.explorerContent = null;
  81. }
  82. },
  83. openMediaRecorder : function(){
  84. MWF.xDesktop.requireApp("Template", "Test", function(){
  85. this.clearContent();
  86. this.explorerContent = new Element("div", {
  87. "styles": this.css.rightContentNode
  88. }).inject(this.node);
  89. MWF.xDesktop.requireApp("Template", "Test", null, false);
  90. var test = new MWF.xApplication.Template.Test(this, { "reportId" : this.options.id }, {}, {
  91. app : this
  92. });
  93. test.open();
  94. }.bind(this));
  95. },
  96. openExplorer : function(){
  97. MWF.xDesktop.requireApp("Template", "Explorer", function(){
  98. this.clearContent();
  99. this.explorerContent = new Element("div", {
  100. "styles": this.css.rightContentNode
  101. }).inject(this.node);
  102. this.explorer = new MWF.xApplication.Template.Explorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  103. this.explorer.load();
  104. }.bind(this));
  105. },
  106. openDepartmentIndex : function(){
  107. MWF.xDesktop.requireApp("Template", "DepartmentIndex", function(){
  108. this.clearContent();
  109. this.explorerContent = new Element("div", {
  110. "styles": this.css.rightContentNode
  111. }).inject(this.node);
  112. this.explorer = new MWF.xApplication.Template.DepartmentIndex(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  113. this.explorer.load();
  114. }.bind(this));
  115. },
  116. openHolidaySetting : function(){
  117. MWF.xDesktop.requireApp("Template", "HolidayExplorer", function(){
  118. this.clearContent();
  119. this.explorerContent = new Element("div", {
  120. "styles": this.css.rightContentNode
  121. }).inject(this.node);
  122. this.explorer = new MWF.xApplication.Template.HolidayExplorer(this.explorerContent, this, this.restActions,{"isAdmin":this.isAdmin() } );
  123. this.explorer.load();
  124. }.bind(this));
  125. },
  126. recordStatus: function(){
  127. return this.navi && this.navi.currentItem ? this.navi.currentItem.retrieve("data") : {};
  128. }
  129. });
  130. MWF.xApplication.Template.Navi = new Class({
  131. Implements: [Options, Events],
  132. options : {
  133. "id" : ""
  134. },
  135. initialize: function(app, node, options){
  136. this.setOptions(options);
  137. this.app = app;
  138. this.node = $(node);
  139. this.css = this.app.css;
  140. this.currentMenu = null;
  141. this.currentItem = null;
  142. this.menus = {};
  143. this.items = {};
  144. this.elements = [];
  145. this.load();
  146. },
  147. load: function(){
  148. var naviUrl = this.app.path+"navi.json";
  149. MWF.getJSON(naviUrl, function(json){
  150. json.each(function(navi){
  151. if( navi.access && navi.access == "admin" ){
  152. if( this.app.isAdmin() )this.createNaviNode(navi);
  153. }else if( navi.access && navi.access == "admin_dept" ){
  154. if( this.app.isDepartmentManager() || this.app.isAdmin() )this.createNaviNode(navi);
  155. }else{
  156. this.createNaviNode(navi);
  157. }
  158. }.bind(this));
  159. if( this.options.id == "" )this.elements[0].click();
  160. }.bind(this));
  161. },
  162. createNaviNode :function(data){
  163. if( data.type == "sep" ){
  164. var flag = true;
  165. if( data.access == "admin" ){
  166. if( !this.app.isAdmin() )flag = false;
  167. }else if( data.access && data.access == "admin_dept" ){
  168. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )flag = false;
  169. }
  170. if( flag ){
  171. new Element("div", { "styles": this.css.viewNaviSepartorNode }).inject(this.node);
  172. }
  173. }else if( data.sub && data.sub.length > 0 ){
  174. this.createNaviMenuNode(data);
  175. }else{
  176. this.menus[data.id] = {};
  177. this.createNaviItemNode(data, data.id);
  178. }
  179. },
  180. createNaviMenuNode :function(data){
  181. if( data.access == "admin" ){
  182. if( !this.app.isAdmin() )return;
  183. }else if(data.access == "admin_dept"){
  184. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )return;
  185. }
  186. var _self = this;
  187. var menuNode = new Element("div", {
  188. "styles": this.css.naviMenuNode
  189. });
  190. menuNode.store("data", data);
  191. menuNode.store("type", "menu");
  192. var textNode = new Element("div", {
  193. "styles": this.css.naviMenuTextNode,
  194. "text": data.title
  195. });
  196. textNode.inject(menuNode);
  197. menuNode.inject(this.node);
  198. this.menus[data.id] = {};
  199. this.menus[data.id].node = menuNode;
  200. this.elements.push(menuNode);
  201. menuNode.addEvents({
  202. "mouseover": function(){ if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  203. "mouseout": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode);},
  204. "mousedown": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_down);},
  205. "mouseup": function(){if (_self.currentMenu!=this) this.setStyles(_self.app.css.naviMenuNode_over);},
  206. "click": function(){
  207. //if (_self.currentNavi!=this) _self.doAction.apply(_self, [this]);
  208. _self.clickMenu.apply(_self, [this]);
  209. }
  210. });
  211. data.sub.each(function( d ){
  212. this.createNaviItemNode( d, data.id, menuNode )
  213. }.bind(this))
  214. },
  215. clickMenu: function(naviNode) {
  216. var navi = naviNode.retrieve("data");
  217. var action = navi.action;
  218. this.closeCurrentMenu();
  219. if( this.menus[navi.id].itemNodes ) {
  220. this.menus[navi.id].itemNodes.each( function(itemNode){
  221. itemNode.setStyle("display","block");
  222. })
  223. }
  224. var type = naviNode.retrieve("type");
  225. if (!navi.target || navi.target != "_blank") {
  226. naviNode.setStyles( this.css.naviMenuNode_current );
  227. this.currentMenu = naviNode;
  228. }
  229. },
  230. closeCurrentMenu:function(){
  231. if( this.currentMenu ) {
  232. var data = this.currentMenu.retrieve("data");
  233. if (this.menus[data.id].itemNodes) {
  234. this.menus[data.id].itemNodes.each(function (itemNode) {
  235. itemNode.setStyle("display", "none");
  236. })
  237. }
  238. this.currentMenu.setStyles( this.css.naviMenuNode);
  239. }
  240. },
  241. createNaviItemNode : function( data,menuId ){
  242. if( data.access == "admin" ){
  243. if( !this.app.isAdmin() )return;
  244. }else if( data.access && data.access == "admin_dept" ){
  245. if( !this.app.isDepartmentManager() && !this.app.isAdmin() )return;
  246. }
  247. var _self = this;
  248. var items = this.menus[menuId].itemNodes = this.menus[menuId].itemNodes || [];
  249. var itemNode = new Element("div", {
  250. "styles": this.css.naviItemNode
  251. });
  252. itemNode.setStyle("display","block");
  253. items.push(itemNode);
  254. itemNode.store("data", data);
  255. itemNode.store("type", "item");
  256. var textNode = new Element("div", {
  257. "styles": this.css.naviItemTextNode,
  258. "text": data.title
  259. });
  260. textNode.inject(itemNode);
  261. itemNode.inject(this.node);
  262. this.elements.push(itemNode);
  263. this.items[data.id] = itemNode;
  264. itemNode.addEvents({
  265. "mouseover": function(){ if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  266. "mouseout": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode);},
  267. "mousedown": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_down);},
  268. "mouseup": function(){if (_self.currentItem!=this) this.setStyles(_self.app.css.naviItemNode_over);},
  269. "click": function(){
  270. _self.clickItem.apply(_self, [this]);
  271. }
  272. });
  273. if( data.id == this.options.id ){
  274. itemNode.click();
  275. }
  276. },
  277. clickItem : function(naviNode) {
  278. var navi = naviNode.retrieve("data");
  279. var action = navi.action;
  280. var type = naviNode.retrieve("type");
  281. if (!navi.target || navi.target != "_blank") {
  282. if (this.currentItem) this.currentItem.setStyles(this.css.naviItemNode);
  283. naviNode.setStyles(this.css.naviItemNode_current);
  284. this.currentItem = naviNode;
  285. }
  286. if (navi.action && this.app[navi.action]) {
  287. this.app[navi.action].call(this.app, navi);
  288. }
  289. }
  290. });