[Repoze-checkins] r1158 - repoze.debug/trunk/repoze/debug/static
Paul Everitt
paul at agendaless.com
Sat Jun 28 11:28:23 EDT 2008
Author: Paul Everitt <paul at agendaless.com>
Date: Sat Jun 28 11:28:22 2008
New Revision: 1158
Log:
We need to preserve state in the 'model', so refactor JS into using a class/prototype thingy
Modified:
repoze.debug/trunk/repoze/debug/static/debugui-xul.js
Modified: repoze.debug/trunk/repoze/debug/static/debugui-xul.js
==============================================================================
--- repoze.debug/trunk/repoze/debug/static/debugui-xul.js (original)
+++ repoze.debug/trunk/repoze/debug/static/debugui-xul.js Sat Jun 28 11:28:22 2008
@@ -1,21 +1,55 @@
-var url = "../feed.xml";
-var treeid = "xui-logtree";
-var processor;
-var atomdoc;
+var gm;
-function asxml (node) {
- return new XMLSerializer().serializeToString(node);
+function GuiModel (treeid, atomurl) {
+ this.treeid = treeid;
+ this.atomurl = atomurl;
+ this.tree = document.getElementById(treeid);
+ this.processor = null;
+ this.atomdoc = null;
}
+GuiModel.prototype.tostring = function (node) {
+ /* Dump a document or node to a string representation */
+
+ var s = new XMLSerializer();
+ return s.serializeToString(node);
+}
+
+
+GuiModel.prototype.loadURL = function (url) {
+ /* Synchronously load some XML, return the document element */
-function geturl(url) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, false);
- xmlhttp.send('');
+ xmlhttp.send('');
return xmlhttp.responseXML;
}
+GuiModel.prototype.loadProcessor = function (xslurl) {
+ /* Load the XSLT that massages Atom-data into XML datasources */
+
+ this.xsldoc = this.loadURL(xslurl);
+ this.processor = new XSLTProcessor();
+ this.processor.importStylesheet(this.xsldoc);
+}
+
+
+GuiModel.prototype.reloadModel = function () {
+ /* Fetch the atom data, then update various trees */
+
+ // Grab the target, which is the document element on the tree
+ var target = this.tree.builder.datasource.documentElement;
+
+ // Get new data, transform it, and import into the document
+ var atomdoc = this.loadURL(this.atomurl);
+ var result = this.processor.transformToDocument(atomdoc);
+ var iresult = document.importNode(result.documentElement, true);
+
+ // Update the tree datasource and rebuild
+ Sarissa.moveChildNodes(iresult, target);
+ this.tree.builder.rebuild();
+}
function documentLoaded (e) {
var tree = document.getElementById(treeid);
@@ -26,6 +60,26 @@
tree.view.toggleOpenState(0);
}
+
+function initGuiModel () {
+ if (window.location.host.indexOf(":") == -1){
+ // Running from FS, not dynamicall via WSGI, use dummy data
+ var atom_url = "samplefeed.xml";
+ } else {
+ var atom_url = "../feed.xml";
+ }
+ gm = new GuiModel("xui-logtree", atom_url);
+ gm.loadProcessor("debugui-xul.xsl");
+ gm.reloadModel();
+ return;
+ var xsldoc = geturl("debugui-xul.xsl");
+ processor = new XSLTProcessor();
+ processor.importStylesheet(xsldoc);
+}
+
+document.addEventListener("DOMContentLoaded", initGuiModel, false);
+
+
function selectEntry () {
var tree = document.getElementById(treeid);
var item = tree.view.getItemAtIndex(tree.currentIndex);
@@ -38,27 +92,3 @@
}
}
-
-function reloadSummary () {
- /* Transform to make XUL trees with XML datasources easier */
-
- // Grab the target, which is the document element on the tree
- var tree = document.getElementById(treeid);
- var target = tree.builder.datasource.documentElement;
-
- // Get new data, transform it, and import into the document
- var result = processor.transformToDocument(geturl("samplefeed.xml"));
- var iresult = document.importNode(result.documentElement, true);
-
- // Update the tree datasource and rebuild
- Sarissa.moveChildNodes(iresult, target);
- tree.builder.rebuild();
-}
-
-function init () {
- var xsldoc = geturl("debugui-xul.xsl");
- processor = new XSLTProcessor();
- processor.importStylesheet(xsldoc);
-}
-
-document.addEventListener("DOMContentLoaded", init, false);
More information about the Repoze-checkins
mailing list