/*
 
Copyright 2009 Palm, Inc.  All rights reserved.

*/

var ErrorDashboardAssistant = Class.create({
	
	initialize: function(details) {
		this.details = details;
		this.details.accountDomain =  details.accountDomain || 'alert';
	},

	setup: function() {
		this.updateDashboard(this.details);
		this.dashboardTapHandler = this.tapHandler.bindAsEventListener(this);
		this.controller.sceneElement.observe(Mojo.Event.tap, this.dashboardTapHandler);
	},

	cleanup: function() {
		this.controller.sceneElement.stopObserving(Mojo.Event.tap, this.dashboardTapHandler);
		// turn off throbber
		Mojo.Log.info('Turning off throbber');
		this.controller.stageController.indicateNewContent(false);
	},

	tapHandler: function(event) {
		if (this.details.commandFunc !== undefined) {
			this.details.commandFunc();
		}
		Mojo.Controller.getAppController().closeStage(this.details.stageName);
	},
	
	updateDashboard: function(details) {
		switch (details.type) {
			case "SyncLoginException":
				// turn on throbber
				this.controller.stageController.indicateNewContent(true);
				break;
		}
		
		var content = Mojo.View.render({object: details,
										template: 'error-dashboard/error-details'
										});
		this.controller.sceneElement.update(content);
	},

});
