-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #499 from coopdevs/develop
Release v1.14.0
- Loading branch information
Showing
70 changed files
with
1,140 additions
and
195 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
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
$( document ).ready(function () { | ||
jQuery.validator.addMethod( | ||
"either-hours-minutes-informed", | ||
function (value, element) { | ||
return Boolean($("#transfer_hours").val() || $("#transfer_minutes").val()); | ||
}, | ||
"Hours or minutes should be informed" | ||
); | ||
|
||
function submitHandler(form) { | ||
// just submit when fields are not visible, in order to not break the multi | ||
// transfer wizard | ||
if (!$("#transfer_hours").is(":visible")) { | ||
form.submit(); | ||
return; | ||
} | ||
|
||
var amount = $("#transfer_hours").val() * 3600 + $("#transfer_minutes").val() * 60; | ||
$("#transfer_amount").val(amount); | ||
|
||
if (amount == 0) { | ||
$(form).find('.js-error-amount').removeClass('invisible').show(); | ||
return; | ||
} | ||
|
||
if ($(form).valid()) { | ||
form.submit(); | ||
} | ||
} | ||
|
||
var config = { | ||
submitHandler: submitHandler | ||
}; | ||
|
||
$("#multi_transfer, #new_transfer").validate(config); | ||
}) |
This file was deleted.
Oops, something went wrong.
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,32 @@ | ||
/** | ||
* A setup function to make select2 jquery plugin play as an ordinary form when | ||
* using the "multiple" flag. | ||
* | ||
* Also allows options to be disabled. | ||
* | ||
* | ||
* @param {String} selector - CSS selector pointing to a <select /> element | ||
* @param {Object} options | ||
* @param {Array<String>} options.value - initial value | ||
* @param {Array<String>} options.disabledOptions - disabled option values to disable | ||
* @param {Array<String>} options.noMatchesFormat - i18n'd string to show when no matches found when filtering | ||
*/ | ||
window.initializeSelect2 = function(selector, options) { | ||
var $select = $(selector); | ||
|
||
var optionsToDisableSelector = (options.disabledOptions || []).map(function (optionId) { | ||
return "option[value=" + optionId + "]"; | ||
}).join(','); | ||
|
||
var $options = $select.find(optionsToDisableSelector); | ||
$options.attr('disabled', 'disabled'); | ||
|
||
$select.select2({ | ||
formatNoMatches: function () { | ||
return options.noMatchesFormat | ||
} | ||
}); | ||
|
||
$select.val(options.value.length === 0 ? null : options.value); | ||
$select.trigger('change'); | ||
} |
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,16 @@ | ||
module WithTransferParams | ||
def transfer_params | ||
permitted_transfer_params = [ | ||
:destination, | ||
:amount, | ||
:reason, | ||
:post_id, | ||
] | ||
|
||
permitted_transfer_params.push(:source) if admin? | ||
|
||
params. | ||
require(:transfer). | ||
permit(*permitted_transfer_params) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
class MultiTransfersController < ApplicationController | ||
include WithTransferParams | ||
|
||
STEPS = [ | ||
'select_type', | ||
'select_source', | ||
'select_target', | ||
'set_params', | ||
'confirm' | ||
] | ||
|
||
def step | ||
authorize :multi_transfer | ||
|
||
set_steps_info | ||
propagate_params | ||
prepare_template_vars | ||
end | ||
|
||
def create | ||
authorize :multi_transfer | ||
|
||
operation = Operations::Transfers.create( | ||
from: params[:from], | ||
to: params[:to], | ||
transfer_params: params[:transfer].to_hash | ||
) | ||
operation.perform | ||
end | ||
|
||
private | ||
|
||
def set_steps_info | ||
@steps = STEPS | ||
@step_name = step_name | ||
@form_action = if @step_name == @steps.last | ||
multi_transfers_create_path | ||
else | ||
multi_transfers_step_path(step: next_step) | ||
end | ||
@is_last_step = is_last_step | ||
end | ||
|
||
def propagate_params | ||
@type_of_transfer = (params[:type_of_transfer] || :many_to_one).to_sym | ||
@from = params[:from] || [] | ||
@to = params[:to] || [] | ||
|
||
@transfer_amount = params[:transfer] && params[:transfer][:amount] | ||
@transfer_post_id = params[:transfer] && params[:transfer][:post_id] | ||
@transfer_reason = params[:transfer] && params[:transfer][:reason] | ||
@transfer_minutes = params[:transfer] && params[:transfer][:minutes] | ||
@transfer_hours = params[:transfer] && params[:transfer][:hours] | ||
end | ||
|
||
def prepare_template_vars | ||
@accounts = [current_organization.account] + current_organization.member_accounts.merge(Member.active) | ||
|
||
if @type_of_transfer == :many_to_one && @to.length == 1 | ||
@target_accountable = Account.find(@to.first).accountable | ||
end | ||
|
||
@should_render_offer_selector = ( | ||
@type_of_transfer.to_sym == :many_to_one && | ||
@target_accountable && | ||
@target_accountable.offers.length > 0 | ||
) | ||
|
||
@from_names = Account.find(@from).map(&:accountable).map(&:to_s) | ||
@to_names = Account.find(@to).map(&:accountable).map(&:to_s) | ||
@post_title = @transfer_post_id && Post.find(@transfer_post_id).title | ||
end | ||
|
||
def step_index | ||
params[:step].to_i - 1 | ||
end | ||
|
||
def next_step | ||
params[:step].to_i + 1 | ||
end | ||
|
||
def step_name | ||
STEPS[step_index] | ||
end | ||
|
||
def is_last_step | ||
step_index == STEPS.length - 1 | ||
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
Oops, something went wrong.