mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Cleaning up line items index (BOM)
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
angular.module("admin.indexUtils").directive "ignoreDirty", ->
|
||||
restrict: 'A'
|
||||
require: 'ngModel'
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
#TODO: This is broken, requires AngularJS > 1.3
|
||||
ngModel.$setDirty = angular.noop
|
||||
@@ -1,12 +1,12 @@
|
||||
angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $http, $q, Columns, Dereferencer, Orders, LineItems, Enterprises, OrderCycles, blankOption, VariantUnitManager, RequestMonitor) ->
|
||||
$scope.initialized = false
|
||||
$scope.RequestMonitor = RequestMonitor
|
||||
$scope.saving = false
|
||||
$scope.filteredLineItems = []
|
||||
$scope.confirmDelete = true
|
||||
$scope.startDate = formatDate daysFromToday -7
|
||||
$scope.endDate = formatDate daysFromToday 1
|
||||
$scope.bulkActions = [ { name: "Delete Selected", callback: $scope.deleteLineItems } ]
|
||||
$scope.selectedBulkAction = $scope.bulkActions[0]
|
||||
$scope.bulkActions = [ { name: "Delete Selected", callback: 'deleteLineItems' } ]
|
||||
$scope.selectedUnitsProduct = {};
|
||||
$scope.selectedUnitsVariant = {};
|
||||
$scope.sharedResource = false
|
||||
@@ -35,6 +35,10 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $http, $q
|
||||
$scope.quickSearch = ""
|
||||
|
||||
$scope.refreshData = ->
|
||||
unless $scope.orderCycleFilter == "0" || angular.equals(OrderCycles.orderCyclesByID, {})
|
||||
$scope.startDate = OrderCycles.orderCyclesByID[$scope.orderCycleFilter].first_order
|
||||
$scope.endDate = OrderCycles.orderCyclesByID[$scope.orderCycleFilter].last_order
|
||||
|
||||
RequestMonitor.load $scope.orders = Orders.index("q[state_not_eq]": "canceled", "q[completed_at_not_null]": "true", "q[completed_at_gt]": "#{$scope.startDate}", "q[completed_at_lt]": "#{$scope.endDate}")
|
||||
RequestMonitor.load $scope.distributors = Enterprises.index(action: "for_line_items", ams_prefix: "basic", "q[sells_in][]": ["own", "any"] )
|
||||
RequestMonitor.load $scope.orderCycles = OrderCycles.index(ams_prefix: "basic", as: "distributor", "q[orders_close_at_gt]": "#{formatDate(daysFromToday(-90))}")
|
||||
@@ -51,23 +55,25 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $http, $q
|
||||
$scope.orderCycles.unshift blankOption()
|
||||
$scope.suppliers.unshift blankOption()
|
||||
$scope.distributors.unshift blankOption()
|
||||
$scope.bulk_order_form.$setPristine()
|
||||
unless $scope.initialized
|
||||
$scope.initialized = true
|
||||
$scope.resetSelectFilters()
|
||||
|
||||
$scope.refreshData()
|
||||
|
||||
$scope.submit = ->
|
||||
$scope.submit = =>
|
||||
if $scope.bulk_order_form.$valid
|
||||
$scope.saving = true
|
||||
$q.all(LineItems.saveAll()).then ->
|
||||
$scope.bulk_order_form.$setPristine()
|
||||
$scope.saving = false
|
||||
else
|
||||
alert "Some errors must be resolved be before you can update orders.\nAny fields with red borders contain errors."
|
||||
|
||||
$scope.deleteLineItem = (lineItem) ->
|
||||
if ($scope.confirmDelete && confirm("Are you sure?")) || !$scope.confirmDelete
|
||||
LineItems.delete(lineItem).then ->
|
||||
LineItems.delete lineItem, =>
|
||||
$scope.lineItems.splice $scope.lineItems.indexOf(lineItem), 1
|
||||
|
||||
$scope.deleteLineItems = (lineItems) ->
|
||||
|
||||
@@ -4,11 +4,7 @@
|
||||
|
||||
= render :partial => 'spree/admin/shared/order_sub_menu'
|
||||
|
||||
=admin_inject_spree_api_key
|
||||
|
||||
%div{ ng: { app: 'ofn.admin', controller: 'AdminOrderMgmtCtrl', init: 'initialise()' } }
|
||||
%div{ 'ng-show' => '!spree_api_key_ok' }
|
||||
{{ api_error_msg }}
|
||||
%div{ ng: { app: 'admin.lineItems', controller: 'LineItemsCtrl' } }
|
||||
%save-bar{ save: "submit()", saving: 'saving', dirty: "bulk_order_form.$dirty" }
|
||||
.filters{ :class => "sixteen columns alpha" }
|
||||
.date_filter{ :class => "two columns alpha" }
|
||||
@@ -35,7 +31,7 @@
|
||||
.filter_clear{ :class => "two columns omega" }
|
||||
%label{ :for => 'clear_all_filters' }
|
||||
%br
|
||||
%input.fullwidth{ :type => 'button', :id => 'clear_all_filters', :value => "Clear All", 'ng-click' => "resetSelectFilters()" }
|
||||
%input.red.fullwidth{ :type => 'button', :id => 'clear_all_filters', :value => "Clear All", 'ng-click' => "resetSelectFilters()" }
|
||||
%hr{ :class => "sixteen columns alpha", 'ng-show' => 'unitsVariantSelected()' }
|
||||
%div#group_buy_calculation{ :class => "sixteen columns alpha", 'ng-show' => 'unitsVariantSelected()' }
|
||||
%div.shared_resource{ :class => "four columns alpha" }
|
||||
@@ -84,7 +80,7 @@
|
||||
%span{ :class => 'icon-check' } Actions
|
||||
%span{ 'ng-class' => "expanded && 'icon-caret-up' || !expanded && 'icon-caret-down'" }
|
||||
%div.menu{ 'ng-show' => "expanded" }
|
||||
%div.menu_item{ :class => "three columns alpha", 'ng-repeat' => "action in bulkActions", 'ng-click' => "selectedBulkAction.callback(filteredLineItems)", 'ofn-close-on-click' => true }
|
||||
%div.menu_item{ :class => "three columns alpha", 'ng-repeat' => "action in bulkActions", 'ng-click' => "$eval(action.callback)(filteredLineItems)", 'ofn-close-on-click' => true }
|
||||
%span{ :class => 'three columns omega' } {{action.name }}
|
||||
%div{ :class => "seven columns" }
|
||||
%div{ :class => "three columns omega" }
|
||||
@@ -135,7 +131,7 @@
|
||||
%input{ :type => 'checkbox', 'ng-model' => "confirmDelete" }
|
||||
%tr.line_item{ 'ng-repeat' => "line_item in filteredLineItems = ( lineItems | filter:quickSearch | selectFilter:supplierFilter:distributorFilter:orderCycleFilter | variantFilter:selectedUnitsProduct:selectedUnitsVariant:sharedResource | orderBy:predicate:reverse )", 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", :id => "li_{{line_item.id}}" }
|
||||
%td.bulk
|
||||
%input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'line_item.checked' }
|
||||
%input{ :type => "checkbox", :name => 'bulk', 'ng-model' => 'line_item.checked', 'ignore-dirty' => true }
|
||||
%td.order_no{ 'ng-show' => 'columns.order_no.visible' } {{ line_item.order.number }}
|
||||
%td.full_name{ 'ng-show' => 'columns.full_name.visible' } {{ line_item.order.full_name }}
|
||||
%td.email{ 'ng-show' => 'columns.email.visible' } {{ line_item.order.email }}
|
||||
|
||||
Reference in New Issue
Block a user