mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-12 23:27:48 +00:00
Merge branch 'new-product-form'
Conflicts: app/assets/javascripts/admin/admin.js.coffee
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
window.Admin = angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown"]).config ($httpProvider) ->
|
||||
angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown"]).config ($httpProvider) ->
|
||||
$httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"
|
||||
@@ -16,5 +16,6 @@
|
||||
//= require admin/spree_auth
|
||||
//= require admin/spree_promo
|
||||
//= require ./admin
|
||||
//= require ./products/products
|
||||
|
||||
//= require_tree .
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.controller "AdminOrderMgmtCtrl", [
|
||||
angular.module("ofn.admin").controller "AdminOrderMgmtCtrl", [
|
||||
"$scope", "$http", "dataFetcher", "blankOption", "pendingChanges"
|
||||
($scope, $http, dataFetcher, blankOption, pendingChanges) ->
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.controller "AdminProductEditCtrl", [
|
||||
angular.module("ofn.admin").controller "AdminProductEditCtrl", [
|
||||
"$scope", "$timeout", "$http", "dataFetcher", "DirtyProducts"
|
||||
($scope, $timeout, $http, dataFetcher, DirtyProducts) ->
|
||||
$scope.updateStatusMessage =
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
angular.module("ofn.admin").controller "enterprisesDashboardCtrl", [
|
||||
"$scope"
|
||||
($scope) ->
|
||||
$scope.activeTab = "hubs"
|
||||
]
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnConfirmLinkPath", (ofnConfirmHandler) ->
|
||||
angular.module("ofn.admin").directive "ofnConfirmLinkPath", (ofnConfirmHandler) ->
|
||||
restrict: "A"
|
||||
scope:
|
||||
path: "@ofnConfirmLinkPath"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) ->
|
||||
angular.module("ofn.admin").directive "ofnConfirmModelChange", (ofnConfirmHandler,$timeout) ->
|
||||
restrict: "A"
|
||||
link: (scope, element, attrs) ->
|
||||
handler = ofnConfirmHandler scope, -> scope.fetchOrders()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "datepicker", ->
|
||||
angular.module("ofn.admin").directive "datepicker", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
element.datepicker
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "datetimepicker", ->
|
||||
angular.module("ofn.admin").directive "datetimepicker", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
element.datetimepicker
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnDecimal", ->
|
||||
angular.module("ofn.admin").directive "ofnDecimal", ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
numRegExp = /^\d+(\.\d+)?$/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnLineItemUpdAttr", [
|
||||
angular.module("ofn.admin").directive "ofnLineItemUpdAttr", [
|
||||
"switchClass", "pendingChanges"
|
||||
(switchClass, pendingChanges) ->
|
||||
require: "ngModel"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnSelect2MinSearch", ->
|
||||
angular.module("ofn.admin").directive "ofnSelect2MinSearch", ->
|
||||
require: 'ngModel'
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
element.select2
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
# Adapted from Spree's existing taxon autocompletion
|
||||
require: "ngModel"
|
||||
link: (scope,element,attrs,ngModel) ->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnToggleColumn", ->
|
||||
angular.module("ofn.admin").directive "ofnToggleColumn", ->
|
||||
link: (scope, element, attrs) ->
|
||||
element.addClass "selected" if scope.column.visible
|
||||
element.click "click", ->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnToggleVariants", ->
|
||||
angular.module("ofn.admin").directive "ofnToggleVariants", ->
|
||||
link: (scope, element, attrs) ->
|
||||
if scope.displayProperties[scope.product.id].showVariants
|
||||
element.removeClass "icon-chevron-right"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnTrackProduct", ["DirtyProducts", (DirtyProducts) ->
|
||||
angular.module("ofn.admin").directive "ofnTrackProduct", ["DirtyProducts", (DirtyProducts) ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
ngModel.$parsers.push (viewValue) ->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.directive "ofnTrackVariant", ["DirtyProducts", (DirtyProducts) ->
|
||||
angular.module("ofn.admin").directive "ofnTrackVariant", ["DirtyProducts", (DirtyProducts) ->
|
||||
require: "ngModel"
|
||||
link: (scope, element, attrs, ngModel) ->
|
||||
ngModel.$parsers.push (viewValue) ->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.filter "rangeArray", ->
|
||||
angular.module("ofn.admin").filter "rangeArray", ->
|
||||
return (input,start,end) ->
|
||||
input.push(i) for i in [start..end]
|
||||
input
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.filter "selectFilter", (blankOption) ->
|
||||
angular.module("ofn.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) &&
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.filter "variantFilter", ->
|
||||
angular.module("ofn.admin").filter "variantFilter", ->
|
||||
return (lineItems,selectedUnitsProduct,selectedUnitsVariant,sharedResource) ->
|
||||
filtered = []
|
||||
filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedUnitsProduct,{}) ||
|
||||
|
||||
1
app/assets/javascripts/admin/products/products.js.coffee
Normal file
1
app/assets/javascripts/admin/products/products.js.coffee
Normal file
@@ -0,0 +1 @@
|
||||
angular.module("admin.products", [])
|
||||
@@ -0,0 +1,46 @@
|
||||
angular.module("admin.products")
|
||||
.controller "unitsCtrl", ($scope) ->
|
||||
$scope.product = { master: {} }
|
||||
|
||||
$scope.$watch ->
|
||||
$scope.product.variant_unit_with_scale
|
||||
, ->
|
||||
if $scope.product.variant_unit_with_scale
|
||||
match = $scope.product.variant_unit_with_scale.match(/^([^_]+)_([\d\.]+)$/)
|
||||
if match
|
||||
$scope.product.variant_unit = match[1]
|
||||
$scope.product.variant_unit_scale = parseFloat(match[2])
|
||||
else
|
||||
$scope.product.variant_unit = $scope.product.variant_unit_with_scale
|
||||
$scope.product.variant_unit_scale = null
|
||||
else
|
||||
$scope.product.variant_unit = $scope.product.variant_unit_scale = null
|
||||
|
||||
$scope.$watch ->
|
||||
$scope.product.master.unit_value_with_description
|
||||
, ->
|
||||
if $scope.product.master.hasOwnProperty("unit_value_with_description")
|
||||
match = $scope.product.master.unit_value_with_description.match(/^([\d\.]+(?= |$)|)( |)(.*)$/)
|
||||
if match
|
||||
$scope.product.master.unit_value = parseFloat(match[1])
|
||||
$scope.product.master.unit_value = null if isNaN($scope.product.master.unit_value)
|
||||
$scope.product.master.unit_value *= $scope.product.variant_unit_scale if $scope.product.master.unit_value && $scope.product.variant_unit_scale
|
||||
$scope.product.master.unit_description = match[3]
|
||||
|
||||
$scope.variant_unit_options = [
|
||||
["Weight (g)", "weight_1"],
|
||||
["Weight (kg)", "weight_1000"],
|
||||
["Weight (T)", "weight_1000000"],
|
||||
["Volume (mL)", "volume_0.001"],
|
||||
["Volume (L)", "volume_1"],
|
||||
["Volume (ML)", "volume_1000000"],
|
||||
["Items", "items"]
|
||||
]
|
||||
|
||||
$scope.hasVariants = (product) ->
|
||||
Object.keys(product.variants).length > 0
|
||||
|
||||
$scope.hasUnit = (product) ->
|
||||
product.variant_unit_with_scale?
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
Admin.value "blankOption", ->
|
||||
angular.module("ofn.admin").value "blankOption", ->
|
||||
{ id: "0", name: "All" }
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.factory "ofnConfirmHandler", (pendingChanges, $compile, $q) ->
|
||||
angular.module("ofn.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)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.factory "dataFetcher", [
|
||||
angular.module("ofn.admin").factory "dataFetcher", [
|
||||
"$http", "$q"
|
||||
($http, $q) ->
|
||||
return (dataLocation) ->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.factory "dataSubmitter", [
|
||||
angular.module("ofn.admin").factory "dataSubmitter", [
|
||||
"$http", "$q", "switchClass"
|
||||
($http, $q, switchClass) ->
|
||||
return (changeObj) ->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.factory "DirtyProducts", ($parse) ->
|
||||
angular.module("ofn.admin").factory "DirtyProducts", ($parse) ->
|
||||
# Temporary service to track changes in products on admin bulk product edit
|
||||
dirtyProducts = {}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.factory "pendingChanges",[
|
||||
angular.module("ofn.admin").factory "pendingChanges",[
|
||||
"dataSubmitter"
|
||||
(dataSubmitter) ->
|
||||
pendingChanges: {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.factory "switchClass", [
|
||||
angular.module("ofn.admin").factory "switchClass", [
|
||||
"$timeout"
|
||||
($timeout) ->
|
||||
return (element,classToAdd,removeClasses,timeout) ->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Admin.factory "Taxons", ($resource) ->
|
||||
angular.module("ofn.admin").factory "Taxons", ($resource) ->
|
||||
resource = $resource "/admin/taxons/search"
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user