Skip to content
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

Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
31414af
update ruby_version -> 2.4.0
weedySeaDragon Jun 16, 2017
c823e06
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 19, 2017
44867ed
add attributes to MembershipApplication: waiting_reason & custom_reas…
weedySeaDragon Jun 21, 2017
f06224f
seed MemberAppWaitingReason with the "Other/Custom" reason (text from…
weedySeaDragon Jun 21, 2017
1d3a786
pass locale to other_reason_name/_desc to make seeding easier
weedySeaDragon Jun 21, 2017
ebb0f4f
features & specs for setting reasons for waiting
weedySeaDragon Jun 21, 2017
0a5dd0d
remove assertion no longer used (removed the 'submit/save' button)
weedySeaDragon Jun 21, 2017
4f48f4c
helpers: return the correct method to call based on the current local
weedySeaDragon Jun 21, 2017
441df21
add allowed attributes to Pundit policy
weedySeaDragon Jun 21, 2017
4a3ce00
refactor reasons_waiting into a parital; move to above the 'status' b…
weedySeaDragon Jun 21, 2017
aaa6ace
respond to a .js request for the reason waiting
weedySeaDragon Jun 21, 2017
10ec808
I18n locale entries needed
weedySeaDragon Jun 21, 2017
e8cc76d
if Seeding tests are run prior to this spec, ensure the table is clea…
weedySeaDragon Jun 21, 2017
b848df6
CSS styling
weedySeaDragon Jun 21, 2017
4f75ecc
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 21, 2017
a041ef3
fix: seed the EN name of the 'other reason' (should have passed in :e…
weedySeaDragon Jun 21, 2017
a44214b
need to get the current text for the 'other reason' if the locale has…
weedySeaDragon Jun 21, 2017
b776f70
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 21, 2017
73afa63
clean up per HoundCI suggestions
weedySeaDragon Jun 21, 2017
df94ef9
DRY error situations
weedySeaDragon Jun 21, 2017
ba9fc60
features: other/custom reason comes from the locale file, is not a mo…
weedySeaDragon Jun 22, 2017
9b798c7
do not seed the 'custom/other' reason; it's not stored in the db
weedySeaDragon Jun 22, 2017
c1fbde8
add set: select an item without any I18n
weedySeaDragon Jun 23, 2017
bf2b195
CSS styling
weedySeaDragon Jun 23, 2017
5bf594e
return "OK" if update successful; set the text for the "other/custom.…
weedySeaDragon Jun 23, 2017
e70d877
no .js is needed to return if action was successful
weedySeaDragon Jun 23, 2017
eb3b970
other_reason placeholder stuff no longer needed in Model; remove spec…
weedySeaDragon Jun 23, 2017
608d0a7
all logic for "enter custom reason.." into this javascript
weedySeaDragon Jun 23, 2017
2c3c0ed
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 23, 2017
a73f2af
interim progress (Pat)
patmbolger Jun 24, 2017
001a5d7
refactored some JS
patmbolger Jun 24, 2017
871fd64
changed feature steps in accordance with id changes in view (Pat)
patmbolger Jun 24, 2017
4fdf5f5
removed selenium webdriver from Gemfile (Pat)
patmbolger Jun 24, 2017
cf0645a
fixed a couple cuke steps (Pat)
patmbolger Jun 24, 2017
05fd86d
fixed remaining cuke tests (Pat)
patmbolger Jun 25, 2017
c0d90a8
changes to CSS per houndci
weedySeaDragon Jun 26, 2017
6d3b704
POLTERGEIST fix: do not use "let" (use var instead)
weedySeaDragon Jun 26, 2017
e5cbbaf
remove selenium (no longer needed)
weedySeaDragon Jun 26, 2017
75a36d6
update gemfile.lock
weedySeaDragon Jun 26, 2017
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
11 changes: 8 additions & 3 deletions app/assets/stylesheets/member-app-waiting-reason.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
.member_app_waiting_reasons {
#member_app_waiting_reasons {

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


input.wpcf7-form-control.is-custom {
width: 3rem;
select {
height: 110%;
}

input[type="text"]{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid qualifying attribute selectors with an element.
Opening curly brace { should be preceded by one space

padding: 0.3rem 0.3rem;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorthand form for property padding should be written more concisely as 0.3rem instead of 0.3rem 0.3rem

width: 35rem;
}

}
55 changes: 47 additions & 8 deletions app/controllers/membership_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def index
authorize MembershipApplication

action_params, @items_count, items_per_page =
process_pagination_params('membership_application')
process_pagination_params('membership_application')

@search_params = MembershipApplication.ransack(action_params)

Expand Down Expand Up @@ -67,17 +67,47 @@ def update

check_and_mark_if_ready_for_review params['membership_application'] if params.fetch('membership_application', false)

helpers.flash_message(:notice, t('.success'))
render :show
respond_to do |format|
format.js do
render partial: 'membership_applications/reason_waiting'
end

format.html do
helpers.flash_message(:notice, t('.success'))
render :show
end

end

else
helpers.flash_message(:alert, t('.error'))
redirect_to edit_membership_application_path(@membership_application)
respond_to do |format|

format.html do
helpers.flash_message(:alert, t('.error'))
redirect_to edit_membership_application_path(@membership_application)
end

format.js do
render :json => @membership_application.errors, :status => :unprocessable_entity
end

end
end

else
helpers.flash_message(:alert, t('.error'))
redirect_to edit_membership_application_path(@membership_application)
respond_to do |format|

format.html do
helpers.flash_message(:alert, t('.error'))
redirect_to edit_membership_application_path(@membership_application)
end

format.js do
render :json => @membership_application.errors, :status => :unprocessable_entity
end

end

end
end

Expand All @@ -95,7 +125,7 @@ def information


def destroy
@membership_application = MembershipApplication.find(params[:id]) # we don't need to fetch the categories
@membership_application = MembershipApplication.find(params[:id]) # we don't need to fetch the categories
@membership_application.destroy
redirect_to membership_applications_url, notice: t('membership_applications.application_deleted')
end
Expand Down Expand Up @@ -132,21 +162,30 @@ def need_info


def cancel_need_info

# empty out the reason for waiting info
@membership_application.waiting_reason = nil
@membership_application.custom_reason_text = nil

simple_state_change(:cancel_waiting_for_applicant!, t('.success'), t('.error'))
end


def need_payment
simple_state_change(:ask_for_payment!, t('.success'), t('.error'))
end


def cancel_need_payment
simple_state_change(:cancel_waiting_for_payment!, t('.success'), t('.error'))
end


def received_payment
simple_state_change(:received_payment!, t('.success'), t('.error'))
end


private
def membership_application_params
params.require(:membership_application).permit(*policy(@membership_application || MembershipApplication).permitted_attributes)
Expand Down
46 changes: 46 additions & 0 deletions app/helpers/membership_applications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Choose a reason for hiding this comment

The 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
14 changes: 12 additions & 2 deletions app/models/admin_only/member_app_waiting_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Expand Down
5 changes: 5 additions & 0 deletions app/models/membership_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class MembershipApplication < ApplicationRecord
has_and_belongs_to_many :business_categories
has_many :uploaded_files

belongs_to :waiting_reason, optional: true,
foreign_key: "member_app_waiting_reasons_id",
class_name: 'AdminOnly::MemberAppWaitingReason'


validates_presence_of :first_name,
:last_name,
:company_number,
Expand Down
4 changes: 2 additions & 2 deletions app/policies/membership_application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def user_owner_attributes


def all_attributes
owner_attributes + [:membership_number]
owner_attributes + [:membership_number, :waiting_reason, :custom_reason_text, :member_app_waiting_reasons_id]
end


Expand All @@ -121,4 +121,4 @@ def owner?
user && @record.respond_to?(:user) && @record.user == user
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?)}

Choose a reason for hiding this comment

The 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?)}

Choose a reason for hiding this comment

The 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?)}

Choose a reason for hiding this comment

The 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?)}

Choose a reason for hiding this comment

The 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?)}

Choose a reason for hiding this comment

The 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?)}

Choose a reason for hiding this comment

The 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?)}

Choose a reason for hiding this comment

The 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?)}

Choose a reason for hiding this comment

The 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?
Expand Down
78 changes: 78 additions & 0 deletions app/views/membership_applications/_reason_waiting.html.haml
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 )

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id attribute must be in lisp-case
%div#other_text_field can be written as #other_text_field since %div is implicit

= 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);


1 change: 1 addition & 0 deletions app/views/membership_applications/_reason_waiting.js.erb
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 %>
6 changes: 3 additions & 3 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,13 @@ en:

need_info:
reason_title: Reason

other_reason_label: "other reason:"
submit_button_label: "Save the reason"

select_a_reason: "Select a reason..."

success: 'The application has been marked as needing info. (Send email to the applicant.)'
error: "There was an error when trying to set the application to 'needing information.'"


cancel_need_info:
success: The application has been changed to no longer needing information from the applicant.
error: "There was an error when trying to set the application to 'no longer needing information from the applicant.'"
Expand Down Expand Up @@ -677,6 +676,7 @@ en:
list_all_member_app_waiting_reasons: "List all Waiting for Information Reasons"

other_custom_reason: "Other (enter the reason)"
other_custom_reason_desc: ""

delete_confirm: "Are you sure you want to delete the reason: %{name_sv} (%{name_en})?"

Expand Down
5 changes: 3 additions & 2 deletions config/locales/sv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,13 @@ sv:

need_info:
reason_title: Anledning

other_reason_label: "Annan orsak"
submit_button_label: "Spara orsaken"
select_a_reason: "Välj en anledning..."

success: 'Ansökan har markerats som: "Behöver kompletteras". (Skicka e-post till den sökande.)'
error: 'Det uppstod ett fel när systemet försökte sätta status: "Behöver kompletteras".'


cancel_need_info:
success: Ansökan har ändrats och behöver ej längre kompletteras av sökande.
error: 'Det uppstod ett fel när systemet försökte ångra status: "Behöver kompletteras".'
Expand Down Expand Up @@ -680,6 +680,7 @@ sv:
list_all_member_app_waiting_reasons: "Lista alla orsaker"

other_custom_reason: "Annat (skriv in orsaken)"
other_custom_reason_desc: ""

delete_confirm: "Är du säker på att du vill radera orsaken: %{name_sv} (%{name_en})?"

Expand Down
Loading