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

var OtaspErrorAssistant = Class.create({
	
	initialize: function(messages) {
		this.messages = messages;
		FirstUseUtil.addDashboardBig($('target'));
	},
	
	handleCommand: function(event) {
		if (event.type == Mojo.Event.back) {
			this.goBack();
		}	
	},
	
	goBack: function () {
		Mojo.Controller.stageController.popScene('error');
	},	
	
	setup: function(){
		
		$('target').addEventListener(Mojo.Event.tap, FirstUseUtil.tapHandler.bindAsEventListener(this));
				
		// Listen to ## key presses
		this.controller.listen(this.controller.sceneElement, Mojo.Event.keydown, FirstUseUtil.handleKeyPressEvent.bind(this));
		
		// Set up the attributes & model for this widget:
    	this.errorModel = {listTemplateAttr: {listTitle:''}, items:this.messages};    
    	this.controller.setupWidget('errorList', 
                  {itemTemplate:'otasp-error/error-message', listTemplate:'otasp-error/error-container'},
                  this.errorModel);
    			
		this.nextModel = {
			buttonLabel : $L('Try again'),
			buttonClass: 'palm-button'
		};
		this.controller.setupWidget('startActivation', undefined, this.nextModel);
		Mojo.listen(this.controller.get('startActivation'), Mojo.Event.tap, this.startActivation.bindAsEventListener(this));
		
		this.nextModel = {
			buttonLabel : $L('Back'),
			buttonClass: 'palm-button'
		};
		this.controller.setupWidget('goBack', undefined, this.nextModel);
		Mojo.listen(this.controller.get('goBack'), Mojo.Event.tap, this.goBack.bindAsEventListener(this));
			
	},
	
	startActivation: function (event) {
		Mojo.Controller.stageController.swapScene('otasp-intro');
	}
	
});	