123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682 |
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Viewer
- *| (C) Copyright IBM Corp. 2001, 2017
- *|
- *| US Government Users Restricted Rights - Use, duplication or
- *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
- *|
- *+------------------------------------------------------------------------+
- */
- /**
- * CViewerToolbar
- * @constructor
- */
- function CViewerToolbar()
- {
- this.m_specification = null;
- this.m_oCBar = null;
- this.m_sWebContentRoot = null;
- this.m_sSkin = null;
- }
- /**
- * Returns the namespace defined in the JSON specification
- * @return (string)
- */
- CViewerToolbar.prototype.getNamespace = function()
- {
- if(this.m_specification && typeof this.m_specification.namespace != "undefined")
- {
- return this.m_specification.namespace;
- }
- return "";
- };
- /**
- * Returns the webContentRoot
- * @return (string)
- */
- CViewerToolbar.prototype.getSkin = function()
- {
- if (this.m_sSkin == null)
- {
- var oCV = null;
- try
- {
- oCV = getCognosViewerObjectRef(this.getNamespace());
- }
- catch(exception){}
- if (oCV)
- {
- this.m_sSkin = oCV.getSkin();
- }
- else
- {
- this.m_sSkin = this.getWebContentRoot() + "/skins/corporate";
- }
- }
- return this.m_sSkin;
- };
- /**
- * Returns the webContentRoot
- * @return (string)
- */
- CViewerToolbar.prototype.getWebContentRoot = function()
- {
- if (this.m_sWebContentRoot == null)
- {
- var oCV = null;
- try
- {
- oCV = getCognosViewerObjectRef(this.getNamespace());
- }
- catch(exception){}
- if (oCV)
- {
- this.m_sWebContentRoot = oCV.getWebContentRoot();
- }
- else
- {
- this.m_sWebContentRoot = "..";
- }
- }
- return this.m_sWebContentRoot;
- };
- /**
- * Returns the div id where the toolbar renders itself
- * @return (string)
- */
- CViewerToolbar.prototype.getDivId = function()
- {
- if(this.m_specification && typeof this.m_specification.divId != "undefined")
- {
- return this.m_specification.divId;
- }
- return "";
- };
- /**
- * Returns the local defined style used by the viewer front end
- * @return (string)
- */
- CViewerToolbar.prototype.getStyle = function()
- {
- if(this.m_specification && typeof this.m_specification.style != "undefined")
- {
- return this.m_specification.style;
- }
- return "";
- };
- /**
- * Returns the toolbar specification (CViewerToolbarSpecification) defined by the JSON specification passed in to the initialize method
- * @return CViewerToolbarSpecification
- */
- CViewerToolbar.prototype.getToolbarSpecification = function()
- {
- if(this.m_specification && typeof this.m_specification.S != "undefined")
- {
- return new CViewerToolbarSpecification(this,this.m_specification.S);
- }
- return null;
- };
- /**
- * Returns the ui item specified by the id (the id should not contain the namespace, the viewer toolbar will look after appending it
- * @return UI item (CMenuItem, CToolbarButton, StaticText, etc)
- */
- CViewerToolbar.prototype.getItem = function(sId)
- {
- if(this.m_oCBar)
- {
- var numItems = this.m_oCBar.getNumItems();
- sId = this.getNamespace() + sId;
- for(var index = 0; index < numItems; ++index)
- {
- var uiItem = this.m_oCBar.get(index);
- if(typeof uiItem.getId == "function" && uiItem.getId() == sId)
- {
- return uiItem;
- }
- }
- }
- return null;
- };
- /**
- * Initializes the viewer toolbar
- * @param jsonSpecification - JSON object specification
- */
- CViewerToolbar.prototype.init = function(jsonSpecification)
- {
- if(typeof jsonSpecification != "undefined" && typeof jsonSpecification == "object" && jsonSpecification != null)
- {
- this.m_specification = jsonSpecification;
- }
- };
- /**
- * Returns the CBar object
- */
- CViewerToolbar.prototype.getCBar = function()
- {
- if (!this.m_oCBar && this.m_specification)
- {
- this.load();
- }
- return this.m_oCBar;
- };
- /**
- * Creates a CBar object using the json specification
- */
- CViewerToolbar.prototype.load = function()
- {
- var toolbar = null;
- if(this.m_specification != null)
- {
- var divId = this.getDivId();
- var divNode = document.getElementById(divId);
- var toolbarSpecification = this.getToolbarSpecification();
- if(divNode && toolbarSpecification)
- {
- toolbar = toolbarSpecification.draw();
- }
- }
- this.m_oCBar = toolbar;
- return toolbar;
- };
- /**
- * Renders the viewer toolbar within the containing <div> element.
- */
- CViewerToolbar.prototype.draw = function()
- {
- if (this.m_oCBar)
- {
- this.m_oCBar.draw();
- }
- };
- /**
- * CViewerToolbarSpecification
- * @constructor
- */
- function CViewerToolbarSpecification(viewerToolbar, jsonSpecification)
- {
- this.m_viewerToolbar = viewerToolbar;
- this.m_toolbarSpecification = jsonSpecification;
- }
- /**
- * Builds ui elements using the toolbar specification
- */
- CViewerToolbarSpecification.prototype.draw = function()
- {
- if(this.m_toolbarSpecification)
- {
- var toolbarStyle = gToolbarStyle;
- if (this.m_viewerToolbar.getStyle() === 'banner')
- {
- toolbarStyle = gBannerToolbarStyle;
- }
- var toolbar = new CBar(this.m_viewerToolbar.getDivId(), toolbarStyle, null, this.m_viewerToolbar.getWebContentRoot());
- toolbar.setMenuType(cHorizonalBar); // TODO: Where is cHorizontalBar defined?
- toolbar.style = this.m_viewerToolbar.getStyle();
- toolbar.setAlign("right");
- // have we placed a button, menuItem on the toolbar yet
- var bToolbarHasItem = false;
- // keeps the seperatorSpec until we go to place the next item
- var oSeperatorObj = null;
- var oSeperatorSpecification = null;
- for (var iIndex=0; iIndex < this.m_toolbarSpecification.length; iIndex++)
- {
- for(var uiItem in this.m_toolbarSpecification[iIndex])
- {
- try
- {
- var object = eval("new " + uiItem + "();");
- // P = Seperator
- if (uiItem == "P")
- {
- if (bToolbarHasItem && oSeperatorSpecification == null)
- {
- oSeperatorObj = object;
- oSeperatorSpecification = this.m_toolbarSpecification[iIndex][uiItem];
- }
- }
- else
- {
- var itemSpec = this.m_toolbarSpecification[iIndex][uiItem];
- if (itemSpec.N !== 'openWith' || !window.isIOS()) {
- bToolbarHasItem = true;
- if (oSeperatorSpecification != null && oSeperatorObj != null) {
- oSeperatorObj.load(toolbar, oSeperatorSpecification, this.m_viewerToolbar);
- oSeperatorObj = null;
- oSeperatorSpecification = null;
- }
- object.load(toolbar, itemSpec, this.m_viewerToolbar);
- }
- }
- }
- catch(exception){}
- }
- }
- return toolbar;
- }
- return null;
- };
- // CVButton
- function B(){}
- B.prototype.isValid = function(jsonSpecification)
- {
- if(jsonSpecification != null)
- {
- return true;
- }
- return false;
- };
- B.prototype.load = function(parentObject, jsonSpecification, viewerToolbar)
- {
- if(this.isValid(jsonSpecification))
- {
- var sTooltip = "";
- var sImage = "";
- var sAction = "";
- var sName = jsonSpecification.N;
- var menuItems = null;
- if (typeof jsonSpecification.M != "undefined" && jsonSpecification.M.IS != "undefined")
- {
- menuItems = jsonSpecification.M.IS;
- }
- // if we don't have an icon defined, then use the first menu item for the button
- if (typeof jsonSpecification.C == "undefined")
- {
- if(menuItems)
- {
- var firstMenuItem = menuItems[0]["I"];
- if (firstMenuItem != null && this.isValid(firstMenuItem))
- {
- sTooltip = firstMenuItem.O;
- if (typeof sTooltip == "undefined" || sTooltip == "")
- {
- sTooltip = firstMenuItem.E;
- }
- sImage = firstMenuItem.C;
- sAction = firstMenuItem.A;
- }
- }
- }
- else
- {
- sTooltip = jsonSpecification.O;
- sImage = jsonSpecification.C;
- sAction = jsonSpecification.A;
- }
- var toolbarButton = null;
- if (viewerToolbar.getStyle() === "banner")
- {
- toolbarButton = new CMenuItem(parentObject, "", sAction, sImage, gBannerButtonStyle, viewerToolbar.getWebContentRoot(), viewerToolbar.getSkin());
- toolbarButton.setDropDownArrow("dropdown_arrow_banner.gif");
- }
- else
- {
- toolbarButton = new CMenuItem(parentObject, "", sAction, sImage, gMenuItemStyle, viewerToolbar.getWebContentRoot(), viewerToolbar.getSkin());
- toolbarButton.setDropDownArrow("dropdown_arrow_narrow.gif");
- }
- toolbarButton.setId(viewerToolbar.getNamespace() + sName);
- toolbarButton.setToolTip(sTooltip);
- if (typeof jsonSpecification.ALT != "undefined")
- {
- toolbarButton.setAltText(jsonSpecification.ALT);
- }
- if(typeof jsonSpecification.D != "undefined" && jsonSpecification.D == "true")
- {
- toolbarButton.disable();
- }
- if(typeof jsonSpecification.M != "undefined")
- {
- var menuSpecification = jsonSpecification.M;
- // only add the menu if there's more then one entry, or we have a callback to populate the menu
- if (
- typeof menuSpecification.Y != "undefined" &&
- (
- typeof menuSpecification.A != "undefined" ||
- (menuItems && menuItems.length > 1) ||
- (typeof menuSpecification.H == "undefined" || menuSpecification.H == "false")
- )
- )
- {
- var menu = new M();
- toolbarButton.m_menu = menu.load(parentObject, menuSpecification, viewerToolbar);
- toolbarButton.m_menu.setParent(toolbarButton);
- toolbarButton.m_menuType = menuSpecification.Y;
- }
- }
- return toolbarButton;
- }
- return null;
- };
- // Menu Item
- function I(){}
- I.prototype.isValid = function(jsonSpecification)
- {
- if(typeof jsonSpecification != "undefined" && jsonSpecification != null)
- {
- return true;
- }
- return false;
- };
- I.prototype.load = function(parentObject, jsonSpecification, viewerToolbar)
- {
- if(this.isValid(jsonSpecification))
- {
- var sText = jsonSpecification.E;
- var sImage = jsonSpecification.C;
- var sAction = jsonSpecification.A;
- var sName = jsonSpecification.N;
- var menuItems = null;
- if (typeof jsonSpecification.M != "undefined" && jsonSpecification.M.IS != "undefined")
- {
- menuItems = jsonSpecification.M.IS;
- }
- // if we don't have an icon defined, then use the first menu item for the button
- if (typeof jsonSpecification.E == "undefined")
- {
- if(menuItems && menuItems[0])
- {
- var firstMenuItem = menuItems[0]["I"];
- if (firstMenuItem != null && this.isValid(firstMenuItem))
- {
- sText = firstMenuItem.E;
- if (typeof sText == "undefined" || sText == "")
- {
- sText = firstMenuItem.O;
- }
- sAction = firstMenuItem.A;
- }
- }
- else {
- return null;
- }
- }
- else
- {
- sText = jsonSpecification.E;
- sImage = jsonSpecification.C;
- sAction = jsonSpecification.A;
- }
- var menuStyle = null;
- if (parentObject.style && parentObject.style === "banner")
- {
- menuStyle = gBannerItemStyle;
- }
- else
- {
- menuStyle = gMenuItemStyle;
- }
- var menuItem = new CMenuItem(parentObject, sText, sAction, sImage, menuStyle, viewerToolbar.getWebContentRoot(), viewerToolbar.getSkin());
- if(typeof jsonSpecification.ALT != "undefined")
- {
- menuItem.setAltText(jsonSpecification.ALT);
- }
- if (parentObject.style && parentObject.style === "banner")
- {
- menuItem.setDropDownArrow("dropdown_arrow_banner.gif");
- }
- else
- {
- menuItem.setDropDownArrow("dropdown_arrow_narrow.gif");
- }
- menuItem.setId(viewerToolbar.getNamespace() + sName);
- if(typeof jsonSpecification.D != "undefined" && jsonSpecification.D == "true")
- {
- menuItem.disable();
- }
- if(typeof jsonSpecification.M != "undefined")
- {
- var menuSpecification = jsonSpecification.M;
- // only add the menu if there's more then one entry, or we have a callback to populate the menu
- if (
- typeof menuSpecification.Y != "undefined" &&
- (
- typeof menuSpecification.A != "undefined" ||
- (menuItems && menuItems.length > 1) ||
- (typeof menuSpecification.H == "undefined" || menuSpecification.H == "false")
- )
- )
- {
- var menu = new M();
- menuItem.m_menu = menu.load(parentObject, menuSpecification, viewerToolbar);
- menuItem.m_menu.setParent(menuItem);
- menuItem.m_menuType = jsonSpecification.M.Y;
- }
- }
- return menuItem;
- }
- return null;
- };
- // Menu
- function M(){}
- M.prototype.isValid = function(jsonSpecification)
- {
- return (typeof jsonSpecification != "undefined" && jsonSpecification != null && typeof jsonSpecification.id != "undefined");
- };
- M.prototype.load = function(parentObject, jsonSpecification, viewerToolbar)
- {
- if(this.isValid(jsonSpecification))
- {
- var menu = new CMenu(jsonSpecification.id, gMenuStyle, viewerToolbar.getWebContentRoot());
- menu.setParent(parentObject);
- if (typeof jsonSpecification.ALT != "undefined")
- {
- menu.setAltText(jsonSpecification.ALT);
- }
- try
- {
- menu.m_oCV = getCognosViewerObjectRef(viewerToolbar.getNamespace());
- }
- catch(e){}//if we can't get the cognos viewr object, eat the exception
- if(typeof jsonSpecification.A != "undefined")
- {
- menu.registerCallback(jsonSpecification.A);
- }
- var menuItems = jsonSpecification.IS;
- if (menuItems)
- {
- for(var iIndex=0; iIndex < menuItems.length; iIndex++)
- {
- for(var uiItem in menuItems[iIndex])
- {
- try
- {
- var menuItem = new I();
- menuItem.load(menu, menuItems[iIndex][uiItem], viewerToolbar);
- }
- catch(exception){}
- }
- }
- }
- return menu;
- }
- return null;
- };
- // StaticText
- function T(){}
- T.prototype.isValid = function(jsonSpecification)
- {
- return (typeof jsonSpecification != "undefined" && jsonSpecification != null && typeof jsonSpecification.E != "undefined");
- };
- T.prototype.load = function(parentObject, jsonSpecification, viewerToolbar)
- {
- if(this.isValid(jsonSpecification))
- {
- var textStyle = null;
- if (viewerToolbar.getStyle() === "banner")
- {
- textStyle = gBannerStaticText;
- }
- else
- {
- //todo
- }
- if (jsonSpecification.E && jsonSpecification.E.length > 0) {
- var oStaticText = new CStaticText(jsonSpecification.E, textStyle);
- if (jsonSpecification.N == "userName")
- {
- oStaticText.setId("userNameTD" + viewerToolbar.getNamespace());
- }
-
- if (jsonSpecification.ALT) {
- oStaticText.setLabelledBy(jsonSpecification.ALT + " " + jsonSpecification.E);
- }
-
- parentObject.add(oStaticText);
- }
- }
- return null;
- };
- // Link
- function L(){}
- L.prototype.isValid = function(jsonSpecification)
- {
- return (typeof jsonSpecification != "undefined" && jsonSpecification != null && typeof jsonSpecification.E != "undefined");
- };
- L.prototype.load = function(parentObject, jsonSpecification, viewerToolbar)
- {
- if(this.isValid(jsonSpecification))
- {
- var linkStyle = null;
- if (viewerToolbar.getStyle() === "banner")
- {
- linkStyle = gBannerLink;
- }
- else
- {
- //todo
- }
- var sAction = jsonSpecification.A;
- // todo: for now simply use the CMenuItem class
- var menuItem = new CMenuItem(parentObject, jsonSpecification.E, sAction, "", linkStyle, viewerToolbar.getWebContentRoot(), viewerToolbar.getSkin());
- // Workaround since CMenuItem currently looks at all its siblings to see if one has an icon
- menuItem.iconPlaceholder = false;
- if (jsonSpecification.ALT != "undefined")
- {
- menuItem.setAltText(jsonSpecification.ALT);
- }
- return menuItem;
- }
- return null;
- };
- // Seperator
- function P() {}
- P.prototype.isValid = function(jsonSpecification)
- {
- return (typeof jsonSpecification != "undefined" && jsonSpecification != null && typeof jsonSpecification.Y != "undefined");
- };
- P.prototype.load = function(parentObject, jsonSpecification, viewerToolbar)
- {
- if(this.isValid(jsonSpecification))
- {
- var seperator = new CSeperator(jsonSpecification.Y, "", "", viewerToolbar.getWebContentRoot());
- if (viewerToolbar.getStyle() === "banner")
- {
- seperator.setToolbarSeperatorClass("bannerDivider");
- }
- else
- {
- seperator.setToolbarSeperatorClass("toolbarDivider");
- }
- parentObject.add(seperator);
- return seperator;
- }
- return null;
- };
|