Kaynağa Gözat

Shipments v2 UI (wip)

Vijayakrishnan 4 yıl önce
ebeveyn
işleme
b35d89c537

+ 42 - 29
resources/views/app/practice-management/shipments-ready-to-print.blade.php

@@ -38,7 +38,8 @@
                 </thead>
                 <tbody>
                 @foreach ($shipments as $shipment)
-                    <tr class="{{$shipment->is_cancelled ? 'bg-light' : ''}}">
+                    <tr data-shipment-uid="{{$shipment->uid}}"
+                        class="{{$shipment->is_cancelled ? 'bg-light' : ''}}">
                         <th class="border-right border-left-0">
                             <label class="d-flex align-items-center m-0">
                                 <input type="checkbox" class="my-0 mr-1 row-select">
@@ -81,23 +82,6 @@
     <script>
         (function() {
 
-            function applyFilters() {
-                let params = {}, queryLine = [];
-                $('[data-filter]').each(function() {
-                    if($.trim($(this).val())) {
-                        params[$(this).attr('data-filter')] = $.trim($(this).val());
-                    }
-                });
-                for(let x in params) {
-                    if(params.hasOwnProperty(x)) {
-                        queryLine.push(x + '=' + encodeURIComponent(params[x]));
-                    }
-                }
-                queryLine = queryLine.join('&');
-
-                fastLoad('/practice-management/shipments?' + queryLine);
-            }
-
             function updatePrintButton() {
                 let num = $('.row-select:checked').length;
                 $('#num-selected').text(num + ' shipment' + (num === 1 ? '' : 's') + ' selected');
@@ -109,18 +93,17 @@
                 }
             }
 
+            function hasError (_data) {
+                let msg = 'Unknown error!';
+                if (_data) {
+                    if (_data.success) return false;
+                    else if (_data.message) msg = _data.message;
+                }
+                toastr.error(msg);
+                return true;
+            }
+
             function init() {
-                $('select[data-filter]')
-                    .off('change')
-                    .on('change', applyFilters);
-                $('input[data-filter]')
-                    .off('keyup')
-                    .on('keyup', function(_event) {
-                        if(_event.which === 13) {
-                            applyFilters();
-                            return false;
-                        }
-                    });
                 $('#select-all')
                     .off('change')
                     .on('change', function() {
@@ -133,6 +116,36 @@
                         $('#select-all').prop('checked', $('.row-select:not(:checked)').length === 0);
                         updatePrintButton();
                     });
+                $('.print-row')
+                    .off('click')
+                    .on('click', function() {
+                        $.post('/api/shipment/setStatus', {
+                            uid: $(this).closest('tr').attr('data-shipment-uid'),
+                            status: 'PRINTED'
+                        }, (_data) => {
+                            if(!hasError(_data)) {
+                                fastReload();
+                            }
+                        }, 'json');
+                        // TODO: generate PDF
+                    });
+                $('#print-selected')
+                    .off('click')
+                    .on('click', function() {
+                        let uids = [];
+                        $('.row-select:checked').each(function() {
+                            uids.push($(this).closest('tr').attr('data-shipment-uid'));
+                        });
+                        $.post('/api/shipment/bulkUpdateStatus', {
+                            shipmentUids: uids.join('|'),
+                            status: 'PRINTED'
+                        }, (_data) => {
+                            if(!hasError(_data)) {
+                                fastReload();
+                            }
+                        }, 'json');
+                        // TODO: generate PDF
+                    });
             }
 
             addMCInitializer('practice-shipments-ready-to-print', init, '#practice-shipments-ready-to-print')