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

//<Reminder Info>
var ContactreminderDashboardAssistant = Class.create({
	initialize: function(dashboardData, personId, stageName) {
		Mojo.Log.info('ContactReminderAssistant.initialize()');
		this.dashboardData = dashboardData; // hold onto a reference to the dashboardData
		this.personId = personId;
		this.stageName = stageName;
		this.tapHandler = this.tapHandler.bind(this);
	},
	
	setup: function() {
		Mojo.Log.info('ConctReminderAssistant.setup()');
		this.update();
		this.reminderInfoElement = this.controller.get('reminder_info');
		this.controller.sceneElement.observe(Mojo.Event.tap, this.tapHandler);
	},
	
	cleanup: function() {
		this.controller.sceneElement.stopObserving(Mojo.Event.tap, this.tapHandler);
	},
	
	update: function() {
		if(!this.dashboardData && !this.dashboardData[this.personId] && this.dashboardData[this.personId].record)
			return;
			
		Mojo.Log.info('this.dashboardData[this.personId]=%j', Object.toJSON(this.dashboardData[this.personId]));
		var data = this.dashboardData[this.personId].record;
		Mojo.Log.info('contact data=%j', Object.toJSON(data));
		var renderedInfo = Mojo.View.render({object: data, template: 'contactreminder-dashboard/reminder-info'});

		// Insert the HTML into the DOM, replacing the existing content.
		Element.update(this.controller.get('reminder_info'),renderedInfo);
	},
	
	tapHandler: function(event) {
		this.controller.serviceRequest("palm://com.palm.applicationManager", {
			method: "open",
			parameters: {
				id: "com.palm.app.contacts",
				params: {
					launchType: "reminder",
					personId: this.personId
				}
			}
		});
		Mojo.Controller.appController.closeStage(this.stageName); 
	},
});