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

/** 
 * This assistant must be refactored to use WaitAssistant to do the login
 */

var ChangepasswordsuccessAssistant = Class.create({
	initialize: function(){
		this.packageURLArray = [];
		FirstUseUtil.addDashboardSmall($('target'));
	},
	
	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));			
		
		this.buttonAttr = {
			disabledProperty: 'disabled'
		};
		
		this.buttonModel = {
			disabled: false,
			buttonLabel : $L('Next'),
			buttonClass: 'palm-button'
		};
		
		this.controller.setupWidget('next', this.buttonAttr, this.buttonModel);
		Mojo.listen(this.controller.get('next'), Mojo.Event.tap, this.checkData.bindAsEventListener(this));
		this.urlRequest = AppAssistant.appCatalogService.getServerUrl();
	},
	
	
	
	activate: function() {
		
	},
	
	handleCommand: function (event) {
		if (event.type == Mojo.Event.back) {
			Mojo.Log.info("------- Blocking back ----------");
			event.preventDefault();
			event.stopPropagation();
		}
	},
	
	checkData: function() {
		if(RoamUtil.enableRoaming() === true) {
			RoamGuardDialog.turnOffRoamguard(
			{
				"sceneController": this.controller,
				"method": this.continueToCheckData.bind(this)
			});
			return;
		}
		this.continueToCheckData();
	},
	
	continueToCheckData: function () {
		this.buttonModel.disabled = true;
		this.controller.modelChanged(this.buttonModel);
		Account.action = "restore";
		saveCurrentState("wait");
		Mojo.Controller.stageController.swapScene("wait");
		//AppAssistant.accountService.isDataAvailable(this.checkIfDataAvailable.bind(this), this.getDevicesFailure.bind(this), this.controller);
	}
});	
	
	