/*
	Controller class for "Are you sure you want to delete event?" confirmation dialog

Copyright 2009 Palm, Inc.  All rights reserved.

*/

var DeleteEventConfirmDialogAssistant = Class.create({
	
	initialize: function(sceneAssistant, event, date) {
		this.sceneAssistant = sceneAssistant;
		this.event = event;
		this.date = date;
	},
	
	setup : function(widget) {
		this.widget = widget;
		if((!this.event.rrule || this.event.rrule == "") 
			&& this.event.parentId<=0)
		{
			//deleting recurring series is the same as deleting a non recurring event
			this.sceneAssistant.controller.get('Delete').addEventListener(Mojo.Event.tap, this.handleSeries.bindAsEventListener(this));
		} 
		else
		{
			this.sceneAssistant.controller.get('Series').addEventListener(Mojo.Event.tap, this.handleSeries.bindAsEventListener(this));
			this.sceneAssistant.controller.get('Single').addEventListener(Mojo.Event.tap, this.handleSingle.bindAsEventListener(this));
		}
		this.sceneAssistant.controller.get('Cancel').addEventListener(Mojo.Event.tap, this.handleCancel.bindAsEventListener(this));
		
	},
	
	handleSeries: function() {
		// If this.sceneAssistant.targetEvent.id == undefined (new event) no need to delete it, 
		// the Edit scene just won't save it
		this.widget.mojo.close();	
		if (this.event.id == undefined) {
			// The user is trying to cancel a new event, i.e. don't save it
			this.sceneAssistant.cancelNewEvent = true;
		} else if (this.sceneAssistant.service.deleteEvent) {
			this.sceneAssistant.service.deleteEvent(this.event.id,true, null, this.sceneAssistant.deletedEvent.bind(this.sceneAssistant), this.sceneAssistant.controller);
		}
		
		if (this.event.id == undefined) {
			// Need to pop the edit scene here
			this.sceneAssistant.controller.stageController.popScene();
		}
	},
	
	handleSingle: function() {
		this.widget.mojo.close();
		if (this.sceneAssistant.service.deleteEvent) {
			this.sceneAssistant.service.deleteEvent(this.event.id, false, this.date,this.sceneAssistant.deletedEvent.bind(this.sceneAssistant), this.sceneAssistant.controller);
		}
	},
	
	handleCancel:function(){
		this.widget.mojo.close();
	},
});