/*global FormplayerFrontend */

FormplayerFrontend.module("SessionNavigate.MenuList", function (MenuList, FormplayerFrontend, Backbone, Marionette, $) {
    MenuList.Controller = {
        selectMenu: function (appId, stepList, page, search) {

            var fetchingNextMenu = FormplayerFrontend.request("app:select:menus", appId, stepList, page, search);

            /*
             Determine the next screen to display.  Could be
             a list of commands (modules and/or forms)
             a list of entities (cases) and their details
             */
            $.when(fetchingNextMenu).done(function (menuResponse) {
                var menuListView;
                var menuData = {
                    collection: menuResponse,
                    title: menuResponse.title,
                    headers: menuResponse.headers,
                    widthHints: menuResponse.widthHints,
                    action: menuResponse.action,
                    pageCount: menuResponse.pageCount,
                    currentPage: menuResponse.currentPage,
                    styles: menuResponse.styles,
                };
                if (menuResponse.type === "commands") {
                    menuListView = new MenuList.MenuListView(menuData);
                    FormplayerFrontend.regions.main.show(menuListView.render());
                }
                else if (menuResponse.type === "entities") {
                    menuListView = new MenuList.CaseListView(menuData);
                    FormplayerFrontend.regions.main.show(menuListView.render());
                }
            });
        },

        showDetail: function (model) {
            var headers = model.options.model.get('detail').headers;
            var details = model.options.model.get('detail').details;
            var detailModel = [];
            // we need to map the details and headers JSON to a list for a Backbone Collection
            for (var i = 0; i < headers.length; i++) {
                var obj = {};
                obj.data = details[i];
                obj.header = headers[i];
                obj.id = i;
                detailModel.push(obj);
            }
            var detailCollection = new Backbone.Collection();
            detailCollection.reset(detailModel);
            var menuListView = new MenuList.DetailListView({
                collection: detailCollection,
            });

            $('#select-case').click(function () {
                FormplayerFrontend.trigger("menu:select", model._index, model.options.model.collection.appId);
            });

            $('#case-detail-modal').find('.modal-body').html(menuListView.render().el);
            $('#case-detail-modal').modal('toggle');
        },
    };
});
@@ -1645,14 +1645,28 @@
 ion 
-(model
+myself (model, index
 ) %7B%0A
@@ -1681,22 +1681,28 @@
     var 
-header
+detailObject
 s = mode
@@ -1732,18 +1732,11 @@
 tail
+s
 ')
-.headers
 ;%0A  
@@ -1759,45 +1759,125 @@
 tail
-s = model.options.model.get('detail')
+Object = detailObjects%5Bindex%5D;%0A            var headers = detailObject.headers;%0A            var details = detailObject
 .det
@@ -2484,32 +2484,640 @@
            %7D);%0A%0A
+            var tabModel = %5B%5D;%0A            for (var j = 0; j %3C detailObjects.length; j++) %7B%0A                var tabObject = %7B%7D;%0A                tabObject.title = detailObjects%5Bj%5D.title;%0A                tabObject.id = j;%0A                tabModel.push(tabObject);%0A            %7D%0A            var tabCollection = new Backbone.Collection();%0A            tabCollection.reset(tabModel);%0A            var tabListView = new MenuList.DetailTabListView(%7B%0A                collection: tabCollection,%0A                showDetail: function(index) %7B%0A                    myself(model, index);%0A                %7D,%0A            %7D);%0A%0A
             $('#
@@ -3269,33 +3269,120 @@
             %7D);%0A
+            $('#case-detail-modal').find('.detail-tabs').html(tabListView.render().el);
 %0A
-
             $('#
@@ -3500,14 +3500,12 @@
 al('
-toggle
+show
 ');%0A

update controller