Layout.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. debugger;
  105. this.window.css = this.windowCss;
  106. this.content = this.window.content;
  107. //if (animation===false){
  108. this.window.reStyle();
  109. this.window.showNoAnimation(false, false);
  110. //}else{
  111. // this.window.show();
  112. //}
  113. },
  114. maxOrRestoreSize: function(){},
  115. loadDesktop: function(){
  116. this.setHeight();
  117. var size = this.desktopNode.getSize();
  118. this.size = {
  119. "x" : size.x,
  120. "y": size.y
  121. };
  122. this.loadTop();
  123. this.loadLnkArea();
  124. },
  125. loadLnkAreaContainer: function(){
  126. this.lnkAreaContainer = new Element("div", {
  127. "styles": {
  128. "height": "100%",
  129. "overflow": "hidden"
  130. }
  131. }).inject(this.contentNode);
  132. },
  133. loadLnkArea: function(){
  134. if (!this.lnkAreaContainer) this.loadLnkAreaContainer();
  135. var lnkArea = new Element("div", {
  136. "styles": this.css.dsektopLnkArea
  137. }).inject(this.lnkAreaContainer);
  138. this.lnkAreas.push(lnkArea);
  139. var width = (lnkArea.getSize().x)*(this.lnkAreas.length);
  140. var contentSize = this.contentNode.getSize();
  141. this.lnkAreaContainer.setStyle("width", ""+Math.max(width, contentSize.x)+"px");
  142. this.setCurrentLnkArea();
  143. },
  144. setCurrentLnkArea: function(){
  145. if (this.lnkAreas.length>1){
  146. var lnkSize = this.lnkAreas[0].getSize().x;
  147. var width = (lnkSize)*(this.lnkAreas.length);
  148. var contentSize = this.contentNode.getSize();
  149. var currentArea = this.lnkAreas[this.lnkAreas.length-1];
  150. if (width<contentSize.x){
  151. width = width-lnkSize;
  152. currentArea.setStyles({
  153. "width": "auto",
  154. "margin-left": ""+width+"px",
  155. "float": "none"
  156. });
  157. }else{
  158. currentArea.setStyles(this.css.dsektopLnkArea);
  159. }
  160. }else{
  161. if (this.lnkAreas.length){
  162. this.lnkAreas[0].setStyles({
  163. "width": "auto",
  164. "margin-left": "0px",
  165. "float": "none"
  166. });
  167. }
  168. }
  169. },
  170. addLnkArea: function(){
  171. if (this.lnkAreas.length){
  172. this.lnkAreas[this.lnkAreas.length-1].setStyles(this.css.dsektopLnkArea);
  173. }
  174. this.loadLnkArea();
  175. },
  176. addLnk: function(json){
  177. var lnk = new MWF.xDesktop.Lnk(json.icon, json.title, json.par);
  178. if (!this.lnkAreas.length) this.loadLnkArea();
  179. lnk.inject(this.lnkAreas[this.lnkAreas.length-1]);
  180. this.lnks.push(lnk);
  181. },
  182. resizeLnk: function(){
  183. if (this.lnkAreaContainer){
  184. if (this.lnkAreas.length>1){
  185. var width = (this.lnkAreas[0].getSize().x)*(this.lnkAreas.length);
  186. var contentSize = this.contentNode.getSize();
  187. this.lnkAreaContainer.setStyle("width", ""+Math.max(width, contentSize.x)+"px");
  188. }else{
  189. this.lnkAreaContainer.setStyle("width", ""+this.contentNode.getSize().x+"px");
  190. }
  191. }
  192. var n=0;
  193. var count = 0;
  194. this.lnks.each(function(lnk, idx){
  195. while(!this.lnkAreas[n]) this.addLnkArea();
  196. var linkArea = this.lnkAreas[n];
  197. lnk.inject(linkArea);
  198. count++;
  199. //var y = lnk.node.getSize().y+lnk.node.getStyle("margin-top").toFloat()+lnk.node.getStyle("margin-bottom").toFloat();
  200. var y = lnk.node.getSize().y+lnk.node.getStyle("margin-top").toFloat();
  201. if (y*(count+1)>linkArea.getSize().y){
  202. if (idx<this.lnks.length-1) n++;
  203. count = 0;
  204. }
  205. }.bind(this));
  206. if (this.lnkAreas.length) while (this.lnkAreas.length>n+1 ) this.lnkAreas.pop().destroy();
  207. this.setCurrentLnkArea();
  208. },
  209. setHeight: function(){
  210. this.resizeHeight();
  211. $(window).addEvent("resize", function(){
  212. this.resizeHeight();
  213. }.bind(this));
  214. },
  215. resizeHeight: function(){
  216. var yTop = this.topNode.getSize().y;
  217. var yBody = this.node.getSize().y;
  218. var y = yBody - yTop;
  219. this.desktopNode.setStyle("height", ""+y+"px");
  220. this.desktopHeight = y;
  221. var yNavi = this.naviNode.getSize().y;
  222. y = y - yNavi;
  223. this.contentNode.setStyle("height", ""+y+"px");
  224. this.resizeLnk();
  225. this.resizeMessage();
  226. this.setTaskitemSize();
  227. if (this.top) if (this.top.userPanel) this.top.userPanel.setPosition();
  228. this.fireEvent("resize");
  229. },
  230. setTaskitemSize: function(){
  231. if (this.top){
  232. var x1 = 10;
  233. var x2 = 5;
  234. var size = this.top.taskbar.getSize();
  235. var taskItems = this.top.taskbar.getChildren();
  236. var allWidth = 0;
  237. if (taskItems.length){
  238. var w = taskItems[0].getStyles("border-left-width", "border-right-width", "margin-left", "margin-right", "padding-left", "padding-right");
  239. for (var i=0; i<taskItems.length; i++){
  240. taskItems[i].setStyle("width", "auto");
  241. 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();
  242. }
  243. if (allWidth>(size.x-x1)){
  244. var x = (size.x-x1)/taskItems.length;
  245. 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();
  246. taskItems.each(function(item){
  247. item.setStyle("width", ""+width+"px");
  248. });
  249. }else{
  250. taskItems.each(function(item){
  251. item.setStyle("width", "auto");
  252. });
  253. }
  254. }
  255. }
  256. },
  257. resizeMessage: function(){
  258. if (this.message) this.message.resize();
  259. },
  260. loadTop: function(){
  261. if (!this.top){
  262. this.top = new MWF.xApplication.Setting.preview.Layout.Top(this.topNode, this);
  263. this.top.load();
  264. }
  265. },
  266. getNodeBackground: function(){
  267. MWF.UD.getDataJson("layoutDesktop", function(json){
  268. var dskImg = MWF.defaultPath+"/xDesktop/$Layout/"+this.options.style+"/desktop.jpg";
  269. if (json){
  270. currentSrc = json.src;
  271. dskImg = MWF.defaultPath+"/xDesktop/$Layout/"+currentSrc+"/desktop.jpg";
  272. }
  273. this.node.setStyle("background-image", "url("+dskImg+")");
  274. }.bind(this), false);
  275. }
  276. });
  277. MWF.xApplication.Setting.preview.Layout.Taskitem = new Class({
  278. initialize: function(app, layout){
  279. this.layout = layout;
  280. this.app = app;
  281. this.node = new Element("div", {
  282. "styles": this.layout.css.taskItemNode,
  283. "title": this.app.options.title+((this.app.appId) ? "-"+this.app.appId : "")
  284. }).inject(this.layout.top.taskbar);
  285. this.iconNode = new Element("div", {
  286. "styles": this.layout.css.taskItemIconNode
  287. }).inject(this.node);
  288. this.iconNode.setStyle("background-image", "url("+this.app.options.icon+")");
  289. this.closeNode = new Element("div", {
  290. "styles": this.layout.css.taskItemCloseNode
  291. }).inject(this.node);
  292. //this.closeNode.
  293. this.textNode = new Element("div", {
  294. "styles": this.layout.css.taskItemTextNode
  295. }).inject(this.node);
  296. this.textNode.set("text", this.app.options.title);
  297. this.setTaskitemSize();
  298. this.setEvent();
  299. },
  300. setTaskitemSize: function(){
  301. var x1 = 10;
  302. var x2 = 5;
  303. var size = this.layout.top.taskbar.getSize();
  304. var taskItems = this.layout.top.taskbar.getChildren();
  305. var allWidth = 0;
  306. if (taskItems.length){
  307. var w = taskItems[0].getStyles("border-left-width", "border-right-width", "margin-left", "margin-right", "padding-left", "padding-right");
  308. for (var i=0; i<taskItems.length; i++){
  309. taskItems[i].setStyle("width", "auto");
  310. 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();
  311. }
  312. if (allWidth>(size.x-x1)){
  313. var x = (size.x-x1)/taskItems.length;
  314. 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();
  315. taskItems.each(function(item){
  316. item.setStyle("width", ""+width+"px");
  317. });
  318. }else{
  319. taskItems.each(function(item){
  320. item.setStyle("width", "auto");
  321. });
  322. }
  323. }
  324. // var x = (size.x-x1)/taskItems.length;
  325. // if (x<165){
  326. // var width = x-x2;
  327. // taskItems.each(function(item){
  328. // item.setStyle("width", ""+width+"px");
  329. // });
  330. // }else{
  331. // taskItems.each(function(item){
  332. // item.setStyle("width", "auto");
  333. // });
  334. // //this.node.setStyle("width", "160px");
  335. // }
  336. },
  337. setText: function(str){
  338. this.textNode.set("text", str || this.app.options.title);
  339. },
  340. setEvent: function(){
  341. this.textNode.addEvents({
  342. "mouseover": function(){
  343. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  344. }.bind(this),
  345. "mouseout": function(){
  346. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  347. }.bind(this),
  348. "mousedown": function(){
  349. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_down);
  350. }.bind(this),
  351. "mouseup": function(){
  352. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  353. }.bind(this),
  354. "click": function(){
  355. if (this.layout.currentApp==this.app){
  356. this.app.minSize();
  357. }else{
  358. this.app.setCurrent();
  359. }
  360. }.bind(this)
  361. });
  362. this.iconNode.addEvents({
  363. "mouseover": function(){
  364. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  365. }.bind(this),
  366. "mouseout": function(){
  367. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  368. }.bind(this),
  369. "mousedown": function(){
  370. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_down);
  371. }.bind(this),
  372. "mouseup": function(){
  373. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  374. }.bind(this),
  375. "click": function(){
  376. if (this.layout.currentApp==this.app){
  377. this.app.minSize();
  378. }else{
  379. this.app.setCurrent();
  380. }
  381. }.bind(this)
  382. });
  383. this.node.addEvents({
  384. "mouseover": function(){
  385. //if (this.layout.currentApp!==this.app)
  386. this.closeNode.fade("in");
  387. }.bind(this),
  388. "mouseout": function(){
  389. //if (this.layout.currentApp!==this.app)
  390. this.closeNode.fade("out");
  391. }.bind(this)
  392. });
  393. this.closeNode.addEvent("click", function(){
  394. this.app.close();
  395. }.bind(this));
  396. },
  397. selected: function(){
  398. this.node.setStyles(this.layout.css.taskItemNode_current);
  399. //this.closeNode.setStyles(this.layout.css.taskItemCloseNode_current);
  400. },
  401. unSelected: function(){
  402. this.node.setStyles(this.layout.css.taskItemNode);
  403. //this.closeNode.setStyles(this.layout.css.taskItemCloseNode);
  404. },
  405. changStyle: function(){
  406. if (this.node){
  407. if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this){
  408. this.node.setStyles(this.layout.css.taskItemNode);
  409. }else{
  410. this.node.setStyles(this.layout.css.taskItemNode);
  411. this.node.setStyles(this.layout.css.taskItemNode_current);
  412. }
  413. }
  414. if (this.iconNode) this.iconNode.setStyles(this.layout.css.taskItemIconNode);
  415. if (this.textNode) this.textNode.setStyles(this.layout.css.taskItemTextNode);
  416. },
  417. destroy: function(){
  418. this.node.destroy();
  419. //this.layout.setTaskitemSize();
  420. }
  421. });
  422. MWF.xApplication.Setting.preview.Layout.Top = new Class({
  423. initialize: function(node, layout){
  424. this.layout = layout;
  425. this.node = $(node);
  426. this.userApplicationsLog = [];
  427. this.sysApplicationsLog = [];
  428. },
  429. load: function(){
  430. this.loadMenuAction();
  431. this.loadSeparate();
  432. this.loadShowDesktop();
  433. this.loadClock();
  434. this.loadSeparate("right");
  435. this.loadUserMenu();
  436. this.loadStyleAction();
  437. this.loadUserChat();
  438. this.loadMessageAction();
  439. this.loadSeparate("right");
  440. this.loadTaskbar();
  441. },
  442. loadMenuAction: function(){
  443. this.loadMenuAction = new Element("div", {
  444. "styles": this.layout.css.loadMenuAction,
  445. "title": MWF.LP.desktop.menuAction
  446. }).inject(this.node);
  447. },
  448. loadShowDesktop: function(){
  449. this.showDesktopAction = new Element("div", {
  450. "styles": this.layout.css.showDesktopAction
  451. }).inject(this.node);
  452. },
  453. loadSeparate : function(cssfloat){
  454. var separateNode = new Element("div.separateNode", {
  455. "styles": this.layout.css.separateNode
  456. }).inject(this.node);
  457. if (cssfloat) separateNode.setStyle("float",cssfloat);
  458. },
  459. loadTaskbar: function(){
  460. this.taskbar = new Element("div", {
  461. "styles": this.layout.css.taskbar
  462. }).inject(this.node);
  463. },
  464. loadUserChat: function(){
  465. this.userChatNode = new Element("div", {
  466. "styles": this.layout.css.userChatNode,
  467. "title": MWF.LP.desktop.userChat
  468. }).inject(this.node);
  469. },
  470. loadStyleAction: function(){
  471. this.styleActionNode = new Element("div", {
  472. "styles": this.layout.css.styleActionNode,
  473. "title": MWF.LP.desktop.styleAction
  474. }).inject(this.node);
  475. },
  476. loadMessageAction: function(){
  477. this.messageActionNode = new Element("div", {
  478. "styles": this.layout.css.messageActionNode,
  479. "title": MWF.LP.desktop.showMessage
  480. }).inject(this.node);
  481. },
  482. loadUserMenu: function(){
  483. this.userMenuNode = new Element("div", {
  484. "styles": this.layout.css.userMenuNode,
  485. "title": MWF.LP.desktop.userMenu
  486. }).inject(this.node);
  487. },
  488. loadClock: function(){
  489. this.clockNode = new Element("div", {
  490. "styles": this.layout.css.clockNode
  491. }).inject(this.node);
  492. this.setTime();
  493. },
  494. setTime: function(){
  495. var now = new Date();
  496. var ms = 1000-now.getMilliseconds();
  497. var ss = 60-now.getSeconds();
  498. var d = now.format("%Y/%m/%d#%H:%M");
  499. dl = d.split("#");
  500. this.clockNode.set("html", dl[1]+"<br/>"+dl[0]);
  501. window.setTimeout(this.setTime.bind(this), ss*1000+ms);
  502. }
  503. });