Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

complete product labels

  • Loading branch information...
commit 94b8e1d3e841a3645be57c58909228662c677ff8 1 parent 236972f
tka authored
12 app/cells/product/labels.html.erb
View
@@ -1,7 +1,5 @@
-<h1>
- Product#label
-</h1>
-
-<p>
- Find me in app/cells/product/label.html.erb
-</p>
+<div id="product_lables">
+ <%@labels.each do |label| %>
+ <%=raw label.content%>
+ <% end %>
+</div>
34 app/controllers/spree/admin/labels_controller.rb
View
@@ -21,6 +21,40 @@ def create
render :new
end
end
+
+ def update
+ @label = Spree::ProductLabel.find(params[:id])
+ if @label.update_attributes(params[:product_label])
+ redirect_to :back, :notice => 'DONE!'
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @label = Spree::ProductLabel.find(params[:id])
+ @label.destroy
+ redirect_to :back, :notice => 'DONE!'
+ end
+
+ # for product
+ def available
+ @labels = Spree::ProductLabel.all
+ @product = Spree::Product.find_by_permalink!(params[:product_id])
+ end
+
+ def select
+ @product = Spree::Product.find_by_permalink!(params[:product_id])
+ @label = Spree::ProductLabel.find(params[:id])
+ @product.labels << @label
+ end
+
+ def remove
+ @product = Spree::Product.find_by_permalink!(params[:product_id])
+ @label = Spree::ProductLabel.find(params[:id])
+ @product.labels.delete(@label)
+ end
+
end
end
end
4 app/models/spree/product_additional_instruction.rb
View
@@ -1,3 +1,5 @@
class Spree::ProductAdditionalInstruction < ActiveRecord::Base
- has_and_belongs_to_many :products, :class_name => "Spree::Product"
+ has_and_belongs_to_many :products,
+ :class_name => "Spree::Product",
+ :join_table => "spree_product_additional_instructions_products"
end
8 app/overrides/add_labels_to_admin_product_tabs.rb
View
@@ -0,0 +1,8 @@
+Deface::Override.new(:virtual_path => "spree/admin/shared/_product_tabs",
+ :name => "add_labels_to_admin_product_tabs",
+ :insert_bottom => "[data-hook='admin_product_tabs'], #admin_product_tabs[data-hook]",
+ :text => " <li<%== ' class=\"active\"' if current == \"Labels\" %>>
+ <%= link_to t(\"labels\"), spree.available_admin_product_labels_path(@product) %>
+ </li>
+",
+ :disabled => false)
4 app/overrides/add_product_tabs.rb
View
@@ -2,8 +2,8 @@
:name => "add_product_tabs",
:insert_after => "code[erb-loud]:contains(':properties')",
:text => "
-<%= tab :labels %>
-<%= tab :links %>
+ <%= tab :labels, :match_path => '/labels' %>
+ <%= tab :links, :match_path => '/links' %>
",
:disabled => false)
19 app/views/spree/admin/labels/available.html.erb
View
@@ -0,0 +1,19 @@
+<%= render :partial => 'spree/admin/shared/product_sub_menu' %>
+
+<%= render :partial => 'spree/admin/shared/product_tabs', :locals => { :current => 'Labels' } %>
+
+<ul>
+ <% @labels.each do |label|%>
+ <li>
+ <%=check_box_tag :labels, label.id, @product.labels.exists?(label)%><%=label.name%>
+ </li>
+ <% end %>
+</ul>
+<script>
+ $(function(){
+ $('input[type=checkbox]').on('click',function(){
+ url=<%=raw admin_product_labels_path(@product).to_json%> + '/' + this.value + ( this.checked ? '/select' : '/remove')
+ $.get(url)
+ })
+ })
+</script>
16 config/routes.rb
View
@@ -1,6 +1,20 @@
Spree::Core::Engine.routes.draw do
namespace :admin do
+ resources :products do
+ resources :labels do
+ collection do
+ get :available
+ end
+ member do
+ get :select
+ get :remove
+ end
+
+ end
+ end
+ resources :links
+
resources :labels
resources :links
- end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.