init.js 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169
  1. /** ***** BEGIN LICENSE BLOCK *****
  2. * |------------------------------------------------------------------------------|
  3. * | O2OA 活力办公 创意无限 o2.js |
  4. * |------------------------------------------------------------------------------|
  5. * | Distributed under the AGPL license: |
  6. * |------------------------------------------------------------------------------|
  7. * | Copyright © 2018, o2oa.net, o2server.io O2 Team |
  8. * | All rights reserved. |
  9. * |------------------------------------------------------------------------------|
  10. *
  11. * This file is part of O2OA.
  12. *
  13. * O2OA is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * O2OA is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with Foobar. If not, see <https://www.gnu.org/licenses/>.
  25. *
  26. * ***** END LICENSE BLOCK ******/
  27. (function(){
  28. var _href = window.location.href;
  29. var _debug = (_href.indexOf("debugger")!==-1);
  30. var _par = _href.substr(_href.lastIndexOf("?")+1, _href.length);
  31. var _lp = "zh-cn";
  32. if (_par){
  33. var _parList = _par.split("&");
  34. for (var i=0; i<_parList.length; i++){
  35. var _v = _parList[i];
  36. var _kv = _v.split("=");
  37. if (_kv[0].toLowerCase()==="lg") _lp = _kv[1];
  38. }
  39. }
  40. this.o2 = {
  41. "version": {
  42. "v": '2.1.0',
  43. "build": "2018.11.22",
  44. "info": "O2OA 活力办公 创意无限. Copyright © 2018, o2oa.net O2 Team All rights reserved."
  45. },
  46. "session": {
  47. "isDebugger": _debug,
  48. "path": "/o2_core/o2"
  49. },
  50. "language": _lp,
  51. "splitStr": /\s*(?:,|;)\s*/
  52. };
  53. var _attempt = function(){
  54. for (var i = 0, l = arguments.length; i < l; i++){
  55. try {
  56. arguments[i]();
  57. return arguments[i];
  58. } catch (e){}
  59. }
  60. return null;
  61. };
  62. var _typeOf = function(item){
  63. if (item == null) return 'null';
  64. if (item.$family != null) return item.$family();
  65. if (item.constructor == window.Array) return "array";
  66. if (item.nodeName){
  67. if (item.nodeType == 1) return 'element';
  68. if (item.nodeType == 3) return (/\S/).test(item.nodeValue) ? 'textnode' : 'whitespace';
  69. } else if (typeof item.length == 'number'){
  70. if (item.callee) return 'arguments';
  71. }
  72. return typeof item;
  73. };
  74. this.o2.typeOf = _typeOf;
  75. var _addListener = function(dom, type, fn){
  76. if (type == 'unload'){
  77. var old = fn, self = this;
  78. fn = function(){
  79. _removeListener(dom, 'unload', fn);
  80. old();
  81. };
  82. }
  83. if (dom.addEventListener) dom.addEventListener(type, fn, !!arguments[2]);
  84. else dom.attachEvent('on' + type, fn);
  85. };
  86. var _removeListener = function(dom, type, fn){
  87. if (dom.removeEventListener) dom.removeEventListener(type, fn, !!arguments[2]);
  88. else dom.detachEvent('on' + type, fn);
  89. };
  90. //http request class
  91. var _request = (function(){
  92. var XMLHTTP = function(){ return new XMLHttpRequest(); };
  93. var MSXML2 = function(){ return new ActiveXObject('MSXML2.XMLHTTP'); };
  94. var MSXML = function(){ return new ActiveXObject('Microsoft.XMLHTTP'); };
  95. return _attempt(XMLHTTP, MSXML2, MSXML);
  96. })();
  97. var _returnBase = function(number, base) {
  98. return (number).toString(base).toUpperCase();
  99. };
  100. var _getIntegerBits = function(val, start, end){
  101. var base16 = _returnBase(val, 16);
  102. var quadArray = new Array();
  103. var quadString = '';
  104. var i = 0;
  105. for (i = 0; i < base16.length; i++) {
  106. quadArray.push(base16.substring(i, i + 1));
  107. }
  108. for (i = Math.floor(start / 4); i <= Math.floor(end / 4); i++) {
  109. if (!quadArray[i] || quadArray[i] == '')
  110. quadString += '0';
  111. else
  112. quadString += quadArray[i];
  113. }
  114. return quadString;
  115. };
  116. var _rand = function(max) {
  117. return Math.floor(Math.random() * (max + 1));
  118. };
  119. this.o2.addListener = _addListener;
  120. this.o2.removeListener = _removeListener;
  121. //uuid
  122. var _uuid = function(){
  123. var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
  124. var dc = new Date();
  125. var t = dc.getTime() - dg.getTime();
  126. var tl = _getIntegerBits(t, 0, 31);
  127. var tm = _getIntegerBits(t, 32, 47);
  128. var thv = _getIntegerBits(t, 48, 59) + '1';
  129. var csar = _getIntegerBits(_rand(4095), 0, 7);
  130. var csl = _getIntegerBits(_rand(4095), 0, 7);
  131. var n = _getIntegerBits(_rand(8191), 0, 7)
  132. + _getIntegerBits(_rand(8191), 8, 15)
  133. + _getIntegerBits(_rand(8191), 0, 7)
  134. + _getIntegerBits(_rand(8191), 8, 15)
  135. + _getIntegerBits(_rand(8191), 0, 15);
  136. return tl + tm + thv + csar + csl + n;
  137. };
  138. this.o2.uuid = _uuid;
  139. var _runCallback = function(callback, key, par){
  140. if (typeOf(callback).toLowerCase() === 'function'){
  141. if (key.toLowerCase()==="success") callback.apply(callback, par);
  142. }else{
  143. if (typeOf(callback).toLowerCase()==='object'){
  144. var name = ("on-"+key).camelCase();
  145. if (callback[name]) callback[name].apply(callback, par);
  146. }
  147. }
  148. };
  149. this.o2.runCallback = _runCallback;
  150. //load js, css, html adn all.
  151. var _getAllOptions = function(options){
  152. var doc = (options && options.doc) || document;
  153. if (!doc.unid) doc.unid = _uuid();
  154. return {
  155. "noCache": !!(options && options.nocache),
  156. "reload": !!(options && options.reload),
  157. "sequence": !!(options && options.sequence),
  158. "doc": doc,
  159. "dom": (options && options.dom) || document.body,
  160. "bind": (options && options.bind) || null,
  161. "position": (options && options.position) || "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
  162. }
  163. };
  164. var _getCssOptions = function(options){
  165. var doc = (options && options.doc) || document;
  166. if (!doc.unid) doc.unid = _uuid();
  167. return {
  168. "noCache": !!(options && options.nocache),
  169. "reload": !!(options && options.reload),
  170. "sequence": !!(options && options.sequence),
  171. "doc": doc,
  172. "dom": (options && options.dom) || null
  173. }
  174. };
  175. var _getJsOptions = function(options){
  176. var doc = (options && options.doc) || document;
  177. if (!doc.unid) doc.unid = _uuid();
  178. return {
  179. "noCache": !!(options && options.nocache),
  180. "reload": !!(options && options.reload),
  181. "sequence": (!(options && options.sequence == false)),
  182. "doc": doc
  183. }
  184. };
  185. var _getHtmlOptions = function(options){
  186. var doc = (options && options.doc) || document;
  187. if (!doc.unid) doc.unid = _uuid();
  188. return {
  189. "noCache": !!(options && options.nocache),
  190. "reload": !!(options && options.reload),
  191. "sequence": !!(options && options.sequence),
  192. "doc": doc,
  193. "dom": (options && options.dom) || null,
  194. "bind": (options && options.bind) || null,
  195. "position": (options && options.position) || "beforeend" //'beforebegin' 'afterbegin' 'beforeend' 'afterend'
  196. }
  197. };
  198. var _xhr_get = function(url, success, failure, completed){
  199. var xhr = new _request();
  200. xhr.open("GET", url, true);
  201. var _checkCssLoaded= function(_, err){
  202. if (!(xhr.readyState == 4)) return;
  203. if (err){
  204. if (completed) completed(xhr);
  205. return;
  206. }
  207. _removeListener(xhr, 'readystatechange', _checkCssLoaded);
  208. _removeListener(xhr, 'load', _checkCssLoaded);
  209. _removeListener(xhr, 'error', _checkCssErrorLoaded);
  210. if (err) {failure(xhr); return}
  211. var status = xhr.status;
  212. status = (status == 1223) ? 204 : status;
  213. if ((status >= 200 && status < 300))
  214. success(xhr);
  215. else if ((status >= 300 && status < 400))
  216. failure(xhr);
  217. else
  218. failure(xhr);
  219. if (completed) completed(xhr);
  220. };
  221. var _checkCssErrorLoaded= function(err){ _checkCssLoaded(err) };
  222. if ("load" in xhr) _addListener(xhr, "load", _checkCssLoaded);
  223. if ("error" in xhr) _addListener(xhr, "load", _checkCssErrorLoaded);
  224. _addListener(xhr, "readystatechange", _checkCssLoaded);
  225. xhr.send();
  226. };
  227. var _loadSequence = function(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun){
  228. loadSingle(ms[n], function(module){
  229. if (module) thisLoaded.push(module);
  230. n++;
  231. if (fun) fun(module);
  232. if (n===ms.length){
  233. if (cb) cb(thisLoaded);
  234. }else{
  235. _loadSequence(ms, cb, op, n, thisLoaded, loadSingle, uuid, fun);
  236. }
  237. }, op, uuid);
  238. };
  239. var _loadDisarray = function(ms, cb, op, thisLoaded, loadSingle, uuid, fun){
  240. var count=0;
  241. for (var i=0; i<ms.length; i++){
  242. loadSingle(ms[i], function(module){
  243. if (module) thisLoaded.push(module);
  244. count++;
  245. if (fun) fun(module);
  246. if (count===ms.length) if (cb) cb(thisLoaded);
  247. }, op, uuid);
  248. }
  249. };
  250. //load js
  251. //use framework url
  252. var _frameworks = {
  253. "o2.core": ["/o2_core/o2/o2.core.js"],
  254. "o2.more": ["/o2_core/o2/o2.more.js"],
  255. "ie_adapter": ["/o2_lib/o2/ie_adapter.js"],
  256. "jquery": ["/o2_lib/jquery/jquery.min.js"],
  257. "mootools": ["/o2_lib/mootools/mootools-1.6.0_all.js"],
  258. "ckeditor": ["/o2_lib/htmleditor/ckeditor4114/ckeditor.js"],
  259. "ckeditor5": ["/o2_lib/htmleditor/ckeditor5-12-1-0/ckeditor.js"],
  260. "raphael": ["/o2_lib/raphael/raphael.js"],
  261. "d3": ["/o2_lib/d3/d3.min.js"],
  262. "ace": ["/o2_lib/ace/src-noconflict/ace.js","/o2_lib/ace/src-noconflict/ext-language_tools.js"],
  263. "JSBeautifier": ["/o2_lib/JSBeautifier/beautify.js"],
  264. "JSBeautifier_css": ["/o2_lib/JSBeautifier/beautify-css.js"],
  265. "JSBeautifier_html": ["/o2_lib/JSBeautifier/beautify-html.js"],
  266. "JSONTemplate": ["/o2_lib/mootools/plugin/Template.js"],
  267. "kity": ["/o2_lib/kityminder/kity/kity.min.js"],
  268. "kityminder": ["/o2_lib/kityminder/core/dist/kityminder.core.js"]
  269. };
  270. var _loaded = {};
  271. var _loadedCss = {};
  272. var _loadedHtml = {};
  273. var _loadCssRunning = {};
  274. var _loadCssQueue = [];
  275. var _loadSingle = function(module, callback, op){
  276. var url = module;
  277. var uuid = _uuid();
  278. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uuid : addr_uri+"?v="+uuid;
  279. var key = encodeURIComponent(url+op.doc.unid);
  280. if (!op.reload) if (_loaded[key]){
  281. if (callback)callback(); return;
  282. }
  283. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  284. var s = op.doc.createElement('script');
  285. head.appendChild(s);
  286. s.id = uuid;
  287. s.src = url;
  288. var _checkScriptLoaded = function(_, isAbort, err){
  289. if (isAbort || !s.readyState || s.readyState === "loaded" || s.readyState === "complete") {
  290. var scriptObj = {"module": module, "id": uuid, "script": s, "doc": op.doc};
  291. if (!err) _loaded[key] = scriptObj;
  292. _removeListener(s, 'readystatechange', _checkScriptLoaded);
  293. _removeListener(s, 'load', _checkScriptLoaded);
  294. _removeListener(s, 'error', _checkScriptErrorLoaded);
  295. if (!isAbort || err){
  296. if (err){
  297. if (s) head.removeChild(s);
  298. if (callback)callback();
  299. }else{
  300. //head.removeChild(s);
  301. if (callback)callback(scriptObj);
  302. }
  303. }
  304. }
  305. };
  306. var _checkScriptErrorLoaded = function(e, err){
  307. console.log("Error: load javascript module: "+module);
  308. _checkScriptLoaded(e, true, "error");
  309. };
  310. if ('onreadystatechange' in s) _addListener(s, 'readystatechange', _checkScriptLoaded);
  311. _addListener(s, 'load', _checkScriptLoaded);
  312. _addListener(s, 'error', _checkScriptErrorLoaded);
  313. };
  314. var _load = function(urls, options, callback){
  315. var ms = (_typeOf(urls)==="array") ? urls : [urls];
  316. var op = (_typeOf(options)==="object") ? _getJsOptions(options) : _getJsOptions(null);
  317. var cb = (_typeOf(options)==="function") ? options : callback;
  318. var modules = [];
  319. for (var i=0; i<ms.length; i++){
  320. var url = ms[i];
  321. var module = _frameworks[url] || url;
  322. if (_typeOf(module)==="array"){
  323. modules = modules.concat(module)
  324. }else{
  325. modules.push(module)
  326. }
  327. }
  328. var thisLoaded = [];
  329. if (op.sequence){
  330. _loadSequence(modules, cb, op, 0, thisLoaded, _loadSingle);
  331. }else{
  332. _loadDisarray(modules, cb, op, thisLoaded, _loadSingle);
  333. }
  334. };
  335. this.o2.load = _load;
  336. //load css
  337. var _loadSingleCss = function(module, callback, op, uuid){
  338. var url = module;
  339. var uid = _uuid();
  340. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  341. var key = encodeURIComponent(url+op.doc.unid);
  342. if (_loadCssRunning[key]){
  343. _loadCssQueue.push(function(){
  344. _loadSingleCss(module, callback, op, uuid);
  345. });
  346. return;
  347. }
  348. if (_loadedCss[key]) uuid = _loadedCss[key]["class"];
  349. if (op.dom) _parseDom(op.dom, function(node){ if (node.className.indexOf(uuid) == -1) node.className += ((node.className) ? " "+uuid : uuid);}, op.doc);
  350. var completed = function(){
  351. if (_loadCssRunning[key]){
  352. _loadCssRunning[key] = false;
  353. delete _loadCssRunning[key];
  354. }
  355. if (_loadCssQueue && _loadCssQueue.length){
  356. (_loadCssQueue.shift())();
  357. }
  358. };
  359. if (_loadedCss[key])if (!op.reload){
  360. if (callback)callback(_loadedCss[key]);
  361. completed();
  362. return;
  363. }
  364. var success = function(xhr){
  365. var cssText = xhr.responseText;
  366. try{
  367. if (cssText){
  368. if (op.bind) cssText = cssText.bindJson(op.bind);
  369. if (op.dom){
  370. var rex = new RegExp("(.+)(?=\\{)", "g");
  371. var match;
  372. while ((match = rex.exec(cssText)) !== null) {
  373. var prefix = "." + uuid + " ";
  374. var rule = prefix + match[0];
  375. cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length);
  376. rex.lastIndex = rex.lastIndex + prefix.length;
  377. }
  378. }
  379. var style = op.doc.createElement("style");
  380. style.setAttribute("type", "text/css");
  381. var head = (op.doc.head || op.doc.getElementsByTagName("head")[0] || op.doc.documentElement);
  382. head.appendChild(style);
  383. if(style.styleSheet){
  384. var setFunc = function(){
  385. style.styleSheet.cssText = cssText;
  386. };
  387. if(style.styleSheet.disabled){
  388. setTimeout(setFunc, 10);
  389. }else{
  390. setFunc();
  391. }
  392. }else{
  393. var cssTextNode = op.doc.createTextNode(cssText);
  394. style.appendChild(cssTextNode);
  395. }
  396. }
  397. style.id = uid;
  398. var styleObj = {"module": module, "id": uid, "style": style, "doc": op.doc, "class": uuid};
  399. _loadedCss[key] = styleObj;
  400. if (callback) callback(styleObj);
  401. }catch (e){
  402. if (callback) callback();
  403. return;
  404. }
  405. };
  406. var failure = function(xhr){
  407. console.log("Error: load css module: "+module);
  408. if (callback) callback();
  409. };
  410. _loadCssRunning[key] = true;
  411. _xhr_get(url, success, failure, completed);
  412. };
  413. var _parseDomString = function(dom, fn, sourceDoc){
  414. var doc = sourceDoc || document;
  415. var list = doc.querySelectorAll(dom);
  416. if (list.length) for (var i=0; i<list.length; i++) _parseDomElement(list[i], fn);
  417. };
  418. var _parseDomElement = function(dom, fn){
  419. if (fn) fn(dom);
  420. };
  421. var _parseDom = function(dom, fn, sourceDoc){
  422. var domType = _typeOf(dom);
  423. if (domType==="string") _parseDomString(dom, fn, sourceDoc);
  424. if (domType==="element") _parseDomElement(dom, fn);
  425. if (domType==="array") for (var i=0; i<dom.length; i++) _parseDom(dom[i], fn, sourceDoc);
  426. };
  427. var _loadCss = function(modules, options, callback){
  428. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  429. var op = (_typeOf(options)==="object") ? _getCssOptions(options) : _getCssOptions(null);
  430. var cb = (_typeOf(options)==="function") ? options : callback;
  431. var uuid = "css"+_uuid();
  432. var thisLoaded = [];
  433. if (op.sequence){
  434. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleCss, uuid);
  435. }else{
  436. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleCss, uuid);
  437. }
  438. };
  439. var _removeCss = function(modules, doc){
  440. var thisDoc = doc || document;
  441. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  442. for (var i=0; i<ms.length; i++){
  443. var module = modules[i];
  444. var k = encodeURIComponent(module+(thisDoc.unid||""));
  445. var removeCss = _loadedCss[k];
  446. if (!removeCss) for (key in _loadedCss){
  447. if (_loadedCss[key].id==module){
  448. removeCss = _loadedCss[key];
  449. k = key;
  450. break;
  451. }
  452. }
  453. if (removeCss){
  454. delete _loadedCss[k];
  455. var styleNode = removeCss.doc.getElementById(removeCss.id);
  456. if (styleNode) styleNode.parentNode.removeChild(styleNode);
  457. removeCss = null;
  458. }
  459. }
  460. };
  461. this.o2.loadCss = _loadCss;
  462. this.o2.removeCss = _removeCss;
  463. Element.prototype.loadCss = function(modules, options, callback){
  464. var op = (_typeOf(options)==="object") ? options : {};
  465. var cb = (_typeOf(options)==="function") ? options : callback;
  466. op.dom = this;
  467. _loadCss(modules, op, cb);
  468. };
  469. //load html
  470. _loadSingleHtml = function(module, callback, op){
  471. var url = module;
  472. var uid = _uuid();
  473. if (op.noCache) url = (url.indexOf("?")!==-1) ? url+"&v="+uid : url+"?v="+uid;
  474. var key = encodeURIComponent(url+op.doc.unid);
  475. if (!op.reload) if (_loadedHtml[key]){ if (callback)callback(_loadedHtml[key]); return; }
  476. var success = function(xhr){
  477. var htmlObj = {"module": module, "id": uid, "data": xhr.responseText, "doc": op.doc};
  478. _loadedHtml[key] = htmlObj;
  479. if (callback) callback(htmlObj);
  480. };
  481. var failure = function(){
  482. console.log("Error: load html module: "+module);
  483. if (callback) callback();
  484. };
  485. _xhr_get(url, success, failure);
  486. };
  487. var _injectHtml = function(op, data){
  488. if (op.bind) data = data.bindJson(op.bind);
  489. if (op.dom) _parseDom(op.dom, function(node){ node.insertAdjacentHTML(op.position, data) }, op.doc);
  490. };
  491. var _loadHtml = function(modules, options, callback){
  492. var ms = (_typeOf(modules)==="array") ? modules : [modules];
  493. var op = (_typeOf(options)==="object") ? _getHtmlOptions(options) : _getHtmlOptions(null);
  494. var cb = (_typeOf(options)==="function") ? options : callback;
  495. var thisLoaded = [];
  496. if (op.sequence){
  497. _loadSequence(ms, cb, op, 0, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  498. }else{
  499. _loadDisarray(ms, cb, op, thisLoaded, _loadSingleHtml, null, function(html){ if (html) _injectHtml(op, html.data ); });
  500. }
  501. };
  502. this.o2.loadHtml = _loadHtml;
  503. Element.prototype.loadHtml = function(modules, options, callback){
  504. var op = (_typeOf(options)==="object") ? options : {};
  505. var cb = (_typeOf(options)==="function") ? options : callback;
  506. op.dom = this;
  507. _loadHtml(modules, op, cb);
  508. };
  509. //load all
  510. _loadAll = function(modules, options, callback){
  511. //var ms = (_typeOf(modules)==="array") ? modules : [modules];
  512. var op = (_typeOf(options)==="object") ? _getAllOptions(options) : _getAllOptions(null);
  513. var cb = (_typeOf(options)==="function") ? options : callback;
  514. var ms, htmls, styles, sctipts;
  515. var _htmlLoaded=(!modules.html), _cssLoaded=(!modules.css), _jsLoaded=(!modules.js);
  516. var _checkloaded = function(){
  517. if (_htmlLoaded && _cssLoaded && _jsLoaded) if (cb) cb(htmls, styles, sctipts);
  518. };
  519. if (modules.html){
  520. _loadHtml(modules.html, op, function(h){
  521. htmls = h;
  522. _htmlLoaded = true;
  523. _checkloaded();
  524. });
  525. }
  526. if (modules.css){
  527. _loadCss(modules.css, op, function(s){
  528. styles = s;
  529. _cssLoaded = true;
  530. _checkloaded();
  531. });
  532. }
  533. if (modules.js){
  534. _load(modules.js, op, function(s){
  535. sctipts = s;
  536. _jsLoaded = true;
  537. _checkloaded();
  538. });
  539. }
  540. };
  541. this.o2.loadAll = _loadAll;
  542. Element.prototype.loadAll = function(modules, options, callback){
  543. var op = (_typeOf(options)==="object") ? options : {};
  544. var cb = (_typeOf(options)==="function") ? options : callback;
  545. op.dom = this;
  546. _loadAll(modules, op, cb);
  547. };
  548. var _getIfBlockEnd = function(v){
  549. var rex = /(\{\{if\s+)|(\{\{\s*end if\s*\}\})/gmi;
  550. var rexEnd = /\{\{\s*end if\s*\}\}/gmi;
  551. var subs = 1;
  552. while ((match = rex.exec(v)) !== null) {
  553. var fullMatch = match[0];
  554. if (fullMatch.search(rexEnd)!==-1){
  555. subs--;
  556. if (subs==0) break;
  557. }else{
  558. subs++
  559. }
  560. }
  561. if (match) return {"codeIndex": match.index, "lastIndex": rex.lastIndex};
  562. return {"codeIndex": v.length-1, "lastIndex": v.length-1};
  563. }
  564. var _getEachBlockEnd = function(v){
  565. var rex = /(\{\{each\s+)|(\{\{\s*end each\s*\}\})/gmi;
  566. var rexEnd = /\{\{\s*end each\s*\}\}/gmi;
  567. var subs = 1;
  568. while ((match = rex.exec(v)) !== null) {
  569. var fullMatch = match[0];
  570. if (fullMatch.search(rexEnd)!==-1){
  571. subs--;
  572. if (subs==0) break;
  573. }else{
  574. subs++;
  575. }
  576. }
  577. if (match) return {"codeIndex": match.index, "lastIndex": rex.lastIndex};
  578. return {"codeIndex": v.length-1, "lastIndex": v.length-1};
  579. }
  580. var _parseHtml = function(str, json){
  581. var v = str;
  582. var rex = /(\{\{\s*)[\s\S]*?(\s*\}\})/gmi;
  583. var match;
  584. while ((match = rex.exec(v)) !== null) {
  585. var fullMatch = match[0];
  586. var offset = 0;
  587. //if statement begin
  588. if (fullMatch.search(/\{\{if\s+/i)!==-1){
  589. //找到对应的end if
  590. var condition = fullMatch.replace(/^\{\{if\s*/i, "");
  591. condition = condition.replace(/\s*\}\}$/i, "");
  592. var flag = _jsonText(json, condition, "boolean");
  593. var tmpStr = v.substring(rex.lastIndex, v.length);
  594. var endIfIndex = _getIfBlockEnd(tmpStr);
  595. if (flag){ //if 为 true
  596. var parseStr = _parseHtml(tmpStr.substring(0, endIfIndex.codeIndex), json);
  597. var vLeft = v.substring(0, match.index);
  598. var vRight = v.substring(rex.lastIndex+endIfIndex.lastIndex, v.length);
  599. v = vLeft + parseStr + vRight;
  600. offset = parseStr.length - fullMatch.length;
  601. }else{
  602. v = v.substring(0, match.index) + v.substring(rex.lastIndex+endIfIndex.lastIndex, v.length);
  603. offset = 0-fullMatch.length;
  604. }
  605. }else if (fullMatch.search(/\{\{each\s+/)!==-1) { //each statement
  606. var itemString = fullMatch.replace(/^\{\{each\s*/, "");
  607. itemString = itemString.replace(/\s*\}\}$/, "");
  608. var eachValue = _jsonText(json, itemString, "object");
  609. var tmpEachStr = v.substring(rex.lastIndex, v.length);
  610. var endEachIndex = _getEachBlockEnd(tmpEachStr);
  611. var parseEachStr = tmpEachStr.substring(0, endEachIndex.codeIndex);
  612. var eachResult = "";
  613. if (eachValue && _typeOf(eachValue)==="array"){
  614. for (var i=0; i<eachValue.length; i++){
  615. eachValue[i]._ = json;
  616. eachResult += _parseHtml(parseEachStr, eachValue[i]);
  617. }
  618. var eLeft = v.substring(0, match.index);
  619. var eRight = v.substring(rex.lastIndex+endEachIndex.lastIndex, v.length);
  620. v = eLeft + eachResult + eRight;
  621. offset = eachResult.length - fullMatch.length;
  622. }else{
  623. v = v.substring(0, match.index) + v.substring(rex.lastIndex+endEachIndex.lastIndex, v.length);
  624. offset = 0-fullMatch.length;
  625. }
  626. }else{ //text statement
  627. var text = fullMatch.replace(/^\{\{\s*/, "");
  628. text = text.replace(/\}\}\s*$/, "");
  629. var value = _jsonText(json, text);
  630. offset = value.length-fullMatch.length;
  631. v = v.substring(0, match.index) + value + v.substring(rex.lastIndex, v.length);
  632. }
  633. rex.lastIndex = rex.lastIndex + offset;
  634. }
  635. return v;
  636. };
  637. var _jsonText = function(json, text, type){
  638. try {
  639. var $ = json;
  640. var f = eval("(function($){\n return "+text+";\n})");
  641. returnValue = f.apply(json, [$]);
  642. if (returnValue===undefined) returnValue="";
  643. if (type==="boolean") return (!!returnValue);
  644. if (type==="object") return returnValue;
  645. returnValue = returnValue.toString();
  646. return returnValue || "";
  647. }catch(e){
  648. if (type==="boolean") return false;
  649. if (type==="object") return null;
  650. return "";
  651. }
  652. };
  653. o2.bindJson = function(str, json){
  654. return _parseHtml(str, json);
  655. };
  656. String.prototype.bindJson = function(json){
  657. return _parseHtml(this, json);
  658. };
  659. //dom ready
  660. var _dom = {
  661. ready: false,
  662. loaded: false,
  663. checks: [],
  664. shouldPoll: false,
  665. timer: null,
  666. testElement: document.createElement('div'),
  667. readys: [],
  668. domready: function(){
  669. clearTimeout(_dom.timer);
  670. if (_dom.ready) return;
  671. _dom.loaded = _dom.ready = true;
  672. _removeListener(document, 'DOMContentLoaded', _dom.checkReady);
  673. _removeListener(document, 'readystatechange', _dom.check);
  674. _dom.onReady();
  675. },
  676. check: function(){
  677. for (var i = _dom.checks.length; i--;) if (_dom.checks[i]() && window.MooTools && o2.core && o2.more){
  678. _dom.domready();
  679. return true;
  680. }
  681. return false;
  682. },
  683. poll: function(){
  684. clearTimeout(_dom.timer);
  685. if (!_dom.check()) _dom.timer = setTimeout(_dom.poll, 10);
  686. },
  687. /*<ltIE8>*/
  688. // doScroll technique by Diego Perini http://javascript.nwbox.com/IEContentLoaded/
  689. // testElement.doScroll() throws when the DOM is not ready, only in the top window
  690. doScrollWorks: function(){
  691. try {
  692. _dom.testElement.doScroll();
  693. return true;
  694. } catch (e){}
  695. return false;
  696. },
  697. /*</ltIE8>*/
  698. onReady: function(){
  699. for (var i=0; i<_dom.readys.length; i++){
  700. this.readys[i].apply(window);
  701. }
  702. },
  703. addReady: function(fn){
  704. if (_dom.loaded){
  705. if (fn) fn.apply(window);
  706. }else{
  707. if (fn) _dom.readys.push(fn);
  708. }
  709. return _dom;
  710. },
  711. checkReady: function(){
  712. _dom.checks.push(function(){return true});
  713. _dom.check();
  714. }
  715. };
  716. var _loadO2 = function(){
  717. this.o2.load("o2.core", _dom.check);
  718. this.o2.load("o2.more", _dom.check);
  719. };
  720. _addListener(document, 'DOMContentLoaded', _dom.checkReady);
  721. /*<ltIE8>*/
  722. // If doScroll works already, it can't be used to determine domready
  723. // e.g. in an iframe
  724. if (_dom.testElement.doScroll && !_dom.doScrollWorks()){
  725. _dom.checks.push(_dom.doScrollWorks);
  726. _dom.shouldPoll = true;
  727. }
  728. /*</ltIE8>*/
  729. if (document.readyState) _dom.checks.push(function(){
  730. var state = document.readyState;
  731. return (state == 'loaded' || state == 'complete');
  732. });
  733. if ('onreadystatechange' in document) _addListener(document, 'readystatechange', _dom.check);
  734. else _dom.shouldPoll = true;
  735. if (_dom.shouldPoll) _dom.poll();
  736. if (!window.MooTools){
  737. this.o2.load("mootools", function(){ _loadO2(); _dom.check(); });
  738. }else{
  739. _loadO2();
  740. }
  741. this.o2.addReady = function(fn){ _dom.addReady.call(_dom, fn); };
  742. })();
  743. layout = window.layout || {};
  744. layout.desktop = layout;
  745. var locate = window.location;
  746. layout.protocol = locate.protocol;
  747. layout.session = layout.session || {};
  748. layout.debugger = (locate.href.toString().indexOf("debugger")!==-1);
  749. o2.xApplication = o2.xApplication || {};
  750. o2.xDesktop = o2.xDesktop || {};
  751. o2.xDesktop.requireApp = function(module, clazz, callback, async){
  752. o2.requireApp(module, clazz, callback, async);
  753. };
  754. o2.addReady(function(){
  755. //兼容方法
  756. Element.implement({
  757. "makeLnk": function(options){}
  758. });
  759. //异步载入必要模块
  760. layout.config = null;
  761. var lp = o2.session.path+"/lp/"+o2.language+".js";
  762. var modules = [ "MWF.xDesktop.Common", "MWF.xAction.RestActions",lp];
  763. MWF.require(modules, function(){
  764. if (layout.config) _getDistribute(function(){ _load(); });
  765. });
  766. o2.getJSON("/x_desktop/res/config/config.json", function(config){
  767. layout.config = config;
  768. if (MWF.xDesktop.getServiceAddress) _getDistribute(function(){ _load(); });
  769. });
  770. var _getDistribute = function(callback){
  771. if (layout.config.app_protocol==="auto"){
  772. layout.config.app_protocol = window.location.protocol;
  773. }
  774. MWF.xDesktop.getServiceAddress(layout.config, function(service, center){
  775. layout.serviceAddressList = service;
  776. layout.centerServer = center;
  777. if (callback) callback();
  778. }.bind(this));
  779. };
  780. var _load = function(){
  781. //先判断用户是否登录
  782. MWF.Actions.get("x_organization_assemble_authentication").getAuthentication(function(json){
  783. //用户已经登录
  784. layout.user = json.data;
  785. layout.session = {};
  786. layout.session.user = json.data;
  787. (function(layout){
  788. var _loadResource = function(callback){
  789. var isLoadedA = false;
  790. var isLoadedB = false;
  791. //var isLoadedC = false;
  792. var modules = [
  793. "o2.xDesktop.Dialog",
  794. "MWF.xDesktop.UserData",
  795. "MWF.xDesktop.Access",
  796. "MWF.widget.UUID",
  797. "MWF.xDesktop.Menu",
  798. "MWF.xDesktop.shortcut",
  799. "MWF.widget.PinYin",
  800. "MWF.xDesktop.Access",
  801. "MWF.xDesktop.MessageMobile",
  802. "MWF.xScript.Macro"
  803. ];
  804. //MWF.xDesktop.requireApp("Common", "", null, false);
  805. var _check = function(){ if (isLoadedA && isLoadedB) if (callback) callback(); };
  806. o2.load(["../o2_lib/mootools/plugin/mBox.min.js"], function(){isLoadedA = true; _check();});
  807. o2.require("MWF.widget.Common", function(){
  808. o2.require(modules, function(){
  809. o2.requireApp("Common", "", function(){isLoadedB = true; _check();})
  810. });
  811. });
  812. };
  813. var _loadContent =function(){
  814. _loadResource(function(){
  815. //this.Macro = new MWF.Macro["PageContext"](this);
  816. for (var i=0; i<layout.readys.length; i++){
  817. layout.readys[i].apply(window);
  818. }
  819. });
  820. };
  821. _loadContent();
  822. })(layout);
  823. }, function(){
  824. //用户未经登录
  825. //打开登录页面
  826. var _loadResource = function(callback){
  827. var isLoadedA = false;
  828. var isLoadedB = false;
  829. //var isLoadedC = false;
  830. // var lp = o2.session.path+"/lp/"+o2.language+".js";
  831. var modules = [
  832. "o2.xDesktop.Dialog",
  833. "MWF.xDesktop.UserData",
  834. "MWF.xDesktop.Access",
  835. "MWF.widget.UUID",
  836. "MWF.xDesktop.Menu",
  837. "MWF.xDesktop.shortcut",
  838. "MWF.widget.PinYin",
  839. "MWF.xDesktop.Access",
  840. "MWF.xDesktop.MessageMobile"
  841. ];
  842. //MWF.xDesktop.requireApp("Common", "", null, false);
  843. var _check = function(){ if (isLoadedA && isLoadedB) if (callback) callback(); };
  844. o2.load(["../o2_lib/mootools/plugin/mBox.min.js"], function(){isLoadedA = true; _check();});
  845. o2.require("MWF.widget.Common", function(){
  846. o2.require(modules, function(){
  847. o2.requireApp("Common", "", function(){isLoadedB = true; _check();})
  848. });
  849. });
  850. };
  851. _loadResource(function(){
  852. layout.openLogin();
  853. });
  854. });
  855. layout.openLogin = function(){
  856. MWF.require("MWF.widget.Common", null, false);
  857. MWF.require("MWF.xDesktop.Authentication", function(){
  858. var authentication = new MWF.xDesktop.Authentication({
  859. "onLogin": _load.bind(layout)
  860. });
  861. authentication.loadLogin(document.body);
  862. });
  863. };
  864. };
  865. });
  866. (function(layout){
  867. layout.readys = [];
  868. layout.addReady = function(){
  869. for (var i = 0; i<arguments.length; i++){
  870. if (o2.typeOf(arguments[i])==="function") layout.readys.push(arguments[i]);
  871. }
  872. };
  873. var _requireApp = function(appNames, callback, clazzName){
  874. var appPath = appNames.split(".");
  875. var baseObject = o2.xApplication;
  876. appPath.each(function(path, i){
  877. if (i<(appPath.length-1)){
  878. baseObject[path] = baseObject[path] || {};
  879. }else {
  880. baseObject[path] = baseObject[path] || {"options": Object.clone(MWF.xApplication.Common.options)};
  881. }
  882. baseObject = baseObject[path];
  883. }.bind(this));
  884. if (!baseObject.options) baseObject.options = Object.clone(MWF.xApplication.Common.options);
  885. var _lpLoaded = false;
  886. MWF.xDesktop.requireApp(appNames, "lp."+o2.language, {
  887. "failure": function(){
  888. MWF.xDesktop.requireApp(appNames, "lp.zh-cn", null, false);
  889. }.bind(this)
  890. }, false);
  891. MWF.xDesktop.requireApp(appNames, clazzName, function(){
  892. if (callback) callback(baseObject);
  893. });
  894. };
  895. var _createNewApplication = function(e, appNamespace, appName, options, statusObj){
  896. var app = new appNamespace["Main"](this, options);
  897. app.desktop = layout;
  898. app.inBrowser = true;
  899. app.status = statusObj;
  900. app.load(true);
  901. var appId = appName;
  902. if (options.appId){
  903. appId = options.appId;
  904. }else{
  905. if (appNamespace.options.multitask) appId = appId+"-"+(new MWF.widget.UUID());
  906. }
  907. app.appId = appId;
  908. layout.app = app;
  909. layout.desktop.currentApp = app;
  910. };
  911. var _openWorkAndroid = function(options){
  912. if (window.o2android && window.o2android.openO2Work) {
  913. if (options.workId) {
  914. window.o2android.openO2Work(options.workId, "", title);
  915. } else if (options.workCompletedId) {
  916. window.o2android.openO2Work("", options.workCompletedId, title);
  917. }
  918. return true;
  919. }
  920. return false;
  921. };
  922. var _openWorkIOS = function(options){
  923. if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Work) {
  924. if (options.workId) {
  925. window.webkit.messageHandlers.openO2Work.postMessage({
  926. "work": options.workId,
  927. "workCompleted": "",
  928. "title": title
  929. });
  930. } else if (options.workCompletedId) {
  931. window.webkit.messageHandlers.openO2Work.postMessage({
  932. "work": "",
  933. "workCompleted": options.workCompletedId,
  934. "title": title
  935. });
  936. }
  937. return true;
  938. }
  939. return false;
  940. };
  941. var _openWorkHTML = function(options){
  942. var uri = new URI(window.location.href);
  943. var redirectlink = uri.getData("redirectlink");
  944. if (!redirectlink) {
  945. redirectlink = encodeURIComponent(locate.pathname + locate.search);
  946. } else {
  947. redirectlink = encodeURIComponent(redirectlink);
  948. }
  949. if (options.workId) {
  950. window.location = "workmobilewithaction.html?workid=" + options.workId + "&redirectlink=" + redirectlink;
  951. } else if (options.workCompletedId) {
  952. window.location = "workmobilewithaction.html?workcompletedid=" + options.workCompletedId + "&redirectlink=" + redirectlink;
  953. }
  954. };
  955. var _openWork = function(options){
  956. if (!_openWorkAndroid(options)) if (!_openWorkIOS(options)) _openWorkHTML(options);
  957. };
  958. var _openDocument = function(appNames, options, statusObj){
  959. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  960. if (window.o2android && window.o2android.openO2CmsDocument){
  961. window.o2android.openO2CmsDocument(options.documentId, title);
  962. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsDocument){
  963. window.webkit.messageHandlers.openO2CmsDocument.postMessage({"docId":options.documentId,"docTitle":title});
  964. }else{
  965. window.location = "appMobile.html?"+par;
  966. }
  967. };
  968. var _openCms = function(appNames, options, statusObj){
  969. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  970. if (window.o2android && window.o2android.openO2CmsApplication){
  971. window.o2android.openO2CmsApplication(options.columnId, title);
  972. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2CmsApplication){
  973. window.webkit.messageHandlers.openO2CmsApplication.postMessage(options.columnId);
  974. }else{
  975. window.location = "appMobile.html?"+par;
  976. }
  977. };
  978. var _openMeeting = function(appNames, options, statusObj){
  979. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  980. if (window.o2android && window.o2android.openO2Meeting){
  981. window.o2android.openO2Meeting("");
  982. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Meeting){
  983. window.webkit.messageHandlers.openO2Meeting.postMessage("");
  984. }else{
  985. window.location = "appMobile.html?"+par;
  986. }
  987. };
  988. var _openCalendar = function(appNames, options, statusObj){
  989. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  990. if (window.o2android && window.o2android.openO2Calendar){
  991. window.o2android.openO2Calendar("");
  992. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2Calendar){
  993. window.webkit.messageHandlers.openO2Calendar.postMessage("");
  994. }else{
  995. window.location = "appMobile.html?"+par;
  996. }
  997. };
  998. var _openTaskCenter = function(appNames, options, statusObj){
  999. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  1000. var tab = ((options && options.navi) ? options.navi : "task").toLowerCase();
  1001. if (tab==="done") tab = "taskCompleted";
  1002. if (tab==="readed") tab = "readCompleted";
  1003. if (window.o2android && window.o2android.openO2WorkSpace){
  1004. window.o2android.openO2WorkSpace(tab);
  1005. }else if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.openO2WorkSpace){
  1006. window.webkit.messageHandlers.openO2WorkSpace.postMessage(tab);
  1007. }else{
  1008. window.location = "appMobile.html?"+par;
  1009. }
  1010. };
  1011. var _openApplicationMobile = function(appNames, options, statusObj){
  1012. switch (appNames) {
  1013. case "process.Work":
  1014. _openWork(options);
  1015. break;
  1016. case "cms.Document":
  1017. _openDocument(appNames, options, statusObj);
  1018. break;
  1019. case "cms.Module":
  1020. _openCms(appNames, options, statusObj);
  1021. break;
  1022. case "Meeting":
  1023. _openMeeting(appNames, options, statusObj);
  1024. break;
  1025. case "Calendar":
  1026. _openCalendar(appNames, options, statusObj);
  1027. break;
  1028. case "process.TaskCenter":
  1029. _openTaskCenter(appNames, options, statusObj);
  1030. break;
  1031. default:
  1032. window.location = "appMobile.html?app="+appNames+"&option="+(optionsStr || "")+"&status="+(statusStr || "");
  1033. }
  1034. };
  1035. layout.openApplication = function(e, appNames, options, statusObj){
  1036. if (layout.app){
  1037. if (layout.mobile){
  1038. _openApplicationMobile(appNames, options, statusObj);
  1039. }else{
  1040. var par = "app="+encodeURIComponent(appNames)+"&status="+encodeURIComponent((statusObj)? JSON.encode(statusObj) : "")+"&option="+encodeURIComponent((options)? JSON.encode(options) : "");
  1041. return window.open("app.html?"+par, "_blank");
  1042. }
  1043. }else{
  1044. var appPath = appNames.split(".");
  1045. var appName = appPath[appPath.length-1];
  1046. _requireApp(appNames, function(appNamespace){
  1047. _createNewApplication(e, appNamespace, appName, options, statusObj);
  1048. }.bind(this));
  1049. }
  1050. };
  1051. layout.refreshApp = function(app){
  1052. var status = app.recordStatus();
  1053. var uri = new URI(window.location.href);
  1054. var appNames = uri.getData("app");
  1055. var optionsStr = uri.getData("option");
  1056. var statusStr = uri.getData("status");
  1057. if (status) statusStr = JSON.encode(status);
  1058. var port = uri.get("port");
  1059. window.location = uri.get("scheme") + "://" + uri.get("host") + ((port) ? ":" + port + "/" : "") + uri.get("directory ") + "?app=" + encodeURIComponent(appNames) + "&status=" + encodeURIComponent(statusStr) + "&option=" + encodeURIComponent((options) ? JSON.encode(options) : "");
  1060. };
  1061. layout.load =function(appNames, options, statusObj){
  1062. layout.message = new MWF.xDesktop.MessageMobile();
  1063. layout.message.load();
  1064. layout.apps = [];
  1065. layout.node = $("layout");
  1066. var appName=appNames, m_status=statusObj, option=options;
  1067. var topWindow = window.opener;
  1068. if (topWindow){
  1069. try{
  1070. if (!appName) appName = topWindow.layout.desktop.openBrowserApp;
  1071. if (!m_status) m_status = topWindow.layout.desktop.openBrowserStatus;
  1072. if (!option) option = topWindow.layout.desktop.openBrowserOption;
  1073. }catch(e){}
  1074. }
  1075. layout.openApplication(null, appName, option||{}, m_status);
  1076. }
  1077. })(layout);