Event.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284
  1. // Licensed Materials - Property of IBM
  2. //
  3. // IBM Cognos Products: cogadmin
  4. //
  5. // (C) Copyright IBM Corp. 2005, 2013
  6. //
  7. // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  8. //
  9. //
  10. // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
  11. // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
  12. //----------------------------------------------------------
  13. com.cognos.admin.ObjectFactory("com.cognos.admin.widget");
  14. /* J2HTMLEvent class deal with all the stuff related to the event handler and its management method
  15. * @param context is a object contains all information of a widget, table widget, dialog widget and etc
  16. * The interface of context:
  17. * table - the id of the widget container
  18. * recipe - the mapping of the cogType and event
  19. * fragment - fragment object
  20. * set/getPublicVariables - function, a way to set and get a widget scope public variables
  21. */
  22. com.cognos.admin.widget.Event = function (context) {
  23. //shareing the variables for general use.
  24. this.tools = com.cognos.admin.util.Tools;
  25. this.context = context;
  26. this.table = context.table;
  27. this.recipes = context.recipe.getAll();
  28. this.fragmentRecipes = context.fragmentRecipe.getAll();
  29. this.fragment = context.fragment;
  30. if (!this.fragment._retrieve) {
  31. this.fragment._retrieve = this.fragment.retrieve;
  32. this.fragment.retrieve = this._evt_retrieve;
  33. }
  34. //the init for costomized attribues of j2html table, will be modified after walking through the DOM.
  35. this.numRow = 1;
  36. this.contentTable = this.fragment.id.toString() + "contentTable";;
  37. this.frameTable = this.fragment.id.toString() + "frame";;
  38. //internal used private variables.
  39. this.selectedRecipe = new this.tools.Recipe();
  40. this.selectedFragmentRecipe = new this.tools.Recipe();
  41. this.filterColumns = [];
  42. this.expandRowsExp = [];
  43. this.tooltip;
  44. this.menuCache = [];
  45. this.extensionFuncs = [];
  46. //state management
  47. this.state = new com.cognos.admin.util.ClientState(this.fragment.id);
  48. this.state.restoreStates();
  49. //backup the object in global scope.
  50. com.cognos.admin.publicParam.callbackEnv = this;
  51. };
  52. com.cognos.admin.widget.Event.VERSION = "0.1.0";
  53. com.cognos.admin.widget.Event.EVENT = "_EVENT_";
  54. com.cognos.admin.widget.Event.TAG = "_TAG_";
  55. com.cognos.admin.widget.Event.ENV = "_ENV_";
  56. com.cognos.admin.widget.Event.prototype = {
  57. /*
  58. * recusive func to mount the event handlers to a proper cogType according to the recipe.
  59. */
  60. mountEvent : function (targetElt){
  61. for (var i = 0; i < this.recipes.length; i++ ){
  62. if (targetElt.getAttribute("cogType").toLowerCase() == this.recipes[i].cogType.toLowerCase()) {
  63. var functionName = "_evt_" + this.recipes[i].fnName;
  64. if (typeof this[functionName] == "function") {
  65. if (this.recipes[i].evt == "init")
  66. this[functionName](targetElt);
  67. else {
  68. var evtHandler = _F_Document.associate(targetElt,this,functionName);
  69. xAddEventListener(targetElt,this.recipes[i].evt,evtHandler,this.recipes[i].cap);
  70. this.selectedRecipe.add(targetElt,evtHandler,this.recipes[i].evt,this.recipes[i].cap);
  71. }
  72. }
  73. }
  74. }
  75. },
  76. unregisterEvent : function () {
  77. xAddEventListener(window,"unload",_F_Document.associate(window,this,"_evt_unloadTable"),false);
  78. if (this.fragment){
  79. this.fragment.addEventListener("fragment.unload",_F_Document.associate(this.fragment,this,"_evt_unloadTable"),false);
  80. }
  81. },
  82. /*
  83. * register the outter function as event handler
  84. */
  85. addCogEvent : function (funcName,func) {
  86. com.cognos.admin.widget.Event.prototype["_evt_"+funcName] = func;
  87. },
  88. /*
  89. * 1) a string with single quote, which will call the internal pre-defined function ;
  90. * 2) a function name (without any quote), which should be defined by developer somewhere in a legal scope;
  91. * 3) a anonymous function beginning with "function () { function body here }"
  92. */
  93. parseFunc : function (funcName,run) {
  94. var run = run || false;
  95. var retFlag = false;
  96. var func;
  97. if (typeof funcName == "function"){
  98. func = funcName;
  99. retFlag = true;
  100. } else if (typeof funcName == "string" && typeof this["_evt_"+funcName] == "function") {
  101. func = this["_evt_"+funcName];
  102. }
  103. if (func && run)
  104. func();
  105. return retFlag;
  106. },
  107. //************************Event handler depot begin*********************************//
  108. /*
  109. * unregister all the events when the fragment or window object unload
  110. */
  111. _evt_unloadTable : function (e,tag) {
  112. var sr = this.selectedRecipe.getAll();
  113. var sfr = this.selectedFragmentRecipe.getAll();
  114. for (var i = 0; i < sr.length; i++){
  115. xRemoveEventListener(sr[i].cogType,sr[i].evt,sr[i].fnName,sr[i].cap);
  116. }
  117. if (this.fragment) {
  118. for (var i = 0; i < sfr.length; i++){
  119. this.fragment.removeEventListener(sfr[i].evt,sfr[i].fnName,sfr[i].cap);
  120. }
  121. this.fragment.removeEventListener("fragment.unload",_F_Document.associate(this.fragment,this,"_evt_unloadTable"),false);
  122. }
  123. com.cognos.admin.publicParam.evtLoaded[this.fragment.id] = false;
  124. if (com.cognos.admin.config.debug){
  125. _F_log("D","Unregister all event handlers.")
  126. }
  127. },
  128. /* Cogtable initializer, init the CogTable scope public variables
  129. * bogus event handler
  130. */
  131. _evt_initTable : function (tag) {
  132. var initParam = this.tools.cogEval(tag);
  133. var self = this;
  134. if (!initParam) return false;
  135. //init for fragment event
  136. if (this.fragment)
  137. _initFragment(this.fragmentRecipes);
  138. //parser the parameters to init the cogTable
  139. for (var o in initParam){
  140. if (typeof initParam[o] !== 'function') {
  141. switch (o) {
  142. case "fragment":
  143. if (this.fragment)
  144. _initFragment(initParam[o]);
  145. break;
  146. case "publicVar":
  147. if (initParam[o]){
  148. for (var key in initParam[o]){
  149. if (typeof initParam[o][key] !== 'function') {
  150. this.context.setPublicVariables(key,initParam[o][key]);
  151. }
  152. }
  153. }
  154. break;
  155. case "state":
  156. if (initParam[o]){
  157. for (var key in initParam[o]){
  158. if (typeof initParam[o][key] !== 'function') {
  159. this.state.setState(key,initParam[o][key]);
  160. }
  161. }
  162. }
  163. break;
  164. default:
  165. }
  166. }
  167. }
  168. function _initFragment(recipe){
  169. if (recipe && recipe instanceof Array){
  170. for (var i = 0; i < recipe.length; i++){
  171. var funcName = recipe[i].fnName;
  172. if (funcName) {
  173. //register the event against it's function
  174. var evtHandler;
  175. if (typeof self["_evt_" + funcName] == "function") {
  176. evtHandler = _F_Document.associate(self.fragment, self, "_evt_" + funcName);
  177. }
  178. else {
  179. continue;
  180. }
  181. //hack for the incompleted implementation in Fragment for resize event handler.
  182. if (recipe[i].evt == "fragment.resize")
  183. self.fragment.onresize = evtHandler;
  184. self.fragment.addEventListener(recipe[i].evt, evtHandler, recipe[i].cap);
  185. self.selectedFragmentRecipe.add ("fragment", evtHandler, recipe[i].evt, recipe[i].cap);
  186. }
  187. if (recipe[i].evtContext) {
  188. //fire the event
  189. self.fragment.raiseEvent(recipe[i].evt,recipe[i].evtContext);
  190. }
  191. }
  192. }
  193. }
  194. },
  195. _evt_maskElement : function (tag){
  196. var initParam = this.tools.cogEval(tag);
  197. var hint = (initParam && initParam.title) ? initParam.title : "";
  198. var masker = new this.tools.Masker(tag,hint,this.fragment);
  199. masker.show(true);
  200. },
  201. /* init the filter column
  202. * bogus event handler
  203. *
  204. */
  205. _evt_initFilter : function (tag){
  206. var initParam = this.tools.cogEval(tag)
  207. if (!initParam) return false;
  208. if (!(this.filterColumns[initParam.filterName] instanceof Array))
  209. this.filterColumns[initParam.filterName] = [];
  210. this.filterColumns[initParam.filterName].push (tag);
  211. tag.value = initParam.value;
  212. },
  213. /* Generic toggler
  214. *
  215. */
  216. _evt_toggle : function (e,tag){
  217. xStopPropagation (e);
  218. var tagId = tag.id.replace(/_toggle/i,"_row");
  219. var exp = "^" + tagId + "_\\d+";
  220. var isDsp = true;
  221. var key = this.tools.getKey($(tagId));
  222. if (tag.src.indexOf("expand.gif") > -1){
  223. exp += "$";
  224. this.expandRowsExp.push (exp);
  225. if (key){
  226. this.state.addState("expandRows",key,true);
  227. }
  228. exp = this.expandRowsExp;
  229. } else {
  230. isDsp = false;
  231. _F_Array.remove(this.expandRowsExp,exp+"$");
  232. this.state.removeState ("expandRows",key,true);
  233. }
  234. var gelt = new this.tools.GetElementsById(exp,this.table,true)
  235. gelt.getElt();
  236. var selectedElts = gelt.selectedElements;
  237. for (var i = 0; i < selectedElts.length; i++){
  238. if (selectedElts[i].id.indexOf("_row") > -1) {
  239. this.tools.revertDsp(selectedElts[i],isDsp);
  240. }
  241. }
  242. this.tools.revertImg (tag);
  243. },
  244. /*
  245. * TODO:Toggle Buttons
  246. */
  247. _evt_toggleButton : function (e,tag){
  248. var initParam = this.tools.cogEval(tag);
  249. var tb = new this.tools.ToggleButton(tag);
  250. tb.click();
  251. if (initParam && initParam.action) {
  252. this._evt_doAction(e,tag,initParam.action);
  253. }
  254. },
  255. /* Group checkbox toggler
  256. *
  257. */
  258. _evt_toggleCheckbox : function (e,tag){
  259. xStopPropagation (e);
  260. var initParam = this.tools.cogEval(tag);
  261. var exp = "^" + tag.id + "_\\d+";
  262. var tools = com.cognos.admin.util.Tools;
  263. var gelt = new tools.GetElementsById(exp,this.table,true);
  264. gelt.getElt();
  265. var selectedElts = gelt.selectedElements;
  266. //include the current element itself
  267. selectedElts.push(tag);
  268. for (var i = 0; i < selectedElts.length; i++){
  269. var key = this.tools.getKey(selectedElts[i]);
  270. if (key) {
  271. selectedElts[i].checked = tag.checked;
  272. if (tag.checked){
  273. this.state.addState(com.cognos.admin.util.ClientState.GROUP_ACTION_ROWS,key,true)
  274. } else {
  275. this.state.removeState(com.cognos.admin.util.ClientState.GROUP_ACTION_ROWS,key,true);
  276. }
  277. }
  278. }
  279. if (initParam) {
  280. this._evt_doAction(e,tag,initParam);
  281. }
  282. },
  283. /* Toggle all
  284. *
  285. */
  286. _evt_toggleAll : function (e,tag){
  287. if (!tag.src)
  288. return false;
  289. xStopPropagation (e);
  290. var initParam = this.tools.cogEval(tag);
  291. var toLevel = 1;
  292. if (initParam && initParam.toLevel)
  293. toLevel = initParam.toLevel;
  294. var tools = this.tools;
  295. var groupDsp = tools.revertImg (tag);
  296. var exp = tag.id + "_";
  297. var tagStatus = tag.src.indexOf("collapse.gif") > -1
  298. var gt = new tools.GetElementsById(exp,this.table,false);
  299. gt.getElt();
  300. var selectedElts = gt.selectedElements;
  301. this.state.clearState("expandRows",true);
  302. for (var i = 0; i < selectedElts.length; i++){
  303. if (selectedElts[i].id) {
  304. //for the toggler icons
  305. if (selectedElts[i].id.indexOf("_toggle") > -1) {
  306. this.tools.revertImg(selectedElts[i],tagStatus)
  307. //for the rows
  308. } else if (selectedElts[i].id.indexOf("_row") > -1) {
  309. //do the expanding and collapsing if it's not a group
  310. if (this.tools.getLevelById(tag.id,selectedElts[i].id) > toLevel) {
  311. this.tools.revertDsp(selectedElts[i],tagStatus);
  312. } else {
  313. //otherwise, collect the state for expanding group
  314. if (tagStatus) {
  315. var key = this.tools.getKey(selectedElts[i]);
  316. this.state.addState("expandRows",key,true);
  317. }
  318. }
  319. //TODO:for other togglees
  320. } /*else {
  321. var togglees = this.context.getPublicVariables("togglees");
  322. if (togglees) {
  323. for (var j = 0; j < togglees.length; j++) {
  324. if (selectedElts[i].id.indexOf("_"+togglees[j].name) > -1) {
  325. var dsp = (togglees[j].isReversed)? tagStatus : !tagStatus;
  326. this.tools.revertDsp(selectedElts[i],dsp);
  327. }
  328. }
  329. }
  330. }*/
  331. }
  332. }
  333. },
  334. /* doAction
  335. *
  336. */
  337. _evt_doAction : function (e,tag,param) {
  338. var param = e.payload || param || this.tools.cogEval(tag);
  339. var self = this;
  340. var evt = new xEvent(e);
  341. var ret;
  342. //for stop propergation
  343. if (!param || (param.stopPropagation == undefined) || (param.stopPropagation == true) || (param.stopPropagation == 'true')){
  344. xStopPropagation (evt);
  345. }
  346. //for keyboard event processer, only allowed the registered event key to trigger the action.
  347. if (evt.type == "keypress"){
  348. var charCode = (typeof e.which == "number") ? e.which : e.keyCode
  349. if (param && param.eventKey != undefined && charCode == dojo.keys[param.eventKey]) {
  350. evt.preventDefault();
  351. } else {
  352. return;
  353. }
  354. }
  355. if (param && param.grpAction){
  356. var selectedGrpKeys = this.state.getState(com.cognos.admin.util.ClientState.GROUP_ACTION_ROWS,true);
  357. if (!selectedGrpKeys || (selectedGrpKeys.length == 0)) {
  358. alert(J2H.GLB.IDS_GRP_ACTION_CHOOSE_ENTRY);
  359. return;
  360. }
  361. }
  362. if (param && param.prompt){
  363. var binded = param.prompt.binded || 'none';
  364. if (binded == 'none' || ((binded == 'binded') && tag.checked) || ((binded == 'reversed') && !tag.checked)){
  365. switch (param.prompt.type){
  366. case "message":
  367. alert (param.prompt.text);
  368. break;
  369. case "confirm":
  370. if (!confirm (param.prompt.text)){
  371. xPreventDefault(evt);
  372. tag.checked = !tag.checked;
  373. return;
  374. }
  375. }
  376. }
  377. }
  378. /* this recusive function will walk through the JSON for cascading menu,
  379. * and attach the anonymous function for each click event, inside of which, it recall the main
  380. * function (_evt_doAction) with different arguments. See the j2html JS behaviour controller
  381. * framework functional SPEC for more details.
  382. */
  383. function parseItems (oItems) {
  384. for (var i = 0; i < oItems.length; i++){
  385. var oAction = oItems[i].action;
  386. if (oAction && !self.parseFunc(oAction))
  387. oItems[i].action = getAction (oAction);
  388. if (oItems[i].items)
  389. parseItems(oItems[i].items);
  390. }
  391. };
  392. //this function is introduced to avoid the closure in parseItems.
  393. function getAction (oAction) {
  394. //TODO: the "e" cannot get the event from popup menu
  395. return function (e) {
  396. var oEvent = new xEvent(e);
  397. var oTag = oEvent.target;
  398. if (com.cognos.admin.config.debug){
  399. _F_log ("D","Event for popup menu:");
  400. _F_log ("D",oEvent);
  401. }
  402. self._evt_doAction (oEvent,oTag,oAction);
  403. };
  404. };
  405. //apply a predefined variables to a reserved key word in args
  406. function applyArgs (args) {
  407. if (args){
  408. for (var i=0; i<args.length; i++){
  409. if (args[i] == com.cognos.admin.widget.Event.EVENT){
  410. args[i] = e;
  411. } else if (args[i] == com.cognos.admin.widget.Event.TAG){
  412. args[i] = tag;
  413. } else if (args[i] == com.cognos.admin.widget.Event.ENV){
  414. args[i] = self;
  415. }
  416. }
  417. }
  418. return args;
  419. };
  420. function applyBreadCrumbs(state, param) {
  421. if (param.model.bc_idx) {
  422. var crumbs = state.getState(com.cognos.admin.util.ClientState.BREADCRUMBS,true);
  423. if (!crumbs) {
  424. crumbs = [];
  425. }
  426. if (crumbs.length < param.model.bc_idx) { //ensure the breadcrumbs size does not increase if user is clicking link multiple times prior to refresh
  427. crumbs[crumbs.length] = param;
  428. }
  429. }
  430. if (param.model.bc_title) {
  431. state.setState(com.cognos.admin.util.ClientState.BREADCRUMBS,crumbs,true);
  432. }
  433. if (crumbs && param.breadcrumb) {
  434. crumbs.length = param.breadcrumb.idx;
  435. }
  436. };
  437. if (param && param.actionType){
  438. switch (param.actionType){
  439. case "function":
  440. if (param.functionName){
  441. if (param.args){
  442. applyArgs (param.args);
  443. }
  444. try {
  445. ret = this.tools.fnParse(param.functionName,param.args);
  446. } catch (ex) {
  447. _F_log("E",ex.message);
  448. }
  449. }
  450. break;
  451. case "extension":
  452. if (param.args){
  453. for (var o in param.args){
  454. if (typeof param.args[o] !== 'function') {
  455. applyArgs(param.args[o]);
  456. }
  457. }
  458. }
  459. var obj = window;
  460. var cArgs = param.args["cArgs"] || [];
  461. var fArgs = param.args["fArgs"] || [];
  462. if (param.thisObj){
  463. if (typeof param.thisObj == "object"){
  464. obj = param.thisObj;
  465. } else if (typeof param.thisObj == "function") {
  466. obj = new param.thisObj(cArgs);
  467. } else if (typeof param.thisObj == "string") {
  468. obj = new com.cognos.admin.extension[param.thisObj](cArgs);
  469. }
  470. }
  471. if (param.functionName){
  472. try {
  473. ret = obj[param.functionName].apply(obj,fArgs);
  474. } catch (ex) {
  475. _F_log("E",ex.message);
  476. }
  477. }
  478. break;
  479. case "iframeDialog":
  480. ui_modal_dialog.open(com.cognos.admin.GATEWAY + '?b_action=xts.run&m=' + param.src+"&m_name="+encodeURIComponent(this.context.getPublicVariables("title")),false,true,true);
  481. break;
  482. case "trans":
  483. //init transient if any
  484. if (trans = param.trans) {
  485. if (trans instanceof Array){
  486. var updateList = [];
  487. for (var j = 0; j < trans.length; j++){
  488. if (trans[j].list instanceof Array){
  489. for (var i = 0; i < trans[j].list.length; i++){
  490. if (param.model[trans[j].list[i]] !== undefined)
  491. if (trans[j].skipThisReload) {
  492. //The active fragment only wants it's transient values updated. Skip the retrieve. (eg. ScoreCard view resource selection)
  493. this.fragment.transientUpdateCheck(trans[j].list[i], param.model[trans[j].list[i]], trans[j].channel, false);
  494. }
  495. updateList.push (this.tools.createTransient(trans[j].list[i],param.model[trans[j].list[i]],trans[j].scope,trans[j].channel));
  496. }
  497. }
  498. }
  499. this.fragment.transientUpdateList (updateList);
  500. if (com.cognos.admin.config.debug){
  501. _F_log ("D","Transient update list:");
  502. _F_log("D",updateList);
  503. }
  504. }
  505. }
  506. break;
  507. case "dialog":
  508. if (param.ui.styles == 0) {
  509. //Hidden.
  510. self.fragment.destroy();
  511. self._evt_unloadTable();
  512. self.fragment.parent.raiseEvent("fragment.refresh");
  513. } else {
  514. var dId = this.table.id.toString() + (param.ui.id?param.ui.id:"dialog");
  515. var dTitle = param.ui.title;
  516. var dStyles = param.ui.styles || 1;
  517. var dX = param.ui.x || 168;
  518. var dY = param.ui.y || 10;
  519. var dDx = param.ui.dx || 550;
  520. var dDy = param.ui.dy;
  521. if ($(dId)){
  522. document.body.removeChild($(dId));
  523. }
  524. var uiDialog = new ui_dialog(dId,dTitle,dStyles,dX,dY,dDx,dDy);
  525. uiDialog.show();
  526. if (param.content)
  527. this.tools.parseContent(param.content,dId+"content",this.state);
  528. //command button section
  529. uiDialog.processCommand = function (btnType){
  530. switch (btnType) {
  531. //TODO: raise btnType context specific events
  532. case "cancel":
  533. return true;
  534. default:
  535. self.fragment.destroy();
  536. self._evt_unloadTable();
  537. self.fragment.parent.raiseEvent("fragment.refresh");
  538. return true;
  539. }
  540. }
  541. }
  542. break;
  543. case "menu":
  544. if (!this.menu) {
  545. this.menu = new ui_menu();
  546. this.menu.fragment = this.fragment;
  547. }
  548. if (param.url){
  549. var cacheKey = param.url+this.tools.JSON.stringify(param.parameters);
  550. var cachedMenu = this.menuCache[cacheKey];
  551. if (cachedMenu) {
  552. this.menu.menudef=cachedMenu;
  553. this.menu.rebuild = true;
  554. this.menu.show(evt);
  555. } else {
  556. var THIS = this;
  557. var a = new this.tools.ajaxObj();
  558. a.setUrl (param.url);
  559. if (param.method)
  560. a.setMethod (param.method);
  561. if (param.parameters)
  562. a.setParameters (param.parameters);
  563. if (!evt.target.srcOrig) {
  564. evt.target.srcOrig = evt.target.src;
  565. }
  566. a.onSuccess = function(transport) {
  567. evt.target.style.cursor= "default";
  568. var responseObj = self.tools.cogEval(transport.responseText);
  569. if (evt.target.srcOrig){
  570. evt.target.src = evt.target.srcOrig;
  571. }
  572. if (responseObj){
  573. if (items = responseObj.items) {
  574. parseItems(items);
  575. if (param.cache) {
  576. THIS.menuCache[cacheKey] = responseObj;
  577. }
  578. THIS.menu.rebuild = true;
  579. THIS.menu.menudef=responseObj;
  580. THIS.menu.show(evt);
  581. } else {
  582. //The menu wasn't returned.
  583. var fragNode = _F_DOM.selectSingleNode(responseObj, "/fragment");
  584. if (fragNode) {
  585. //It's an Error fragment. Process it.
  586. THIS.fragment.processFragmentXML(fragNode,evt.target);
  587. } else {
  588. //Not an Error fragment, Could be an HTML error response. Alert the user as best we can.
  589. var txt = transport.responseText;
  590. var code = _F_Document.extractTagText(txt, "ERROR_CODE");
  591. if (code == "CAM_PASSPORT_ERROR") {
  592. // substitute the error code to an invalid passport
  593. THIS.fragment.processError("invalidCredentials", null, null);
  594. } else {
  595. // open up that HTML markup and let the end-user deal with it
  596. if (!code) {
  597. code="ERROR HTTP-"+transport.status;
  598. }
  599. var msg = _F_Document.extractTagText(txt, "ERROR_MSG");
  600. if (!msg) {
  601. msg=code+" " + THIS.tools.JSON.stringify(param);
  602. }
  603. var details = _F_Document.extractTagText(txt, "ERROR_DETAILS");
  604. if (!details) {
  605. details=txt;
  606. }
  607. THIS.fragment.processError(code, msg, details);
  608. var w = window.open(_F_Config.webContent + "/common/blank.html", THIS.fragment.id, "width=700,height=600,resizable,status=no,menubar=no,toolbar=no,location=no");
  609. w.document.open();
  610. w.document.write(txt);
  611. w.document.close();
  612. w.focus();
  613. }
  614. THIS.fragment.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
  615. _F_log("W", "expecting XML, got HTML for fragment: "+THIS.fragment.id);
  616. }
  617. }
  618. }
  619. };
  620. //To avoid jumpiness, only change the menu icon if it matches the size of icon_loading.gif. Otherwise, just change the mouse cursor.
  621. if (evt.target.src && (evt.target.height == 16)) {
  622. evt.target.src=_F_Config.webContent+'/ps/portal/images/icon_loading.gif';
  623. } else {
  624. evt.target.style.cursor = "wait";
  625. }
  626. a.run();
  627. }
  628. } else if (param.model) {
  629. var cacheKey = param.model.id;
  630. var cachedMenu = this.menuCache[cacheKey];
  631. if (cachedMenu) {
  632. this.menu.menudef=cachedMenu;
  633. } else {
  634. this.menu.menudef=param.model;
  635. this.menuCache[cacheKey] = param.model;
  636. }
  637. if (items = param.model.items) {
  638. parseItems(items);
  639. }
  640. this.menu.rebuild = true;
  641. this.menu.show(evt);
  642. }
  643. break;
  644. case "retrieve":
  645. if (param.model){
  646. var targetDivID = param.model.targetDivID || this.fragment.div;
  647. var targetFragID = param.model.targetFragID;
  648. var url = param.model.url;
  649. var args = param.model.args;
  650. applyBreadCrumbs(this.state, param);
  651. if (args) {
  652. for (var o in args){
  653. if (typeof args[o] !== 'function') {
  654. this.state.setState(o,args[o]);
  655. }
  656. }
  657. }
  658. if (targetFragID) {
  659. var frag = _F_getFragmentByID(targetFragID);
  660. if (frag && url && frag.path != url) {
  661. frag.path = url;
  662. }
  663. }
  664. if (targetFragID == this.fragment.id){
  665. this.fragment.retrieve();
  666. } else {
  667. if (targetDivID && !$(targetDivID)) {
  668. var targetDiv = document.createElement("div");
  669. targetDiv.id = targetDivID;
  670. targetDiv.style.display = "none";
  671. document.body.appendChild(targetDiv);
  672. }
  673. var frag = this.fragment;
  674. if (targetFragID) {
  675. frag = _F_getFragmentByID(targetFragID) || this.tools.createFragment(url,targetFragID,targetDivID);
  676. }
  677. frag.retrieve(this.state.getStateURL(),targetDivID);
  678. }
  679. }
  680. break;
  681. case "toggle":
  682. if (param.target) {
  683. for (var i=0; i<param.target.length; i++){
  684. var item;
  685. if (tag.checked == true && param.target[i].selected){
  686. item = param.target[i].selected;
  687. } else if (tag.checked == false && param.target[i].deselected){
  688. item = param.target[i].deselected;
  689. }
  690. if (item){
  691. this._evt_doAction(e,$(param.target[i].targetId),item);
  692. }
  693. }
  694. }
  695. break;
  696. case "dhtml":
  697. //Flip the current dhtml attrs with the ones supplied within the cogparam
  698. if (param.targets) {
  699. for (var i=0; i<param.targets.length; i++){
  700. for (var attr in param.targets[i].attributes) {
  701. var target = $(this.fragment.id+param.targets[i].id);
  702. if (target != null) {
  703. var currentValue = target.getAttribute(attr); //temp store for the current dhtml attrs
  704. var newValue = param.targets[i].attributes[attr] //get the dhtml attr from the cogparam
  705. if (attr == "style") {
  706. //overcome IE's lack of setAttribute support for "style" attr. Has no effect for Firefox
  707. currentValue = target.style.cssText;
  708. target.style.cssText = newValue;
  709. }
  710. target.setAttribute(attr, newValue); //change the current dhtml attr with the one supplied in the cogparam
  711. param.targets[i].attributes[attr] = currentValue; //Update the cogparm dhtml attr with the current one
  712. }
  713. }
  714. }
  715. tag.setAttribute("cogparam",com.cognos.admin.util.Tools.JSON.stringify(param)); //update the cogparam dhtml attrs
  716. }
  717. break;
  718. default:
  719. var thisObj = window;
  720. var obj = param.actionType;
  721. //Try three different ways to active an action.
  722. //from an existed object
  723. if (typeof obj == "object"){
  724. thisObj = obj;
  725. //from an instantiated function
  726. } else if (typeof obj == "function") {
  727. thisObj = new obj (this);
  728. //from extension handler underneath js/extension, do nothing otherwise
  729. } else {
  730. thisObj = this.extensionFuncs[obj];
  731. if (!thisObj) {
  732. _F_log("D","No matched extensionHandler was found for: name="+obj);
  733. return false;
  734. }
  735. }
  736. if (typeof thisObj["doAction"] === "function"){
  737. try {
  738. ret = thisObj["doAction"].apply(thisObj,[e,tag,param]);
  739. } catch (ex) {
  740. _F_log("E",ex.message);
  741. }
  742. } else {
  743. throw new Error("Missing 'doAction' interface implementation in " + param.actionType);
  744. }
  745. }
  746. }
  747. return ret;
  748. },
  749. /* apply the sort to the table column
  750. *
  751. */
  752. _evt_sortColumn : function (e,tag) {
  753. // "Enter" key supported
  754. var evt = new xEvent(e);
  755. if (evt.type == "keypress"){
  756. if (evt.keyCode == dojo.keys.ENTER) {
  757. evt.preventDefault();
  758. } else {
  759. return;
  760. }
  761. }
  762. var sortParam = this.tools.cogEval(tag)
  763. if (!sortParam) return false;
  764. this.state.setState(com.cognos.admin.util.ClientState.SORT,sortParam,true);
  765. this.fragment.retrieve();
  766. },
  767. /* apply the filter
  768. *
  769. */
  770. _evt_filterColumn : function (e,tag) {
  771. var param = this.tools.cogEval(tag)
  772. if (!param) return false;
  773. //TODO:target parameter will be: "filter=Table1:1:inclusive:poor;average;good;other;2:exclusive:A:B:C:D"
  774. var filterParam = param.filterName + "=1:false:";;
  775. for (var j = 0; j < this.filterColumns[param.filterName].length; j++){
  776. if (this.filterColumns[param.filterName][j].checked)
  777. filterParam += this.filterColumns[param.filterName][j].value + ";";
  778. }
  779. this.fragment.retrieve(filterParam);
  780. },
  781. //for client side filter summary widget only
  782. _evt_filterSummary : function (tag){
  783. var param = this.tools.cogEval(tag);
  784. if (!param) return false;
  785. var fs = new com.cognos.admin.widget.FilterSummary(tag,param);
  786. },
  787. /*
  788. *
  789. */
  790. _evt_mouseOverLink : function (tag){
  791. tag.style.cursor = "pointer";
  792. },
  793. /*
  794. *
  795. */
  796. _evt_defaultCursor : function (tag){
  797. tag.style.cursor = "default";
  798. },
  799. /* change the styles for an action button when mouseover
  800. *
  801. */
  802. _evt_mouseOverElt : function (e,tag) {
  803. if (!tag.getAttribute("origclass")) {
  804. tag.setAttribute("origclass",tag.className);
  805. }
  806. if (this.tools.includeClass(tag,'cogstyle-toolbar-imageNormal')) {
  807. tag.className = 'cogstyle-toolbar-imageOver';
  808. }
  809. if (this.tools.includeClass(tag,'cogstyle-toolbar-imagePressed')) {
  810. tag.className = 'cogstyle-toolbar-imageOverPressed';
  811. }
  812. if (this.tools.includeClass(tag,'cogstyle-table-row-default')) {
  813. tag.className = 'cogstyle-table-row-hilite';
  814. }
  815. if (this.tools.includeClass(tag,'cogstyle-table-row-alternate')) {
  816. tag.className = 'cogstyle-table-row-hilite';
  817. }
  818. if (this.tools.includeClass(tag,'button')) {
  819. tag.className = 'button_hover';
  820. }
  821. },
  822. /* change the styles for an action button when mouseout
  823. *
  824. */
  825. _evt_mouseOutElt : function (e,tag) {
  826. if (this.tools.includeClass(tag,'cogstyle-toolbar-imageOver')) {
  827. tag.className = tag.getAttribute("origclass");
  828. }
  829. if (this.tools.includeClass(tag,'cogstyle-toolbar-imageOverPressed')) {
  830. tag.className = tag.getAttribute("origclass");
  831. }
  832. if (this.tools.includeClass(tag,'cogstyle-table-row-alternate')) {
  833. tag.className = tag.getAttribute("origclass");
  834. }
  835. if (this.tools.includeClass(tag,'cogstyle-table-row-hilite')) {
  836. tag.className = tag.getAttribute("origclass");
  837. }
  838. if (this.tools.includeClass(tag,'button_hover') || this.tools.includeClass(tag,'button_pressed')) {
  839. tag.className = 'button';
  840. }
  841. },
  842. /* change the styles for an action button when mouse click
  843. *
  844. */
  845. _evt_mouseClickElt : function (e,tag) {
  846. //this is for the selectable row
  847. if (tag.className.search(/^cogstyle-table-row-/i) != -1 && tag.parentNode.nodeType == 1){
  848. for (var m = tag.parentNode.firstChild; m != null; m = m.nextSibling){
  849. if (this.tools.includeClass(m,"cogstyle-table-row-selected")){
  850. var origClass = m.getAttribute("origclass");
  851. m.className = origClass ? origClass : 'cogstyle-table-row-default';
  852. break;
  853. }
  854. }
  855. if (!tag.getAttribute("origclass")) {
  856. tag.setAttribute("origclass",tag.className);
  857. }
  858. tag.className = "cogstyle-table-row-selected";
  859. this.state.setState(com.cognos.admin.util.ClientState.SELECTED_ROW,this.tools.getKey(tag),true);
  860. }
  861. },
  862. /* change the styles for an action button when mouse down
  863. *
  864. */
  865. _evt_mouseDownElt : function (e,tag) {
  866. if (this.tools.includeClass(tag,'button') || this.tools.includeClass(tag,'button_hover')) {
  867. tag.className = 'button_pressed';
  868. }
  869. },
  870. /* change the styles for an action button when mouse up
  871. *
  872. */
  873. _evt_mouseUpElt : function (e,tag) {
  874. if (this.tools.includeClass(tag,'button_pressed')) {
  875. tag.className = 'button';
  876. }
  877. },
  878. /*
  879. *
  880. */
  881. _evt_showTooltip : function (e,tag){
  882. var param = this.tools.cogEval(tag);
  883. if (param){
  884. param.content = this._evt_doAction(e,tag,param);
  885. if (param.content){
  886. this.tooltip = new com.cognos.admin.widget.Tooltip(tag,e,param);
  887. this.tooltip.show();
  888. }
  889. }
  890. },
  891. _evt_hideTooltip : function (e,tag){
  892. if (this.tooltip) this.tooltip.hide();
  893. },
  894. //*****************************init for fragment begin***********************************
  895. /*
  896. *
  897. */
  898. _evt_fgmtRefresh : function (e,tag) {
  899. if (com.cognos.admin.config.debug){
  900. _F_log('D','fragment.refresh');
  901. }
  902. },
  903. /*
  904. *
  905. */
  906. _evt_fgmtResize : function (e,tag) {
  907. if (com.cognos.admin.config.debug){
  908. _F_log('D','fragment.resize');
  909. }
  910. //init the resizing content table
  911. if ($(this.contentTable)){
  912. var winState = this.fragment.cogadminWindowState || this.fragment.windowState;
  913. this.tools.adjustTableHeight(this.frameTable,this.contentTable,winState,this.numRow);
  914. }
  915. },
  916. /*
  917. *
  918. */
  919. _evt_fgmtLoad : function (evt,tag) {
  920. if (com.cognos.admin.config.debug){
  921. _F_log('D','fragment.load');
  922. _F_log('D','state:');
  923. _F_log(this.state.states);
  924. }
  925. //init the contentTable after the CogTable was initialized
  926. if (this.context.getPublicVariables("contentTableId"))
  927. this.contentTable = this.context.getPublicVariables("contentTableId");
  928. //init the depth of the current fragment
  929. if (num = this.context.getPublicVariables("depth")){
  930. var obj = this.fragment;
  931. for (var n = 0; n < num; n++){
  932. if (obj.parent)
  933. obj = obj.parent;
  934. else
  935. break;
  936. }
  937. this.frameTable = obj.id+"frame";
  938. }
  939. //init the number of the vertical frags
  940. if (this.context.getPublicVariables("numRow"))
  941. this.numRow = this.context.getPublicVariables("numRow");
  942. //init the vertical and horizonal scroll position
  943. if ($(this.contentTable)){
  944. $(this.contentTable).scrollTop = this.state.getState(com.cognos.admin.util.ClientState.SCROLL_TOP,true);
  945. $(this.contentTable).scrollTop = this.state.getState(com.cognos.admin.util.ClientState.SCROLL_LEFT,true);
  946. //init the windowS resizing content table
  947. this.fragment.cogadminWindowState = this.state.getState(com.cognos.admin.util.ClientState.COGADMIN_WINDOW_STATE,true);
  948. var winState = this.fragment.cogadminWindowState || this.fragment.windowState;
  949. this.tools.adjustTableHeight(this.frameTable,this.contentTable,winState,this.numRow);
  950. }
  951. },
  952. /*
  953. *
  954. */
  955. _evt_fgmtUnload : function (e,tag) {
  956. if (com.cognos.admin.config.debug){
  957. _F_log('D','fragment.unload');
  958. }
  959. },
  960. /*
  961. *
  962. */
  963. _evt_fgmtRetrieveBefore : function (e,tag) {
  964. if (com.cognos.admin.config.debug){
  965. _F_log('D','fragment.retrieve.before');
  966. }
  967. //provides a means to lazily inject parms onto the existing retrieve parms list. Eg. When a transient update is triggered by a foreign frag, this allows parms (like clientState) to be injected onto the URI.
  968. //TODO: Trakker 592247. Refactor this solution once/if CPS adds an enhancement to easily augment e.payload within "fragment.before.retrieve" event.
  969. if ($(this.contentTable)){
  970. this.state.setState (com.cognos.admin.util.ClientState.SCROLL_TOP,$(this.contentTable).scrollTop,true);
  971. this.state.setState (com.cognos.admin.util.ClientState.SCROLL_LEFT,$(this.contentTable).scrollLeft,true);
  972. }
  973. this.state.setSkipPersistStates (this.context.getPublicVariables("skipPersistClientState"));
  974. e.payload.value = (e.payload.value ? e.payload.value+"&" : '')+this.state.getStateURL();
  975. },
  976. /*
  977. *
  978. */
  979. _evt_fgmtRetrieveAfter : function (e,tag) {
  980. if (com.cognos.admin.config.debug){
  981. _F_log('D','fragment.retrieve.after');
  982. }
  983. },
  984. /*
  985. *
  986. */
  987. _evt_fgmtCreate : function (e,tag) {
  988. if (com.cognos.admin.config.debug){
  989. _F_log('D','fragment.create');
  990. }
  991. },
  992. /*
  993. *
  994. */
  995. _evt_fgmtDestroy : function (e,tag) {
  996. if (com.cognos.admin.config.debug){
  997. _F_log('D','fragment.destroy');
  998. }
  999. },
  1000. /*
  1001. *
  1002. */
  1003. _evt_fgmtError : function (e,tag) {
  1004. if (com.cognos.admin.config.debug){
  1005. _F_log('D','fragment.error');
  1006. }
  1007. },
  1008. /*
  1009. *
  1010. */
  1011. _evt_fgmtTitleChange : function (e,tag) {
  1012. if (com.cognos.admin.config.debug){
  1013. _F_log('D','fragment.title.change');
  1014. }
  1015. },
  1016. /*
  1017. *
  1018. */
  1019. _evt_fgmtWindowstateChange : function (e,tag) {
  1020. if (com.cognos.admin.config.debug){
  1021. _F_log('D','fragment.windowstate.change');
  1022. }
  1023. //init the resizing content table
  1024. if ($(this.contentTable)){
  1025. var winState = e.payload.newWindowState;
  1026. if (winState == "normal" && this.fragment.cogadminWindowState == "extended")
  1027. winState = "extended";
  1028. this.tools.adjustTableHeight(this.frameTable,this.contentTable,winState,this.numRow);
  1029. }
  1030. if (this.numRow > 1)
  1031. this.fragment.raiseEvent("cogadmin.fragment.windowstate.change",e.payload.newWindowState);
  1032. },
  1033. /*
  1034. *
  1035. */
  1036. _evt_fgmtModeChange : function (e,tag) {
  1037. if (com.cognos.admin.config.debug){
  1038. _F_log('D','fragment.mode.change');
  1039. }
  1040. },
  1041. _evt_menuSelect : function (e,tag) {
  1042. var menuDef = e.payload.menuDef;
  1043. var selectedIdx = e.payload.selectedIdx;
  1044. var target = $(this.fragment.id+menuDef.id);
  1045. if (target) {
  1046. target[target.getAttribute("textAttr")] = menuDef.items[selectedIdx].title;
  1047. var valueAttr = document.createAttribute("pvalue");
  1048. valueAttr.nodeValue = menuDef.items[selectedIdx].id;
  1049. target.setAttributeNode(valueAttr);
  1050. }
  1051. if (com.cognos.admin.config.debug){
  1052. _F_log('D','uicommon.menu.select');
  1053. }
  1054. },
  1055. //*****************************init for fragment end***********************************
  1056. //*****************************init for j2html customized fragment event start***********************************
  1057. _evt_cadminFragRefresh : function (e,tag) {
  1058. if (com.cognos.admin.config.debug){
  1059. _F_log('D','cogadmin.refresh');
  1060. }
  1061. this._evt_fgmtRefresh(e,tag);
  1062. },
  1063. _evt_distCadminFragWschange : function (e,tag) {
  1064. if (com.cognos.admin.config.debug){
  1065. _F_log('D','_evt_distCadminFragWschange');
  1066. }
  1067. if ($(this.contentTable)){
  1068. if (e.source.id != this.fragment.id) {
  1069. if (this.numRow > 1) {
  1070. switch (e.payload){
  1071. case "minimized":
  1072. this.fragment.cogadminWindowState = "extended";
  1073. this.state.setState(com.cognos.admin.util.ClientState.COGADMIN_WINDOW_STATE,"extended",true);
  1074. this.tools.adjustTableHeight(this.frameTable,this.contentTable,"extended",this.numRow);
  1075. break;
  1076. case "normal":
  1077. this.fragment.cogadminWindowState = null;
  1078. this.state.clearState(com.cognos.admin.util.ClientState.COGADMIN_WINDOW_STATE,true);
  1079. this.tools.adjustTableHeight(this.frameTable,this.contentTable,"normal",this.numRow);
  1080. break;
  1081. default:
  1082. }
  1083. }
  1084. }
  1085. }
  1086. },
  1087. _evt_retrieve : function(sParams, dest, synchronous) {
  1088. if (com.cognos.admin.config.debug){
  1089. _F_log('D','_evt_retrieve');
  1090. }
  1091. paramsObj = new ParamsObject(sParams);
  1092. this._retrieve(paramsObj, dest, synchronous);
  1093. function ParamsObject (params) {
  1094. this.value = params;
  1095. this.valueOf = function() {
  1096. return this.value;
  1097. }
  1098. this.indexOf = function(value) {
  1099. return this.value.indexOf(value);
  1100. }
  1101. }
  1102. }
  1103. //*****************************init for cogadmin customized fragment event end***********************************
  1104. };