Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/stash_engine/journal_admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def edit_params
:preprint_server, :journal_code, :manuscript_number_regex, :peer_review_custom_text, :sponsor_id,
:default_to_ppr, :allow_review_workflow, :flag, :note,
flag_attributes: %i[id note _destroy],
payment_configuration_attributes: %i[id payment_plan covers_ldf ldf_limit yearly_ldf_limit])
payment_configuration_attributes: %i[id payment_plan])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def index

def edit
@org = authorize StashEngine::JournalOrganization.find(params[:id])
@payment_configuration = @org.payment_configuration || @org.build_payment_configuration
respond_to(&:js)
end

Expand All @@ -42,6 +43,7 @@ def update

def new
@org = authorize StashEngine::JournalOrganization.new
@payment_configuration = @org.build_payment_configuration
respond_to(&:js)
end

Expand Down Expand Up @@ -73,15 +75,16 @@ def setup_sponsors
end

def update_hash
valid = %i[name parent_org_id]
valid = %i[name parent_org_id payment_configuration_attributes]
update = edit_params.slice(*valid)
update[:parent_org_id] = nil if edit_params.key?(:parent_org_id) && edit_params[:parent_org_id].blank?
update[:contact] = edit_params[:contact].split("\n").map(&:strip).to_json if edit_params[:contact]
update
end

def edit_params
params.permit(:id, :name, :contact, :parent_org_id)
params.permit(:id, :name, :contact, :parent_org_id,
payment_configuration_attributes: %i[id payment_plan covers_ldf ldf_limit yearly_ldf_limit])
end

end
Expand Down
2 changes: 2 additions & 0 deletions app/models/stash_engine/journal_organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class JournalOrganization < ApplicationRecord
has_many :journals_sponsored, class_name: 'StashEngine::Journal', foreign_key: :sponsor_id
has_many :roles, class_name: 'StashEngine::Role', as: :role_object, dependent: :destroy
has_many :users, through: :roles
has_one :payment_configuration, as: :partner, dependent: :destroy
accepts_nested_attributes_for(*%i[payment_configuration])

scope :has_children, -> { distinct.joins(:children) }

Expand Down
4 changes: 4 additions & 0 deletions app/services/sponsored_payments_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ def ldf_fees
end
FeeCalculatorService.new(payer_type).ldf_amount(resource: resource, payer: payer)
end

def sponsor_id
payer.sponsor_id
end
end
13 changes: 0 additions & 13 deletions app/views/stash_engine/journal_admin/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@
<br />
<% end %>
</fieldset>

<p>
<%= pf.check_box :covers_ldf, {checked: @payment_configuration.covers_ldf}, 1, 0 %>
<%= pf.label :covers_ldf, "When checked, journal covers Large Data Fees" %>
</p>
<p>
<%= pf.label :ldf_limit, "Covered Large Data Fee limit (GB)" %>
<%= pf.select :ldf_limit, ldf_pricing_tiers_options, { selected: @payment_configuration.ldf_limit }, class: 'c-input__select', disabled: !@payment_configuration.covers_ldf %>
</p>
<p>
<%= pf.label :yearly_ldf_limit, "Yearly Large Data Fee limit $" %>
<%= pf.number_field :yearly_ldf_limit, value: @payment_configuration.yearly_ldf_limit, class: 'c-input__text', disabled: !@payment_configuration.covers_ldf %>
</p>
<% end %>

<p class="o-admin-form-inline">
Expand Down
28 changes: 28 additions & 0 deletions app/views/stash_engine/journal_organization_admin/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
<%= form.label :name, "Name of publisher or society"%>
<%= form.text_field(:name, required: true, value: @org.name, class: 'c-input__text', style: 'width:100%') %>
</div>
<%= fields_for :payment_configuration_attributes do |pf| %>
<%= pf.hidden_field :id, value: @payment_configuration.id %>
<%
plan_radios = [ ['', 'None'] ] + StashEngine::Journal::PAYMENT_PLANS.map {|p| [p, p.capitalize]}
%>
<h2>Membership</h2>
<fieldset class="c-fieldset">
<legend>Payment plan type:</legend>
<% plan_radios.each do |plan| %>
<%= pf.radio_button :payment_plan, plan.first, checked: plan.first == @payment_configuration.payment_plan %>
<label for="<%= "payment_configuration_attributes_payment_plan_#{plan.first.downcase}" %>"><%= plan[1] %></label>
<br />
<% end %>
</fieldset>

<p>
<%= pf.check_box :covers_ldf, {checked: @payment_configuration.covers_ldf}, 1, 0 %>
<%= pf.label :covers_ldf, "When checked, journal covers Large Data Fees" %>
</p>
<p>
<%= pf.label :ldf_limit, "Covered Large Data Fee limit (GB)" %>
<%= pf.select :ldf_limit, ldf_pricing_tiers_options, { selected: @payment_configuration.ldf_limit }, class: 'c-input__select', disabled: !@payment_configuration.covers_ldf %>
</p>
<p>
<%= pf.label :yearly_ldf_limit, "Yearly Large Data Fee limit $" %>
<%= pf.number_field :yearly_ldf_limit, value: @payment_configuration.yearly_ldf_limit, class: 'c-input__text', disabled: !@payment_configuration.covers_ldf %>
</p>
<% end %>
<h2>Contacts</h2>
<div class="c-input">
<%= form.label :contact, "Place each email address on a new line:"%>
Expand Down
12 changes: 12 additions & 0 deletions app/views/stash_engine/journal_organization_admin/edit.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ document.getElementById('cancel_dialog').addEventListener('click', (e) => {
e.preventDefault();
document.getElementById('genericModalDialog').close();
});

var ldf = document.getElementById('payment_configuration_attributes_covers_ldf')
ldf.addEventListener('change', () => {
var limit = document.getElementById('payment_configuration_attributes_ldf_limit')
limit.disabled = !ldf.checked
var amount_limit = document.getElementById('payment_configuration_attributes_yearly_ldf_limit')
amount_limit.disabled = !ldf.checked
if (!ldf.checked) {
limit.value = ''
amount_limit.value = ''
}
})
12 changes: 12 additions & 0 deletions app/views/stash_engine/journal_organization_admin/new.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@ document.getElementById('cancel_dialog').addEventListener('click', (e) => {
e.preventDefault();
document.getElementById('genericModalDialog').close();
});

var ldf = document.getElementById('payment_configuration_attributes_covers_ldf')
ldf.addEventListener('change', () => {
var limit = document.getElementById('payment_configuration_attributes_ldf_limit')
limit.disabled = !ldf.checked
var amount_limit = document.getElementById('payment_configuration_attributes_yearly_ldf_limit')
amount_limit.disabled = !ldf.checked
if (!ldf.checked) {
limit.value = ''
amount_limit.value = ''
}
})
Loading
Loading