-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI for setting the reason why SHF is waiting on an applicant #281
Changes from 17 commits
31414af
c823e06
44867ed
f06224f
1d3a786
ebb0f4f
0a5dd0d
4f48f4c
441df21
4a3ce00
aaa6ace
10ec808
e8cc76d
b848df6
4f75ecc
a041ef3
a44214b
b776f70
73afa63
df94ef9
ba9fc60
9b798c7
c1fbde8
bf2b195
5bf594e
e70d877
eb3b970
608d0a7
2c3c0ed
a73f2af
001a5d7
871fd64
4fdf5f5
cf0645a
05fd86d
c0d90a8
6d3b704
e5cbbaf
75a36d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
.member_app_waiting_reasons { | ||
#member_app_waiting_reasons { | ||
|
||
input.wpcf7-form-control.is-custom { | ||
width: 3rem; | ||
select { | ||
height: 110%; | ||
} | ||
|
||
input[type="text"]{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid qualifying attribute selectors with an element. |
||
padding: 0.3rem 0.3rem; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shorthand form for property |
||
width: 35rem; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,54 @@ def can_edit_state? | |
policy(@membership_application).permitted_attributes_for_edit.include? :state | ||
end | ||
|
||
|
||
def member_full_name | ||
@membership_application ? "#{@membership_application.first_name} #{@membership_application.last_name}" : '..' | ||
|
||
end | ||
|
||
|
||
# the method to use to get the name for a reason, given the locale | ||
# If no locale is given, the current locale is used. | ||
# If the locale given isn't found or defined, the default name method is used | ||
def reason_name_method(locale = I18n.locale) | ||
reason_method 'name', locale | ||
end | ||
|
||
|
||
# the method to use to get the description for a reason, given the locale | ||
# If no locale is given, the current locale is used. | ||
# If the locale given isn't found or defined, the default name method is used | ||
def reason_desc_method(locale = I18n.locale) | ||
reason_method 'description', locale | ||
end | ||
|
||
|
||
# a collection of arrays with [the name of the reasons for waiting, the reason (object)] | ||
# in the locale | ||
def reasons_for_waiting_names(use_locale = I18n.locale) | ||
reasons_for_waiting_info('name', use_locale) | ||
end | ||
|
||
|
||
# a collection of arrays with [the descriptions of the reasons for waiting, the reason (object)] | ||
# in the locale | ||
def reasons_for_waiting_descs(use_locale = I18n.locale) | ||
reasons_for_waiting_info('description', use_locale) | ||
end | ||
|
||
|
||
private | ||
|
||
def reason_method(method_prefix, locale) | ||
possible_method = "#{method_prefix}_#{locale}".to_sym | ||
method_name = (AdminOnly::MemberAppWaitingReason.new.respond_to?(possible_method) ? possible_method : AdminOnly::MemberAppWaitingReason.send("default_#{method_prefix}_method".to_sym)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless assignment to variable - method_name. |
||
end | ||
|
||
|
||
def reasons_for_waiting_info(method_prefix, locale) | ||
method_name = reason_method(method_prefix, locale) | ||
AdminOnly::MemberAppWaitingReason.all.map { |r| [r.id, r.send(method_name)] } | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,25 @@ def other_reason_placeholder? | |
|
||
|
||
# This is effectively a CONSTANT that is used in the UI | ||
def self.other_reason_name | ||
I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason') | ||
def self.other_reason_name(locale = I18n.locale) | ||
I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason', locale) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The second parameter to the translate method should be an options hash. As it stands now the locale is ignored, and the method always returns the swedish translation I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason', locale: locale) |
||
end | ||
|
||
|
||
def self.other_reason_desc(locale = I18n.locale) | ||
I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason_desc', locale) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
||
|
||
|
||
def self.default_name_method | ||
:name_sv | ||
end | ||
|
||
def self.default_description_method | ||
:description_sv | ||
end | ||
|
||
end | ||
|
||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
- if @membership_application.waiting_for_applicant? | ||
= render 'reason_waiting' | ||
|
||
|
||
|
||
#admin-change-status-buttons | ||
%p.header | ||
= "#{t('membership_applications.show.change_status')}:" | ||
|
||
|
||
= button_to t('membership_applications.start_review_btn'), start_review_membership_application_path(@membership_application), {class: 'btn start-review', disabled: !(@membership_application.may_start_review?)} | ||
.row | ||
= button_to t('membership_applications.start_review_btn'), start_review_membership_application_path(@membership_application), {class: 'btn start-review', disabled: !(@membership_application.may_start_review?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.accept_btn'), accept_membership_application_path(@membership_application), {class: 'btn accept', disabled: !(@membership_application.may_accept?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.accept_btn'), accept_membership_application_path(@membership_application), {class: 'btn accept', disabled: !(@membership_application.may_accept?)} | ||
= button_to t('membership_applications.reject_btn'), reject_membership_application_path(@membership_application), {class: 'btn reject', disabled: !(@membership_application.may_reject?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.reject_btn'), reject_membership_application_path(@membership_application), {class: 'btn reject', disabled: !(@membership_application.may_reject?)} | ||
= button_to t('membership_applications.ask_applicant_for_info_btn'), need_info_membership_application_path(@membership_application), {class: 'btn need-info', disabled: !(@membership_application.may_ask_applicant_for_info?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.ask_applicant_for_info_btn'), need_info_membership_application_path(@membership_application), {class: 'btn need-info', disabled: !(@membership_application.may_ask_applicant_for_info?)} | ||
.row | ||
= button_to t('membership_applications.cancel_waiting_for_applicant_btn'), cancel_need_info_membership_application_path(@membership_application), {class: 'btn cancel-need-info', disabled: !(@membership_application.may_cancel_waiting_for_applicant?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.cancel_waiting_for_applicant_btn'), cancel_need_info_membership_application_path(@membership_application), {class: 'btn cancel-need-info', disabled: !(@membership_application.may_cancel_waiting_for_applicant?)} | ||
= button_to t('membership_applications.ask_applicant_for_payment_btn'), need_payment_membership_application_path(@membership_application), {class: 'btn need-payment', disabled: !(@membership_application.may_ask_for_payment?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.ask_applicant_for_payment_btn'), need_payment_membership_application_path(@membership_application), {class: 'btn need-payment', disabled: !(@membership_application.may_ask_for_payment?)} | ||
= button_to t('membership_applications.cancel_waiting_for_payment_btn'), cancel_need_payment_membership_application_path(@membership_application), {class: 'btn cancel_need-payment', disabled: !(@membership_application.may_cancel_waiting_for_payment?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.cancel_waiting_for_payment_btn'), cancel_need_payment_membership_application_path(@membership_application), {class: 'btn cancel_need-payment', disabled: !(@membership_application.may_cancel_waiting_for_payment?)} | ||
= button_to t('membership_applications.received_payment_btn'), received_payment_membership_application_path(@membership_application), {class: 'btn received-payment', disabled: !(@membership_application.may_received_payment?)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using instance variables in partials views |
||
|
||
= button_to t('membership_applications.received_payment_btn'), received_payment_membership_application_path(@membership_application), {class: 'btn received-payment', disabled: !(@membership_application.may_received_payment?)} | ||
|
||
%br | ||
- if !@membership_application.paid? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
-# submit the changed reason via xhr (javascript) whenever the change from the ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 consecutive comments can be merged into one |
||
-# Do not make user press a "save" or "submit" button for just these changes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment should have a space after the |
||
= form_for @membership_application, html: { id: 'member_app_waiting_reasons', multipart: true}, url: membership_application_path do |f| | ||
.row | ||
|
||
.reason_waiting_information | ||
.col-sm-4 | ||
= f.label( :member_app_waiting_reasons, t('membership_applications.need_info.reason_title')) | ||
= f.collection_select(:member_app_waiting_reasons_id, | ||
AdminOnly::MemberAppWaitingReason.all, | ||
:id, | ||
reason_name_method, | ||
{ include_blank: t('membership_applications.need_info.select_a_reason') }, | ||
class: 'reason-waiting-list', | ||
data: { remote: true, | ||
url: membership_application_path, | ||
method: 'put' } ) | ||
|
||
|
||
.col-sm-8 | ||
%div#other_text_field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
= f.label( :reason_waiting_custom_text, t('membership_applications.need_info.other_reason_label') ) | ||
= f.text_field :custom_reason_text, | ||
data: {remote: true, url: membership_application_path, method: 'put'} | ||
|
||
|
||
:javascript | ||
|
||
|
||
let reason_select_list = $(".reason-waiting-list"); | ||
|
||
// Changing the value in the member_app_waiting_reasons_id select list | ||
// will send an AJAX request to the controller with the newly selected value. | ||
// The controller will send a JS message back (the callback). | ||
// If the callback reported that everything was successful, we don't need to do anything. | ||
// If the callback reported an error, display an error message. | ||
|
||
|
||
reason_select_list.bind("ajax:error", function(evt, data, status, xhr){ | ||
|
||
alert( "#{I18n.t('membership_applications.update.error')}" ) | ||
|
||
}); | ||
|
||
|
||
|
||
// hide or show the text field for entering a custom reason | ||
let hideOrShow = function() { | ||
|
||
let showEm; | ||
let selected_reason = $('#membership_application_member_app_waiting_reasons_id').find('option:selected').text(); | ||
let other_reason = '#{AdminOnly::MemberAppWaitingReason.other_reason_name}'; | ||
showEm = other_reason === selected_reason; | ||
|
||
if (!showEm && document.getElementById("membership_application_custom_reason_text") !== null ) { | ||
// clear out any custom reason if the selected reason is not the custom reason | ||
document.getElementById("membership_application_custom_reason_text").value = ""; | ||
} | ||
|
||
$('#other_text_field').toggle(showEm); | ||
}; | ||
|
||
|
||
|
||
let initialize_hide_or_show = (function() { | ||
|
||
$('#other_text_field').hide(); // start with this hidden. | ||
|
||
$('#membership_application_member_app_waiting_reasons_id').change(hideOrShow); | ||
|
||
hideOrShow(); | ||
}); | ||
|
||
|
||
|
||
$(document).ready(initialize_hide_or_show); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%# This file needs to be here because otherwise the controller will try to render the .html partial. We simply want to return 'success' to the javascript sender %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using id selectors
Selector
member_app_waiting_reasons
should be written in lowercase with hyphens