Main.js 9.7 KB

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