jeus.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. if(!dojo._hasResource["jeus.core"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  2. dojo._hasResource["jeus.core"] = true;
  3. dojo.provide("jeus.core");
  4. dojo.require("dojo.parser");
  5. dojo.require("dijit.layout.BorderContainer");
  6. dojo.require("dijit.layout.ContentPane");
  7. dojo.require("dojox.layout.ContentPane");
  8. dojo.require("dijit.layout.AccordionContainer");
  9. dojo.require("dijit.TitlePane");
  10. dojo.require("dijit.Tooltip");
  11. dojo.require("dijit.Dialog");
  12. dojo.require("dijit.form.Button");
  13. dojo.require("dijit.form.Textarea");
  14. dojo.require("dojo.data.ItemFileReadStore");
  15. dojo.require("dijit.Tree");
  16. dojo.require("dojo.i18n");
  17. dojo.require("dojo.io.iframe");
  18. dojo.require("dojo.cache");
  19. dojo.require("dijit.Declaration");
  20. //dojo.registerModulePath("jeus","../../dojo_js");
  21. dojo.require("jeus.Chart");
  22. dojo.require("jeus.Loading");
  23. dojo.require("jeus.Dialog");
  24. dojo.require("jeus.Menu");
  25. dojo.require("jeus.Tree");
  26. dojo.require("jeus.TargetExplorer");
  27. dojo.require("jeus.Palette");
  28. dojo.require("jeus.Stacktrace");
  29. dojo.require("jeus.ListenerConnection");
  30. dojo.requireLocalization("jeus", "common", null, "ROOT,ko");
  31. function decodeURL(str){
  32. var s0, i, j, s, ss, u, n, f;
  33. s0 = ""; // decoded str
  34. for (i = 0; i < str.length; i++){ // scan the source str
  35. s = str.charAt(i);
  36. if (s == "+"){s0 += " ";} // "+" should be changed to SP
  37. else {
  38. if (s != "%"){s0 += s;} // add an unescaped char
  39. else{ // escape sequence decoding
  40. u = 0; // unicode of the character
  41. f = 1; // escape flag, zero means end of this sequence
  42. while (true) {
  43. ss = ""; // local str to parse as int
  44. for (j = 0; j < 2; j++ ) { // get two maximum hex characters for parse
  45. sss = str.charAt(++i);
  46. if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f")) || ((sss >= "A") && (sss <= "F"))) {
  47. ss += sss; // if hex, add the hex character
  48. } else {--i; break;} // not a hex char., exit the loop
  49. }
  50. n = parseInt(ss, 16); // parse the hex str as byte
  51. if (n <= 0x7f){u = n; f = 1;} // single byte format
  52. if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;} // double byte format
  53. if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;} // triple byte format
  54. if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;} // quaternary byte format (extended)
  55. if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;} // not a first, shift and add 6 lower bits
  56. if (f <= 1){break;} // end of the utf byte sequence
  57. if (str.charAt(i + 1) == "%"){ i++ ;} // test for the next shift byte
  58. else {break;} // abnormal, format error
  59. }
  60. s0 += String.fromCharCode(u); // add the escaped character
  61. }
  62. }
  63. }
  64. return s0;
  65. }
  66. (function(){
  67. var jeus = window.jeus;
  68. dojo.mixin(jeus, {
  69. loading: null,
  70. append: function(target, value){
  71. target = dojo.byId(target);
  72. var old = dojo.trim(target.value);
  73. var append = "";
  74. if(!!old){
  75. append = " \r\n";
  76. }
  77. append += value;
  78. target.value = old + append;
  79. },
  80. fireEvent: function(element,event){
  81. if (document.createEventObject){
  82. var evt = document.createEventObject();
  83. return element.fireEvent('on'+event,evt);
  84. }
  85. else{
  86. // dispatch for firefox + others
  87. // var evt = document.createEvent("HTMLEvents");
  88. // evt.initEvent(event, true, true ); // event type,bubbling,cancelable
  89. // return !element.dispatchEvent(evt);
  90. var evt = document.createEvent('MouseEvents');
  91. evt.initMouseEvent( event, true, true, window, 0, 0, 0, 0, 0, false, false, true, false, 0, null );
  92. element.dispatchEvent(evt);
  93. }
  94. },
  95. showContextMenu: function(evt, href) {
  96. var tn = dijit.getEnclosingWidget(evt.target);
  97. if(!!tn){
  98. var item = tn.item;
  99. var store = tn.tree.model.store;
  100. var type = store.getValue(item, "type");
  101. if(!!type){
  102. if(!this.contextmenus)
  103. this.contextmenus = [];
  104. if(!this.contextmenus[type]){
  105. dojo.xhrGet({
  106. url: href,
  107. content:{
  108. "type": type
  109. },
  110. handleAs: "json",
  111. sync: true,
  112. load: dojo.hitch(this, function(response, ioArgs){
  113. if(response.success){
  114. this.contextmenus[type] = response.menu;
  115. }
  116. })
  117. });
  118. }
  119. var menu = this.contextmenus[type];
  120. if( menu ){
  121. menu = dojo.clone(menu);
  122. menu.objectName = store.getValue(item, "objectName");
  123. menu.state = store.getValue(item, "state");
  124. menu.name = store.getValue(item, "label");
  125. var treeMenu = this._makeMenu(menu, false);
  126. treeMenu.startup();
  127. treeMenu._openMyself(evt);
  128. }
  129. }
  130. }
  131. dojo.stopEvent(evt);
  132. return false;
  133. },
  134. _makeMenu: function(items, isTop){
  135. var menu2 = dijit.byId("nodeTreeMenu");
  136. if(menu2 !== undefined){
  137. menu2.destroy(true);
  138. }
  139. menu2 = new dijit.Menu({id: "nodeTreeMenu", contextMenuForWindow: isTop});
  140. dojo.forEach(items, function(itemJson){
  141. // if submenu is specified, create the submenu and then make submenuId point to it
  142. if(itemJson.separator){
  143. menu2.addChild(new dijit.MenuSeparator());
  144. }else{
  145. if(itemJson.submenu){
  146. var submenu = this._makeMenu(itemJson.submenu, false);
  147. itemJson.submenuId = submenu.widgetId;
  148. }
  149. itemJson.label = itemJson.label.replace(/\{0\}/, items.name);
  150. var item = new jeus.MenuItem(itemJson);
  151. if( items.state && itemJson.enableStates && itemJson.enableStates.indexOf(items.state) < 0 ){
  152. item.setDisabled(true);
  153. }else{
  154. item.objectName = items.objectName;
  155. }
  156. menu2.addChild(item);
  157. }
  158. });
  159. return menu2;
  160. },
  161. toggleButton: function(obj){
  162. var button = dojo.byId(obj);
  163. var detail = dojo.byId(button.id + "_detail");
  164. if(!detail) return;
  165. var messages = dojo.i18n.getLocalization("jeus", "common");
  166. if(dojo.style(detail, "display") == 'block'){
  167. dojo.style(detail, "display", "none");
  168. dojo.attr(button, "value", messages.detail);
  169. }else{
  170. dojo.style(detail, "display", "block");
  171. detail.focus();
  172. dojo.attr(button, "value", messages.hide);
  173. }
  174. },
  175. showElementDocument: function(obj){
  176. var panel = dijit.byId("ElementDocument");
  177. if(!panel){
  178. var node = document.createElement("div");
  179. dojo.body().appendChild(node);
  180. var messages = dojo.i18n.getLocalization("jeus", "common");
  181. var params = {
  182. id : "ElementDocument",
  183. title : messages.elementDocument,
  184. refocus : false,
  185. autofocus : false,
  186. duration : 300
  187. };
  188. panel = new jeus.Dialog(params, node);
  189. panel.resize({ w:600 });
  190. }
  191. panel.setHref(obj.href);
  192. panel.show();
  193. },
  194. alert: function(message){
  195. var panel = dijit.byId("AlertDialog");
  196. if(!panel){
  197. var node = document.createElement("div");
  198. dojo.body().appendChild(node);
  199. var messages = dojo.i18n.getLocalization("jeus", "common");
  200. var params = {
  201. id : "AlertDialog",
  202. title : messages.info,
  203. refocus : false,
  204. autofocus : true,
  205. duration : 50,
  206. templateString: dojo.cache("jeus", "templates/AlertDialog.html")
  207. };
  208. panel = new jeus.Dialog(params, node);
  209. panel.resize({ w:400 });
  210. }
  211. panel.setContent(message);
  212. panel.show();
  213. },
  214. confirm: function(message, func){
  215. var panel = dijit.byId("ConfirmDialog");
  216. if(!panel){
  217. var node = document.createElement("div");
  218. dojo.body().appendChild(node);
  219. var messages = dojo.i18n.getLocalization("jeus", "common");
  220. var params = {
  221. id : "ConfirmDialog",
  222. title : messages.confirm,
  223. refocus : false,
  224. autofocus : true,
  225. duration : 50,
  226. templateString: dojo.cache("jeus", "templates/ConfirmDialog.html")
  227. };
  228. panel = new jeus.Dialog(params, node);
  229. panel.resize({ w:400 });
  230. }
  231. panel.setContent(message);
  232. panel.execute = func;
  233. panel.show();
  234. },
  235. onExtendedCheckbox: function(obj, parent){
  236. var checked = !obj.checked;
  237. dojo.query("input,textarea", dojo.byId(parent)).attr("disabled", checked);
  238. dojo.attr(dojo.byId(obj), "disabled", false);
  239. return true;
  240. },
  241. onChangeInnerTabPanel: function(obj, targetId, index){
  242. dojo.xhrGet({
  243. url: obj.href + "&json=true"
  244. });
  245. dojo.query("> ul.top_nav > li > a", dojo.byId(targetId)).removeClass("selected");
  246. dojo.addClass(dojo.byId(obj), "selected");
  247. dojo.query("> div.top_content", dojo.byId(targetId)).style("display","none");
  248. dojo.style(targetId + "_" + index, "display","block");
  249. },
  250. helpURL: null,
  251. popupHelp: function(){
  252. var helpURL = this.helpURL;
  253. if(helpURL != null) {
  254. helpURL = helpURL.substring(1);
  255. } else {
  256. helpURL = "onlinehelp.html";
  257. }
  258. var src = "./app?page=OnlineHelp_Main&service=external&sp=" + escape(helpURL);
  259. window.open(src , "help", "width=971,height=600,scrollbars=yes,toolbars=no,resizable=no").focus();
  260. },
  261. loadContent: function(page, href, noHistory){
  262. dijit.byId(page).attr("href", href);
  263. if(page == "rightPane" && !noHistory){
  264. var data = href || "";
  265. if(data.indexOf("service=external") != -1){
  266. jeus.back.addToHistory(href);
  267. }
  268. }
  269. },
  270. loadRightPane: function(evt){
  271. var href = evt.currentTarget.href || evt.target.href;
  272. this.loadContent("rightPane", href);
  273. dojo.stopEvent(evt);
  274. },
  275. rightPaneInit: function(){
  276. dojo.query('a[href]:not([href^="javascript:"]):not([onclick])', this.containerNode || this.domNode).forEach(function(src){
  277. if(dojo.hasClass(src, "confirm")){
  278. this.connect(src, "onclick", (function(){
  279. var message = dojo.attr(src, "message");
  280. var href = dojo.attr(src, "href");
  281. return function(e){
  282. dojo.stopEvent(e);
  283. jeus.confirm(decodeURL(message), function(){
  284. jeus.loadContent("rightPane", href);
  285. });
  286. };
  287. })());
  288. }else{
  289. this.connect(src, "onclick", dojo.hitch(jeus, "loadRightPane"));
  290. }
  291. }, this);
  292. dojo.query('input[type=button].refresh', this.containerNode || this.domNode).forEach(function(src){
  293. this.connect(dojo.byId(src), "onclick", function(e){
  294. dojo.stopEvent(e);
  295. dijit.byId("rightPane").refresh();
  296. });
  297. }, this);
  298. dojo.query('input[type=reset]', this.containerNode || this.domNode).forEach(function(src){
  299. this.connect(dojo.byId(src), "onclick", function(e){
  300. dojo.stopEvent(e);
  301. var messages = dojo.i18n.getLocalization("jeus", "common");
  302. var target = e.currentTarget;
  303. jeus.confirm(messages.resetConfirm, dojo.hitch(this, function(){
  304. target.form.reset();
  305. }));
  306. });
  307. }, this);
  308. dojo.query('form', this.containerNode || this.domNode).forEach(dojo.hitch(this, jeus.form.registerForm), this);
  309. },
  310. upload: function(element){
  311. jeus.loading.show();
  312. dojo.io.iframe.send({
  313. form: element.form,
  314. handleAs: "text",
  315. handle: function(response,ioArgs){
  316. dijit.byId("rightPane").setContent(response);
  317. jeus.loading.hide();
  318. }
  319. });
  320. },
  321. onChangeAllCheck: function(obj, target){
  322. dojo.query("td input[type=checkbox]:not([disabled])", dojo.byId(target)).forEach(function(src){
  323. src.checked = obj.checked;
  324. },this);
  325. }
  326. });
  327. })();
  328. (function(){
  329. jeus.form = {
  330. forms:{},
  331. registerForm: function(id) {
  332. var form = dojo.byId(id);
  333. if(!form){
  334. dojo.raise("Form not found with id " + id);
  335. return;
  336. }
  337. // make sure id is correct just in case node passed in has only name
  338. id = dojo.attr(form, "id");
  339. // if previously connected, cleanup and reconnect
  340. if(jeus.form.forms[id]){
  341. delete jeus.form.forms[id];
  342. }
  343. jeus.form.forms[id] = {};
  344. var elements = dojo.query("[type=submit]", form).concat(dojo.query("[type=button]", form), dojo.query("input[type=image]", form));
  345. var sync = dojo.hasClass(form, "sync");
  346. if(sync){
  347. dojo.forEach(elements, function(src){
  348. var message = dojo.attr(src, "message");
  349. if(!!!message){
  350. }else{
  351. this.connect(src, "onclick", (function(message){
  352. return function(e){
  353. dojo.stopEvent(e);
  354. var target = e.currentTarget || e.target;
  355. jeus.confirm(message, dojo.hitch(this, function(){
  356. target.form.submit();
  357. }));
  358. };
  359. })(message));
  360. }
  361. }, this);
  362. }else{
  363. dojo.forEach(elements, function(src){
  364. var message = dojo.attr(src, "message");
  365. if(!!!message){
  366. this.connect(src, "onclick", dojo.hitch(jeus.form, "inputClicked"));
  367. }else{
  368. this.connect(src, "onclick", (function(message){
  369. return function(e){
  370. dojo.stopEvent(e);
  371. jeus.confirm(message, dojo.hitch(this, function(){
  372. jeus.form.inputClicked(e);
  373. jeus.form.overrideSubmit(e);
  374. }));
  375. };
  376. })(message));
  377. }
  378. }, this);
  379. this.connect(form, "onsubmit", dojo.hitch(jeus.form, "overrideSubmit"));
  380. }
  381. },
  382. overrideSubmit: function(e){
  383. dojo.stopEvent(e);
  384. var elm = e.target;
  385. if (dojo.exists("form", elm)){
  386. elm = elm.form;
  387. }
  388. jeus.form.submitAsync(elm);
  389. },
  390. inputClicked: function(e){
  391. var node = e.currentTarget || e.target;
  392. if(node.disabled || !dojo.exists("form", node)){
  393. dojo.stopEvent(e);
  394. return;
  395. }
  396. jeus.form.forms[node.form.getAttribute("id")].clickedButton = node;
  397. },
  398. submitAsync: function(form, content, submitName, parms){
  399. form = dojo.byId(form);
  400. if(!form){
  401. console.log("Form not found with id " + id);
  402. return;
  403. }
  404. var formId = dojo.attr(form, "id");
  405. if (submitName){
  406. var previous = form.submitname.value;
  407. form.submitname.value=submitName;
  408. if(!content){ content={}; }
  409. if(form[submitName]){
  410. content[submitName]=form[submitName].value;
  411. }
  412. }
  413. // handle submissions from input buttons
  414. if (dojo.exists("clickedButton", jeus.form.forms[formId])) {
  415. if (!content) { content={}; }
  416. content[jeus.form.forms[formId].clickedButton.getAttribute("name")]=jeus.form.forms[formId].clickedButton.getAttribute("value");
  417. delete jeus.form.forms[formId].clickedButton;
  418. }
  419. var kwArgs={
  420. form:form,
  421. sync:false,
  422. content:content,
  423. useCache:true,
  424. preventCache:true,
  425. error: function(response, ioArgs){
  426. jeus.loading.hide();
  427. var rightPane = dijit.byId("rightPane");
  428. rightPane._onError.call(rightPane, 'Download', response);
  429. },
  430. load: function(response, ioArgs){
  431. jeus.loading.hide();
  432. dijit.byId("rightPane").setContent(response);
  433. },
  434. handle: function(response, ioArgs){
  435. }
  436. };
  437. // check for override
  438. if (parms){
  439. if (dojo.exists("url", parms)) { kwArgs.url=parms.url; }
  440. }
  441. jeus.loading.show();
  442. dojo.xhrPost(kwArgs);
  443. if (submitName){
  444. form.submitname.value = previous;
  445. }
  446. }
  447. };
  448. })();
  449. (function(){
  450. var back = jeus.back = {};
  451. var currentHref = null;
  452. var historyIframe = null;
  453. function getUrlQuery(url){
  454. var segments = url.split("?");
  455. if(segments.length < 2){
  456. return null; //null
  457. }
  458. else{
  459. return segments[1]; //String
  460. }
  461. }
  462. function loadIframeHistory(href){
  463. var url = (dojo.config["dojoIframeHistoryUrl"] || dojo.moduleUrl("jeus", "resources/iframe_history.html")) + "?" + encodeURIComponent(href);
  464. if(historyIframe){
  465. dojo.isSafari ? historyIframe.location = url : window.frames[historyIframe.name].location = url;
  466. }else{
  467. }
  468. return url; //String
  469. }
  470. back.init = function(href){
  471. if(dojo.byId("dj_history")){ return; } // prevent reinit
  472. currentHref = href;
  473. var src = dojo.config["dojoIframeHistoryUrl"] || dojo.moduleUrl("jeus", "resources/iframe_history.html") + "?" + encodeURIComponent(href);
  474. document.write('<iframe style="border:0;width:1px;height:1px;position:absolute;visibility:hidden;bottom:0;right:0;" name="dj_history" id="dj_history" src="' + src + '"></iframe>');
  475. };
  476. back.addToHistory = function(href){
  477. if(!historyIframe){
  478. if(dojo.config["useXDomain"] && !dojo.config["dojoIframeHistoryUrl"]){}
  479. historyIframe = window.frames["dj_history"];
  480. }
  481. currentHref = href;
  482. var url = loadIframeHistory(href);
  483. };
  484. back._iframeLoaded = function(evt, ifrLoc){
  485. var query = getUrlQuery(ifrLoc.href);
  486. query = decodeURIComponent(query);
  487. if(query != currentHref){
  488. currentHref = query;
  489. jeus.loadContent("rightPane", currentHref, true);
  490. }
  491. };
  492. })();
  493. }