/*******************************************************************************
* Handling of Prompts
******************************************************************************/
/**
* Handler for the prompt dialog
* @param {string} data URL to open
* @param {function} finishFunction function to execute when done
*/
var promptHandling = function (data, finishFunction) {
var self = this;
this.finishFunction = finishFunction;
// Creates the new prompt array - which should be triggered by the iframe
this.popup = new popupHandler(data, function (event, form, input) {
var topWindow = window.htmlviewer || window;
topWindow.PROMPT = [];
// The HTML Nodes can not be accessed by IE. So copy the values, leave the nodes.
input.forEach(function (elem, i) {
topWindow.PROMPT.push({
name: elem.name,
value: elem.value
});
});
topWindow.HASPROMPTS = topWindow.PROMPT.length > 0 && !topWindow.HASNOPROMPTONREFRESH;
this.hide();
var menubar = new topWindow.menubaractions();
menubar.refreshReport(null, self.finishFunction);
}, "__promptHandling");
};
/**
* Adds the content of PROMPT to an object
* @param {object} object Object to put the PROMPTs into
* @param {boolean} [encode=true] If the parts of PROMPT should be URIComponent encoded
*/
var addPromptToObject = function (object, encode) {
if (typeof encode == 'undefined') {
encode = true;
}
applyFormFieldFunction(getPromptsField(), function (elem, i) {
// So, a reload does not like this, but a regular prompt needs this. WTF.
if (encode) {
object[encodeURIComponent(elem.name)] = encodeURIComponent(elem.value);
} else {
object[elem.name] = elem.value;
}
});
};
/**
* Return the save prompt fields
*/
var getPromptsField = function () {
return (window.htmlviewer ? window.htmlviewer.PROMPT : PROMPT) || [];
};
/**
* Return the save prompt fields
*/
var setPromptsField = function ( promptField ) {
if ( window.htmlviewer ) {
window.htmlviewer.PROMPT = promptField;
} else {
PROMPT = promptField;
}
};
/**
* add PROMPT Values to ajax request
* Will always be encoded
*
* @param {object} ajax The AJAX Request
*/
var addPromptToAjax = function (ajax) {
applyFormFieldFunction(getPromptsField(), function (elem, i) {
ajax.setVar(encodeURIComponent(elem.name), encodeURIComponent(elem.value));
});
};