123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356 |
- // Licensed Materials - Property of IBM
- //
- // IBM Cognos Products: ps
- //
- // (C) Copyright IBM Corp. 2005, 2011
- //
- // 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 and the Cognos logo are trademarks of Cognos ULC, (formerly Cognos Incorporated).
- // a set of global javascript variables that get sets when the edit field takes focus or the user click on
- // the arrow to open the dropdown
- var g_dynamicDD_controlName = null;
- var g_dynamicDD_array = null;
- var g_dynamicDD_dropdownDiv = null;
- var g_dynamicDD_editField = null;
- var g_dynamicDD_callbackFunc = null;
- var g_dynamicDD_openedBy = null;
- var g_dynamicDD_filterList = null;
- var g_dynamicDD_currentValue = null;
- var regEx = new RegExp(String.fromCharCode(160),"g");
- var IDX_LABEL = 0;
- var IDX_VALUE = 1;
- // handle all keyboard events for the drop down list
- function handleSelectKey(evt) {
- var keyCode = evt ? evt.keyCode : window.event.keyCode;
- // Enter and Esc
- if ((keyCode == 27) || (keyCode == 13)) {
- closeDropDown();
- g_dynamicDD_editField.focus();
- }
- }
- // handle all keyboard events for the edit field list
- function handleEditFieldKey(evt) {
- }
- // handle all keyboard events for the edit field list
- function handleEditFieldKey(evt) {
- var keyCode = evt ? evt.keyCode : window.event.keyCode;
- if (keyCode == 40) {
- // if the dropdown is closed, then simply change the current value to the next in the list
- if (g_dynamicDD_dropdownDiv && g_dynamicDD_dropdownDiv.style.display == 'none') {
- moveThroughArray(1);
- } else {
- moveThroughDropDown(1);
- }
- } else if (keyCode == 38) { // up arrow
- // if the dropdown is closed, then simply change the current value to the next in the list
- if (g_dynamicDD_dropdownDiv && g_dynamicDD_dropdownDiv.style.display == 'none') {
- moveThroughArray(-1);
- } else {
- moveThroughDropDown(-1);
- }
- } else if ((keyCode == 27) || (keyCode == 13)) { // Enter and Esc
- closeDropDown();
- } else if ((keyCode == 8) || (keyCode >= 32)) { // all other keys
- if (g_dynamicDD_editField.value != '') {
- // only do something if the value of the edit field has changed
- if (g_dynamicDD_currentValue != g_dynamicDD_editField.value) {
- g_dynamicDD_currentValue = g_dynamicDD_editField.value;
- if (g_dynamicDD_dropdownDiv && g_dynamicDD_dropdownDiv.style.display == 'none' && g_dynamicDD_filterList == 'true') {
- doDropDown('typing');
- } else if (g_dynamicDD_filterList == 'true' && g_dynamicDD_openedBy == 'typing') {
- populateDropDown();
- }
- }
- if (document.getElementById('select_' + g_dynamicDD_controlName) && document.getElementById('select_' + g_dynamicDD_controlName).options.length == 0) {
- closeDropDown();
- }
- document.getElementById(g_dynamicDD_controlName).value = g_dynamicDD_editField.value;
- g_dynamicDD_currentValue = g_dynamicDD_editField.value;
- }
- else {
- closeDropDown();
- }
-
- handleEditFieldChange();
- }
- }
- // Change the edit and hidden field to a value in the array using a delta from the current selection
- function moveThroughArray(delta) {
- var found = false;
- for (var i = 0; i < g_dynamicDD_array.length; i++) {
- if (g_dynamicDD_editField.value == g_dynamicDD_array[i][IDX_LABEL]) {
-
- found = true;
- setEditAndHiddenFromArray(i+delta);
- break;
- }
- }
-
- if (!found) {
- setEditAndHiddenFromArray(0);
- }
-
- handleEditFieldChange();
- }
- function moveThroughDropDown(delta) {
- var selectControl = document.getElementById('select_' + g_dynamicDD_controlName);
- if (!selectControl) {
- return;
- }
- var found = false;
- for (var i = 0; i < selectControl.options.length; i++) {
- if (selectControl[i].selected) {
- changeDropDownSelection(i, i+delta);
- found = true;
- break;
- }
- }
- if (!found && selectControl.options.length > 0) {
- selectControl.selectedIndex = 0;
- setEditAndHiddenFromDropDown(0);
- }
- selectControl.focus();
- }
- function changeDropDownSelection(fromIndex, toIndex) {
- var selectControl = document.getElementById('select_' + g_dynamicDD_controlName);
-
- if (selectControl.options.length > toIndex && toIndex >= 0) {
- selectControl.selectedIndex = toIndex;
- setEditAndHiddenFromDropDown(toIndex);
- }
- }
- // Sets a bunch of global vars. Should be called everytime one of the controls gets focus or
- // when the user hits the open dropdown button
- function setGlobals(name, array, validateCallback, filterList) {
- if (g_dynamicDD_controlName != name) {
- if (g_dynamicDD_controlName != null) {
- closeDropDown();
- }
- g_dynamicDD_controlName = name;
- g_currentSelectedIndex = null;
- g_dynamicDD_array = array;
- g_dynamicDD_dropdownDiv = document.getElementById('div_'+name);
- g_dynamicDD_editField = document.getElementById('editField_'+name);
- g_dynamicDD_callbackFunc = validateCallback;
- g_dynamicDD_filterList = filterList;
- g_dynamicDD_editField.onkeyup = handleEditFieldKey;
- g_dynamicDD_openedBy = null;
- g_dynamicDD_currentValue = g_dynamicDD_editField.value;
- }
- }
- // handles the logic for opening the drop down
- function doDropDown(calledBy) {
- if (g_dynamicDD_dropdownDiv && g_dynamicDD_dropdownDiv.style.display == 'none') {
- g_dynamicDD_openedBy = calledBy;
- populateDropDown();
-
- // if this was called by typing in the edit field,
- // then only open the drop down if it's not empty
- if (calledBy != 'typing' || document.getElementById('select_' + g_dynamicDD_controlName).options.length > 0) {
- openDropDown(calledBy=='downArrow');
- }
- }
- else {
- closeDropDown();
- g_dynamicDD_openedBy = null;
- }
- }
- // close the drop down
- function closeDropDown() {
- if (g_dynamicDD_dropdownDiv)
- {
- g_dynamicDD_dropdownDiv.style.display='none';
- }
- }
- // open the drop down
- function openDropDown(setFocus) {
- if (g_dynamicDD_dropdownDiv)
- {
- g_dynamicDD_dropdownDiv.style.display='';
- if (setFocus) {
- document.getElementById('select_'+g_dynamicDD_controlName).focus();
- }
- }
- }
- // Build up the select control
- function populateDropDown() {
- var currentSelectedValue = document.getElementById(g_dynamicDD_controlName).value;
- var filterList = false;
- var container = document.getElementById('div_'+g_dynamicDD_controlName);
- var eleSelect = document.getElementById("select_"+g_dynamicDD_controlName);
-
- if (eleSelect) {
- eleSelect.parentNode.removeChild(eleSelect);
- }
- //build select control (dropDown)
- eleSelect = document.createElement('select');
- container.appendChild(eleSelect);
- eleSelect.name="select_"+g_dynamicDD_controlName;
- eleSelect.id="select_"+g_dynamicDD_controlName;
- eleSelect.size = 10;
- eleSelect.multiple = false;
- eleSelect.style.width="215";
- eleSelect.onclick=function(){onClickSelectControl(this)};
- eleSelect.onchange=function(){onChangeSelectControl(this)};
- eleSelect.onkeyup = handleSelectKey;
- var selectedIdx = -1;
- // build the options
- for (var i = 0; i < g_dynamicDD_array.length; i++) {
- DD_label = g_dynamicDD_array[i][IDX_LABEL];
- DD_value = g_dynamicDD_array[i][IDX_VALUE];
- if (g_dynamicDD_openedBy == 'downArrow' || g_dynamicDD_filterList != 'true' || DD_label.indexOf(g_dynamicDD_editField.value) == 0) {
- var eleOpt = document.createElement('option');
- eleSelect.appendChild(eleOpt);
-
- eleOpt.value = DD_value;
- eleOpt.innerHTML = htmlEncode(DD_label,true);
- // select the default
- if (DD_value == currentSelectedValue && g_dynamicDD_openedBy == 'downArrow') {
- selectedIdx=eleSelect.childNodes.length-1;
- g_dynamicDD_currentValue = DD_value;
- }
- }
- }
- eleSelect.selectedIndex=selectedIdx;
- }
- // Handle the onclick event of the select control
- function onClickSelectControl(obj) {
- g_dynamicDD_editField.focus();
- closeDropDown();
- }
- // Handle the onchange event of the select control
- function onChangeSelectControl(obj) {
- for (var i = 0; i < obj.options.length; i++) {
- if (obj[i].selected) {
- setEditAndHiddenFromDropDown(i);
- g_dynamicDD_currentValue = g_dynamicDD_array[i][IDX_VALUE];
- break;
- }
- }
- }
- // Updated the edit and hidden field using the selected item in the drop down
- function setEditAndHiddenFromDropDown(index) {
- var selectControl = document.getElementById("select_" + g_dynamicDD_controlName);
- document.getElementById(g_dynamicDD_controlName).value = selectControl[index].value; //hidden field
- g_dynamicDD_editField.value = selectControl[index].text;
-
- handleEditFieldChange();
- }
- // Set the hidden and edit field using the array
- function setEditAndHiddenFromArray(index) {
- if (index < g_dynamicDD_array.length && index >=0) {
- document.getElementById(g_dynamicDD_controlName).value = g_dynamicDD_array[index][IDX_VALUE];
- g_dynamicDD_editField.value = g_dynamicDD_array[index][IDX_LABEL];
- }
- }
-
- // Checks to see if the current value is in the array and returns true or false
- function isValidValue() {
- for (var i = 0; i < g_dynamicDD_array.length; i++) {
- if (isEditorEqualToListElement(i)) {
- return true;
- }
- }
- return false;
- }
- function isEditorEqualToListElement(idx) {
- return g_dynamicDD_editField.value.replace(regEx," ") == g_dynamicDD_array[idx][IDX_LABEL];
- }
- function htmlEncode(string, encodeSpaces) {
- tempString = string.replace(/&/g,"&");
- tempString = tempString.replace(/"/g,""");
- tempString = tempString.replace(/</g,"<");
- tempString = tempString.replace(/>/g,">");
- if (encodeSpaces) {
- tempString = tempString.replace(/\ /g,"&nbsp;").replace(/\s/g," ");
- }
- return tempString;
- }
- // Whenever the value changes, call the necessary javascript function if one was provided
- function handleEditFieldChange() {
- var callBackFunc = window[g_dynamicDD_callbackFunc];
- if (callBackFunc) {
- callBackFunc(g_dynamicDD_editField, isValidValue());
- }
- }
- // When the edit field takes focus
- function handleEditFieldFocus() {
- if (g_dynamicDD_dropdownDiv && g_dynamicDD_dropdownDiv.style.display != 'none' && g_dynamicDD_openedBy != 'typing') {
- closeDropDown();
- }
- }
- //Returns the value in the hidden input.
- //The hidden input name is handled by g_dynamicDD_controlName
- function getHiddenValue () {
- if (g_dynamicDD_controlName != null && document.getElementById(g_dynamicDD_controlName)) {
- return (document.getElementById(g_dynamicDD_controlName).value);
- } else {
- return ;
- }
- }
- //Update the hidden update (created by utml) that the hidden input has changed.
- //The hidden changed input is handled by 'changed_' + g_dynamicDD_controlName.
- function updateChanged () {
- if (g_dynamicDD_controlName != null && document.getElementById(g_dynamicDD_controlName)) {
- var changed = document.pform.elements['changed_' + g_dynamicDD_controlName];
- if (changed) {
- changed.value = 1;
- }
- }
- }
- //Set a value to the hidden field g_dynamicDD_controlName.
- //This is usually used for empty value.
- function setHiddenValue (val) {
- var valueField = null;
-
- if (g_dynamicDD_controlName != null) {
- valueField = document.getElementById(g_dynamicDD_controlName);
- }
- if (valueField) {
- valueField.value = val;
- updateChanged();
- }
- }
- //This function allows to update the value within the array corresponding to "Number"
- //This allows to know which entry has been selected "Unlimited" or "Number".
- function updateTheArray(index, value) {
- g_dynamicDD_array[index][IDX_VALUE] = value;
- }
|