2014-04-15 12:52:18 -05:00
|
|
|
var wrongTextInput = '#F9EDBE none';
|
2015-02-10 10:20:50 -06:00
|
|
|
var loadingLink = '<img src="ui/loading.gif"/>';
|
|
|
|
var loadingButton = '<img align="center" src="ui/loadingBtn.gif"/>';
|
|
|
|
var loadingZone = '<div align="center"><img src="ui/loadingBig.gif"/></div>';
|
|
|
|
var lsTimeout; // Timout for the live search
|
|
|
|
var podTimeout; // Timeout for checking status of pod downloads
|
2014-04-15 12:52:18 -05:00
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
// Functions related to user authentication
|
2011-09-15 08:52:21 -05:00
|
|
|
function cookiesAreEnabled() {
|
|
|
|
// Test whether cookies are enabled by attempting to set a cookie and then
|
|
|
|
// change its value
|
|
|
|
var c = "areYourCookiesEnabled=0";
|
|
|
|
document.cookie = c;
|
|
|
|
var dc = document.cookie;
|
|
|
|
// Cookie not set? Fail
|
|
|
|
if (dc.indexOf(c) == -1) return 0;
|
|
|
|
// Change test cookie
|
|
|
|
c = "areYourCookiesEnabled=1";
|
|
|
|
document.cookie = c;
|
|
|
|
dc = document.cookie;
|
|
|
|
// Cookie not changed? fail
|
|
|
|
if (dc.indexOf(c) == -1) return 0;
|
|
|
|
// Delete cookie
|
|
|
|
document.cookie = "areYourCookiesEnabled=; expires=Thu, 01-Jan-70 00:00:01 GMT";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function setLoginVars() {
|
|
|
|
// Indicate if JS is enabled
|
|
|
|
document.getElementById('js_enabled').value = 1;
|
|
|
|
// Indicate if cookies are enabled
|
|
|
|
document.getElementById('cookies_enabled').value = cookiesAreEnabled();
|
|
|
|
// Copy login and password length to alternative vars since current vars will
|
|
|
|
// be removed from the request by zope's authentication mechanism.
|
|
|
|
document.getElementById('login_name').value = document.getElementById('__ac_name').value;
|
|
|
|
password = document.getElementById('__ac_password');
|
|
|
|
emptyPassword = document.getElementById('pwd_empty');
|
|
|
|
if (password.value.length==0) emptyPassword.value = '1';
|
|
|
|
else emptyPassword.value = '0';
|
|
|
|
}
|
2011-09-18 08:00:05 -05:00
|
|
|
|
2013-05-10 05:16:57 -05:00
|
|
|
function showLoginForm() {
|
|
|
|
// Hide the login link.
|
|
|
|
var loginLink = document.getElementById('loginLink');
|
|
|
|
loginLink.style.display = "none";
|
|
|
|
// Displays the login form.
|
|
|
|
var loginFields = document.getElementById('loginFields');
|
|
|
|
loginFields.style.display = "inline";
|
|
|
|
}
|
|
|
|
|
2013-07-23 03:29:39 -05:00
|
|
|
function goto(url) { window.location = url }
|
2014-04-14 13:55:23 -05:00
|
|
|
function len(dict) {
|
|
|
|
var res = 0;
|
|
|
|
for (var key in dict) res += 1;
|
|
|
|
return res;
|
|
|
|
}
|
2013-07-23 03:29:39 -05:00
|
|
|
|
2014-04-15 06:01:39 -05:00
|
|
|
function switchLanguage(selectWidget, siteUrl) {
|
2013-06-26 10:06:06 -05:00
|
|
|
var language = selectWidget.options[selectWidget.selectedIndex].value;
|
2014-04-15 06:01:39 -05:00
|
|
|
goto(siteUrl + '/config/changeLanguage?language=' + language);
|
2013-06-26 10:06:06 -05:00
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
var isIe = (navigator.appName == "Microsoft Internet Explorer");
|
2013-02-21 12:04:47 -06:00
|
|
|
|
2013-02-22 02:54:23 -06:00
|
|
|
function getElementsHavingName(tag, name) {
|
2013-02-21 12:04:47 -06:00
|
|
|
if (!isIe) return document.getElementsByName(name);
|
2013-02-22 02:54:23 -06:00
|
|
|
var elems = document.getElementsByTagName(tag);
|
2013-02-21 12:04:47 -06:00
|
|
|
var res = new Array();
|
2013-02-22 02:54:23 -06:00
|
|
|
for (var i=0; i<elems.length; i++) {
|
|
|
|
var nameAttr = elems[i].attributes['name'];
|
|
|
|
if (nameAttr && (nameAttr.value == name)) res.push(elems[i]);
|
2013-02-21 12:04:47 -06:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
// AJAX machinery
|
|
|
|
var xhrObjects = new Array(); // An array of XMLHttpRequest objects
|
|
|
|
function XhrObject() { // Wraps a XmlHttpRequest object
|
|
|
|
this.freed = 1; // Is this xhr object already dealing with a request or not?
|
|
|
|
this.xhr = false;
|
|
|
|
if (window.XMLHttpRequest) this.xhr = new XMLHttpRequest();
|
|
|
|
else this.xhr = new ActiveXObject("Microsoft.XMLHTTP");
|
|
|
|
this.hook = ''; /* The ID of the HTML element in the page that will be
|
|
|
|
replaced by result of executing the Ajax request. */
|
|
|
|
this.onGet = ''; /* The name of a Javascript function to call once we
|
|
|
|
receive the result. */
|
2015-02-03 03:56:15 -06:00
|
|
|
this.info = {}; /* An associative array for putting anything else */
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2013-03-29 08:50:12 -05:00
|
|
|
/* When inserting HTML at some DOM node in a page via Ajax, scripts defined in
|
|
|
|
this chunk of HTML are not executed. This function, typically used as "onGet"
|
|
|
|
param for the askAjaxChunk function below, will evaluate those scripts. */
|
|
|
|
function evalInnerScripts(xhrObject, hookElem) {
|
|
|
|
var scripts = hookElem.getElementsByTagName('script');
|
|
|
|
for (var i=0; i<scripts.length; i++) { eval(scripts[i].innerHTML) }
|
|
|
|
}
|
|
|
|
|
2015-02-04 11:33:27 -06:00
|
|
|
function injectChunk(elem, content, inner, searchTop){
|
|
|
|
var res = elem;
|
|
|
|
if (!isIe || (elem.tagName != 'TABLE')) {
|
|
|
|
if (inner) res.innerHTML = content;
|
2014-03-04 08:03:37 -06:00
|
|
|
else {
|
2015-02-04 11:33:27 -06:00
|
|
|
// Replace p_elem with a new node filled with p_content and return it
|
|
|
|
var id = elem.id;
|
2015-02-10 10:20:50 -06:00
|
|
|
if (id && searchTop) id = ':' + id;
|
2015-02-04 11:33:27 -06:00
|
|
|
elem.outerHTML = content;
|
2015-02-10 10:20:50 -06:00
|
|
|
if (id) res = getAjaxHook(id); // Get the new element
|
|
|
|
}
|
2014-03-04 08:03:37 -06:00
|
|
|
}
|
2015-02-04 11:33:27 -06:00
|
|
|
else {
|
|
|
|
/* IE doesn't want to replace content of a table. Force it to do so via
|
|
|
|
a temporary DOM element. */
|
|
|
|
var temp = document.createElement('div');
|
|
|
|
temp.innerHTML = content;
|
|
|
|
temp.firstChild.id = elem.id;
|
|
|
|
elem.parentNode.replaceChild(temp.firstChild, elem);
|
|
|
|
}
|
|
|
|
return res;
|
2014-03-04 08:03:37 -06:00
|
|
|
}
|
|
|
|
|
2015-02-04 11:33:27 -06:00
|
|
|
function getAjaxHook(hookId, forceTop) {
|
2014-07-23 15:29:47 -05:00
|
|
|
/* Gets the XHTML element whose ID is p_hookId: it will be the placeholder
|
|
|
|
for the result of an ajax request. If p_hookId starts with ':', we search
|
|
|
|
the element in the top browser window, not in the current one that can be
|
2015-02-04 11:33:27 -06:00
|
|
|
an iframe. If p_forceTop is true, even if hookId does not start with ':',
|
|
|
|
if the elem is not found we will search in the top browser window. */
|
2014-08-15 03:46:28 -05:00
|
|
|
if (!hookId) return;
|
2014-07-23 15:29:47 -05:00
|
|
|
var container = window.document;
|
|
|
|
var startIndex = 0;
|
|
|
|
if (hookId[0] == ':') {
|
|
|
|
container = window.top.document;
|
|
|
|
startIndex = 1;
|
|
|
|
}
|
2015-02-04 11:33:27 -06:00
|
|
|
var id = hookId.slice(startIndex);
|
|
|
|
var res = container.getElementById(id);
|
|
|
|
if (!res && forceTop) res = window.top.document.getElementById(id);
|
|
|
|
return res;
|
2014-07-23 15:29:47 -05:00
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
function getAjaxChunk(pos) {
|
|
|
|
// This function is the callback called by the AJAX machinery (see function
|
|
|
|
// askAjaxChunk below) when an Ajax response is available.
|
|
|
|
// First, find back the correct XMLHttpRequest object
|
2015-02-10 10:20:50 -06:00
|
|
|
var rq = xhrObjects[pos];
|
|
|
|
if ( (typeof(rq) != 'undefined') && (rq.freed == 0)) {
|
|
|
|
if ((!rq.hook) || (rq.xhr.readyState != 4)) return;
|
|
|
|
// We have received the HTML chunk
|
|
|
|
var hookElem = getAjaxHook(rq.hook);
|
|
|
|
if (hookElem) {
|
|
|
|
var content = rq.xhr.responseText;
|
|
|
|
var searchTop = rq.hook[0] == ':';
|
|
|
|
var injected = injectChunk(hookElem, content, false, searchTop);
|
|
|
|
// Call a custom Javascript function if required
|
|
|
|
if (rq.onGet) rq.onGet(rq, injected);
|
|
|
|
// Display the Appy message if present
|
|
|
|
var msg = rq.xhr.getResponseHeader('Appy-Message');
|
|
|
|
if (msg) showAppyMessage(decodeURIComponent(escape(msg)));
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
2015-02-10 10:20:50 -06:00
|
|
|
rq.freed = 1;
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-04 11:33:27 -06:00
|
|
|
function askAjaxChunk(hook, mode, url, px, params, beforeSend, onGet) {
|
2013-08-21 05:35:30 -05:00
|
|
|
/* This function will ask to get a chunk of XHTML on the server through a
|
2011-09-18 08:00:05 -05:00
|
|
|
XMLHttpRequest. p_mode can be 'GET' or 'POST'. p_url is the URL of a
|
2013-08-21 05:35:30 -05:00
|
|
|
given server object. On this object we will call method "ajax" that will
|
|
|
|
call a specific p_px with some additional p_params (must be an associative
|
|
|
|
array) if required. If p_px is of the form <field name>:<px name>, the PX
|
|
|
|
will be found on the field named <field name> instead of being found
|
|
|
|
directly on the object at p_url.
|
2011-09-18 08:00:05 -05:00
|
|
|
|
2013-08-21 05:35:30 -05:00
|
|
|
p_hook is the ID of the XHTML element that will be filled with the XHTML
|
2014-07-23 15:29:47 -05:00
|
|
|
result from the server. If it starts with ':', we will find the element in
|
|
|
|
the top browser window and not in the current one (that can be an iframe).
|
2011-09-18 08:00:05 -05:00
|
|
|
|
|
|
|
p_beforeSend is a Javascript function to call before sending the request.
|
2013-08-21 05:35:30 -05:00
|
|
|
This function will get 2 args: the XMLHttpRequest object and the p_params.
|
|
|
|
This method can return, in a string, additional parameters to send, ie:
|
|
|
|
"¶m1=blabla¶m2=blabla".
|
2011-09-18 08:00:05 -05:00
|
|
|
|
|
|
|
p_onGet is a Javascript function to call when we will receive the answer.
|
|
|
|
This function will get 2 args, too: the XMLHttpRequest object and the
|
|
|
|
HTML node element into which the result has been inserted.
|
|
|
|
*/
|
|
|
|
// First, get a non-busy XMLHttpRequest object.
|
|
|
|
var pos = -1;
|
|
|
|
for (var i=0; i < xhrObjects.length; i++) {
|
|
|
|
if (xhrObjects[i].freed == 1) { pos = i; break; }
|
|
|
|
}
|
|
|
|
if (pos == -1) {
|
|
|
|
pos = xhrObjects.length;
|
|
|
|
xhrObjects[pos] = new XhrObject();
|
|
|
|
}
|
|
|
|
xhrObjects[pos].hook = hook;
|
|
|
|
xhrObjects[pos].onGet = onGet;
|
|
|
|
if (xhrObjects[pos].xhr) {
|
|
|
|
var rq = xhrObjects[pos];
|
|
|
|
rq.freed = 0;
|
|
|
|
// Construct parameters
|
2013-08-21 05:35:30 -05:00
|
|
|
var paramsFull = 'px=' + px;
|
2011-09-18 08:00:05 -05:00
|
|
|
if (params) {
|
|
|
|
for (var paramName in params)
|
|
|
|
paramsFull = paramsFull + '&' + paramName + '=' + params[paramName];
|
|
|
|
}
|
|
|
|
// Call beforeSend if required
|
|
|
|
if (beforeSend) {
|
|
|
|
var res = beforeSend(rq, params);
|
|
|
|
if (res) paramsFull = paramsFull + res;
|
|
|
|
}
|
|
|
|
// Construct the URL to call
|
2013-08-21 05:35:30 -05:00
|
|
|
var urlFull = url + '/ajax';
|
2011-09-18 08:00:05 -05:00
|
|
|
if (mode == 'GET') {
|
|
|
|
urlFull = urlFull + '?' + paramsFull;
|
|
|
|
}
|
2015-02-17 12:15:50 -06:00
|
|
|
/* Display the preloader (rq.hook may be null if the ajax result would be
|
|
|
|
the same as what is currently shown, as when inline-editing a rich text
|
|
|
|
field). */
|
|
|
|
if (rq.hook) injectChunk(getAjaxHook(rq.hook), loadingZone, true);
|
2011-09-18 08:00:05 -05:00
|
|
|
// Perform the asynchronous HTTP GET or POST
|
|
|
|
rq.xhr.open(mode, urlFull, true);
|
|
|
|
if (mode == 'POST') {
|
|
|
|
// Set the correct HTTP headers
|
|
|
|
rq.xhr.setRequestHeader(
|
|
|
|
"Content-Type", "application/x-www-form-urlencoded");
|
2014-08-15 03:46:28 -05:00
|
|
|
// rq.xhr.setRequestHeader("Content-length", paramsFull.length);
|
|
|
|
// rq.xhr.setRequestHeader("Connection", "close");
|
2011-09-18 08:00:05 -05:00
|
|
|
rq.xhr.onreadystatechange = function(){ getAjaxChunk(pos); }
|
|
|
|
rq.xhr.send(paramsFull);
|
|
|
|
}
|
|
|
|
else if (mode == 'GET') {
|
|
|
|
rq.xhr.onreadystatechange = function() { getAjaxChunk(pos); }
|
|
|
|
if (window.XMLHttpRequest) { rq.xhr.send(null); }
|
|
|
|
else if (window.ActiveXObject) { rq.xhr.send(); }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-03 03:56:15 -06:00
|
|
|
// Object representing all the data required to perform an Ajax request
|
|
|
|
function AjaxData(hook, px, params, parentHook, url, mode, beforeSend, onGet) {
|
|
|
|
this.hook = hook;
|
|
|
|
this.mode = mode;
|
|
|
|
if (!mode) this.mode = 'GET';
|
|
|
|
this.url = url;
|
|
|
|
this.px = px;
|
|
|
|
this.params = params;
|
|
|
|
this.beforeSend = beforeSend;
|
|
|
|
this.onGet = onGet;
|
|
|
|
/* If a parentHook is spefified, this AjaxData must be completed with a parent
|
|
|
|
AjaxData instance. */
|
|
|
|
this.parentHook = parentHook;
|
2015-02-17 01:58:04 -06:00
|
|
|
// Inject this AjaxData instance into p_hook
|
|
|
|
getAjaxHook(hook, true)['ajax'] = this;
|
2015-02-03 03:56:15 -06:00
|
|
|
}
|
|
|
|
|
2015-02-04 05:23:56 -06:00
|
|
|
function askAjax(hook, form, params) {
|
|
|
|
/* Call askAjaxChunk by getting an AjaxData instance from p_hook, a
|
|
|
|
potential action from p_form and additional parameters from p_param. */
|
2015-02-04 11:33:27 -06:00
|
|
|
var d = getAjaxHook(hook)['ajax'];
|
2015-02-03 03:56:15 -06:00
|
|
|
// Complete data with a parent data if present
|
|
|
|
if (d['parentHook']) {
|
2015-02-04 11:33:27 -06:00
|
|
|
var parentHook = d['parentHook'];
|
|
|
|
if (hook[0] == ':') parentHook = ':' + parentHook;
|
|
|
|
var parent = getAjaxHook(parentHook)['ajax'];
|
2015-02-03 03:56:15 -06:00
|
|
|
for (var key in parent) {
|
|
|
|
if (key == 'params') continue; // Will get a specific treatment herafter
|
|
|
|
if (!d[key]) d[key] = parent[key]; // Override if no value on child
|
|
|
|
}
|
|
|
|
// Merge parameters
|
|
|
|
if (parent.params) {
|
|
|
|
for (var key in parent.params) {
|
|
|
|
if (key in d.params) continue; // Override if not value on child
|
|
|
|
d.params[key] = parent.params[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-17 01:58:04 -06:00
|
|
|
// Resolve dynamic parameter "cbChecked" if present
|
|
|
|
if ('cbChecked' in d.params) {
|
|
|
|
var cb = getAjaxHook(d.params['cbChecked'], true);
|
|
|
|
if (cb) d.params['cbChecked'] = cb.checked;
|
|
|
|
else delete d.params['cbChecked'];
|
|
|
|
}
|
2015-02-03 03:56:15 -06:00
|
|
|
// If a p_form id is given, integrate the form submission in the ajax request
|
|
|
|
if (form) {
|
|
|
|
var f = document.getElementById(form);
|
|
|
|
var mode = 'POST';
|
|
|
|
// Deduce the action from the form action
|
|
|
|
d.params['action'] = _rsplit(f.action, '/', 2)[1];
|
|
|
|
// Get the other params
|
|
|
|
var elems = f.elements;
|
|
|
|
for (var i=0; i < elems.length; i++) {
|
2015-02-04 03:23:40 -06:00
|
|
|
var value = elems[i].value;
|
|
|
|
if (elems[i].name == 'comment') value = encodeURIComponent(value);
|
|
|
|
d.params[elems[i].name] = value;
|
2015-02-03 03:56:15 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else var mode = d.mode;
|
2015-02-04 05:23:56 -06:00
|
|
|
// Get p_params if given. Note that they override anything else.
|
2015-03-04 07:35:02 -06:00
|
|
|
if (params && ('mode' in params)) {
|
|
|
|
mode = params['mode']; delete params['mode'] }
|
2015-02-04 05:23:56 -06:00
|
|
|
if (params) { for (var key in params) d.params[key] = params[key]; }
|
2015-03-04 07:35:02 -06:00
|
|
|
askAjaxChunk(hook,mode,d.url,d.px,d.params,d.beforeSend,evalInnerScripts);
|
2015-02-04 11:33:27 -06:00
|
|
|
}
|
2015-02-03 03:56:15 -06:00
|
|
|
|
2015-02-13 10:29:51 -06:00
|
|
|
function askBunch(hookId, startNumber) {
|
|
|
|
askAjax(hookId, null, {'startNumber': startNumber})}
|
|
|
|
|
|
|
|
function askBunchSorted(hookId, sortKey, sortOrder) {
|
|
|
|
var data = {'startNumber': '0', 'sortKey': sortKey, 'sortOrder': sortOrder};
|
|
|
|
askAjax(hookId, null, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function askBunchFiltered(hookId, filterKey) {
|
|
|
|
var data = {'startNumber': '0', 'filterKey': filterKey, 'filterValue': ''};
|
|
|
|
var node = document.getElementById(hookId + '_' + filterKey);
|
|
|
|
if (node.value) data['filterValue'] = encodeURIComponent(node.value);
|
|
|
|
askAjax(hookId, null, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function askBunchMove(hookId, startNumber, uid, move){
|
|
|
|
var moveTo = move;
|
|
|
|
if (typeof move == 'object'){
|
|
|
|
// Get the new index from an input field
|
|
|
|
var id = move.id;
|
2015-02-23 08:02:19 -06:00
|
|
|
id = id.substr(0, id.length-4) + '_v';
|
2015-02-13 10:29:51 -06:00
|
|
|
var input = document.getElementById(id);
|
|
|
|
if (isNaN(input.value)) {
|
|
|
|
input.style.background = wrongTextInput;
|
|
|
|
return;
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
2015-02-13 10:29:51 -06:00
|
|
|
moveTo = 'index_' + input.value;
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
2015-02-13 10:29:51 -06:00
|
|
|
var data = {'startNumber': startNumber, 'action': 'doChangeOrder',
|
|
|
|
'refObjectUid': uid, 'move': moveTo};
|
|
|
|
askAjax(hookId, null, data);
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2015-02-13 10:29:51 -06:00
|
|
|
function askBunchSortRef(hookId, startNumber, sortKey, reverse) {
|
|
|
|
var data = {'startNumber': startNumber, 'action': 'sort', 'sortKey': sortKey,
|
|
|
|
'reverse': reverse};
|
|
|
|
askAjax(hookId, null, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function clickOn(node) {
|
|
|
|
// If node is a form, disable all form buttons
|
|
|
|
if (node.tagName == 'FORM') {
|
|
|
|
var i = node.elements.length -1;
|
|
|
|
while (i >= 0) {
|
|
|
|
if (node.elements[i].type == 'button') { clickOn(node.elements[i]); }
|
|
|
|
i = i - 1;
|
|
|
|
}
|
|
|
|
return;
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
2015-02-13 10:29:51 -06:00
|
|
|
// Disable any click on p_node to be protected against double-click
|
|
|
|
var cn = (node.className)? 'unclickable ' + node.className : 'unclickable';
|
|
|
|
node.className = cn;
|
|
|
|
/* For a button, show the preloader directly. For a link, show it only after
|
|
|
|
a while, if the target page is still not there. */
|
|
|
|
if (node.tagName != 'A') injectChunk(node, loadingButton);
|
|
|
|
else setTimeout(function(){injectChunk(node, loadingLink)}, 700);
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2014-10-21 02:25:37 -05:00
|
|
|
function gotoTied(objectUrl, field, numberWidget, total) {
|
|
|
|
// Check that the number is correct
|
|
|
|
try {
|
|
|
|
var number = parseInt(numberWidget.value);
|
|
|
|
if (!isNaN(number)) {
|
|
|
|
if ((number >= 1) && (number <= total)) {
|
|
|
|
goto(objectUrl + '/gotoTied?field=' + field + '&number=' + number);
|
|
|
|
}
|
|
|
|
else numberWidget.style.background = wrongTextInput; }
|
|
|
|
else numberWidget.style.background = wrongTextInput; }
|
|
|
|
catch (err) { numberWidget.style.background = wrongTextInput; }
|
|
|
|
}
|
|
|
|
|
2014-08-05 02:48:05 -05:00
|
|
|
function askField(hookId, objectUrl, layoutType, customParams, showChanges,
|
|
|
|
masterValues, requestValue, error, className){
|
2015-02-13 10:29:51 -06:00
|
|
|
// Sends an Ajax request for getting the content of any field
|
2013-01-08 09:58:29 -06:00
|
|
|
var fieldName = hookId.split('_')[1];
|
2013-08-21 05:35:30 -05:00
|
|
|
var params = {'layoutType': layoutType, 'showChanges': showChanges};
|
2014-07-23 15:29:47 -05:00
|
|
|
if (customParams){for (var key in customParams) params[key]=customParams[key]}
|
2014-03-03 11:54:21 -06:00
|
|
|
if (masterValues) params['masterValues'] = masterValues.join('*');
|
|
|
|
if (requestValue) params[fieldName] = requestValue;
|
2014-03-04 08:03:37 -06:00
|
|
|
if (error) params[fieldName + '_error'] = error;
|
2014-03-05 06:25:36 -06:00
|
|
|
var px = fieldName + ':pxRender';
|
|
|
|
if (className) px = className + ':' + px;
|
|
|
|
askAjaxChunk(hookId, 'GET', objectUrl, px, params, null, evalInnerScripts);
|
2013-01-08 09:58:29 -06:00
|
|
|
}
|
|
|
|
|
2014-08-15 03:46:28 -05:00
|
|
|
function doInlineSave(objectUid, name, objectUrl, content, language){
|
|
|
|
/* Ajax-saves p_content of field named p_name (or only on part corresponding
|
|
|
|
to p_language if the field is multilingual) on object whose id is
|
2014-04-30 14:08:42 -05:00
|
|
|
p_objectUid and whose URL is p_objectUrl. Asks a confirmation before
|
|
|
|
doing it. */
|
2014-05-02 05:35:09 -05:00
|
|
|
var doIt = confirm(save_confirm);
|
2014-04-30 14:08:42 -05:00
|
|
|
var params = {'action': 'storeFromAjax', 'layoutType': 'view'};
|
2014-08-15 03:46:28 -05:00
|
|
|
if (language) params['languageOnly'] = language;
|
2014-04-30 14:08:42 -05:00
|
|
|
var hook = null;
|
|
|
|
if (!doIt) {
|
|
|
|
params['cancel'] = 'True';
|
|
|
|
hook = objectUid + '_' + name;
|
|
|
|
}
|
|
|
|
else { params['fieldContent'] = encodeURIComponent(content) }
|
|
|
|
askAjaxChunk(hook, 'POST', objectUrl, name + ':pxRender', params, null,
|
|
|
|
evalInnerScripts);
|
|
|
|
}
|
|
|
|
|
2014-04-03 10:32:57 -05:00
|
|
|
// Used by checkbox widgets for having radio-button-like behaviour.
|
2011-09-18 08:00:05 -05:00
|
|
|
function toggleCheckbox(visibleCheckbox, hiddenBoolean) {
|
|
|
|
vis = document.getElementById(visibleCheckbox);
|
|
|
|
hidden = document.getElementById(hiddenBoolean);
|
|
|
|
if (vis.checked) hidden.value = 'True';
|
|
|
|
else hidden.value = 'False';
|
|
|
|
}
|
|
|
|
|
2015-02-05 07:05:29 -06:00
|
|
|
// JS implementation of Python ''.rsplit
|
2014-04-04 09:49:22 -05:00
|
|
|
function _rsplit(s, delimiter, limit) {
|
|
|
|
var elems = s.split(delimiter);
|
|
|
|
var exc = elems.length - limit;
|
|
|
|
if (exc <= 0) return elems;
|
2015-02-03 03:56:15 -06:00
|
|
|
// Merge back first elements to get p_limit elements
|
2014-04-04 09:49:22 -05:00
|
|
|
var head = '';
|
|
|
|
var res = [];
|
|
|
|
for (var i=0; i < elems.length; i++) {
|
|
|
|
if (exc > 0) { head += elems[i] + delimiter; exc -= 1 }
|
|
|
|
else { if (exc == 0) { res.push(head + elems[i]); exc -= 1 }
|
|
|
|
else res.push(elems[i]) }
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-02-05 07:05:29 -06:00
|
|
|
// (Un)checks a checkbox corresponding to a linked object
|
2014-07-19 06:42:39 -05:00
|
|
|
function toggleCb(checkbox) {
|
2014-04-03 10:32:57 -05:00
|
|
|
var name = checkbox.getAttribute('name');
|
2014-04-04 09:49:22 -05:00
|
|
|
var elems = _rsplit(name, '_', 3);
|
2015-02-05 07:05:29 -06:00
|
|
|
// Get the DOM node corresponding to the Ref field
|
2014-04-03 10:32:57 -05:00
|
|
|
var node = document.getElementById(elems[0] + '_' + elems[1]);
|
|
|
|
// Get the array that stores checkbox statuses.
|
|
|
|
var statuses = node['_appy_' + elems[2] + '_cbs'];
|
|
|
|
// Get the array semantics
|
|
|
|
var semantics = node['_appy_' + elems[2] + '_sem'];
|
|
|
|
var uid = checkbox.value;
|
|
|
|
if (semantics == 'unchecked') {
|
|
|
|
if (!checkbox.checked) statuses[uid] = null;
|
|
|
|
else {if (uid in statuses) delete statuses[uid]};
|
|
|
|
}
|
|
|
|
else { // semantics is 'checked'
|
|
|
|
if (checkbox.checked) statuses[uid] = null;
|
|
|
|
else {if (uid in statuses) delete statuses[uid]};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-05 07:05:29 -06:00
|
|
|
function findNode(node, id) {
|
|
|
|
/* When coming back from the iframe popup, we are still in the context of the
|
|
|
|
iframe, which can cause problems for finding nodes. We have found that this
|
|
|
|
case can be detected by checking node.window. */
|
|
|
|
if (node.window) var container = node.window.document;
|
|
|
|
else var container = window.parent.document;
|
|
|
|
return container.getElementById(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialise checkboxes of a Ref field or Search
|
2014-07-19 06:42:39 -05:00
|
|
|
function initCbs(id) {
|
2014-04-04 09:49:22 -05:00
|
|
|
var elems = _rsplit(id, '_', 3);
|
2015-02-05 07:05:29 -06:00
|
|
|
// Get the DOM node corresponding to the Ref field
|
2014-04-03 10:32:57 -05:00
|
|
|
var node = document.getElementById(elems[0] + '_' + elems[1]);
|
2015-02-05 07:05:29 -06:00
|
|
|
// Get the array that stores checkbox statuses
|
2014-04-03 10:32:57 -05:00
|
|
|
var statuses = node['_appy_' + elems[2] + '_cbs'];
|
|
|
|
// Get the array semantics
|
|
|
|
var semantics = node['_appy_' + elems[2] + '_sem'];
|
|
|
|
var value = (semantics == 'unchecked')? false: true;
|
2015-02-05 07:05:29 -06:00
|
|
|
// Update visible checkboxes
|
2014-04-03 10:32:57 -05:00
|
|
|
var checkboxes = getElementsHavingName('input', id);
|
|
|
|
for (var i=0; i < checkboxes.length; i++) {
|
|
|
|
if (checkboxes[i].value in statuses) checkboxes[i].checked = value;
|
|
|
|
else checkboxes[i].checked = !value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-05 07:05:29 -06:00
|
|
|
// Toggle all checkboxes of a Ref field or Search
|
2014-07-19 06:42:39 -05:00
|
|
|
function toggleAllCbs(id) {
|
2014-04-04 09:49:22 -05:00
|
|
|
var elems = _rsplit(id, '_', 3);
|
2015-02-05 07:05:29 -06:00
|
|
|
// Get the DOM node corresponding to the Ref field
|
2014-04-03 10:32:57 -05:00
|
|
|
var node = document.getElementById(elems[0] + '_' + elems[1]);
|
2015-02-05 07:05:29 -06:00
|
|
|
// Empty the array that stores checkbox statuses
|
2014-04-03 10:32:57 -05:00
|
|
|
var statuses = node['_appy_' + elems[2] + '_cbs'];
|
|
|
|
for (var key in statuses) delete statuses[key];
|
2015-02-05 07:05:29 -06:00
|
|
|
// Switch the array semantics
|
2014-04-03 10:32:57 -05:00
|
|
|
var semAttr = '_appy_' + elems[2] + '_sem';
|
|
|
|
if (node[semAttr] == 'unchecked') node[semAttr] = 'checked';
|
|
|
|
else node[semAttr] = 'unchecked';
|
|
|
|
// Update the visible checkboxes
|
2014-07-19 06:42:39 -05:00
|
|
|
initCbs(id);
|
2014-04-03 10:32:57 -05:00
|
|
|
}
|
|
|
|
|
2014-02-26 03:40:27 -06:00
|
|
|
// Shows/hides a dropdown menu
|
|
|
|
function toggleDropdown(dropdownId, forcedValue){
|
|
|
|
var dropdown = document.getElementById(dropdownId);
|
|
|
|
// Force to p_forcedValue if specified
|
|
|
|
if (forcedValue) {dropdown.style.display = forcedValue}
|
|
|
|
else {
|
|
|
|
var displayValue = dropdown.style.display;
|
|
|
|
if (displayValue == 'block') dropdown.style.display = 'none';
|
|
|
|
else dropdown.style.display = 'block';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 11:25:29 -06:00
|
|
|
// Function that sets a value for showing/hiding sub-titles
|
2013-09-23 15:36:09 -05:00
|
|
|
function setSubTitles(value, tag) {
|
2012-10-31 15:17:31 -05:00
|
|
|
createCookie('showSubTitles', value);
|
|
|
|
// Get the sub-titles
|
2013-09-23 15:36:09 -05:00
|
|
|
var subTitles = getElementsHavingName(tag, 'subTitle');
|
2012-10-31 15:17:31 -05:00
|
|
|
if (subTitles.length == 0) return;
|
2015-02-06 11:25:29 -06:00
|
|
|
// Define the display style depending on p_tag
|
2013-09-23 15:36:09 -05:00
|
|
|
var displayStyle = 'inline';
|
|
|
|
if (tag == 'tr') displayStyle = 'table-row';
|
2012-10-31 15:17:31 -05:00
|
|
|
for (var i=0; i < subTitles.length; i++) {
|
2013-09-23 15:36:09 -05:00
|
|
|
if (value == 'true') subTitles[i].style.display = displayStyle;
|
2012-10-31 15:17:31 -05:00
|
|
|
else subTitles[i].style.display = 'none';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-06 11:25:29 -06:00
|
|
|
// Function that toggles the value for showing/hiding sub-titles
|
2013-09-23 15:36:09 -05:00
|
|
|
function toggleSubTitles(tag) {
|
2012-12-20 09:09:05 -06:00
|
|
|
// Get the current value
|
2012-10-31 15:17:31 -05:00
|
|
|
var value = readCookie('showSubTitles');
|
2012-12-20 09:09:05 -06:00
|
|
|
if (value == null) value = 'true';
|
|
|
|
// Toggle the value
|
2012-10-31 15:17:31 -05:00
|
|
|
var newValue = 'true';
|
|
|
|
if (value == 'true') newValue = 'false';
|
2013-09-23 15:36:09 -05:00
|
|
|
if (!tag) tag = 'div';
|
|
|
|
setSubTitles(newValue, tag);
|
2012-10-31 15:17:31 -05:00
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
// Functions used for master/slave relationships between widgets
|
2011-10-01 15:40:13 -05:00
|
|
|
function getSlaveInfo(slave, infoType) {
|
2015-02-06 11:25:29 -06:00
|
|
|
// Returns the appropriate info about slavery, depending on p_infoType
|
2014-03-03 11:54:21 -06:00
|
|
|
var cssClasses = slave.className.split(' ');
|
|
|
|
var masterInfo = null;
|
2015-02-06 11:25:29 -06:00
|
|
|
// Find the CSS class containing master-related info
|
2011-10-01 15:40:13 -05:00
|
|
|
for (var j=0; j < cssClasses.length; j++) {
|
2014-03-03 11:54:21 -06:00
|
|
|
if (cssClasses[j].indexOf('slave*') == 0) {
|
2015-02-06 11:25:29 -06:00
|
|
|
// Extract, from this CSS class, master name or master values
|
2014-03-03 11:54:21 -06:00
|
|
|
masterInfo = cssClasses[j].split('*');
|
2011-10-01 15:40:13 -05:00
|
|
|
if (infoType == 'masterName') return masterInfo[1];
|
2014-03-03 11:54:21 -06:00
|
|
|
else return masterInfo.slice(2);
|
2011-10-01 15:40:13 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getMasterValues(master) {
|
2015-02-06 11:25:29 -06:00
|
|
|
// Returns the list of values that p_master currently has
|
2012-10-29 23:53:45 -05:00
|
|
|
var res = null;
|
2011-11-10 14:59:02 -06:00
|
|
|
if ((master.tagName == 'INPUT') && (master.type != 'checkbox')) {
|
|
|
|
res = master.value;
|
2012-10-29 23:53:45 -05:00
|
|
|
if ((res.charAt(0) == '(') || (res.charAt(0) == '[')) {
|
2011-10-01 15:40:13 -05:00
|
|
|
// There are multiple values, split it
|
|
|
|
values = res.substring(1, res.length-1).split(',');
|
|
|
|
res = [];
|
2012-10-29 23:53:45 -05:00
|
|
|
var v = null;
|
2011-10-01 15:40:13 -05:00
|
|
|
for (var i=0; i < values.length; i++){
|
|
|
|
v = values[i].replace(' ', '');
|
|
|
|
res.push(v.substring(1, v.length-1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else res = [res]; // A single value
|
|
|
|
}
|
|
|
|
else if (master.type == 'checkbox') {
|
|
|
|
res = master.checked + '';
|
|
|
|
res = res.charAt(0).toUpperCase() + res.substr(1);
|
|
|
|
res = [res];
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
else { // SELECT widget
|
2011-10-01 15:40:13 -05:00
|
|
|
res = [];
|
|
|
|
for (var i=0; i < master.options.length; i++) {
|
|
|
|
if (master.options[i].selected) res.push(master.options[i].value);
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2011-10-01 15:40:13 -05:00
|
|
|
function getSlaves(master) {
|
2015-02-06 11:25:29 -06:00
|
|
|
// Gets all the slaves of master
|
2013-02-22 02:54:23 -06:00
|
|
|
allSlaves = getElementsHavingName('table', 'slave');
|
2011-11-10 14:59:02 -06:00
|
|
|
res = [];
|
2011-10-04 13:12:58 -05:00
|
|
|
masterName = master.attributes['name'].value;
|
2015-02-06 11:25:29 -06:00
|
|
|
// Remove leading 'w_' if the master is in a search screen
|
2014-03-05 06:25:36 -06:00
|
|
|
if (masterName.indexOf('w_') == 0) masterName = masterName.slice(2);
|
2011-10-04 13:12:58 -05:00
|
|
|
if (master.type == 'checkbox') {
|
|
|
|
masterName = masterName.substr(0, masterName.length-8);
|
|
|
|
}
|
2014-03-03 11:54:21 -06:00
|
|
|
slavePrefix = 'slave*' + masterName + '*';
|
2011-11-10 14:59:02 -06:00
|
|
|
for (var i=0; i < allSlaves.length; i++){
|
|
|
|
cssClasses = allSlaves[i].className.split(' ');
|
2011-10-01 15:40:13 -05:00
|
|
|
for (var j=0; j < cssClasses.length; j++) {
|
|
|
|
if (cssClasses[j].indexOf(slavePrefix) == 0) {
|
2011-11-10 14:59:02 -06:00
|
|
|
res.push(allSlaves[i]);
|
2011-10-01 15:40:13 -05:00
|
|
|
break;
|
|
|
|
}
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
}
|
2011-10-01 15:40:13 -05:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2014-03-05 06:25:36 -06:00
|
|
|
function updateSlaves(master, slave, objectUrl, layoutType, requestValues,
|
|
|
|
errors, className){
|
2014-03-03 11:54:21 -06:00
|
|
|
/* Given the value(s) in a master field, we must update slave's visibility or
|
|
|
|
value(s). If p_slave is given, it updates only this slave. Else, it updates
|
|
|
|
all slaves of p_master. */
|
2011-11-10 14:59:02 -06:00
|
|
|
var slaves = null;
|
|
|
|
if (slave) { slaves = [slave]; }
|
|
|
|
else { slaves = getSlaves(master); }
|
2011-10-01 15:40:13 -05:00
|
|
|
masterValues = getMasterValues(master);
|
|
|
|
for (var i=0; i < slaves.length; i++) {
|
|
|
|
slaveryValues = getSlaveInfo(slaves[i], 'masterValues');
|
2014-03-03 11:54:21 -06:00
|
|
|
if (slaveryValues[0] != '+') {
|
2015-02-06 11:25:29 -06:00
|
|
|
// Update slaves visibility depending on master values
|
2014-03-03 11:54:21 -06:00
|
|
|
var showSlave = false;
|
|
|
|
for (var j=0; j < slaveryValues.length; j++) {
|
|
|
|
for (var k=0; k< masterValues.length; k++) {
|
|
|
|
if (slaveryValues[j] == masterValues[k]) showSlave = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showSlave) slaves[i].style.display = '';
|
|
|
|
else slaves[i].style.display = 'none';
|
|
|
|
}
|
|
|
|
else {
|
2015-02-06 11:25:29 -06:00
|
|
|
// Update slaves' values depending on master values
|
2014-03-03 11:54:21 -06:00
|
|
|
var slaveId = slaves[i].id;
|
|
|
|
var slaveName = slaveId.split('_')[1];
|
|
|
|
var reqValue = null;
|
|
|
|
if (requestValues && (slaveName in requestValues))
|
|
|
|
reqValue = requestValues[slaveName];
|
2014-03-04 08:03:37 -06:00
|
|
|
var err = null;
|
|
|
|
if (errors && (slaveName in errors))
|
|
|
|
err = errors[slaveName];
|
2014-08-05 02:48:05 -05:00
|
|
|
askField(slaveId, objectUrl, layoutType, null, false, masterValues,
|
|
|
|
reqValue, err, className);
|
2014-03-03 11:54:21 -06:00
|
|
|
}
|
2011-10-01 15:40:13 -05:00
|
|
|
}
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2014-03-04 08:03:37 -06:00
|
|
|
function initSlaves(objectUrl, layoutType, requestValues, errors) {
|
2014-03-03 11:54:21 -06:00
|
|
|
/* When the current page is loaded, we must set the correct state for all
|
2014-03-04 08:03:37 -06:00
|
|
|
slave fields. For those that are updated via Ajax requests, their
|
|
|
|
p_requestValues and validation p_errors must be carried to those
|
|
|
|
requests. */
|
2013-02-22 02:54:23 -06:00
|
|
|
slaves = getElementsHavingName('table', 'slave');
|
2011-11-10 14:59:02 -06:00
|
|
|
i = slaves.length -1;
|
|
|
|
while (i >= 0) {
|
2011-10-01 15:40:13 -05:00
|
|
|
masterName = getSlaveInfo(slaves[i], 'masterName');
|
|
|
|
master = document.getElementById(masterName);
|
2012-06-02 07:36:49 -05:00
|
|
|
// If master is not here, we can't hide its slaves when appropriate.
|
2014-03-03 11:54:21 -06:00
|
|
|
if (master) {
|
2014-03-04 08:03:37 -06:00
|
|
|
updateSlaves(master,slaves[i],objectUrl,layoutType,requestValues,errors);}
|
2011-11-10 14:59:02 -06:00
|
|
|
i -= 1;
|
2011-09-20 12:21:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-21 15:25:27 -05:00
|
|
|
// Function used to submit the appy form on pxEdit
|
2013-01-18 07:32:29 -06:00
|
|
|
function submitAppyForm(button) {
|
2015-02-04 03:23:40 -06:00
|
|
|
var f = document.getElementById('appyForm');
|
|
|
|
// On which button has the user clicked ?
|
2015-02-10 10:20:50 -06:00
|
|
|
f.button.value = button.id;
|
|
|
|
f.submit(); clickOn(button);
|
2013-01-18 07:32:29 -06:00
|
|
|
}
|
|
|
|
|
2015-02-04 02:27:07 -06:00
|
|
|
function submitForm(formId, msg, showComment, back) {
|
2015-02-03 03:56:15 -06:00
|
|
|
var f = document.getElementById(formId);
|
|
|
|
if (!msg) {
|
2015-02-04 02:27:07 -06:00
|
|
|
/* Submit the form and either refresh the entire page (back is null)
|
2015-02-03 03:56:15 -06:00
|
|
|
or ajax-refresh a given part only (p_back corresponds to the id of the
|
|
|
|
DOM node to be refreshed. */
|
2015-02-10 10:20:50 -06:00
|
|
|
if (back) { askAjax(back, formId); }
|
|
|
|
else { f.submit(); clickOn(f) }
|
2015-02-03 03:56:15 -06:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Ask a confirmation to the user before proceeding
|
|
|
|
if (back) {
|
2015-02-04 03:23:40 -06:00
|
|
|
var js = "askAjax('"+back+"', '"+formId+"');";
|
|
|
|
askConfirm('form-script', formId+'+'+js, msg, showComment); }
|
2015-02-04 02:27:07 -06:00
|
|
|
else askConfirm('form', formId, msg, showComment);
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-04 02:27:07 -06:00
|
|
|
// Function used for triggering a workflow transition
|
2015-02-10 10:20:50 -06:00
|
|
|
function triggerTransition(formId, node, msg, back) {
|
2015-02-04 02:27:07 -06:00
|
|
|
var f = document.getElementById(formId);
|
2015-02-10 10:20:50 -06:00
|
|
|
f.transition.value = node.id;
|
2015-02-04 02:27:07 -06:00
|
|
|
submitForm(formId, msg, true, back);
|
|
|
|
}
|
|
|
|
|
2015-02-04 11:33:27 -06:00
|
|
|
function onDeleteObject(uid, back) {
|
|
|
|
var f = document.getElementById('deleteForm');
|
|
|
|
f.uid.value = uid;
|
|
|
|
submitForm('deleteForm', action_confirm, false, back);
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2013-01-11 03:52:54 -06:00
|
|
|
function onDeleteEvent(objectUid, eventTime) {
|
|
|
|
f = document.getElementById('deleteEventForm');
|
|
|
|
f.objectUid.value = objectUid;
|
|
|
|
f.eventTime.value = eventTime;
|
2014-03-24 16:55:00 -05:00
|
|
|
askConfirm('form', 'deleteEventForm', action_confirm);
|
2013-01-11 03:52:54 -06:00
|
|
|
}
|
|
|
|
|
2014-04-03 10:32:57 -05:00
|
|
|
function onLink(action, sourceUid, fieldName, targetUid) {
|
|
|
|
f = document.getElementById('linkForm');
|
|
|
|
f.linkAction.value = action;
|
2012-10-08 03:08:54 -05:00
|
|
|
f.sourceUid.value = sourceUid;
|
|
|
|
f.fieldName.value = fieldName;
|
|
|
|
f.targetUid.value = targetUid;
|
2014-04-03 10:32:57 -05:00
|
|
|
f.submit();
|
2012-10-08 03:08:54 -05:00
|
|
|
}
|
|
|
|
|
2014-07-23 15:29:47 -05:00
|
|
|
function stringFromDictKeys(d){
|
2015-02-06 11:25:29 -06:00
|
|
|
// Gets a string containing comma-separated keys from dict p_d
|
2014-07-23 15:29:47 -05:00
|
|
|
var res = [];
|
|
|
|
for (var key in d) res.push(key);
|
|
|
|
return res.join();
|
|
|
|
}
|
|
|
|
|
2014-04-04 09:49:22 -05:00
|
|
|
function onLinkMany(action, id) {
|
|
|
|
var elems = _rsplit(id, '_', 3);
|
2015-02-06 11:25:29 -06:00
|
|
|
// Get the DOM node corresponding to the Ref field
|
2014-04-03 10:32:57 -05:00
|
|
|
var node = document.getElementById(elems[0] + '_' + elems[1]);
|
|
|
|
// Get the uids of (un-)checked objects.
|
|
|
|
var statuses = node['_appy_' + elems[2] + '_cbs'];
|
2014-07-23 15:29:47 -05:00
|
|
|
var uids = stringFromDictKeys(statuses);
|
2014-04-03 10:32:57 -05:00
|
|
|
// Get the array semantics
|
|
|
|
var semantics = node['_appy_' + elems[2] + '_sem'];
|
2015-02-06 11:25:29 -06:00
|
|
|
// Show an error message if no element is selected
|
2014-04-14 13:55:23 -05:00
|
|
|
if ((semantics == 'checked') && (len(statuses) == 0)) {
|
2014-04-05 03:54:40 -05:00
|
|
|
openPopup('alertPopup', no_elem_selected);
|
|
|
|
return;
|
|
|
|
}
|
2014-04-03 10:32:57 -05:00
|
|
|
// Fill the form and ask for a confirmation
|
2014-04-01 11:34:12 -05:00
|
|
|
f = document.getElementById('linkForm');
|
2014-04-04 09:49:22 -05:00
|
|
|
f.linkAction.value = action + '_many';
|
2014-04-03 10:32:57 -05:00
|
|
|
f.sourceUid.value = elems[0];
|
|
|
|
f.fieldName.value = elems[1];
|
|
|
|
f.targetUid.value = uids;
|
|
|
|
f.semantics.value = semantics;
|
|
|
|
askConfirm('form', 'linkForm', action_confirm);
|
2014-04-01 11:34:12 -05:00
|
|
|
}
|
|
|
|
|
2013-05-22 03:27:31 -05:00
|
|
|
function onUnlockPage(objectUid, pageName) {
|
|
|
|
f = document.getElementById('unlockForm');
|
|
|
|
f.objectUid.value = objectUid;
|
|
|
|
f.pageName.value = pageName;
|
2014-03-24 16:55:00 -05:00
|
|
|
askConfirm('form', 'unlockForm', action_confirm);
|
2013-05-22 03:27:31 -05:00
|
|
|
}
|
|
|
|
|
2011-09-28 14:17:15 -05:00
|
|
|
function createCookie(name, value, days) {
|
|
|
|
if (days) {
|
|
|
|
var date = new Date();
|
|
|
|
date.setTime(date.getTime()+(days*24*60*60*1000));
|
|
|
|
var expires = "; expires="+date.toGMTString();
|
|
|
|
} else expires = "";
|
|
|
|
document.cookie = name+"="+escape(value)+expires+"; path=/;";
|
|
|
|
}
|
|
|
|
|
|
|
|
function readCookie(name) {
|
|
|
|
var nameEQ = name + "=";
|
|
|
|
var ca = document.cookie.split(';');
|
|
|
|
for (var i=0; i < ca.length; i++) {
|
|
|
|
var c = ca[i];
|
|
|
|
while (c.charAt(0)==' ') { c = c.substring(1,c.length); }
|
|
|
|
if (c.indexOf(nameEQ) == 0) {
|
|
|
|
return unescape(c.substring(nameEQ.length,c.length));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-01-26 10:26:05 -06:00
|
|
|
function toggleCookie(cookieId, display, defaultValue) {
|
2011-09-18 08:00:05 -05:00
|
|
|
// What is the state of this boolean (expanded/collapsed) cookie?
|
|
|
|
var state = readCookie(cookieId);
|
|
|
|
if ((state != 'collapsed') && (state != 'expanded')) {
|
2015-01-26 10:26:05 -06:00
|
|
|
// No cookie yet, create it
|
|
|
|
createCookie(cookieId, defaultValue);
|
|
|
|
state = defaultValue;
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
var hook = document.getElementById(cookieId); // The hook is the part of
|
|
|
|
// the HTML document that needs to be shown or hidden.
|
|
|
|
var displayValue = 'none';
|
|
|
|
var newState = 'collapsed';
|
2011-11-25 11:01:20 -06:00
|
|
|
var imgSrc = 'ui/expand.gif';
|
2011-09-18 08:00:05 -05:00
|
|
|
if (state == 'collapsed') {
|
|
|
|
// Show the HTML zone
|
2015-01-26 10:26:05 -06:00
|
|
|
displayValue = display;
|
2011-11-25 11:01:20 -06:00
|
|
|
imgSrc = 'ui/collapse.gif';
|
2011-09-18 08:00:05 -05:00
|
|
|
newState = 'expanded';
|
|
|
|
}
|
|
|
|
// Update the corresponding HTML element
|
|
|
|
hook.style.display = displayValue;
|
|
|
|
var img = document.getElementById(cookieId + '_img');
|
|
|
|
img.src = imgSrc;
|
|
|
|
// Inverse the cookie value
|
|
|
|
createCookie(cookieId, newState);
|
|
|
|
}
|
|
|
|
|
2015-02-10 10:20:50 -06:00
|
|
|
function podDownloadStatus(node, data) {
|
|
|
|
// Checks the status of cookie "podDownload"
|
|
|
|
var status = readCookie('podDownload');
|
|
|
|
// Stop the timeout if the download is complete
|
|
|
|
if (status == 'false') return;
|
|
|
|
clearInterval(podTimeout);
|
|
|
|
for (var key in data) node.setAttribute(key, data[key]);
|
|
|
|
}
|
|
|
|
|
2015-02-06 11:25:29 -06:00
|
|
|
// Function that allows to generate a document from a pod template
|
2015-02-10 10:20:50 -06:00
|
|
|
function generatePod(node, uid, fieldName, template, podFormat, queryData,
|
2014-09-17 11:09:30 -05:00
|
|
|
customParams, getChecked, mailing) {
|
2014-03-24 16:55:00 -05:00
|
|
|
var f = document.getElementById('podForm');
|
|
|
|
f.objectUid.value = uid;
|
|
|
|
f.fieldName.value = fieldName;
|
|
|
|
f.template.value = template;
|
|
|
|
f.podFormat.value = podFormat;
|
|
|
|
f.queryData.value = queryData;
|
|
|
|
if (customParams) { f.customParams.value = customParams; }
|
|
|
|
else { f.customParams.value = ''; }
|
2014-09-17 11:09:30 -05:00
|
|
|
if (mailing) f.mailing.value = mailing;
|
2014-10-16 10:35:35 -05:00
|
|
|
// Transmit value of cookie "showSubTitles"
|
|
|
|
f.showSubTitles.value = readCookie('showSubTitles') || 'true';
|
2014-03-24 16:55:00 -05:00
|
|
|
f.action.value = 'generate';
|
2014-07-10 14:22:52 -05:00
|
|
|
f.checkedUids.value = '';
|
|
|
|
f.checkedSem.value = '';
|
|
|
|
if (getChecked) {
|
2015-02-06 11:25:29 -06:00
|
|
|
// We must collect selected objects from a Ref field
|
2015-02-13 10:29:51 -06:00
|
|
|
var cNode = document.getElementById(uid + '_' + getChecked);
|
|
|
|
if (cNode && cNode.hasOwnProperty('_appy_objs_cbs')) {
|
|
|
|
f.checkedUids.value = stringFromDictKeys(cNode['_appy_objs_cbs']);
|
|
|
|
f.checkedSem.value = cNode['_appy_objs_sem'];
|
2014-07-10 14:22:52 -05:00
|
|
|
}
|
|
|
|
}
|
2015-02-10 10:20:50 -06:00
|
|
|
// Submitting the form at the end blocks the animated gifs on FF
|
2014-03-24 16:55:00 -05:00
|
|
|
f.submit();
|
2015-02-10 10:20:50 -06:00
|
|
|
// If p_node is an image, replace it with a preloader to prevent double-clicks
|
|
|
|
if (node.tagName == 'IMG') {
|
|
|
|
var data = {'src': node.src, 'class': node.className,
|
|
|
|
'onclick': node.attributes.onclick.value};
|
|
|
|
node.setAttribute('onclick', '');
|
|
|
|
node.className = '';
|
|
|
|
var src2 = node.src.replace(podFormat + '.png', 'loadingPod.gif');
|
|
|
|
node.setAttribute('src', src2);
|
|
|
|
// Initialize the pod download cookie. "false" means: not downloaded yet
|
|
|
|
createCookie('podDownload', 'false');
|
|
|
|
// Set a timer that will check the cookie value
|
|
|
|
podTimeout = window.setInterval(function(){
|
|
|
|
podDownloadStatus(node, data)}, 700);
|
|
|
|
}
|
2014-03-24 16:55:00 -05:00
|
|
|
}
|
|
|
|
|
2015-02-06 11:25:29 -06:00
|
|
|
// Function that allows to (un-)freeze a document from a pod template
|
2014-03-24 16:55:00 -05:00
|
|
|
function freezePod(uid, fieldName, template, podFormat, action) {
|
|
|
|
var f = document.getElementById('podForm');
|
|
|
|
f.objectUid.value = uid;
|
|
|
|
f.fieldName.value = fieldName;
|
|
|
|
f.template.value = template;
|
|
|
|
f.podFormat.value = podFormat;
|
|
|
|
f.action.value = action;
|
|
|
|
askConfirm('form', 'podForm', action_confirm);
|
|
|
|
}
|
|
|
|
|
2015-02-06 11:25:29 -06:00
|
|
|
// Function that allows to upload a file for freezing it in a pod field
|
2014-03-24 16:55:00 -05:00
|
|
|
function uploadPod(uid, fieldName, template, podFormat) {
|
|
|
|
var f = document.getElementById('uploadForm');
|
|
|
|
f.objectUid.value = uid;
|
|
|
|
f.fieldName.value = fieldName;
|
|
|
|
f.template.value = template;
|
|
|
|
f.podFormat.value = podFormat;
|
2014-03-25 06:05:07 -05:00
|
|
|
f.uploadedFile.value = null;
|
2014-03-24 16:55:00 -05:00
|
|
|
openPopup('uploadPopup');
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
2013-09-11 15:11:44 -05:00
|
|
|
|
|
|
|
function protectAppyForm() {
|
|
|
|
window.onbeforeunload = function(e){
|
2015-02-04 03:23:40 -06:00
|
|
|
f = document.getElementById("appyForm");
|
|
|
|
if (f.button.value == "") {
|
2013-09-11 15:11:44 -05:00
|
|
|
var e = e || window.event;
|
|
|
|
if (e) {e.returnValue = warn_leave_form;}
|
|
|
|
return warn_leave_form;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
// Functions for opening and closing a popup
|
2015-02-04 11:33:27 -06:00
|
|
|
function openPopup(popupId, msg, width, height, back) {
|
2011-09-18 08:00:05 -05:00
|
|
|
// Put the message into the popup
|
2012-10-03 07:44:34 -05:00
|
|
|
if (msg) {
|
2014-04-05 03:54:40 -05:00
|
|
|
var msgHook = (popupId == 'alertPopup')? 'appyAlertText': 'appyConfirmText';
|
|
|
|
var confirmElem = document.getElementById(msgHook);
|
2012-10-03 07:44:34 -05:00
|
|
|
confirmElem.innerHTML = msg;
|
|
|
|
}
|
2011-09-18 08:00:05 -05:00
|
|
|
// Open the popup
|
|
|
|
var popup = document.getElementById(popupId);
|
2014-07-18 09:54:11 -05:00
|
|
|
// Put it at the right place on the screen and give it the right dimensions
|
2014-04-14 13:55:23 -05:00
|
|
|
var scrollTop = document.documentElement.scrollTop || window.pageYOffset || 0;
|
2011-09-18 08:00:05 -05:00
|
|
|
popup.style.top = (scrollTop + 150) + 'px';
|
2014-06-15 17:58:45 -05:00
|
|
|
if (width) popup.style.width = width + 'px';
|
2014-07-18 09:54:11 -05:00
|
|
|
if (height) popup.style.height = height + 'px';
|
2014-06-15 17:58:45 -05:00
|
|
|
if (popupId == 'iframePopup') {
|
2015-02-04 11:33:27 -06:00
|
|
|
// Initialize iframe's width
|
2014-06-15 17:58:45 -05:00
|
|
|
var iframe = document.getElementById('appyIFrame');
|
2014-07-18 09:54:11 -05:00
|
|
|
if (!width) width = window.innerWidth - 200;
|
|
|
|
if (!height) {
|
|
|
|
height = window.innerHeight - 200;
|
|
|
|
popup.style.top = ((window.innerHeight - height) / 2).toFixed() + 'px';
|
|
|
|
}
|
|
|
|
popup.style.left = ((window.innerWidth - width) / 2).toFixed() + 'px';
|
|
|
|
popup.style.width = width + 'px';
|
2014-06-15 17:58:45 -05:00
|
|
|
iframe.style.width = (width-20) + 'px';
|
2014-07-18 09:54:11 -05:00
|
|
|
popup.style.height = height + 'px';
|
|
|
|
iframe.style.height = (height-20) + 'px';
|
2015-02-04 11:33:27 -06:00
|
|
|
popup['back'] = back;
|
2014-06-15 17:58:45 -05:00
|
|
|
}
|
2014-04-14 13:55:23 -05:00
|
|
|
popup.style.display = 'block';
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2015-02-04 05:23:56 -06:00
|
|
|
function closePopup(popupId, clean) {
|
2014-07-23 15:29:47 -05:00
|
|
|
// Get the popup
|
|
|
|
var container = null;
|
|
|
|
if (popupId == 'iframePopup') container = window.parent.document;
|
|
|
|
else container = window.document;
|
2014-06-15 17:58:45 -05:00
|
|
|
var popup = container.getElementById(popupId);
|
2014-07-23 15:29:47 -05:00
|
|
|
// Close the popup
|
2014-04-14 13:55:23 -05:00
|
|
|
popup.style.display = 'none';
|
2014-06-15 17:58:45 -05:00
|
|
|
popup.style.width = null;
|
2015-02-04 05:23:56 -06:00
|
|
|
// Clean field "clean" if specified
|
|
|
|
if (clean) {
|
|
|
|
var f = popup.getElementsByTagName('form')[0];
|
|
|
|
f.elements[clean].value = '';
|
|
|
|
}
|
2014-06-15 17:58:45 -05:00
|
|
|
if (popupId == 'iframePopup') {
|
2015-02-04 05:23:56 -06:00
|
|
|
// Reinitialise the enclosing iframe
|
2014-06-15 17:58:45 -05:00
|
|
|
var iframe = container.getElementById('appyIFrame');
|
|
|
|
iframe.style.width = null;
|
2015-02-05 07:05:29 -06:00
|
|
|
while (iframe.firstChild) iframe.removeChild(iframe.firstChild);
|
2014-06-15 17:58:45 -05:00
|
|
|
// Leave the form silently if we are on an edit page
|
|
|
|
iframe.contentWindow.onbeforeunload = null;
|
|
|
|
}
|
2015-02-04 11:33:27 -06:00
|
|
|
return popup;
|
2014-06-15 17:58:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function backFromPopup() {
|
2015-02-04 11:33:27 -06:00
|
|
|
var popup = closePopup('iframePopup');
|
|
|
|
if (popup['back']) askAjax(':'+popup['back']);
|
|
|
|
else window.parent.location = window.parent.location;
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2014-11-10 06:34:52 -06:00
|
|
|
function showAppyMessage(message) {
|
|
|
|
// Fill the message zone with the message to display
|
2015-02-05 07:05:29 -06:00
|
|
|
var messageZone = getAjaxHook(':appyMessageContent');
|
2014-11-10 06:34:52 -06:00
|
|
|
messageZone.innerHTML = message;
|
|
|
|
// Display the message zone
|
2015-02-05 07:05:29 -06:00
|
|
|
var messageDiv = getAjaxHook(':appyMessage');
|
2014-11-10 06:34:52 -06:00
|
|
|
messageDiv.style.display = 'block';
|
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
// Function triggered when an action needs to be confirmed by the user
|
2012-03-19 11:00:44 -05:00
|
|
|
function askConfirm(actionType, action, msg, showComment) {
|
2011-09-18 08:00:05 -05:00
|
|
|
/* Store the actionType (send a form, call an URL or call a script) and the
|
|
|
|
related action, and shows the confirm popup. If the user confirms, we
|
2012-03-19 11:00:44 -05:00
|
|
|
will perform the action. If p_showComment is true, an input field allowing
|
|
|
|
to enter a comment will be shown in the popup. */
|
2011-09-18 08:00:05 -05:00
|
|
|
var confirmForm = document.getElementById('confirmActionForm');
|
|
|
|
confirmForm.actionType.value = actionType;
|
|
|
|
confirmForm.action.value = action;
|
2014-08-05 07:53:08 -05:00
|
|
|
if (!msg) msg = action_confirm;
|
2012-03-19 11:00:44 -05:00
|
|
|
var commentArea = document.getElementById('commentArea');
|
2014-06-15 17:58:45 -05:00
|
|
|
if (showComment) commentArea.style.display = 'block';
|
|
|
|
else commentArea.style.display = 'none';
|
2011-09-18 08:00:05 -05:00
|
|
|
openPopup("confirmActionPopup", msg);
|
|
|
|
}
|
|
|
|
|
2015-02-04 03:23:40 -06:00
|
|
|
// Transfer comment from the confirm form to some other form
|
|
|
|
function transferComment(confirmForm, targetForm) {
|
|
|
|
if ((confirmForm.comment.style.display != 'none') &&
|
|
|
|
(confirmForm.comment.value)) {
|
|
|
|
targetForm.comment.value = confirmForm.comment.value;
|
|
|
|
// Clean the confirm form
|
|
|
|
confirmForm.comment.value = '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
// Function triggered when an action confirmed by the user must be performed
|
|
|
|
function doConfirm() {
|
2015-02-04 05:23:56 -06:00
|
|
|
// The user confirmed: perform the required action
|
2011-09-18 08:00:05 -05:00
|
|
|
closePopup('confirmActionPopup');
|
|
|
|
var confirmForm = document.getElementById('confirmActionForm');
|
|
|
|
var actionType = confirmForm.actionType.value;
|
|
|
|
var action = confirmForm.action.value;
|
|
|
|
if (actionType == 'form') {
|
2015-02-04 03:23:40 -06:00
|
|
|
/* Submit the form whose id is in "action", and transmit him the comment
|
2015-02-04 05:23:56 -06:00
|
|
|
from the popup when relevant. */
|
2015-02-04 03:23:40 -06:00
|
|
|
var f = document.getElementById(action);
|
|
|
|
transferComment(confirmForm, f);
|
2015-02-10 10:20:50 -06:00
|
|
|
f.submit(); clickOn(f);
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
2015-02-04 03:23:40 -06:00
|
|
|
else if (actionType == 'url') { goto(action) } // Go to some URL
|
|
|
|
else if (actionType == 'script') { eval(action) } // Exec some JS code
|
2014-06-15 17:58:45 -05:00
|
|
|
else if (actionType == 'form+script') {
|
|
|
|
var elems = action.split('+');
|
2015-02-04 03:23:40 -06:00
|
|
|
var f = document.getElementById(elems[0]);
|
2014-06-15 17:58:45 -05:00
|
|
|
// Submit the form in elems[0] and execute the JS code in elems[1]
|
2015-02-04 03:23:40 -06:00
|
|
|
transferComment(confirmForm, f);
|
2015-02-10 10:20:50 -06:00
|
|
|
f.submit(); clickOn(f);
|
2015-02-04 03:23:40 -06:00
|
|
|
eval(elems[1]);
|
|
|
|
}
|
|
|
|
else if (actionType == 'form-script') {
|
|
|
|
/* Similar to form+script, but the form must not be submitted. It will
|
|
|
|
probably be used by the JS code, so the comment must be transfered. */
|
|
|
|
var elems = action.split('+');
|
|
|
|
var f = document.getElementById(elems[0]);
|
|
|
|
// Submit the form in elems[0] and execute the JS code in elems[1]
|
|
|
|
transferComment(confirmForm, f);
|
2014-06-15 17:58:45 -05:00
|
|
|
eval(elems[1]);
|
|
|
|
}
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
2012-10-03 07:44:34 -05:00
|
|
|
// Function triggered when the user asks password reinitialisation
|
2012-07-09 08:47:38 -05:00
|
|
|
function doAskPasswordReinit() {
|
|
|
|
// Check that the user has typed a login
|
2015-02-04 03:23:40 -06:00
|
|
|
var f = document.getElementById('askPasswordReinitForm');
|
|
|
|
var login = f.login.value.replace(' ', '');
|
|
|
|
if (!login) { f.login.style.background = wrongTextInput; }
|
2012-07-09 08:47:38 -05:00
|
|
|
else {
|
|
|
|
closePopup('askPasswordReinitPopup');
|
2015-02-04 03:23:40 -06:00
|
|
|
f.submit();
|
2012-07-09 08:47:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-18 08:00:05 -05:00
|
|
|
// Function that finally posts the edit form after the user has confirmed that
|
|
|
|
// she really wants to post it.
|
|
|
|
function postConfirmedEditForm() {
|
2015-02-04 03:23:40 -06:00
|
|
|
var f = document.getElementById('appyForm');
|
|
|
|
f.confirmed.value = "True";
|
|
|
|
f.button.value = 'save';
|
|
|
|
f.submit();
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Function that shows or hides a tab. p_action is 'show' or 'hide'.
|
|
|
|
function manageTab(tabId, action) {
|
|
|
|
// Manage the tab content (show it or hide it)
|
|
|
|
var content = document.getElementById('tabcontent_' + tabId);
|
|
|
|
if (action == 'show') { content.style.display = 'table-row'; }
|
|
|
|
else { content.style.display = 'none'; }
|
|
|
|
// Manage the tab itself (show as selected or unselected)
|
|
|
|
var left = document.getElementById('tab_' + tabId + '_left');
|
|
|
|
var tab = document.getElementById('tab_' + tabId);
|
|
|
|
var right = document.getElementById('tab_' + tabId + '_right');
|
|
|
|
if (action == 'show') {
|
2011-11-25 11:01:20 -06:00
|
|
|
left.src = "ui/tabLeft.png";
|
|
|
|
tab.style.backgroundImage = "url(ui/tabBg.png)";
|
|
|
|
right.src = "ui/tabRight.png";
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
if (action == 'hide') {
|
2011-11-25 11:01:20 -06:00
|
|
|
left.src = "ui/tabLeftu.png";
|
|
|
|
tab.style.backgroundImage = "url(ui/tabBgu.png)";
|
|
|
|
right.src = "ui/tabRightu.png";
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function used for displaying/hiding content of a tab
|
|
|
|
function showTab(tabId) {
|
|
|
|
// 1st, show the tab to show
|
|
|
|
manageTab(tabId, 'show');
|
2015-02-10 10:20:50 -06:00
|
|
|
// Compute the number of tabs
|
2011-09-18 08:00:05 -05:00
|
|
|
var idParts = tabId.split('_');
|
|
|
|
var prefix = idParts[0] + '_';
|
2015-02-10 10:20:50 -06:00
|
|
|
// Store the currently selected tab in a cookie
|
2011-09-18 08:00:05 -05:00
|
|
|
createCookie('tab_' + idParts[0], tabId);
|
|
|
|
var nbOfTabs = idParts[2]*1;
|
2015-02-10 10:20:50 -06:00
|
|
|
// Then, hide the other tabs
|
2011-09-18 08:00:05 -05:00
|
|
|
for (var i=0; i<nbOfTabs; i++) {
|
|
|
|
var idTab = prefix + (i+1) + '_' + nbOfTabs;
|
|
|
|
if (idTab != tabId) {
|
|
|
|
manageTab(idTab, 'hide');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function that initializes the state of a tab
|
2014-04-30 08:10:11 -05:00
|
|
|
function initTab(tabsId, defaultValue) {
|
|
|
|
var selectedTabId = readCookie(tabsId);
|
|
|
|
if (!selectedTabId) { showTab(defaultValue) }
|
|
|
|
else {
|
|
|
|
/* Ensure the selected tab exists (it could be absent because of field
|
|
|
|
visibility settings) */
|
|
|
|
var selectedTab = document.getElementById('tab_' + selectedTabId);
|
|
|
|
if (selectedTab) { showTab(selectedTabId) }
|
|
|
|
else { showTab(defaultValue) }
|
|
|
|
}
|
2011-09-18 08:00:05 -05:00
|
|
|
}
|
2011-10-19 02:37:44 -05:00
|
|
|
|
|
|
|
// List-related Javascript functions
|
|
|
|
function updateRowNumber(row, rowIndex, action) {
|
|
|
|
/* Within p_row, we update every field whose name and id include the row index
|
|
|
|
with new p_rowIndex. If p_action is 'set', p_rowIndex becomes the new
|
|
|
|
index. If p_action is 'add', new index becomes:
|
|
|
|
existing index + p_rowIndex. */
|
2012-03-08 13:56:14 -06:00
|
|
|
var tagTypes = ['input', 'select', 'img', 'textarea'];
|
2012-03-01 10:35:23 -06:00
|
|
|
var currentIndex = -1;
|
2011-10-19 02:37:44 -05:00
|
|
|
for (var i=0; i < tagTypes.length; i++) {
|
2012-03-01 10:35:23 -06:00
|
|
|
var widgets = row.getElementsByTagName(tagTypes[i]);
|
2011-10-19 02:37:44 -05:00
|
|
|
for (var j=0; j < widgets.length; j++) {
|
2012-03-01 10:35:23 -06:00
|
|
|
var id = widgets[j].id;
|
|
|
|
if (!id) continue;
|
|
|
|
var name = widgets[j].name;
|
|
|
|
// Extract the suffix if there is one (ie, if the field is a Date part:
|
|
|
|
// _img, _day,...).
|
|
|
|
var iSuffix = id.lastIndexOf('_');
|
|
|
|
var idSuffix = '';
|
|
|
|
if (iSuffix != -1) {
|
|
|
|
idSuffix = id.substring(iSuffix);
|
|
|
|
id = id.substring(0, iSuffix);
|
|
|
|
}
|
|
|
|
var nSuffix = name.lastIndexOf('_');
|
|
|
|
var nameSuffix = '';
|
|
|
|
if (nSuffix != -1) {
|
2012-03-03 16:29:32 -06:00
|
|
|
nameSuffix = name.substring(nSuffix);
|
2012-03-01 10:35:23 -06:00
|
|
|
name = name.substring(0, nSuffix);
|
|
|
|
}
|
|
|
|
// Compute the current row index if not already done.
|
2011-10-19 02:37:44 -05:00
|
|
|
idNbIndex = id.lastIndexOf('*') + 1;
|
|
|
|
nameNbIndex = name.lastIndexOf('*') + 1;
|
|
|
|
if (currentIndex == -1) {
|
|
|
|
currentIndex = parseInt(id.substring(idNbIndex));
|
|
|
|
}
|
|
|
|
// Compute the new values for attributes "id" and "name".
|
|
|
|
newId = id.substring(0, idNbIndex);
|
2012-03-01 10:35:23 -06:00
|
|
|
newName = name.substring(0, nameNbIndex);
|
2011-10-19 02:37:44 -05:00
|
|
|
newIndex = rowIndex;
|
|
|
|
if (action == 'add') newIndex = newIndex + currentIndex;
|
2012-03-01 10:35:23 -06:00
|
|
|
var oldId = widgets[j].id;
|
|
|
|
widgets[j].id = newId + String(newIndex) + idSuffix;
|
|
|
|
if (name) widgets[j].name = newName + String(newIndex) + nameSuffix;
|
|
|
|
/* In the case of an img that must show a calendar, update the script that
|
|
|
|
is triggered when clicking on it. */
|
|
|
|
if ((tagTypes[i] == 'img') && (idSuffix == '_img')) {
|
|
|
|
var scripts = row.getElementsByTagName('script');
|
|
|
|
for (var k=0; k < scripts.length; k++) {
|
|
|
|
var text = scripts[k].text;
|
|
|
|
if (text.indexOf(oldId) != -1) {
|
|
|
|
var oldIdField = oldId.substring(0, oldId.length-4);
|
|
|
|
var newIdField = widgets[j].id.substring(0, widgets[j].id.length-4);
|
|
|
|
text = text.replace(oldIdField, newIdField);
|
|
|
|
scripts[k].text = text.replace(oldId, widgets[j].id);
|
|
|
|
eval(scripts[k].text);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-19 02:37:44 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function insertRow(tableId) {
|
|
|
|
// This function adds a new row in table with ID p_tableId.
|
|
|
|
table = document.getElementById(tableId);
|
|
|
|
newRow = table.rows[1].cloneNode(true);
|
|
|
|
newRow.style.display = 'table-row';
|
2012-03-01 10:35:23 -06:00
|
|
|
// Within newRow, incorporate the row number within field names and ids.
|
2011-10-19 02:37:44 -05:00
|
|
|
table.tBodies[0].appendChild(newRow);
|
2012-03-01 10:35:23 -06:00
|
|
|
updateRowNumber(newRow, table.rows.length-4, 'set');
|
2011-10-19 02:37:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function deleteRow(tableId, deleteImg) {
|
|
|
|
row = deleteImg.parentNode.parentNode;
|
|
|
|
table = document.getElementById(tableId);
|
|
|
|
allRows = table.rows;
|
|
|
|
toDeleteIndex = -1; // Will hold the index of the row to delete.
|
|
|
|
for (var i=0; i < allRows.length; i++) {
|
|
|
|
if (toDeleteIndex == -1) {
|
|
|
|
if (row == allRows[i]) toDeleteIndex = i;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Decrement higher row numbers by 1 because of the deletion
|
|
|
|
updateRowNumber(allRows[i], -1, 'add');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
table.deleteRow(toDeleteIndex);
|
|
|
|
}
|
2012-01-02 09:59:11 -06:00
|
|
|
|
|
|
|
function onSelectDate(cal) {
|
|
|
|
var p = cal.params;
|
|
|
|
var update = (cal.dateClicked || p.electric);
|
|
|
|
if (update && p.inputField) {
|
|
|
|
var fieldName = cal.params.inputField.id;
|
|
|
|
// Update day
|
|
|
|
var dayValue = cal.date.getDate() + '';
|
|
|
|
if (dayValue.length == 1) dayValue = '0' + dayValue;
|
|
|
|
document.getElementById(fieldName + '_day').value = dayValue;
|
|
|
|
// Update month
|
|
|
|
var monthValue = (cal.date.getMonth() + 1) + '';
|
|
|
|
if (monthValue.length == 1) monthValue = '0' + monthValue;
|
|
|
|
document.getElementById(fieldName + '_month').value = monthValue;
|
|
|
|
// Update year
|
|
|
|
var year = document.getElementById(fieldName + '_year');
|
|
|
|
if (!year) {
|
|
|
|
// On the search screen, the 'from year' field has a special name.
|
|
|
|
var yearId = 'w_' + fieldName.split('_')[0] + '*date';
|
|
|
|
year = document.getElementById(yearId);
|
|
|
|
}
|
|
|
|
year.value = cal.date.getFullYear() + '';
|
|
|
|
}
|
|
|
|
if (update && p.singleClick && cal.dateClicked) {
|
|
|
|
cal.callCloseHandler();
|
|
|
|
}
|
2014-06-15 17:58:45 -05:00
|
|
|
}
|
2014-07-23 15:29:47 -05:00
|
|
|
|
2014-07-28 05:29:16 -05:00
|
|
|
function onSelectObjects(nodeId, objectUrl, mode, sortKey, sortOrder,
|
2014-07-23 15:29:47 -05:00
|
|
|
filterKey, filterValue){
|
|
|
|
/* Objects have been selected in a popup, to be linked via a Ref with
|
|
|
|
link='popup'. Get them. */
|
|
|
|
var node = document.getElementById(nodeId);
|
|
|
|
var uids = stringFromDictKeys(node['_appy_objs_cbs']);
|
|
|
|
var semantics = node['_appy_objs_sem'];
|
2015-02-05 07:05:29 -06:00
|
|
|
// Show an error message if no element is selected
|
2014-07-23 15:29:47 -05:00
|
|
|
if ((semantics == 'checked') && (!uids)) {
|
|
|
|
openPopup('alertPopup', no_elem_selected);
|
|
|
|
return;
|
|
|
|
}
|
2015-02-05 07:05:29 -06:00
|
|
|
// Close the popup
|
2014-07-23 15:29:47 -05:00
|
|
|
closePopup('iframePopup');
|
2014-07-28 05:29:16 -05:00
|
|
|
/* When refreshing the Ref field we will need to pass all those parameters,
|
|
|
|
for replaying the popup query. */
|
|
|
|
var params = {'selected': uids, 'semantics': semantics, 'sortKey': sortKey,
|
|
|
|
'sortOrder': sortOrder, 'filterKey': filterKey,
|
|
|
|
'filterValue': filterValue};
|
|
|
|
if (mode == 'repl') {
|
|
|
|
/* Link the selected objects (and unlink the potentially already linked
|
|
|
|
ones) and refresh the Ref edit widget. */
|
2014-08-05 02:48:05 -05:00
|
|
|
askField(':'+nodeId, objectUrl, 'edit', params, false);
|
2014-07-28 05:29:16 -05:00
|
|
|
}
|
|
|
|
else {
|
2015-02-05 07:05:29 -06:00
|
|
|
// Link the selected objects and refresh the Ref view widget
|
2014-07-28 05:29:16 -05:00
|
|
|
params['action'] = 'onSelectFromPopup';
|
2014-08-05 02:48:05 -05:00
|
|
|
askField(':'+nodeId, objectUrl, 'view', params, false);
|
2014-07-28 05:29:16 -05:00
|
|
|
}
|
2014-07-23 15:29:47 -05:00
|
|
|
}
|
|
|
|
|
2014-07-25 08:07:31 -05:00
|
|
|
function onSelectObject(tdId, nodeId, objectUrl) {
|
|
|
|
/* In a Ref field with link="popup", a single object has been clicked. If
|
|
|
|
multiple objects can be selected, simply update the corresponding checkbox
|
|
|
|
status. Else, close the popup and return the selected object. p_tdId is
|
|
|
|
the ID of the td that contains the checkbox. */
|
|
|
|
var td = document.getElementById(tdId);
|
|
|
|
// If the td is visible, simply click the checkbox.
|
|
|
|
var checkbox = td.getElementsByTagName('input')[0];
|
|
|
|
if (td.style.display == 'table-cell') { checkbox.click(); }
|
|
|
|
else {
|
|
|
|
/* Close the popup and directly refresh the initiator field with the
|
|
|
|
selected object. */
|
2014-08-05 02:48:05 -05:00
|
|
|
var uids = checkbox.value;
|
2014-07-25 08:07:31 -05:00
|
|
|
closePopup('iframePopup');
|
2014-08-05 02:48:05 -05:00
|
|
|
var params = {'selected': uids, 'semantics': 'checked'};
|
|
|
|
askField(':'+nodeId, objectUrl, 'edit', params, false);
|
2014-07-25 08:07:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-23 15:29:47 -05:00
|
|
|
// Sets the focus on the correct element in some page.
|
|
|
|
function initFocus(pageId){
|
|
|
|
var id = pageId + '_title';
|
|
|
|
var elem = document.getElementById(id);
|
|
|
|
if (elem) elem.focus();
|
|
|
|
}
|
2014-12-19 04:21:43 -06:00
|
|
|
|
|
|
|
function reindexObject(indexName){
|
|
|
|
var f = document.forms['reindexForm'];
|
|
|
|
f.indexName.value = indexName;
|
|
|
|
f.submit();
|
|
|
|
}
|
2014-12-29 08:55:17 -06:00
|
|
|
|
|
|
|
// Live-search-related functions (LS)
|
|
|
|
function detectEventType(event) {
|
|
|
|
/* After p_event occurred on a live search input field, must we trigger a
|
|
|
|
search (a new char has been added), move up/down within the search
|
|
|
|
results (key up/down has been pressed) or hide the dropdown (escape)? */
|
|
|
|
if (event.type == 'focus') return 'search'
|
|
|
|
switch (event.keyCode) {
|
|
|
|
case 38: return 'up';
|
|
|
|
case 40: return 'down';
|
|
|
|
case 27: return 'hide'; // escape
|
|
|
|
case 13: return 'go'; // cr
|
|
|
|
case 37: break; // left
|
|
|
|
case 39: break; // right
|
|
|
|
default: return 'search';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Function that selects the search result within the dropdown, after the user
|
|
|
|
has pressed the 'up' od 'down' key (p_direction). */
|
|
|
|
function selectLSResult(dropdown, direction){
|
|
|
|
var results = dropdown.children[0].getElementsByTagName('div');
|
|
|
|
if (results.length == 0) return;
|
|
|
|
var j; // The index of the new element to select
|
|
|
|
for (var i=0, len=results.length; i<len; i++) {
|
|
|
|
if (results[i].className == 'lsSelected') {
|
|
|
|
if (direction == 'up') {
|
|
|
|
if (i > 0) j = i-1;
|
|
|
|
else j = len-1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (i < (len-1)) j = i+1;
|
|
|
|
else j = 0;
|
|
|
|
}
|
|
|
|
results[i].className = '';
|
|
|
|
results[j].className = 'lsSelected';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isNaN(j)) results[0].className = 'lsSelected';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function that allows to go to a selected search result
|
|
|
|
function gotoLSLink(dropdown) {
|
|
|
|
var results = dropdown.children[0].getElementsByTagName('div');
|
|
|
|
for (var i=0, len=results.length; i<len; i++) {
|
|
|
|
if (results[i].className == 'lsSelected') {
|
|
|
|
var a = results[i].children[0];
|
|
|
|
if (a.href) window.location = a.href;
|
|
|
|
else eval(a.onclick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideLSDropdown(dropdown, timeout) {
|
|
|
|
if (dropdown.style.display == 'none') return;
|
|
|
|
if (!timeout) { dropdown.style.display = 'none'; return; }
|
|
|
|
lsTimeout = setTimeout(function(){
|
|
|
|
dropdown.style.display = 'none';}, 400);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function that manages an p_event that occurred on a live search input field
|
|
|
|
function onLiveSearchEvent(event, klass, action, toolUrl) {
|
|
|
|
var dropdown = document.getElementById(klass + '_LSDropdown');
|
|
|
|
if (lsTimeout) clearTimeout(lsTimeout);
|
|
|
|
// Hide the dropdown if action is forced to 'hide'
|
|
|
|
if (action == 'hide') { hideLSDropdown(dropdown, true); return; }
|
|
|
|
// Detect if the dropdown must be shown or hidden
|
|
|
|
var input = document.getElementById(klass + '_LSinput');
|
|
|
|
if (input.value.length > 2) {
|
|
|
|
var eventType = detectEventType(event);
|
|
|
|
if (!eventType) return;
|
|
|
|
if (eventType == 'hide') { hideLSDropdown(dropdown, false); return;}
|
|
|
|
if (eventType == 'go') { gotoLSLink(dropdown); return; }
|
|
|
|
if (eventType == 'search') {
|
|
|
|
// Trigger an Ajax search and refresh the dropdown content
|
|
|
|
var formElems = document.getElementById(klass + '_LSForm').elements;
|
|
|
|
var params = {};
|
|
|
|
for (var i=0, len=formElems.length; i<len; i++) {
|
|
|
|
var param = formElems.item(i);
|
|
|
|
var paramName = formElems.item(i).name;
|
|
|
|
if (param.name == 'action') continue;
|
|
|
|
params[param.name] = param.value;
|
|
|
|
}
|
|
|
|
lsTimeout = setTimeout(function() {
|
|
|
|
askAjaxChunk(klass+ '_LSResults', 'GET', toolUrl, 'pxLiveSearchResults',
|
|
|
|
params);
|
|
|
|
dropdown.style.display = 'block';}, 400);
|
|
|
|
}
|
|
|
|
else { selectLSResult(dropdown, eventType);} // Move up/down in results
|
|
|
|
}
|
|
|
|
else { hideLSDropdown(dropdown, true); }
|
|
|
|
}
|