Layout.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. MWF.xApplication.Setting.preview = MWF.xApplication.Setting.preview || {};
  2. MWF.xApplication.Setting.preview.Layout = new Class({
  3. Extends: MWF.xDesktop.Layout,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "topShim": "layout_top_shim",
  8. "top": "layout_top",
  9. "desktop": "layout_desktop",
  10. "content": "desktop_content",
  11. "navi": "desktop_navi"
  12. },
  13. categoryCount: 20,
  14. processCount: 40,
  15. initialize: function(node, options){
  16. this.setOptions(options);
  17. this.initData();
  18. this.session.user = layout.desktop.session.user;
  19. this.node = $(node);
  20. },
  21. initNode: function(node){
  22. this.path = MWF.defaultPath+"/xDesktop/$Layout/";
  23. var html = "<div id=\"layout\" style=\"overflow: hidden; height: 100%; background-size: cover;\">\n" +
  24. " <div id=\"layout_top_shim\"></div>\n" +
  25. " <div id=\"layout_top\"></div>\n" +
  26. " <div id=\"layout_desktop\">\n" +
  27. " <div id=\"desktop_content\">\n" +
  28. " \n" +
  29. " <div id=\"desktop_navi\"></div>\n" +
  30. " </div>\n" +
  31. " </div>";
  32. this.node.set("html", html);
  33. this.node = this.node.getFirst();
  34. this.topShimNode = this.node.getElement("#"+this.options.topShim);
  35. this.topNode = this.node.getElement("#"+this.options.top);
  36. this.topAreaNode = this.node.getElement("#"+this.options.top);
  37. this.desktopNode = this.node.getElement("#"+this.options.desktop);
  38. this.contentNode = this.node.getElement("#"+this.options.content);
  39. this.naviNode = this.node.getElement("#"+this.options.navi);
  40. if (this.node) this.node.setStyles(this.css.layoutNode);
  41. if (this.topShimNode) this.topShimNode.setStyles(this.css.layoutTopShimNode);
  42. if (this.topNode) this.topNode.setStyles(this.css.layoutTopNode);
  43. if (this.desktopNode) this.desktopNode.setStyles(this.css.desktopNode);
  44. if (this.contentNode) this.contentNode.setStyles(this.css.contentNode);
  45. if (this.naviNode) this.naviNode.setStyles(this.css.naviNode);
  46. this.node.setStyle("background-image", this.css.desktop.background);
  47. this.node.setStyles(this.options.styles);
  48. //"url("+this.css.desktop.background+")"
  49. },
  50. initData: function(callback){
  51. this.apps = {};
  52. this.widgets = {};
  53. this.appCurrentList = [];
  54. this.lnkAreas = [];
  55. this.lnks = [];
  56. this.currentApp = null;
  57. this.status = null;
  58. this.session = {};
  59. this.serviceAddressList = null;
  60. },
  61. load : function(){
  62. this.initNode();
  63. this.loadDesktop();
  64. this.loadWindow();
  65. //
  66. // this.isAuthentication(function(){
  67. // if (this.status){
  68. // if (this.status.style){
  69. // if (this.options.style !== this.status.style){
  70. // this.changStyle(this.status.style);
  71. // }
  72. // }
  73. // }
  74. // this.getNodeBackground();
  75. //
  76. // this.loadDesktop();
  77. //
  78. // if (this.session.user.passwordExpired){
  79. // this.openApplication({"page":{"x": 0, "y": 0}}, "Profile", {"tab": "passwordConfigPage"});
  80. // window.setTimeout(function(){
  81. // MWF.xDesktop.notice("error", {"y":"top", "x": "left"}, MWF.LP.desktop.notice.changePassword, this.desktopNode);
  82. // }.bind(this), 500);
  83. // }
  84. //
  85. // }.bind(this));
  86. },
  87. loadWindow: function(){
  88. var options = {
  89. "style": "desktop_default",
  90. "title": "app",
  91. "isResize": true,
  92. "isMax": true,
  93. "isRefresh": true,
  94. "container": this.node,
  95. "width": "400",
  96. "height": "280",
  97. "top": "100",
  98. "left": "50",
  99. "fromTop": "0",
  100. "fromLeft": "0",
  101. "isMove": false
  102. };
  103. this.window = new MWF.xDesktop.Window(this.app, options);
  104. this.window.css = this.windowCss;
  105. this.content = this.window.content;
  106. //if (animation===false){
  107. this.window.reStyle();
  108. this.window.showNoAnimation(false, false);
  109. //}else{
  110. // this.window.show();
  111. //}
  112. },
  113. maxOrRestoreSize: function(){},
  114. loadDesktop: function(){
  115. this.setHeight();
  116. var size = this.desktopNode.getSize();
  117. this.size = {
  118. "x" : size.x,
  119. "y": size.y
  120. };
  121. this.loadTop();
  122. this.loadLnkArea();
  123. },
  124. loadLnkAreaContainer: function(){
  125. this.lnkAreaContainer = new Element("div", {
  126. "styles": {
  127. "height": "100%",
  128. "overflow": "hidden"
  129. }
  130. }).inject(this.contentNode);
  131. },
  132. loadLnkArea: function(){
  133. if (!this.lnkAreaContainer) this.loadLnkAreaContainer();
  134. var lnkArea = new Element("div", {
  135. "styles": this.css.dsektopLnkArea
  136. }).inject(this.lnkAreaContainer);
  137. this.lnkAreas.push(lnkArea);
  138. var width = (lnkArea.getSize().x)*(this.lnkAreas.length);
  139. var contentSize = this.contentNode.getSize();
  140. this.lnkAreaContainer.setStyle("width", ""+Math.max(width, contentSize.x)+"px");
  141. this.setCurrentLnkArea();
  142. },
  143. setCurrentLnkArea: function(){
  144. if (this.lnkAreas.length>1){
  145. var lnkSize = this.lnkAreas[0].getSize().x;
  146. var width = (lnkSize)*(this.lnkAreas.length);
  147. var contentSize = this.contentNode.getSize();
  148. var currentArea = this.lnkAreas[this.lnkAreas.length-1];
  149. if (width<contentSize.x){
  150. width = width-lnkSize;
  151. currentArea.setStyles({
  152. "width": "auto",
  153. "margin-left": ""+width+"px",
  154. "float": "none"
  155. });
  156. }else{
  157. currentArea.setStyles(this.css.dsektopLnkArea);
  158. }
  159. }else{
  160. if (this.lnkAreas.length){
  161. this.lnkAreas[0].setStyles({
  162. "width": "auto",
  163. "margin-left": "0px",
  164. "float": "none"
  165. });
  166. }
  167. }
  168. },
  169. addLnkArea: function(){
  170. if (this.lnkAreas.length){
  171. this.lnkAreas[this.lnkAreas.length-1].setStyles(this.css.dsektopLnkArea);
  172. }
  173. this.loadLnkArea();
  174. },
  175. addLnk: function(json){
  176. var lnk = new MWF.xDesktop.Lnk(json.icon, json.title, json.par);
  177. if (!this.lnkAreas.length) this.loadLnkArea();
  178. lnk.inject(this.lnkAreas[this.lnkAreas.length-1]);
  179. this.lnks.push(lnk);
  180. },
  181. resizeLnk: function(){
  182. if (this.lnkAreaContainer){
  183. if (this.lnkAreas.length>1){
  184. var width = (this.lnkAreas[0].getSize().x)*(this.lnkAreas.length);
  185. var contentSize = this.contentNode.getSize();
  186. this.lnkAreaContainer.setStyle("width", ""+Math.max(width, contentSize.x)+"px");
  187. }else{
  188. this.lnkAreaContainer.setStyle("width", ""+this.contentNode.getSize().x+"px");
  189. }
  190. }
  191. var n=0;
  192. var count = 0;
  193. this.lnks.each(function(lnk, idx){
  194. while(!this.lnkAreas[n]) this.addLnkArea();
  195. var linkArea = this.lnkAreas[n];
  196. lnk.inject(linkArea);
  197. count++;
  198. //var y = lnk.node.getSize().y+lnk.node.getStyle("margin-top").toFloat()+lnk.node.getStyle("margin-bottom").toFloat();
  199. var y = lnk.node.getSize().y+lnk.node.getStyle("margin-top").toFloat();
  200. if (y*(count+1)>linkArea.getSize().y){
  201. if (idx<this.lnks.length-1) n++;
  202. count = 0;
  203. }
  204. }.bind(this));
  205. if (this.lnkAreas.length) while (this.lnkAreas.length>n+1 ) this.lnkAreas.pop().destroy();
  206. this.setCurrentLnkArea();
  207. },
  208. setHeight: function(){
  209. this.resizeHeight();
  210. $(window).addEvent("resize", function(){
  211. this.resizeHeight();
  212. }.bind(this));
  213. },
  214. resizeHeight: function(){
  215. var yTop = this.topNode.getSize().y;
  216. var yBody = this.node.getSize().y;
  217. var y = yBody - yTop;
  218. this.desktopNode.setStyle("height", ""+y+"px");
  219. this.desktopHeight = y;
  220. var yNavi = this.naviNode.getSize().y;
  221. y = y - yNavi;
  222. this.contentNode.setStyle("height", ""+y+"px");
  223. this.resizeLnk();
  224. this.resizeMessage();
  225. this.setTaskitemSize();
  226. if (this.top) if (this.top.userPanel) this.top.userPanel.setPosition();
  227. this.fireEvent("resize");
  228. },
  229. setTaskitemSize: function(){
  230. if (this.top){
  231. var x1 = 10;
  232. var x2 = 5;
  233. var size = this.top.taskbar.getSize();
  234. var taskItems = this.top.taskbar.getChildren();
  235. var allWidth = 0;
  236. if (taskItems.length){
  237. var w = taskItems[0].getStyles("border-left-width", "border-right-width", "margin-left", "margin-right", "padding-left", "padding-right");
  238. for (var i=0; i<taskItems.length; i++){
  239. taskItems[i].setStyle("width", "auto");
  240. allWidth += taskItems[i].getSize().x+w["border-left-width"].toInt()+w["border-right-width"].toInt()+w["margin-left"].toInt()+w["margin-right"].toInt()+w["padding-left"].toInt()+w["padding-right"].toInt();
  241. }
  242. if (allWidth>(size.x-x1)){
  243. var x = (size.x-x1)/taskItems.length;
  244. var width = x-w["border-left-width"].toInt()-w["border-right-width"].toInt()-w["margin-left"].toInt()-w["margin-right"].toInt()-w["padding-left"].toInt()-w["padding-right"].toInt();
  245. taskItems.each(function(item){
  246. item.setStyle("width", ""+width+"px");
  247. });
  248. }else{
  249. taskItems.each(function(item){
  250. item.setStyle("width", "auto");
  251. });
  252. }
  253. }
  254. }
  255. },
  256. resizeMessage: function(){
  257. if (this.message) this.message.resize();
  258. },
  259. loadTop: function(){
  260. if (!this.top){
  261. this.top = new MWF.xApplication.Setting.preview.Layout.Top(this.topNode, this);
  262. this.top.load();
  263. }
  264. },
  265. getNodeBackground: function(){
  266. MWF.UD.getDataJson("layoutDesktop", function(json){
  267. var dskImg = MWF.defaultPath+"/xDesktop/$Layout/"+this.options.style+"/desktop.jpg";
  268. if (json){
  269. currentSrc = json.src;
  270. dskImg = MWF.defaultPath+"/xDesktop/$Layout/"+currentSrc+"/desktop.jpg";
  271. }
  272. this.node.setStyle("background-image", "url("+dskImg+")");
  273. }.bind(this), false);
  274. }
  275. });
  276. MWF.xApplication.Setting.preview.Layout.Taskitem = new Class({
  277. initialize: function(app, layout){
  278. this.layout = layout;
  279. this.app = app;
  280. this.node = new Element("div", {
  281. "styles": this.layout.css.taskItemNode,
  282. "title": this.app.options.title+((this.app.appId) ? "-"+this.app.appId : "")
  283. }).inject(this.layout.top.taskbar);
  284. this.iconNode = new Element("div", {
  285. "styles": this.layout.css.taskItemIconNode
  286. }).inject(this.node);
  287. this.iconNode.setStyle("background-image", "url("+this.app.options.icon+")");
  288. this.closeNode = new Element("div", {
  289. "styles": this.layout.css.taskItemCloseNode
  290. }).inject(this.node);
  291. //this.closeNode.
  292. this.textNode = new Element("div", {
  293. "styles": this.layout.css.taskItemTextNode
  294. }).inject(this.node);
  295. this.textNode.set("text", this.app.options.title);
  296. this.setTaskitemSize();
  297. this.setEvent();
  298. },
  299. setTaskitemSize: function(){
  300. var x1 = 10;
  301. var x2 = 5;
  302. var size = this.layout.top.taskbar.getSize();
  303. var taskItems = this.layout.top.taskbar.getChildren();
  304. var allWidth = 0;
  305. if (taskItems.length){
  306. var w = taskItems[0].getStyles("border-left-width", "border-right-width", "margin-left", "margin-right", "padding-left", "padding-right");
  307. for (var i=0; i<taskItems.length; i++){
  308. taskItems[i].setStyle("width", "auto");
  309. allWidth += taskItems[i].getSize().x+w["border-left-width"].toInt()+w["border-right-width"].toInt()+w["margin-left"].toInt()+w["margin-right"].toInt()+w["padding-left"].toInt()+w["padding-right"].toInt();
  310. }
  311. if (allWidth>(size.x-x1)){
  312. var x = (size.x-x1)/taskItems.length;
  313. var width = x-w["border-left-width"].toInt()-w["border-right-width"].toInt()-w["margin-left"].toInt()-w["margin-right"].toInt()-w["padding-left"].toInt()-w["padding-right"].toInt();
  314. taskItems.each(function(item){
  315. item.setStyle("width", ""+width+"px");
  316. });
  317. }else{
  318. taskItems.each(function(item){
  319. item.setStyle("width", "auto");
  320. });
  321. }
  322. }
  323. // var x = (size.x-x1)/taskItems.length;
  324. // if (x<165){
  325. // var width = x-x2;
  326. // taskItems.each(function(item){
  327. // item.setStyle("width", ""+width+"px");
  328. // });
  329. // }else{
  330. // taskItems.each(function(item){
  331. // item.setStyle("width", "auto");
  332. // });
  333. // //this.node.setStyle("width", "160px");
  334. // }
  335. },
  336. setText: function(str){
  337. this.textNode.set("text", str || this.app.options.title);
  338. },
  339. setEvent: function(){
  340. this.textNode.addEvents({
  341. "mouseover": function(){
  342. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  343. }.bind(this),
  344. "mouseout": function(){
  345. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  346. }.bind(this),
  347. "mousedown": function(){
  348. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_down);
  349. }.bind(this),
  350. "mouseup": function(){
  351. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  352. }.bind(this),
  353. "click": function(){
  354. if (this.layout.currentApp==this.app){
  355. this.app.minSize();
  356. }else{
  357. this.app.setCurrent();
  358. }
  359. }.bind(this)
  360. });
  361. this.iconNode.addEvents({
  362. "mouseover": function(){
  363. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  364. }.bind(this),
  365. "mouseout": function(){
  366. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  367. }.bind(this),
  368. "mousedown": function(){
  369. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_down);
  370. }.bind(this),
  371. "mouseup": function(){
  372. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  373. }.bind(this),
  374. "click": function(){
  375. if (this.layout.currentApp==this.app){
  376. this.app.minSize();
  377. }else{
  378. this.app.setCurrent();
  379. }
  380. }.bind(this)
  381. });
  382. this.node.addEvents({
  383. "mouseover": function(){
  384. //if (this.layout.currentApp!==this.app)
  385. this.closeNode.fade("in");
  386. }.bind(this),
  387. "mouseout": function(){
  388. //if (this.layout.currentApp!==this.app)
  389. this.closeNode.fade("out");
  390. }.bind(this)
  391. });
  392. this.closeNode.addEvent("click", function(){
  393. this.app.close();
  394. }.bind(this));
  395. },
  396. selected: function(){
  397. this.node.setStyles(this.layout.css.taskItemNode_current);
  398. //this.closeNode.setStyles(this.layout.css.taskItemCloseNode_current);
  399. },
  400. unSelected: function(){
  401. this.node.setStyles(this.layout.css.taskItemNode);
  402. //this.closeNode.setStyles(this.layout.css.taskItemCloseNode);
  403. },
  404. changStyle: function(){
  405. if (this.node){
  406. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this){
  407. this.node.setStyles(this.layout.css.taskItemNode);
  408. }else{
  409. this.node.setStyles(this.layout.css.taskItemNode);
  410. this.node.setStyles(this.layout.css.taskItemNode_current);
  411. }
  412. }
  413. if (this.iconNode) this.iconNode.setStyles(this.layout.css.taskItemIconNode);
  414. if (this.textNode) this.textNode.setStyles(this.layout.css.taskItemTextNode);
  415. },
  416. destroy: function(){
  417. this.node.destroy();
  418. //this.layout.setTaskitemSize();
  419. }
  420. });
  421. MWF.xApplication.Setting.preview.Layout.Top = new Class({
  422. initialize: function(node, layout){
  423. this.layout = layout;
  424. this.node = $(node);
  425. this.userApplicationsLog = [];
  426. this.sysApplicationsLog = [];
  427. },
  428. load: function(){
  429. this.loadMenuAction();
  430. this.loadSeparate();
  431. this.loadShowDesktop();
  432. this.loadClock();
  433. this.loadSeparate("right");
  434. this.loadUserMenu();
  435. this.loadStyleAction();
  436. this.loadUserChat();
  437. this.loadMessageAction();
  438. this.loadSeparate("right");
  439. this.loadTaskbar();
  440. },
  441. loadMenuAction: function(){
  442. this.loadMenuAction = new Element("div", {
  443. "styles": this.layout.css.loadMenuAction,
  444. "title": MWF.LP.desktop.menuAction
  445. }).inject(this.node);
  446. },
  447. loadShowDesktop: function(){
  448. this.showDesktopAction = new Element("div", {
  449. "styles": this.layout.css.showDesktopAction
  450. }).inject(this.node);
  451. },
  452. loadSeparate : function(cssfloat){
  453. var separateNode = new Element("div.separateNode", {
  454. "styles": this.layout.css.separateNode
  455. }).inject(this.node);
  456. if (cssfloat) separateNode.setStyle("float",cssfloat);
  457. },
  458. loadTaskbar: function(){
  459. this.taskbar = new Element("div", {
  460. "styles": this.layout.css.taskbar
  461. }).inject(this.node);
  462. },
  463. loadUserChat: function(){
  464. this.userChatNode = new Element("div", {
  465. "styles": this.layout.css.userChatNode,
  466. "title": MWF.LP.desktop.userChat
  467. }).inject(this.node);
  468. },
  469. loadStyleAction: function(){
  470. this.styleActionNode = new Element("div", {
  471. "styles": this.layout.css.styleActionNode,
  472. "title": MWF.LP.desktop.styleAction
  473. }).inject(this.node);
  474. },
  475. loadMessageAction: function(){
  476. this.messageActionNode = new Element("div", {
  477. "styles": this.layout.css.messageActionNode,
  478. "title": MWF.LP.desktop.showMessage
  479. }).inject(this.node);
  480. },
  481. loadUserMenu: function(){
  482. this.userMenuNode = new Element("div", {
  483. "styles": this.layout.css.userMenuNode,
  484. "title": MWF.LP.desktop.userMenu
  485. }).inject(this.node);
  486. },
  487. loadClock: function(){
  488. this.clockNode = new Element("div", {
  489. "styles": this.layout.css.clockNode
  490. }).inject(this.node);
  491. this.setTime();
  492. },
  493. setTime: function(){
  494. var now = new Date();
  495. var ms = 1000-now.getMilliseconds();
  496. var ss = 60-now.getSeconds();
  497. var d = now.format("%Y/%m/%d#%H:%M");
  498. dl = d.split("#");
  499. this.clockNode.set("html", dl[1]+"<br/>"+dl[0]);
  500. window.setTimeout(this.setTime.bind(this), ss*1000+ms);
  501. }
  502. });