|
| 1 | +CheckoutHelper.module_eval do |
| 2 | + |
| 3 | + def checkout_states |
| 4 | + %w(address delivery payment confirm) |
| 5 | + end |
| 6 | + |
| 7 | + # TODO: this can be deleted from extension after Spree 0.70.0 release |
| 8 | + def checkout_progress |
| 9 | + states = checkout_states |
| 10 | + items = states.map do |state| |
| 11 | + css_class = "empty" |
| 12 | + current_index = states.index(@order.state) |
| 13 | + state_index = states.index(state) |
| 14 | + |
| 15 | + text = t("order_state.#{state}").titleize |
| 16 | + link = link_to "#{state_index + 1}. #{text}", checkout_state_path(state) |
| 17 | + |
| 18 | + if state == @order.state |
| 19 | + link = link_to "#{state_index + 1}. #{text}", "#" |
| 20 | + css_class = 'active' |
| 21 | + end |
| 22 | + |
| 23 | + content_tag('li', link, :class => css_class) if state_index <= current_index |
| 24 | + end |
| 25 | + content_tag('ul', raw(items.join("\n")), :class => 'nav nav-tabs checkout_states', :id => "checkout-step-#{@order.state}") |
| 26 | + end |
| 27 | + |
| 28 | + |
| 29 | + def address_field(form, method, id_prefix = "b", &handler) |
| 30 | + if handler |
| 31 | + handler.call |
| 32 | + else |
| 33 | + label = form.label(method, :class => "control-label") |
| 34 | + field = content_tag :div, :class => "controls" do |
| 35 | + form.text_field(method) |
| 36 | + end |
| 37 | + label + field |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + def address_state(form, country) |
| 42 | + country ||= Country.find(Spree::Config[:default_country_id]) |
| 43 | + have_states = !country.states.empty? |
| 44 | + state_elements = [ |
| 45 | + form.collection_select(:state_id, country.states.order(:name), |
| 46 | + :id, :name, |
| 47 | + {:include_blank => true}, |
| 48 | + {:style => have_states ? "" : "display:none", |
| 49 | + :disabled => !have_states}) + |
| 50 | + form.text_field(:state_name, |
| 51 | + :style => !have_states ? "" : "display:none", |
| 52 | + :disabled => have_states) |
| 53 | + ].join.gsub('"', "'").gsub("\n", "") |
| 54 | + |
| 55 | + content_tag :div, :class => "control-group" do |
| 56 | + label = form.label(:state, t(:state), :class => "control-label") |
| 57 | + field = content_tag :div, :class => "controls" do |
| 58 | + content_tag(:noscript, form.text_field(:state_name, :class => 'required')) + |
| 59 | + javascript_tag("document.write(\"#{state_elements.html_safe}\");") |
| 60 | + end |
| 61 | + label + field |
| 62 | + end |
| 63 | + |
| 64 | + |
| 65 | + end |
| 66 | + |
| 67 | + |
| 68 | +end |
| 69 | + |
0 commit comments