crmApp.controller("AdminSearchViewController", AdminSearchViewController);

function AdminSearchViewController($scope, $window) {
    var vm = this;

    vm.init = function () {
      
        var windowHash=$window.location.hash;
        //angular.element('.treeview-menu >li:first-child >a').click();
        if (!windowHash) {
            angular.element('.sidebar-menu>li.treeview:first-child').addClass('active');
            angular.element('.treeview-menu >li:first-child').addClass('active');
            $window.location.hash = "#/Activity";
        }
        else {
            var n=0;
            switch (windowHash) {
                case '#/Taxpayer':
                    n = 1;
                    break;
                case '#/Case':
                    n = 2;
                    break;
                case '#/Activity':
                    n = 3;
                    break;
            }
            angular.element('.sidebar-menu>li.treeview:first-child').addClass('active');
            angular.element('.treeview-menu >li:nth-child('+n+')').addClass('active');
        }
           

    };
    vm.navMenuClicked = function ($event) {
        var elem = $event.currentTarget || $event.srcElement;
        var activeMenu = document.querySelector('.sidebar-menu > .treeview.active');

        if (activeMenu)
            angular.element(activeMenu).removeClass("active");

        angular.element(elem).addClass("active");
    };

    vm.navSubMenuClicked = function ($event) {
        var elem = $event.currentTarget || $event.srcElement;
        var activeSubMenu = document.querySelector('.treeview-menu > li.active');

        if (activeSubMenu)
            angular.element(activeSubMenu).removeClass("active");

        angular.element(elem).addClass("active");
    };

}


crmApp.controller('CfgSearchView', function ($scope, $filter, $window, DTOptionsBuilder, DTColumnDefBuilder, AdminSI) {
    var vm = this;
    vm.isActiveOptions = [{ Text: 'Ya', Value: true },
                         { Text: 'Tidak', Value: false }];
    vm.dtInstance = {};
    vm.list = {};
    vm.editing = {};
    vm.editMode = false;
    vm.showValidationMsg = false;
    vm.changesHistory = [];

    var configViewURL = $window.configviewurl;

    vm.tableType = $window.tabletype;
    //var constConfigViewURL = $window.configviewurl;

    //console.log('url');
    //console.log(constConfigViewURL);

    vm.dtOptions = DTOptionsBuilder.newOptions()
       .withPaginationType('full_numbers')
       .withDisplayLength(10);

    vm.init = function () {
        var model = { LookupCode: "JenisPelanggan" };
        AdminSI.getSearchViewDetailList($window.tabletype).then(function (r) {
            if (r.status === 200) {
                vm.list = r.data;
                console.log(vm.list);
            }
        });
    };
      
    vm.openConfigSearchView = function (viewID, tableType) {
         
        $window.open(configViewURL + '?ViewID=' + viewID + '&TableType=' + tableType, '_blank');
    }
     

});

 

crmApp.config(function ($routeProvider) {
    $routeProvider

        .when('/Taxpayer', {
            templateUrl: '/Admin/SearchView/AdvancedRulesViews/1',
            controller: 'CfgSearchView'
        })

        .when('/Case', {
            templateUrl: '/Admin/SearchView/AdvancedRulesViews/2',
            controller: 'CfgSearchView'
        })

        .when('/Activity', {
            templateUrl: '/Admin/SearchView/AdvancedRulesViews/3',
            controller: 'CfgSearchView'
        })
        //.when('/TPFileType', {
        //    templateUrl: '/Admin/Setting/ConfigureFileType/',
        //    controller: 'CfgFileType'
        //})
         
});