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

var ErrorAssistant = Class.create({

    initialize: function(docAssistant) {
        Mojo.Log.info("ErrorAssistant: initialize");
		this.docAssistant = docAssistant;
		this.controller = docAssistant.controller;
    },

    setup: function() {
        //Mojo.Log.info("ErrorAssistant: setup");

        this.controller.get('errorText').innerHTML = this.docAssistant.errorText;

        this.controller.get('dismiss_button').observe(Mojo.Event.tap,
            this.doDismiss.bindAsEventListener(this));

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

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

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

    cleanup: function() {
        //Mojo.Log.info("ErrorAssistant: cleanup");
        this.docAssistant.errorText = undefined;
        //window.close();
    },

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

    doDismiss: function(event) {
        //Mojo.Log.info("ErrorAssistant: deactivate");

        Mojo.Controller.appController.closeAllStages();
    },

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

    handleCommand: function(event) {
        if (event.type == Mojo.Event.back) {
            Mojo.Controller.appController.closeAllStages();
		}
    }
});
