﻿/*
    MetadataLoader
*/
Veeam.MetadataLoader = function(config, containerId ) {
    this.containerId = containerId;
    this.reload = false;
    if( !config.query ) throw new Error('query undefined');
    Veeam.MetadataLoader.superclass.constructor.apply(this, [config]);
};

Ext.extend(Veeam.MetadataLoader, Ext.Component, {
    loadMetadata : function(callback) {
        var call = CommonDataHandler.rpc.getMetadata( this.initialConfig.query, 
            this.reload||false,
            callback );
        ext_channel( call );
    }
});

Ext.reg('vm.ui.metadataloader',  Veeam.MetadataLoader );

/* 
    ContainerPanel
*/
Veeam.ContainerPanel = function (config) {
    if (!config.containerId) throw new Error("containerId undefined");
    this.contentItems = [];
    this.breadcrumbs = new Ext.util.MixedCollection();
    this.breadcrumbsHistory = [];

    this.btnRefresh = new Ext.Toolbar.Button({
        text: 'Refresh', cls: 'x-btn-text-icon', icon: 'img/refresh.gif',
        handler: this.refreshHandler, scope: this
    });

    this.btnExport = new Ext.Toolbar.Button({
        text: 'Export Excel', cls: 'x-btn-text-icon', icon: 'img/excel.gif',
        handler: this.exportHandler, scope: this
    });

    this.breadcrumbsPn = new Ext.BoxComponent({
        region: 'north',
        border: false,
        cls: 'breadcrumbs-panel-body',
        autoHeight: true,
        hidden: !config.showBreadcrumbs,
        margins: '0 0 10 0',
        id: 'container-breadcrumbs-' + config.containerId,
        listeners: {
            'afterrender': function () {
                this.el.on('click', this.brcrClickHandler,
                        this, { stopEvent: true, delegate: 'a.x-breadcrumb' });
            },
            scope: this
        }
    });

    var containerConfig = {
        region: 'center',
        layout: 'fit',
        border: false,
        //boxMinWidth: 923,
        //autoScroll: true,
        id: 'container-content-' + config.containerId
    };

    this.contentPn = new Ext.Container(containerConfig);


    config = Ext.apply({
        layout: 'border',
        baseCls: 'container-panel',
        border: false,
        autoScroll: true,
        cls: 'container-panel-body',
        id: 'container-' + config.containerId,
        items: [this.contentPn, this.breadcrumbsPn],
        removeOldItems: true
    }, config);

    if (config.containerTitle){
        var cssClass = Ext.util.Format.lowercase(config.containerTitle).replace(/\s/g, "_");
        config.ctCls = cssClass;
    };
    Veeam.ContainerPanel.superclass.constructor.apply(this, [config]);
    this.addEvents("beforeactivatecontent");

    var c = Veeam.ContainerPanel.containers;
    if (c[config.containerId]) throw new Error(config.containerId + ' already exists');
    c[config.containerId] = this;

    this.currentHistorySize = App.getHistory().getCount();
};

Veeam.ContainerPanel.containers = {};
Ext.reg('vm.ui.containerpanel', Veeam.ContainerPanel);

Ext.extend(Veeam.ContainerPanel, Ext.Panel, {
    destroy: function() {
        if ( this.loadMask) this.loadMask.destroy();
        this.breadcrumbs.each( function(el) { el.remove(); });
        Veeam.ContainerPanel.containers.remove( this.containerId );
        Veeam.ContainerPanel.superclass.destroy.call(this);
    },

    activateContent : function( contentConfig, replace ) {
        if ( !this.initialConfig.contentConfig && contentConfig )
            this.initialConfig.contentConfig = contentConfig;
        var cc = contentConfig||this.initialConfig.contentConfig;
        if (cc) {
            this.loadContent(cc);
        }
    },
    
    deactivateContent : function() {
    },
    
    addBreadcrumb : function( contentConfig, isActive ) {
        var title = (contentConfig.query||{}).displayName||"#";
        var tag = isActive ? 'a' : 'span';
        var id = Ext.id("", 'breadcrumb-');
        var html = String.format('<{1} href="#" class="x-breadcrumb" id="{2}">{0}</{1}>', title, tag,  id);
        if ( this.breadcrumbs.items.length > 0) { html = '&nbsp;<span>&gt;&nbsp;' + html; }
        var el = this.breadcrumbsPn.el.insertHtml('beforeEnd', html , true );
        this.breadcrumbs.add(id, el);
        return el;
    },

    clearBreadcrumbs: function(){
        this.breadcrumbs.each( function(el) { el.remove(); });
        this.breadcrumbs.clear();
        if (this.breadcrumbsPn.el)
            this.breadcrumbsPn.el.update('');
    },

    renderBreadcrumbs: function(contentConfig){
        this.clearBreadcrumbs();
        var historyEntryIndex = this.breadcrumbsHistory.indexOf(contentConfig);
        if (historyEntryIndex != -1){
            this.breadcrumbsHistory.length = historyEntryIndex + 1;
        } else {
            this.breadcrumbsHistory.push(contentConfig);
        }

        for (var i = 0, len = this.breadcrumbsHistory.length; i < len; i++){
            var el = this.addBreadcrumb(this.breadcrumbsHistory[i], !(i == (len - 1)) );
        }
    },

    brcrClickHandler : function( e, t, o ) {
        e.stopEvent();
        var ccIdx = this.breadcrumbs.indexOfKey(t.id);
        if (ccIdx >= 0){
            var cc = this.breadcrumbsHistory[ ccIdx ];
            if (cc)
                this.activateContent(cc, true);
        }
    },

    removeOld : function(date) {
      // depricated
    },

    loadContent: function(contentConfig) {
        if (!contentConfig) throw new Error("contentConfig undefined");
        if (contentConfig.initialConfig) throw new Error("only configs supported, not instances");

        var skey = Ext.encode( contentConfig );

        var pn = this.contentItems[skey];

        this.fireEvent("beforeload", this);

        if ( contentConfig.xtype == 'vm.ui.metadataloader' ) {
            this.loading = true;
            this.doLoadMask();
            var o = Ext.ComponentMgr.create(contentConfig, this.initialConfig.containerId );
            o.loadMetadata( this.createContent.createDelegate(this, [skey], true ) );
        } else {
            this.createContent( contentConfig, skey );
        }
        this.renderBreadcrumbs(contentConfig);
    },

    doLoadMask : function() {
        if ( !this.loading ) return;
        if ( !this.loadMask )
            { this.loadMask = new Ext.LoadMask( Ext.getBody(), {} ); }
        this.loadMask.show();
    },

    createContent: function( contentConfig, skey ) {
        this.loading = false;
        if ( this.loadMask ) this.loadMask.hide();

        var pn;
        if ( contentConfig.initialConfig ) {
            pn = contentConfig;
            contentConfig = contentConfig.initialConfig;
        } else {
            contentConfig = Ext.apply({
                //layout:'fit',
                currentContainerId:this.initialConfig.containerId
            }, contentConfig||{} );
            var pn = Ext.ComponentMgr.create( contentConfig, 'vm.ui.emptypanel' );
        }
                        
        pn.createMoment = new Date();
        this.contentPn.removeAll(true);
        this.contentPn.add( pn );
        this.contentPn.doLayout();
       // if (pn.doLayout)
       //     pn.doLayout();
        this.syncSize();
        if ( this.fireEvent("beforeactivatecontent", this, pn, skey ) !== false ) {
            if(pn.activateContent) { pn.activateContent(); }
        }
    }, 
    
    refreshHandler : function() {
        App.registerActivity();
    },
    
    exportHandler : function() {
    }
});

/*
    Veeam.Window
*/
Veeam.Window = function(config) {
    Veeam.Window.superclass.constructor.apply( this, [config] );
};

Ext.extend( Veeam.Window, Ext.Window, {
    show: function() {
        Veeam.Window.superclass.show.apply(this, arguments);
        App.registerActivity();
    },
    hide: function() {
        Veeam.Window.superclass.hide.apply(this, arguments);
        App.registerActivity();
    }
});

Ext.reg('vm.ui.window', Veeam.Window);


/* 
    Window
*/ 
Veeam.WindowPanel = function(config) {
    config = config||{};

    this.btnClose = new Ext.Button({ text : 'Close', handler: this.close, scope:this });
    
    config = Ext.apply( config, { 
        width:800,
        height:500,
        modal:true,
        layout:'fit',
        monitorResize:true,
        buttons:[this.btnClose],
        listeners:{
            scope: this,
            close:this.closeHandler,
            resize:this.moveHandler
        }
    });
    
    Veeam.WindowPanel.superclass.constructor.apply( this, [config] );
};

Ext.extend(Veeam.WindowPanel, Veeam.Window, {
    activateContent : function( contentConfig ) {
        if ( !this.initialConfig.contentConfig )
            this.initialConfig.contentConfig = contentConfig;
        
        var cc = contentConfig||this.initialConfig.contentConfig;
        if (cc) this.loadContent(cc);
    },
    
    deactivateContent : function() {
    },
    
    loadContent: function(contentConfig) {
        if (!contentConfig) throw new Error("contentConfig undefined");
        if (contentConfig.initialConfig) throw new Error("only configs supported, not instances");
            
        if ( contentConfig.xtype == 'vm.ui.metadataloader' ) {
            var o = Ext.ComponentMgr.create(contentConfig, this.initialConfig.containerId );
                o.loadMetadata( this.createContent.createDelegate(this ) );
        } else {
            this.createContent( contentConfig, skey );
        }
    }, 
    
    createContent: function( config ) {
        this.loading = false;
        
        if ( config.initialConfig ) { 
            var pn = this.contentPanel = config;
            config = config.initialConfig;
        } else { 
            config = Ext.apply( { layout:'fit' }, config||{} );
            var pn = this.contentPanel = Ext.ComponentMgr.create( config, 'vm.ui.emptypanel' ); 
        }
        
        this.add(this.contentPanel);
        this.doLayout();            
        this.contentPanel.doLayout();
        
        if ( this.fireEvent("beforeactivatecontent", this, pn ) !== false ) {
            if ( pn.activateContent ) 
                pn.activateContent();
        }
    },
    
    moveHandler : function() {
        this._haveBeenMoved = true;
    },
    
    closeHandler : function() {
        if ( this.contentPanel && this.contentPanel.deactivateContent )
            this.contentPanel.deactivateContent();
            
        //this.close();
    }, 
    
    onWindowResize: function() {
        Veeam.WindowPanel.superclass.onWindowResize.apply(this, arguments);
        if ( !this._haveBeenMoved )
            this.center();
    }
});

Ext.reg('vm.ui.windowpanel', Veeam.WindowPanel);

/*
    Tab Panel
*/
Veeam.TabPanel = function(config) {
    config = Ext.applyIf( config||{}, { 
        border:false,
        items:[ {}]
    });
    Ext.apply(this, config);
    
    Veeam.TabPanel.superclass.constructor.apply( this, arguments );
};
Ext.reg('vm.ui.tabpanel', Veeam.TabPanel);

Ext.extend(Veeam.TabPanel, Ext.TabPanel, {
    destroy: function() {
        Veeam.TabPanel.superclass.destroy.call(this);
    }
});

/*
    Composite Panel
*/
Veeam.CompositePanel = function(config) {
    config = Ext.apply( config||{}, { 
        layout:'border',
        style:'background:transparent',
        bodyStyle:'background:transparent',
        border:false,
        listeners: { resize : this.resizeHandler.createDelegate(this) }
    });
    
    Veeam.CompositePanel.superclass.constructor.apply( this, [config] );
};
Ext.reg('vm.ui.compositepanel', Veeam.CompositePanel);

Ext.extend(Veeam.CompositePanel, Ext.Panel, {
    destroy: function() {
        Veeam.CompositePanel.superclass.destroy.call(this);
    }, 
    
    resizeHandler: function( cmp, aw, ah, rw, rh) {
        for ( var i = 0; i<this.items.items.length; i++ ) {
            var pn = this.items.items[i];
            if ( (pn.region == 'west' || pn.region=='east') && aw && pn.relativeWidth ) {
                pn.setWidth( aw * pn.relativeWidth );
            } else if ( (pn.region == 'north' || pn.region=='south') && ah && pn.relativeHeight ) {
                pn.setHeight( ah * pn.relativeHeight );
            }
        }
    },
    
    activateContent : function() {
        var items = this.items.items;
        for ( var i = 0; i<items.length; i++ )
            if (items[i].activateContent)
                items[i].activateContent();
    },
    
    deactivateContent: function() {
    }
});

/*
    Veeam.Box
*/
Veeam.Box = function(config) {
    config = Ext.applyIf( config||{}, {
        frame:true,
        baseCls:'box-panel'
    });
    Veeam.Box.superclass.constructor.apply( this, [config] );
};

Ext.extend( Veeam.Box, Ext.Panel, {
});

Ext.reg('vm.ui.box', Veeam.Box);


Veeam.DateMenu = Ext.extend(Ext.menu.Menu, {
    enableScrolling: false,
    hideOnClick: true,
    autoHeight: true,
    pickerId: null,
    cls: 'x-date-menu',
    initComponent: function () {
        this.on('beforeshow', this.onBeforeShow, this);
        if (this.strict = (Ext.isIE && Ext.isStrict)) {
            this.on('show', this.onShow, this, { single: true, delay: 20 });
        }

        this.initialConfig.listViewConfig = this.initialConfig.listViewConfig || {};

        this.dataStore = new Ext.data.SimpleStore({
            idIndex: 0,
            fields: [
                { name: 'id' },
                { name: 'date', type: 'date', format: 'timestamp' }
            ]
        });

        this.listView = new Ext.list.ListView({
            store: this.dataStore,
            multiSelect: false,
            width: 180,
            height: 185,
            columnResize: false,
            columnSort: false,
            singleSelect: true,
            reserveScrollOffset: true,
            columns: [{
                header: this.initialConfig.listViewConfig.listHeader || 'Timestamp',
                dataIndex: 'date',
                tpl: '{date:date(Veeam.Defaults.dtFormat)}'
            }]
        });

        this.picker = new Ext.DatePicker(Ext.applyIf({
            internalRender: this.strict || !Ext.isIE,
            id: this.pickerId,
            cls: 'x-right-border'
        }, this.initialConfig)),

        this.wrapper = new Ext.Container({
            id: 'datemenu-wrapper',
            layout: 'column',
            cls: 'x-veeam-datemenu',
            ctCls: 'x-menu-date-item',
            width:  350,
            defaults: { columnWidth: .5 },
            items: [this.picker, this.listView]
        });

        Ext.apply(this, {
            plain: true,
            showSeparator: false,
            items: [this.wrapper]
        });

        this.picker.purgeListeners();

        this.markedDates = [];

        Ext.apply(this.picker, { markedDates: this.markedDates });

        Veeam.DateMenu.superclass.initComponent.call(this);

        this.relayEvents(this.listView, ['selectionchange']);
        this.on('show', this.picker.focus, this.picker);
        //this.on('select', this.hide, this);
        this.on('selectionchange', this.onSelectionChange, this);

        this.picker.on('select', this.filterDates, this);

        if (this.handler) {
            this.on('select', this.handler, this.scope || this);
        }

        this.initData();

    },

    menuHide: function () {
        if (this.hideOnClick) {
            this.hide(true);
        }
    },

    onBeforeShow: function () {
        if (this.picker) {
            this.picker.hideMonthPicker(true);
        }
    },

    onShow: function () {
        var el = this.picker.getEl();
        el.setWidth(el.getWidth()); //nasty hack for IE7 strict mode
    },

    onSelectionChange: function (lv, selections) {
        if (!selections || selections.length == 0) return
        var r = this.listView.getRecord(selections[0])
        var date = r.get('date'),
            id = r.get('id');
        this.fireEvent('select', this, { 'date': date, 'id': id });
    },

    filterDates: function (dp, date) {
        var midnight = date.clearTime(true);
        this.dataStore.filterBy(function (r, id) {
            var ts = r.get('date');
            var d = new Date(ts).clearTime();
            if (d.valueOf() == midnight.valueOf()) return true
        });
    },

    setValue: function (date) {

        this.picker.setValue(date);
        if (Ext.isDate(date)) {
            this.filterDates(null, date);
            var index = this.dataStore.find('id', id);
            if (index >= 0) {
                this.listView.select(index, false, true);
            }
        }

    },

    addDate: function (point) {
        var store = this.dataStore,
            r = new store.recordType(point, point.id),
            date = new Date(r.get('date').valueOf());

        store.add(r);
        var d = date.clearTime();
        this.markedDates.push(d);
        this.picker.markedDates.push(d);
    },

    clearDates: function () {
        this.dataStore.removeAll();
        this.initialConfig.initialData = null;
        this.markedDates = [];
        if (this.picker)
            this.picker.markedDates = [];

    },

    setData: function (points) {
        this.clearDates();
        this.initData(points);
    },

    initData: function (points) {
        var points = points ? points : this.initialConfig.initialData;
        for (var i = 0, len = points.length; i < len; i++) {
            this.addDate(points[i]);

        }
    }
});

Veeam.DateField = Ext.extend(Ext.form.DateField, {
    constructor: function(config){
        config = Ext.applyIf( { 
            allowedDatesText: 'The date in this field is not allowed',
          	disableKeyFilter: true,
          	editable: false,
          	validateOnBlur: false,
          	validationEvent: false
        }, config || {} );
        
        Ext.form.DateField.superclass.constructor.call(this, config);
    },
    
    initComponent: function(){
        this.restorePoints = [];
        this.selectedPoint = null;
        this.initMenu();
        Ext.form.DateField.superclass.initComponent.call(this);
    },
    
    initEvents: function(){
        Veeam.DateField.superclass.initEvents.call(this);
        this.addEvents('datesloaded');
    },
  
    onTriggerClick : function(){
        if(this.disabled){
            return;
        }
        
        this.onFocus();
        this.menuEvents('on');
        this.menu.setValue(this.getValue(true) || new Date());
        this.menu.show(this.el, "tl-bl?");
        
    },
    
    initMenu: function(){
          var config = Ext.copyTo({
                hideOnClick: false,
                focusOnSelect: false,
                initialData: this.restorePoints
            }, this.initialConfig);

           this.menu = new Veeam.DateMenu(config);
           Ext.apply(this.menu.picker,  {
                minDate : this.minValue,
                maxDate : this.maxValue,
                disabledDatesRE : this.disabledDatesRE,
                disabledDatesText : this.disabledDatesText,
                disabledDays : this.disabledDays,
                disabledDaysText : this.disabledDaysText,
                format : this.format,
                showToday : this.showToday,
                minText : String.format(this.minText, this.formatDate(this.minValue)),
                maxText : String.format(this.maxText, this.formatDate(this.maxValue))
            });
    },
    
    setDateCollection: function(points){
        if (!points)
            return;
        
        this.restorePoints = points;    
        if(this.menu)
            this.menu.setData.call(this.menu, [].concat(points) );
        
        this.allowedDates = Ext.pluck(points, 'date') || [];
        // set date and fire select event
        var lastPoint = this.initialValue && this.initialValue.date ? 
            this.initialValue : 
            points[ points.length - 1 ];
        this.setValue(lastPoint, true);
        this.fireEvent('datesloaded', this);
    },
    
    setValue : function(point, fireSelectEvent){
        var date = Ext.isDate(point.date) ? point.date : Date.parse(point.date);
        var cmp =  Ext.form.DateField.superclass.setRawValue.call(this, this.formatDate(date));
        this.selectedPoint = point;
        // filter records for selected date
        if (this.menu && Ext.isDate(date)){
            this.menu.filterDates(null, date)
        }
        if (fireSelectEvent === true){
            this.fireEvent('select', this, point);
        }
        return cmp;
    },
    
    beforeBlur: function() {
        
    },
    
    getValue: function(as_date){
        this.validate(this.selectedPoint? this.selectedPoint.date : null);
        return (as_date === true) ? this.selectedPoint ? this.selectedPoint.date : null : this.selectedPoint;  
    },   
    
    clearField: function(){
        Veeam.DateField.superclass.setValue.call(this, '');
        this.allowedDates = null;
        if (this.menu)
            this.menu.clearDates.call(this.menu);
        this.selectedPoint = null;
        this.restorePoints = [];
        this.initialValue = null;
        
    },
    validateValue: function(value){
        if (!value)
            return false;
        var flag = Ext.form.DateField.superclass.validateValue.call(this, value);
        if (flag === false) return false;
        flag = false;
        var d = this.parseDate(value);
        if (Ext.isDate(d) && Ext.isArray(this.allowedDates)){
            var time = d.valueOf();
            for(var i=0, len = this.allowedDates.length; i < len; i++){
                if (time == this.allowedDates[i].valueOf()) { flag = true; break; }
            }
        }
        
        if (flag == false) { this.markInvalid(this.allowedDatesText); }
        return flag;
    
    },
    
    getState: function(){
        return { initialValue: this.getValue() }
    
    }
});



Ext.ns('Veeam.Msg');

Ext.Msg.minWidth = 300;

Veeam.Msg.error = function (cfg) {
    if (typeof cfg == "string")
        cfg = { msg: cfg };
    return Ext.Msg.show(
        Ext.apply({
            title: 'Veeam Backup Enterprise Manager',
            buttons: Ext.Msg.OK,
            minWidth: 300,
            icon: Ext.MessageBox.ERROR
        }, cfg || {})
    );
}

Veeam.Msg.success = function(cfg){
    return Ext.Msg.show(
        Ext.apply({
            title:'Veeam Backup Enterprise Manager',
            buttons: Ext.Msg.OK,
            minWidth: 300,
            icon: Ext.MessageBox.INFO
        }, cfg || {})
    );
}

Veeam.Msg.warning = function(cfg){
    return Ext.Msg.show(
        Ext.apply({
            title:'Veeam Backup Enterprise Manager',
            buttons: Ext.Msg.OK,
            minWidth: 300,
            icon: Ext.MessageBox.WARNING
        }, cfg || {})
    );
}

Veeam.ColorRadio = Ext.extend(Ext.form.Radio, {
    constructor: function(cfg){
        Veeam.ColorRadio.superclass.constructor.call(this, cfg);  
        this.boxCls = cfg.boxCls || '';
    },
    onRender: function(ct, pos){
        Veeam.ColorRadio.superclass.onRender.apply(this, arguments);
        this.wrap.insertFirst({
            tag: 'div',
            cls: this.boxCls
        });
    }
});

Ext.reg('vm.ui.colorradio', Veeam.ColorRadio);


Veeam.Link = Ext.extend(Ext.BoxComponent, {
    autoEl: {
        tag: 'a',
        cls: 'x-veeam-link',
        href: "#"
    },
    alwaysEnabled: true,
    onRender: function() {
        var cfg = Ext.copyTo({}, this.initialConfig, 'text, cls, iconCls');
        this.autoEl = Ext.apply( { }, cfg, this.autoEl);
        this.autoEl.html = this.text;
        Veeam.Link.superclass.onRender.apply(this, arguments);
        this.el.on('click', this.onClick, this);
    },

    onClick: function(ev, target, options){
        ev.stopEvent();
        if (this.fireEvent('click', this) !== false){
            if (typeof(this.handler) == 'function')
                this.handler.apply( this.scope || this, Array.prototype.slice.call(arguments));
        }
    },
    setText: function (text){
        if (!this.el)
            this.text = text;
        else
            this.el.update(text);
    }

});

Ext.reg('vm.ui.link', Veeam.Link);


Ext.ns('Veeam.Plugins');

Veeam.Plugins.MenuQuickTips = Ext.extend(Object, {
    init: function (menu) {
        menu.items.each(function (item) {
            if (typeof (item.qtip) != 'undefined')
                item.on('afterrender', function (menuItem) {
                    var qtip = typeof (menuItem.qtip) == 'string'
                                ? {text: menuItem.qtip} 
                                : menuItem.qtip;
                    qtip = Ext.apply(qtip, {target: menuItem.getEl().getAttribute('id')});
                    Ext.QuickTips.register(qtip);
                });
        });
    }
});
Ext.preg('veeam.menuqtips', Veeam.Plugins.MenuQuickTips);


/* Noifier */
Veeam.NotifyManager = (function(){
    var queue = [];
    return {
      push: function(message){
            queue.push(message);
      },
      remove: function(ob){
          queue.remove(ob);
      }
    };
})();


Veeam.Notification = function(message){
    var _el,
        _message = message;
    var createDiv = function(text){
            var messageId = Ext.id(null, 'notification-');
            var spec = {
                id: messageId,
                tag: 'div',
                cls: 'x-notification',
                children: [ {tag: 'div', cls: 'x-notification-body', html: text} ]
            };
            return Ext.DomHelper.append(document.body, spec, true);
    };

    var afterShow = function(){
        this.destroy.defer(4000, this);
    };

    return {
          destroy: function(){
            if (_el){
                _el.remove();
            }
            Veeam.NotifyManager.remove(this);

          },
          show: function(){
              _el = createDiv(_message);
              Veeam.NotifyManager.push(this);
              if (!_el)
                throw new Exception('Failed to create notification object.');

              _el.slideIn('t', {
                duration: 1,
                callback: afterShow,
                scope: this
              });

          }
     }
};