mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Angularise payment method provider UI
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
angular.module("ofn.admin").controller "ProvidersCtrl", ($scope, paymentMethod) ->
|
||||
$scope.include_html = "/admin/payment_methods/#{paymentMethod.id}/show_provider_preferences?provider_type=#{paymentMethod.type}"
|
||||
@@ -0,0 +1,5 @@
|
||||
angular.module("ofn.admin").directive "ofnFetchProviderPrefs", ($http) ->
|
||||
link: (scope, element, attrs) ->
|
||||
element.on "change blur", ->
|
||||
scope.$apply ->
|
||||
scope.include_html = "/admin/payment_methods/#{attrs.ofnFetchProviderPrefs}/show_provider_preferences?provider_type=#{element.val()}"
|
||||
@@ -1,32 +1,46 @@
|
||||
Spree::Admin::PaymentMethodsController.class_eval do
|
||||
before_filter :load_hubs, only: [:new, :edit, :create, :update]
|
||||
module Spree
|
||||
module Admin
|
||||
PaymentMethodsController.class_eval do
|
||||
before_filter :load_hubs, only: [:new, :edit, :create, :update]
|
||||
|
||||
# Only show payment methods that user has access to and sort by distributor name
|
||||
# ! Redundant code copied from Spree::Admin::ResourceController with modifications marked
|
||||
def collection
|
||||
return parent.send(controller_name) if parent_data.present?
|
||||
collection = if model_class.respond_to?(:accessible_by) &&
|
||||
!current_ability.has_block?(params[:action], model_class)
|
||||
# Only show payment methods that user has access to and sort by distributor name
|
||||
# ! Redundant code copied from Spree::Admin::ResourceController with modifications marked
|
||||
def collection
|
||||
return parent.send(controller_name) if parent_data.present?
|
||||
collection = if model_class.respond_to?(:accessible_by) &&
|
||||
!current_ability.has_block?(params[:action], model_class)
|
||||
|
||||
model_class.accessible_by(current_ability, action)
|
||||
model_class.accessible_by(current_ability, action)
|
||||
|
||||
else
|
||||
model_class.scoped
|
||||
end
|
||||
else
|
||||
model_class.scoped
|
||||
end
|
||||
|
||||
collection = collection.managed_by(spree_current_user).by_name # This line added
|
||||
collection = collection.managed_by(spree_current_user).by_name # This line added
|
||||
|
||||
# This block added
|
||||
if params.key? :enterprise_id
|
||||
distributor = Enterprise.find params[:enterprise_id]
|
||||
collection = collection.for_distributor(distributor)
|
||||
# This block added
|
||||
if params.key? :enterprise_id
|
||||
distributor = Enterprise.find params[:enterprise_id]
|
||||
collection = collection.for_distributor(distributor)
|
||||
end
|
||||
|
||||
collection
|
||||
end
|
||||
|
||||
def show_provider_preferences
|
||||
@payment_method = PaymentMethod.find(params[:id])
|
||||
payment_method_type = params[:provider_type]
|
||||
if @payment_method['type'].to_s != payment_method_type
|
||||
@payment_method.update_column(:type, payment_method_type)
|
||||
@payment_method = PaymentMethod.find(params[:id])
|
||||
end
|
||||
render partial: 'provider_settings'
|
||||
end
|
||||
|
||||
private
|
||||
def load_hubs
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@payment_method.has_distributor? d) ? 0 : 1, d.name] }
|
||||
end
|
||||
end
|
||||
|
||||
collection
|
||||
end
|
||||
|
||||
private
|
||||
def load_hubs
|
||||
@hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@payment_method.has_distributor? d) ? 0 : 1, d.name] }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ class AbilityDecorator
|
||||
|
||||
# Enterprise User can only access payment methods for their distributors
|
||||
can [:index, :create], Spree::PaymentMethod
|
||||
can [:admin, :read, :update, :fire, :resend, :destroy], Spree::PaymentMethod do |payment_method|
|
||||
can [:admin, :read, :update, :fire, :resend, :destroy, :show_provider_preferences], Spree::PaymentMethod do |payment_method|
|
||||
(user.enterprises & payment_method.distributors).any?
|
||||
end
|
||||
|
||||
|
||||
@@ -33,17 +33,4 @@
|
||||
= radio_button :payment_method, :active, false
|
||||
|
||||
= label_tag nil, t(:say_no)
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= f.label :type, t(:provider)
|
||||
.omega.eight.columns
|
||||
= collection_select(:payment_method, :type, @providers, :to_s, :clean_name, {}, {:id => 'gtwy-type', :class => 'select2 fullwidth'})
|
||||
|
||||
%fieldset.alpha.eleven.columns.no-border-bottom#gateway_fields
|
||||
%legend{ align="center"}
|
||||
= t(:provider_settings)
|
||||
#preference-settings
|
||||
- unless @object.new_record?
|
||||
= preference_fields(@object, f)
|
||||
- if @object.respond_to?(:preferences)
|
||||
#gateway-settings-warning.info.warning= t(:provider_settings_warning)
|
||||
= render 'providers'
|
||||
@@ -0,0 +1,7 @@
|
||||
- if @payment_method.preferences.present?
|
||||
%fieldset.alpha.eleven.columns.no-border-bottom#gateway_fields
|
||||
%legend{ align: "center"}
|
||||
= t(:provider_settings)
|
||||
.preference-settings
|
||||
= fields_for :payment_method, @payment_method do |payment_method_form|
|
||||
= preference_fields(@payment_method, payment_method_form)
|
||||
10
app/views/spree/admin/payment_methods/_providers.html.haml
Normal file
10
app/views/spree/admin/payment_methods/_providers.html.haml
Normal file
@@ -0,0 +1,10 @@
|
||||
:javascript
|
||||
angular.module('ofn.admin').value('paymentMethod', #{ { id: @payment_method.id, type: @payment_method.type }.to_json })
|
||||
#provider-settings{ ng: { app: "ofn.admin", controller: "ProvidersCtrl" } }
|
||||
.row
|
||||
.alpha.three.columns
|
||||
= label :payment_method, :type, t(:provider)
|
||||
.omega.eight.columns
|
||||
= collection_select(:payment_method, :type, @providers, :to_s, :clean_name, {}, { class: 'select2 fullwidth', 'ofn-fetch-provider-prefs' => "#{@object.id}"})
|
||||
|
||||
%div{"ng-include" => "include_html" }
|
||||
@@ -135,6 +135,10 @@ Spree::Core::Engine.routes.prepend do
|
||||
|
||||
post :bulk_update, :on => :collection, :as => :bulk_update
|
||||
end
|
||||
|
||||
resources :payment_methods do
|
||||
get :show_provider_preferences, on: :member
|
||||
end
|
||||
end
|
||||
|
||||
resources :orders do
|
||||
|
||||
Reference in New Issue
Block a user