SettingModuleMenu.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. o2.require("o2.xDesktop.Default", null, false);
  2. o2.xApplication.Setting.ModuleMenuDocument = new Class({
  3. Extends: MWF.xApplication.Common.Main,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default"
  7. },
  8. initialize: function(explorer, content, options){
  9. this.setOptions(options);
  10. this.content = content;
  11. this.explorer = explorer;
  12. this.app = this.explorer.app;
  13. this.css = this.app.css;
  14. this.lp = this.app.lp.module;
  15. this.load();
  16. },
  17. "destroy": function(){
  18. // this.appDeploymentContent.destroy();
  19. // this.content.empty();
  20. // if (this.setContentHeightFun) this.app.removeEvent("resize", this.setContentHeightFun);
  21. MWF.release(this);
  22. },
  23. load: function(){
  24. this.menuShowArea = new Element("div", {
  25. styles: {
  26. "height": "100%",
  27. "overflow": "hidden",
  28. "width": "400px",
  29. "float": "left"
  30. }
  31. }).inject(this.content);
  32. this.actionsArea = new Element("div", {
  33. styles: {
  34. "height": "calc( 100% - 40px )",
  35. "overflow": "hidden",
  36. "margin-left": "420px",
  37. "padding": "20px 20px"
  38. }
  39. }).inject(this.content);
  40. this.startMenu = new o2.xApplication.Setting.ModuleMenuDocument.StartMenu(this);
  41. this.startMenu.addEvents({
  42. // "onHide": function(){
  43. // this.startMenuNode.removeClass("overColor_bg");
  44. // }.bind(this),
  45. "onLoad": function(){
  46. if (!this.startMenu.isShow){
  47. this.startMenu.show();
  48. }
  49. this.createDefaultMenuDataActions();
  50. this.createForceMenuDataActions();
  51. this.createCustomMenuDataActions();
  52. }.bind(this)
  53. });
  54. this.startMenu.load();
  55. },
  56. createDefaultMenuDataActions: function(){
  57. var node = new Element("div", {"styles": {"margin-bottom": "40px", "overflow": "hidden"}}).inject(this.actionsArea);
  58. new Element("div", {"styles": this.css.menuDataInfor,"text": this.app.lp.saveDefaultMenuDataInfor}).inject(node);
  59. this.createButton(this.app.lp.saveDefaultMenuData, this.saveDefaultMenuData.bind(this)).inject(node);
  60. this.createButton(this.app.lp.clearDefaultMenuData, this.clearDefaultMenuData.bind(this), "grayColor_bg", "grayColor_bg", "grayColor_bg").inject(node)
  61. if (this.startMenu.defaultData){
  62. this.createButton(this.app.lp.loadDefaultMenuData, this.loadDefaultMenuData.bind(this), "grayColor_bg", "grayColor_bg", "grayColor_bg").inject(node)
  63. }
  64. },
  65. createForceMenuDataActions: function(){
  66. var node = new Element("div", {"styles": {"margin-bottom": "40px", "overflow": "hidden"}}).inject(this.actionsArea);
  67. new Element("div", {"styles": this.css.menuDataInfor,"text": this.app.lp.saveForceMenuDataInfor}).inject(node);
  68. this.createButton(this.app.lp.saveForceMenuData, this.saveForceMenuData.bind(this)).inject(node);
  69. this.createButton(this.app.lp.clearForceMenuData, this.clearForceMenuData.bind(this), "grayColor_bg", "grayColor_bg", "grayColor_bg").inject(node)
  70. if (this.startMenu.forceData){
  71. this.createButton(this.app.lp.loadForceMenuData, this.loadForceMenuData.bind(this), "grayColor_bg", "grayColor_bg", "grayColor_bg").inject(node)
  72. }
  73. },
  74. createCustomMenuDataActions: function(){
  75. var node = new Element("div", {"styles": {"margin-bottom": "40px", "overflow": "hidden"}}).inject(this.actionsArea);
  76. new Element("div", {"styles": this.css.menuDataInfor,"text": this.app.lp.clearCustomMenuDataInfor}).inject(node);
  77. this.createButton(this.app.lp.clearCustomMenuData, this.clearCustomMenuData.bind(this), "grayColor_bg", "grayColor_bg", "grayColor_bg").inject(node)
  78. },
  79. createButton: function(text, action, main, over, down){
  80. var mainClass = main || "mainColor_bg";
  81. var overClass = over || "overColor_bg";
  82. var downClass = down || "deepColor_bg";
  83. var button = new Element("div."+mainClass, {"type": "button", "styles": this.css.buttonNode, "text": text});
  84. button.addEvents({
  85. "click": function(){
  86. if (action) action(button);
  87. }.bind(this),
  88. "mouseover": function(){this.removeClass(mainClass); this.removeClass(downClass); this.addClass(overClass);},
  89. "mouseout": function(){this.removeClass(overClass); this.removeClass(downClass); this.addClass(mainClass);},
  90. "mousedown": function(){this.removeClass(mainClass); this.removeClass(overClass); this.addClass(downClass);},
  91. "mouseup": function(){this.removeClass(mainClass); this.removeClass(downClass); this.addClass(overClass);}
  92. });
  93. return button
  94. },
  95. saveDefaultMenuData: function(){
  96. if (this.startMenu){
  97. this.startMenu.resetMenuData();
  98. if (this.startMenu.menuData){
  99. o2.UD.putPublicData("defaultMainMenuData", this.startMenu.menuData, function(){
  100. this.app.notice(this.app.lp.saveDefaultMenuDataSuccess, "success");
  101. }.bind(this));
  102. }
  103. }
  104. },
  105. clearDefaultMenuData: function(bt){
  106. var _self = this;
  107. this.app.confirm("warn", bt, this.app.lp.clearDefaultMenuData, this.app.lp.clearDefaultMenuDataConfirm, 380, 120, function(){
  108. o2.UD.deletePublicData("defaultMainMenuData", function(){
  109. _self.app.notice(_self.app.lp.clearDefaultMenuDataSuccess, "success");
  110. });
  111. this.close();
  112. }, function(){
  113. this.close();
  114. });
  115. },
  116. saveForceMenuData: function(){
  117. if (this.startMenu){
  118. this.startMenu.resetMenuData();
  119. if (this.startMenu.menuData){
  120. o2.UD.putPublicData("forceMainMenuData", this.startMenu.menuData, function(){
  121. this.app.notice(this.app.lp.saveForceMenuDataSuccess, "success");
  122. }.bind(this));
  123. }
  124. }
  125. },
  126. clearForceMenuData: function(bt){
  127. var _self = this;
  128. this.app.confirm("warn", bt, this.app.lp.clearForceMenuData, this.app.lp.clearForceMenuDataConfirm, 380, 120, function(){
  129. o2.UD.deletePublicData("forceMainMenuData", function(){
  130. _self.app.notice(_self.app.lp.clearForceMenuDataSuccess, "success");
  131. });
  132. this.close();
  133. }, function(){
  134. this.close();
  135. });
  136. },
  137. clearCustomMenuData: function(bt){
  138. var _self = this;
  139. this.app.confirm("warn", bt, this.app.lp.clearForceMenuData, this.app.lp.clearCustomMenuDataConfirm, 380, 120, function(){
  140. o2.require("o2.widget.UUID", function(){
  141. var id = new o2.widget.UUID();
  142. o2.UD.putPublicData("clearCustomMenuDataFlag", {"id": id.toString()}, function(){
  143. _self.app.notice(_self.app.lp.clearForceMenuDataSuccess, "success");
  144. });
  145. this.close();
  146. }.bind(this));
  147. }, function(){
  148. this.close();
  149. });
  150. },
  151. loadForceMenuData: function(){
  152. if (this.startMenu){
  153. this.startMenu.reload(this.startMenu.forceData);
  154. }
  155. },
  156. loadDefaultMenuData: function(){
  157. if (this.startMenu){
  158. this.startMenu.reload(this.startMenu.defaultData);
  159. }
  160. }
  161. });
  162. o2.xApplication.Setting.ModuleMenuDocument.StartMenu = new Class({
  163. Extends: o2.xDesktop.Default.StartMenu,
  164. Implements: [Events],
  165. initialize: function (setting) {
  166. this.layout = layout.desktop;
  167. this.setting = setting;
  168. this.container = this.setting.menuShowArea;
  169. //this.actionNode = this.setting.startMenuNode;
  170. this.isLoaded = false;
  171. this.isShow = false;
  172. this.isMorph = false;
  173. this.items = [];
  174. // this.menuData = (this.layout.status && this.layout.status.menuData) ? Object.clone(this.layout.status.menuData) : {
  175. // "appList": [],
  176. // "processList": [],
  177. // "inforList": [],
  178. // "queryList": []
  179. // };
  180. this.itemTempletedHtml = "" +
  181. " <div class='layout_start_item_iconArea'>" +
  182. " <div class='layout_start_item_icon'></div>" +
  183. " </div>" +
  184. " <div class='layout_start_item_text'></div>" +
  185. " <div class='layout_start_item_badge'></div>";
  186. this.checkLayout();
  187. },
  188. loadMenuData: function(callback){
  189. debugger;
  190. this.menuData = (this.layout.status && this.layout.status.menuData) ? Object.clone(this.layout.status.menuData) : {
  191. "appList": [],
  192. "processList": [],
  193. "inforList": [],
  194. "queryList": []
  195. };
  196. var forceData = null, defaultData = null;
  197. var forceLoaded = false, defaultLoaded = false;
  198. var check = function(){
  199. if (forceLoaded && defaultLoaded){
  200. this.forceData = forceData;
  201. this.defaultData = defaultData;
  202. if (forceData){
  203. this.menuData=forceData;
  204. }else if (defaultData){
  205. this.menuData=defaultData;
  206. }
  207. if (callback) callback();
  208. }
  209. }.bind(this)
  210. o2.UD.getPublicData("forceMainMenuData", function(fData){
  211. forceData = fData;
  212. forceLoaded = true;
  213. check();
  214. }.bind(this));
  215. o2.UD.getPublicData("defaultMainMenuData", function(dData){
  216. defaultData = dData;
  217. defaultLoaded = true;
  218. check();
  219. }.bind(this));
  220. },
  221. load: function(){
  222. this.loadMenuData(function(){
  223. var view = this.layout.path+this.layout.options.style+((o2.session.isMobile || layout.mobile) ? "/layout-menu-mobile.html" : "/layout-menu-pc.html");
  224. this.container.loadHtml(view, {"module": this}, function(){
  225. this.maskNode.destroy();
  226. this.node.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  227. //this.layout.menuNode.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  228. this.node.addEvent("mousedown", function(e){
  229. e.stopPropagation();
  230. e.preventDefault();
  231. });
  232. // this.triangleNode = new Element("div.layout_menu_start_triangle").inject(this.layout.menuNode, "after");
  233. // this.hideMessage = function(){ this.hide(); }.bind(this);
  234. //this.fireEvent("load");
  235. this.layout.addEvent("resize", this.setSize.bind(this));
  236. this.loadTitle();
  237. this.loadLnks();
  238. this.setSize();
  239. this.isLoaded = true;
  240. this.fireEvent("load");
  241. }.bind(this));
  242. }.bind(this));
  243. },
  244. setSize: function(){
  245. if (this.appScrollBar && this.appScrollBar.scrollVNode) this.appScrollBar.scrollVNode.setStyle("margin-top", "0px");
  246. var isLnk = false;
  247. if (false && this.layout.lnks && this.layout.lnks.length){
  248. this.lnkAreaNode.show();
  249. this.lineNode.show();
  250. var h = 100*3;
  251. this.lnkScrollNode.setStyle("height", ""+h+"px");
  252. isLnk = true;
  253. }else{
  254. this.lnkAreaNode.hide();
  255. this.lineNode.hide();
  256. }
  257. debugger;
  258. if( !this.node.offsetParent )this.node.show();
  259. var size = this.node.getSize();
  260. var lnkSizeY = (isLnk) ? this.lnkAreaNode.getSize().y : 0;
  261. var lineSizeY = (isLnk) ? this.lineNode.getSize().y : 0;
  262. var mt = (isLnk) ? (this.lineNode.getStyle("margin-top").toInt() || 0) : 0;
  263. var mb = (isLnk) ? (this.lineNode.getStyle("margin-bottom").toInt() || 0) : 0;
  264. var titleSize = this.appTitleNode.getSize();
  265. var y = size.y-lnkSizeY-lineSizeY-mt-mb-titleSize.y - 40;
  266. this.appScrollNode.setStyle("height", ""+y+"px");
  267. },
  268. checkLayout: function(){
  269. if( !this.layout.path )this.layout.path = o2.session.path+"/xDesktop/$Default/";
  270. if( !this.layout.options )this.layout.options = {};
  271. if( !this.layout.options.style )this.layout.options.style = "blue";
  272. },
  273. reload: function(menuData){
  274. this.menuData = menuData || {
  275. "appList": [],
  276. "processList": [],
  277. "inforList": [],
  278. "queryList": []
  279. };
  280. this.container.empty();
  281. var view = this.layout.path+this.layout.options.style+((o2.session.isMobile || layout.mobile) ? "/layout-menu-mobile.html" : "/layout-menu-pc.html");
  282. this.container.loadHtml(view, {"module": this}, function(){
  283. if (this.maskNode) this.maskNode.destroy();
  284. this.node.addEvent("mousedown", function(e){
  285. e.stopPropagation();
  286. e.preventDefault();
  287. });
  288. this.loadTitle();
  289. this.loadLnks();
  290. this.node.setStyles({
  291. "display": "block",
  292. "position": "relative",
  293. "left": "0",
  294. "top": "0"
  295. });
  296. this.loadJsons(function(){
  297. (this.currentTab || this.appCategoryTab).click();
  298. }.bind(this));
  299. this.isShow = true;
  300. this.setScroll();
  301. this.isLoaded = true;
  302. }.bind(this));
  303. },
  304. show: function(){
  305. this.node.setStyles({
  306. "display": "block",
  307. "position": "relative",
  308. "left": "0",
  309. "top": "0"
  310. });
  311. this.appAreaNode.setStyles({ "filter": "" });
  312. this.loadJsons(function(){
  313. (this.currentTab || this.appCategoryTab).click();
  314. }.bind(this));
  315. this.isShow = true;
  316. this.isMorph = false;
  317. this.setScroll();
  318. },
  319. hide: function(){
  320. },
  321. createApplicationMenuItem: function(value){
  322. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.Item(this, this.appContentNode, value));
  323. },
  324. createPortalMenuItem: function(value){
  325. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.PortalItem(this, this.appContentNode, value));
  326. },
  327. createProcessMenuItem: function(value){
  328. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.ProcessItem(this, this.appContentNode, value));
  329. },
  330. createInforMenuItem: function(value){
  331. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.InforItem(this, this.appContentNode, value));
  332. },
  333. createQueryMenuItem: function(value){
  334. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.QueryItem(this, this.appContentNode, value));
  335. },
  336. createGroupMenuItem: function(value){
  337. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.GroupItem(this, this.appContentNode, value));
  338. },
  339. resetMenuData: function(){
  340. if (!this.menuData) this.menuData = {
  341. "appList": [],
  342. "processList": [],
  343. "inforList": [],
  344. "queryList": []
  345. }
  346. var nodes = this.appContentNode.getChildren();
  347. var data = [];
  348. nodes.each(function(node){
  349. var item = node.retrieve("item");
  350. if (item){
  351. if (item.data.type==="group"){
  352. var d = {
  353. "id": item.data.id,
  354. "name": item.data.name,
  355. "type": item.data.type,
  356. "itemDataList": []
  357. }
  358. if (item.data.itemDataList) item.data.itemDataList.each(function(i){
  359. d.itemDataList.push(i);
  360. });
  361. data.push(d);
  362. }else{
  363. data.push({
  364. "id": item.data.id,
  365. "name": item.data.name,
  366. "type": item.data.type,
  367. });
  368. }
  369. }
  370. }.bind(this));
  371. if (this.currentTab === this.appCategoryTab){
  372. this.menuData.appList = data;
  373. }else if (this.currentTab === this.processCategoryTab){
  374. this.menuData.processList = data;
  375. }else if (this.currentTab === this.inforCategoryTab){
  376. this.menuData.inforList = data;
  377. }else if (this.currentTab === this.queryCategoryTab){
  378. this.menuData.queryList = data;
  379. }
  380. //this.layout.menuData = this.menuData;
  381. },
  382. defaultMenu: function(){
  383. this.menuData = null;
  384. this.reload();
  385. }
  386. });
  387. o2.xApplication.Setting.ModuleMenuDocument.StartMenu.Item = new Class({
  388. Extends: o2.xDesktop.Default.StartMenu.Item,
  389. loadBadge: function(){
  390. this.badgeNode.hide();
  391. },
  392. _drag_drag: function(dragging, e){
  393. if (this.dragStatus == "group"){
  394. if (!this.onGroup) this.checkDargOver(dragging);
  395. if (!this.overItem){
  396. this.checkDargPosition(dragging);
  397. }
  398. }
  399. }
  400. });
  401. o2.xApplication.Setting.ModuleMenuDocument.StartMenu.GroupItem = new Class({
  402. Extends: o2.xDesktop.Default.StartMenu.GroupItem,
  403. loadBadge: function(){
  404. this.badgeNode.hide();
  405. },
  406. _drag_drag: function(dragging, e){
  407. if (this.dragStatus == "group"){
  408. if (!this.onGroup) this.checkDargOver(dragging);
  409. if (!this.overItem){
  410. this.checkDargPosition(dragging);
  411. }
  412. }
  413. },
  414. loadItems: function(){
  415. if (!this.items) this.items = [];
  416. this.data.itemDataList.each(function(data){
  417. var item = this.items.find(function(i){
  418. return i.data.id == data.id;
  419. });
  420. if (!item){
  421. switch (data.type){
  422. case "portal":
  423. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.PortalItem(this, this.menuContentNode, data));
  424. break;
  425. case "process":
  426. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.ProcessItem(this, this.menuContentNode, data));
  427. break;
  428. case "cms":
  429. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.InforItem(this, this.menuContentNode, data));
  430. break;
  431. case "query":
  432. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.QueryItem(this, this.menuContentNode, data));
  433. break;
  434. default:
  435. this.items.push(new o2.xApplication.Setting.ModuleMenuDocument.StartMenu.Item(this, this.menuContentNode, data));
  436. }
  437. }
  438. }.bind(this));
  439. },
  440. });
  441. o2.xApplication.Setting.ModuleMenuDocument.StartMenu.PortalItem = new Class({
  442. Extends: o2.xDesktop.Default.StartMenu.PortalItem,
  443. loadBadge: function(){
  444. this.badgeNode.hide();
  445. },
  446. _drag_drag: function(dragging, e){
  447. if (this.dragStatus == "group"){
  448. if (!this.onGroup) this.checkDargOver(dragging);
  449. if (!this.overItem){
  450. this.checkDargPosition(dragging);
  451. }
  452. }
  453. }
  454. });
  455. o2.xApplication.Setting.ModuleMenuDocument.StartMenu.ProcessItem = new Class({
  456. Extends: o2.xDesktop.Default.StartMenu.ProcessItem,
  457. loadBadge: function(){
  458. this.badgeNode.hide();
  459. },
  460. _drag_drag: function(dragging, e){
  461. if (this.dragStatus == "group"){
  462. if (!this.onGroup) this.checkDargOver(dragging);
  463. if (!this.overItem){
  464. this.checkDargPosition(dragging);
  465. }
  466. }
  467. }
  468. });
  469. o2.xApplication.Setting.ModuleMenuDocument.StartMenu.InforItem = new Class({
  470. Extends: o2.xDesktop.Default.StartMenu.InforItem,
  471. loadBadge: function(){
  472. this.badgeNode.hide();
  473. },
  474. _drag_drag: function(dragging, e){
  475. if (this.dragStatus == "group"){
  476. if (!this.onGroup) this.checkDargOver(dragging);
  477. if (!this.overItem){
  478. this.checkDargPosition(dragging);
  479. }
  480. }
  481. }
  482. });
  483. o2.xApplication.Setting.ModuleMenuDocument.StartMenu.QueryItem = new Class({
  484. Extends: o2.xDesktop.Default.StartMenu.QueryItem,
  485. loadBadge: function(){
  486. this.badgeNode.hide();
  487. },
  488. _drag_drag: function(dragging, e){
  489. if (this.dragStatus == "group"){
  490. if (!this.onGroup) this.checkDargOver(dragging);
  491. if (!this.overItem){
  492. this.checkDargPosition(dragging);
  493. }
  494. }
  495. }
  496. });