123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284 |
- // Licensed Materials - Property of IBM
- //
- // IBM Cognos Products: cogadmin
- //
- // (C) Copyright IBM Corp. 2005, 2013
- //
- // US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- //
- //
- // Copyright (C) 2008 Cognos ULC, an IBM Company. All rights reserved.
- // Cognos (R) is a trademark of Cognos ULC, (formerly Cognos Incorporated).
- //----------------------------------------------------------
- com.cognos.admin.ObjectFactory("com.cognos.admin.widget");
- /* J2HTMLEvent class deal with all the stuff related to the event handler and its management method
- * @param context is a object contains all information of a widget, table widget, dialog widget and etc
- * The interface of context:
- * table - the id of the widget container
- * recipe - the mapping of the cogType and event
- * fragment - fragment object
- * set/getPublicVariables - function, a way to set and get a widget scope public variables
- */
- com.cognos.admin.widget.Event = function (context) {
- //shareing the variables for general use.
- this.tools = com.cognos.admin.util.Tools;
- this.context = context;
- this.table = context.table;
- this.recipes = context.recipe.getAll();
- this.fragmentRecipes = context.fragmentRecipe.getAll();
- this.fragment = context.fragment;
- if (!this.fragment._retrieve) {
- this.fragment._retrieve = this.fragment.retrieve;
- this.fragment.retrieve = this._evt_retrieve;
- }
-
- //the init for costomized attribues of j2html table, will be modified after walking through the DOM.
- this.numRow = 1;
- this.contentTable = this.fragment.id.toString() + "contentTable";;
- this.frameTable = this.fragment.id.toString() + "frame";;
-
-
- //internal used private variables.
- this.selectedRecipe = new this.tools.Recipe();
- this.selectedFragmentRecipe = new this.tools.Recipe();
- this.filterColumns = [];
- this.expandRowsExp = [];
- this.tooltip;
-
- this.menuCache = [];
-
- this.extensionFuncs = [];
-
- //state management
- this.state = new com.cognos.admin.util.ClientState(this.fragment.id);
- this.state.restoreStates();
-
- //backup the object in global scope.
- com.cognos.admin.publicParam.callbackEnv = this;
-
- };
- com.cognos.admin.widget.Event.VERSION = "0.1.0";
- com.cognos.admin.widget.Event.EVENT = "_EVENT_";
- com.cognos.admin.widget.Event.TAG = "_TAG_";
- com.cognos.admin.widget.Event.ENV = "_ENV_";
- com.cognos.admin.widget.Event.prototype = {
- /*
- * recusive func to mount the event handlers to a proper cogType according to the recipe.
- */
- mountEvent : function (targetElt){
- for (var i = 0; i < this.recipes.length; i++ ){
- if (targetElt.getAttribute("cogType").toLowerCase() == this.recipes[i].cogType.toLowerCase()) {
- var functionName = "_evt_" + this.recipes[i].fnName;
- if (typeof this[functionName] == "function") {
- if (this.recipes[i].evt == "init")
- this[functionName](targetElt);
- else {
- var evtHandler = _F_Document.associate(targetElt,this,functionName);
- xAddEventListener(targetElt,this.recipes[i].evt,evtHandler,this.recipes[i].cap);
- this.selectedRecipe.add(targetElt,evtHandler,this.recipes[i].evt,this.recipes[i].cap);
- }
- }
- }
- }
- },
-
- unregisterEvent : function () {
- xAddEventListener(window,"unload",_F_Document.associate(window,this,"_evt_unloadTable"),false);
- if (this.fragment){
- this.fragment.addEventListener("fragment.unload",_F_Document.associate(this.fragment,this,"_evt_unloadTable"),false);
- }
- },
-
- /*
- * register the outter function as event handler
- */
- addCogEvent : function (funcName,func) {
- com.cognos.admin.widget.Event.prototype["_evt_"+funcName] = func;
- },
- /*
- * 1) a string with single quote, which will call the internal pre-defined function ;
- * 2) a function name (without any quote), which should be defined by developer somewhere in a legal scope;
- * 3) a anonymous function beginning with "function () { function body here }"
- */
- parseFunc : function (funcName,run) {
- var run = run || false;
- var retFlag = false;
- var func;
-
- if (typeof funcName == "function"){
- func = funcName;
- retFlag = true;
-
- } else if (typeof funcName == "string" && typeof this["_evt_"+funcName] == "function") {
- func = this["_evt_"+funcName];
- }
-
- if (func && run)
- func();
-
- return retFlag;
- },
- //************************Event handler depot begin*********************************//
-
- /*
- * unregister all the events when the fragment or window object unload
- */
- _evt_unloadTable : function (e,tag) {
- var sr = this.selectedRecipe.getAll();
- var sfr = this.selectedFragmentRecipe.getAll();
-
- for (var i = 0; i < sr.length; i++){
- xRemoveEventListener(sr[i].cogType,sr[i].evt,sr[i].fnName,sr[i].cap);
- }
-
- if (this.fragment) {
- for (var i = 0; i < sfr.length; i++){
- this.fragment.removeEventListener(sfr[i].evt,sfr[i].fnName,sfr[i].cap);
- }
- this.fragment.removeEventListener("fragment.unload",_F_Document.associate(this.fragment,this,"_evt_unloadTable"),false);
- }
- com.cognos.admin.publicParam.evtLoaded[this.fragment.id] = false;
- if (com.cognos.admin.config.debug){
- _F_log("D","Unregister all event handlers.")
- }
- },
-
- /* Cogtable initializer, init the CogTable scope public variables
- * bogus event handler
- */
- _evt_initTable : function (tag) {
- var initParam = this.tools.cogEval(tag);
- var self = this;
- if (!initParam) return false;
-
- //init for fragment event
- if (this.fragment)
- _initFragment(this.fragmentRecipes);
- //parser the parameters to init the cogTable
- for (var o in initParam){
- if (typeof initParam[o] !== 'function') {
- switch (o) {
- case "fragment":
- if (this.fragment)
- _initFragment(initParam[o]);
- break;
- case "publicVar":
- if (initParam[o]){
- for (var key in initParam[o]){
- if (typeof initParam[o][key] !== 'function') {
- this.context.setPublicVariables(key,initParam[o][key]);
- }
- }
- }
- break;
- case "state":
- if (initParam[o]){
- for (var key in initParam[o]){
- if (typeof initParam[o][key] !== 'function') {
- this.state.setState(key,initParam[o][key]);
- }
- }
- }
- break;
- default:
- }
- }
- }
-
-
- function _initFragment(recipe){
- if (recipe && recipe instanceof Array){
- for (var i = 0; i < recipe.length; i++){
- var funcName = recipe[i].fnName;
- if (funcName) {
- //register the event against it's function
-
- var evtHandler;
-
- if (typeof self["_evt_" + funcName] == "function") {
- evtHandler = _F_Document.associate(self.fragment, self, "_evt_" + funcName);
- }
- else {
- continue;
- }
-
- //hack for the incompleted implementation in Fragment for resize event handler.
- if (recipe[i].evt == "fragment.resize")
- self.fragment.onresize = evtHandler;
-
- self.fragment.addEventListener(recipe[i].evt, evtHandler, recipe[i].cap);
- self.selectedFragmentRecipe.add ("fragment", evtHandler, recipe[i].evt, recipe[i].cap);
- }
- if (recipe[i].evtContext) {
- //fire the event
- self.fragment.raiseEvent(recipe[i].evt,recipe[i].evtContext);
- }
- }
- }
- }
- },
-
- _evt_maskElement : function (tag){
- var initParam = this.tools.cogEval(tag);
- var hint = (initParam && initParam.title) ? initParam.title : "";
- var masker = new this.tools.Masker(tag,hint,this.fragment);
-
- masker.show(true);
- },
-
- /* init the filter column
- * bogus event handler
- *
- */
- _evt_initFilter : function (tag){
- var initParam = this.tools.cogEval(tag)
- if (!initParam) return false;
-
- if (!(this.filterColumns[initParam.filterName] instanceof Array))
- this.filterColumns[initParam.filterName] = [];
-
- this.filterColumns[initParam.filterName].push (tag);
- tag.value = initParam.value;
- },
-
- /* Generic toggler
- *
- */
- _evt_toggle : function (e,tag){
- xStopPropagation (e);
-
- var tagId = tag.id.replace(/_toggle/i,"_row");
- var exp = "^" + tagId + "_\\d+";
- var isDsp = true;
- var key = this.tools.getKey($(tagId));
-
- if (tag.src.indexOf("expand.gif") > -1){
- exp += "$";
- this.expandRowsExp.push (exp);
- if (key){
- this.state.addState("expandRows",key,true);
- }
-
- exp = this.expandRowsExp;
-
- } else {
- isDsp = false;
- _F_Array.remove(this.expandRowsExp,exp+"$");
- this.state.removeState ("expandRows",key,true);
- }
-
- var gelt = new this.tools.GetElementsById(exp,this.table,true)
- gelt.getElt();
-
- var selectedElts = gelt.selectedElements;
- for (var i = 0; i < selectedElts.length; i++){
- if (selectedElts[i].id.indexOf("_row") > -1) {
- this.tools.revertDsp(selectedElts[i],isDsp);
- }
- }
-
- this.tools.revertImg (tag);
- },
-
- /*
- * TODO:Toggle Buttons
- */
- _evt_toggleButton : function (e,tag){
- var initParam = this.tools.cogEval(tag);
-
- var tb = new this.tools.ToggleButton(tag);
- tb.click();
-
- if (initParam && initParam.action) {
- this._evt_doAction(e,tag,initParam.action);
- }
- },
-
- /* Group checkbox toggler
- *
- */
- _evt_toggleCheckbox : function (e,tag){
- xStopPropagation (e);
- var initParam = this.tools.cogEval(tag);
- var exp = "^" + tag.id + "_\\d+";
- var tools = com.cognos.admin.util.Tools;
-
- var gelt = new tools.GetElementsById(exp,this.table,true);
- gelt.getElt();
-
- var selectedElts = gelt.selectedElements;
- //include the current element itself
- selectedElts.push(tag);
-
- for (var i = 0; i < selectedElts.length; i++){
- var key = this.tools.getKey(selectedElts[i]);
- if (key) {
- selectedElts[i].checked = tag.checked;
- if (tag.checked){
- this.state.addState(com.cognos.admin.util.ClientState.GROUP_ACTION_ROWS,key,true)
- } else {
- this.state.removeState(com.cognos.admin.util.ClientState.GROUP_ACTION_ROWS,key,true);
- }
- }
- }
-
- if (initParam) {
- this._evt_doAction(e,tag,initParam);
- }
- },
-
- /* Toggle all
- *
- */
- _evt_toggleAll : function (e,tag){
- if (!tag.src)
- return false;
-
- xStopPropagation (e);
- var initParam = this.tools.cogEval(tag);
- var toLevel = 1;
- if (initParam && initParam.toLevel)
- toLevel = initParam.toLevel;
- var tools = this.tools;
- var groupDsp = tools.revertImg (tag);
- var exp = tag.id + "_";
- var tagStatus = tag.src.indexOf("collapse.gif") > -1
-
- var gt = new tools.GetElementsById(exp,this.table,false);
- gt.getElt();
- var selectedElts = gt.selectedElements;
- this.state.clearState("expandRows",true);
-
- for (var i = 0; i < selectedElts.length; i++){
- if (selectedElts[i].id) {
- //for the toggler icons
- if (selectedElts[i].id.indexOf("_toggle") > -1) {
- this.tools.revertImg(selectedElts[i],tagStatus)
- //for the rows
- } else if (selectedElts[i].id.indexOf("_row") > -1) {
- //do the expanding and collapsing if it's not a group
- if (this.tools.getLevelById(tag.id,selectedElts[i].id) > toLevel) {
- this.tools.revertDsp(selectedElts[i],tagStatus);
- } else {
- //otherwise, collect the state for expanding group
- if (tagStatus) {
- var key = this.tools.getKey(selectedElts[i]);
- this.state.addState("expandRows",key,true);
- }
- }
- //TODO:for other togglees
- } /*else {
- var togglees = this.context.getPublicVariables("togglees");
- if (togglees) {
- for (var j = 0; j < togglees.length; j++) {
- if (selectedElts[i].id.indexOf("_"+togglees[j].name) > -1) {
- var dsp = (togglees[j].isReversed)? tagStatus : !tagStatus;
- this.tools.revertDsp(selectedElts[i],dsp);
- }
- }
- }
- }*/
- }
- }
- },
- /* doAction
- *
- */
- _evt_doAction : function (e,tag,param) {
- var param = e.payload || param || this.tools.cogEval(tag);
- var self = this;
- var evt = new xEvent(e);
- var ret;
-
- //for stop propergation
- if (!param || (param.stopPropagation == undefined) || (param.stopPropagation == true) || (param.stopPropagation == 'true')){
- xStopPropagation (evt);
- }
-
- //for keyboard event processer, only allowed the registered event key to trigger the action.
- if (evt.type == "keypress"){
- var charCode = (typeof e.which == "number") ? e.which : e.keyCode
- if (param && param.eventKey != undefined && charCode == dojo.keys[param.eventKey]) {
- evt.preventDefault();
- } else {
- return;
- }
- }
-
- if (param && param.grpAction){
- var selectedGrpKeys = this.state.getState(com.cognos.admin.util.ClientState.GROUP_ACTION_ROWS,true);
- if (!selectedGrpKeys || (selectedGrpKeys.length == 0)) {
- alert(J2H.GLB.IDS_GRP_ACTION_CHOOSE_ENTRY);
- return;
- }
- }
-
- if (param && param.prompt){
- var binded = param.prompt.binded || 'none';
- if (binded == 'none' || ((binded == 'binded') && tag.checked) || ((binded == 'reversed') && !tag.checked)){
- switch (param.prompt.type){
- case "message":
- alert (param.prompt.text);
- break;
-
- case "confirm":
- if (!confirm (param.prompt.text)){
- xPreventDefault(evt);
- tag.checked = !tag.checked;
- return;
- }
- }
- }
- }
-
- /* this recusive function will walk through the JSON for cascading menu,
- * and attach the anonymous function for each click event, inside of which, it recall the main
- * function (_evt_doAction) with different arguments. See the j2html JS behaviour controller
- * framework functional SPEC for more details.
- */
- function parseItems (oItems) {
- for (var i = 0; i < oItems.length; i++){
- var oAction = oItems[i].action;
- if (oAction && !self.parseFunc(oAction))
- oItems[i].action = getAction (oAction);
-
- if (oItems[i].items)
- parseItems(oItems[i].items);
- }
- };
-
- //this function is introduced to avoid the closure in parseItems.
- function getAction (oAction) {
- //TODO: the "e" cannot get the event from popup menu
- return function (e) {
- var oEvent = new xEvent(e);
- var oTag = oEvent.target;
-
- if (com.cognos.admin.config.debug){
- _F_log ("D","Event for popup menu:");
- _F_log ("D",oEvent);
- }
-
- self._evt_doAction (oEvent,oTag,oAction);
- };
- };
-
- //apply a predefined variables to a reserved key word in args
- function applyArgs (args) {
- if (args){
- for (var i=0; i<args.length; i++){
- if (args[i] == com.cognos.admin.widget.Event.EVENT){
- args[i] = e;
- } else if (args[i] == com.cognos.admin.widget.Event.TAG){
- args[i] = tag;
- } else if (args[i] == com.cognos.admin.widget.Event.ENV){
- args[i] = self;
- }
- }
- }
- return args;
- };
-
- function applyBreadCrumbs(state, param) {
- if (param.model.bc_idx) {
- var crumbs = state.getState(com.cognos.admin.util.ClientState.BREADCRUMBS,true);
- if (!crumbs) {
- crumbs = [];
- }
- if (crumbs.length < param.model.bc_idx) { //ensure the breadcrumbs size does not increase if user is clicking link multiple times prior to refresh
- crumbs[crumbs.length] = param;
- }
-
- }
-
- if (param.model.bc_title) {
- state.setState(com.cognos.admin.util.ClientState.BREADCRUMBS,crumbs,true);
- }
-
- if (crumbs && param.breadcrumb) {
- crumbs.length = param.breadcrumb.idx;
- }
- };
- if (param && param.actionType){
- switch (param.actionType){
- case "function":
- if (param.functionName){
- if (param.args){
- applyArgs (param.args);
- }
-
- try {
- ret = this.tools.fnParse(param.functionName,param.args);
- } catch (ex) {
- _F_log("E",ex.message);
- }
- }
- break;
-
- case "extension":
- if (param.args){
- for (var o in param.args){
- if (typeof param.args[o] !== 'function') {
- applyArgs(param.args[o]);
- }
- }
- }
- var obj = window;
- var cArgs = param.args["cArgs"] || [];
- var fArgs = param.args["fArgs"] || [];
-
- if (param.thisObj){
- if (typeof param.thisObj == "object"){
- obj = param.thisObj;
- } else if (typeof param.thisObj == "function") {
- obj = new param.thisObj(cArgs);
- } else if (typeof param.thisObj == "string") {
- obj = new com.cognos.admin.extension[param.thisObj](cArgs);
- }
- }
-
- if (param.functionName){
- try {
- ret = obj[param.functionName].apply(obj,fArgs);
- } catch (ex) {
- _F_log("E",ex.message);
- }
- }
- break;
-
- case "iframeDialog":
- 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);
- break;
-
- case "trans":
- //init transient if any
- if (trans = param.trans) {
- if (trans instanceof Array){
- var updateList = [];
- for (var j = 0; j < trans.length; j++){
- if (trans[j].list instanceof Array){
- for (var i = 0; i < trans[j].list.length; i++){
- if (param.model[trans[j].list[i]] !== undefined)
- if (trans[j].skipThisReload) {
- //The active fragment only wants it's transient values updated. Skip the retrieve. (eg. ScoreCard view resource selection)
- this.fragment.transientUpdateCheck(trans[j].list[i], param.model[trans[j].list[i]], trans[j].channel, false);
- }
- updateList.push (this.tools.createTransient(trans[j].list[i],param.model[trans[j].list[i]],trans[j].scope,trans[j].channel));
- }
- }
- }
- this.fragment.transientUpdateList (updateList);
-
- if (com.cognos.admin.config.debug){
- _F_log ("D","Transient update list:");
- _F_log("D",updateList);
- }
- }
- }
- break;
-
- case "dialog":
- if (param.ui.styles == 0) {
- //Hidden.
- self.fragment.destroy();
- self._evt_unloadTable();
- self.fragment.parent.raiseEvent("fragment.refresh");
- } else {
- var dId = this.table.id.toString() + (param.ui.id?param.ui.id:"dialog");
- var dTitle = param.ui.title;
- var dStyles = param.ui.styles || 1;
- var dX = param.ui.x || 168;
- var dY = param.ui.y || 10;
- var dDx = param.ui.dx || 550;
- var dDy = param.ui.dy;
-
- if ($(dId)){
- document.body.removeChild($(dId));
- }
-
- var uiDialog = new ui_dialog(dId,dTitle,dStyles,dX,dY,dDx,dDy);
- uiDialog.show();
- if (param.content)
- this.tools.parseContent(param.content,dId+"content",this.state);
-
- //command button section
- uiDialog.processCommand = function (btnType){
- switch (btnType) {
- //TODO: raise btnType context specific events
- case "cancel":
- return true;
- default:
- self.fragment.destroy();
- self._evt_unloadTable();
- self.fragment.parent.raiseEvent("fragment.refresh");
- return true;
- }
- }
- }
- break;
-
- case "menu":
- if (!this.menu) {
- this.menu = new ui_menu();
- this.menu.fragment = this.fragment;
- }
- if (param.url){
- var cacheKey = param.url+this.tools.JSON.stringify(param.parameters);
- var cachedMenu = this.menuCache[cacheKey];
- if (cachedMenu) {
- this.menu.menudef=cachedMenu;
- this.menu.rebuild = true;
- this.menu.show(evt);
- } else {
- var THIS = this;
- var a = new this.tools.ajaxObj();
- a.setUrl (param.url);
-
- if (param.method)
- a.setMethod (param.method);
-
- if (param.parameters)
- a.setParameters (param.parameters);
- if (!evt.target.srcOrig) {
- evt.target.srcOrig = evt.target.src;
- }
-
- a.onSuccess = function(transport) {
- evt.target.style.cursor= "default";
- var responseObj = self.tools.cogEval(transport.responseText);
- if (evt.target.srcOrig){
- evt.target.src = evt.target.srcOrig;
- }
- if (responseObj){
- if (items = responseObj.items) {
- parseItems(items);
- if (param.cache) {
- THIS.menuCache[cacheKey] = responseObj;
- }
- THIS.menu.rebuild = true;
- THIS.menu.menudef=responseObj;
- THIS.menu.show(evt);
- } else {
- //The menu wasn't returned.
- var fragNode = _F_DOM.selectSingleNode(responseObj, "/fragment");
- if (fragNode) {
- //It's an Error fragment. Process it.
- THIS.fragment.processFragmentXML(fragNode,evt.target);
- } else {
- //Not an Error fragment, Could be an HTML error response. Alert the user as best we can.
- var txt = transport.responseText;
- var code = _F_Document.extractTagText(txt, "ERROR_CODE");
- if (code == "CAM_PASSPORT_ERROR") {
- // substitute the error code to an invalid passport
- THIS.fragment.processError("invalidCredentials", null, null);
- } else {
- // open up that HTML markup and let the end-user deal with it
- if (!code) {
- code="ERROR HTTP-"+transport.status;
- }
- var msg = _F_Document.extractTagText(txt, "ERROR_MSG");
- if (!msg) {
- msg=code+" " + THIS.tools.JSON.stringify(param);
- }
- var details = _F_Document.extractTagText(txt, "ERROR_DETAILS");
- if (!details) {
- details=txt;
- }
- THIS.fragment.processError(code, msg, details);
- 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");
- w.document.open();
- w.document.write(txt);
- w.document.close();
- w.focus();
- }
- THIS.fragment.raiseEvent("fragment.retrieve.after", false, "xsd:boolean");
- _F_log("W", "expecting XML, got HTML for fragment: "+THIS.fragment.id);
- }
- }
- }
- };
-
- //To avoid jumpiness, only change the menu icon if it matches the size of icon_loading.gif. Otherwise, just change the mouse cursor.
- if (evt.target.src && (evt.target.height == 16)) {
- evt.target.src=_F_Config.webContent+'/ps/portal/images/icon_loading.gif';
- } else {
- evt.target.style.cursor = "wait";
- }
- a.run();
- }
- } else if (param.model) {
- var cacheKey = param.model.id;
- var cachedMenu = this.menuCache[cacheKey];
- if (cachedMenu) {
- this.menu.menudef=cachedMenu;
- } else {
- this.menu.menudef=param.model;
- this.menuCache[cacheKey] = param.model;
- }
- if (items = param.model.items) {
- parseItems(items);
- }
- this.menu.rebuild = true;
- this.menu.show(evt);
- }
-
- break;
- case "retrieve":
- if (param.model){
- var targetDivID = param.model.targetDivID || this.fragment.div;
- var targetFragID = param.model.targetFragID;
- var url = param.model.url;
- var args = param.model.args;
-
- applyBreadCrumbs(this.state, param);
-
- if (args) {
- for (var o in args){
- if (typeof args[o] !== 'function') {
- this.state.setState(o,args[o]);
- }
- }
- }
- if (targetFragID) {
- var frag = _F_getFragmentByID(targetFragID);
- if (frag && url && frag.path != url) {
- frag.path = url;
- }
- }
- if (targetFragID == this.fragment.id){
- this.fragment.retrieve();
- } else {
- if (targetDivID && !$(targetDivID)) {
- var targetDiv = document.createElement("div");
- targetDiv.id = targetDivID;
- targetDiv.style.display = "none";
- document.body.appendChild(targetDiv);
- }
- var frag = this.fragment;
- if (targetFragID) {
- frag = _F_getFragmentByID(targetFragID) || this.tools.createFragment(url,targetFragID,targetDivID);
- }
- frag.retrieve(this.state.getStateURL(),targetDivID);
- }
- }
- break;
-
- case "toggle":
- if (param.target) {
- for (var i=0; i<param.target.length; i++){
- var item;
- if (tag.checked == true && param.target[i].selected){
- item = param.target[i].selected;
- } else if (tag.checked == false && param.target[i].deselected){
- item = param.target[i].deselected;
- }
-
- if (item){
- this._evt_doAction(e,$(param.target[i].targetId),item);
- }
- }
- }
- break;
- case "dhtml":
- //Flip the current dhtml attrs with the ones supplied within the cogparam
- if (param.targets) {
- for (var i=0; i<param.targets.length; i++){
- for (var attr in param.targets[i].attributes) {
- var target = $(this.fragment.id+param.targets[i].id);
- if (target != null) {
- var currentValue = target.getAttribute(attr); //temp store for the current dhtml attrs
- var newValue = param.targets[i].attributes[attr] //get the dhtml attr from the cogparam
- if (attr == "style") {
- //overcome IE's lack of setAttribute support for "style" attr. Has no effect for Firefox
- currentValue = target.style.cssText;
- target.style.cssText = newValue;
- }
- target.setAttribute(attr, newValue); //change the current dhtml attr with the one supplied in the cogparam
- param.targets[i].attributes[attr] = currentValue; //Update the cogparm dhtml attr with the current one
- }
- }
- }
- tag.setAttribute("cogparam",com.cognos.admin.util.Tools.JSON.stringify(param)); //update the cogparam dhtml attrs
-
- }
- break;
-
- default:
- var thisObj = window;
- var obj = param.actionType;
-
- //Try three different ways to active an action.
- //from an existed object
- if (typeof obj == "object"){
- thisObj = obj;
-
- //from an instantiated function
- } else if (typeof obj == "function") {
- thisObj = new obj (this);
-
- //from extension handler underneath js/extension, do nothing otherwise
- } else {
- thisObj = this.extensionFuncs[obj];
- if (!thisObj) {
- _F_log("D","No matched extensionHandler was found for: name="+obj);
- return false;
- }
- }
-
- if (typeof thisObj["doAction"] === "function"){
- try {
- ret = thisObj["doAction"].apply(thisObj,[e,tag,param]);
- } catch (ex) {
- _F_log("E",ex.message);
- }
- } else {
- throw new Error("Missing 'doAction' interface implementation in " + param.actionType);
- }
- }
- }
- return ret;
- },
- /* apply the sort to the table column
- *
- */
- _evt_sortColumn : function (e,tag) {
- // "Enter" key supported
- var evt = new xEvent(e);
- if (evt.type == "keypress"){
- if (evt.keyCode == dojo.keys.ENTER) {
- evt.preventDefault();
- } else {
- return;
- }
- }
-
- var sortParam = this.tools.cogEval(tag)
- if (!sortParam) return false;
- this.state.setState(com.cognos.admin.util.ClientState.SORT,sortParam,true);
- this.fragment.retrieve();
- },
-
- /* apply the filter
- *
- */
- _evt_filterColumn : function (e,tag) {
- var param = this.tools.cogEval(tag)
- if (!param) return false;
-
- //TODO:target parameter will be: "filter=Table1:1:inclusive:poor;average;good;other;2:exclusive:A:B:C:D"
- var filterParam = param.filterName + "=1:false:";;
-
- for (var j = 0; j < this.filterColumns[param.filterName].length; j++){
- if (this.filterColumns[param.filterName][j].checked)
- filterParam += this.filterColumns[param.filterName][j].value + ";";
- }
-
- this.fragment.retrieve(filterParam);
- },
-
- //for client side filter summary widget only
- _evt_filterSummary : function (tag){
- var param = this.tools.cogEval(tag);
- if (!param) return false;
-
- var fs = new com.cognos.admin.widget.FilterSummary(tag,param);
- },
-
- /*
- *
- */
- _evt_mouseOverLink : function (tag){
- tag.style.cursor = "pointer";
- },
-
- /*
- *
- */
- _evt_defaultCursor : function (tag){
- tag.style.cursor = "default";
- },
-
- /* change the styles for an action button when mouseover
- *
- */
- _evt_mouseOverElt : function (e,tag) {
- if (!tag.getAttribute("origclass")) {
- tag.setAttribute("origclass",tag.className);
- }
-
- if (this.tools.includeClass(tag,'cogstyle-toolbar-imageNormal')) {
- tag.className = 'cogstyle-toolbar-imageOver';
- }
-
- if (this.tools.includeClass(tag,'cogstyle-toolbar-imagePressed')) {
- tag.className = 'cogstyle-toolbar-imageOverPressed';
- }
-
- if (this.tools.includeClass(tag,'cogstyle-table-row-default')) {
- tag.className = 'cogstyle-table-row-hilite';
- }
-
- if (this.tools.includeClass(tag,'cogstyle-table-row-alternate')) {
- tag.className = 'cogstyle-table-row-hilite';
- }
-
- if (this.tools.includeClass(tag,'button')) {
- tag.className = 'button_hover';
- }
- },
- /* change the styles for an action button when mouseout
- *
- */
- _evt_mouseOutElt : function (e,tag) {
-
- if (this.tools.includeClass(tag,'cogstyle-toolbar-imageOver')) {
- tag.className = tag.getAttribute("origclass");
- }
- if (this.tools.includeClass(tag,'cogstyle-toolbar-imageOverPressed')) {
- tag.className = tag.getAttribute("origclass");
- }
-
- if (this.tools.includeClass(tag,'cogstyle-table-row-alternate')) {
- tag.className = tag.getAttribute("origclass");
- }
- if (this.tools.includeClass(tag,'cogstyle-table-row-hilite')) {
- tag.className = tag.getAttribute("origclass");
- }
-
- if (this.tools.includeClass(tag,'button_hover') || this.tools.includeClass(tag,'button_pressed')) {
- tag.className = 'button';
- }
- },
- /* change the styles for an action button when mouse click
- *
- */
- _evt_mouseClickElt : function (e,tag) {
- //this is for the selectable row
- if (tag.className.search(/^cogstyle-table-row-/i) != -1 && tag.parentNode.nodeType == 1){
- for (var m = tag.parentNode.firstChild; m != null; m = m.nextSibling){
- if (this.tools.includeClass(m,"cogstyle-table-row-selected")){
- var origClass = m.getAttribute("origclass");
- m.className = origClass ? origClass : 'cogstyle-table-row-default';
- break;
- }
- }
- if (!tag.getAttribute("origclass")) {
- tag.setAttribute("origclass",tag.className);
- }
- tag.className = "cogstyle-table-row-selected";
- this.state.setState(com.cognos.admin.util.ClientState.SELECTED_ROW,this.tools.getKey(tag),true);
-
- }
- },
- /* change the styles for an action button when mouse down
- *
- */
- _evt_mouseDownElt : function (e,tag) {
- if (this.tools.includeClass(tag,'button') || this.tools.includeClass(tag,'button_hover')) {
- tag.className = 'button_pressed';
- }
- },
-
- /* change the styles for an action button when mouse up
- *
- */
- _evt_mouseUpElt : function (e,tag) {
- if (this.tools.includeClass(tag,'button_pressed')) {
- tag.className = 'button';
- }
- },
- /*
- *
- */
- _evt_showTooltip : function (e,tag){
- var param = this.tools.cogEval(tag);
-
- if (param){
- param.content = this._evt_doAction(e,tag,param);
- if (param.content){
- this.tooltip = new com.cognos.admin.widget.Tooltip(tag,e,param);
- this.tooltip.show();
- }
- }
- },
-
- _evt_hideTooltip : function (e,tag){
- if (this.tooltip) this.tooltip.hide();
- },
- //*****************************init for fragment begin***********************************
- /*
- *
- */
- _evt_fgmtRefresh : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.refresh');
- }
- },
- /*
- *
- */
- _evt_fgmtResize : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.resize');
- }
-
- //init the resizing content table
- if ($(this.contentTable)){
- var winState = this.fragment.cogadminWindowState || this.fragment.windowState;
- this.tools.adjustTableHeight(this.frameTable,this.contentTable,winState,this.numRow);
- }
- },
-
- /*
- *
- */
- _evt_fgmtLoad : function (evt,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.load');
- _F_log('D','state:');
- _F_log(this.state.states);
- }
-
- //init the contentTable after the CogTable was initialized
- if (this.context.getPublicVariables("contentTableId"))
- this.contentTable = this.context.getPublicVariables("contentTableId");
-
- //init the depth of the current fragment
- if (num = this.context.getPublicVariables("depth")){
- var obj = this.fragment;
- for (var n = 0; n < num; n++){
- if (obj.parent)
- obj = obj.parent;
- else
- break;
- }
- this.frameTable = obj.id+"frame";
- }
-
- //init the number of the vertical frags
- if (this.context.getPublicVariables("numRow"))
- this.numRow = this.context.getPublicVariables("numRow");
-
- //init the vertical and horizonal scroll position
- if ($(this.contentTable)){
- $(this.contentTable).scrollTop = this.state.getState(com.cognos.admin.util.ClientState.SCROLL_TOP,true);
- $(this.contentTable).scrollTop = this.state.getState(com.cognos.admin.util.ClientState.SCROLL_LEFT,true);
-
- //init the windowS resizing content table
- this.fragment.cogadminWindowState = this.state.getState(com.cognos.admin.util.ClientState.COGADMIN_WINDOW_STATE,true);
- var winState = this.fragment.cogadminWindowState || this.fragment.windowState;
- this.tools.adjustTableHeight(this.frameTable,this.contentTable,winState,this.numRow);
- }
- },
-
- /*
- *
- */
- _evt_fgmtUnload : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.unload');
- }
- },
-
- /*
- *
- */
- _evt_fgmtRetrieveBefore : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.retrieve.before');
- }
- //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.
- //TODO: Trakker 592247. Refactor this solution once/if CPS adds an enhancement to easily augment e.payload within "fragment.before.retrieve" event.
- if ($(this.contentTable)){
- this.state.setState (com.cognos.admin.util.ClientState.SCROLL_TOP,$(this.contentTable).scrollTop,true);
- this.state.setState (com.cognos.admin.util.ClientState.SCROLL_LEFT,$(this.contentTable).scrollLeft,true);
- }
-
- this.state.setSkipPersistStates (this.context.getPublicVariables("skipPersistClientState"));
- e.payload.value = (e.payload.value ? e.payload.value+"&" : '')+this.state.getStateURL();
- },
-
- /*
- *
- */
- _evt_fgmtRetrieveAfter : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.retrieve.after');
- }
-
- },
-
- /*
- *
- */
- _evt_fgmtCreate : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.create');
- }
- },
-
- /*
- *
- */
- _evt_fgmtDestroy : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.destroy');
- }
- },
-
- /*
- *
- */
- _evt_fgmtError : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.error');
- }
- },
-
- /*
- *
- */
- _evt_fgmtTitleChange : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.title.change');
- }
- },
-
- /*
- *
- */
- _evt_fgmtWindowstateChange : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.windowstate.change');
- }
-
- //init the resizing content table
- if ($(this.contentTable)){
- var winState = e.payload.newWindowState;
- if (winState == "normal" && this.fragment.cogadminWindowState == "extended")
- winState = "extended";
-
- this.tools.adjustTableHeight(this.frameTable,this.contentTable,winState,this.numRow);
- }
-
- if (this.numRow > 1)
- this.fragment.raiseEvent("cogadmin.fragment.windowstate.change",e.payload.newWindowState);
-
-
- },
-
- /*
- *
- */
- _evt_fgmtModeChange : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','fragment.mode.change');
- }
- },
-
- _evt_menuSelect : function (e,tag) {
- var menuDef = e.payload.menuDef;
- var selectedIdx = e.payload.selectedIdx;
- var target = $(this.fragment.id+menuDef.id);
- if (target) {
- target[target.getAttribute("textAttr")] = menuDef.items[selectedIdx].title;
- var valueAttr = document.createAttribute("pvalue");
- valueAttr.nodeValue = menuDef.items[selectedIdx].id;
- target.setAttributeNode(valueAttr);
- }
- if (com.cognos.admin.config.debug){
- _F_log('D','uicommon.menu.select');
- }
- },
-
- //*****************************init for fragment end***********************************
-
- //*****************************init for j2html customized fragment event start***********************************
- _evt_cadminFragRefresh : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','cogadmin.refresh');
- }
- this._evt_fgmtRefresh(e,tag);
-
- },
-
- _evt_distCadminFragWschange : function (e,tag) {
- if (com.cognos.admin.config.debug){
- _F_log('D','_evt_distCadminFragWschange');
- }
-
- if ($(this.contentTable)){
- if (e.source.id != this.fragment.id) {
- if (this.numRow > 1) {
- switch (e.payload){
- case "minimized":
- this.fragment.cogadminWindowState = "extended";
- this.state.setState(com.cognos.admin.util.ClientState.COGADMIN_WINDOW_STATE,"extended",true);
- this.tools.adjustTableHeight(this.frameTable,this.contentTable,"extended",this.numRow);
- break;
- case "normal":
- this.fragment.cogadminWindowState = null;
- this.state.clearState(com.cognos.admin.util.ClientState.COGADMIN_WINDOW_STATE,true);
- this.tools.adjustTableHeight(this.frameTable,this.contentTable,"normal",this.numRow);
- break;
- default:
- }
- }
- }
- }
- },
- _evt_retrieve : function(sParams, dest, synchronous) {
- if (com.cognos.admin.config.debug){
- _F_log('D','_evt_retrieve');
- }
- paramsObj = new ParamsObject(sParams);
- this._retrieve(paramsObj, dest, synchronous);
-
- function ParamsObject (params) {
- this.value = params;
-
- this.valueOf = function() {
- return this.value;
- }
-
- this.indexOf = function(value) {
- return this.value.indexOf(value);
- }
- }
- }
- //*****************************init for cogadmin customized fragment event end***********************************
-
- };
|