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

21.21% Statements 7/33
0% Branches 0/6
14.29% Functions 1/7
21.21% Lines 7/33
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158                                                                                                                                                                                                                                                                                                              
(function ()
{
    'use strict';
 
    angular
        .module('app.e-commerce')
        .controller('OrderController', OrderController);
 
    /** @ngInject */
    function OrderController($state, Statuses, uiGmapGoogleMapApi, Order)
    {
        var vm = this;
 
        // Data
        vm.order = Order.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 image column
                    targets   : 1,
                    filterable: false,
                    sortable  : false,
                    width     : '80px'
                },
                {
                    // Target the actions column
                    targets           : 5,
                    responsivePriority: 1,
                    filterable        : false,
                    sortable          : false
                }
            ],
            pagingType: 'simple',
            lengthMenu: [10, 20, 30, 50, 100],
            pageLength: 20,
            responsive: true
        };
 
        vm.newStatus = '';
 
        // Methods
        vm.gotoOrders = gotoOrders;
        vm.gotoProductDetail = gotoProductDetail;
        vm.updateStatus = updateStatus;
 
        //////////
 
        init();
 
        // Normally, you would need Google Maps Geocoding API
        // to convert addresses into latitude and longitude
        // but because Google's policies, we are faking it for
        // the demo
        uiGmapGoogleMapApi.then(function (maps)
        {
            vm.shippingAddressMap = {
                center: {
                    latitude : -34.397,
                    longitude: 150.644
                },
                marker: {
                    id: 'shippingAddress'
                },
                zoom  : 8
            };
 
            vm.invoiceAddressMap = {
                center: {
                    latitude : -34.397,
                    longitude: 150.644
                },
                marker: {
                    id: 'invoiceAddress'
                },
                zoom  : 8
            };
        });
 
        /**
         * Initialize
         */
        function init()
        {
            // Select the correct order from the data.
            // This is an unnecessary step for a real world app
            // because normally, you would request the product
            // with its id and you would get only one product.
            // For demo purposes, we are grabbing the entire
            // json file which have more than one product details
            // and then hand picking the requested product from
            // it.
            var id = $state.params.id;
 
            for ( var i = 0; i < vm.order.length; i++ )
            {
                if ( vm.order[i].id === parseInt(id) )
                {
                    vm.order = vm.order[i];
                    break;
                }
            }
            // END - Select the correct product from the data
        }
 
        /**
         * Go to orders page
         */
        function gotoOrders()
        {
            $state.go('app.e-commerce.orders');
        }
 
        /**
         * Go to product page
         * @param id
         */
        function gotoProductDetail(id)
        {
            $state.go('app.e-commerce.products.detail', {id: id});
        }
 
        /**
         * Update order status
         *
         * @param id
         */
        function updateStatus(id)
        {
            if ( !id )
            {
                return;
            }
 
            for ( var i = 0; i < vm.statuses.length; i++ )
            {
                if ( vm.statuses[i].id === parseInt(id) )
                {
                    vm.order.status.unshift({
                        id   : vm.statuses[i].id,
                        name : vm.statuses[i].name,
                        color: vm.statuses[i].color,
                        date : moment().format('YYYY/MM/DD HH:mm:ss')
                    });
 
                    break;
                }
            }
        }
    }
})();