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

var label_button_done = $L('Done');

var SuccessAssistant = Class.create({
    initialize: function(params){
        this.params = params || {}
		console.log("Updater success params: " + Object.toJSON(this.params));
		UpdatesDepot.getDepot().saveDepotObject("releaseDetails", "");
		UpdatesDepot.getDepot().saveDepotObject("currentBuildDetails", "");
    },

    doneCallback: function(event) {
	   window.close();
    },

    setup: function(){
	   	this.controller.get('system_version').update(this.params.version.escapeHTML());

        UpdatesDepot.getDepot().getNewReleaseDetails( 
					function(obj){
							Mojo.Log.info(obj);
							if (obj && obj != "") {
								this.controller.get('release_notes').innerHTML = obj;
							}
							else{
								Mojo.Log.info("obj false");
							}
						}.bind(this)
				);
				
   		this.joinButtonModel = {buttonLabel: label_button_done};
		this.joinButton = this.controller.get('done-button');
        this.controller.setupWidget('done-button', {}, this.joinButtonModel);
		Mojo.Event.listen(this.joinButton, 'mojo-tap', this.doneCallback.bindAsEventListener(this))

       	var appMenuModel = {
	    	visible: true,
           	items: [Mojo.Menu.editItem, Mojo.Menu.helpItem]
       	};
       	this.controller.setupWidget(Mojo.Menu.appMenu, {omitDefaultItems: true}, appMenuModel);
    },
	
	handleCommand: function(event) {
		if(event.type == Mojo.Event.command) {
			if (event.command == Mojo.Menu.helpCmd) {
				Event.stop(event);
				var openParams = {
					target: 'http://help.palm.com/updates/index.html'
				};
				this.controller.serviceRequest('palm://com.palm.applicationManager', {
					method: 'open',
					parameters: {
						id: 'com.palm.app.help',
						params: openParams
					}
				});
			}
		} else if (event.type == Mojo.Event.commandEnable && 
		         (event.command == Mojo.Menu.helpCmd)) {
			event.stopPropagation();
		}
	},
	
    activate: function(){
    },
	
    deactivate: function(){
    },
	
    cleanup: function(){
    },
});

