function initController() { YAHOO.buzzWatch.controller = new BuzzWatchController(); } function BuzzWatchController () { this.callback = { success: this.handleSuccess, failure: this.handleFailure, scope: this }; this.saveCallback = { success: this.handleSaveSuccess, failure: this.handleFailure, scope: this }; this.callbackList = { success: this.handleListSuccess, failure: this.handleListFailure, scope: this }; YAHOO.util.Event.addListener( "menubar.file.save", "click", this.save, this, true); YAHOO.util.Event.addListener( "menubar.file.new", "click", this._new, this, true); YAHOO.buzzWatch.menuGo.cfg.getProperty("submenu").show(); this.loadList(); } BuzzWatchController.prototype.loadList = function() { YAHOO.util.Connect.asyncRequest('GET', "watch.php", this.callbackList); } BuzzWatchController.prototype.load = function(symbol) { if (symbol != undefined) this.symbol = symbol; if (this.symbol != undefined) { YAHOO.util.Connect.asyncRequest('GET', "watch.php?name="+this.symbol, this.callback); } } BuzzWatchController.prototype.loadSymbol = function(e, o, symbol) { YAHOO.buzzWatch.menuGo.cfg.getProperty("submenu").hide(); YAHOO.buzzWatch.controller.load(symbol); } BuzzWatchController.prototype.handleSuccess = function(o) { if(o.responseText !== undefined){ var xotree = new XML.ObjTree(); var tree = xotree.parseDOM( o.responseXML.documentElement ); YAHOO.buzzWatch.config.set(tree.watch.symbol, tree.watch.tag); refreshPanels(); YAHOO.buzzWatch.editInPlace.set('textTitle', tree.watch.title); YAHOO.buzzWatch.editInPlace.set('textDescription', tree.watch.description); } } BuzzWatchController.prototype.handleListSuccess = function(o) { if(o.responseText !== undefined){ this.setTimeout(getMaxAge(o)); var xotree = new XML.ObjTree(); xotree.force_array = ["watch"]; var tree = xotree.parseDOM( o.responseXML.documentElement ); var menu = YAHOO.buzzWatch.menuGo.cfg.getProperty("submenu"); while (menu.getItemGroups().length > 0) { var menuItem = menu.removeItem(0); menuItem.destroy(); } var watches = tree.watches.watch; for (var i=0; i< watches.length; i++) { var watch = watches[i]; var menuItem = new YAHOO.widget.MenuItem( watch.title + ' (' + watch.symbol+')', {} ); menu.addItem(menuItem); menuItem.clickEvent.subscribe( this.loadSymbol, watch.symbol, false ); } menu.render(); } } BuzzWatchController.prototype.handleSaveSuccess = function(o) { alert ("saved"); } BuzzWatchController.prototype.handleFailure = function(o) { alert("failure"); } BuzzWatchController.prototype.handleListFailure = function(o) { this.setTimeout(30); alert("failure"); } BuzzWatchController.prototype.clearTimeout = function() { if (this.timeout!=undefined) { clearTimeout(this.timer); this.timeout = undefined; } //alert ("clearing timeout controller"); } BuzzWatchController.prototype.setTimeout = function(duration) { this.clearTimeout; duration = Number(duration); if (duration) this.period = duration; if (this.period == undefined) this.period = 60; this.timeout = setTimeout('YAHOO.buzzWatch.controller.loadList()' , this.period * 1000); //alert ("seting timeout controller to "+ this.period); } BuzzWatchController.prototype.save = function() { var xotree = new XML.ObjTree(); var tree = { watch: { symbol: YAHOO.buzzWatch.config.symbol, tag: YAHOO.buzzWatch.config.tag, title: YAHOO.buzzWatch.editInPlace.get('textTitle'), description: YAHOO.buzzWatch.editInPlace.get('textDescription') } }; alert("save: " + xotree.writeXML(tree)); var o = YAHOO.util.Connect.getConnectionObject(); o.conn.open("POST", "watch.php", true); YAHOO.util.Connect.initHeader('Content-Type','application/xml'); YAHOO.util.Connect.setHeader(o); YAHOO.util.Connect.handleReadyState(o, this.saveCallback); o.conn.send(xotree.writeXML(tree)); } BuzzWatchController.prototype._new = function() { YAHOO.buzzWatch.editInPlace.set('textTitle', "[title]"); YAHOO.buzzWatch.editInPlace.set('textDescription', "[description]"); YAHOO.buzzWatch.config.set("", ""); YAHOO.buzzWatch.config.displayConfig(); }