Default.js 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  1. // o2.require("o2.widget.Common", null, false);
  2. // o2.require("o2.xDesktop.Common", null, false);
  3. // o2.require("o2.xDesktop.Actions.RestActions", null, false);
  4. // o2.require("o2.xDesktop.Authentication", null, false);
  5. o2.require("o2.widget.PinYin", null, false);
  6. o2.xDesktop.Default = new Class({
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "blue",
  10. "index": "Homepage"
  11. },
  12. initialize: function(node, options){
  13. this.setOptions(options);
  14. this.type = "layout";
  15. this.path = o2.session.path+"/xDesktop/$Default/";
  16. this.node = $(node);
  17. this.node.empty();
  18. this.initData();
  19. //this.load();
  20. },
  21. initData: function(){
  22. this.apps = {};
  23. this.appArr = [];
  24. this.appCurrentList = [];
  25. this.lnks = [];
  26. this.currentApp = null;
  27. this.session = {};
  28. this.serviceAddressList = layout.serviceAddressList;
  29. this.centerServer = layout.centerServer;
  30. this.session.user = layout.session.user;
  31. var uri = new URI(window.location.href);
  32. var df = uri.getData("default") || "";
  33. this.noDefault = df.toString().toLowerCase()==="false";
  34. var appNames = uri.getData("app");
  35. var optionsStr = uri.getData("option");
  36. var options = (optionsStr) ? JSON.decode(optionsStr) : null;
  37. if (appNames){
  38. this.status = layout.userLayout;
  39. this.status.apps = {};
  40. this.status.apps[appNames] = options || {};
  41. this.status.apps[appNames].name = appNames;
  42. this.status.apps[appNames].appId = appNames;
  43. this.status.apps[appNames].isIndex = true;
  44. this.status.currentApp = appNames;
  45. }else{
  46. this.status = layout.userLayout;
  47. }
  48. if (this.status && this.status.flatStyle) this.options.style = this.status.flatStyle;
  49. },
  50. load: function(cb){
  51. this.loadLayout(function(){
  52. this.setEvent();
  53. if (!this.noDefault) this.loadDefaultPage();
  54. window.setTimeout(function(){
  55. var iconsPath = this.path+"icons.json";
  56. o2.JSON.get(iconsPath, function(json) {
  57. this.iconsJson = json;
  58. this.loadDefaultLnk();
  59. this.loadStatus();
  60. if (cb) cb();
  61. }.bind(this));
  62. this.openWebSocket();
  63. this.checkTaskBarSize();
  64. this.addEvent("resize", this.checkTaskBarSize.bind(this));
  65. }.bind(this), 0);
  66. this.loadMessageMenu();
  67. this.fireEvent("load");
  68. MWF.require("MWF.xDesktop.shortcut");
  69. }.bind(this));
  70. },
  71. resizeHeight: function(){
  72. var y = this.menuNode.getSize().y;
  73. var y1 = this.startMenuNode.getParent().getSize().y;
  74. var o1 = this.startMenuNode.getParent().getStyles("border-top-width", "margin-top", "padding-top", "border-bottom-width", "margin-bottom", "padding-bottom");
  75. var y2 = this.settingNode.getParent().getSize().y;
  76. var o2 = this.settingNode.getParent().getStyles("border-top-width", "margin-top", "padding-top", "border-bottom-width", "margin-bottom", "padding-bottom");
  77. oy1 = o1["border-top-width"].toInt()+o1["margin-top"].toInt()+o1["padding-top"].toInt()+o1["border-bottom-width"].toInt()+o1["margin-bottom"].toInt()+o1["padding-bottom"].toInt();
  78. oy2 = o2["border-top-width"].toInt()+o2["margin-top"].toInt()+o2["padding-top"].toInt()+o2["border-bottom-width"].toInt()+o2["margin-bottom"].toInt()+o2["padding-bottom"].toInt();
  79. var height = y-y1-y2-oy1-oy2;
  80. this.lnkContentNode.setStyle("height", ""+height+"px");
  81. },
  82. checkTaskBarSize: function(){
  83. window.setTimeout(function(){
  84. var size = this.taskContentAreaNode.getSize();
  85. var contentSize = this.taskContentNode.getSize();
  86. if (size.y<contentSize.y){
  87. this.taskActionUp.show();
  88. this.taskActionDown.show();
  89. }else{
  90. this.taskActionUp.hide();
  91. this.taskActionDown.hide();
  92. }
  93. }.bind(this), 50);
  94. },
  95. checkTaskBarScrollTo: function(app){
  96. var currentApp = app || this.currentApp;
  97. if (currentApp && currentApp.taskitem){
  98. var size = this.taskContentAreaNode.getSize();
  99. var scroll = this.taskContentAreaNode.getScroll();
  100. var scrollSize = this.taskContentAreaNode.getScrollSize();
  101. var p = currentApp.taskitem.node.getPosition(this.taskContentNode);
  102. if (p.y!=scroll.y){
  103. var scrollTo = p.y;
  104. if (scrollTo<scrollSize.y-size.y){
  105. this.taskActionDown.addClass("icon_down");
  106. this.taskActionDown.removeClass("icon_down_gray");
  107. }else{
  108. this.taskActionDown.removeClass("icon_down");
  109. this.taskActionDown.addClass("icon_down_gray");
  110. }
  111. if (scrollTo<=0){
  112. scrollTo = 0;
  113. this.taskActionUp.removeClass("icon_up");
  114. this.taskActionUp.addClass("icon_up_gray");
  115. }else{
  116. this.taskActionUp.addClass("icon_up");
  117. this.taskActionUp.removeClass("icon_up_gray");
  118. }
  119. this.taskContentAreaNode.scrollTo(0, p.y);
  120. }
  121. }
  122. },
  123. toolbarUp: function(){
  124. var size = this.taskContentAreaNode.getSize();
  125. var scroll = this.taskContentAreaNode.getScroll();
  126. var scrollSize = this.taskContentAreaNode.getScrollSize();
  127. var scrollTo = scroll.y-size.y;
  128. if (scrollTo<scrollSize.y-size.y){
  129. this.taskActionDown.addClass("icon_down");
  130. this.taskActionDown.removeClass("icon_down_gray");
  131. }
  132. if (scrollTo<=0){
  133. scrollTo = 0;
  134. this.taskActionUp.removeClass("icon_up");
  135. this.taskActionUp.addClass("icon_up_gray");
  136. }
  137. this.taskContentAreaNode.scrollTo(0,scrollTo);
  138. },
  139. toolbarDown: function(){
  140. var size = this.taskContentAreaNode.getSize();
  141. var scroll = this.taskContentAreaNode.getScroll();
  142. var scrollSize = this.taskContentAreaNode.getScrollSize();
  143. var scrollTo = scroll.y+size.y;
  144. if (scrollTo+size.y>=scrollSize.y){
  145. scrollTo=scrollSize.y-size.y;
  146. this.taskActionDown.removeClass("icon_down");
  147. this.taskActionDown.addClass("icon_down_gray");
  148. }
  149. if (scrollTo>0){
  150. this.taskActionUp.addClass("icon_up");
  151. this.taskActionUp.removeClass("icon_up_gray");
  152. }
  153. this.taskContentAreaNode.scrollTo(0, scrollTo);
  154. },
  155. loadLayout: function(callback){
  156. this.session.user.iconUrl = o2.filterUrl(o2.Actions.get("x_organization_assemble_control").getPersonIcon(this.session.user.id));
  157. var css = this.path+this.options.style+ ((o2.session.isMobile || layout.mobile) ? "/style-pc.css" : "/style-pc.css");
  158. var skinCss = this.path+this.options.style+ "/style-skin.css";
  159. var html = this.path+this.options.style+((o2.session.isMobile || layout.mobile) ? "/layout-pc.html" : "/layout-pc.html");
  160. this.node.loadAll({ "css": [css], "html": [html]}, {"bind": {"user": this.session.user}, "module": this},function(){
  161. var oReq = new XMLHttpRequest();
  162. debugger;
  163. oReq.addEventListener("load", function(){
  164. var reader = new FileReader();
  165. reader.addEventListener("load", function () {
  166. this.userInforNode.getFirst().setStyle("background-image", "url("+reader.result+")");
  167. }.bind(this), false);
  168. reader.readAsDataURL(oReq.response);
  169. }.bind(this));
  170. oReq.open("GET", this.session.user.iconUrl);
  171. oReq.setRequestHeader("authorization", layout.session.user.token);
  172. oReq.responseType = "blob";
  173. oReq.withCredentials = true;
  174. oReq.send();
  175. // var res = new Request({
  176. // "url": this.session.user.iconUrl,
  177. // method: "get",
  178. // withCredentials: true,
  179. // onSuccess: function(response,a,s,d){
  180. //
  181. // }.bind(this)
  182. // });
  183. // res.setHeader("authorization", layout.session.user.token);
  184. // res.send();
  185. this.node.loadCss(skinCss);
  186. if (callback) callback();
  187. // this.node.load(html, {
  188. // "bind": {"user": this.session.user}
  189. // }, function(){});
  190. }.bind(this));
  191. },
  192. setEvent: function(){
  193. this.loadSkinMenu();
  194. this.loadUserMenu();
  195. window.onbeforeunload = function(e){
  196. if (!this.isLogout){
  197. if (!this.notRecordStatus) this.recordDesktopStatus();
  198. this.closeWebSocket();
  199. //if (this.socket && this.socket.webSocket) this.socket.close();
  200. this.fireEvent("unload");
  201. e = e || window.event;
  202. e.returnValue = o2.LP.desktop.notice.unload;
  203. return o2.LP.desktop.notice.unload;
  204. }
  205. }.bind(this);
  206. $(window).addEvent("resize", function(){
  207. this.fireEvent("resize");
  208. }.bind(this));
  209. this.resizeHeight();
  210. this.addEvent("resize", this.resizeHeight.bind(this));
  211. o2.require("o2.widget.ScrollBar", function(){
  212. this.appScrollBar = new o2.widget.ScrollBar(this.lnkContentNode, {
  213. "style":"hide", "where": "before", "indent": true, "distance": 100, "friction": 0, "axis": {"x": false, "y": true}
  214. });
  215. }.bind(this));
  216. },
  217. loadDefaultPage: function(){
  218. //默认载入首页
  219. var app;
  220. if (layout.config.indexPage && layout.config.indexPage.enable && layout.config.indexPage.portal){
  221. appId = "portal.Portal"+layout.config.indexPage.portal;
  222. this.options.index = appId;
  223. //var options = {"portalId": layout.config.indexPage.portal, "pageId": layout.config.indexPage.page, "appId": appId};
  224. app = {
  225. "options": {"name": "portal.Portal", "portalId": layout.config.indexPage.portal, "pageId": layout.config.indexPage.page, "appId": appId},
  226. "close": function(){
  227. this.taskitem.destroy();
  228. },
  229. "setCurrent": function(){
  230. if (this.taskitem.textNode) this.taskitem.textNode.click();
  231. }
  232. };
  233. //layout.openApplication(null, "portal.Portal", options);
  234. }else{
  235. app = {
  236. "options": {"name": "Homepage", "appId": "Homepage", "title": o2.LP.desktop.homepage},
  237. "close": function(){
  238. this.taskitem.destroy();
  239. },
  240. "setCurrent": function(){
  241. if (this.taskitem.textNode) this.taskitem.textNode.click();
  242. }
  243. };
  244. //layout.openApplication(null, "Homepage");
  245. }
  246. taskitem = layout.desktop.createTaskItem(app);
  247. app.taskitem = taskitem;
  248. app.options.isIndex = true;
  249. this.apps[app.options.appId] = app;
  250. taskitem.textNode.click();
  251. },
  252. loadDefaultLnk: function(){
  253. if (this.status && this.status.flatLnks && this.status.flatLnks.length){
  254. }else{
  255. o2.JSON.get(this.path+"defaultLnk.json", function(defaultLnk){
  256. defaultLnk.each(function(lnkJson){
  257. this.addLnk(lnkJson);
  258. }.bind(this));
  259. }.bind(this));
  260. }
  261. },
  262. loadStatus: function(){
  263. if (this.status){
  264. var keys = Object.keys(this.status.apps);
  265. if (this.status.apps && keys.length){
  266. if (this.status.currentApp == "Note"){
  267. var idx = keys.length-1;
  268. while (idx>-1 && keys[idx]=="Note") idx--;
  269. this.status.currentApp = (idx>-1) ? this.status.apps[keys[idx]].appId : "";
  270. }
  271. var currentTaskitem = null;
  272. Object.each(this.status.apps, function(appStatus, id){
  273. var app = {
  274. "options": appStatus,
  275. "close": function(){
  276. this.taskitem.destroy();
  277. },
  278. "setCurrent": function(){
  279. if (this.taskitem.textNode) this.taskitem.textNode.click();
  280. }
  281. };
  282. taskitem = layout.desktop.createTaskItem(app);
  283. app.taskitem = taskitem;
  284. this.apps[appStatus.appId] = app;
  285. if ((this.status.currentApp === appStatus.appId)) currentTaskitem=taskitem;
  286. }.bind(this));
  287. if (currentTaskitem) {
  288. currentTaskitem.textNode.click();
  289. }
  290. }
  291. if (this.status.widgets){/* nothing to do */}
  292. if (this.status.flatLnks && this.status.flatLnks.length){
  293. this.status.flatLnks.each(function(lnkJson){
  294. this.addLnk(lnkJson);
  295. }.bind(this));
  296. }
  297. }
  298. },
  299. addLnk: function(lnkData, targetLnk, position){
  300. var lnk = new o2.xDesktop.Default.Lnk(this, lnkData, targetLnk, position);
  301. if (targetLnk){
  302. var idx = this.lnks.indexOf(targetLnk);
  303. if (position=="before"){
  304. this.lnks.splice(idx, 0, lnk);
  305. }else{
  306. this.lnks.splice(idx+1, 0, lnk);
  307. }
  308. }else{
  309. this.lnks.push(lnk);
  310. }
  311. },
  312. openWebSocket: function(){
  313. MWF.require("MWF.xDesktop.WebSocket", function(){
  314. this.socket = new MWF.xDesktop.WebSocket();
  315. }.bind(this));
  316. },
  317. closeWebSocket: function(){
  318. if (this.socket) this.socket.close();
  319. },
  320. //******* begin page skin ****************************************************
  321. loadSkinMenu: function(){
  322. if (!this.styleMenu){
  323. this.styleMenu = new o2.xDesktop.Menu(this.skinActionNode, {
  324. "event": "click", "style": "flatStyle", "offsetX": -10, "offsetY": 26, "container": this.node,
  325. "onQueryShow": this.showSkinMenu.bind(this),
  326. "onQueryHide": function(){
  327. this.skinActionNode.removeClass("icon_skin_focus");
  328. this.skinActionNode.removeClass("mainColor_bg");
  329. }.bind(this)
  330. });
  331. this.styleMenu.load();
  332. this.loadSkinMenuItems();
  333. }
  334. },
  335. showSkinMenu: function(){
  336. this.styleMenu.items.each(function(item){
  337. if (this.options.style==item.styleName){
  338. item.setDisable(true);
  339. if (item.text) item.text.setStyles({ "background": "url("+this.path+this.options.style+"/icons/icon_gouxuan.png) right center no-repeat" });
  340. }else{
  341. item.setDisable(false);
  342. if (item.text) item.text.setStyles({ "background": "transparent" });
  343. }
  344. }.bind(this));
  345. this.skinActionNode.addClass("icon_skin_focus");
  346. this.skinActionNode.addClass("mainColor_bg");
  347. },
  348. loadSkinMenuItems: function(){
  349. o2.JSON.get(this.path+"styles.json", function(json){
  350. json.each(function(style){
  351. var color = style.color;
  352. var memuItem = this.styleMenu.addMenuItem(style.title, "click", function(){this.changeLayoutSkin(style.style);}.bind(this));
  353. memuItem.styleName = style.style;
  354. var imgDiv = memuItem.item.getFirst();
  355. var imgNode = new Element("div", {"styles": memuItem.menu.css.menuItemImg}).inject(imgDiv);
  356. imgNode.setStyle("background-color", color);
  357. }.bind(this));
  358. this.styleMenu.addMenuLine();
  359. var img = o2.defaultPath+"/xDesktop/$Layout/default/preview.jpg";
  360. var memuItem = this.styleMenu.addMenuItem(o2.LP.desktop_style, "click", function(e){this.changeToDesktopStyle(e);}.bind(this), img);
  361. memuItem.styleName = "desktop";
  362. }.bind(this));
  363. },
  364. changeLayoutSkin: function(style){
  365. var skinCss = this.path+this.options.style+ "/style-skin.css";
  366. o2.removeCss(skinCss);
  367. this.options.style = style;
  368. skinCss = this.path+this.options.style+"/style-skin.css";
  369. this.node.loadCss(skinCss);
  370. },
  371. changeToDesktopStyle: function(e){
  372. //MWF.xDesktop.confirm("infor", e, o2.LP.desktop.changeViewTitle, {"html": o2.LP.desktop.changeView}, 500, 100, function(){
  373. // this.close();
  374. var uri = new URI(window.location.href);
  375. uri.setData("view", "layout");
  376. uri.go();
  377. // }, function(){
  378. // this.close();
  379. // }, null, null, "o2"
  380. // );
  381. },
  382. //******* end page skin ****************************************************
  383. //******* begin user menu ****************************************************
  384. loadUserMenu: function(){
  385. if (!this.userMenu){
  386. this.userMenu = new o2.xDesktop.Menu(this.userInforNode, {
  387. "event": "click", "style": "flatUser", "offsetX": 30, "offsetY":6, "container": this.node
  388. // "onQueryShow": this.showSkinMenu.bind(this),
  389. // "onQueryHide": function(){
  390. // this.skinActionNode.removeClass("icon_skin_focus");
  391. // this.skinActionNode.removeClass("mainColor_bg");
  392. // }.bind(this),
  393. });
  394. this.userMenu.load();
  395. this.loadUserMenuItems();
  396. }
  397. },
  398. loadUserMenuItems: function(){
  399. var img = this.path+this.options.style+"/icons/config.png";
  400. this.userMenu.addMenuItem(o2.LP.desktop.userConfig, "click", function(e){this.userConfig(e);}.bind(this), img);
  401. this.userMenu.addMenuLine();
  402. img = this.path+this.options.style+"/icons/logout.png";
  403. this.userMenu.addMenuItem(o2.LP.desktop.logout, "click", function(){this.logout();}.bind(this), img);
  404. },
  405. userConfig: function(e){
  406. layout.openApplication(e, "Profile");
  407. },
  408. logout: function(){
  409. this.isLogout = true;
  410. if (!this.notRecordStatus){
  411. this.recordDesktopStatus(function(){
  412. (layout.authentication || new o2.xDesktop.Authentication()).logout();
  413. }.bind(this.layout));
  414. }else{
  415. (layout.authentication || new o2.xDesktop.Authentication()).logout();
  416. }
  417. },
  418. //******* end user menu ****************************************************
  419. //******* begin search *****************************************************
  420. focusSearch: function(){
  421. this.searchBoxNode.addClass("layout_content_taskbar_area_search_box_focus");
  422. this.searchBoxNode.addClass("mainColor_border");
  423. this.searchIconNode.addClass("icon_search_focus");
  424. },
  425. blurSearch: function(){
  426. this.searchBoxNode.removeClass("layout_content_taskbar_area_search_box_focus");
  427. this.searchBoxNode.removeClass("mainColor_border");
  428. this.searchIconNode.removeClass("icon_search_focus");
  429. },
  430. searchInputKeyDown: function(e){
  431. if (this.searchInputNode.get("value")){
  432. this.searchClearNode.addClass("icon_clear");
  433. }else{
  434. this.searchClearNode.removeClass("icon_clear");
  435. }
  436. if (e.keyCode===13) this.doSearch();
  437. },
  438. clearSearch: function(){
  439. this.searchInputNode.set("value", "");
  440. this.searchClearNode.removeClass("icon_clear");
  441. this.clearSearchResult();
  442. },
  443. doSearch: function(){
  444. var key = this.searchInputNode.get("value");
  445. if (key){
  446. if (this.apps["Search"]){
  447. this.apps["Search"].input.setValue(key);
  448. this.apps["Search"].input.doSearch();
  449. }
  450. layout.openApplication(null,"Search", {"key": key});
  451. }
  452. },
  453. clearSearchResult: function(){
  454. //alert("clear search result");
  455. // @todo
  456. },
  457. //******* end search*******************************************************
  458. //******* begin record status *********************************************
  459. recordDesktopStatus: function(callback){
  460. Object.each(this.apps, function(app, id){
  461. if (!app.options.desktopReload){
  462. this.closeApp(app);
  463. }
  464. }.bind(this));
  465. var status = this.getLayoutStatusData();
  466. // if (navigator.sendBeacon) {
  467. // var obj = this.personalAction.action.actions["putUserData"];
  468. // var url = this.personalAction.action.address + obj.uri;
  469. // url = url.replace("{name}", "layout");
  470. // navigator.sendBeacon(url, status);
  471. // } else {
  472. try{
  473. o2.UD.putData("layout", status, function(){
  474. if (callback) callback();
  475. });
  476. }catch(e){};
  477. // }
  478. },
  479. getLayoutStatusData: function(){
  480. var status = {
  481. "viewMode": "Default",
  482. "style": this.status.style,
  483. "flatStyle": this.options.style,
  484. "styleType": this.status.styleType || "",
  485. "currentApp": (this.currentApp) ? this.currentApp.appId : "Homepage",
  486. "apps": {},
  487. "lnks": (this.status.lnks && o2.typeOf(this.status.lnks)==="array") ? this.status.lnks : [],
  488. //"lnks": [],
  489. "flatLnks": [],
  490. "widgets": {}
  491. };
  492. // this.appArr.each(function(app){
  493. // if (app.options.appId!==this.options.index){
  494. // var appStatus = this.getAppStatusData(app, app.appId);
  495. // if (appStatus) status.apps[id] = appStatus;
  496. // }
  497. // }.bind(this));
  498. Object.each(this.apps, function(app, id){
  499. if (app.options.appId!==this.options.index){
  500. var appStatus = this.getAppStatusData(app, id);
  501. if (appStatus) status.apps[id] = appStatus;
  502. }
  503. if (app.isIndex){
  504. if (!status.apps[id]) status.apps[id] = {};
  505. status.apps[id].isIndex = true;
  506. }
  507. }.bind(this));
  508. this.lnks.each(function(lnk){
  509. status.flatLnks.push(lnk.data);
  510. //status.flatLnks.push({"icon": lnk.icon, "color": lnk.color, "title": lnk.title,"par": lnk.par});
  511. });
  512. Object.each(this.widgets, function(widget, id){
  513. var widgetStatus = this.getWidgetStatusData(widget, id);
  514. if (widgetStatus) status.widgets[id] = widgetStatus;
  515. }.bind(this));
  516. return status;
  517. },
  518. getAppStatusData: function(app, id){
  519. var appStatus = null;
  520. if (app.window){
  521. if (app.options.desktopReload){
  522. appStatus ={
  523. "appId": app.appId,
  524. "name": app.options.name,
  525. "style": app.options.style,
  526. "title": app.options.title,
  527. "window": {
  528. // //"size": app.window.node.getSize(),
  529. // "size": {"x": app.window.css.to.width.toFloat(), "y": app.window.css.to.height.toFloat()},
  530. // "position": {"x": app.window.css.to.left.toFloat(), "y": app.window.css.to.top.toFloat()},
  531. // "isMax": app.window.isMax,
  532. // "isHide": app.window.isHide,
  533. // "style": app.window.options.style
  534. },
  535. "app": null
  536. };
  537. if (app.recordStatus) appStatus.app = app.recordStatus();
  538. }
  539. }else{
  540. if (app.options){
  541. appStatus = app.options;
  542. }
  543. }
  544. return appStatus;
  545. },
  546. getWidgetStatusData: function(widget, id){
  547. var widgetStatus ={
  548. "name": widget.options.name,
  549. "appName": widget.options.appName,
  550. "position": widget.options.position,
  551. "widget": null
  552. };
  553. if (widget.recordStatus) widgetStatus.widget = widget.recordStatus();
  554. return widgetStatus;
  555. },
  556. //******* end record status ***********************************************
  557. //******* begin start menu ************************************************
  558. showStartMenu: function(){
  559. this.loadStartMenu(function(){
  560. if (!this.startMenu.isShow){
  561. this.startMenuNode.addClass("overColor_bg");
  562. this.startMenu.show();
  563. }
  564. }.bind(this));
  565. },
  566. loadStartMenu: function(callback){
  567. if (!this.startMenu){
  568. this.startMenu = new o2.xDesktop.Default.StartMenu(this);
  569. this.startMenu.addEvents({
  570. "onHide": function(){
  571. this.startMenuNode.removeClass("overColor_bg");
  572. }.bind(this),
  573. "onLoad": function(){
  574. if (callback) callback();
  575. }
  576. });
  577. this.startMenu.load();
  578. }else{
  579. if (this.startMenu.isLoaded) if (callback) callback();
  580. }
  581. },
  582. //******* end start menu **************************************************
  583. //******* begin message menu **********************************************
  584. showDesktopMessage: function(){
  585. if (!this.message){
  586. this.loadMessageMenu(function(){
  587. this.showMessage();
  588. }.bind(this));
  589. }else{
  590. this.showMessage();
  591. }
  592. },
  593. loadMessageMenu: function(callback){
  594. o2.require("o2.xDesktop.MessageV2", function(){
  595. this.message = new o2.xDesktop.MessageV2(this);
  596. this.message.addEvents({
  597. "onLoad": function(){ if (callback) callback(); }.bind(this),
  598. "onHide": function(){
  599. this.msgActionNode.removeClass("icon_msg_focus");
  600. this.msgActionNode.removeClass("mainColor_bg");
  601. }.bind(this),
  602. });
  603. this.message.load();
  604. }.bind(this));
  605. },
  606. showMessage: function(){
  607. if (!this.message.isShow){
  608. this.msgActionNode.addClass("icon_msg_focus");
  609. this.msgActionNode.addClass("mainColor_bg");
  610. this.message.show();
  611. }
  612. },
  613. //******* end message menu ************************************************
  614. //******* begin task item *************************************************
  615. createTaskItem: function(app){
  616. return new o2.xDesktop.Default.TaskItem(this, app);
  617. },
  618. //******* end task item ***************************************************
  619. closeApp: function(app, hasTaskitem) {
  620. var appId = app.appId;
  621. this.appCurrentList.erase(app);
  622. this.appArr.erase(app);
  623. this.apps[appId] = null;
  624. delete this.apps[appId];
  625. if (!hasTaskitem){
  626. var i = this.appCurrentList.length;
  627. if (i && this.appCurrentList[i-1]){
  628. this.appCurrentList[i-1].setCurrent();
  629. }else{
  630. var keys = Object.keys(this.apps);
  631. i = keys.length;
  632. if (i && this.apps[keys[i-1]] && this.apps[keys[i-1]].setCurrent){
  633. this.apps[keys[i-1]].setCurrent();
  634. }else{
  635. //if (app.appId!=="Homepage") layout.openApplication(null, "Homepage");
  636. layout.openApplication(null, "Homepage");
  637. }
  638. }
  639. this.checkTaskBarSize();
  640. this.checkTaskBarScrollTo();
  641. }
  642. },
  643. refreshApp:function(app){
  644. if (app.window){
  645. var taskitem = app.taskitem;
  646. var appStatus ={
  647. "id": app.appId,
  648. "name": app.options.name,
  649. "style": app.options.style,
  650. "appId": app.appId
  651. };
  652. var status = (app.recordStatus) ? app.recordStatus() : null;
  653. app.close(true);
  654. layout.openApplication(null, appStatus.name, appStatus, status, false, taskitem);
  655. //this.openApplicationWithStatus(appStatus);
  656. }
  657. },
  658. getPageDesignerStyle: function(callback){
  659. if (!this.pageDesignerStyle){
  660. this.pageDesignerStyle = "default";
  661. MWF.UD.getData("pageDesignerStyle", function(json) {
  662. if (json.data) {
  663. var styles = JSON.decode(json.data);
  664. this.pageDesignerStyle = styles.style;
  665. }
  666. if (callback) callback();
  667. }.bind(this));
  668. }else{
  669. if (callback) callback();
  670. }
  671. },
  672. getFormDesignerStyle: function(callback){
  673. if (!this.formDesignerStyle){
  674. this.formDesignerStyle = "default";
  675. MWF.UD.getData("formDesignerStyle", function(json) {
  676. if (json.data) {
  677. var styles = JSON.decode(json.data);
  678. this.formDesignerStyle = styles.style;
  679. }
  680. if (callback) callback();
  681. }.bind(this));
  682. }else{
  683. if (callback) callback();
  684. }
  685. },
  686. createRefreshNode: function(){
  687. this.refreshNode = new Element("div.layout_refresh_node.icon_refresh").inject(this.desktopNode);
  688. this.refreshNode.set("morph", {
  689. "duration": 100,
  690. "transition": Fx.Transitions.Quart.easeOut
  691. });
  692. this.refreshNode.addEvent("click", function(){
  693. if (this.currentApp) this.currentApp.refresh();
  694. this.hideRefresh();
  695. }.bind(this));
  696. },
  697. showRefresh: function(){
  698. if (!this.refreshNodeShow){
  699. if (!this.refreshNode) this.createRefreshNode();
  700. var size = this.taskbarNode.getSize();
  701. var nodeSize = this.refreshNode.getSize();
  702. var top = size.y;
  703. var left = size.x/2-nodeSize.x/2;
  704. this.refreshNode.setStyles({
  705. "left": left,
  706. "top": 0-nodeSize.y,
  707. "opacity": 0
  708. });
  709. this.refreshNode.morph({
  710. "top": top,
  711. "left": left,
  712. "opacity": 0.9
  713. });
  714. this.refreshNodeShow = true;
  715. this.refreshTimeoutId = window.setTimeout(function(){
  716. this.hideRefresh();
  717. }.bind(this), 2000);
  718. }
  719. },
  720. hideRefresh: function(){
  721. if (this.refreshNodeShow){
  722. if (this.refreshNode){
  723. var size = this.taskbarNode.getSize();
  724. var nodeSize = this.refreshNode.getSize();
  725. var top = size.y;
  726. var left = size.x/2-nodeSize.x/2;
  727. this.refreshNode.morph({
  728. "top": 0-nodeSize.y,
  729. "left": left,
  730. "opacity": 0
  731. });
  732. window.setTimeout(function(){
  733. this.refreshNodeShow = false;
  734. }.bind(this), 100);
  735. }
  736. }
  737. if (this.refreshTimeoutId){
  738. window.clearTimeout(this.refreshTimeoutId);
  739. this.refreshTimeoutId = "";
  740. }
  741. }
  742. });
  743. o2.xDesktop.Default.StartMenu = new Class({
  744. Implements: [Events],
  745. initialize: function(layout){
  746. this.layout = layout;
  747. this.container = this.layout.startMenuArea;
  748. this.actionNode = this.layout.startMenuNode;
  749. this.isLoaded = false;
  750. this.isShow = false;
  751. this.isMorph = false;
  752. this.itemTempletedHtml = "" +
  753. " <div class='layout_start_item_iconArea'>" +
  754. " <div class='layout_start_item_icon'></div>" +
  755. " </div>" +
  756. " <div class='layout_start_item_text'></div>"+
  757. " <div class='layout_start_item_badge'></div>";
  758. },
  759. load: function(){
  760. var view = this.layout.path+this.layout.options.style+((o2.session.isMobile || layout.mobile) ? "/layout-menu-mobile.html" : "/layout-menu-pc.html");
  761. this.container.loadHtml(view, {"module": this}, function(){
  762. this.maskNode.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  763. this.node.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  764. this.layout.menuNode.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  765. this.node.addEvent("mousedown", function(e){
  766. e.stopPropagation();
  767. e.preventDefault();
  768. });
  769. this.triangleNode = new Element("div.layout_menu_start_triangle").inject(this.layout.menuNode, "after");
  770. this.hideMessage = function(){ this.hide(); }.bind(this);
  771. this.fireEvent("load");
  772. this.layout.addEvent("resize", this.setSize.bind(this));
  773. this.loadTitle();
  774. this.loadLnks();
  775. this.isLoaded = true;
  776. this.fireEvent("load");
  777. }.bind(this));
  778. },
  779. setScroll: function(){
  780. o2.require("o2.widget.ScrollBar", function(){
  781. this.appScrollBar = new o2.widget.ScrollBar(this.appScrollNode, {
  782. "style":"xDesktop_Message", "where": "before", "indent": false, "distance": 100, "friction": 6, "axis": {"x": false, "y": true}
  783. });
  784. }.bind(this));
  785. },
  786. loadTitle: function(){
  787. this.lnkTitleNode.set("text", o2.LP.desktop.lnkAppTitle);
  788. this.appCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.application}).inject(this.appTitleNode);
  789. this.processCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.process}).inject(this.appTitleNode);
  790. this.inforCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.infor}).inject(this.appTitleNode);
  791. this.queryCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.query}).inject(this.appTitleNode);
  792. this.searchNode = new Element("div.layout_start_search").inject(this.appTitleNode);
  793. this.searchIconNode = new Element("div.layout_start_search_icon").inject(this.searchNode);
  794. this.searchIconNode.addClass("icon_startMenu_search");
  795. var currentWidth = this.searchNode.getSize().x;
  796. this.searchNode.store("currentWidth", currentWidth);
  797. this.appCategoryTab.addEvent("click", function(){
  798. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  799. this.appCategoryTab.addClass("mainColor_bg");
  800. this.currentTab = this.appCategoryTab;
  801. this.loadApplications();
  802. }.bind(this));
  803. this.processCategoryTab.addEvent("click", function(){
  804. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  805. this.processCategoryTab.addClass("mainColor_bg");
  806. this.currentTab = this.processCategoryTab;
  807. this.loadProcesses();
  808. }.bind(this));
  809. this.inforCategoryTab.addEvent("click", function(){
  810. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  811. this.inforCategoryTab.addClass("mainColor_bg");
  812. this.currentTab = this.inforCategoryTab;
  813. this.loadInfors();
  814. }.bind(this));
  815. this.queryCategoryTab.addEvent("click", function(){
  816. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  817. this.queryCategoryTab.addClass("mainColor_bg");
  818. this.currentTab = this.queryCategoryTab;
  819. this.loadQuerys();
  820. }.bind(this));
  821. this.searchIconNode.addEvent("click", this.searchIconAction.bind(this));
  822. },
  823. searchIconAction: function(){
  824. if (!this.isMorph){
  825. if (this.isSearch){
  826. this.doSearch();
  827. }else{
  828. this.loadSearch()
  829. }
  830. }
  831. },
  832. loadSearch: function(){
  833. this.isSearch = true;
  834. this.searchNode.addClass("mainColor_border");
  835. this.appCategoryTab.hide();
  836. this.processCategoryTab.hide();
  837. this.inforCategoryTab.hide();
  838. this.queryCategoryTab.hide();
  839. var size = this.appTitleNode.getSize();
  840. var pr = this.appTitleNode.getStyle("padding-right").toInt() || 0;
  841. var pl = this.appTitleNode.getStyle("padding-left").toInt() || 0;
  842. var margin = this.searchNode.getStyle("margin-right").toInt() || 0;
  843. var w = size.x-margin*2-pr-pl;
  844. this.isMorph = true;
  845. this.searchNode.set("morph", {"duration": 200});
  846. this.searchNode.morph({"width": ""+w+"px"});
  847. window.setTimeout(function(){
  848. this.isMorph = false;
  849. }.bind(this), 220);
  850. if (!this.searchClearNode){
  851. this.searchClearNode = new Element("div.layout_start_search_clear").inject(this.searchNode);
  852. this.searchClearNode.addClass("icon_clear");
  853. this.searchClearNode.addEvent("click", this.hideSearch.bind(this));
  854. }
  855. this.searchClearNode.show();
  856. if (!this.searchAreaNode) this.searchAreaNode = new Element("div.layout_start_search_area").inject(this.searchNode);
  857. this.searchAreaNode.show();
  858. if (!this.searchInputNode){
  859. this.searchInputNode = new Element("input.layout_start_search_input", {"placeholder": o2.LP.searchKey}).inject(this.searchAreaNode);
  860. this.searchInputNode.addEvent("keydown", function(e){
  861. if (e.code==13) this.doSearch();
  862. }.bind(this));
  863. }
  864. this.searchInputNode.show();
  865. this.searchInputNode.focus();
  866. //this.searchNode.addClass("layout_start_search_load");
  867. },
  868. hideSearch: function(){
  869. if (this.isSearch){
  870. if (this.searchInputNode){
  871. this.searchInputNode.set("value", "");
  872. this.searchInputNode.hide();
  873. }
  874. if (this.searchAreaNode) this.searchAreaNode.hide();
  875. if (this.searchClearNode) this.searchClearNode.hide();
  876. this.isMorph = true;
  877. var currentWidth = this.searchNode.retrieve("currentWidth");
  878. this.searchNode.morph({"width": ""+currentWidth+"px"});
  879. window.setTimeout(function(){
  880. if (this.currentTab && this.isSearchResult) this.currentTab.click();
  881. this.searchNode.removeClass("mainColor_border");
  882. this.appCategoryTab.show();
  883. this.processCategoryTab.show();
  884. this.inforCategoryTab.show();
  885. this.queryCategoryTab.show();
  886. this.isSearch = false;
  887. this.isMorph = false;
  888. this.isSearchResult = false;
  889. }.bind(this), 220);
  890. }
  891. },
  892. doSearch: function(){
  893. var key = this.searchInputNode.get("value").toLowerCase();
  894. if (key){
  895. this.isSearchResult = true;
  896. this.appContentNode.empty();
  897. this.searchApplicatins(key);
  898. this.searchProcesses(key);
  899. this.searchInfors(key);
  900. this.searchQuerys(key);
  901. }
  902. },
  903. searchApplicatins: function(value){
  904. var user = this.layout.session.user;
  905. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  906. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  907. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  908. if (this.layoutJson && this.layoutJson.length) this.layoutJson.each(function(v){
  909. if ( this.checkMenuItem(v, currentNames) ){
  910. if ((v.title.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.title.toPY().toLowerCase().indexOf(value)!==-1) || (v.title.indexOf(value)!==-1)){
  911. this.createApplicationMenuItem(v);
  912. }
  913. }
  914. }.bind(this));
  915. if (this.componentJson && this.componentJson.length) this.componentJson.each(function(v){
  916. if ( this.checkMenuItem(v, currentNames) ){
  917. if ((v.title.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.title.toPY().toLowerCase().indexOf(value)!==-1) || (v.title.indexOf(value)!==-1)){
  918. this.createApplicationMenuItem(v);
  919. }
  920. }
  921. }.bind(this));
  922. if (this.portalJson && this.portalJson.length) this.portalJson.each(function(v){
  923. if ((v.name.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.name.toPY().toLowerCase().indexOf(value)!==-1) || (v.name.indexOf(value)!==-1)){
  924. this.createPortalMenuItem(v);
  925. }
  926. }.bind(this));
  927. },
  928. searchProcesses: function(value){
  929. if (this.processJson && this.processJson.length) this.processJson.each(function(v){
  930. if ((v.name.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.name.toPY().toLowerCase().indexOf(value)!==-1) || (v.name.indexOf(value)!==-1)){
  931. this.createProcessMenuItem(v);
  932. }
  933. }.bind(this));
  934. },
  935. searchInfors: function(value){
  936. if (this.inforJson && this.inforJson.length) this.inforJson.each(function(v){
  937. if ((v.appName.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.appName.toPY().toLowerCase().indexOf(value)!==-1) || (v.appName.indexOf(value)!==-1)){
  938. this.createInforMenuItem(v);
  939. }
  940. }.bind(this));
  941. },
  942. searchQuerys: function(value){
  943. if (this.queryJson && this.queryJson.length) this.queryJson.each(function(v){
  944. if ((v.name.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.name.toPY().toLowerCase().indexOf(value)!==-1) || (v.name.indexOf(value)!==-1)){
  945. this.createQueryMenuItem(v);
  946. }
  947. }.bind(this));
  948. },
  949. loadJsons: function(callback){
  950. this.clearAppContentNode();
  951. this.loadLayoutApplications(function(json_layout){
  952. var componentAction = o2.Actions.get("x_component_assemble_control");
  953. var portalAction = o2.Actions.get("x_portal_assemble_surface");
  954. var processAction = o2.Actions.get("x_processplatform_assemble_surface");
  955. var inforAction = o2.Actions.get("x_cms_assemble_control");
  956. var queryAction = o2.Actions.get("x_query_assemble_surface");
  957. var iconsPath = this.layout.path+"icons.json";
  958. this.getIconsJson(function(){
  959. o2.Actions.invokeAsync([
  960. {"action": componentAction, "name": "listComponent"},
  961. {"action": portalAction, "name": "listApplication"},
  962. {"action": processAction, "name": "listApplication"},
  963. {"action": inforAction, "name": "listColumn"},
  964. {"action": queryAction, "name": "listQuery"},
  965. ], {"success": function(json_component, json_portal, json_process, json_infor, json_query){
  966. this.layoutJson = json_layout;
  967. this.componentJson = json_component.data;
  968. this.portalJson = json_portal.data;
  969. this.processJson = json_process.data;
  970. this.inforJson = json_infor.data;
  971. this.queryJson = json_query.data;
  972. if (callback) callback();
  973. }.bind(this), "failure": function(){}}
  974. );
  975. }.bind(this));
  976. }.bind(this));
  977. },
  978. getIconsJson: function(callback){
  979. if (this.layout.iconsJson){
  980. if (callback) callback();
  981. }else{
  982. o2.JSON.get(iconsPath, function(json){
  983. this.layout.iconsJson = json;
  984. if (callback) callback();
  985. }.bind(this));
  986. }
  987. },
  988. setPosition: function(){
  989. //var size = this.container.getSize();
  990. var index = o2.xDesktop.zIndexPool.zIndex;
  991. var nodeSize = this.node.getSize();
  992. var left = 0-nodeSize.x;
  993. this.maskNode.setStyles({"left": ""+left+"px"});
  994. this.node.setStyles({"left": ""+left+"px"});
  995. },
  996. setSize: function(){
  997. if (this.appScrollBar && this.appScrollBar.scrollVNode) this.appScrollBar.scrollVNode.setStyle("margin-top", "0px");
  998. var isLnk = false;
  999. if (false && this.layout.lnks && this.layout.lnks.length){
  1000. this.lnkAreaNode.show();
  1001. this.lineNode.show();
  1002. var h = 100*3;
  1003. this.lnkScrollNode.setStyle("height", ""+h+"px");
  1004. isLnk = true;
  1005. }else{
  1006. this.lnkAreaNode.hide();
  1007. this.lineNode.hide();
  1008. }
  1009. var size = this.node.getSize();
  1010. var lnkSizeY = (isLnk) ? this.lnkAreaNode.getSize().y : 0;
  1011. var lineSizeY = (isLnk) ? this.lineNode.getSize().y : 0;
  1012. var mt = (isLnk) ? (this.lineNode.getStyle("margin-top").toInt() || 0) : 0;
  1013. var mb = (isLnk) ? (this.lineNode.getStyle("margin-bottom").toInt() || 0) : 0;
  1014. var titleSize = this.appTitleNode.getSize();
  1015. var y = size.y-lnkSizeY-lineSizeY-mt-mb-titleSize.y;
  1016. this.appScrollNode.setStyle("height", ""+y+"px");
  1017. },
  1018. loadLnks: function(){
  1019. // if (this.layout.lnks && this.layout.lnks.length){
  1020. // this.lnkAreaNode.show();
  1021. // this.lineNode.show();
  1022. // this.lnkContentNode.empty();
  1023. // this.createLnkMenuItem();
  1024. // }else{
  1025. this.lnkAreaNode.hide();
  1026. this.lineNode.hide();
  1027. //}
  1028. },
  1029. createLnkMenuItem: function(){
  1030. //this.templetedHtml
  1031. },
  1032. clearAppContentNode: function(){
  1033. this.appContentNode.empty();
  1034. this.appContentNode.addClass("icon_loading");
  1035. },
  1036. loadApplications: function(callback){
  1037. this.clearAppContentNode();
  1038. // this.loadLayoutApplications(function(json_layout){
  1039. // var componentAction = o2.Actions.get("x_component_assemble_control");
  1040. // var portalAction = o2.Actions.get("x_portal_assemble_surface");
  1041. // o2.Actions.invokeAsync([
  1042. // {"action": componentAction, "name": "listComponent"},
  1043. // {"action": portalAction, "name": "listApplication"},
  1044. // ], {"success": function(json_component, json_portal){
  1045. // this.loadApplicationsItem(json_layout, json_component.data, json_portal.data);
  1046. // }.bind(this), "failure": function(){}}
  1047. // );
  1048. // }.bind(this));
  1049. this.loadApplicationsItem(this.layoutJson, this.componentJson, this.portalJson);
  1050. },
  1051. loadLayoutApplications: function(callback){
  1052. var url = this.layout.path+"applications.json";
  1053. o2.getJSON(url, function(json){
  1054. if (callback) callback(json);
  1055. }.bind(this));
  1056. },
  1057. loadApplicationsItem: function(json_layout, json_component, json_portal){
  1058. var user = this.layout.session.user;
  1059. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  1060. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  1061. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  1062. this.appContentNode.removeClass("icon_loading");
  1063. if (json_layout && json_layout.length) json_layout.each(function(value){
  1064. if ( this.checkMenuItem(value, currentNames) ) this.createApplicationMenuItem(value);
  1065. }.bind(this));
  1066. if (json_component && json_component.length) json_component.each(function(value){
  1067. if ( this.checkMenuItem(value, currentNames) ) this.createApplicationMenuItem(value);
  1068. }.bind(this));
  1069. if (json_portal && json_portal.length) json_portal.each(function(value){
  1070. this.createPortalMenuItem(value);
  1071. }.bind(this));
  1072. },
  1073. loadProcesses: function(){
  1074. this.clearAppContentNode();
  1075. // o2.Actions.get("x_processplatform_assemble_surface").listApplication(this.loadProcessesItem.bind(this));
  1076. this.loadProcessesItem(this.processJson)
  1077. },
  1078. loadProcessesItem: function(json){
  1079. this.appContentNode.removeClass("icon_loading");
  1080. if (json && json.length) json.each(function(value){
  1081. this.createProcessMenuItem(value);
  1082. }.bind(this));
  1083. },
  1084. loadInfors: function(){
  1085. this.clearAppContentNode();
  1086. //o2.Actions.get("x_cms_assemble_control").listColumn(this.loadInforsItem.bind(this));
  1087. this.loadInforsItem(this.inforJson)
  1088. },
  1089. loadInforsItem: function(json){
  1090. this.appContentNode.removeClass("icon_loading");
  1091. if (json && json.length) json.each(function(value){
  1092. this.createInforMenuItem(value);
  1093. }.bind(this));
  1094. },
  1095. loadQuerys: function(){
  1096. this.clearAppContentNode();
  1097. // o2.Actions.get("x_query_assemble_surface").listQuery(this.loadQuerysItem.bind(this));
  1098. this.loadQuerysItem(this.queryJson)
  1099. },
  1100. loadQuerysItem: function(json){
  1101. this.appContentNode.removeClass("icon_loading");
  1102. if (json && json.length) json.each(function(value){
  1103. this.createQueryMenuItem(value);
  1104. }.bind(this));
  1105. },
  1106. checkMenuItem: function(value, currentNames){
  1107. if (value.visible===false) return false;
  1108. var isAllow = true;
  1109. if (value.allowList) isAllow = (value.allowList.length) ? (value.allowList.isIntersect(currentNames)) : true;
  1110. var isDeny = false;
  1111. if (value.denyList) isDeny = (value.denyList.length) ? (value.denyList.isIntersect(currentNames)) : false;
  1112. return ((!isDeny && isAllow) || o2.AC.isAdministrator());
  1113. },
  1114. createApplicationMenuItem: function(value){
  1115. new o2.xDesktop.Default.StartMenu.Item(this, this.appContentNode, value)
  1116. },
  1117. createPortalMenuItem: function(value){
  1118. new o2.xDesktop.Default.StartMenu.PortalItem(this, this.appContentNode, value)
  1119. },
  1120. createProcessMenuItem: function(value){
  1121. new o2.xDesktop.Default.StartMenu.ProcessItem(this, this.appContentNode, value)
  1122. },
  1123. createInforMenuItem: function(value){
  1124. new o2.xDesktop.Default.StartMenu.InforItem(this, this.appContentNode, value)
  1125. },
  1126. createQueryMenuItem: function(value){
  1127. new o2.xDesktop.Default.StartMenu.QueryItem(this, this.appContentNode, value)
  1128. },
  1129. show: function(){
  1130. if (!this.isMorph){
  1131. this.isMorph = true;
  1132. if (!this.morph){
  1133. this.maskMorph = new Fx.Morph(this.maskNode, {
  1134. duration: "200",
  1135. transition: Fx.Transitions.Sine.easeOut
  1136. });
  1137. this.morph = new Fx.Morph(this.node, {
  1138. duration: "200",
  1139. transition: Fx.Transitions.Sine.easeOut
  1140. });
  1141. }
  1142. this.maskNode.setStyles({"display": "block"});
  1143. this.node.setStyles({"display": "block"});
  1144. this.triangleNode.setStyles({"display": "block"});
  1145. this.setSize();
  1146. this.setPosition();
  1147. var size = this.layout.menuNode.getSize();
  1148. var left = size.x;
  1149. this.loadJsons(function(){
  1150. (this.currentTab || this.appCategoryTab).click();
  1151. }.bind(this));
  1152. //this.loadContent();
  1153. this.maskMorph.start({"left": ""+left+"px"});
  1154. this.morph.start({"left": ""+left+"px"}).chain(function(){
  1155. this.isShow = true;
  1156. this.isMorph = false;
  1157. this.layout.desktopNode.addEvent("mousedown", this.hideMessage);
  1158. this.setScroll();
  1159. this.fireEvent("show");
  1160. }.bind(this));
  1161. }
  1162. },
  1163. hide: function(callback){
  1164. if (!this.isMorph){
  1165. this.isMorph = true;
  1166. if (!this.morph){
  1167. this.maskMorph = new Fx.Morph(this.maskNode, {
  1168. duration: "200",
  1169. transition: Fx.Transitions.Sine.easeOut
  1170. });
  1171. this.morph = new Fx.Morph(this.node, {
  1172. duration: "200",
  1173. transition: Fx.Transitions.Sine.easeOut
  1174. });
  1175. }
  1176. var nodeSize = this.node.getSize();
  1177. var left = 0-nodeSize.x;
  1178. // var position = this.node.getPosition();
  1179. // var size = this.node.getSize();
  1180. // var left = position.x+size.x;
  1181. this.isSearchResult = false;
  1182. this.hideSearch();
  1183. this.lnkContentNode.empty();
  1184. this.appContentNode.empty();
  1185. if (this.appScrollBar) this.appScrollBar.destroy();
  1186. this.maskMorph.start({"left": ""+left+"px"}).chain(function(){
  1187. this.maskNode.setStyle("display", "none");
  1188. this.triangleNode.setStyles({"display": "none"});
  1189. }.bind(this));
  1190. this.morph.start({"left": ""+left+"px"}).chain(function(){
  1191. this.node.setStyle("display", "none");
  1192. this.isShow = false;
  1193. this.isMorph = false;
  1194. this.layout.desktopNode.removeEvent("mousedown", this.hideMessage);
  1195. this.fireEvent("hide");
  1196. if (callback) callback();
  1197. }.bind(this));
  1198. }
  1199. },
  1200. });
  1201. o2.xDesktop.Default.StartMenu.Item = new Class({
  1202. initialize: function (menu, container, data) {
  1203. this.menu = menu;
  1204. this.layout = this.menu.layout;
  1205. this.data = data;
  1206. this.container = $(container);
  1207. this.load();
  1208. },
  1209. load: function(){
  1210. this.node = new Element("div.layout_start_item").inject(this.container);
  1211. this.node.set("html", this.menu.itemTempletedHtml);
  1212. this.iconAreaNode = this.node.getElement(".layout_start_item_iconArea");
  1213. this.iconNode = this.node.getElement(".layout_start_item_icon");
  1214. this.badgeNode = this.node.getElement(".layout_start_item_badge");
  1215. this.textNode = this.node.getElement(".layout_start_item_text");
  1216. this.loadIcon();
  1217. this.loadBadge();
  1218. this.loadText();
  1219. this.setEvent();
  1220. },
  1221. loadIcon: function(){
  1222. var icon;
  1223. var bgcolor = "";
  1224. if (this.data.path.substring(0, 4)==="@url"){
  1225. if (this.data.iconPath){
  1226. icon = this.data.iconPath;
  1227. }else{
  1228. if (this.layout.iconsJson["Url"] && this.layout.iconsJson["Url"].icon){
  1229. icon = this.layout.path+"appicons/"+this.layout.iconsJson["Url"].icon;
  1230. bgcolor = this.layout.iconsJson["Url"].color;
  1231. }else{
  1232. icon = "../x_component_Setting/$Main/default/icon/site.png";
  1233. bgcolor = "";
  1234. }
  1235. }
  1236. }else{
  1237. if (this.layout.iconsJson[this.data.path] && this.layout.iconsJson[this.data.path].icon){
  1238. icon = this.layout.path+"appicons/"+this.layout.iconsJson[this.data.path].icon;
  1239. bgcolor = this.layout.iconsJson[this.data.path].color;
  1240. }else{
  1241. icon = "../x_component_"+this.data.path.replace(/\./g, "_")+"/$Main/"+this.data.iconPath;
  1242. bgcolor = "";
  1243. }
  1244. }
  1245. if (icon && bgcolor){
  1246. this.iconNode.addClass("layout_start_item_icon_flat");
  1247. this.iconNode.setStyle("background-color", bgcolor);
  1248. }
  1249. this.iconNode.setStyle("background-image", "url("+icon+")");
  1250. this.icon = icon;
  1251. this.bgcolor = bgcolor;
  1252. },
  1253. loadBadge: function(){
  1254. this.badgeNode.set("title", o2.LP.desktop.addLnk).addClass("icon_add_red");
  1255. },
  1256. loadText: function(){
  1257. this.textNode.set("text", this.data.title);
  1258. },
  1259. setEvent: function(){
  1260. this.node.addEvents({
  1261. "mouseover": function(){ this.badgeNode.fade("in"); }.bind(this),
  1262. "mouseout": function(){ this.badgeNode.fade("out"); }.bind(this),
  1263. "click": function(e){
  1264. this.menu.hide(function(){
  1265. this.open(e);
  1266. }.bind(this));
  1267. }.bind(this)
  1268. });
  1269. this.badgeNode.addEvent("click", function(e){
  1270. this.addLnk();
  1271. e.stopPropagation();
  1272. }.bind(this));
  1273. this.makeLnk();
  1274. },
  1275. addLnk: function(dragTargetLnk, dragPosition){
  1276. lnkdata = {
  1277. "name": this.data.path,
  1278. "title": this.data.title,
  1279. "iconData": this.data.iconData || null,
  1280. "icon": this.iconData || null,
  1281. "appType": null,
  1282. "options": null
  1283. }
  1284. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  1285. },
  1286. open: function(e){
  1287. layout.openApplication(e, this.data.path);
  1288. },
  1289. makeLnk: function(){
  1290. var drag = new Drag(this.node, {
  1291. "stopPropagation": true,
  1292. "compensateScroll": true,
  1293. "onStart": function(el, e){
  1294. this.doDragMove(e);
  1295. drag.stop();
  1296. }.bind(this)
  1297. });
  1298. },
  1299. getDragNode: function(){
  1300. if (!this.dragNode){
  1301. this.dragNode = new Element("div.layout_menu_lnk_item_drag")
  1302. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  1303. .inject(this.layout.node);
  1304. var dragIconNode = this.iconNode.clone(true).inject(this.dragNode)
  1305. .removeClass("layout_menu_lnk_item_icon")
  1306. .addClass("layout_menu_lnk_item_icon_drag");
  1307. if (this.bgcolor) dragIconNode.setStyle("background-color", this.bgcolor);
  1308. }
  1309. var p = this.iconNode.getPosition(this.dragNode.getOffsetParent());
  1310. this.dragNode.show().setStyles({
  1311. "left": ""+p.x+"px", "top": ""+p.y+"px"
  1312. });
  1313. },
  1314. doDragMove: function(e){
  1315. this.getDragNode();
  1316. var drag = new Drag.Move(this.dragNode, {
  1317. "stopPropagation": true,
  1318. "compensateScroll": true,
  1319. "droppables": [this.layout.lnkContentNode],
  1320. "onStart": function(){ this._drag_start(); }.bind(this),
  1321. "onDrag": function(dragging,e){ this._drag_drag(dragging, e); }.bind(this),
  1322. "onEnter": function(dragging, inObj){ this._drag_enter(dragging, inObj); }.bind(this),
  1323. "onLeave": function(dragging, obj){ this._drag_leave(dragging, obj); }.bind(this),
  1324. "onDrop": function(dragging, inObj){ this._drag_drop(dragging, inObj); }.bind(this),
  1325. "onCancel": function(dragging){ this._drag_cancel(dragging); }.bind(this),
  1326. "onComplete": function(dragging, e){ this._drag_complete(dragging, e); }.bind(this),
  1327. });
  1328. drag.start(e);
  1329. this.dragStatus == "remove";
  1330. },
  1331. _drag_start: function(){
  1332. this.dragTargetLnk = null;
  1333. this.dragPosition = "before";
  1334. },
  1335. _drag_drag: function(dragging, e){
  1336. if (this.dragStatus == "order"){
  1337. if (this.layout.lnks && this.layout.lnks.length){
  1338. var current = e.page.y;
  1339. for (var i=0; i<this.layout.lnks.length; i++){
  1340. var lnk = this.layout.lnks[i];
  1341. var y = lnk.node.getSize().y;
  1342. var top = lnk.node.getPosition(this.layout.node).y;
  1343. var center = top+y/2;
  1344. var bottom = top+y;
  1345. if (top<=current && center>=current){
  1346. this.dragTargetLnk = lnk;
  1347. this.dragPosition = "before";
  1348. break;
  1349. }else if (center<=current && bottom>=current){
  1350. this.dragTargetLnk = lnk;
  1351. this.dragPosition = "after";
  1352. break;
  1353. }
  1354. }
  1355. if (!this.layout.positionNode) this.layout.positionNode = new Element("div.layout_menu_lnk_item_position")
  1356. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  1357. .inject(this.layout.node);
  1358. this.layout.positionNode.show();
  1359. if (!this.dragTargetLnk){
  1360. this.dragTargetLnk = this.layout.lnks[this.layout.lnks.length-1];
  1361. this.dragPosition = "after";
  1362. }
  1363. this.layout.positionNode.position({
  1364. relativeTo: this.dragTargetLnk.node,
  1365. position: (this.dragPosition=="before") ? 'topcenter' : 'bottomcenter',
  1366. edge: 'center'
  1367. });
  1368. }
  1369. }
  1370. },
  1371. _drag_enter: function(){
  1372. this.dragStatus = "order";
  1373. },
  1374. _drag_leave: function(){
  1375. this.dragStatus = "remove";
  1376. if (this.layout.positionNode) this.layout.positionNode.hide();
  1377. },
  1378. _drag_drop: function(dragging, inObj){
  1379. if (this.dragStatus == "order" && this.dragTargetLnk && this.dragTargetLnk!=this){
  1380. this.addLnk(this.dragTargetLnk, this.dragPosition);
  1381. // this.node.inject(this.dragTargetLnk.node, this.dragPosition);
  1382. // this.layout.lnks.erase(this);
  1383. // var idx = this.layout.lnks.indexOf(this.dragTargetLnk);
  1384. // if (this.dragPosition=="before"){
  1385. // this.layout.lnks.splice(idx, 0, this);
  1386. // }else{
  1387. // this.layout.lnks.splice(idx+1, 0, this);
  1388. // }
  1389. }
  1390. },
  1391. _drag_cancel: function(dragging){
  1392. dragging.hide();
  1393. if (this.layout.positionNode) this.layout.positionNode.hide();
  1394. if (this.dragRemoveNode) this.dragRemoveNode.hide();
  1395. },
  1396. _drag_complete: function(dragging){
  1397. this._drag_cancel(dragging);
  1398. }
  1399. });
  1400. o2.xDesktop.Default.StartMenu.PortalItem = new Class({
  1401. Extends: o2.xDesktop.Default.StartMenu.Item,
  1402. loadIcon: function(){
  1403. var icon = "";
  1404. var bgcolor = "";
  1405. if (this.data.icon){
  1406. icon = "data:image/png;base64,"+this.data.icon+"";
  1407. }else{
  1408. var p = "portalDefault";
  1409. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  1410. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  1411. bgcolor = this.layout.iconsJson[p].color;
  1412. }else{
  1413. icon = "../x_component_portal_PortalExplorer/$Main/default/icon/application.png";
  1414. bgcolor = "";
  1415. }
  1416. }
  1417. if (icon && bgcolor){
  1418. this.iconNode.addClass("layout_start_item_icon_flat");
  1419. this.iconNode.setStyle("background-color", bgcolor);
  1420. }
  1421. this.iconNode.setStyle("background-image", "url("+icon+")");
  1422. this.icon = icon;
  1423. },
  1424. loadText: function(){
  1425. this.textNode.set("text", this.data.name);
  1426. },
  1427. addLnk: function(dragTargetLnk, dragPosition){
  1428. var options = {"portalId": this.data.id, "appId": "portal.Portal"+this.data.id};
  1429. lnkdata = {
  1430. "name": "portal.Portal",
  1431. "title": this.data.name,
  1432. "iconData": (this.data.icon) || "",
  1433. "icon": null,
  1434. "appType": "portal",
  1435. "options": options
  1436. }
  1437. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  1438. },
  1439. open: function(e){
  1440. var options = {"portalId": this.data.id, "appId": "portal.Portal"+this.data.id};
  1441. layout.openApplication(e, "portal.Portal", options);
  1442. }
  1443. // makeLnk: function(){
  1444. // //@todo
  1445. // // this.node.makeLnk({
  1446. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  1447. // // });
  1448. // }
  1449. });
  1450. o2.xDesktop.Default.StartMenu.ProcessItem = new Class({
  1451. Extends: o2.xDesktop.Default.StartMenu.PortalItem,
  1452. loadIcon: function(){
  1453. var icon = "";
  1454. var bgcolor = "";
  1455. if (this.data.icon){
  1456. icon = "data:image/png;base64,"+this.data.icon+"";
  1457. bgcolor = "";
  1458. }else{
  1459. var p = "processDefault";
  1460. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  1461. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  1462. bgcolor = this.layout.iconsJson[p].color;
  1463. }else{
  1464. icon = "../x_component_process_ApplicationExplorer/$Main/default/icon/application.png";
  1465. bgcolor = "";
  1466. }
  1467. }
  1468. if (icon && bgcolor){
  1469. this.iconNode.addClass("layout_start_item_icon_flat");
  1470. this.iconNode.setStyle("background-color", bgcolor);
  1471. }
  1472. this.iconNode.setStyle("background-image", "url("+icon+")");
  1473. this.icon = icon;
  1474. },
  1475. addLnk: function(dragTargetLnk, dragPosition){
  1476. var options = {"id": this.data.id, "appId": "process.Application"+this.data.id};
  1477. lnkdata = {
  1478. "name": "process.Application",
  1479. "title": this.data.name,
  1480. "iconData": (this.data.icon) || "",
  1481. "icon": null,
  1482. "appType": "process",
  1483. "options": options
  1484. }
  1485. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  1486. },
  1487. open: function(e){
  1488. var options = {"id": this.data.id, "appId": "process.Application"+this.data.id};
  1489. layout.openApplication(e, "process.Application", options);
  1490. }
  1491. // makeLnk: function(){
  1492. // //@todo
  1493. // // this.node.makeLnk({
  1494. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  1495. // // });
  1496. // }
  1497. });
  1498. o2.xDesktop.Default.StartMenu.InforItem = new Class({
  1499. Extends: o2.xDesktop.Default.StartMenu.PortalItem,
  1500. loadIcon: function(){
  1501. var icon = "";
  1502. var bgcolor = "";
  1503. if (this.data.appIcon){
  1504. icon = "data:image/png;base64,"+this.data.appIcon+"";
  1505. bgcolor = "";
  1506. }else{
  1507. var p = "cmsDefault";
  1508. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  1509. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  1510. bgcolor = this.layout.iconsJson[p].color;
  1511. }else{
  1512. icon = "../x_component_cms_Index/$Main/default/icon/column.png";
  1513. bgcolor = "";
  1514. }
  1515. }
  1516. if (icon && bgcolor){
  1517. this.iconNode.addClass("layout_start_item_icon_flat");
  1518. this.iconNode.setStyle("background-color", bgcolor);
  1519. }
  1520. this.iconNode.setStyle("background-image", "url("+icon+")");
  1521. this.icon = icon;
  1522. },
  1523. loadText: function(){
  1524. this.textNode.set("text", this.data.appName);
  1525. },
  1526. addLnk: function(dragTargetLnk, dragPosition){
  1527. lnkdata = {
  1528. "name": "cms.Module",
  1529. "title": this.data.appName,
  1530. "iconData": (this.data.appIcon) || "",
  1531. "icon": null,
  1532. "appType": "cms",
  1533. "options": {"columnData": this.data, "appId": "cms.Module"+this.data.id}
  1534. }
  1535. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  1536. },
  1537. open: function(e){
  1538. layout.openApplication(e, "cms.Module", {"columnData": this.data, "appId": "cms.Module"+this.data.id});
  1539. }
  1540. // makeLnk: function(){
  1541. // //@todo
  1542. // // this.node.makeLnk({
  1543. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  1544. // // });
  1545. // }
  1546. });
  1547. o2.xDesktop.Default.StartMenu.QueryItem = new Class({
  1548. Extends: o2.xDesktop.Default.StartMenu.PortalItem,
  1549. loadIcon: function(){
  1550. var icon = "";
  1551. var bgcolor = "";
  1552. if (this.data.icon){
  1553. icon = "data:image/png;base64,"+this.data.icon+"";
  1554. bgcolor = "";
  1555. }else{
  1556. var p = "queryDefault";
  1557. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  1558. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  1559. bgcolor = this.layout.iconsJson[p].color;
  1560. }else{
  1561. icon = "../x_component_query_Query/$Main/appicon.png";
  1562. bgcolor = "";
  1563. }
  1564. }
  1565. if (icon && bgcolor){
  1566. this.iconNode.addClass("layout_start_item_icon_flat");
  1567. this.iconNode.setStyle("background-color", bgcolor);
  1568. }
  1569. this.iconNode.setStyle("background-image", "url("+icon+")");
  1570. this.icon = icon;
  1571. },
  1572. addLnk: function(){
  1573. lnkdata = {
  1574. "name": "query.Query",
  1575. "title": this.data.name,
  1576. "iconData": (this.data.icon)||"",
  1577. "icon": null,
  1578. "appType": "query",
  1579. "options": {"id": this.data.id, "appId": "query.Query"+this.data.id}
  1580. }
  1581. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  1582. },
  1583. open: function(e){
  1584. layout.openApplication(e, "query.Query", {"id": this.data.id, "appId": "query.Query"+this.data.id});
  1585. }
  1586. // makeLnk: function(){
  1587. // //@todo
  1588. // // this.node.makeLnk({
  1589. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  1590. // // });
  1591. // }
  1592. });
  1593. o2.xDesktop.Default.TaskItem = new Class({
  1594. initialize: function(desktop, app){
  1595. this.desktop = desktop;
  1596. this.container = this.desktop.taskContentNode;
  1597. this.app = app;
  1598. this.load();
  1599. },
  1600. load: function(){
  1601. this.node = new Element("div.layout_content_taskbar_item").inject(this.container);
  1602. this.iconNode = new Element("div");
  1603. this.closeNode = new Element("div.layout_content_taskbar_item_icon", {"title": o2.LP.widget.close}).inject(this.node);
  1604. this.closeNode.addClass("icon_close");
  1605. if (this.app.options.appId==this.desktop.options.index){
  1606. this.closeNode.hide();
  1607. this.noCloseNode = true;
  1608. }
  1609. this.refreshNode = new Element("div.layout_content_taskbar_item_refresh", {"title": o2.LP.widget.refresh}).inject(this.node);;
  1610. this.refreshNode.addClass("icon_refresh");
  1611. this.refreshNode.addClass("animation_taskItemLoading");
  1612. this.actionNode = new Element("div.layout_content_taskbar_item_action").inject(this.node);;
  1613. this.actionNode.addClass("icon_taskitem_down");
  1614. this.textNode = new Element("div.layout_content_taskbar_item_text").inject(this.node);;
  1615. this.setText(this.app.options.title);
  1616. //this.desktop.checkTaskBarSize();
  1617. this.setEvent();
  1618. this.unSelected();
  1619. },
  1620. setEvent: function(){
  1621. this.textNode.addEvents({
  1622. "click": function(){
  1623. if (this.desktop.currentApp!=this.app){
  1624. if (!this.app.window){
  1625. this.desktop.apps[this.app.options.appId] = null;
  1626. layout.openApplication(null, this.app.options.name, this.app.options, this.app.options.app, false, this, false);
  1627. }else{
  1628. this.app.setCurrent();
  1629. }
  1630. }else{
  1631. // this.app.refresh();
  1632. }
  1633. }.bind(this),
  1634. "dblclick": function(){
  1635. this.app.openInNewBrowser((this.app.options.appId==this.desktop.options.index));
  1636. }.bind(this)
  1637. });
  1638. this.closeNode.addEvents({
  1639. "mouseover": function(){
  1640. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  1641. }.bind(this),
  1642. "mouseout": function(){
  1643. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  1644. }.bind(this),
  1645. "click": function(){
  1646. if (!this.app.window){
  1647. this.desktop.apps[this.app.options.appId] = null;
  1648. delete this.desktop.apps[this.app.options.appId];
  1649. this.destroy();
  1650. }else{
  1651. this.app.close();
  1652. }
  1653. }.bind(this)
  1654. });
  1655. this.refreshNode.addEvents({
  1656. "mouseover": function(){
  1657. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  1658. }.bind(this),
  1659. "mouseout": function(){
  1660. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  1661. }.bind(this),
  1662. "click": function(){
  1663. this.app.refresh();
  1664. }.bind(this)
  1665. });
  1666. this.loadTaskItemMenu();
  1667. if (this.desktop && this.desktop.checkTaskBarSize) this.desktop.checkTaskBarSize();
  1668. },
  1669. loadTaskItemMenu: function(){
  1670. if (!this.taskitemMenu){
  1671. this.taskitemMenu = new o2.xDesktop.Menu(this.actionNode, {
  1672. "event": "click", "style": "flatUser", "offsetX": -10, "offsetY":6, "container": this.node
  1673. });
  1674. this.taskitemMenu.load();
  1675. this.loadTaskItemMenuItems();
  1676. }
  1677. },
  1678. loadTaskItemMenuItems: function(){
  1679. var img = this.desktop.path+this.desktop.options.style+"/icons/menu_refresh.png";
  1680. this.taskitemMenu.addMenuItem(o2.LP.desktop.refresh, "click", function(e){this.app.refresh(e);}.bind(this), img);
  1681. this.taskitemMenu.addMenuLine();
  1682. //img = this.path+this.options.style+"/icons/logout.png";
  1683. if (this.app.options.appId!==this.desktop.options.index){
  1684. img = this.desktop.path+this.desktop.options.style+"/icons/menu_close.png";
  1685. this.taskitemMenu.addMenuItem(o2.LP.desktop.close, "click", function(){
  1686. if (!this.app.window){
  1687. this.desktop.apps[this.app.options.appId] = null;
  1688. delete this.desktop.apps[this.app.options.appId];
  1689. this.destroy();
  1690. }else{
  1691. this.app.close();
  1692. }
  1693. }.bind(this), img);
  1694. }
  1695. img = this.desktop.path+this.desktop.options.style+"/icons/menu_closeall.png";
  1696. this.taskitemMenu.addMenuItem(o2.LP.desktop.closeAll, "click", function(){
  1697. var keys = Array.clone(Object.keys(this.desktop.apps));
  1698. keys.each(function(key){
  1699. if (!this.desktop.apps[key].isIndex && !this.desktop.apps[key].options.isIndex) this.desktop.apps[key].close();
  1700. }.bind(this));
  1701. keys = null;
  1702. }.bind(this), img);
  1703. img = this.desktop.path+this.desktop.options.style+"/icons/menu_closeother.png";
  1704. this.taskitemMenu.addMenuItem(o2.LP.desktop.closeOther, "click", function(){
  1705. var keys = Array.clone(Object.keys(this.desktop.apps));
  1706. keys.each(function(key){
  1707. if (!this.desktop.apps[key].isIndex &&
  1708. !this.desktop.apps[key].options.isIndex &&
  1709. this.desktop.apps[key].options.appId!=this.app.options.appId) this.desktop.apps[key].close();
  1710. }.bind(this));
  1711. keys = null;
  1712. }.bind(this), img);
  1713. },
  1714. setText: function(str){
  1715. this.textNode.set("text", str || this.app.options.title);
  1716. },
  1717. unSelected: function(){
  1718. this.node.removeClass("mainColor_bg");
  1719. if (!this.noCloseNode) {
  1720. this.closeNode.addClass("icon_close");
  1721. this.closeNode.removeClass("icon_close_focus");
  1722. //this.closeNode.hide();
  1723. }
  1724. if (this.refreshNode) this.refreshNode.hide();
  1725. if (this.actionNode) this.actionNode.hide();
  1726. },
  1727. selected: function(){
  1728. this.node.addClass("mainColor_bg");
  1729. if (!this.noCloseNode){
  1730. this.closeNode.removeClass("icon_close");
  1731. this.closeNode.addClass("icon_close_focus");
  1732. //this.closeNode.show();
  1733. }
  1734. this.desktop.checkTaskBarScrollTo(this.app);
  1735. //this.refreshNode.show();
  1736. if (this.actionNode) this.actionNode.show();
  1737. },
  1738. destroy: function(){
  1739. this.iconNode.destroy();
  1740. this.node.destroy();
  1741. if (this.desktop && this.desktop.checkTaskBarSize) this.desktop.checkTaskBarSize();
  1742. if (this.app.options && this.app.options.appId) delete this.desktop.apps[this.app.options.appId];
  1743. o2.release(this);
  1744. },
  1745. setTaskitemSize: function(){
  1746. this.desktop.checkTaskBarSize();
  1747. this.desktop.checkTaskBarScrollTo();
  1748. }
  1749. });
  1750. o2.xDesktop.Default.Lnk = new Class({
  1751. initialize: function(layout, data, targetLnk, position){
  1752. this.layout = layout;
  1753. this.container = this.layout.lnkAreaNode;
  1754. this.data = data;
  1755. this.load(targetLnk, position);
  1756. },
  1757. load: function(targetLnk, position){
  1758. this.node = new Element("div.layout_menu_lnk_item");
  1759. if (targetLnk){
  1760. if (!position) position = "before";
  1761. this.node.inject(targetLnk.node, position);
  1762. }else{
  1763. this.node.inject(this.container);
  1764. }
  1765. this.iconNode = new Element("div.layout_menu_lnk_item_icon").inject(this.node);
  1766. this.textNode = new Element("div.layout_menu_lnk_item_text", {"text": this.data.title}).inject(this.node);
  1767. this.actionNode = new Element("div.layout_menu_lnk_item_action", {"title": o2.LP.desktop.deleteLnk}).inject(this.node);
  1768. this.actionNode.addClass("icon_off_light");
  1769. var icon = this.getIcon();
  1770. this.iconNode.setStyle("background-image", "url("+icon+")");
  1771. this.setEvent();
  1772. },
  1773. setEvent: function(){
  1774. this.node.addEvents({
  1775. "click": function(){
  1776. if (this.data.name=="Homepage"){
  1777. var name = this.data.name;
  1778. var options = this.data.options;
  1779. if (layout.config.indexPage && layout.config.indexPage.enable && layout.config.indexPage.portal){
  1780. name = "portal.Portal";
  1781. var appId = "portal.Portal"+layout.config.indexPage.portal;
  1782. options = {"name": "portal.Portal", "portalId": layout.config.indexPage.portal, "pageId": layout.config.indexPage.page, "appId": appId};
  1783. }
  1784. layout.openApplication(null, name, options);
  1785. }else{
  1786. layout.openApplication(null, this.data.name, this.data.options);
  1787. }
  1788. }.bind(this),
  1789. "mouseover": function(){
  1790. this.actionNode.fade("in");
  1791. this.node.addClass("overColor_bg");
  1792. this.textNode.fade("in");
  1793. }.bind(this),
  1794. "mouseout": function(){
  1795. this.actionNode.fade("out");
  1796. this.node.removeClass("overColor_bg");
  1797. this.textNode.fade("out");
  1798. }.bind(this)
  1799. });
  1800. this.actionNode.addEvents({
  1801. "click": function(e){
  1802. this.destroy();
  1803. e.stopPropagation();
  1804. }.bind(this),
  1805. "mouseover": function(){
  1806. this.actionNode.addClass("layout_menu_lnk_item_action_shadow");
  1807. }.bind(this),
  1808. "mouseout": function(){
  1809. this.actionNode.removeClass("layout_menu_lnk_item_action_shadow");
  1810. }.bind(this)
  1811. });
  1812. var drag = new Drag(this.node, {
  1813. "stopPropagation": true,
  1814. "compensateScroll": true,
  1815. "onStart": function(el, e){
  1816. this.doDragMove(e);
  1817. drag.stop();
  1818. }.bind(this)
  1819. });
  1820. },
  1821. getDragNode: function(){
  1822. if (!this.dragNode){
  1823. this.dragNode = new Element("div.layout_menu_lnk_item_drag")
  1824. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  1825. .inject(this.layout.node);
  1826. var dragIconNode = this.iconNode.clone(true).inject(this.dragNode)
  1827. .removeClass("layout_menu_lnk_item_icon")
  1828. .addClass("layout_menu_lnk_item_icon_drag");
  1829. var p = (this.data.appType) ? this.data.appType+"Default" : this.data.name;
  1830. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].color){
  1831. dragIconNode.setStyle("background-color", this.layout.iconsJson[p].color)
  1832. }
  1833. this.dragRemoveNode = new Element("div.layout_menu_lnk_item_icon_drag_del").inject(this.dragNode)
  1834. .addClass("icon_remove_badge")
  1835. .hide();
  1836. }
  1837. var ps = this.iconNode.getPosition(this.dragNode.getOffsetParent());
  1838. this.dragNode.show().setStyles({
  1839. "left": ""+ps.x+"px", "top": ""+ps.y+"px"
  1840. });
  1841. },
  1842. doDragMove: function(e){
  1843. this.getDragNode();
  1844. var drag = new Drag.Move(this.dragNode, {
  1845. "stopPropagation": true,
  1846. "compensateScroll": true,
  1847. "droppables": [this.container.getParent()],
  1848. "onStart": function(){ this._drag_start(); }.bind(this),
  1849. "onDrag": function(dragging,e){ this._drag_drag(dragging, e); }.bind(this),
  1850. "onEnter": function(dragging, inObj){ this._drag_enter(dragging, inObj); }.bind(this),
  1851. "onLeave": function(dragging, obj){ this._drag_leave(dragging, obj); }.bind(this),
  1852. "onDrop": function(dragging, inObj){ this._drag_drop(dragging, inObj); }.bind(this),
  1853. "onCancel": function(dragging){ this._drag_cancel(dragging); }.bind(this),
  1854. "onComplete": function(dragging, e){ this._drag_complete(dragging, e); }.bind(this),
  1855. });
  1856. drag.start(e);
  1857. this.dragStatus = "order";
  1858. },
  1859. _drag_start: function(){
  1860. this.node.addClass("overColor_bg");
  1861. this.node.addClass("opacity50");
  1862. this.dragTargetLnk = null;
  1863. this.dragPosition = "before";
  1864. },
  1865. _drag_drag: function(dragging, e){
  1866. if (this.dragStatus == "order"){
  1867. if (this.layout.lnks && this.layout.lnks.length){
  1868. var current = e.page.y;
  1869. for (var i=0; i<this.layout.lnks.length; i++){
  1870. var lnk = this.layout.lnks[i];
  1871. var y = lnk.node.getSize().y;
  1872. var top = lnk.node.getPosition(this.layout.node).y;
  1873. var center = top+y/2;
  1874. var bottom = top+y;
  1875. if (top<=current && center>=current){
  1876. this.dragTargetLnk = lnk;
  1877. this.dragPosition = "before";
  1878. break;
  1879. }else if (center<=current && bottom>=current){
  1880. this.dragTargetLnk = lnk;
  1881. this.dragPosition = "after";
  1882. break;
  1883. }
  1884. }
  1885. if (!this.layout.positionNode) this.layout.positionNode = new Element("div.layout_menu_lnk_item_position")
  1886. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  1887. .inject(this.layout.node);
  1888. this.layout.positionNode.show();
  1889. if (!this.dragTargetLnk){
  1890. this.dragTargetLnk = this.layout.lnks[this.layout.lnks.length-1];
  1891. this.dragPosition = "after";
  1892. }
  1893. this.layout.positionNode.position({
  1894. relativeTo: this.dragTargetLnk.node,
  1895. position: (this.dragPosition=="before") ? 'topcenter' : 'bottomcenter',
  1896. edge: 'center'
  1897. });
  1898. }
  1899. }
  1900. },
  1901. _drag_enter: function(){
  1902. this.dragStatus = "order";
  1903. if (this.dragRemoveNode) this.dragRemoveNode.hide();
  1904. },
  1905. _drag_leave: function(){
  1906. this.dragStatus = "remove";
  1907. if (this.dragRemoveNode) this.dragRemoveNode.show();
  1908. if (this.layout.positionNode) this.layout.positionNode.hide();
  1909. },
  1910. _drag_drop: function(dragging, inObj){
  1911. if (this.dragStatus == "order" && this.dragTargetLnk && this.dragTargetLnk!=this){
  1912. this.node.inject(this.dragTargetLnk.node, this.dragPosition);
  1913. this.layout.lnks.erase(this);
  1914. var idx = this.layout.lnks.indexOf(this.dragTargetLnk);
  1915. if (this.dragPosition=="before"){
  1916. this.layout.lnks.splice(idx, 0, this);
  1917. }else{
  1918. this.layout.lnks.splice(idx+1, 0, this);
  1919. }
  1920. }
  1921. },
  1922. _drag_cancel: function(dragging){
  1923. dragging.hide();
  1924. if (this.node) {
  1925. this.node.removeClass("overColor_bg");
  1926. this.node.removeClass("opacity50");
  1927. }
  1928. if (this.layout.positionNode) this.layout.positionNode.hide();
  1929. if (this.dragRemoveNode) this.dragRemoveNode.hide();
  1930. },
  1931. _drag_complete: function(dragging){
  1932. if (this.dragStatus == "remove"){
  1933. this.destroy();
  1934. }else{
  1935. this._drag_cancel(dragging);
  1936. }
  1937. },
  1938. destroy: function(){
  1939. this.layout.lnks.erase(this);
  1940. if (this.dragNode) this.dragNode.destroy();
  1941. //if (this.positionNode) this.positionNode.destroy();
  1942. this.node.destroy();
  1943. o2.release(this);
  1944. },
  1945. getIcon: function(){
  1946. if (this.data.icon) return this.data.icon;
  1947. var icon;
  1948. if (this.data.name.substring(0, 4)==="@url"){
  1949. if (this.layout.iconsJson["Url"] && this.layout.iconsJson["Url"].icon){
  1950. icon = this.layout.path+"appicons/"+this.layout.iconsJson["Url"].icon;
  1951. }else{
  1952. icon = this.layout.path+"appicons/url.png";
  1953. }
  1954. }else{
  1955. if (this.data.iconData){
  1956. icon = "data:image/png;base64,"+this.data.iconData+"";
  1957. }else if (this.data.iconPath){
  1958. icon = this.data.iconPath;
  1959. }else{
  1960. var p = (this.data.appType) ? this.data.appType+"Default" : this.data.name;
  1961. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  1962. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  1963. }else{
  1964. icon = "../x_component_"+this.data.name.replace(/\./g, "_")+"/$Main/appicon.png";
  1965. }
  1966. }
  1967. }
  1968. return icon;
  1969. }
  1970. });
  1971. o2.xDesktop.zIndexPool = {
  1972. zIndex: 102,
  1973. applyZindex: function(){
  1974. var i = this.zIndex;
  1975. this.zIndex = this.zIndex+2;
  1976. return i;
  1977. }
  1978. };