mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-23 05:28:53 +00:00
Create angularjs admin module
This commit is contained in:
3
app/assets/javascripts/admin/admin.js.coffee
Normal file
3
app/assets/javascripts/admin/admin.js.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
Admin = angular.module("ofn.admin", ["ngResource", "ofn.shared_services", "ofn.shared_directives"]).config ($httpProvider) ->
|
||||
$httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"
|
||||
@@ -1,16 +1,7 @@
|
||||
orderManagementModule = angular.module("ofn.bulk_order_management", ["ofn.shared_services", "ofn.shared_directives", "ofn.dropdown"])
|
||||
|
||||
orderManagementModule.config [
|
||||
"$httpProvider"
|
||||
(provider) ->
|
||||
provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
provider.defaults.headers.common["Accept"] = "application/json"
|
||||
]
|
||||
|
||||
orderManagementModule.value "blankOption", ->
|
||||
Admin.value "blankOption", ->
|
||||
{ id: "0", name: "All" }
|
||||
|
||||
orderManagementModule.directive "ofnLineItemUpdAttr", [
|
||||
Admin.directive "ofnLineItemUpdAttr", [
|
||||
"switchClass", "pendingChanges"
|
||||
(switchClass, pendingChanges) ->
|
||||
require: "ngModel"
|
||||
@@ -34,14 +25,14 @@ orderManagementModule.directive "ofnLineItemUpdAttr", [
|
||||
switchClass( element, "update-pending", ["update-error", "update-success"], false )
|
||||
]
|
||||
|
||||
orderManagementModule.directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) ->
|
||||
Admin.directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) ->
|
||||
restrict: "A"
|
||||
link: (scope, element, attrs) ->
|
||||
handler = ofnConfirmHandler scope, -> scope.fetchOrders()
|
||||
scope.$watch attrs.ngModel, (oldValue,newValue) ->
|
||||
handler() unless oldValue == undefined || newValue == oldValue
|
||||
|
||||
orderManagementModule.directive "ofnConfirmLinkPath", (ofnConfirmHandler) ->
|
||||
Admin.directive "ofnConfirmLinkPath", (ofnConfirmHandler) ->
|
||||
restrict: "A"
|
||||
scope:
|
||||
path: "@ofnConfirmLinkPath"
|
||||
@@ -49,7 +40,7 @@ orderManagementModule.directive "ofnConfirmLinkPath", (ofnConfirmHandler) ->
|
||||
element.click ofnConfirmHandler scope, ->
|
||||
window.location = scope.path
|
||||
|
||||
orderManagementModule.factory "ofnConfirmHandler", (pendingChanges, $compile, $q) ->
|
||||
Admin.factory "ofnConfirmHandler", (pendingChanges, $compile, $q) ->
|
||||
return (scope, callback) ->
|
||||
template = "<div id='dialog-div' style='padding: 10px'><h6>Unsaved changes currently exist, save now or ignore?</h6></div>"
|
||||
dialogDiv = $compile(template)(scope)
|
||||
@@ -74,7 +65,7 @@ orderManagementModule.factory "ofnConfirmHandler", (pendingChanges, $compile, $q
|
||||
else
|
||||
callback()
|
||||
|
||||
orderManagementModule.factory "pendingChanges",[
|
||||
Admin.factory "pendingChanges",[
|
||||
"dataSubmitter"
|
||||
(dataSubmitter) ->
|
||||
pendingChanges: {}
|
||||
@@ -108,7 +99,7 @@ orderManagementModule.factory "pendingChanges",[
|
||||
]
|
||||
|
||||
|
||||
orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
Admin.controller "AdminOrderMgmtCtrl", [
|
||||
"$scope", "$http", "dataFetcher", "blankOption", "pendingChanges"
|
||||
($scope, $http, dataFetcher, blankOption, pendingChanges) ->
|
||||
|
||||
@@ -290,7 +281,7 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
$scope.quickSearch = ""
|
||||
]
|
||||
|
||||
orderManagementModule.filter "selectFilter", (blankOption) ->
|
||||
Admin.filter "selectFilter", (blankOption) ->
|
||||
return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle) ->
|
||||
filtered = []
|
||||
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,"0") || lineItem.supplier.id == selectedSupplier) &&
|
||||
@@ -298,7 +289,7 @@ orderManagementModule.filter "selectFilter", (blankOption) ->
|
||||
(angular.equals(selectedOrderCycle,"0") || lineItem.order.order_cycle.id == selectedOrderCycle)
|
||||
filtered
|
||||
|
||||
orderManagementModule.filter "variantFilter", ->
|
||||
Admin.filter "variantFilter", ->
|
||||
return (lineItems,selectedUnitsProduct,selectedUnitsVariant,sharedResource) ->
|
||||
filtered = []
|
||||
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedUnitsProduct,{}) ||
|
||||
@@ -306,7 +297,7 @@ orderManagementModule.filter "variantFilter", ->
|
||||
filtered
|
||||
|
||||
|
||||
orderManagementModule.factory "dataSubmitter", [
|
||||
Admin.factory "dataSubmitter", [
|
||||
"$http", "$q", "switchClass"
|
||||
($http, $q, switchClass) ->
|
||||
return (changeObj) ->
|
||||
@@ -320,7 +311,7 @@ orderManagementModule.factory "dataSubmitter", [
|
||||
deferred.promise
|
||||
]
|
||||
|
||||
orderManagementModule.factory "switchClass", [
|
||||
Admin.factory "switchClass", [
|
||||
"$timeout"
|
||||
($timeout) ->
|
||||
return (element,classToAdd,removeClasses,timeout) ->
|
||||
|
||||
@@ -1,13 +1,4 @@
|
||||
productEditModule = angular.module("ofn.bulk_product_edit", ["ngResource", "ofn.shared_services", "ofn.shared_directives"])
|
||||
|
||||
productEditModule.config [
|
||||
"$httpProvider"
|
||||
(provider) ->
|
||||
provider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
provider.defaults.headers.common["Accept"] = "application/json"
|
||||
]
|
||||
|
||||
productEditModule.factory "Taxons", ($resource) ->
|
||||
Admin.factory "Taxons", ($resource) ->
|
||||
resource = $resource "/admin/taxons/search"
|
||||
|
||||
return {
|
||||
@@ -21,7 +12,7 @@ productEditModule.factory "Taxons", ($resource) ->
|
||||
data['taxons'].map (result) -> result
|
||||
}
|
||||
|
||||
productEditModule.directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
Admin.directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
# Adapted from Spree's existing taxon autocompletion
|
||||
require: "ngModel"
|
||||
link: (scope,element,attrs,ngModel) ->
|
||||
@@ -43,7 +34,7 @@ productEditModule.directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
scope.$apply ->
|
||||
ngModel.$setViewValue element.val()
|
||||
|
||||
productEditModule.directive "ofnDecimal", ->
|
||||
Admin.directive "ofnDecimal", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
numRegExp = /^\d+(\.\d+)?$/
|
||||
@@ -56,7 +47,7 @@ productEditModule.directive "ofnDecimal", ->
|
||||
viewValue
|
||||
|
||||
|
||||
productEditModule.directive "ofnTrackProduct", ['$parse', ($parse) ->
|
||||
Admin.directive "ofnTrackProduct", ['$parse', ($parse) ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
ngModel.$parsers.push (viewValue) ->
|
||||
@@ -68,7 +59,7 @@ productEditModule.directive "ofnTrackProduct", ['$parse', ($parse) ->
|
||||
]
|
||||
|
||||
|
||||
productEditModule.directive "ofnTrackVariant", ['$parse', ($parse) ->
|
||||
Admin.directive "ofnTrackVariant", ['$parse', ($parse) ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
ngModel.$parsers.push (viewValue) ->
|
||||
@@ -82,7 +73,7 @@ productEditModule.directive "ofnTrackVariant", ['$parse', ($parse) ->
|
||||
viewValue
|
||||
]
|
||||
|
||||
productEditModule.directive "ofnToggleVariants", ->
|
||||
Admin.directive "ofnToggleVariants", ->
|
||||
link: (scope, element, attrs) ->
|
||||
if scope.displayProperties[scope.product.id].showVariants
|
||||
element.removeClass "icon-chevron-right"
|
||||
@@ -101,7 +92,7 @@ productEditModule.directive "ofnToggleVariants", ->
|
||||
element.removeClass "icon-chevron-right"
|
||||
element.addClass "icon-chevron-down"
|
||||
|
||||
productEditModule.controller "AdminProductEditCtrl", [
|
||||
Admin.controller "AdminProductEditCtrl", [
|
||||
"$scope", "$timeout", "$http", "dataFetcher"
|
||||
($scope, $timeout, $http, dataFetcher) ->
|
||||
$scope.updateStatusMessage =
|
||||
@@ -525,7 +516,7 @@ productEditModule.controller "AdminProductEditCtrl", [
|
||||
Object.keys($scope.dirtyProducts).length
|
||||
]
|
||||
|
||||
productEditModule.filter "rangeArray", ->
|
||||
Admin.filter "rangeArray", ->
|
||||
return (input,start,end) ->
|
||||
input.push(i) for i in [start..end]
|
||||
input
|
||||
|
||||
Reference in New Issue
Block a user