This repository has been archived by the owner on Jun 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FieldUpdater.js
69 lines (64 loc) · 2.56 KB
/
FieldUpdater.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
function FieldUpdater(targetClass, url, waitImage, sessionid, queryid) {
this.targetClass = targetClass;
this.url = url;
this.waitImage = waitImage;
this.sessionid = sessionid;
this.queryid = queryid;
this.debug = false; // for this to work: include debug.js
}
FieldUpdater.prototype = {
updateAll: function() {
var els = document.getElementsByClassName(this.targetClass);
var waitIndicator = '';
if (this.waitImage != null) {
waitIndicator = '<img src="'+this.waitImage+'" />';
}
var params = 'PHPSESSID='+this.sessionid+'&queryid='+this.queryid;
var collection = new Array();
els.each( function(field) {
if (this.waitImage != null) {
Element.update(field, waitIndicator);
}
collection = field.id.split('_');
params += "&collectionid="+collection[1];
this.updateFieldFromServer(field, params);
}.bind(this));
},
setDebug: function(boolVal) {
this.debug = boolVal;
},
updateFieldFromServer: function(field, params) {
var updater = new Ajax.Updater(
{success: field.id},
this.url,
{
method: 'get',
parameters: params,
onFailure: function (xhr, response){ this.ajaxUpdateFailure(field.id, xhr, response);}.bind(this),
onException: function (xhr, exception){ this.ajaxUpdateException(field.id, xhr, exception);}.bind(this)
});
return updater;
},
ajaxUpdateFailure: function(elementId, xhr, response) {
// update the field with a failure message ...
Element.update(elementId, "? (failed)");
if (this.debug) {
var info = 'function: ajaxUpdateFailure<br/>'
+ toString($(elementId), elementId, 1)
+ toString(xhr, 'xhr', 1)
+ toString(response, 'response', 1)
showInfo(info);
}
},
ajaxUpdateException: function(elementId, xhr, exception) {
// update the field with a failure message ...
Element.update(elementId, "? (failed:exception)");
if (this.debug) {
var info = 'function: ajaxUpdateException<br/>'
+ toString($(elementId), elementId, 1)
+ toString(xhr, 'xhr', 1)
+ toString(exception, 'exception', 1)
showInfo(info);
}
}
}