
// ----------------------------------------------
STUNDENPLAN.Navigation_cl = Class.create({
// ----------------------------------------------
    initialize: function () {
        // zur Vereinfachung hier direkt den Inhalt des
        // Navigationsbereichs anzeigen und die Ereignisverarbeitung einrichten
        //this.render_px();
        this.initHandler_p();
        STUNDENPLAN.es_o.subscribe_px(this, 'nav');
    },
    notify_px: function (self_opl, message_spl, data_apl) {
        switch (message_spl) {
            case 'nav':
                switch (data_apl[0]) {
                    case 'init':

                        break;
                    case 'templates.loaded':

                        break;
                    case 'init.nav':
                        this.nav_o.render_px(data_apl[1]);
                        break;
                    case 'set_action':
                        this.setMenuActive_p(data_apl[1]);
                        break;
                    default:
                        console.log('[Application_cl] unbekannte nav-Notification: ' + data_apl[0]);
                        break;
                }
                break;
            default:
                console.log('[Application_cl] unbekannte Notification: ' + message_spl);
                break;
        }
    },
    setMenuActive_p: function (data_action) {
        $('.cl_navigation').find('.active').toggleClass('active');
        $('.cl_navigation').find('a[data-action="' + data_action + '"]').parent('li').toggleClass('active');
    },
    render_px: function (data_opl) {
        var markup_s = "";

        for (var nIndex = 0; nIndex < data_opl.length; nIndex++) {
            markup_s += '<li><a href="#" data-action="' + data_opl[nIndex].action + '" data-method="' + data_opl[nIndex].method + '" data-name="' + data_opl[nIndex].name + '">' + data_opl[nIndex].text + '</a></li>';
        }
        $('.cl_navigation').html(markup_s);
        STUNDENPLAN.es_o.publish_px('app', ['nav.finishd', null]);
    },
    addMenu_px: function (data_opl) {
        var markup_s = "";

        markup_s += '<li><a href="#" data-action="' + data_opl.action + '" data-method="' + data_opl.method + '" data-name="' + data_opl.name + '">' + data_opl.text + '</a></li>';
        $('.cl_navigation').append(markup_s);

    },
    initHandler_p: function () {
        // Ereignisverarbeitung für die Schalter einrichten
        var that = this;
        $(".cl_navigation").on("click", "a", function (event_opl) {
            var viewName_s = $(event_opl.target).attr('data-name');
            var action_s = $(event_opl.target).attr('data-action');
            var method_s = $(event_opl.target).attr('data-method');
            // Weiterleitung! Das Nav-Objekt ist nicht für die Bearbeitung direkt verantwortlich

            console.log("[Navigation_cl] data-action: %o", action_s);
            STUNDENPLAN.es_o.publish_px('app', [method_s, viewName_s, null]);
            that.setMenuActive_p(action_s);
            // Weiterleitung und Standardbearbeitung unterbinden
            event_opl.stopPropagation();
            event_opl.preventDefault();
        });
    }
});

// EOF