Author: eallen
Date: 2009-03-30 18:22:08 -0400 (Mon, 30 Mar 2009)
New Revision: 3241
Modified:
mgmt/trunk/cumin/python/cumin/visualizations.strings
mgmt/trunk/cumin/python/cumin/widgets.py
mgmt/trunk/wooly/resources/wooly.js
Log:
Consolidating update functions into two functions:
backgroundUpdate: single request returns objectified xml
intervalUpdate: recurring request returns responseXML
Modified: mgmt/trunk/cumin/python/cumin/visualizations.strings
===================================================================
--- mgmt/trunk/cumin/python/cumin/visualizations.strings 2009-03-30 21:49:02 UTC (rev
3240)
+++ mgmt/trunk/cumin/python/cumin/visualizations.strings 2009-03-30 22:22:08 UTC (rev
3241)
@@ -568,7 +568,7 @@
var branch = wooly.session.branch(slot_info_url);
branch.session[slot_info_index] = index;
var newreq = branch.marshal();
- wooly.directUpdate(newreq, got_slot_info, 0, {index: index});
+ wooly.setIntervalUpdate(newreq, got_slot_info, 0, {index: index});
}
function got_slot_info(xhtml, args) {
Modified: mgmt/trunk/cumin/python/cumin/widgets.py
===================================================================
--- mgmt/trunk/cumin/python/cumin/widgets.py 2009-03-30 21:49:02 UTC (rev 3240)
+++ mgmt/trunk/cumin/python/cumin/widgets.py 2009-03-30 22:22:08 UTC (rev 3241)
@@ -1145,7 +1145,7 @@
<script type="text/javascript">
window.addEvent('domready', function get_%s() {
var now = new Date();
- wooly.deferredUpdate('%s'+';ts='+now.getTime(), got_%s,
"%s");
+ wooly.backgroundUpdate('%s'+';ts='+now.getTime(), got_%s,
"%s");
});
</script>
"""
Modified: mgmt/trunk/wooly/resources/wooly.js
===================================================================
--- mgmt/trunk/wooly/resources/wooly.js 2009-03-30 21:49:02 UTC (rev 3240)
+++ mgmt/trunk/wooly/resources/wooly.js 2009-03-30 22:22:08 UTC (rev 3241)
@@ -322,38 +322,9 @@
}
}
- // pass the responseXML directly back to function
-
- this.directUpdate = function(url, callback, interval, passback) {
+ this.backgroundUpdate = function(url, callback, passback) {
var req = this.getNewRequest();
- function fetch() {
- req.open("get", url, true);
- req.onreadystatechange = update;
- req.send(null);
- }
-
- if (interval > 0) {
- var id = window.setInterval(fetch, interval);
- this.updater_ids.push(id);
- }
- fetch(); // send request immediately
-
- function update() {
- try {
- if (req.readyState == 4 && req.status == 200) {
- callback(req.responseXML, passback);
- }
- } catch (e) {
- log(e);
- throw e;
- }
- }
- }
-
- this.deferredUpdate = function(url, callback, passback) {
- var req = this.getNewRequest();
-
req.open("get", url, true);
req.onreadystatechange = update;
req.send(null);
@@ -379,15 +350,9 @@
interval: 0
};
- this.setIntervalUpdate = function(url, callback, interval) {
+ this.setIntervalUpdate = function(url, callback, interval, passback) {
var req = this.getNewRequest();
- // save the arguments in case we need to modify the url
- // and restart the interval
- this.intervalUpdateInfo.url = url;
- this.intervalUpdateInfo.callback = callback;
- this.intervalUpdateInfo.interval = interval;
-
function fetch() {
req.open("get", url, true);
req.onreadystatechange = update;
@@ -396,14 +361,22 @@
fetch();
- var id = window.setInterval(fetch, interval);
- this.intervalUpdateInfo.timerId = id;
- this.updaterIDs.push(id);
+ if (interval > 0) {
+ var id = window.setInterval(fetch, interval);
+ this.updaterIDs.push(id);
+ // save the arguments in case we need to modify the url
+ // and restart the interval
+ this.intervalUpdateInfo.timerId = id;
+ this.intervalUpdateInfo.url = url;
+ this.intervalUpdateInfo.callback = callback;
+ this.intervalUpdateInfo.interval = interval;
+ }
+
function update() {
try {
if (req.readyState == 4 && req.status == 200) {
- callback(req.responseXML);
+ callback(req.responseXML, passback);
}
} catch (e) {
log(e);