﻿//provide namespace
dojo.provide("NGCJS.StatusBox");

//declare new dijit class
dojo.declare("NGCJS.StatusBox", null, {
    constructor: function(/*HTMLElement*/node, mnode) {

        //apply CSS class to legend
        //dojo.addClass(node, "legend");
        this.domNode = node;
        this.msgNode = mnode;
        this.ststusTimerId = null;

        //node for each layer's legend
        this._statusList = new Array();

        dojo.style(this.domNode, "display", "none");
    },

    _addStatus: function(pId, pMsg) {
        this._statusList.push({
            id: pId,
            message: pMsg
        });
        dojo.style(this.domNode, "display", "block");
        clearTimeout(this.statusTimerId);
        this.statusTimerId = setTimeout(this._timeoutStatus, 40000);
        this._showLastMessage();
    },

    _removeStatus: function(pId) {
        var removeIdx = -1;
        for (idx in this._statusList) {
            if (this._statusList[idx].id == pId) {
                removeIdx = idx;
            }
        }
        if (removeIdx > -1) {
            //alert("removing idx: "+removeIdx);
            this._statusList.splice(removeIdx, 1);
            this._showLastMessage();
        }
    },

    _timeoutStatus: function() {
        //alert("timeout");
        statusBox._statusList = new Array();
        statusBox._showLastMessage();
    },

    _showLastMessage: function() {
        if (this._statusList.length > 0) {
            this.msgNode.innerHTML = this._statusList[this._statusList.length - 1].message;
        } else {
            dojo.style(this.domNode, "display", "none");
            clearTimeout(this.statusTimerId);
        }
    }
});