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

var PoweroffalertAssistant = Class.create({
	
	initialize: function(sceneAssistant) {
		Mojo.Log.info("------------- power off initialize --------------");
		this.sceneAssistant = sceneAssistant;
		this.controller = sceneAssistant.controller;
	},
	
	setup : function(widget) {
		this.widget = widget;
		this.controller.get('poweroff').addEventListener(Mojo.Event.tap, this.powerOff.bindAsEventListener(this));
		this.controller.get('cancel').addEventListener(Mojo.Event.tap, this.doClose.bindAsEventListener(this));
	},
	
	doClose: function() {
		this.widget.mojo.close();
	},
	
	powerOff:function() {	
		Mojo.Log.info("------------- power off --------------");
		this.powerOffRequest = AppAssistant.accountService.powerDown(this.successPowerDown.bind(this),
									this.errorPowerDown.bind(this), "PowerOff Selected by User in PowerOff dialog");
	},
	
	successPowerDown: function (response) {
		Mojo.Log.info("------------- power off success --------------%j", response);
		this.animationRequest = AppAssistant.accountService.runProgressAnimation();
	},
	
	errorPowerDown: function (response) {
		Mojo.Log.error("----------- Could not power down the device %j ", response);
		this.doClose();
	}
	
	
});
