mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Moving taxons into its own module, adding preferred shopfront taxon order to enterprise
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown", "admin.products", "infinite-scroll"]).config ($httpProvider) ->
|
||||
angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown", "admin.products", "admin.taxons", "infinite-scroll"]).config ($httpProvider) ->
|
||||
$httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content")
|
||||
$httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*"
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
//= require ./products/products
|
||||
//= require ./shipping_methods/shipping_methods
|
||||
//= require ./side_menu/side_menu
|
||||
//= require ./taxons/taxons
|
||||
//= require ./utils/utils
|
||||
//= require ./users/users
|
||||
//= require textAngular.min.js
|
||||
|
||||
@@ -1 +1 @@
|
||||
angular.module("admin.enterprises", [
|
||||
angular.module("admin.enterprises", [
|
||||
@@ -1,9 +1,10 @@
|
||||
angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
angular.module("admin.taxons").directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
# Adapted from Spree's existing taxon autocompletion
|
||||
scope: true
|
||||
link: (scope,element,attrs) ->
|
||||
multiple = scope.$eval attrs.multipleSelection
|
||||
placeholder = attrs.placeholder
|
||||
initalSelection = scope.$eval attrs.ngModel
|
||||
|
||||
setTimeout ->
|
||||
element.select2
|
||||
@@ -11,9 +12,9 @@ angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) ->
|
||||
multiple: multiple
|
||||
initSelection: (element, callback) ->
|
||||
if multiple
|
||||
callback Taxons.findByIDs(scope.product.category_id)
|
||||
callback Taxons.findByIDs(initalSelection)
|
||||
else
|
||||
callback Taxons.findByID(scope.product.category_id)
|
||||
callback Taxons.findByID(initalSelection)
|
||||
query: (query) ->
|
||||
query.callback { results: Taxons.findByTerm(query.term) }
|
||||
formatResult: (taxon) ->
|
||||
@@ -1,4 +1,4 @@
|
||||
angular.module("ofn.admin").factory "Taxons", (taxons, $filter) ->
|
||||
angular.module("admin.taxons").factory "Taxons", (taxons, $filter) ->
|
||||
new class Taxons
|
||||
constructor: ->
|
||||
@taxons = taxons
|
||||
1
app/assets/javascripts/admin/taxons/taxons.js.coffee
Normal file
1
app/assets/javascripts/admin/taxons/taxons.js.coffee
Normal file
@@ -0,0 +1 @@
|
||||
angular.module("admin.taxons", [])
|
||||
@@ -3,6 +3,7 @@ module Admin
|
||||
before_filter :load_enterprise_set, :only => :index
|
||||
before_filter :load_countries, :except => :index
|
||||
before_filter :load_methods_and_fees, :only => [:new, :edit, :update, :create]
|
||||
before_filter :load_taxons, :only => [:new, :edit, :update, :create]
|
||||
before_filter :check_can_change_sells, only: :update
|
||||
before_filter :check_can_change_bulk_sells, only: :bulk_update
|
||||
before_filter :override_owner, only: :create
|
||||
@@ -89,6 +90,10 @@ module Admin
|
||||
@enterprise_fees = EnterpriseFee.managed_by(spree_current_user).for_enterprise(@enterprise).order(:fee_type, :name).all
|
||||
end
|
||||
|
||||
def load_taxons
|
||||
@taxons = Spree::Taxon.order(:name)
|
||||
end
|
||||
|
||||
def check_can_change_bulk_sells
|
||||
unless spree_current_user.admin?
|
||||
params[:enterprise_set][:collection_attributes].each do |i, enterprise_params|
|
||||
|
||||
@@ -42,7 +42,7 @@ module Admin
|
||||
end
|
||||
|
||||
def admin_inject_taxons
|
||||
admin_inject_json_ams_array "ofn.admin", "taxons", @taxons, Api::Admin::TaxonSerializer
|
||||
admin_inject_json_ams_array "admin.taxons", "taxons", @taxons, Api::Admin::TaxonSerializer
|
||||
end
|
||||
|
||||
def admin_inject_users
|
||||
|
||||
@@ -3,8 +3,9 @@ class Enterprise < ActiveRecord::Base
|
||||
SHOP_TRIAL_LENGTH = 30
|
||||
ENTERPRISE_SEARCH_RADIUS = 100
|
||||
|
||||
preference :shopfront_message, :text, default: ""
|
||||
preference :shopfront_closed_message, :text, default: ""
|
||||
preference :shopfront_message, :text, default: nil
|
||||
preference :shopfront_closed_message, :text, default: nil
|
||||
preference :shopfront_taxon_order, :string, default: nil
|
||||
|
||||
devise :confirmable, reconfirmable: true, confirmation_keys: [ :id, :email ]
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids
|
||||
attributes :producer_profile_only, :email, :long_description, :preferred_shopfront_message, :preferred_shopfront_closed_message
|
||||
attributes :producer_profile_only, :email, :long_description
|
||||
attributes :preferred_shopfront_message, :preferred_shopfront_closed_message, :preferred_shopfront_taxon_order
|
||||
end
|
||||
@@ -1,3 +1,4 @@
|
||||
= admin_inject_enterprise
|
||||
= admin_inject_taxons
|
||||
= admin_inject_payment_methods
|
||||
= admin_inject_shipping_methods
|
||||
@@ -1,7 +1,7 @@
|
||||
.row
|
||||
.alpha.eleven.columns
|
||||
.three.columns.alpha
|
||||
= f.label "preferred_shopfront_message", t(:shopfront_message)
|
||||
= f.label "enterprise_preferred_shopfront_message", t(:shopfront_message)
|
||||
.eight.columns.omega
|
||||
%text-angular{'ng-model' => 'Enterprise.preferred_shopfront_message', 'id' => 'enterprise_preferred_shopfront_message', 'name' => 'enterprise[preferred_shopfront_message]', 'class' => 'text-angular',
|
||||
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
|
||||
@@ -9,8 +9,17 @@
|
||||
.row
|
||||
.alpha.eleven.columns
|
||||
.three.columns.alpha
|
||||
= f.label "preferred_shopfront_closed_message", t(:shopfront_closed_message)
|
||||
= f.label "enterprise_preferred_shopfront_closed_message", t(:shopfront_closed_message)
|
||||
.eight.columns.omega
|
||||
%text-angular{'ng-model' => 'Enterprise.preferred_shopfront_closed_message', 'id' => 'enterprise_preferred_shopfront_closed_message', 'name' => 'enterprise[preferred_shopfront_closed_message]', 'class' => 'text-angular',
|
||||
'ta-toolbar' => "[['h1','h2','h3','h4','p'],['bold','italics','underline','clear'],['insertLink']]",
|
||||
'placeholder' => 'A message which provides a more detailed explanation about why your shop is closed and/or when customers can expect it to open again. This is displayed on your shop only when you have no active order cycles (ie. shop is closed).'}
|
||||
.row
|
||||
.alpha.eleven.columns
|
||||
.three.columns.alpha
|
||||
= f.label "enterprise_preferred_shopfront_taxon_order", t(:preferred_shopfront_taxon_order)
|
||||
%br
|
||||
(top to bottom)
|
||||
.eight.columns.omega
|
||||
%textarea.fullwidth{ id: 'enterprise_preferred_shopfront_taxon_order', name: 'enterprise[preferred_shopfront_taxon_order]', rows: 6, 'ng-model' => 'Enterprise.preferred_shopfront_taxon_order', 'ofn-taxon-autocomplete' => '', 'multiple-selection' => 'true', placeholder: 'Category' }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user