/******************************************************************************************************************************** * Licensed Materials - Property of IBM * * * * IBM Cognos Products: AGS * * * * (C) Copyright IBM Corp. 2005, 2014 * * * * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. * *********************************************************************************************************************************/ /*----------------------------------------------------------------------------------------------------- Class : CMenuItem Description : -----------------------------------------------------------------------------------------------------*/ var theMenuCnt = 1; function CMenuItem(parent, label, id, action, iconPath, style, tooltip,itemTooltip, capability) { this.m_label = label; this.m_id = id; this.m_bVisible = true; this.m_bEnabled = true; this.m_action = action; this.m_icon = new CIcon(iconPath,tooltip); this.m_parent = parent; this.m_menu = null; this.m_menuType=''; this.m_style = style; this.m_observers = new CObserver(this); this.itemTooltip = itemTooltip; this.m_capability = capability; //skin folder this.m_sSkin = (typeof getPromptSkin != "undefined" ? getPromptSkin() : "../skins/corporate"); if(typeof this.m_parent == "object" && typeof this.m_parent.add == "function") this.m_parent.add(this); } function CMenuItem_getId() { return this.m_id; } function CMenuItem_getObservers() { return this.m_observers; } function CMenuItem_setParent(parent) { this.m_parent = parent; } function CMenuItem_getParent() { return this.m_parent; } function CMenuItem_draw() { var html = '
'; var tabindexVal = -1 ; if (typeof AccessibilityHandler != "undefined" && AccessibilityHandler.isEnabled()) { tabindexVal = AccessibilityHandler.getTabindex(this); } if(this.m_menu == null || this.m_menuType=='dropDown') { html += ''; html += '-1) { html += xmlEncode(this.m_label); }else{ html += this.m_label; } html += ''; html += ''; if (this.getParent().hasCascadedChildren && this.getParent().hasCascadedChildren()) { html += ''; //} else if(!(this.getParent() instanceof CBar)) { //html += ''; }else { html += ''; } html += ''; html += '
'; } else { html += ''; html += ''; html += ''; html += ''; html += ''; } return html; } //To POST the XML it must be encoded. This is done here. Therefore we //can build a more readable XML string. window.xmlEncode = function(text) { var entityMap = { ">" : "gt", "<" : "lt", "\"" : null, "&" : null }; var retval = ""; if(!text) { return ""; } for(var i =0; i < text.length; i++) { var ch = text.charAt(i); if(entityMap[ch]) { retval += "&"+entityMap[ch]+";"; } else { retval += ch; } } return retval; } function CMenuItem_onmouseover(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // get the menu item from the html element which is handling the event var menuItem = null; var htmlElement = null; if(typeof this.menuItem != 'undefined') { menuItem = this.menuItem; htmlElement = this; } else if (this instanceof CMenuItem) { menuItem = this; htmlElement = this.getHTMLElement(); } if(menuItem == null || !(menuItem instanceof CMenuItem) || !menuItem.isEnabled()) return; if(typeof menuItem.getStyle() == "object") { htmlElement.className = menuItem.getStyle().getRolloverState(); } menu = menuItem.getMenu(); if(menu != null) { var pageWidth = 0; var pageHeight = 0; if(typeof window.innerWidth != "undefined") pageWidth = window.innerWidth; else pageWidth = document.body.clientWidth; if(typeof window.innerHeight != "undefined") pageHeight = window.innerHeight; else pageHeight = document.body.clientHeight; if(menuItem.getMenuType() == 'cascaded') { if(menu.isVisible() == false) { menu.setHTMLContainer((document.all && typeof htmlElement.document != "undefined") ? htmlElement.document.body : htmlElement.ownerDocument.body); menu.draw(); menu.show(); if(menu.get(0) != null) { menu.get(0).setFocus(); } } } else if(menuItem.getMenuType() == 'dropDown') { // check with the parent to see if there current are menus open. If there are, we'll automatically open this menu menuItemParent = menuItem.getParent(); var numOfItems = menuItemParent.getNumItems(); for(var i = 0; i < numOfItems; ++i) { currentItem = menuItemParent.get(i); if(currentItem != menuItem && typeof currentItem.getMenu == "function" && currentItem.getMenu() && currentItem.getMenu().isVisible()) { // the user clicked on the menu menu.setHTMLContainer((document.all && typeof htmlElement.document != "undefined") ? htmlElement.document.body : htmlElement.ownerDocument.body); menu.draw(); menu.show(); break; } } } } // send the message up to our parent if(menuItem.getParent() != null && typeof menuItem.getParent().onmouseover == "function") menuItem.getParent().onmouseover(evt); // notify our observers of this event menuItem.getObservers().notify(CMenuItem_onmouseover); } function CMenuItem_onfocus(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); // get the menu item from the html element which is handling the event var menuItem = null; var htmlElement = null; if(typeof this.menuItem != 'undefined') { menuItem = this.menuItem; htmlElement = this; } else if (this instanceof CMenuItem) { menuItem = this; htmlElement = this.getHTMLElement(); } if(menuItem == null || !(menuItem instanceof CMenuItem) || !menuItem.isEnabled()) return; if(menuItem.getMenuType() == "dropDown") { AccessibilityHandler.setTabindex(menuItem); } if(typeof menuItem.getStyle() == "object") { htmlElement.className = menuItem.getStyle().getRolloverState(); AccessibilityHandler.setRolloverState(menuItem); } // send the message up to our parent (a fake mouseover) if(menuItem.getParent() != null && typeof menuItem.getParent().onmouseover == "function") menuItem.getParent().onmouseover(evt); // notify our observers of this event menuItem.getObservers().notify(CMenuItem_onfocus); } function CMenuItem_onmouseout(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); var menuItem = null; var htmlElement = null; if(typeof this.menuItem != 'undefined') { menuItem = this.menuItem; htmlElement = this; } else if (this instanceof CMenuItem) { menuItem = this; htmlElement = this.getHTMLElement(); } // get the menu item from the html element which is handling the event if(menuItem == null || !(menuItem instanceof CMenuItem) || !menuItem.isEnabled()) return; if(typeof menuItem.getStyle() == "object" && !(menuItem.getMenu() != null && menuItem.getMenu().isVisible())) { htmlElement.className = menuItem.getStyle().getNormalState(); } // send the message up to our parent if(menuItem.getParent() != null && typeof menuItem.getParent().onmouseout == "function") menuItem.getParent().onmouseout(evt); // notify our observers of this event menuItem.getObservers().notify(CMenuItem_onmouseout); } function CMenuItem_ondragstart(evt) { event.cancelBubble = true; return false; } function CMenuItem_onmouseup(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); var buttonValue = (document.all && typeof this.document != "undefined")?1:0; if (evt.button != buttonValue) { //Only do it for left click return; } var menuItem = null; var htmlElement = null; if(typeof this.menuItem != 'undefined') { menuItem = this.menuItem; htmlElement = this; } else if (this instanceof CMenuItem) { menuItem = this; htmlElement = this.getHTMLElement(); } if(menuItem != null && menuItem instanceof CMenuItem) { if(!menuItem.isEnabled()) return; if(menuItem.getMenu() != null) { if(menuItem.getMenuType() == 'cascaded') { // do nothing } else if(menuItem.getMenuType() == 'dropDown') { menu = menuItem.getMenu(); if(menu.isVisible() == false) { // the user clicked on the menu menu.setHTMLContainer((document.all && typeof htmlElement.document != "undefined") ? htmlElement.document.body : htmlElement.ownerDocument.body); menu.draw(); menu.show(); if(menu.get(0) != null) { menu.get(0).setFocus(); } } else { menu.remove(true); } } } else { // handle the event eval(menuItem.getAction()); } if (typeof getReportFrame != "undefined") getReportFrame().clearTextSelection(); else if (typeof clearTextSelection != "undefined") clearTextSelection(); // send the message up to our parent if(menuItem.getParent() != null && typeof menuItem.getParent().onmouseup == "function") menuItem.getParent().onmouseup(evt); // notify our observers of this event if(menuItem.getMenuType() != 'cascaded') menuItem.getObservers().notify(CMenuItem_onmouseup); } if(evt != null) evt.cancelBubble = true; return false; } function CMenuItem_onkeydown(evt) { // do nothing } function CMenuItem_onkeypress(evt) { //get the event in a cross-browser fashion evt = (evt) ? evt : ((event) ? event : null); var keyCode = evt.keyCode || evt.which; if(AccessibilityHandler.isEnabled() && AccessibilityHandler.isSupportedKeycode(keyCode)) { var menuItem = null; if(typeof this.menuItem != 'undefined') { menuItem = this.menuItem; } else if (this instanceof CMenuItem) { menuItem = this; } if(menuItem != null && menuItem instanceof CMenuItem && typeof evt == "object" && evt != null) { //flag which determines if we notify observers of the event var performNotification = true; //check for Tab key press if (keyCode == 9) { // for "dropDown" and "dynamic" menu item, transfer the event to HTML body. if (menuItem.getMenuType() == "dropDown" || menuItem.getMenuType() == "dynamic") { return true; } // block the Tab key press for others menu item. else { return false; } } //check for the Enter key press else if (keyCode == 13) { //menu item should always be enabled if you can tab to it, but just in case if(!menuItem.isEnabled()) return; if(isNormalMenuItem(menuItem)){ if(menuItem.getMenu() != null) { performNotification = false; var menu = menuItem.getMenu(); menuItem.showMenu(menu); } else { // handle the event eval(menuItem.getAction()); } } else { performNotification = false; } } //check for Esc key press else if (keyCode == 27) { if (menuItem.getMenuType() == "dynamic") { menuItem.setFocus(); } if (menuItem.getMenuType() == "dropDown") { var menu = menuItem.getMenu(); menu.remove(true); } //close the menu menuItem.getParent().hide(); //cancel event being bubbled up the hierarchy since only one level of menus needs to hide return; } //check for Space key press else if (keyCode == 32) { if(isNormalMenuItem(menuItem)) { var menu = menuItem.getMenu(); menuItem.showMenu(menu); } performNotification = false; } //check for Left and Right key press else if (keyCode == 37 || keyCode == 39) { if (isMenubarItem(menuItem)) { var nextItem = AccessibilityHandler.getNextItem(menuItem, keyCode); nextItem.setFocus(); } else if (isCascadedMenuItem(menuItem) && keyCode == 39) { var menu = menuItem.getMenu(); menuItem.showMenu(menu); } else if (isCascadedSubMenuItem(menuItem) && keyCode == 37) { menuItem.getParent().hide(); return; } performNotification = false; } //check for Up and Down key press else if (keyCode == 38 || keyCode == 40) { if (isNormalMenuItem(menuItem) && !isMenubarItem(menuItem)) { var nextItem = AccessibilityHandler.getNextItem(menuItem, keyCode); nextItem.setFocus(); } else if (isMenubarItem(menuItem) && keyCode == 40) { var menu = menuItem.getMenu(); menuItem.showMenu(menu); } performNotification = false; } // send the message up to our parent if (menuItem.getParent() != null && typeof menuItem.getParent().onkeypress == "function") menuItem.getParent().onkeypress(evt); if (performNotification) { // notify our observers of this event menuItem.getObservers().notify(CMenuItem_onkeypress); } } } if(evt != null) evt.cancelBubble = true; return false; } function isMenubarItem(menuItem) { // the visible is false means the sub menu is hidden, so it can response to the key press if (menuItem.getMenuType() == "dropDown" && menuItem.getMenu().isVisible() == false) return true; return false; } function isCascadedMenuItem(menuItem) { // the visible is false means the sub menu is hidden, so it can response to the key press if (menuItem.getMenuType() == "cascaded" && menuItem.getMenu().isVisible() == false) return true; return false; } function isCascadedSubMenuItem(menuItem) { var parentItem = menuItem.getParent(); if (parentItem.getParent() != null && parentItem.getParent().getMenuType() == "cascaded") return true; return false; } function isNormalMenuItem(menuItem) { // if the menuItem itself is not a menu or even it is the sub menu is hidden, response the key press if (menuItem.getMenu() == null || menuItem.getMenu().isVisible() == false) return true; return false; } function CMenuItem_showMenu(menu) { // show the menu if(this.getMenuType() == 'cascaded') { menu.draw(); menu.show(); if(menu.get(0) != null) { menu.get(0).setFocus(); } } else if(this.getMenuType() == 'dropDown') { menu.draw(); menu.show(); if(menu.get(0) != null) { menu.get(0).setFocus(); } } } function CMenuItem_enableTabindex() { this.getHTMLElement().setAttribute("tabindex", "0"); } function CMenuItem_disableTabindex() { this.getHTMLElement().setAttribute("tabindex", "-1"); } function CMenuItem_createDropDownMenu(menuStyle) { this.m_menu = new CMenu('dropDownMenu_'+this.getId(),menuStyle); this.m_menu.setParent(this); this.m_menuType = 'dropDown'; return this.m_menu; } function CMenuItem_createCascadedMenu(menuStyle,offsetXCoords, offsetYCoords) { this.m_menu = new CMenu('cascadedMenu_'+this.getId(),menuStyle); this.m_menu.setOffsetXCoords(offsetXCoords); this.m_menu.setOffsetYCoords(offsetYCoords); this.m_menu.setParent(this); this.getParent().setContainsCascadedChildren(true); this.m_menuType = 'cascaded'; return this.m_menu; } function CMenuItem_addOwnerDrawControl(control, type) { this.m_menu = control; this.m_menuType = type; if(typeof control.setParent != "undefined") this.m_menu.setParent(this); } function CMenuItem_attachEvents() { var hMenuItem = this.getHTMLElement(); if(hMenuItem == null) return; // just to be safe hMenuItem.onmouseover = this.onmouseover; hMenuItem.onmouseout = this.onmouseout; hMenuItem.onmouseup = this.onmouseup; hMenuItem.onkeypress = this.onkeypress; hMenuItem.onfocus = this.onfocus; hMenuItem.onblur = this.onblur; hMenuItem.onkeydown = this.onkeydown; hMenuItem.ondragstart = this.ondragstart; hMenuItem.menuItem = eval(this); } function CMenuItem_remove() { } function CMenuItem_getMenu() { return this.m_menu; } function CMenuItem_getMenuType() { return this.m_menuType; } function CMenuItem_setMenuType(menuType) { return this.m_menuType = menuType; } function CMenuItem_getStyle() { return this.m_style; } function CMenuItem_setStyle(style) { this.m_style = style; } function CMenuItem_hide() { this.m_bVisible = false; } function CMenuItem_show() { this.m_bVisible = true; } function CMenuItem_setCapability(capability) { this.m_capability = capability; } function CMenuItem_getCapability() { return this.m_capability; } function CMenuItem_enable() { if(typeof this.getStyle() == "object") { var htmlElement = this.getHTMLElement(); if(htmlElement != null) { htmlElement.className = this.getStyle().getNormalState(); } this.m_bEnabled = true; this.getIcon().enable(); } } function CMenuItem_disable() { if(typeof this.getStyle() == "object") { var htmlElement = this.getHTMLElement(); if(htmlElement != null) { htmlElement.className = this.getStyle().getDisabledState(); } this.m_bEnabled = false; this.getIcon().disable(); } } function CMenuItem_isVisible() { return this.m_bVisible; } function CMenuItem_isEnabled() { return this.m_bEnabled; } function CMenuItem_getAction() { return this.m_action; } function CMenuItem_getIcon() { return this.m_icon; } function CMenuItem_getLabel() { return this.m_label; } function CMenuItem_getHTMLElement() { var htmlElement = null; if(this.getParent && typeof this.getParent().getHTMLContainer == "function") { var htmlContainer = this.getParent().getHTMLContainer(); if(htmlContainer != null) { htmlElement = htmlContainer.ownerDocument.getElementById(this.getId()); } } return htmlElement; } function CMenuItem_setFocus() { if (document.getElementById(this.m_id).focus) { document.getElementById(this.m_id).focus(); } } CMenuItem.prototype.draw = CMenuItem_draw; CMenuItem.prototype.onmouseover = CMenuItem_onmouseover; CMenuItem.prototype.onmouseout = CMenuItem_onmouseout; CMenuItem.prototype.onmouseup = CMenuItem_onmouseup; CMenuItem.prototype.onkeypress = CMenuItem_onkeypress; CMenuItem.prototype.onkeydown = CMenuItem_onkeydown; CMenuItem.prototype.onfocus = CMenuItem_onfocus; CMenuItem.prototype.ondragstart = CMenuItem_ondragstart; CMenuItem.prototype.onblur = CMenuItem_onmouseout; CMenuItem.prototype.attachEvents = CMenuItem_attachEvents; CMenuItem.prototype.getMenu = CMenuItem_getMenu; CMenuItem.prototype.setMenuType = CMenuItem_setMenuType; CMenuItem.prototype.getMenuType = CMenuItem_getMenuType; CMenuItem.prototype.setParent = CMenuItem_setParent; CMenuItem.prototype.getParent = CMenuItem_getParent; CMenuItem.prototype.getObservers = CMenuItem_getObservers; CMenuItem.prototype.getId = CMenuItem_getId; CMenuItem.prototype.remove = CMenuItem_remove; CMenuItem.prototype.setStyle = CMenuItem_setStyle; CMenuItem.prototype.getStyle = CMenuItem_getStyle; CMenuItem.prototype.createDropDownMenu = CMenuItem_createDropDownMenu; CMenuItem.prototype.createCascadedMenu = CMenuItem_createCascadedMenu; CMenuItem.prototype.addOwnerDrawControl = CMenuItem_addOwnerDrawControl; CMenuItem.prototype.isVisible = CMenuItem_isVisible; CMenuItem.prototype.hide = CMenuItem_hide; CMenuItem.prototype.show = CMenuItem_show; CMenuItem.prototype.isEnabled = CMenuItem_isEnabled; CMenuItem.prototype.enable = CMenuItem_enable; CMenuItem.prototype.disable = CMenuItem_disable; CMenuItem.prototype.getAction = CMenuItem_getAction; CMenuItem.prototype.getIcon = CMenuItem_getIcon; CMenuItem.prototype.getLabel = CMenuItem_getLabel; CMenuItem.prototype.getHTMLElement = CMenuItem_getHTMLElement; CMenuItem.prototype.setFocus = CMenuItem_setFocus; CMenuItem.prototype.update = new Function("return true"); CMenuItem.prototype.setCapability = CMenuItem_setCapability; CMenuItem.prototype.getCapability = CMenuItem_getCapability; CMenuItem.prototype.showMenu = CMenuItem_showMenu; CMenuItem.prototype.enableTabindex = CMenuItem_enableTabindex; CMenuItem.prototype.disableTabindex = CMenuItem_disableTabindex; /*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Class CSeperator todo : Add commments describing class.... /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ /* CSeperator styles: 1. horizonal_blank 2. vertical_blank 3. vertical_line 4. horizonal_line */ function CSeperator(type, size, style) { this.m_type=type; this.m_size=size; this.m_bVisible = true; if(typeof style == "object") this.m_style = new CUIStyle(style.getNormalState(),style.getRolloverState(),style.getDepressedState(),style.getDepressedRolloverState(),style.getDisabledState()); else this.m_style = new CUIStyle('','','','',''); } function CSeperator_draw() { if(this.m_style == '') return; html=''; switch(this.m_type) { case "horizonal_blank": { html += ''; break; } } return html; } function CSeperator_getSize() { return this.m_size; } function CSeperator_setSize(size) { this.m_size = size; } function CSeperator_setStyle(style) { this.m_style = style; } function CSeperator_getStyle() { return this.m_style; } function CSeperator_setType(type) { this.m_type = type; } function CSeperator_getType() { return this.m_type; } function CSeperator_hide() { this.m_bVisible = false; } function CSeperator_show() { this.m_bVisible = true; } function CSeperator_isVisible() { return this.m_bVisible; } CSeperator.prototype.draw = CSeperator_draw; CSeperator.prototype.setSize = CSeperator_setSize; CSeperator.prototype.getSize = CSeperator_getSize; CSeperator.prototype.setStyle = CSeperator_setStyle; CSeperator.prototype.getStyle = CSeperator_getStyle; CSeperator.prototype.getType = CSeperator_getType; CSeperator.prototype.setType = CSeperator_setType; CSeperator.prototype.isVisible = CSeperator_isVisible; CSeperator.prototype.show = CSeperator_show; CSeperator.prototype.hide = CSeperator_hide;