From bbfe9b22e33412cce94bc0a7a4a19eb6202424f7 Mon Sep 17 00:00:00 2001 From: Aleksandr Melentiev Date: Sun, 6 Jan 2013 13:25:34 -0800 Subject: [PATCH] Fix properties population when prototype selected and order them by position rather then alphabetically. Fixes #2389 --- core/app/models/spree/property.rb | 2 -- core/app/views/spree/admin/prototypes/_form.html.erb | 2 +- core/app/views/spree/admin/prototypes/select.js.erb | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core/app/models/spree/property.rb b/core/app/models/spree/property.rb index 0c5e6c2cf3c..8fd4fa9bb45 100644 --- a/core/app/models/spree/property.rb +++ b/core/app/models/spree/property.rb @@ -9,8 +9,6 @@ class Property < ActiveRecord::Base validates :name, :presentation, :presence => true - scope :sorted, lambda { order(:name) } - def self.find_all_by_prototype(prototype) id = prototype if prototype.class == Prototype diff --git a/core/app/views/spree/admin/prototypes/_form.html.erb b/core/app/views/spree/admin/prototypes/_form.html.erb index 4c29af3a836..a38b7265ac2 100644 --- a/core/app/views/spree/admin/prototypes/_form.html.erb +++ b/core/app/views/spree/admin/prototypes/_form.html.erb @@ -11,7 +11,7 @@
<%= f.field_container :property_ids do %> <%= f.label :property_ids, t(:properties) %>
- <%= f.select :property_ids, Spree::Property.sorted.map { |p| [p.presentation, p.id] }, {}, { :multiple => true, :class => "select2 fullwidth" } %> + <%= f.select :property_ids, Spree::Property.all.map { |p| [p.presentation, p.id] }, {}, { :multiple => true, :class => "select2 fullwidth" } %> <% end %>
diff --git a/core/app/views/spree/admin/prototypes/select.js.erb b/core/app/views/spree/admin/prototypes/select.js.erb index 1d601986349..493d431fada 100644 --- a/core/app/views/spree/admin/prototypes/select.js.erb +++ b/core/app/views/spree/admin/prototypes/select.js.erb @@ -1,4 +1,4 @@ -<% @prototype_properties.each do |prop| %> +<% @prototype_properties.sort_by{ |prop| -prop[:id] }.each do |prop| %> $("a.add_fields").click(); - $(".product_property.fields:last input:first").val("<%= prop.name %>"); + $(".product_property.fields:first input:first").val("<%= prop.name %>"); <% end %>