-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7c1e959
commit 4ebd9f9
Showing
8 changed files
with
176 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Spree | ||
module Admin | ||
module GoogleWalletsHelper | ||
# override | ||
def preference_fields(object, form) | ||
return unless object.respond_to?(:preferences) | ||
|
||
fields = object.preferences.keys.map do |key| | ||
next unless object.has_preference?(key) | ||
next if %i[response verified_at].include?(key) | ||
|
||
render_preference_field(object, form, key) | ||
end | ||
safe_join(fields) | ||
end | ||
|
||
private | ||
|
||
def render_preference_field(object, form, key) | ||
case key | ||
when :background_color | ||
render_background_color_field(object, form, key) | ||
when :start_date, :end_date | ||
render_date_field(object, form, key) | ||
when object.preference_type(key).to_sym == :boolean | ||
render_boolean_field(object, form, key) | ||
else | ||
render_default_field(object, form, key) | ||
end | ||
end | ||
|
||
def render_background_color_field(object, form, key) | ||
content_tag(:div, class: 'form-group', id: [object.class.to_s.parameterize, 'preference', key].join('-')) do | ||
form.label("preferred_#{key}", Spree.t(key), class: 'mb-2') + | ||
content_tag(:div, class: 'd-flex') do | ||
preference_field_for(form, "preferred_#{key}", type: object.preference_type(key), class: 'form-control mr-2') + | ||
content_tag(:div, '', class: 'color-preview', | ||
style: "background-color: #{object.preferred_background_color}; | ||
height: 40px; width: 50px; margin-left: 10px; | ||
border-radius: 5px; border: 1px solid #ccc;" | ||
) | ||
end | ||
end | ||
end | ||
|
||
def render_boolean_field(object, form, key) | ||
content_tag(:div, preference_field_for(form, "preferred_#{key}", type: object.preference_type(key)) + | ||
form.label("preferred_#{key}", Spree.t(key), class: 'form-check-label'), | ||
class: 'form-group form-check', id: [object.class.to_s.parameterize, 'preference', key].join('-') | ||
) | ||
end | ||
|
||
def render_date_field(object, form, key) | ||
content_tag(:div, class: 'form-group', id: "#{object.class.to_s.parameterize}-preference-#{key}") do | ||
form.label("preferred_#{key}", Spree.t(key), class: 'mb-2') + | ||
content_tag(:div, class: 'input-group datePickerTo', data: { | ||
wrap: 'true', 'alt-input': 'true', 'min-date': object.preferred_start_date, 'enable-time': 'true' | ||
} | ||
) do | ||
form.text_field("preferred_#{key}", value: object.send("preferred_#{key}"), class: 'form-control shadow-none', 'data-input' => '') | ||
end | ||
end | ||
end | ||
|
||
def render_default_field(object, form, key) | ||
content_tag(:div, form.label("preferred_#{key}", Spree.t(key)) + | ||
preference_field_for(form, "preferred_#{key}", type: object.preference_type(key)), | ||
class: 'form-group', id: [object.class.to_s.parameterize, 'preference', key].join('-') | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
<%= render partial: 'spree/admin/shared/product_tabs', locals: { current: :google_wallet } %> | ||
|
||
<div class="my-2 mx-1"> | ||
<%= button_to Spree.t(:create), create_google_wallet_class_admin_product_google_wallet_path(@product, @object.id), method: :post, class: 'btn bg-success text-white my-1' %> | ||
<%= button_to Spree.t(:update), update_google_wallet_class_admin_product_google_wallet_path(@product, @object), method: :patch, class: 'btn bg-success text-white my-1' %> | ||
<small class="form-text text-muted"> | ||
<%= raw I18n.t('google_wallet.note') %> | ||
</small> | ||
</div> | ||
|
||
<div data-hook="admin_product_google_wallet_edit_form_header"> | ||
<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @object } %> | ||
<div class="card card-body mb-3"> | ||
<div data-hook="active" class="form-group"> | ||
<strong><%= Spree.t(:verified) %></strong> | ||
<%= active_badge(@object.verified?) %> | ||
</div> | ||
|
||
<div data-hook="admin_product_google_wallet_edit_form"> | ||
<%= form_with model: @object, url: { action: 'update' } do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<div data-hook="admin_product_google_wallet_form_buttons"> | ||
<%= render partial: 'spree/admin/shared/edit_resource_links' %> | ||
<% if @object.verified_at.present? %> | ||
<div data-hook="verified-at" class="form-group"> | ||
<p><%= Spree.t(:verified_at) %>: <%= @object.verified_at %></p> | ||
</div> | ||
<% end %> | ||
|
||
<%= button_to Spree.t('verify_with_google_wallet'), | ||
verify_with_google_admin_product_google_wallet_path(@product, @object), | ||
method: :post, | ||
class: 'btn btn-outline-primary my-1', | ||
disabled: @object.verified? %> | ||
|
||
<% end %> | ||
<small class="form-text text-muted"> | ||
<%= raw I18n.t('google_wallet.note') %> | ||
</small> | ||
</div> | ||
|
||
|
||
<div data-hook="admin_product_google_wallet_edit_form_header"> | ||
<%= render partial: 'spree/admin/shared/error_messages', locals: { target: @object } %> | ||
<div data-hook="admin_product_google_wallet_edit_form"> | ||
<%= form_with model: @object, url: { action: 'update' } do |f| %> | ||
<%= render partial: 'form', locals: { f: f } %> | ||
<div data-hook="admin_product_google_wallet_form_buttons"> | ||
<%= render partial: 'spree/admin/shared/edit_resource_links' %> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters