all files / app/main/apps/e-commerce/views/orders/ orders.controller.js

19.23% Statements 5/26
0% Branches 0/8
14.29% Functions 1/7
19.23% Lines 5/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108                                                                                                                                                                                                              
(function ()
{
    'use strict';
 
    angular
        .module('app.e-commerce')
        .controller('OrdersController', OrdersController);
 
    /** @ngInject */
    function OrdersController($state, Statuses, Orders)
    {
        var vm = this;
 
        // Data
        vm.orders = Orders.data;
        vm.statuses = Statuses.data;
 
        vm.dtInstance = {};
        vm.dtOptions = {
            dom         : 'rt<"bottom"<"left"<"length"l>><"right"<"info"i><"pagination"p>>>',
            columnDefs  : [
                {
                    // Target the id column
                    targets: 0,
                    width  : '72px'
                },
                {
                    // Target the status column
                    targets: 6,
                    render : function (data, type)
                    {
                        if ( type === 'display' )
                        {
                            var orderStatus = vm.getOrderStatus(data);
                            return '<span class="status ' + orderStatus.color + '">' + orderStatus.name + '</span>';
                        }
 
                        if ( type === 'filter' )
                        {
                            return vm.getOrderStatus(data).name;
                        }
 
                        return data;
                    }
                },
                {
                    // Target the actions column
                    targets           : 8,
                    responsivePriority: 1,
                    filterable        : false,
                    sortable          : false
                }
            ],
            initComplete: function ()
            {
                var api = this.api(),
                    searchBox = angular.element('body').find('#e-commerce-products-search');
 
                // Bind an external input as a table wide search box
                if ( searchBox.length > 0 )
                {
                    searchBox.on('keyup', function (event)
                    {
                        api.search(event.target.value).draw();
                    });
                }
            },
            pagingType  : 'simple',
            lengthMenu  : [10, 20, 30, 50, 100],
            pageLength  : 20,
            scrollY     : 'auto',
            responsive  : true
        };
 
        // Methods
        vm.getOrderStatus = getOrderStatus;
        vm.gotoOrderDetail = gotoOrderDetail;
 
        //////////
 
        /**
         * Get order status
         *
         * @param id
         * @returns {*}
         */
        function getOrderStatus(id)
        {
            for ( var i = 0; i < vm.statuses.length; i++ )
            {
                if ( vm.statuses[i].id === parseInt(id) )
                {
                    return vm.statuses[i];
                }
            }
        }
 
        /**
         * Go to product detail
         *
         * @param id
         */
        function gotoOrderDetail(id)
        {
            $state.go('app.e-commerce.orders.detail', {id: id});
        }
    }
})();