mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 21:25:42 +00:00 
			
		
		
		
	Refactorin'
- Add the "download" button into the "filters" list - Cuts down on boilerplate code
This commit is contained in:
		| @@ -256,7 +256,7 @@ function generateFilterInput(tableKey, filterKey) { | ||||
|  * @param {*} table - bootstrapTable element to update | ||||
|  * @param {*} target - name of target element on page | ||||
|  */ | ||||
| function setupFilterList(tableKey, table, target) { | ||||
| function setupFilterList(tableKey, table, target, options={}) { | ||||
|  | ||||
|     var addClicked = false; | ||||
|  | ||||
| @@ -283,6 +283,11 @@ function setupFilterList(tableKey, table, target) { | ||||
|  | ||||
|     var buttons = ''; | ||||
|  | ||||
|     // Add download button | ||||
|     if (options.download) { | ||||
|         buttons += `<button id='download-${tableKey}' title='{% trans "Download data" %}' class='btn btn-outline-secondary filter-button'><span class='fas fa-download'></span></button>`; | ||||
|     } | ||||
|  | ||||
|     buttons += `<button id='reload-${tableKey}' title='{% trans "Reload data" %}' class='btn btn-outline-secondary filter-button'><span class='fas fa-redo-alt'></span></button>`; | ||||
|  | ||||
|     // If there are filters defined for this table, add more buttons | ||||
| @@ -295,7 +300,7 @@ function setupFilterList(tableKey, table, target) { | ||||
|     } | ||||
|  | ||||
|     element.html(` | ||||
|     <div class='btn-group' role='group'> | ||||
|     <div class='btn-group filter-group' role='group'> | ||||
|         ${buttons} | ||||
|     </div> | ||||
|     `); | ||||
| @@ -322,6 +327,13 @@ function setupFilterList(tableKey, table, target) { | ||||
|         $(table).bootstrapTable('refresh'); | ||||
|     }); | ||||
|  | ||||
|     // Add a callback for downloading table data | ||||
|     if (options.download) { | ||||
|         element.find(`#download-${tableKey}`).click(function() { | ||||
|             downloadTableData($(table)); | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     // Add a callback for adding a new filter | ||||
|     element.find(`#${add}`).click(function clicked() { | ||||
|  | ||||
|   | ||||
| @@ -1218,7 +1218,7 @@ function loadPartTable(table, url, options={}) { | ||||
|         filters[key] = params[key]; | ||||
|     } | ||||
|  | ||||
|     setupFilterList('parts', $(table), options.filterTarget || null); | ||||
|     setupFilterList('parts', $(table), options.filterTarget, {download: true}); | ||||
|  | ||||
|     var columns = [ | ||||
|         { | ||||
|   | ||||
| @@ -1571,7 +1571,7 @@ function loadStockTable(table, options) { | ||||
|         original[k] = params[k]; | ||||
|     } | ||||
|  | ||||
|     setupFilterList(filterKey, table, filterTarget); | ||||
|     setupFilterList(filterKey, table, filterTarget, {download: true}); | ||||
|  | ||||
|     // Override the default values, or add new ones | ||||
|     for (var key in params) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user