mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-15 23:57:48 +00:00
Merge pull request #4449 from luisramos0/properties
Move properties and product properties from spree_backend to OFN
This commit is contained in:
19
app/controllers/spree/admin/product_properties_controller.rb
Normal file
19
app/controllers/spree/admin/product_properties_controller.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
module Spree
|
||||
module Admin
|
||||
class ProductPropertiesController < ResourceController
|
||||
belongs_to 'spree/product', find_by: :permalink
|
||||
before_filter :find_properties
|
||||
before_filter :setup_property, only: [:index]
|
||||
|
||||
private
|
||||
|
||||
def find_properties
|
||||
@properties = Spree::Property.pluck(:name)
|
||||
end
|
||||
|
||||
def setup_property
|
||||
@product.product_properties.build
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
6
app/controllers/spree/admin/properties_controller.rb
Normal file
6
app/controllers/spree/admin/properties_controller.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
module Spree
|
||||
module Admin
|
||||
class PropertiesController < ResourceController
|
||||
end
|
||||
end
|
||||
end
|
||||
12
app/models/spree/property.rb
Normal file
12
app/models/spree/property.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
module Spree
|
||||
class Property < ActiveRecord::Base
|
||||
has_many :product_properties, dependent: :destroy
|
||||
has_many :products, through: :product_properties
|
||||
|
||||
attr_accessible :name, :presentation
|
||||
|
||||
validates :name, :presentation, presence: true
|
||||
|
||||
scope :sorted, -> { order(:name) }
|
||||
end
|
||||
end
|
||||
15
app/views/spree/admin/properties/_form.html.haml
Normal file
15
app/views/spree/admin/properties/_form.html.haml
Normal file
@@ -0,0 +1,15 @@
|
||||
.align-center.row
|
||||
.alpha.eight.columns
|
||||
= f.field_container :name do
|
||||
= f.label :name, t('.name')
|
||||
%span.required *
|
||||
%br/
|
||||
= f.text_field :name, class: 'fullwidth'
|
||||
= f.error_message_on :name
|
||||
.eight.columns.omega
|
||||
= f.field_container :presentation do
|
||||
= f.label :presentation, t('.presentation')
|
||||
%span.required *
|
||||
%br/
|
||||
= f.text_field :presentation, class: 'fullwidth'
|
||||
= f.error_message_on :presentation
|
||||
14
app/views/spree/admin/properties/edit.html.haml
Normal file
14
app/views/spree/admin/properties/edit.html.haml
Normal file
@@ -0,0 +1,14 @@
|
||||
= render partial: 'spree/admin/shared/product_sub_menu'
|
||||
|
||||
- content_for :page_title do
|
||||
= t('.editing_property')
|
||||
|
||||
- content_for :page_actions do
|
||||
%li= button_link_to t('.back_to_properties_list'), admin_properties_url, icon: 'icon-arrow-left'
|
||||
|
||||
= render partial: 'spree/shared/error_messages', locals: { target: @property }
|
||||
|
||||
= form_for [:admin, @property] do |f|
|
||||
%fieldset.no-border-top
|
||||
= render partial: 'form', locals: { f: f }
|
||||
= render partial: 'spree/admin/shared/edit_resource_links'
|
||||
30
app/views/spree/admin/properties/index.html.haml
Normal file
30
app/views/spree/admin/properties/index.html.haml
Normal file
@@ -0,0 +1,30 @@
|
||||
- content_for :page_title do
|
||||
= t('.properties')
|
||||
|
||||
- content_for :page_actions do
|
||||
%li#new_property_link
|
||||
= button_link_to t('.new_property'), new_admin_property_url, { remote: true, icon: 'icon-plus', 'data-update' => 'new_property', id: 'new_property_link' }
|
||||
|
||||
= render partial: 'spree/admin/shared/product_sub_menu'
|
||||
|
||||
#new_property
|
||||
%table#listing_properties.index
|
||||
%colgroup
|
||||
%col{style: "width: 45%"}/
|
||||
%col{style: "width: 45%"}/
|
||||
%col{style: "width: 10%"}/
|
||||
%thead
|
||||
%tr
|
||||
%th= t('.name')
|
||||
%th= t('.presentation')
|
||||
%th.actions
|
||||
%tbody
|
||||
- @properties.each do |property|
|
||||
- tr_class = cycle('odd', 'even')
|
||||
- tr_id = spree_dom_id(property)
|
||||
%tr{class: tr_class, id: tr_id}
|
||||
%td= property.name
|
||||
%td= property.presentation
|
||||
%td.actions
|
||||
= link_to_edit(property, no_text: true)
|
||||
= link_to_delete(property, no_text: true)
|
||||
10
app/views/spree/admin/properties/new.html.haml
Normal file
10
app/views/spree/admin/properties/new.html.haml
Normal file
@@ -0,0 +1,10 @@
|
||||
= render partial: 'spree/admin/shared/product_sub_menu'
|
||||
|
||||
= render partial: 'spree/shared/error_messages', locals: { target: @property }
|
||||
|
||||
= form_for [:admin, @property] do |f|
|
||||
%fieldset
|
||||
%legend{align: "center"}= t('.new_property')
|
||||
= render partial: 'form', locals: { f: f }
|
||||
.filter-actions
|
||||
= render partial: 'spree/admin/shared/new_resource_links'
|
||||
2
app/views/spree/admin/properties/new.js.erb
Normal file
2
app/views/spree/admin/properties/new.js.erb
Normal file
@@ -0,0 +1,2 @@
|
||||
$("#new_property").html('<%= escape_javascript(render :template => "spree/admin/properties/new", :formats => [:html], :handlers => [:erb]) %>');
|
||||
$("#new_property_link").parent().hide();
|
||||
@@ -2992,6 +2992,20 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
inherits_properties_checkbox_hint: "Inherit properties from %{supplier}? (unless overridden above)"
|
||||
add_product_properties: "Add Product Properties"
|
||||
select_from_prototype: "Select From Prototype"
|
||||
properties:
|
||||
index:
|
||||
properties: "Properties"
|
||||
new_property: "New Property"
|
||||
name: "Name"
|
||||
presentation: "Presentation"
|
||||
new:
|
||||
new_property: "New Property"
|
||||
edit:
|
||||
editing_property: "Editing Property"
|
||||
back_to_properties_list: "Back To Properties List"
|
||||
form:
|
||||
name: "Name"
|
||||
presentation: "Presentation"
|
||||
orders:
|
||||
index:
|
||||
listing_orders: "Listing Orders"
|
||||
|
||||
Reference in New Issue
Block a user