Default.js 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808
  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. this.menuData = this.status.menuData;
  265. var keys = Object.keys(this.status.apps);
  266. if (this.status.apps && keys.length){
  267. if (this.status.currentApp == "Note"){
  268. var idx = keys.length-1;
  269. while (idx>-1 && keys[idx]=="Note") idx--;
  270. this.status.currentApp = (idx>-1) ? this.status.apps[keys[idx]].appId : "";
  271. }
  272. var currentTaskitem = null;
  273. Object.each(this.status.apps, function(appStatus, id){
  274. var app = {
  275. "options": appStatus,
  276. "close": function(){
  277. this.taskitem.destroy();
  278. },
  279. "setCurrent": function(){
  280. if (this.taskitem.textNode) this.taskitem.textNode.click();
  281. }
  282. };
  283. taskitem = layout.desktop.createTaskItem(app);
  284. app.taskitem = taskitem;
  285. this.apps[appStatus.appId] = app;
  286. if ((this.status.currentApp === appStatus.appId)) currentTaskitem=taskitem;
  287. }.bind(this));
  288. if (currentTaskitem) {
  289. currentTaskitem.textNode.click();
  290. }
  291. }
  292. if (this.status.widgets){/* nothing to do */}
  293. if (this.status.flatLnks && this.status.flatLnks.length){
  294. this.status.flatLnks.each(function(lnkJson){
  295. this.addLnk(lnkJson);
  296. }.bind(this));
  297. }
  298. }
  299. },
  300. addLnk: function(lnkData, targetLnk, position){
  301. var lnk = new o2.xDesktop.Default.Lnk(this, lnkData, targetLnk, position);
  302. if (targetLnk){
  303. var idx = this.lnks.indexOf(targetLnk);
  304. if (position=="before"){
  305. this.lnks.splice(idx, 0, lnk);
  306. }else{
  307. this.lnks.splice(idx+1, 0, lnk);
  308. }
  309. }else{
  310. this.lnks.push(lnk);
  311. }
  312. },
  313. openWebSocket: function(){
  314. MWF.require("MWF.xDesktop.WebSocket", function(){
  315. this.socket = new MWF.xDesktop.WebSocket();
  316. }.bind(this));
  317. },
  318. closeWebSocket: function(){
  319. if (this.socket) this.socket.close();
  320. },
  321. //******* begin page skin ****************************************************
  322. loadSkinMenu: function(){
  323. if (!this.styleMenu){
  324. this.styleMenu = new o2.xDesktop.Menu(this.skinActionNode, {
  325. "event": "click", "style": "flatStyle", "offsetX": -10, "offsetY": 26, "container": this.node,
  326. "onQueryShow": this.showSkinMenu.bind(this),
  327. "onQueryHide": function(){
  328. this.skinActionNode.removeClass("icon_skin_focus");
  329. this.skinActionNode.removeClass("mainColor_bg");
  330. }.bind(this)
  331. });
  332. this.styleMenu.load();
  333. this.loadSkinMenuItems();
  334. }
  335. },
  336. showSkinMenu: function(){
  337. this.styleMenu.items.each(function(item){
  338. if (this.options.style==item.styleName){
  339. item.setDisable(true);
  340. if (item.text) item.text.setStyles({ "background": "url("+this.path+this.options.style+"/icons/icon_gouxuan.png) right center no-repeat" });
  341. }else{
  342. item.setDisable(false);
  343. if (item.text) item.text.setStyles({ "background": "transparent" });
  344. }
  345. }.bind(this));
  346. this.skinActionNode.addClass("icon_skin_focus");
  347. this.skinActionNode.addClass("mainColor_bg");
  348. },
  349. loadSkinMenuItems: function(){
  350. o2.JSON.get(this.path+"styles.json", function(json){
  351. json.each(function(style){
  352. var color = style.color;
  353. var memuItem = this.styleMenu.addMenuItem(style.title, "click", function(){this.changeLayoutSkin(style.style);}.bind(this));
  354. memuItem.styleName = style.style;
  355. var imgDiv = memuItem.item.getFirst();
  356. var imgNode = new Element("div", {"styles": memuItem.menu.css.menuItemImg}).inject(imgDiv);
  357. imgNode.setStyle("background-color", color);
  358. }.bind(this));
  359. this.styleMenu.addMenuLine();
  360. var img = o2.defaultPath+"/xDesktop/$Layout/default/preview.jpg";
  361. var memuItem = this.styleMenu.addMenuItem(o2.LP.desktop_style, "click", function(e){this.changeToDesktopStyle(e);}.bind(this), img);
  362. memuItem.styleName = "desktop";
  363. }.bind(this));
  364. },
  365. changeLayoutSkin: function(style){
  366. var skinCss = this.path+this.options.style+ "/style-skin.css";
  367. o2.removeCss(skinCss);
  368. this.options.style = style;
  369. skinCss = this.path+this.options.style+"/style-skin.css";
  370. this.node.loadCss(skinCss);
  371. },
  372. changeToDesktopStyle: function(e){
  373. //MWF.xDesktop.confirm("infor", e, o2.LP.desktop.changeViewTitle, {"html": o2.LP.desktop.changeView}, 500, 100, function(){
  374. // this.close();
  375. var uri = new URI(window.location.href);
  376. uri.setData("view", "layout");
  377. uri.go();
  378. // }, function(){
  379. // this.close();
  380. // }, null, null, "o2"
  381. // );
  382. },
  383. //******* end page skin ****************************************************
  384. //******* begin user menu ****************************************************
  385. loadUserMenu: function(){
  386. if (!this.userMenu){
  387. this.userMenu = new o2.xDesktop.Menu(this.userInforNode, {
  388. "event": "click", "style": "flatUser", "offsetX": 30, "offsetY":6, "container": this.node
  389. // "onQueryShow": this.showSkinMenu.bind(this),
  390. // "onQueryHide": function(){
  391. // this.skinActionNode.removeClass("icon_skin_focus");
  392. // this.skinActionNode.removeClass("mainColor_bg");
  393. // }.bind(this),
  394. });
  395. this.userMenu.load();
  396. this.loadUserMenuItems();
  397. }
  398. },
  399. loadUserMenuItems: function(){
  400. var img = this.path+this.options.style+"/icons/config.png";
  401. this.userMenu.addMenuItem(o2.LP.desktop.userConfig, "click", function(e){this.userConfig(e);}.bind(this), img);
  402. this.userMenu.addMenuLine();
  403. img = this.path+this.options.style+"/icons/logout.png";
  404. this.userMenu.addMenuItem(o2.LP.desktop.logout, "click", function(){this.logout();}.bind(this), img);
  405. },
  406. userConfig: function(e){
  407. layout.openApplication(e, "Profile");
  408. },
  409. logout: function(){
  410. this.isLogout = true;
  411. if (!this.notRecordStatus){
  412. this.recordDesktopStatus(function(){
  413. (layout.authentication || new o2.xDesktop.Authentication()).logout();
  414. }.bind(this.layout));
  415. }else{
  416. (layout.authentication || new o2.xDesktop.Authentication()).logout();
  417. }
  418. },
  419. //******* end user menu ****************************************************
  420. //******* begin search *****************************************************
  421. focusSearch: function(){
  422. this.searchBoxNode.addClass("layout_content_taskbar_area_search_box_focus");
  423. this.searchBoxNode.addClass("mainColor_border");
  424. this.searchIconNode.addClass("icon_search_focus");
  425. },
  426. blurSearch: function(){
  427. this.searchBoxNode.removeClass("layout_content_taskbar_area_search_box_focus");
  428. this.searchBoxNode.removeClass("mainColor_border");
  429. this.searchIconNode.removeClass("icon_search_focus");
  430. },
  431. searchInputKeyDown: function(e){
  432. if (this.searchInputNode.get("value")){
  433. this.searchClearNode.addClass("icon_clear");
  434. }else{
  435. this.searchClearNode.removeClass("icon_clear");
  436. }
  437. if (e.keyCode===13) this.doSearch();
  438. },
  439. clearSearch: function(){
  440. this.searchInputNode.set("value", "");
  441. this.searchClearNode.removeClass("icon_clear");
  442. this.clearSearchResult();
  443. },
  444. doSearch: function(){
  445. var key = this.searchInputNode.get("value");
  446. if (key){
  447. if (this.apps["Search"]){
  448. this.apps["Search"].input.setValue(key);
  449. this.apps["Search"].input.doSearch();
  450. }
  451. layout.openApplication(null,"Search", {"key": key});
  452. }
  453. },
  454. clearSearchResult: function(){
  455. //alert("clear search result");
  456. // @todo
  457. },
  458. //******* end search*******************************************************
  459. //******* begin record status *********************************************
  460. recordDesktopStatus: function(callback){
  461. Object.each(this.apps, function(app, id){
  462. if (!app.options.desktopReload){
  463. this.closeApp(app);
  464. }
  465. }.bind(this));
  466. var status = this.getLayoutStatusData();
  467. // if (navigator.sendBeacon) {
  468. // var obj = this.personalAction.action.actions["putUserData"];
  469. // var url = this.personalAction.action.address + obj.uri;
  470. // url = url.replace("{name}", "layout");
  471. // navigator.sendBeacon(url, status);
  472. // } else {
  473. try{
  474. o2.UD.putData("layout", status, function(){
  475. if (callback) callback();
  476. });
  477. }catch(e){};
  478. // }
  479. },
  480. getLayoutStatusData: function(){
  481. var status = {
  482. "viewMode": "Default",
  483. "style": this.status.style,
  484. "flatStyle": this.options.style,
  485. "styleType": this.status.styleType || "",
  486. "currentApp": (this.currentApp) ? this.currentApp.appId : "Homepage",
  487. "apps": {},
  488. "lnks": (this.status.lnks && o2.typeOf(this.status.lnks)==="array") ? this.status.lnks : [],
  489. //"lnks": [],
  490. "flatLnks": [],
  491. "widgets": {},
  492. "menuData": this.menuData
  493. };
  494. // this.appArr.each(function(app){
  495. // if (app.options.appId!==this.options.index){
  496. // var appStatus = this.getAppStatusData(app, app.appId);
  497. // if (appStatus) status.apps[id] = appStatus;
  498. // }
  499. // }.bind(this));
  500. Object.each(this.apps, function(app, id){
  501. if (app.options.appId!==this.options.index){
  502. var appStatus = this.getAppStatusData(app, id);
  503. if (appStatus) status.apps[id] = appStatus;
  504. }
  505. if (app.isIndex){
  506. if (!status.apps[id]) status.apps[id] = {};
  507. status.apps[id].isIndex = true;
  508. }
  509. }.bind(this));
  510. this.lnks.each(function(lnk){
  511. status.flatLnks.push(lnk.data);
  512. //status.flatLnks.push({"icon": lnk.icon, "color": lnk.color, "title": lnk.title,"par": lnk.par});
  513. });
  514. Object.each(this.widgets, function(widget, id){
  515. var widgetStatus = this.getWidgetStatusData(widget, id);
  516. if (widgetStatus) status.widgets[id] = widgetStatus;
  517. }.bind(this));
  518. return status;
  519. },
  520. getAppStatusData: function(app, id){
  521. var appStatus = null;
  522. if (app.window){
  523. if (app.options.desktopReload){
  524. appStatus ={
  525. "appId": app.appId,
  526. "name": app.options.name,
  527. "style": app.options.style,
  528. "title": app.options.title,
  529. "window": {
  530. // //"size": app.window.node.getSize(),
  531. // "size": {"x": app.window.css.to.width.toFloat(), "y": app.window.css.to.height.toFloat()},
  532. // "position": {"x": app.window.css.to.left.toFloat(), "y": app.window.css.to.top.toFloat()},
  533. // "isMax": app.window.isMax,
  534. // "isHide": app.window.isHide,
  535. // "style": app.window.options.style
  536. },
  537. "app": null
  538. };
  539. if (app.recordStatus) appStatus.app = app.recordStatus();
  540. }
  541. }else{
  542. if (app.options){
  543. appStatus = app.options;
  544. }
  545. }
  546. return appStatus;
  547. },
  548. getWidgetStatusData: function(widget, id){
  549. var widgetStatus ={
  550. "name": widget.options.name,
  551. "appName": widget.options.appName,
  552. "position": widget.options.position,
  553. "widget": null
  554. };
  555. if (widget.recordStatus) widgetStatus.widget = widget.recordStatus();
  556. return widgetStatus;
  557. },
  558. //******* end record status ***********************************************
  559. //******* begin start menu ************************************************
  560. showStartMenu: function(){
  561. this.loadStartMenu(function(){
  562. if (!this.startMenu.isShow){
  563. this.startMenuNode.addClass("overColor_bg");
  564. this.startMenu.show();
  565. }
  566. }.bind(this));
  567. },
  568. loadStartMenu: function(callback){
  569. if (!this.startMenu){
  570. this.startMenu = new o2.xDesktop.Default.StartMenu(this);
  571. this.startMenu.addEvents({
  572. "onHide": function(){
  573. this.startMenuNode.removeClass("overColor_bg");
  574. }.bind(this),
  575. "onLoad": function(){
  576. if (callback) callback();
  577. }
  578. });
  579. this.startMenu.load();
  580. }else{
  581. if (this.startMenu.isLoaded) if (callback) callback();
  582. }
  583. },
  584. //******* end start menu **************************************************
  585. //******* begin message menu **********************************************
  586. showDesktopMessage: function(){
  587. if (!this.message){
  588. this.loadMessageMenu(function(){
  589. this.showMessage();
  590. }.bind(this));
  591. }else{
  592. this.showMessage();
  593. }
  594. },
  595. loadMessageMenu: function(callback){
  596. o2.require("o2.xDesktop.MessageV2", function(){
  597. this.message = new o2.xDesktop.MessageV2(this);
  598. this.message.addEvents({
  599. "onLoad": function(){ if (callback) callback(); }.bind(this),
  600. "onHide": function(){
  601. this.msgActionNode.removeClass("icon_msg_focus");
  602. this.msgActionNode.removeClass("mainColor_bg");
  603. }.bind(this),
  604. });
  605. this.message.load();
  606. }.bind(this));
  607. },
  608. showMessage: function(){
  609. if (!this.message.isShow){
  610. this.msgActionNode.addClass("icon_msg_focus");
  611. this.msgActionNode.addClass("mainColor_bg");
  612. this.message.show();
  613. }
  614. },
  615. //******* end message menu ************************************************
  616. //******* begin task item *************************************************
  617. createTaskItem: function(app){
  618. return new o2.xDesktop.Default.TaskItem(this, app);
  619. },
  620. //******* end task item ***************************************************
  621. closeApp: function(app, hasTaskitem) {
  622. var appId = app.appId;
  623. this.appCurrentList.erase(app);
  624. this.appArr.erase(app);
  625. this.apps[appId] = null;
  626. delete this.apps[appId];
  627. if (!hasTaskitem){
  628. var i = this.appCurrentList.length;
  629. if (i && this.appCurrentList[i-1]){
  630. this.appCurrentList[i-1].setCurrent();
  631. }else{
  632. var keys = Object.keys(this.apps);
  633. i = keys.length;
  634. if (i && this.apps[keys[i-1]] && this.apps[keys[i-1]].setCurrent){
  635. this.apps[keys[i-1]].setCurrent();
  636. }else{
  637. //if (app.appId!=="Homepage") layout.openApplication(null, "Homepage");
  638. layout.openApplication(null, "Homepage");
  639. }
  640. }
  641. this.checkTaskBarSize();
  642. this.checkTaskBarScrollTo();
  643. }
  644. },
  645. refreshApp:function(app){
  646. if (app.window){
  647. var taskitem = app.taskitem;
  648. var appStatus ={
  649. "id": app.appId,
  650. "name": app.options.name,
  651. "style": app.options.style,
  652. "appId": app.appId
  653. };
  654. var status = (app.recordStatus) ? app.recordStatus() : null;
  655. app.close(true);
  656. layout.openApplication(null, appStatus.name, appStatus, status, false, taskitem);
  657. //this.openApplicationWithStatus(appStatus);
  658. }
  659. },
  660. getPageDesignerStyle: function(callback){
  661. if (!this.pageDesignerStyle){
  662. this.pageDesignerStyle = "default";
  663. MWF.UD.getData("pageDesignerStyle", function(json) {
  664. if (json.data) {
  665. var styles = JSON.decode(json.data);
  666. this.pageDesignerStyle = styles.style;
  667. }
  668. if (callback) callback();
  669. }.bind(this));
  670. }else{
  671. if (callback) callback();
  672. }
  673. },
  674. getFormDesignerStyle: function(callback){
  675. if (!this.formDesignerStyle){
  676. this.formDesignerStyle = "default";
  677. MWF.UD.getData("formDesignerStyle", function(json) {
  678. if (json.data) {
  679. var styles = JSON.decode(json.data);
  680. this.formDesignerStyle = styles.style;
  681. }
  682. if (callback) callback();
  683. }.bind(this));
  684. }else{
  685. if (callback) callback();
  686. }
  687. },
  688. createRefreshNode: function(){
  689. this.refreshNode = new Element("div.layout_refresh_node.icon_refresh").inject(this.desktopNode);
  690. this.refreshNode.set("morph", {
  691. "duration": 100,
  692. "transition": Fx.Transitions.Quart.easeOut
  693. });
  694. this.refreshNode.addEvent("click", function(){
  695. if (this.currentApp) this.currentApp.refresh();
  696. this.hideRefresh();
  697. }.bind(this));
  698. },
  699. showRefresh: function(){
  700. if (!this.refreshNodeShow){
  701. if (!this.refreshNode) this.createRefreshNode();
  702. var size = this.taskbarNode.getSize();
  703. var nodeSize = this.refreshNode.getSize();
  704. var top = size.y;
  705. var left = size.x/2-nodeSize.x/2;
  706. this.refreshNode.setStyles({
  707. "left": left,
  708. "top": 0-nodeSize.y,
  709. "opacity": 0
  710. });
  711. this.refreshNode.morph({
  712. "top": top,
  713. "left": left,
  714. "opacity": 0.9
  715. });
  716. this.refreshNodeShow = true;
  717. this.refreshTimeoutId = window.setTimeout(function(){
  718. this.hideRefresh();
  719. }.bind(this), 2000);
  720. }
  721. },
  722. hideRefresh: function(){
  723. if (this.refreshNodeShow){
  724. if (this.refreshNode){
  725. var size = this.taskbarNode.getSize();
  726. var nodeSize = this.refreshNode.getSize();
  727. var top = size.y;
  728. var left = size.x/2-nodeSize.x/2;
  729. this.refreshNode.morph({
  730. "top": 0-nodeSize.y,
  731. "left": left,
  732. "opacity": 0
  733. });
  734. window.setTimeout(function(){
  735. this.refreshNodeShow = false;
  736. }.bind(this), 100);
  737. }
  738. }
  739. if (this.refreshTimeoutId){
  740. window.clearTimeout(this.refreshTimeoutId);
  741. this.refreshTimeoutId = "";
  742. }
  743. }
  744. });
  745. o2.xDesktop.Default.StartMenu = new Class({
  746. Implements: [Events],
  747. initialize: function(layout){
  748. this.layout = layout;
  749. this.container = this.layout.startMenuArea;
  750. this.actionNode = this.layout.startMenuNode;
  751. this.isLoaded = false;
  752. this.isShow = false;
  753. this.isMorph = false;
  754. this.items = [];
  755. this.menuData = (this.layout.status && this.layout.status.menuData) ? this.layout.status.menuData : {
  756. "appList": [],
  757. "processList": [],
  758. "inforList": [],
  759. "queryList": []
  760. };
  761. this.itemTempletedHtml = "" +
  762. " <div class='layout_start_item_iconArea'>" +
  763. " <div class='layout_start_item_icon'></div>" +
  764. " </div>" +
  765. " <div class='layout_start_item_text'></div>"+
  766. " <div class='layout_start_item_badge'></div>";
  767. },
  768. load: function(){
  769. var view = this.layout.path+this.layout.options.style+((o2.session.isMobile || layout.mobile) ? "/layout-menu-mobile.html" : "/layout-menu-pc.html");
  770. this.container.loadHtml(view, {"module": this}, function(){
  771. this.maskNode.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  772. this.node.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  773. this.layout.menuNode.setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex());
  774. this.node.addEvent("mousedown", function(e){
  775. e.stopPropagation();
  776. e.preventDefault();
  777. });
  778. this.triangleNode = new Element("div.layout_menu_start_triangle").inject(this.layout.menuNode, "after");
  779. this.hideMessage = function(){ this.hide(); }.bind(this);
  780. this.fireEvent("load");
  781. this.layout.addEvent("resize", this.setSize.bind(this));
  782. this.loadTitle();
  783. this.loadLnks();
  784. this.isLoaded = true;
  785. this.fireEvent("load");
  786. }.bind(this));
  787. },
  788. resetMenuData: function(){
  789. if (!this.menuData) this.menuData = {
  790. "appList": [],
  791. "processList": [],
  792. "inforList": [],
  793. "queryList": []
  794. }
  795. var nodes = this.appContentNode.getChildren();
  796. var data = [];
  797. nodes.each(function(node){
  798. var item = node.retrieve("item");
  799. if (item){
  800. if (item.data.type==="group"){
  801. var d = {
  802. "id": item.data.id,
  803. "name": item.data.name,
  804. "type": item.data.type,
  805. "itemDataList": []
  806. }
  807. if (item.data.itemDataList) item.data.itemDataList.each(function(i){
  808. d.itemDataList.push(i);
  809. });
  810. data.push(d);
  811. }else{
  812. data.push({
  813. "id": item.data.id,
  814. "name": item.data.name,
  815. "type": item.data.type,
  816. });
  817. }
  818. }
  819. }.bind(this));
  820. if (this.currentTab === this.appCategoryTab){
  821. this.menuData.appList = data;
  822. }else if (this.currentTab === this.processCategoryTab){
  823. this.menuData.processList = data;
  824. }else if (this.currentTab === this.inforCategoryTab){
  825. this.menuData.inforList = data;
  826. }else if (this.currentTab === this.queryCategoryTab){
  827. this.menuData.queryList = data;
  828. }
  829. this.layout.menuData = this.menuData;
  830. },
  831. setScroll: function(){
  832. o2.require("o2.widget.ScrollBar", function(){
  833. this.appScrollBar = new o2.widget.ScrollBar(this.appScrollNode, {
  834. "style":"xDesktop_Message", "where": "before", "indent": false, "distance": 100, "friction": 6, "axis": {"x": false, "y": true}
  835. });
  836. }.bind(this));
  837. },
  838. loadTitle: function(){
  839. this.lnkTitleNode.set("text", o2.LP.desktop.lnkAppTitle);
  840. this.appCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.application}).inject(this.appTitleNode);
  841. this.processCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.process}).inject(this.appTitleNode);
  842. this.inforCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.infor}).inject(this.appTitleNode);
  843. this.queryCategoryTab = new Element("div.layout_start_tab", {"text": o2.LP.desktop.message.query}).inject(this.appTitleNode);
  844. this.searchNode = new Element("div.layout_start_search").inject(this.appTitleNode);
  845. this.searchIconNode = new Element("div.layout_start_search_icon").inject(this.searchNode);
  846. this.searchIconNode.addClass("icon_startMenu_search");
  847. var currentWidth = this.searchNode.getSize().x;
  848. this.searchNode.store("currentWidth", currentWidth);
  849. this.appCategoryTab.addEvent("click", function(){
  850. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  851. this.appCategoryTab.addClass("mainColor_bg");
  852. this.currentTab = this.appCategoryTab;
  853. this.loadApplications();
  854. }.bind(this));
  855. this.processCategoryTab.addEvent("click", function(){
  856. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  857. this.processCategoryTab.addClass("mainColor_bg");
  858. this.currentTab = this.processCategoryTab;
  859. this.loadProcesses();
  860. }.bind(this));
  861. this.inforCategoryTab.addEvent("click", function(){
  862. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  863. this.inforCategoryTab.addClass("mainColor_bg");
  864. this.currentTab = this.inforCategoryTab;
  865. this.loadInfors();
  866. }.bind(this));
  867. this.queryCategoryTab.addEvent("click", function(){
  868. this.appTitleNode.getElements(".layout_start_tab").removeClass("mainColor_bg");
  869. this.queryCategoryTab.addClass("mainColor_bg");
  870. this.currentTab = this.queryCategoryTab;
  871. this.loadQuerys();
  872. }.bind(this));
  873. this.searchIconNode.addEvent("click", this.searchIconAction.bind(this));
  874. },
  875. searchIconAction: function(){
  876. if (!this.isMorph){
  877. if (this.isSearch){
  878. this.doSearch();
  879. }else{
  880. this.loadSearch()
  881. }
  882. }
  883. },
  884. loadSearch: function(){
  885. this.isSearch = true;
  886. this.searchNode.addClass("mainColor_border");
  887. this.appCategoryTab.hide();
  888. this.processCategoryTab.hide();
  889. this.inforCategoryTab.hide();
  890. this.queryCategoryTab.hide();
  891. var size = this.appTitleNode.getSize();
  892. var pr = this.appTitleNode.getStyle("padding-right").toInt() || 0;
  893. var pl = this.appTitleNode.getStyle("padding-left").toInt() || 0;
  894. var margin = this.searchNode.getStyle("margin-right").toInt() || 0;
  895. var w = size.x-margin*2-pr-pl;
  896. this.isMorph = true;
  897. this.searchNode.set("morph", {"duration": 200});
  898. this.searchNode.morph({"width": ""+w+"px"});
  899. window.setTimeout(function(){
  900. this.isMorph = false;
  901. }.bind(this), 220);
  902. if (!this.searchClearNode){
  903. this.searchClearNode = new Element("div.layout_start_search_clear").inject(this.searchNode);
  904. this.searchClearNode.addClass("icon_clear");
  905. this.searchClearNode.addEvent("click", this.hideSearch.bind(this));
  906. }
  907. this.searchClearNode.show();
  908. if (!this.searchAreaNode) this.searchAreaNode = new Element("div.layout_start_search_area").inject(this.searchNode);
  909. this.searchAreaNode.show();
  910. if (!this.searchInputNode){
  911. this.searchInputNode = new Element("input.layout_start_search_input", {"placeholder": o2.LP.searchKey}).inject(this.searchAreaNode);
  912. this.searchInputNode.addEvent("keydown", function(e){
  913. if (e.code==13) this.doSearch();
  914. }.bind(this));
  915. }
  916. this.searchInputNode.show();
  917. this.searchInputNode.focus();
  918. //this.searchNode.addClass("layout_start_search_load");
  919. },
  920. hideSearch: function(){
  921. if (this.isSearch){
  922. if (this.searchInputNode){
  923. this.searchInputNode.set("value", "");
  924. this.searchInputNode.hide();
  925. }
  926. if (this.searchAreaNode) this.searchAreaNode.hide();
  927. if (this.searchClearNode) this.searchClearNode.hide();
  928. this.isMorph = true;
  929. var currentWidth = this.searchNode.retrieve("currentWidth");
  930. this.searchNode.morph({"width": ""+currentWidth+"px"});
  931. window.setTimeout(function(){
  932. if (this.currentTab && this.isSearchResult) this.currentTab.click();
  933. this.searchNode.removeClass("mainColor_border");
  934. this.appCategoryTab.show();
  935. this.processCategoryTab.show();
  936. this.inforCategoryTab.show();
  937. this.queryCategoryTab.show();
  938. this.isSearch = false;
  939. this.isMorph = false;
  940. this.isSearchResult = false;
  941. }.bind(this), 220);
  942. }
  943. },
  944. doSearch: function(){
  945. var key = this.searchInputNode.get("value").toLowerCase();
  946. if (key){
  947. this.isSearchResult = true;
  948. this.appContentNode.empty();
  949. this.searchApplicatins(key);
  950. this.searchProcesses(key);
  951. this.searchInfors(key);
  952. this.searchQuerys(key);
  953. }
  954. },
  955. searchApplicatins: function(value){
  956. // var user = this.layout.session.user;
  957. // // var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  958. // // if (user.roleList) currentNames = currentNames.concat(user.roleList);
  959. // // if (user.groupList) currentNames = currentNames.concat(user.groupList);
  960. this.getCurrentName( function (currentNames) {
  961. if (this.layoutJson && this.layoutJson.length) this.layoutJson.each(function(v){
  962. if ( this.checkMenuItem(v, currentNames) ){
  963. if ((v.title.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.title.toPY().toLowerCase().indexOf(value)!==-1) || (v.title.indexOf(value)!==-1)){
  964. this.createApplicationMenuItem(v);
  965. }
  966. }
  967. }.bind(this));
  968. if (this.componentJson && this.componentJson.length) this.componentJson.each(function(v){
  969. if ( this.checkMenuItem(v, currentNames) ){
  970. if ((v.title.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.title.toPY().toLowerCase().indexOf(value)!==-1) || (v.title.indexOf(value)!==-1)){
  971. this.createApplicationMenuItem(v);
  972. }
  973. }
  974. }.bind(this));
  975. if (this.portalJson && this.portalJson.length) this.portalJson.each(function(v){
  976. if ((v.name.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.name.toPY().toLowerCase().indexOf(value)!==-1) || (v.name.indexOf(value)!==-1)){
  977. this.createPortalMenuItem(v);
  978. }
  979. }.bind(this));
  980. })
  981. },
  982. searchProcesses: function(value){
  983. if (this.processJson && this.processJson.length) this.processJson.each(function(v){
  984. if ((v.name.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.name.toPY().toLowerCase().indexOf(value)!==-1) || (v.name.indexOf(value)!==-1)){
  985. this.createProcessMenuItem(v);
  986. }
  987. }.bind(this));
  988. },
  989. searchInfors: function(value){
  990. if (this.inforJson && this.inforJson.length) this.inforJson.each(function(v){
  991. if ((v.appName.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.appName.toPY().toLowerCase().indexOf(value)!==-1) || (v.appName.indexOf(value)!==-1)){
  992. this.createInforMenuItem(v);
  993. }
  994. }.bind(this));
  995. },
  996. searchQuerys: function(value){
  997. if (this.queryJson && this.queryJson.length) this.queryJson.each(function(v){
  998. if ((v.name.toPYFirst().toLowerCase().indexOf(value)!==-1) || (v.name.toPY().toLowerCase().indexOf(value)!==-1) || (v.name.indexOf(value)!==-1)){
  999. this.createQueryMenuItem(v);
  1000. }
  1001. }.bind(this));
  1002. },
  1003. loadJsons: function(callback){
  1004. this.clearAppContentNode();
  1005. this.loadLayoutApplications(function(json_layout){
  1006. var componentAction = o2.Actions.get("x_component_assemble_control");
  1007. var portalAction = o2.Actions.get("x_portal_assemble_surface");
  1008. var processAction = o2.Actions.get("x_processplatform_assemble_surface");
  1009. var inforAction = o2.Actions.get("x_cms_assemble_control");
  1010. var queryAction = o2.Actions.get("x_query_assemble_surface");
  1011. var iconsPath = this.layout.path+"icons.json";
  1012. this.getIconsJson(function(){
  1013. o2.Actions.invokeAsync([
  1014. {"action": componentAction, "name": "listComponent"},
  1015. {"action": portalAction, "name": "listApplication"},
  1016. {"action": processAction, "name": "listApplication"},
  1017. {"action": inforAction, "name": "listColumn"},
  1018. {"action": queryAction, "name": "listQuery"},
  1019. ], {"success": function(json_component, json_portal, json_process, json_infor, json_query){
  1020. this.layoutJson = json_layout;
  1021. this.componentJson = json_component.data;
  1022. this.portalJson = json_portal.data;
  1023. this.processJson = json_process.data;
  1024. this.inforJson = json_infor.data;
  1025. this.queryJson = json_query.data;
  1026. if (callback) callback();
  1027. }.bind(this), "failure": function(){}}
  1028. );
  1029. }.bind(this));
  1030. }.bind(this));
  1031. },
  1032. getIconsJson: function(callback){
  1033. if (this.layout.iconsJson){
  1034. if (callback) callback();
  1035. }else{
  1036. o2.JSON.get(iconsPath, function(json){
  1037. this.layout.iconsJson = json;
  1038. if (callback) callback();
  1039. }.bind(this));
  1040. }
  1041. },
  1042. setPosition: function(){
  1043. //var size = this.container.getSize();
  1044. var index = o2.xDesktop.zIndexPool.zIndex;
  1045. var nodeSize = this.node.getSize();
  1046. var left = 0-nodeSize.x;
  1047. this.maskNode.setStyles({"left": ""+left+"px"});
  1048. this.node.setStyles({"left": ""+left+"px"});
  1049. },
  1050. setSize: function(){
  1051. if (this.appScrollBar && this.appScrollBar.scrollVNode) this.appScrollBar.scrollVNode.setStyle("margin-top", "0px");
  1052. var isLnk = false;
  1053. if (false && this.layout.lnks && this.layout.lnks.length){
  1054. this.lnkAreaNode.show();
  1055. this.lineNode.show();
  1056. var h = 100*3;
  1057. this.lnkScrollNode.setStyle("height", ""+h+"px");
  1058. isLnk = true;
  1059. }else{
  1060. this.lnkAreaNode.hide();
  1061. this.lineNode.hide();
  1062. }
  1063. var size = this.node.getSize();
  1064. var lnkSizeY = (isLnk) ? this.lnkAreaNode.getSize().y : 0;
  1065. var lineSizeY = (isLnk) ? this.lineNode.getSize().y : 0;
  1066. var mt = (isLnk) ? (this.lineNode.getStyle("margin-top").toInt() || 0) : 0;
  1067. var mb = (isLnk) ? (this.lineNode.getStyle("margin-bottom").toInt() || 0) : 0;
  1068. var titleSize = this.appTitleNode.getSize();
  1069. var y = size.y-lnkSizeY-lineSizeY-mt-mb-titleSize.y;
  1070. this.appScrollNode.setStyle("height", ""+y+"px");
  1071. },
  1072. loadLnks: function(){
  1073. // if (this.layout.lnks && this.layout.lnks.length){
  1074. // this.lnkAreaNode.show();
  1075. // this.lineNode.show();
  1076. // this.lnkContentNode.empty();
  1077. // this.createLnkMenuItem();
  1078. // }else{
  1079. this.lnkAreaNode.hide();
  1080. this.lineNode.hide();
  1081. //}
  1082. },
  1083. createLnkMenuItem: function(){
  1084. //this.templetedHtml
  1085. },
  1086. clearAppContentNode: function(){
  1087. this.appContentNode.empty();
  1088. this.appContentNode.addClass("icon_loading");
  1089. },
  1090. loadApplications: function(callback){
  1091. this.clearAppContentNode();
  1092. // this.loadLayoutApplications(function(json_layout){
  1093. // var componentAction = o2.Actions.get("x_component_assemble_control");
  1094. // var portalAction = o2.Actions.get("x_portal_assemble_surface");
  1095. // o2.Actions.invokeAsync([
  1096. // {"action": componentAction, "name": "listComponent"},
  1097. // {"action": portalAction, "name": "listApplication"},
  1098. // ], {"success": function(json_component, json_portal){
  1099. // this.loadApplicationsItem(json_layout, json_component.data, json_portal.data);
  1100. // }.bind(this), "failure": function(){}}
  1101. // );
  1102. // }.bind(this));
  1103. this.loadApplicationsItem(this.layoutJson, this.componentJson, this.portalJson);
  1104. },
  1105. loadLayoutApplications: function(callback){
  1106. var url = this.layout.path+"applications.json";
  1107. o2.getJSON(url, function(json){
  1108. if (callback) callback(json);
  1109. }.bind(this));
  1110. },
  1111. loadApplicationsItem: function(layoutJson, componentJson, portalJson){
  1112. debugger;
  1113. var user = this.layout.session.user;
  1114. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  1115. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  1116. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  1117. var json_layout = Array.clone(layoutJson);
  1118. var json_component = Array.clone(componentJson);
  1119. var json_portal = Array.clone(portalJson);
  1120. this.appContentNode.removeClass("icon_loading");
  1121. var loadedApps = {};
  1122. if (this.menuData && this.menuData.appList && this.menuData.appList.length){
  1123. this.menuData.appList.each(function(app){
  1124. if (app.type==="group"){
  1125. this.createGroupMenuItem(app);
  1126. app.itemDataList.each(function(a){
  1127. var d = json_layout.find(function(i){ return (i.id === a.id); });
  1128. if (d) json_layout.erase(d);
  1129. d = json_component.find(function(i){ return (i.id === a.id); });
  1130. if (d) json_component.erase(d);
  1131. d = json_portal.find(function(i){ return (i.id === a.id); });
  1132. if (d) json_portal.erase(d);
  1133. }.bind(this));
  1134. }else{
  1135. var appData = null;
  1136. if (!appData && json_layout && json_layout.length){
  1137. appData = json_layout.find(function(i){ return (i.id === app.id); });
  1138. if (appData){
  1139. json_layout.erase(appData);
  1140. if ( this.checkMenuItem(appData, currentNames) ) this.createApplicationMenuItem(appData);
  1141. }
  1142. }
  1143. if (!appData && json_component && json_component.length){
  1144. appData = json_component.find(function(i){ return (i.id === app.id); });
  1145. if (appData){
  1146. json_component.erase(appData);
  1147. if ( this.checkMenuItem(appData, currentNames) ) this.createApplicationMenuItem(appData);
  1148. }
  1149. }
  1150. if (!appData && json_portal && json_portal.length){
  1151. appData = json_portal.find(function(i){ return (i.id === app.id); });
  1152. if (appData){
  1153. json_portal.erase(appData);
  1154. appData.type = "portal";
  1155. this.createPortalMenuItem(appData);
  1156. }
  1157. }
  1158. }.bind(this));
  1159. }
  1160. if (json_layout && json_layout.length) json_layout.each(function(value){
  1161. if ( this.checkMenuItem(value, currentNames) ) this.createApplicationMenuItem(value);
  1162. }.bind(this));
  1163. if (json_component && json_component.length) json_component.each(function(value){
  1164. if ( this.checkMenuItem(value, currentNames) ) this.createApplicationMenuItem(value);
  1165. }.bind(this));
  1166. if (json_portal && json_portal.length) json_portal.each(function(value){
  1167. this.createPortalMenuItem(value);
  1168. }.bind(this));
  1169. if (json_portal && json_portal.length) json_portal.each(function(value){
  1170. value.type = "portal";
  1171. this.createPortalMenuItem(value);
  1172. }.bind(this));
  1173. },
  1174. loadProcesses: function(){
  1175. this.clearAppContentNode();
  1176. // o2.Actions.get("x_processplatform_assemble_surface").listApplication(this.loadProcessesItem.bind(this));
  1177. this.loadProcessesItem(this.processJson)
  1178. },
  1179. loadProcessesItem: function(list){
  1180. this.appContentNode.removeClass("icon_loading");
  1181. var json = Array.clone(list);
  1182. if (this.menuData && this.menuData.processList && this.menuData.processList.length){
  1183. this.menuData.processList.each(function(app){
  1184. if (app.type==="group"){
  1185. this.createGroupMenuItem(app);
  1186. app.itemDataList.each(function(a){
  1187. var d = json.find(function(i){ return (i.id === a.id); });
  1188. if (d) json.erase(d);
  1189. }.bind(this));
  1190. }else{
  1191. var appData = null;
  1192. if (!appData && json && json.length){
  1193. appData = json.find(function(i){ return (i.id === app.id); });
  1194. if (appData){
  1195. json.erase(appData);
  1196. appData.type = "process";
  1197. this.createProcessMenuItem(appData);
  1198. }
  1199. }
  1200. }
  1201. }.bind(this));
  1202. }
  1203. if (json && json.length) json.each(function(value){
  1204. value.type = "process";
  1205. this.createProcessMenuItem(value);
  1206. }.bind(this));
  1207. },
  1208. loadInfors: function(){
  1209. this.clearAppContentNode();
  1210. //o2.Actions.get("x_cms_assemble_control").listColumn(this.loadInforsItem.bind(this));
  1211. this.loadInforsItem(this.inforJson)
  1212. },
  1213. loadInforsItem: function(list){
  1214. this.appContentNode.removeClass("icon_loading");
  1215. var json = Array.clone(list);
  1216. if (this.menuData && this.menuData.inforList && this.menuData.inforList.length){
  1217. this.menuData.inforList.each(function(app){
  1218. if (app.type==="group"){
  1219. this.createGroupMenuItem(app);
  1220. app.itemDataList.each(function(a){
  1221. var d = json.find(function(i){ return (i.id === a.id); });
  1222. if (d) json.erase(d);
  1223. }.bind(this));
  1224. }else{
  1225. var appData = null;
  1226. if (!appData && json && json.length){
  1227. appData = json.find(function(i){ return (i.id === app.id); });
  1228. if (appData){
  1229. json.erase(appData);
  1230. appData.type = "cms";
  1231. this.createInforMenuItem(appData);
  1232. }
  1233. }
  1234. }
  1235. }.bind(this));
  1236. }
  1237. if (json && json.length) json.each(function(value){
  1238. value.type = "cms";
  1239. this.createInforMenuItem(value);
  1240. }.bind(this));
  1241. },
  1242. loadQuerys: function(){
  1243. this.clearAppContentNode();
  1244. // o2.Actions.get("x_query_assemble_surface").listQuery(this.loadQuerysItem.bind(this));
  1245. this.loadQuerysItem(this.queryJson)
  1246. },
  1247. loadQuerysItem: function(list){
  1248. this.appContentNode.removeClass("icon_loading");
  1249. var json = Array.clone(list);
  1250. if (this.menuData && this.menuData.queryList && this.menuData.queryList.length){
  1251. this.menuData.queryList.each(function(app){
  1252. if (app.type==="group"){
  1253. this.createGroupMenuItem(app);
  1254. app.itemDataList.each(function(a){
  1255. var d = json.find(function(i){ return (i.id === a.id); });
  1256. if (d) json.erase(d);
  1257. }.bind(this));
  1258. }else{
  1259. var appData = null;
  1260. if (!appData && json && json.length){
  1261. appData = json.find(function(i){ return (i.id === app.id); });
  1262. if (appData){
  1263. json.erase(appData);
  1264. appData.type = "query";
  1265. this.createQueryMenuItem(appData);
  1266. }
  1267. }
  1268. }
  1269. }.bind(this));
  1270. }
  1271. if (json && json.length) json.each(function(value){
  1272. value.type = "query";
  1273. this.createQueryMenuItem(value);
  1274. }.bind(this));
  1275. },
  1276. checkMenuItem: function(value, currentNames){
  1277. if (value.visible===false) return false;
  1278. var isAllow = true;
  1279. if (value.allowList) isAllow = (value.allowList.length) ? (value.allowList.isIntersect(currentNames)) : true;
  1280. var isDeny = false;
  1281. if (value.denyList) isDeny = (value.denyList.length) ? (value.denyList.isIntersect(currentNames)) : false;
  1282. return ((!isDeny && isAllow) || o2.AC.isAdministrator());
  1283. },
  1284. createApplicationMenuItem: function(value){
  1285. this.items.push(new o2.xDesktop.Default.StartMenu.Item(this, this.appContentNode, value));
  1286. },
  1287. createPortalMenuItem: function(value){
  1288. this.items.push(new o2.xDesktop.Default.StartMenu.PortalItem(this, this.appContentNode, value));
  1289. },
  1290. createProcessMenuItem: function(value){
  1291. this.items.push(new o2.xDesktop.Default.StartMenu.ProcessItem(this, this.appContentNode, value));
  1292. },
  1293. createInforMenuItem: function(value){
  1294. this.items.push(new o2.xDesktop.Default.StartMenu.InforItem(this, this.appContentNode, value));
  1295. },
  1296. createQueryMenuItem: function(value){
  1297. this.items.push(new o2.xDesktop.Default.StartMenu.QueryItem(this, this.appContentNode, value));
  1298. },
  1299. createGroupMenuItem: function(value){
  1300. this.items.push(new o2.xDesktop.Default.StartMenu.GroupItem(this, this.appContentNode, value));
  1301. },
  1302. show: function(){
  1303. if (!this.isMorph){
  1304. this.isMorph = true;
  1305. if (!this.morph){
  1306. this.maskMorph = new Fx.Morph(this.maskNode, {
  1307. duration: "200",
  1308. transition: Fx.Transitions.Sine.easeOut
  1309. });
  1310. this.morph = new Fx.Morph(this.node, {
  1311. duration: "200",
  1312. transition: Fx.Transitions.Sine.easeOut
  1313. });
  1314. }
  1315. this.maskNode.setStyles({"display": "block"});
  1316. this.node.setStyles({"display": "block"});
  1317. this.triangleNode.setStyles({"display": "block"});
  1318. this.appAreaNode.setStyles({ "filter": "" });
  1319. this.setSize();
  1320. this.setPosition();
  1321. var size = this.layout.menuNode.getSize();
  1322. var left = size.x;
  1323. this.loadJsons(function(){
  1324. (this.currentTab || this.appCategoryTab).click();
  1325. }.bind(this));
  1326. //this.loadContent();
  1327. this.maskMorph.start({"left": ""+left+"px"});
  1328. this.morph.start({"left": ""+left+"px"}).chain(function(){
  1329. this.isShow = true;
  1330. this.isMorph = false;
  1331. this.layout.desktopNode.addEvent("mousedown", this.hideMessage);
  1332. this.setScroll();
  1333. this.fireEvent("show");
  1334. }.bind(this));
  1335. }
  1336. },
  1337. hide: function(callback){
  1338. if (!this.isMorph){
  1339. this.isMorph = true;
  1340. if (!this.morph){
  1341. this.maskMorph = new Fx.Morph(this.maskNode, {
  1342. duration: "200",
  1343. transition: Fx.Transitions.Sine.easeOut
  1344. });
  1345. this.morph = new Fx.Morph(this.node, {
  1346. duration: "200",
  1347. transition: Fx.Transitions.Sine.easeOut
  1348. });
  1349. }
  1350. var nodeSize = this.node.getSize();
  1351. var left = 0-nodeSize.x;
  1352. // var position = this.node.getPosition();
  1353. // var size = this.node.getSize();
  1354. // var left = position.x+size.x;
  1355. this.isSearchResult = false;
  1356. this.hideSearch();
  1357. this.lnkContentNode.empty();
  1358. this.appContentNode.empty();
  1359. this.groupMenuArea.empty();
  1360. if (this.appScrollBar) this.appScrollBar.destroy();
  1361. this.maskMorph.start({"left": ""+left+"px"}).chain(function(){
  1362. this.maskNode.setStyle("display", "none");
  1363. this.triangleNode.setStyles({"display": "none"});
  1364. }.bind(this));
  1365. this.morph.start({"left": ""+left+"px"}).chain(function(){
  1366. this.node.setStyle("display", "none");
  1367. this.isShow = false;
  1368. this.isMorph = false;
  1369. this.layout.desktopNode.removeEvent("mousedown", this.hideMessage);
  1370. this.fireEvent("hide");
  1371. if (callback) callback();
  1372. }.bind(this));
  1373. }
  1374. },
  1375. defaultMenu: function(){
  1376. this.layout.menuData = null;
  1377. if (this.layout.status) this.layout.status.menuData = null;
  1378. this.menuData = null;
  1379. this.hide();
  1380. }
  1381. });
  1382. o2.xDesktop.Default.StartMenu.Item = new Class({
  1383. initialize: function (menu, container, data, positionNode) {
  1384. this.menu = menu;
  1385. this.layout = this.menu.layout;
  1386. this.data = data;
  1387. this.container = $(container);
  1388. this.load(positionNode);
  1389. this.init();
  1390. },
  1391. load: function(positionNode){
  1392. this.node = new Element("div.layout_start_item");
  1393. if (positionNode){
  1394. this.node.inject(positionNode, "before");
  1395. }else{
  1396. this.node.inject(this.container);
  1397. }
  1398. this.node.set("html", this.menu.itemTempletedHtml);
  1399. this.iconAreaNode = this.node.getElement(".layout_start_item_iconArea");
  1400. this.iconNode = this.node.getElement(".layout_start_item_icon");
  1401. this.badgeNode = this.node.getElement(".layout_start_item_badge");
  1402. this.textNode = this.node.getElement(".layout_start_item_text");
  1403. this.loadIcon();
  1404. this.loadBadge();
  1405. this.loadText();
  1406. this.setEvent();
  1407. this.node.store("item", this);
  1408. if (this.menu.data && this.menu.data.type==="group"){
  1409. this.node.addClass("layout_start_item_sub");
  1410. }
  1411. },
  1412. init: function(){},
  1413. dragOver: function(){
  1414. if (!this.overNode){
  1415. this.overNode = new Element("div.layout_start_item_over").inject(this.container);
  1416. this.overNode.addClass("mainColor_bg");
  1417. }
  1418. this.overNode.position({
  1419. "relativeTo": this.iconAreaNode,
  1420. "position": "leftTop",
  1421. "edge": "leftTop",
  1422. "offset": {
  1423. "x": -6, "y":-6
  1424. }
  1425. });
  1426. this.overNode.show();
  1427. },
  1428. dragOut: function(){
  1429. if (this.overNode) this.overNode.hide();
  1430. },
  1431. loadIcon: function(){
  1432. var icon;
  1433. var bgcolor = "";
  1434. if (this.data.path.substring(0, 4)==="@url"){
  1435. if (this.data.iconPath){
  1436. icon = this.data.iconPath;
  1437. }else{
  1438. if (this.layout.iconsJson["Url"] && this.layout.iconsJson["Url"].icon){
  1439. icon = this.layout.path+"appicons/"+this.layout.iconsJson["Url"].icon;
  1440. bgcolor = this.layout.iconsJson["Url"].color;
  1441. }else{
  1442. icon = "../x_component_Setting/$Main/default/icon/site.png";
  1443. bgcolor = "";
  1444. }
  1445. }
  1446. }else{
  1447. if (this.layout.iconsJson[this.data.path] && this.layout.iconsJson[this.data.path].icon){
  1448. icon = this.layout.path+"appicons/"+this.layout.iconsJson[this.data.path].icon;
  1449. bgcolor = this.layout.iconsJson[this.data.path].color;
  1450. }else{
  1451. icon = "../x_component_"+this.data.path.replace(/\./g, "_")+"/$Main/"+this.data.iconPath;
  1452. bgcolor = "";
  1453. }
  1454. }
  1455. if (icon && bgcolor){
  1456. this.iconNode.addClass("layout_start_item_icon_flat");
  1457. this.iconNode.setStyle("background-color", bgcolor);
  1458. }
  1459. this.iconNode.setStyle("background-image", "url("+icon+")");
  1460. this.icon = icon;
  1461. this.bgcolor = bgcolor;
  1462. },
  1463. loadBadge: function(){
  1464. this.badgeNode.set("title", o2.LP.desktop.addLnk).addClass("icon_add_red");
  1465. },
  1466. loadText: function(){
  1467. this.textNode.set("text", this.data.title || this.data.name);
  1468. },
  1469. setEvent: function(){
  1470. this.node.addEvents({
  1471. "mouseover": function(){ this.badgeNode.fade("in"); }.bind(this),
  1472. "mouseout": function(){ this.badgeNode.fade("out"); }.bind(this),
  1473. "click": function(e){
  1474. //this.menu.hide(function(){
  1475. this.open(e);
  1476. //}.bind(this));
  1477. }.bind(this)
  1478. });
  1479. this.badgeNode.addEvent("click", function(e){
  1480. this.addLnk();
  1481. e.stopPropagation();
  1482. }.bind(this));
  1483. this.makeLnk();
  1484. },
  1485. addLnk: function(dragTargetLnk, dragPosition){
  1486. lnkdata = {
  1487. "name": this.data.path,
  1488. "title": this.data.title,
  1489. "iconData": this.data.iconData || null,
  1490. "icon": this.iconData || null,
  1491. "appType": null,
  1492. "options": null
  1493. }
  1494. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  1495. },
  1496. open: function(e){
  1497. this.menu.hide(function(){
  1498. if (this.menu.menu){
  1499. this.menu.menu.hide(function(){
  1500. layout.openApplication(e, this.data.path);
  1501. }.bind(this));
  1502. }else{
  1503. layout.openApplication(e, this.data.path);
  1504. }
  1505. }.bind(this));
  1506. },
  1507. makeLnk: function(){
  1508. var drag = new Drag(this.node, {
  1509. "stopPropagation": true,
  1510. "compensateScroll": true,
  1511. "onStart": function(el, e){
  1512. this.doDragMove(e);
  1513. drag.stop();
  1514. }.bind(this)
  1515. });
  1516. },
  1517. getDragNode: function(){
  1518. if (!this.dragNode){
  1519. this.dragNode = new Element("div.layout_menu_lnk_item_drag")
  1520. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  1521. .inject(this.layout.node);
  1522. var dragIconNode = this.iconNode.clone(true).inject(this.dragNode)
  1523. .removeClass("layout_menu_lnk_item_icon")
  1524. .addClass("layout_menu_lnk_item_icon_drag");
  1525. if (this.bgcolor) dragIconNode.setStyle("background-color", this.bgcolor);
  1526. }
  1527. var p = this.iconNode.getPosition(this.dragNode.getOffsetParent());
  1528. this.dragNode.show().setStyles({
  1529. "left": ""+p.x+"px", "top": ""+p.y+"px"
  1530. });
  1531. },
  1532. doDragMove: function(e){
  1533. this.getDragNode();
  1534. var droppables = [this.layout.lnkContentNode, this.menu.appContentNode];
  1535. if (this.menu.appContentNode.hasClass("layout_start_groupItem_menu_content")){
  1536. this.onGroup = true;
  1537. }
  1538. //if (this.menu.maskGroupNode) droppables.push(this.menu.maskGroupNode);
  1539. var drag = new Drag.Move(this.dragNode, {
  1540. "stopPropagation": true,
  1541. "compensateScroll": true,
  1542. "droppables": droppables,
  1543. "onStart": function(el){ this._drag_start(el); }.bind(this),
  1544. "onDrag": function(dragging,e){ this._drag_drag(dragging, e); }.bind(this),
  1545. "onEnter": function(dragging, inObj){ this._drag_enter(dragging, inObj); }.bind(this),
  1546. "onLeave": function(dragging, obj){ this._drag_leave(dragging, obj); }.bind(this),
  1547. "onDrop": function(dragging, inObj){ this._drag_drop(dragging, inObj); }.bind(this),
  1548. "onCancel": function(dragging){ this._drag_cancel(dragging); }.bind(this),
  1549. "onComplete": function(dragging, e){ this._drag_complete(dragging, e); }.bind(this),
  1550. });
  1551. drag.start(e);
  1552. this.dragStatus == "remove";
  1553. },
  1554. _drag_start: function(el){
  1555. this.isDrag = true;
  1556. this.dragTargetLnk = null;
  1557. this.dragPosition = "before";
  1558. this.node.setStyle("opacity", 0.2);
  1559. this.positionFlagNode = new Element("div", {"styles": {"display": "none"}}).inject(this.node, "after");
  1560. },
  1561. _drag_drag: function(dragging, e){
  1562. console.log(this.dragStatus);
  1563. if (this.dragStatus == "order"){
  1564. if (this.layout.lnks && this.layout.lnks.length){
  1565. var current = e.page.y;
  1566. for (var i=0; i<this.layout.lnks.length; i++){
  1567. var lnk = this.layout.lnks[i];
  1568. var y = lnk.node.getSize().y;
  1569. var top = lnk.node.getPosition(this.layout.node).y;
  1570. var center = top+y/2;
  1571. var bottom = top+y;
  1572. if (top<=current && center>=current){
  1573. this.dragTargetLnk = lnk;
  1574. this.dragPosition = "before";
  1575. break;
  1576. }else if (center<=current && bottom>=current){
  1577. this.dragTargetLnk = lnk;
  1578. this.dragPosition = "after";
  1579. break;
  1580. }
  1581. }
  1582. if (!this.layout.positionNode) this.layout.positionNode = new Element("div.layout_menu_lnk_item_position")
  1583. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  1584. .inject(this.layout.node);
  1585. this.layout.positionNode.show();
  1586. if (!this.dragTargetLnk){
  1587. this.dragTargetLnk = this.layout.lnks[this.layout.lnks.length-1];
  1588. this.dragPosition = "after";
  1589. }
  1590. this.layout.positionNode.position({
  1591. relativeTo: this.dragTargetLnk.node,
  1592. position: (this.dragPosition=="before") ? 'topcenter' : 'bottomcenter',
  1593. edge: 'center'
  1594. });
  1595. }
  1596. }
  1597. if (this.dragStatus == "group"){
  1598. if (!this.onGroup) this.checkDargOver(dragging);
  1599. if (!this.overItem){
  1600. this.checkDargPosition(dragging);
  1601. }
  1602. }
  1603. },
  1604. checkDargOver: function(dragging){
  1605. var p = dragging.getPosition();
  1606. var s = dragging.getSize();
  1607. var x = p.x+s.x/2-1;
  1608. var y = p.y+s.y/2-1;
  1609. var ex = x+2;
  1610. var ey = y+2;
  1611. var overItem = null;
  1612. this.menu.items.each(function(item){
  1613. if (!item.isDrag){
  1614. if (item.iconAreaNode.isInPointInRect(x,y,ex,ey)){
  1615. item.dragOver();
  1616. overItem = item;
  1617. }else{
  1618. item.dragOut();
  1619. }
  1620. }
  1621. });
  1622. this.overItem = overItem;
  1623. },
  1624. checkDargPosition: function(dragging){
  1625. var p = dragging.getPosition();
  1626. var s = dragging.getSize();
  1627. var rightP = { "x": p.x+s.x-2, "y": p.y+s.y/2-1, "ex": p.x+s.x, "ey": p.y+s.y/2+1 };
  1628. var leftP = { "x": p.x, "y": p.y+s.y/2-1, "ex": p.x+2, "ey": p.y+s.y/2+1 };
  1629. var moveFlag = false;
  1630. for (var i = 0; i<this.menu.items.length; i++){
  1631. var item = this.menu.items[i];
  1632. if (!item.isDrag){
  1633. if (item.iconAreaNode.isInPointInRect(rightP.x, rightP.y, rightP.ex, rightP.ey)){
  1634. moveFlag = true;
  1635. this.node.inject(item.node, "before");
  1636. break;
  1637. }else if (item.iconAreaNode.isInPointInRect(leftP.x, leftP.y, leftP.ex, leftP.ey)){
  1638. moveFlag = true;
  1639. this.node.inject(item.node, "after");
  1640. break;
  1641. }
  1642. }
  1643. }
  1644. //if (!moveFlag) this.node.inject(this.menu.appContentNode);
  1645. },
  1646. _drag_enter: function(el, inObj){
  1647. if (inObj.hasClass("layout_start_content_appContent") || inObj.hasClass("layout_start_groupItem_menu_content")){
  1648. this.dragStatus = "group";
  1649. this.node.setStyle("opacity", 0.2);
  1650. }else{
  1651. if (this.positionFlagNode) this.node.inject(this.positionFlagNode, "before");
  1652. this.dragStatus = "order";
  1653. this.node.setStyle("opacity", 1);
  1654. }
  1655. },
  1656. _drag_leave: function(el, inObj){
  1657. if (inObj.hasClass("layout_start_content_appContent")){
  1658. //this.node.inject(this.menu.appContentNode);
  1659. }else if (inObj.hasClass("layout_start_groupItem_menu_content")){
  1660. this.dragStatus = "ungroup";
  1661. this.node.setStyle("opacity", 0);
  1662. }else{
  1663. this.dragStatus = "remove";
  1664. if (this.layout.positionNode) this.layout.positionNode.hide();
  1665. }
  1666. },
  1667. _drag_drop: function(dragging, inObj){
  1668. if (this.dragStatus==="ungroup"){
  1669. this.removeFormGroup();
  1670. }else{
  1671. if (this.dragStatus == "order" && this.dragTargetLnk && this.dragTargetLnk!=this){
  1672. this.addLnk(this.dragTargetLnk, this.dragPosition);
  1673. }else if (this.dragStatus == "group" && this.overItem && this.overItem!=this){
  1674. this.overItem.dragOut();
  1675. this.addGroup();
  1676. }
  1677. this.node.setStyle("opacity", 1);
  1678. }
  1679. this.menu.resetMenuData();
  1680. },
  1681. _drag_cancel: function(dragging){
  1682. console.log("_drag_cancel");
  1683. dragging.hide();
  1684. if (this.layout.positionNode) this.layout.positionNode.hide();
  1685. if (this.dragRemoveNode) this.dragRemoveNode.hide();
  1686. this.node.setStyle("opacity", 1);
  1687. this.isDrag = false;
  1688. this.menu.resetMenuData();
  1689. },
  1690. _drag_complete: function(dragging) {
  1691. this._drag_cancel(dragging);
  1692. if (this.positionFlagNode) this.positionFlagNode.destroy();
  1693. this.positionFlagNode = null;
  1694. },
  1695. removeFormGroup: function(){
  1696. // this.menu.itemDataList.erase(this.data);
  1697. // this.menu.items.erase(this);
  1698. this.menu.data.itemDataList.erase(this.data);
  1699. switch (this.data.type){
  1700. case "portal":
  1701. this.layout.startMenu.createPortalMenuItem(this.data);
  1702. break;
  1703. case "process":
  1704. this.layout.startMenu.createProcessMenuItem(this.data);
  1705. break;
  1706. case "cms":
  1707. this.layout.startMenu.createInforMenuItem(this.data);
  1708. break;
  1709. case "query":
  1710. this.layout.startMenu.createQueryMenuItem(this.data);
  1711. break;
  1712. default:
  1713. this.layout.startMenu.createApplicationMenuItem(this.data);
  1714. }
  1715. debugger;
  1716. this.destroy();
  1717. if (!this.menu.data.itemDataList.length){
  1718. this.menu.hide(function(){
  1719. this.menu.destroy();
  1720. }.bind(this));
  1721. }else{
  1722. this.menu.resetSubItemIcon();
  1723. }
  1724. },
  1725. addGroup: function(){
  1726. debugger;
  1727. if (this.overItem.data.type==="group"){
  1728. this.overItem.addItem(this.data);
  1729. }else{
  1730. var v = {
  1731. name: "Group",
  1732. title: "Group",
  1733. type: "group",
  1734. visible: true
  1735. }
  1736. var group = new o2.xDesktop.Default.StartMenu.GroupItem(this.menu, this.container, v, this.overItem.node);
  1737. group.addItem(this.overItem.data);
  1738. group.addItem(this.data);
  1739. this.menu.items.push(group);
  1740. this.overItem.node.destroy();
  1741. group.open(null, function(){
  1742. group.editTitle();
  1743. });
  1744. }
  1745. this.node.destroy();
  1746. this.menu.resetMenuData();
  1747. },
  1748. destroy: function(){
  1749. this.menu.items.erase(this);
  1750. this.node.destroy();
  1751. }
  1752. });
  1753. o2.xDesktop.Default.StartMenu.GroupItem = new Class({
  1754. Extends: o2.xDesktop.Default.StartMenu.Item,
  1755. loadIcon: function(){
  1756. this.iconNode.addClass("layout_start_item_icon_group");
  1757. this.iconNode.addClass("grayColor_bg");
  1758. this.sunIconNodes = [];
  1759. var node = new Element("div.layout_start_item_icon_group_sub").inject(this.iconNode);
  1760. this.sunIconNodes.push(node);
  1761. node = new Element("div.layout_start_item_icon_group_sub").inject(this.iconNode);
  1762. this.sunIconNodes.push(node);
  1763. node = new Element("div.layout_start_item_icon_group_sub").inject(this.iconNode);
  1764. this.sunIconNodes.push(node);
  1765. node = new Element("div.layout_start_item_icon_group_sub").inject(this.iconNode);
  1766. this.sunIconNodes.push(node);
  1767. },
  1768. init: function(){
  1769. this.itemTempletedHtml = this.menu.itemTempletedHtml;
  1770. if (this.data.itemDataList && this.data.itemDataList.length){
  1771. for (var i=0; i<Math.min(this.data.itemDataList.length, 4); i++){
  1772. var icon = this.setSubItemIcon(this.data.itemDataList[i], this.sunIconNodes[i]);
  1773. }
  1774. }
  1775. },
  1776. resetSubItemIcon: function(){
  1777. this.sunIconNodes.each(function(e){
  1778. e.setStyle("background-image", "");
  1779. e.setStyle("background-color", "");
  1780. });
  1781. if (this.data.itemDataList && this.data.itemDataList.length){
  1782. for (var i=0; i<Math.min(this.data.itemDataList.length, 4); i++){
  1783. var icon = this.setSubItemIcon(this.data.itemDataList[i], this.sunIconNodes[i]);
  1784. }
  1785. }
  1786. },
  1787. open: function(e, callback){
  1788. if (!this.menuNode) this.createMenuNode();
  1789. this.maskNode = new Element("div.layout_start_groupItem_menuMask").inject(this.menuNode, "before");
  1790. this.maskNode.addEvent("click", function(e){
  1791. this.hide();
  1792. }.bind(this));
  1793. this.maskGroupNode = this.maskNode;
  1794. this.menuNode.show();
  1795. var styles = this.getMenuNodeOpenDimensions();
  1796. this.menuNode.morph.set("transition", Fx.Transitions.Quart.easeOut);
  1797. this.menuNode.morph.start(styles).chain(function(){
  1798. this.menuTitleNode.show();
  1799. this.menuScrollNode.show();
  1800. var s = this.menuNode.getSize();
  1801. var ts = this.menuTitleNode.getSize();
  1802. var h = s.y - ts.y;
  1803. this.menuContentNode.setStyle("height", ""+h+"px");
  1804. this.loadItems();
  1805. if (callback) callback();
  1806. }.bind(this));
  1807. this.menu.appAreaNode.setStyles({ "filter": "blur(5px)" });
  1808. },
  1809. hide: function(callback){
  1810. this.menuTitleNode.hide();
  1811. this.menuScrollNode.hide();
  1812. var styles = this.getMenuNodeCloseDimensions();
  1813. this.menuNode.morph.set("transition", Fx.Transitions.Quart.easeIn);
  1814. this.menuNode.morph.start(styles).chain(function(){
  1815. if (this.maskNode) this.maskNode.destroy();
  1816. if (this.menuNode) this.menuNode.hide();
  1817. if (callback) callback();
  1818. }.bind(this));
  1819. this.menu.appAreaNode.setStyles({ "filter": "" });
  1820. },
  1821. loadItems: function(){
  1822. if (!this.items) this.items = [];
  1823. this.data.itemDataList.each(function(data){
  1824. var item = this.items.find(function(i){
  1825. return i.data.id == data.id;
  1826. });
  1827. if (!item){
  1828. switch (data.type){
  1829. case "portal":
  1830. this.items.push(new o2.xDesktop.Default.StartMenu.PortalItem(this, this.menuContentNode, data));
  1831. break;
  1832. case "process":
  1833. this.items.push(new o2.xDesktop.Default.StartMenu.ProcessItem(this, this.menuContentNode, data));
  1834. break;
  1835. case "cms":
  1836. this.items.push(new o2.xDesktop.Default.StartMenu.InforItem(this, this.menuContentNode, data));
  1837. break;
  1838. case "query":
  1839. this.items.push(new o2.xDesktop.Default.StartMenu.QueryItem(this, this.menuContentNode, data));
  1840. break;
  1841. default:
  1842. this.items.push(new o2.xDesktop.Default.StartMenu.Item(this, this.menuContentNode, data));
  1843. }
  1844. }
  1845. }.bind(this));
  1846. },
  1847. getMenuNodeOpenDimensions: function(){
  1848. var size = this.menu.appAreaNode.getSize();
  1849. var w = size.x*0.94;
  1850. var h = size.y*0.7;
  1851. var x = (size.x*(1-0.94))/2;
  1852. var y = (size.y*(1-0.7))/2;
  1853. return {"width":w, "height": h, "left": x, "top": y}
  1854. },
  1855. getMenuNodeCloseDimensions: function(){
  1856. var size = this.iconNode.getSize();
  1857. var position = this.iconNode.getPosition(this.menu.node);
  1858. return {"width":size.x, "height": size.y, "left": position.x, "top": position.y}
  1859. },
  1860. createMenuNode: function(){
  1861. this.menuNode = new Element("div.layout_start_groupItem_menu").inject(this.menu.groupMenuArea);
  1862. this.menuNode.addClass("grayColor_bg");
  1863. this.menuTitleNode = new Element("div.layout_start_groupItem_menu_title").inject(this.menuNode);
  1864. this.menuTitleNode.set("text", this.data.name);
  1865. this.menuScrollNode = new Element("div.layout_start_groupItem_menu_scroll").inject(this.menuNode);
  1866. this.menuContentNode = new Element("div.layout_start_groupItem_menu_content").inject(this.menuScrollNode);
  1867. this.appContentNode = this.menuContentNode;
  1868. this.menuNode.position({
  1869. "relativeTo": this.iconNode,
  1870. "position": "upperLeft",
  1871. "edge": "upperLeft"
  1872. });
  1873. this.menuNode.morph = new Fx.Morph(this.menuNode, {
  1874. "duration": 200,
  1875. "transition": Fx.Transitions.Quart.easeOut
  1876. });
  1877. this.menuTitleNode.addEvent("click", function(){
  1878. var input = this.menuTitleNode.getElement("input");
  1879. if (!input) this.editTitle();
  1880. }.bind(this))
  1881. },
  1882. destroy: function(){
  1883. this.menu.items.erase(this);
  1884. this.node.destroy();
  1885. this.menuNode.destroy();
  1886. },
  1887. editTitle: function(){
  1888. this.menuTitleNode.empty();
  1889. this.editotTitleNode = new Element("input.layout_start_groupItem_menu_title_edit", {"type": "text"}).inject(this.menuTitleNode);
  1890. this.editotTitleNode.set("value", this.data.name);
  1891. this.editotTitleNode.focus();
  1892. this.editotTitleNode.addEvent("blur", function(){
  1893. var name = this.editotTitleNode.get("value");
  1894. if (name) this.data.name = name;
  1895. this.menuTitleNode.empty();
  1896. this.menuTitleNode.set("text", this.data.name);
  1897. this.loadText();
  1898. }.bind(this));
  1899. },
  1900. addItem: function(data){
  1901. if (!this.data.itemDataList) this.data.itemDataList = [];
  1902. if (this.data.itemDataList.length<4){
  1903. this.setSubItemIcon(data, this.sunIconNodes[this.data.itemDataList.length]);
  1904. }
  1905. this.data.itemDataList.push(data);
  1906. },
  1907. setSubItemIcon: function(data, node){
  1908. switch (data.type){
  1909. case "process":
  1910. this.setAppSubItemIcon(node, data.icon, "processDefault", "../x_component_process_ApplicationExplorer/$Main/default/icon/application.png");
  1911. break;
  1912. case "portal":
  1913. this.setAppSubItemIcon(node, data.icon, "portalDefault", "../x_component_portal_PortalExplorer/$Main/default/icon/application.png");
  1914. break;
  1915. case "cms":
  1916. this.setAppSubItemIcon(node, data.icon, "cmsDefault", "../x_component_cms_Index/$Main/default/icon/column.png");
  1917. break;
  1918. case "query":
  1919. this.setAppSubItemIcon(node, data.icon, "queryDefault", "../x_component_query_Query/$Main/appicon.png");
  1920. break;
  1921. default:
  1922. this.setDefaultSubItemIcon(data, node);
  1923. }
  1924. },
  1925. setAppSubItemIcon: function(node, iconData, defaultIcon, defaultUrl){
  1926. var icon = "";
  1927. var bgcolor = "";
  1928. if (iconData){
  1929. icon = "data:image/png;base64,"+iconData+"";
  1930. bgcolor = "";
  1931. node.addClass("layout_start_item_icon_group_subIcon");
  1932. }else{
  1933. var p = defaultIcon;
  1934. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  1935. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  1936. bgcolor = this.layout.iconsJson[p].color;
  1937. }else{
  1938. icon = defaultUrl;
  1939. bgcolor = "";
  1940. }
  1941. }
  1942. if (icon && bgcolor) node.setStyle("background-color", bgcolor);
  1943. node.setStyle("background-image", "url("+icon+")");
  1944. },
  1945. setDefaultSubItemIcon: function(data, node){
  1946. var icon;
  1947. var bgcolor = "";
  1948. if (data.path.substring(0, 4)==="@url"){
  1949. if (data.iconPath){
  1950. icon = data.iconPath;
  1951. }else{
  1952. if (this.layout.iconsJson["Url"] && this.layout.iconsJson["Url"].icon){
  1953. icon = this.layout.path+"appicons/"+this.layout.iconsJson["Url"].icon;
  1954. bgcolor = this.layout.iconsJson["Url"].color;
  1955. }else{
  1956. icon = "../x_component_Setting/$Main/default/icon/site.png";
  1957. bgcolor = "";
  1958. }
  1959. }
  1960. }else{
  1961. if (this.layout.iconsJson[data.path] && this.layout.iconsJson[data.path].icon){
  1962. icon = this.layout.path+"appicons/"+this.layout.iconsJson[data.path].icon;
  1963. bgcolor = this.layout.iconsJson[data.path].color;
  1964. }else{
  1965. icon = "../x_component_"+data.path.replace(/\./g, "_")+"/$Main/"+data.iconPath;
  1966. bgcolor = "";
  1967. }
  1968. }
  1969. if (icon && bgcolor){
  1970. node.setStyle("background-color", bgcolor);
  1971. }
  1972. node.setStyle("background-image", "url("+icon+")");
  1973. },
  1974. resetMenuData: function(){
  1975. debugger;
  1976. var nodes = this.menuContentNode.getChildren(".layout_start_item");
  1977. var data = [];
  1978. nodes.each(function(node){
  1979. var item = node.retrieve("item");
  1980. if (item){
  1981. data.push(item.data);
  1982. }
  1983. }.bind(this));
  1984. this.data.itemDataList = data;
  1985. }
  1986. });
  1987. o2.xDesktop.Default.StartMenu.PortalItem = new Class({
  1988. Extends: o2.xDesktop.Default.StartMenu.Item,
  1989. loadIcon: function(){
  1990. var icon = "";
  1991. var bgcolor = "";
  1992. if (this.data.icon){
  1993. icon = "data:image/png;base64,"+this.data.icon+"";
  1994. }else{
  1995. var p = "portalDefault";
  1996. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  1997. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  1998. bgcolor = this.layout.iconsJson[p].color;
  1999. }else{
  2000. icon = "../x_component_portal_PortalExplorer/$Main/default/icon/application.png";
  2001. bgcolor = "";
  2002. }
  2003. }
  2004. if (icon && bgcolor){
  2005. this.iconNode.addClass("layout_start_item_icon_flat");
  2006. this.iconNode.setStyle("background-color", bgcolor);
  2007. }
  2008. this.iconNode.setStyle("background-image", "url("+icon+")");
  2009. this.icon = icon;
  2010. },
  2011. loadText: function(){
  2012. this.textNode.set("text", this.data.name);
  2013. },
  2014. addLnk: function(dragTargetLnk, dragPosition){
  2015. var options = {"portalId": this.data.id, "appId": "portal.Portal"+this.data.id};
  2016. lnkdata = {
  2017. "name": "portal.Portal",
  2018. "title": this.data.name,
  2019. "iconData": (this.data.icon) || "",
  2020. "icon": null,
  2021. "appType": "portal",
  2022. "options": options
  2023. }
  2024. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  2025. },
  2026. open: function(e){
  2027. var options = {"portalId": this.data.id, "appId": "portal.Portal"+this.data.id};
  2028. this.menu.hide(function(){
  2029. if (this.menu.menu){
  2030. this.menu.menu.hide(function(){
  2031. layout.openApplication(e, "portal.Portal", options);
  2032. }.bind(this));
  2033. }else{
  2034. layout.openApplication(e, "portal.Portal", options);
  2035. }
  2036. }.bind(this));
  2037. }
  2038. // makeLnk: function(){
  2039. // //@todo
  2040. // // this.node.makeLnk({
  2041. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  2042. // // });
  2043. // }
  2044. });
  2045. o2.xDesktop.Default.StartMenu.ProcessItem = new Class({
  2046. Extends: o2.xDesktop.Default.StartMenu.PortalItem,
  2047. loadIcon: function(){
  2048. var icon = "";
  2049. var bgcolor = "";
  2050. if (this.data.icon){
  2051. icon = "data:image/png;base64,"+this.data.icon+"";
  2052. bgcolor = "";
  2053. }else{
  2054. var p = "processDefault";
  2055. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  2056. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  2057. bgcolor = this.layout.iconsJson[p].color;
  2058. }else{
  2059. icon = "../x_component_process_ApplicationExplorer/$Main/default/icon/application.png";
  2060. bgcolor = "";
  2061. }
  2062. }
  2063. if (icon && bgcolor){
  2064. this.iconNode.addClass("layout_start_item_icon_flat");
  2065. this.iconNode.setStyle("background-color", bgcolor);
  2066. }
  2067. this.iconNode.setStyle("background-image", "url("+icon+")");
  2068. this.icon = icon;
  2069. },
  2070. addLnk: function(dragTargetLnk, dragPosition){
  2071. var options = {"id": this.data.id, "appId": "process.Application"+this.data.id};
  2072. lnkdata = {
  2073. "name": "process.Application",
  2074. "title": this.data.name,
  2075. "iconData": (this.data.icon) || "",
  2076. "icon": null,
  2077. "appType": "process",
  2078. "options": options
  2079. }
  2080. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  2081. },
  2082. open: function(e){
  2083. var options = {"id": this.data.id, "appId": "process.Application"+this.data.id};
  2084. this.menu.hide(function(){
  2085. if (this.menu.menu){
  2086. this.menu.menu.hide(function(){
  2087. layout.openApplication(e, "process.Application", options);
  2088. }.bind(this));
  2089. }else{
  2090. layout.openApplication(e, "process.Application", options);
  2091. }
  2092. }.bind(this));
  2093. }
  2094. // makeLnk: function(){
  2095. // //@todo
  2096. // // this.node.makeLnk({
  2097. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  2098. // // });
  2099. // }
  2100. });
  2101. o2.xDesktop.Default.StartMenu.InforItem = new Class({
  2102. Extends: o2.xDesktop.Default.StartMenu.PortalItem,
  2103. loadIcon: function(){
  2104. var icon = "";
  2105. var bgcolor = "";
  2106. if (this.data.appIcon){
  2107. icon = "data:image/png;base64,"+this.data.appIcon+"";
  2108. bgcolor = "";
  2109. }else{
  2110. var p = "cmsDefault";
  2111. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  2112. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  2113. bgcolor = this.layout.iconsJson[p].color;
  2114. }else{
  2115. icon = "../x_component_cms_Index/$Main/default/icon/column.png";
  2116. bgcolor = "";
  2117. }
  2118. }
  2119. if (icon && bgcolor){
  2120. this.iconNode.addClass("layout_start_item_icon_flat");
  2121. this.iconNode.setStyle("background-color", bgcolor);
  2122. }
  2123. this.iconNode.setStyle("background-image", "url("+icon+")");
  2124. this.icon = icon;
  2125. },
  2126. loadText: function(){
  2127. this.textNode.set("text", this.data.appName);
  2128. },
  2129. addLnk: function(dragTargetLnk, dragPosition){
  2130. lnkdata = {
  2131. "name": "cms.Module",
  2132. "title": this.data.appName,
  2133. "iconData": (this.data.appIcon) || "",
  2134. "icon": null,
  2135. "appType": "cms",
  2136. "options": {"columnData": this.data, "appId": "cms.Module"+this.data.id}
  2137. }
  2138. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  2139. },
  2140. open: function(e){
  2141. this.menu.hide(function(){
  2142. if (this.menu.menu){
  2143. this.menu.menu.hide(function(){
  2144. layout.openApplication(e, "cms.Module", {"columnData": this.data, "appId": "cms.Module"+this.data.id});
  2145. }.bind(this));
  2146. }else{
  2147. layout.openApplication(e, "cms.Module", {"columnData": this.data, "appId": "cms.Module"+this.data.id});
  2148. }
  2149. }.bind(this));
  2150. }
  2151. // makeLnk: function(){
  2152. // //@todo
  2153. // // this.node.makeLnk({
  2154. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  2155. // // });
  2156. // }
  2157. });
  2158. o2.xDesktop.Default.StartMenu.QueryItem = new Class({
  2159. Extends: o2.xDesktop.Default.StartMenu.PortalItem,
  2160. loadIcon: function(){
  2161. var icon = "";
  2162. var bgcolor = "";
  2163. if (this.data.icon){
  2164. icon = "data:image/png;base64,"+this.data.icon+"";
  2165. bgcolor = "";
  2166. }else{
  2167. var p = "queryDefault";
  2168. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  2169. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  2170. bgcolor = this.layout.iconsJson[p].color;
  2171. }else{
  2172. icon = "../x_component_query_Query/$Main/appicon.png";
  2173. bgcolor = "";
  2174. }
  2175. }
  2176. if (icon && bgcolor){
  2177. this.iconNode.addClass("layout_start_item_icon_flat");
  2178. this.iconNode.setStyle("background-color", bgcolor);
  2179. }
  2180. this.iconNode.setStyle("background-image", "url("+icon+")");
  2181. this.icon = icon;
  2182. },
  2183. addLnk: function(){
  2184. lnkdata = {
  2185. "name": "query.Query",
  2186. "title": this.data.name,
  2187. "iconData": (this.data.icon)||"",
  2188. "icon": null,
  2189. "appType": "query",
  2190. "options": {"id": this.data.id, "appId": "query.Query"+this.data.id}
  2191. }
  2192. this.layout.addLnk(lnkdata, dragTargetLnk, dragPosition);
  2193. },
  2194. open: function(e){
  2195. this.menu.hide(function(){
  2196. if (this.menu.menu){
  2197. this.menu.menu.hide(function(){
  2198. layout.openApplication(e, "query.Query", {"id": this.data.id, "appId": "query.Query"+this.data.id});
  2199. }.bind(this));
  2200. }else{
  2201. layout.openApplication(e, "query.Query", {"id": this.data.id, "appId": "query.Query"+this.data.id});
  2202. }
  2203. }.bind(this));
  2204. }
  2205. // makeLnk: function(){
  2206. // //@todo
  2207. // // this.node.makeLnk({
  2208. // // "par": {"icon": this.icon, "color": this.color, "title": this.data.title, "par": this.data.path},
  2209. // // });
  2210. // }
  2211. });
  2212. o2.xDesktop.Default.TaskItem = new Class({
  2213. initialize: function(desktop, app){
  2214. this.desktop = desktop;
  2215. this.container = this.desktop.taskContentNode;
  2216. this.app = app;
  2217. this.load();
  2218. },
  2219. load: function(){
  2220. this.node = new Element("div.layout_content_taskbar_item").inject(this.container);
  2221. this.iconNode = new Element("div");
  2222. this.closeNode = new Element("div.layout_content_taskbar_item_icon", {"title": o2.LP.widget.close}).inject(this.node);
  2223. this.closeNode.addClass("icon_close");
  2224. if (this.app.options.appId==this.desktop.options.index){
  2225. this.closeNode.hide();
  2226. this.noCloseNode = true;
  2227. }
  2228. this.refreshNode = new Element("div.layout_content_taskbar_item_refresh", {"title": o2.LP.widget.refresh}).inject(this.node);;
  2229. this.refreshNode.addClass("icon_refresh");
  2230. this.refreshNode.addClass("animation_taskItemLoading");
  2231. this.actionNode = new Element("div.layout_content_taskbar_item_action").inject(this.node);;
  2232. this.actionNode.addClass("icon_taskitem_down");
  2233. this.textNode = new Element("div.layout_content_taskbar_item_text").inject(this.node);;
  2234. this.setText(this.app.options.title);
  2235. //this.desktop.checkTaskBarSize();
  2236. this.setEvent();
  2237. this.unSelected();
  2238. },
  2239. setEvent: function(){
  2240. this.textNode.addEvents({
  2241. "click": function(){
  2242. if (this.desktop.currentApp!=this.app){
  2243. if (!this.app.window){
  2244. this.desktop.apps[this.app.options.appId] = null;
  2245. layout.openApplication(null, this.app.options.name, this.app.options, this.app.options.app, false, this, false);
  2246. }else{
  2247. this.app.setCurrent();
  2248. }
  2249. }else{
  2250. // this.app.refresh();
  2251. }
  2252. }.bind(this),
  2253. "dblclick": function(){
  2254. this.app.openInNewBrowser((this.app.options.appId==this.desktop.options.index));
  2255. }.bind(this)
  2256. });
  2257. this.closeNode.addEvents({
  2258. "mouseover": function(){
  2259. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  2260. }.bind(this),
  2261. "mouseout": function(){
  2262. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  2263. }.bind(this),
  2264. "click": function(){
  2265. if (!this.app.window){
  2266. this.desktop.apps[this.app.options.appId] = null;
  2267. delete this.desktop.apps[this.app.options.appId];
  2268. this.destroy();
  2269. }else{
  2270. this.app.close();
  2271. }
  2272. }.bind(this)
  2273. });
  2274. this.refreshNode.addEvents({
  2275. "mouseover": function(){
  2276. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode_over);
  2277. }.bind(this),
  2278. "mouseout": function(){
  2279. // if (!this.layout.currentApp || this.layout.currentApp.taskitem!=this) this.node.setStyles(this.layout.css.taskItemNode);
  2280. }.bind(this),
  2281. "click": function(){
  2282. this.app.refresh();
  2283. }.bind(this)
  2284. });
  2285. this.loadTaskItemMenu();
  2286. if (this.desktop && this.desktop.checkTaskBarSize) this.desktop.checkTaskBarSize();
  2287. },
  2288. loadTaskItemMenu: function(){
  2289. if (!this.taskitemMenu){
  2290. this.taskitemMenu = new o2.xDesktop.Menu(this.actionNode, {
  2291. "event": "click", "style": "flatUser", "offsetX": -10, "offsetY":6, "container": this.node
  2292. });
  2293. this.taskitemMenu.load();
  2294. this.loadTaskItemMenuItems();
  2295. }
  2296. },
  2297. loadTaskItemMenuItems: function(){
  2298. var img = this.desktop.path+this.desktop.options.style+"/icons/menu_refresh.png";
  2299. this.taskitemMenu.addMenuItem(o2.LP.desktop.refresh, "click", function(e){this.app.refresh(e);}.bind(this), img);
  2300. this.taskitemMenu.addMenuLine();
  2301. //img = this.path+this.options.style+"/icons/logout.png";
  2302. if (this.app.options.appId!==this.desktop.options.index){
  2303. img = this.desktop.path+this.desktop.options.style+"/icons/menu_close.png";
  2304. this.taskitemMenu.addMenuItem(o2.LP.desktop.close, "click", function(){
  2305. if (!this.app.window){
  2306. this.desktop.apps[this.app.options.appId] = null;
  2307. delete this.desktop.apps[this.app.options.appId];
  2308. this.destroy();
  2309. }else{
  2310. this.app.close();
  2311. }
  2312. }.bind(this), img);
  2313. }
  2314. img = this.desktop.path+this.desktop.options.style+"/icons/menu_closeall.png";
  2315. this.taskitemMenu.addMenuItem(o2.LP.desktop.closeAll, "click", function(){
  2316. var keys = Array.clone(Object.keys(this.desktop.apps));
  2317. keys.each(function(key){
  2318. if (!this.desktop.apps[key].isIndex && !this.desktop.apps[key].options.isIndex) this.desktop.apps[key].close();
  2319. }.bind(this));
  2320. keys = null;
  2321. }.bind(this), img);
  2322. img = this.desktop.path+this.desktop.options.style+"/icons/menu_closeother.png";
  2323. this.taskitemMenu.addMenuItem(o2.LP.desktop.closeOther, "click", function(){
  2324. var keys = Array.clone(Object.keys(this.desktop.apps));
  2325. keys.each(function(key){
  2326. if (!this.desktop.apps[key].isIndex &&
  2327. !this.desktop.apps[key].options.isIndex &&
  2328. this.desktop.apps[key].options.appId!=this.app.options.appId) this.desktop.apps[key].close();
  2329. }.bind(this));
  2330. keys = null;
  2331. }.bind(this), img);
  2332. },
  2333. setText: function(str){
  2334. this.textNode.set("text", str || this.app.options.title);
  2335. },
  2336. unSelected: function(){
  2337. this.node.removeClass("mainColor_bg");
  2338. if (!this.noCloseNode) {
  2339. this.closeNode.addClass("icon_close");
  2340. this.closeNode.removeClass("icon_close_focus");
  2341. //this.closeNode.hide();
  2342. }
  2343. if (this.refreshNode) this.refreshNode.hide();
  2344. if (this.actionNode) this.actionNode.hide();
  2345. },
  2346. selected: function(){
  2347. this.node.addClass("mainColor_bg");
  2348. if (!this.noCloseNode){
  2349. this.closeNode.removeClass("icon_close");
  2350. this.closeNode.addClass("icon_close_focus");
  2351. //this.closeNode.show();
  2352. }
  2353. this.desktop.checkTaskBarScrollTo(this.app);
  2354. //this.refreshNode.show();
  2355. if (this.actionNode) this.actionNode.show();
  2356. },
  2357. destroy: function(){
  2358. this.iconNode.destroy();
  2359. this.node.destroy();
  2360. if (this.desktop && this.desktop.checkTaskBarSize) this.desktop.checkTaskBarSize();
  2361. if (this.app.options && this.app.options.appId) delete this.desktop.apps[this.app.options.appId];
  2362. o2.release(this);
  2363. },
  2364. setTaskitemSize: function(){
  2365. this.desktop.checkTaskBarSize();
  2366. this.desktop.checkTaskBarScrollTo();
  2367. }
  2368. });
  2369. o2.xDesktop.Default.Lnk = new Class({
  2370. initialize: function(layout, data, targetLnk, position){
  2371. this.layout = layout;
  2372. this.container = this.layout.lnkAreaNode;
  2373. this.data = data;
  2374. this.load(targetLnk, position);
  2375. },
  2376. load: function(targetLnk, position){
  2377. this.node = new Element("div.layout_menu_lnk_item");
  2378. if (targetLnk){
  2379. if (!position) position = "before";
  2380. this.node.inject(targetLnk.node, position);
  2381. }else{
  2382. this.node.inject(this.container);
  2383. }
  2384. this.iconNode = new Element("div.layout_menu_lnk_item_icon").inject(this.node);
  2385. this.textNode = new Element("div.layout_menu_lnk_item_text", {"text": this.data.title}).inject(this.node);
  2386. this.actionNode = new Element("div.layout_menu_lnk_item_action", {"title": o2.LP.desktop.deleteLnk}).inject(this.node);
  2387. this.actionNode.addClass("icon_off_light");
  2388. var icon = this.getIcon();
  2389. this.iconNode.setStyle("background-image", "url("+icon+")");
  2390. this.setEvent();
  2391. },
  2392. setEvent: function(){
  2393. this.node.addEvents({
  2394. "click": function(){
  2395. if (this.data.name=="Homepage"){
  2396. var name = this.data.name;
  2397. var options = this.data.options;
  2398. if (layout.config.indexPage && layout.config.indexPage.enable && layout.config.indexPage.portal){
  2399. name = "portal.Portal";
  2400. var appId = "portal.Portal"+layout.config.indexPage.portal;
  2401. options = {"name": "portal.Portal", "portalId": layout.config.indexPage.portal, "pageId": layout.config.indexPage.page, "appId": appId};
  2402. }
  2403. layout.openApplication(null, name, options);
  2404. }else{
  2405. layout.openApplication(null, this.data.name, this.data.options);
  2406. }
  2407. }.bind(this),
  2408. "mouseover": function(){
  2409. this.actionNode.fade("in");
  2410. this.node.addClass("overColor_bg");
  2411. this.textNode.fade("in");
  2412. }.bind(this),
  2413. "mouseout": function(){
  2414. this.actionNode.fade("out");
  2415. this.node.removeClass("overColor_bg");
  2416. this.textNode.fade("out");
  2417. }.bind(this)
  2418. });
  2419. this.actionNode.addEvents({
  2420. "click": function(e){
  2421. this.destroy();
  2422. e.stopPropagation();
  2423. }.bind(this),
  2424. "mouseover": function(){
  2425. this.actionNode.addClass("layout_menu_lnk_item_action_shadow");
  2426. }.bind(this),
  2427. "mouseout": function(){
  2428. this.actionNode.removeClass("layout_menu_lnk_item_action_shadow");
  2429. }.bind(this)
  2430. });
  2431. var drag = new Drag(this.node, {
  2432. "stopPropagation": true,
  2433. "compensateScroll": true,
  2434. "onStart": function(el, e){
  2435. this.doDragMove(e);
  2436. drag.stop();
  2437. }.bind(this)
  2438. });
  2439. },
  2440. getDragNode: function(){
  2441. if (!this.dragNode){
  2442. this.dragNode = new Element("div.layout_menu_lnk_item_drag")
  2443. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  2444. .inject(this.layout.node);
  2445. var dragIconNode = this.iconNode.clone(true).inject(this.dragNode)
  2446. .removeClass("layout_menu_lnk_item_icon")
  2447. .addClass("layout_menu_lnk_item_icon_drag");
  2448. var p = (this.data.appType) ? this.data.appType+"Default" : this.data.name;
  2449. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].color){
  2450. dragIconNode.setStyle("background-color", this.layout.iconsJson[p].color)
  2451. }
  2452. this.dragRemoveNode = new Element("div.layout_menu_lnk_item_icon_drag_del").inject(this.dragNode)
  2453. .addClass("icon_remove_badge")
  2454. .hide();
  2455. }
  2456. var ps = this.iconNode.getPosition(this.dragNode.getOffsetParent());
  2457. this.dragNode.show().setStyles({
  2458. "left": ""+ps.x+"px", "top": ""+ps.y+"px"
  2459. });
  2460. },
  2461. doDragMove: function(e){
  2462. this.getDragNode();
  2463. var drag = new Drag.Move(this.dragNode, {
  2464. "stopPropagation": true,
  2465. "compensateScroll": true,
  2466. "droppables": [this.container.getParent()],
  2467. "onStart": function(){ this._drag_start(); }.bind(this),
  2468. "onDrag": function(dragging,e){ this._drag_drag(dragging, e); }.bind(this),
  2469. "onEnter": function(dragging, inObj){ this._drag_enter(dragging, inObj); }.bind(this),
  2470. "onLeave": function(dragging, obj){ this._drag_leave(dragging, obj); }.bind(this),
  2471. "onDrop": function(dragging, inObj){ this._drag_drop(dragging, inObj); }.bind(this),
  2472. "onCancel": function(dragging){ this._drag_cancel(dragging); }.bind(this),
  2473. "onComplete": function(dragging, e){ this._drag_complete(dragging, e); }.bind(this),
  2474. });
  2475. drag.start(e);
  2476. this.dragStatus = "order";
  2477. },
  2478. _drag_start: function(){
  2479. this.node.addClass("overColor_bg");
  2480. this.node.addClass("opacity50");
  2481. this.dragTargetLnk = null;
  2482. this.dragPosition = "before";
  2483. },
  2484. _drag_drag: function(dragging, e){
  2485. if (this.dragStatus == "order"){
  2486. if (this.layout.lnks && this.layout.lnks.length){
  2487. var current = e.page.y;
  2488. for (var i=0; i<this.layout.lnks.length; i++){
  2489. var lnk = this.layout.lnks[i];
  2490. var y = lnk.node.getSize().y;
  2491. var top = lnk.node.getPosition(this.layout.node).y;
  2492. var center = top+y/2;
  2493. var bottom = top+y;
  2494. if (top<=current && center>=current){
  2495. this.dragTargetLnk = lnk;
  2496. this.dragPosition = "before";
  2497. break;
  2498. }else if (center<=current && bottom>=current){
  2499. this.dragTargetLnk = lnk;
  2500. this.dragPosition = "after";
  2501. break;
  2502. }
  2503. }
  2504. if (!this.layout.positionNode) this.layout.positionNode = new Element("div.layout_menu_lnk_item_position")
  2505. .setStyle("z-index", o2.xDesktop.zIndexPool.applyZindex())
  2506. .inject(this.layout.node);
  2507. this.layout.positionNode.show();
  2508. if (!this.dragTargetLnk){
  2509. this.dragTargetLnk = this.layout.lnks[this.layout.lnks.length-1];
  2510. this.dragPosition = "after";
  2511. }
  2512. this.layout.positionNode.position({
  2513. relativeTo: this.dragTargetLnk.node,
  2514. position: (this.dragPosition=="before") ? 'topcenter' : 'bottomcenter',
  2515. edge: 'center'
  2516. });
  2517. }
  2518. }
  2519. },
  2520. _drag_enter: function(){
  2521. this.dragStatus = "order";
  2522. if (this.dragRemoveNode) this.dragRemoveNode.hide();
  2523. },
  2524. _drag_leave: function(){
  2525. this.dragStatus = "remove";
  2526. if (this.dragRemoveNode) this.dragRemoveNode.show();
  2527. if (this.layout.positionNode) this.layout.positionNode.hide();
  2528. },
  2529. _drag_drop: function(dragging, inObj){
  2530. if (this.dragStatus == "order" && this.dragTargetLnk && this.dragTargetLnk!=this){
  2531. this.node.inject(this.dragTargetLnk.node, this.dragPosition);
  2532. this.layout.lnks.erase(this);
  2533. var idx = this.layout.lnks.indexOf(this.dragTargetLnk);
  2534. if (this.dragPosition=="before"){
  2535. this.layout.lnks.splice(idx, 0, this);
  2536. }else{
  2537. this.layout.lnks.splice(idx+1, 0, this);
  2538. }
  2539. }
  2540. },
  2541. _drag_cancel: function(dragging){
  2542. dragging.hide();
  2543. if (this.node) {
  2544. this.node.removeClass("overColor_bg");
  2545. this.node.removeClass("opacity50");
  2546. }
  2547. if (this.layout.positionNode) this.layout.positionNode.hide();
  2548. if (this.dragRemoveNode) this.dragRemoveNode.hide();
  2549. },
  2550. _drag_complete: function(dragging){
  2551. if (this.dragStatus == "remove"){
  2552. this.destroy();
  2553. }else{
  2554. this._drag_cancel(dragging);
  2555. }
  2556. },
  2557. destroy: function(){
  2558. this.layout.lnks.erase(this);
  2559. if (this.dragNode) this.dragNode.destroy();
  2560. //if (this.positionNode) this.positionNode.destroy();
  2561. this.node.destroy();
  2562. o2.release(this);
  2563. },
  2564. getIcon: function(){
  2565. if (this.data.icon) return this.data.icon;
  2566. var icon;
  2567. if (this.data.name.substring(0, 4)==="@url"){
  2568. if (this.layout.iconsJson["Url"] && this.layout.iconsJson["Url"].icon){
  2569. icon = this.layout.path+"appicons/"+this.layout.iconsJson["Url"].icon;
  2570. }else{
  2571. icon = this.layout.path+"appicons/url.png";
  2572. }
  2573. }else{
  2574. if (this.data.iconData){
  2575. icon = "data:image/png;base64,"+this.data.iconData+"";
  2576. }else if (this.data.iconPath){
  2577. icon = this.data.iconPath;
  2578. }else{
  2579. var p = (this.data.appType) ? this.data.appType+"Default" : this.data.name;
  2580. if (this.layout.iconsJson[p] && this.layout.iconsJson[p].icon){
  2581. icon = this.layout.path+"appicons/"+this.layout.iconsJson[p].icon;
  2582. }else{
  2583. icon = "../x_component_"+this.data.name.replace(/\./g, "_")+"/$Main/appicon.png";
  2584. }
  2585. }
  2586. }
  2587. return icon;
  2588. }
  2589. });
  2590. o2.xDesktop.zIndexPool = {
  2591. zIndex: 102,
  2592. applyZindex: function(){
  2593. var i = this.zIndex;
  2594. this.zIndex = this.zIndex+2;
  2595. return i;
  2596. }
  2597. };