/* Copyright 2009 Palm, Inc.  All rights reserved. */
/*global Mojo, Class, $L */
/*jslint rhino:true, undef:true */

var UpgradeAssistant = Class.create({

    initialize: function(docAssistant) {
		this.docAssistant = docAssistant;
		this.controller = docAssistant.controller;
    },

    setup: function() {

        // Set up the view buttons (header)

        this.controller.get('info_button').observe(Mojo.Event.tap,
            this.doInfo.bindAsEventListener(this));

        this.controller.setupWidget(Mojo.Menu.appMenu,
                                    { omitDefaultItems: true },
                                    this.appMenuModel);
    },

    activate: function() {
        //Mojo.Log.info("UpgradeAssistant: activate");
    },

    ready: function() {
        //Mojo.Log.info("UpgradeAssistant: ready");
    },

    cleanup: function() {
        //Mojo.Log.info("UpgradeAssistant: cleanup");
    },

    deactivate: function() {
        //Mojo.Log.info("UpgradeAssistant: deactivate");
    },

    doInfo: function(event) {
        //Mojo.Log.info("UpgradeAssistant: doInfo");

        this.docAssistant.showElement('PlugIn');

        var openParams = { target: 'http://www.dataviz.com/MoreInfoDTGEditor' };

        this.controller.serviceRequest(
                'palm://com.palm.applicationManager',
                {
                  method: 'open',
                  parameters: {
                                id: 'com.palm.app.browser',
                                params: openParams
                              }
                });

        this.controller.stageController.popScene();
    },

    handleCommand: function(event) {
        if (event.type == Mojo.Event.command)
        {
            try {
                Mojo.Log.info("Got command: '%s'", event.command);

                if (event.command === Mojo.Menu.helpCmd) {
                       Mojo.Log.info("Help command for docviewer");

                       this.controller.serviceRequest('palm://com.palm.applicationManager', {
                           method: 'open',
                           parameters: {
                               id: 'com.palm.app.help',
                               params: {
                                   target: "http://help.palm.com/doc_view/index.html"
                               }
                           }
                       });
                }
            }
			catch (e)
			{
				Mojo.Log.logException(e);
			}

        }
    },

    appMenuModel: {
                    items: [
                             {
                               label: $L('Help...'),
                               command: Mojo.Menu.helpCmd
                             }
                           ]
                  }

});
