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

/**
 * A network dialog assistant for display of current network status.
 */
NetworkDialogAssistant = Class.create({
	
	initialize: function(params) {
		this.onDismiss = params.onDismiss;
		this.controller= params.sceneAssistant.controller;
		
		// Button handlers.
		this.onDismissHandler = this.handleDismiss.bindAsEventListener(this);
	},
	
	setup: function(widget) {
		this.widget = widget;
		this.controller.get('dismissButton').addEventListener(Mojo.Event.tap, this.onDismissHandler);
		this.controller.get('dismissButton').focus();
	},
	
	handleDismiss: function() {
		this.onDismiss();
		delete this.onDismiss;
		this.widget.mojo.close();
	},
	
	cleanup: function() {
		Mojo.Log.info("NetworkDialogAssistant#cleanup()");
		Mojo.Event.stopListening(this.controller.get('dismissButton'), Mojo.Event.tap, this.onDismissHandler);
		
		// Send a dismiss if NOT already sent a response
		if (this.onDismiss) {
			this.onDismiss();
		}	
	}
});
