/*############################################################################## # HPCC SYSTEMS software Copyright (C) 2015 HPCC Systems®. # # Licensed 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. ############################################################################## */ // for test purpose function getAttributes(ctrl) { var results = ""; var attrs = ctrl.attributes; for (var i = 0; i < attrs.length; i++) { var attr = attrs[i]; results += attr.nodeName + '=' + attr.nodeValue + ' (' + attr.specified + ')
'; } return results; } //================================================================== // Restore dynamically generate content, and user input values(non-IE browsers only) function restoreDataFromCache() { var vals = document.getElementById("esp_vals_").value; if (vals && vals!="") { // alert("esp_vals_ = "+vals); var end = vals.indexOf('|'); while (end>0) { var name = vals.substring(0,end); vals = vals.substring(end+1); end = vals.indexOf("|"); if (end<0) break; var ctrl = document.getElementsByName(name)[0]; if (ctrl) { if (ctrl.type == 'checkbox') { ctrl.checked = vals.substring(0,end)=='1'; // alert("Name = "+name+", string = "+ vals.substring(0,end) + ", ctrl.checked = "+ ctrl.checked); } else if (ctrl.type == 'text' || ctrl.type == 'textarea') ctrl.value = decodeURI(vals.substring(0,end)); else if(ctrl.type == 'radio') { //alert("Name = "+name+", string = "+ vals.substring(0,end) + ", ctrl.checked = "+ ctrl.checked); if(vals.substring(0,end) == '0') { ctrl = document.getElementsByName(name)[1]; } if(ctrl) ctrl.checked = true; } else if(ctrl.type == 'select-one') { //alert("Select: name="+ctrl.name+"; value="+vals.substring(0,end)); ctrl.options[vals.substring(0,end)].selected = true; } //TODO: more types } vals = vals.substring(end+1); end = vals.indexOf("|"); } } } function disableAllInputs(self) { var toEnable = self.checked ? 1 : 0; var form = document.forms['esp_form']; var ctrls = form.elements; for (var idx=0; idx0) url = url.substring(idx+1); var a = url.split('&'); var ps = new Hashtable(); for (var i=0; i0) { var key = a[i].substring(0,idx); var val = a[i].substring(idx+1); if (val != '') ps.put(key, val); } } return ps; } function getUrlEspFlags(url) { var idx = url.indexOf('?'); if (idx>0) url = url.substring(idx+1); var a = url.split('&'); var ps = new Hashtable(); for (var i=0; i0) { var key = a[i].substring(0,idx); var val = a[i].substring(idx+1); ps.put(key,val); } else ps.put(a[i],""); } } return ps; } function createArray(ps) { var remains = new Hashtable(); ps.moveFirst(); while (ps.next()) { var name = ps.getKey(); var val = ps.getValue(); // alert(name + ": " + val); if (val > 0 && name.substring(name.length-11)==".itemcount!") { var id = name.substring(1, name.length-10) + '_AddBtn'; var ctrl = document.getElementById(id); if (ctrl) { // alert("name: " + ctrl.tagName + ", type " + ctrl.type); for (var i=0; i0) return remains; else return null; } function initFormValues(form, ps) { // create array controls // Implementation NOTE: The Add order is important: if array A contains array B, item in A must be created first before B can be created. var working = ps; do { working = createArray(working); //alert("Left: " + working); } while (working!=null); // init values ps.moveFirst(); while (ps.next()) { var name = ps.getKey(); if (name.charAt(0) != '.') { //alert("Skip " + name); continue; } name = name.substring(1); var val = ps.getValue(); ctrl = document.getElementsByName(name)[0]; // alert("Set value for " + name + ": " + val + ". Ctrl type: " + ctrl.type); if (ctrl) { if (ctrl.type == 'checkbox') { ctrl.checked = val =='1'; } else if (ctrl.type == 'text') { ctrl.value = decodeURIComponent(val); // decodeURI(vals.substring(0,end)); //TODO: do we need encoding } else if (ctrl.type == 'textarea') { ctrl.value = decodeURIComponent(val); } else if(ctrl.type == 'radio') { if(val == '0') ctrl = document.getElementsByName(name)[1]; if(ctrl) ctrl.checked = true; } else if (ctrl.type=='select-one') { //alert("Set select value: " + val); ctrl.options[val].selected=true; } } else alert("failed to find contrl: " + name); } } function doBookmark(form) { var ps = getUrlEspFlags(form.action); var ctrls = form.elements; for (var idx=0; idx0) { if (action.length <= idx + 13) // no more char after 'soap_builder_' { var ch = action.charAt(idx-1); if (ch == '&' || ch == '?') action = action.substring(0,idx-1); } else { var ch = action.charAt(idx+13) // the char after 'soap_builder_'; if (ch == '&') action = action.substring(0,idx) + action.substring(idx+13); } // alert("Old action: " + form.action + "\nNew action: " + action); form.action = action; } } // -- change action if user wants to var dest = document.getElementById('esp_dest'); if (dest && dest.checked) { form.action = document.getElementById('dest_url').value; } if (reqType==1) { if (form.action.indexOf('soap_builder_')<0) // add only if does not exist already { var c = (form.action.indexOf('?')>0) ? '&' : '?'; form.action += c + "soap_builder_"; } } else if (reqType==2) { doBookmark(form); } if (reqType==3) { if (form.action.indexOf('roxie_builder_')<0) // add only if does not exist already { var c = (form.action.indexOf('?')>0) ? '&' : '?'; form.action += c + "roxie_builder_"; } } if (reqType==4) { if (form.action.indexOf('json_builder_')<0) // add only if does not exist already { var c = (form.action.indexOf('?')>0) ? '&' : '?'; form.action += c + "json_builder_"; } } // alert("Form action = " + form.action); // firefox now save input values (version 1.5) saveInputValues(form); return true; } //================================================================== // Save dynamically generate content, and user input values(non-IE browsers only) function onWsEcl2Submit(path) // reqType: 0: regular form, 1: soap, 2: form param passing, 3: roxiexml { var form = document.forms['esp_form']; if (!form) return false; var dest = document.getElementById('esp_dest'); if (dest && dest.checked) { form.action = document.getElementById('dest_url').value; } else if (path=="bookmark") { doBookmark(form); } else { form.action = path; } alert("Form action = " + form.action); // firefox now save input values (version 1.5) saveInputValues(form); return true; } function saveInputValues(form) { // -- save values in input for browser var ctrl = document.getElementById('esp_html_'); // IE seems to need this too //if (isIE || !ctrl) return true; ctrl.value=form.innerHTML; // save all user input var ctrls = form.elements; var items = ctrls.length; var inputValues = ""; for (var idx=0; idx