diff --git a/framework/images/webapp/images/fieldlookup.js b/framework/images/webapp/images/fieldlookup.js index 08ca1ec578..c8e51966b4 100644 --- a/framework/images/webapp/images/fieldlookup.js +++ b/framework/images/webapp/images/fieldlookup.js @@ -1,842 +1,884 @@ /* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ // ================= FIELD LOOKUP METHODS ============================ -var NS4 = (navigator.appName.indexOf("Netscape") >= 0 && ! document.getElementById)? true: false; -var IE4 = (document.all && ! document.getElementById)? true: false; -var IE5 = (document.getElementById && document.all)? true: false; -var NS6 = (document.getElementById && navigator.appName.indexOf("Netscape") >= 0)? true: false; + var mx, my; var ACTIVATED_LOOKUP = null; var LOOKUP_DIV = null; var INITIALLY_COLLAPSED = null; var SHOW_DESCRIPTION = false; - - -function moveobj(evt) { - if (NS4 || NS6) { - mx = evt.screenX; - my = evt.screenY; - } else if (IE5 || IE4) { - mx = event.screenX; - my = event.screenY; - } -} +var COLLAPSE_SEQUENCE_NUMBER = 1999; var target = null; var target2 = null; var targetW = null; -var lookups =[]; +var lookups = []; function call_fieldlookup(target, viewName, formName, viewWidth, viewheight) { - var fieldLookup = new fieldLookup1(target); - if (! viewWidth) viewWidth = 350; - if (! viewheight) viewheight = 200; - fieldLookup.popup(viewName, formName, viewWidth, viewheight); -} -function call_fieldlookupLayer(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed) { - if (isEmpty(target) || isEmpty(viewName)) { - return lookup_error("Lookup can't be created, one of these variables is missing: target=" + target + " viewName=" + viewName); - } - - var fieldLookupPopup = new FieldLookupPopup(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed, arguments); - fieldLookupPopup.showLookup(); - this.target = target; -} - -function call_fieldlookupLayer3(target, target2, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed) { - if (isEmpty(target) || isEmpty(target2) || isEmpty(viewName)) { - return lookup_error("Lookup can't be created, one of these variables is missing: target=" + target + " target2=" + target2 + " viewName=" + viewName); - } - - var fieldLookupPopup = new FieldLookupPopup(target, viewName, lookupWidth, lookupHeight, lookupPosition, fadeBackground, initiallyCollapsed, arguments); - fieldLookupPopup.showLookup(); - this.target = target; - this.target2 = target2; + var fieldLookup = new fieldLookup1(target); + if (!viewWidth) + viewWidth = 350; + if (!viewheight) + viewheight = 200; + fieldLookup.popup(viewName, formName, viewWidth, viewheight); } function call_fieldlookup2(target, viewName, presentation) { - var fieldLookup = new fieldLookup1(target, arguments, presentation); - fieldLookup.popup2(viewName); + var fieldLookup = new fieldLookup1(target, arguments, presentation); + fieldLookup.popup2(viewName); } function call_fieldlookup3(target, target2, viewName, presentation) { - var fieldLookup = new fieldLookup2(target, target2, arguments, presentation); - fieldLookup.popup2(viewName); + var fieldLookup = new fieldLookup2(target, target2, arguments, presentation); + fieldLookup.popup2(viewName); } function fieldLookup1(obj_target, args, presentation) { - this.args = args; - this.presentation = presentation; - // passing methods - this.popup = lookup_popup1; - this.popup2 = lookup_popup2; - - // validate input parameters - if (! obj_target) return lookup_error("Error calling the field lookup: no target control specified"); - if (obj_target.value == null) return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); - targetW = obj_target; + this.args = args; + this.presentation = presentation; + // passing methods + this.popup = lookup_popup1; + this.popup2 = lookup_popup2; + + // validate input parameters + if (!obj_target) + return lookup_error("Error calling the field lookup: no target control specified"); + if (obj_target.value == null) + return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); + targetW = obj_target; } function fieldLookup2(obj_target, obj_target2, args, presentation) { - this.args = args; - this.presentation = presentation; - // passing methods - this.popup = lookup_popup1; - this.popup2 = lookup_popup2; - // validate input parameters - if (! obj_target) return lookup_error("Error calling the field lookup: no target control specified"); - if (obj_target.value == null) return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); - targetW = obj_target; - // validate input parameters - if (! obj_target2) return lookup_error("Error calling the field lookup: no target2 control specified"); - if (obj_target2.value == null) return lookup_error("Error calling the field lookup: parameter specified is not valid target2 control"); - target2 = obj_target2; - + this.args = args; + this.presentation = presentation; + // passing methods + this.popup = lookup_popup1; + this.popup2 = lookup_popup2; + // validate input parameters + if (!obj_target) + return lookup_error("Error calling the field lookup: no target control specified"); + if (obj_target.value == null) + return lookup_error("Error calling the field lookup: parameter specified is not valid target control"); + targetW = obj_target; + // validate input parameters + if (!obj_target2) + return lookup_error("Error calling the field lookup: no target2 control specified"); + if (obj_target2.value == null) + return lookup_error("Error calling the field lookup: parameter specified is not valid target2 control"); + target2 = obj_target2; + } function lookup_popup1(view_name, form_name, viewWidth, viewheight) { - var obj_lookupwindow = window.open(getViewNameWithSeparator(view_name) + 'formName=' + form_name + '&presentation=' + this.presentation + '&id=' + this.id, '_blank', 'width=' + viewWidth + ',height=' + viewheight + ',scrollbars=yes,status=no,resizable=yes,top=' + my + ',left=' + mx + ',dependent=yes,alwaysRaised=yes'); - obj_lookupwindow.opener = window; - obj_lookupwindow.focus(); + var obj_lookupwindow = window.open(getViewNameWithSeparator(view_name) + 'formName=' + form_name + '&presentation=' + this.presentation + + '&id=' + this.id, '_blank', 'width=' + viewWidth + ',height=' + viewheight + ',scrollbars=yes,status=no,resizable=yes,top=' + + my + ',left=' + mx + ',dependent=yes,alwaysRaised=yes'); + obj_lookupwindow.opener = window; + obj_lookupwindow.focus(); } function lookup_popup2(view_name) { - var argString = ""; - if (this.args != null) { - if (this.args.length > 2) { - for (var i = 2; i < this.args.length; i++) { - argString += "&parm" + (i - 3) + "=" + this.args[i]; - } - } - } + var argString = ""; + if (this.args != null) { + if (this.args.length > 2) { + for ( var i = 2; i < this.args.length; i++) { + argString += "&parm" + (i - 3) + "=" + this.args[i]; + } + } + } - var obj_lookupwindow = window.open(getViewNameWithSeparator(view_name) + 'presentation=' + this.presentation + '&id=' + this.id + argString, '_blank', 'width=900,height=700,scrollbars=yes,status=no,resizable=yes,top=' + my + ',left=' + mx + ',dependent=yes,alwaysRaised=yes'); - obj_lookupwindow.opener = window; - obj_lookupwindow.focus(); + var obj_lookupwindow = window.open(getViewNameWithSeparator(view_name) + 'presentation=' + this.presentation + '&id=' + this.id + + argString, '_blank', 'width=900,height=700,scrollbars=yes,status=no,resizable=yes,top=' + my + ',left=' + mx + + ',dependent=yes,alwaysRaised=yes'); + obj_lookupwindow.opener = window; + obj_lookupwindow.focus(); } function lookup_error(str_message) { - var CommonErrorMessage2 = getJSONuiLabel("CommonUiLabels", "CommonErrorMessage2"); - showErrorAlert(CommonErrorMessage2, str_message); - return null; + var CommonErrorMessage2 = getJSONuiLabel("CommonUiLabels", "CommonErrorMessage2"); + showErrorAlert(CommonErrorMessage2, str_message); + return null; } function getViewNameWithSeparator(view_name) { - var sep = "?"; - if (view_name.indexOf("?") >= 0) { - sep = "&"; - } - return view_name + sep; + var sep = "?"; + if (view_name.indexOf("?") >= 0) { + sep = "&"; + } + return view_name + sep; } function initiallyCollapse() { - if ((!LOOKUP_DIV) || (INITIALLY_COLLAPSED != "true")) return; - var slTitleBars = LOOKUP_DIV.getElementsByClassName('screenlet-title-bar'); - for (i in slTitleBars) { - var slTitleBar = slTitleBars[i]; - var ul = slTitleBar.firstChild; - if ((typeof ul) != 'object') continue; + if ((!LOOKUP_DIV) || (INITIALLY_COLLAPSED != "true")) + return; + var slTitleBars = LOOKUP_DIV.getElementsByClassName('screenlet-title-bar'); + for (i in slTitleBars) { + var slTitleBar = slTitleBars[i]; + var ul = slTitleBar.firstChild; + if ((typeof ul) != 'object') + continue; - var childElements = ul.childNodes; - for (j in childElements) { - if (childElements[j].className == 'expanded' || childElements[j].className == 'collapsed') { - break; - } - } - var childEle = childElements[j].firstChild; - CollapsePanel(childEle, 'lec' + COLLAPSE); - break; - } + var childElements = ul.childNodes; + for (j in childElements) { + if (childElements[j].className == 'expanded' || childElements[j].className == 'collapsed') { + break; + } + } + var childEle = childElements[j].firstChild; + CollapsePanel(childEle, 'lec' + COLLAPSE_SEQUENCE_NUMBER); + break; + } } -function CollapsePanel(link, areaId){ - var container = $(areaId); - var liElement = $(link).up('li'); - liElement.removeClassName('expanded'); - liElement.addClassName('collapsed'); - Effect.toggle(container, 'appear'); +function CollapsePanel(link, areaId) { + var container = $(areaId); + var liElement = $(link).up('li'); + liElement.removeClassName('expanded'); + liElement.addClassName('collapsed'); + Effect.toggle(container, 'appear'); } function initiallyCollapseDelayed() { - setTimeout("initiallyCollapse()", 400); + setTimeout("initiallyCollapse()", 400); } +/******************************************************************************* + * Lookup Object + ******************************************************************************/ +var Lookup = function(options) { + var _newInputBoxId, _lookupId, _inputBox, _lookupContainer, _backgroundCloseClickEvent; -/************************************* -* Fieldlookup Class & Methods -*************************************/ -function ConstructLookup(requestUrl, inputFieldId, dialogTarget, dialogOptionalTarget, formName, width, height, position, modal, ajaxUrl, showDescription, presentation, defaultMinLength, defaultDelay, args) { - // add the presentation attribute to the request url to let the request know which decorator should be loaded - if(!presentation) { - var presentation = "layer" - } - - // create Link Element with unique Key - var lookupId = GLOBAL_LOOKUP_REF.createNextKey(); - var inputBox = document.getElementById(inputFieldId); - newInputBoxId = lookupId + "_" + inputFieldId; - inputBox.id = newInputBoxId; - var parent = inputBox.parentNode; + options = { + requestUrl : options.requestUrl || "", + inputFieldId : options.inputFieldId || "", + dialogTarget : options.dialogTarget || "", + dialogOptionalTarget : options.dialogOptionalTarget || "", + formName : options.formName || "", + width : options.width || "620", + height : options.height || "500", + position : options.position || "topleft", + modal : options.modal || "true", + ajaxUrl : options.ajaxUrl || "", + showDescription : options.showDescription || "", + presentation : options.presentation || "layer", + defaultMinLength : options.defaultMinLength || "", + defaultDelay : options.defaultDelay || "", + args : options.args || "" + } - var link = document.createElement('A'); - link.href = "javascript:void(0);"; - link.id = lookupId + "_button"; + function _init() { + _lookupId = GLOBAL_LOOKUP_REF.createNextKey(); - parent.appendChild(link); + _modifyContainer(); + _createAjaxAutoComplete(); - var hiddenDiv = document.createElement("DIV"); - hiddenDiv.id = lookupId; - hiddenDiv.css = "{display: none;}"; - hiddenDiv.title = ""; + _lookupContainer = jQuery("#" + _lookupId); + var dialogOpts = _createDialogOptions(_lookupContainer); - parent.appendChild(hiddenDiv); + // init Dialog and register + // create an object with all Lookup Informationes that are needed + var dialogRef = _lookupContainer.dialog(dialogOpts); - // createAjax autocomplete - if (ajaxUrl != "" && showDescription != "") { - SHOW_DESCRIPTION = showDescription; - //write the new input box id in the ajaxUrl Array - ajaxUrl = ajaxUrl.replace(ajaxUrl.substring(0, ajaxUrl.indexOf(",")), newInputBoxId); - new ajaxAutoCompleter(ajaxUrl, showDescription, defaultMinLength, defaultDelay, formName); - } - - var positioning = null; - if (position == "topleft") { - positioning = ['left', 'top']; - } else if (position == "topcenter") { - positioning = ['center', 'top']; - } else if (position == "topright") { - positioning = ['right', 'top']; - } else if (position == "center") { - positioning = 'center'; - } else if (position == "left") { - positioning = 'left'; - } else if (position == "right") { - positioning = 'right'; - } else { - positioning = ['left', 'top']; - } + // setting up global variabels, for external access + this.inputBoxId = _inputBox.id; + this.lookupId = _lookupId; + this.formName = options.formName; + this.target = null; + this.presentation = options.presentation; + if (options.dialogOptionalTarget != null) { + this.target2 = null; + } + this.prevLookup = null; + this.dialogRef = dialogRef; - var lookupFormAction = null; - function lookup_onKeyEnter(event) { - if (event.which == 13) { - lookupFormAjaxRequest(lookupFormAction, "form_" + lookupId); - return false; - } - } - - // Lookup Configuration - var dialogOpts = { - modal: (modal == "true") ? true : false, - bgiframe: true, - autoOpen: false, - height: (height != "") ? parseInt(height) : 500, - width: (width != "") ? parseInt(width) : 620, - position: positioning, - draggable: true, - resizeable: true, - open: function(event,ui) { - waitSpinnerShow(); - jQuery("#" + lookupId).empty(); + // write external settings in global window manager + GLOBAL_LOOKUP_REF.setReference(_lookupId, this); - var queryArgs = "presentation=" + presentation; - if (typeof args == "object" && jQuery.isArray(args)) { - for (var i = 0; i < args.length; i++) { - queryArgs += "&parm" + i + "=" + jQuery(args[i]).val(); - } - } + _addOpenEvent(dialogRef); + } - jQuery.ajax({ - type: "post", - url: requestUrl, - data: queryArgs, - timeout: AJAX_REQUEST_TIMEOUT, - cache: false, - dataFilter: function(data, dataType) { - waitSpinnerHide(); - return data; - }, - success: function(data) { - jQuery("#" + lookupId).html(data); - - lookupFormAction = jQuery("#" + lookupId + " form:first").attr("action"); - modifySubmitButton(lookupId); - jQuery("#" + lookupId).bind("keypress", lookup_onKeyEnter); - // set up the window chaining - // if the ACTIVATED_LOOKUP var is set there have to be more than one lookup, - // before registrating the new lookup we store the id of the old lookup in the - // preLookup variable of the new lookup object. I.e. lookup_1 calls lookup_8, the lookup_8 - // object need a reference to lookup_1, this reference is set here - var prevLookup = null - if (ACTIVATED_LOOKUP) { - prevLookup = GLOBAL_LOOKUP_REF.getReference(ACTIVATED_LOOKUP).lookupId; - } - identifyLookup(lookupId); - - if (prevLookup) { - GLOBAL_LOOKUP_REF.getReference(ACTIVATED_LOOKUP).prevLookup = prevLookup; - } - }, - error: function(xhr, reason, exception) { - if(exception != 'abort') { - alert("An error occurred while communicating with the server:\n\n\nreason=" + reason + "\n\nexception=" + exception); - } - location.reload(true); - }, - }); - }, - close: function() { - jQuery("#" + lookupId).unbind("keypress", lookup_onKeyEnter); - - waitSpinnerHide(); + function _modifyContainer() { + _inputBox = document.getElementById(options.inputFieldId); + _newInputBoxId = _lookupId + "_" + options.inputFieldId; + _inputBox.id = _newInputBoxId; + var parent = _inputBox.parentNode; - //when the window is closed the prev Lookup get the focus (if exists) - if (ACTIVATED_LOOKUP) { - var prevLookup = GLOBAL_LOOKUP_REF.getReference(ACTIVATED_LOOKUP).prevLookup; - } - if (prevLookup) { - identifyLookup(prevLookup); - } else { - ACTIVATED_LOOKUP = null; - } - } - }; - - // init Dialog and register - // create an object with all Lookup Informationes that are needed - var dialogRef = jQuery("#" + lookupId).dialog(dialogOpts); - - //setting up global variabels, for external access - this.inputBoxId = inputBox.id; - this.lookupId = lookupId; - this.formName = formName; - this.target = null; - this.presentation = presentation; - if (dialogOptionalTarget != null) { - this.target2 = null; - } - this.prevLookup = null; - this.dialogRef = dialogRef; - //write external settings in global window manager - GLOBAL_LOOKUP_REF.setReference(lookupId, this); - - // bind click Event to Dialog button - jQuery("#" + lookupId + "_button").click( - function (){ - jQuery("#" + lookupId).dialog("open"); - jQuery("#" + lookupId).dialog(dialogOpts); - GLOBAL_LOOKUP_REF.getReference(lookupId).target = jQuery(dialogTarget); - if (dialogOptionalTarget != null) { - //the target2 have to be set here, because the input field is not created before - GLOBAL_LOOKUP_REF.getReference(lookupId).target2 = jQuery(dialogOptionalTarget); - } - return false; - } - ); + var link = document.createElement('A'); + link.href = "javascript:void(0);"; + link.id = _lookupId + "_button"; - // close the dialog when clicking outside the dialog area - jQuery(".ui-widget-overlay").live("click", function() { - if(!ACTIVATED_LOOKUP || lookupId==ACTIVATED_LOOKUP){ - jQuery("#" + lookupId).dialog("close"); - } - }); -} + parent.appendChild(link); -function FieldLookupCounter() { - this.refArr = {}; + var hiddenDiv = document.createElement("DIV"); + hiddenDiv.id = _lookupId; + hiddenDiv.css = "{display: none;}"; + hiddenDiv.title = ""; + + parent.appendChild(hiddenDiv); + } + + function _createAjaxAutoComplete() { + if (options.ajaxUrl != "" && options.showDescription != "") { + SHOW_DESCRIPTION = options.showDescription; + // write the new input box id in the ajaxUrl Array + options.ajaxUrl = options.ajaxUrl.replace(options.ajaxUrl.substring(0, options.ajaxUrl.indexOf(",")), _newInputBoxId); + new ajaxAutoCompleter(options.ajaxUrl, options.showDescription, options.defaultMinLength, options.defaultDelay, + options.formName); + } + } + + function _createDialogOptions(_lookupContainer) { + var positioning = _positioning(); + + var dialogOpts = { + modal : (options.modal == "true") ? true : false, + bgiframe : true, + autoOpen : false, + height : parseInt(options.height), + width : parseInt(options.width), + position : positioning, + draggable : true, + resizeable : true, + open : _dialogOpen, + close : _dialogClose + }; + + return dialogOpts; + } + + function _positioning() { + var positioning = null; + if (options.position == "topleft") { + positioning = [ 'left', 'top' ]; + } else if (options.position == "topcenter") { + positioning = [ 'center', 'top' ]; + } else if (options.position == "topright") { + positioning = [ 'right', 'top' ]; + } else if (options.position == "center") { + positioning = 'center'; + } else if (options.position == "left") { + positioning = 'left'; + } else if (options.position == "right") { + positioning = 'right'; + } else { + positioning = [ 'left', 'top' ]; + } + + return positioning; + } + + function _dialogOpen(event, ui) { + waitSpinnerShow(); + _lookupContainer.empty(); + + var queryArgs = "presentation=" + options.presentation; + if (typeof options.args == "object" && jQuery.isArray(options.args)) { + for ( var i = 0; i < options.args.length; i++) { + queryArgs += "&parm" + i + "=" + jQuery(options.args[i]).val(); + } + } + + _lookupChaining(); + _addCloseEventForClickingOnBackgroundLayer(); + + // load lookup data from server + jQuery.ajax({ + type : "POST", + url : options.requestUrl, + data : queryArgs, + timeout : AJAX_REQUEST_TIMEOUT, + cache : false, + dataFilter : function(data, dataType) { + waitSpinnerHide(); + return data; + }, + + success : function(data) { + _lookupContainer.html(data); + new ButtonModifier(_lookupId).modifySubmitButton(); + }, + + error : function(xhr, reason, exception) { + if (exception != 'abort') { + alert("An error occurred while communicating with the server:\n\n\nreason=" + reason + "\n\nexception=" + exception); + } + location.reload(true); + }, + }); + } + + function _lookupChaining() { + /* + * set up the window chaining if the ACTIVATED_LOOKUP var is set there + * have to be more than one lookup, before registrating the new lookup + * we store the id of the old lookup in the preLookup variable of the + * new lookup object. I.e. lookup_1 calls lookup_8, the lookup_8 object + * need a reference to lookup_1, this reference is set here + */ + + var prevLookup = null + if (ACTIVATED_LOOKUP) { + prevLookup = ACTIVATED_LOOKUP; + } + + _activateLookup(_lookupId); + + GLOBAL_LOOKUP_REF.getReference(ACTIVATED_LOOKUP).prevLookup = prevLookup; + } + + function _activateLookup(newAl) { + if (ACTIVATED_LOOKUP != newAl) { + console.log("set ACTIVATED_LOOKUP from " + ACTIVATED_LOOKUP + " to " + newAl) + ACTIVATED_LOOKUP = newAl; + } + } + + function _addCloseEventForClickingOnBackgroundLayer() { + _backgroundCloseClickEvent = function() { + console.log("click outside box " + ACTIVATED_LOOKUP + " with lookupId " + _lookupId); + if (ACTIVATED_LOOKUP && ACTIVATED_LOOKUP == _lookupId) { + console.log("close layer " + ACTIVATED_LOOKUP); + GLOBAL_LOOKUP_REF.getReference(ACTIVATED_LOOKUP).dialogRef.dialog("close"); + } + } + + jQuery(".ui-widget-overlay").click(_backgroundCloseClickEvent); + } + + function _dialogClose() { + jQuery(".ui-widget-overlay").unbind("click", _backgroundCloseClickEvent) + + var prevLookup = null; + if (ACTIVATED_LOOKUP) { + prevLookup = GLOBAL_LOOKUP_REF.getReference(ACTIVATED_LOOKUP).prevLookup; + } + + if (prevLookup) { + _activateLookup(prevLookup); + } else { + ACTIVATED_LOOKUP = null; + } + } + + function _addOpenEvent(dialogReference) { + jQuery("#" + _lookupId + "_button").click(function() { + dialogReference.dialog("open"); + + GLOBAL_LOOKUP_REF.getReference(_lookupId).target = jQuery(options.dialogTarget); + if (options.dialogOptionalTarget != null) { + GLOBAL_LOOKUP_REF.getReference(_lookupId).target2 = jQuery(options.dialogOptionalTarget); + } + }); + + } + + return { + init : _init + } +}; + +/******************************************************************************* + * Lookup Counter Object + ******************************************************************************/ +var FieldLookupCounter = function() { + this.refArr = {}; + + this.setReference = function(key, ref) { + // if key doesn't exist in the array and + for (itm in this.refArr) { + if (itm == key) { + prefix = key.substring(0, key.indexOf("_")); + key = prefix + "_" + key; + this.refArr["" + key + ""] = ref; + return this.refArr[key]; + } + } + this.refArr["" + key + ""] = ref; + return this.refArr[key]; + }; + + this.getReference = function(key) { + // when key does not exist return null? + return this.refArr[key] != null ? this.refArr[key] : null; + }; + + this.getLastReference = function() { + return (this.countFields() - 1) + "_lookupId"; + } + + this.createNextKey = function() { + return this.countFields() + "_lookupId"; + }; + + this.countFields = function() { + var count = 0; + jQuery.each(this.refArr, function(itm) { + count++; + }); + return count; + }; + + this.removeReference = function(key) { + // deletes the Array entry (doesn't effect the array length) + delete this.refArr[key]; + }; - this.setReference = function (key, ref) { - //if key doesn't exist in the array and - for (itm in this.refArr) { - if (itm == key) { - prefix = key.substring(0, key.indexOf("_")); - key = prefix + "_" + key; - this.refArr[""+ key + ""] = ref; - return this.refArr[key]; - } - } - this.refArr[""+ key + ""] = ref; - return this.refArr[key]; - }; - - this.getReference = function (key) { - // when key does not exist return null? - return this.refArr[key] != null ? this.refArr[key] : null; - }; - - this.getLastReference = function () { - return (this.countFields() -1) + "_lookupId"; - } - - this.createNextKey = function () { - return this.countFields() + "_lookupId"; - }; - - this.countFields = function () { - var count = 0; - jQuery.each(this.refArr, function (itm) {count++;}); - return count; - }; - - this.removeReference = function (key) { - // deletes the Array entry (doesn't effect the array length) - delete this.refArr[key]; - }; - }; var GLOBAL_LOOKUP_REF = new FieldLookupCounter; -/** -* returns true if a String is empty -* @param value - String value -* @return -*/ -function isEmpty(value) { - if (value == null || value == "") { - return true; - } - return false; +/******************************************************************************* + * Button Modifier Object + ******************************************************************************/ +var ButtonModifier = function(lookupDiv) { + + function _modifySubmitButton() { + if (!lookupDiv) { + return; + } + + _modifyCollapseable(); + + // find the lookup form and input button + var lookupForm = jQuery("#" + lookupDiv + " form:first"); + + // set new form name and id + oldFormName = lookupForm.attr("name"); + lookupForm.attr("name", "form_" + lookupDiv); + lookupForm.attr("id", "form_" + lookupDiv); + lookupForm = jQuery("#form_" + lookupDiv); + // set new links for lookups + var newLookups = jQuery("#" + lookupDiv + " .field-lookup"); + + var formAction = lookupForm.attr("action"); + // remove the form action + lookupForm.attr("action", ""); + var input = jQuery("#" + lookupDiv + " input[type=submit]").css({ + display : "block" + }); + + // remove the original input button and replace with a new one + + var txt = input.attr("value"); + (input.parent()).append(jQuery("