mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	Add dialog for selection of stock location labels
This commit is contained in:
		@@ -29,7 +29,7 @@
 | 
				
			|||||||
            <button id='barcode-options' title='{% trans "Barcode actions" %}' class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown'><span class='fas fa-qrcode'></span> <span class='caret'></span></button>
 | 
					            <button id='barcode-options' title='{% trans "Barcode actions" %}' class='btn btn-default dropdown-toggle' type='button' data-toggle='dropdown'><span class='fas fa-qrcode'></span> <span class='caret'></span></button>
 | 
				
			||||||
            <ul class='dropdown-menu' role='menu'>
 | 
					            <ul class='dropdown-menu' role='menu'>
 | 
				
			||||||
                <li><a href='#' id='show-qr-code'><span class='fas fa-qrcode'></span> {% trans "Show QR Code" %}</a></li>
 | 
					                <li><a href='#' id='show-qr-code'><span class='fas fa-qrcode'></span> {% trans "Show QR Code" %}</a></li>
 | 
				
			||||||
                <li class='disabled'><a href='#' id='print-label'><span class='fas fa-tag'></span> {% trans "Print Label" %}</a></li>
 | 
					                <li><a href='#' id='print-label'><span class='fas fa-tag'></span> {% trans "Print Label" %}</a></li>
 | 
				
			||||||
                <li><a href='#' id='barcode-check-in'><span class='fas fa-arrow-right'></span> {% trans "Check-in Items" %}</a></li>
 | 
					                <li><a href='#' id='barcode-check-in'><span class='fas fa-arrow-right'></span> {% trans "Check-in Items" %}</a></li>
 | 
				
			||||||
            </ul>
 | 
					            </ul>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
@@ -203,6 +203,15 @@
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    $('#print-label').click(function() {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					        var locs = [{{ location.pk }}];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        printStockLocationLabels(locs);        
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {% endif %}
 | 
					    {% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $('#show-qr-code').click(function() {
 | 
					    $('#show-qr-code').click(function() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,7 +8,7 @@ function printStockItemLabels(items, options={}) {
 | 
				
			|||||||
    if (items.length == 0) {
 | 
					    if (items.length == 0) {
 | 
				
			||||||
        showAlertDialog(
 | 
					        showAlertDialog(
 | 
				
			||||||
            '{% trans "Select Stock Items" %}',
 | 
					            '{% trans "Select Stock Items" %}',
 | 
				
			||||||
            '{% trans "Stock items must be selected before printing labels" %}'
 | 
					            '{% trans "Stock item(s) must be selected before printing labels" %}'
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
@@ -29,16 +29,76 @@ function printStockItemLabels(items, options={}) {
 | 
				
			|||||||
                        '{% trans "No Labels Found" %}',
 | 
					                        '{% trans "No Labels Found" %}',
 | 
				
			||||||
                        '{% trans "No labels found which match selected stock item(s)" %}',
 | 
					                        '{% trans "No labels found which match selected stock item(s)" %}',
 | 
				
			||||||
                    );
 | 
					                    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return;
 | 
					                    return;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Select label to print
 | 
					                // Select label to print
 | 
				
			||||||
                selectLabel(response, items);
 | 
					                selectLabel(
 | 
				
			||||||
 | 
					                    response,
 | 
				
			||||||
 | 
					                    items,
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        success: function(pk) {
 | 
				
			||||||
 | 
					                            var href = `/api/label/stock/${pk}/print/?`;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					                            items.forEach(function(item) {
 | 
				
			||||||
 | 
					                                href += `items[]=${item}&`;
 | 
				
			||||||
 | 
					                            });
 | 
				
			||||||
 | 
					                    
 | 
				
			||||||
 | 
					                            window.location.href = href;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function printStockLocationLabels(locations, options={}) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (locations.length == 0) {
 | 
				
			||||||
 | 
					        showAlertDialog(
 | 
				
			||||||
 | 
					            '{% trans "Select Stock Locations" %}',
 | 
				
			||||||
 | 
					            '{% trans "Stock location(s) must be selected before printing labels" %}'
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Request available labels from the server
 | 
				
			||||||
 | 
					    inventreeGet(
 | 
				
			||||||
 | 
					        '{% url "api-stocklocation-label-list" %}',
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            enabled: true,
 | 
				
			||||||
 | 
					            locations: locations,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            success: function(response) {
 | 
				
			||||||
 | 
					                if (response.length == 0) {
 | 
				
			||||||
 | 
					                    showAlertDialog(
 | 
				
			||||||
 | 
					                        '{% trans "No Labels Found" %}',
 | 
				
			||||||
 | 
					                        '{% trans "No labels found which match selected stock location(s)" %}',
 | 
				
			||||||
 | 
					                    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    return;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Select label to print
 | 
				
			||||||
 | 
					                selectLabel(
 | 
				
			||||||
 | 
					                    response,
 | 
				
			||||||
 | 
					                    locations,
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        success: function(pk) {
 | 
				
			||||||
 | 
					                            // TODO - Print the label!
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                );
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function selectLabel(labels, items, options={}) {
 | 
					function selectLabel(labels, items, options={}) {
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Present the user with the available labels,
 | 
					     * Present the user with the available labels,
 | 
				
			||||||
@@ -48,8 +108,6 @@ function selectLabel(labels, items, options={}) {
 | 
				
			|||||||
     * (via AJAX) from the server.
 | 
					     * (via AJAX) from the server.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var stock_items = items;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    var modal = options.modal || '#modal-form';
 | 
					    var modal = options.modal || '#modal-form';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var label_list = makeOptionsList(
 | 
					    var label_list = makeOptionsList(
 | 
				
			||||||
@@ -102,12 +160,8 @@ function selectLabel(labels, items, options={}) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        closeModal(modal);
 | 
					        closeModal(modal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var href = `/api/label/stock/${pk}/print/?`;
 | 
					        if (options.success) {
 | 
				
			||||||
        
 | 
					            options.success(pk);
 | 
				
			||||||
        stock_items.forEach(function(item) {
 | 
					        }
 | 
				
			||||||
            href += `items[]=${item}&`;
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        window.location.href = href;
 | 
					 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user