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

Sj cart ssr bug #224

Merged
merged 2 commits into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 16 additions & 6 deletions app/assets/javascripts/cart.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

# Functions for manipulating the Services cart.
window.cart =
selectService: (id, srid) ->
selectService: (id, srid, ssrid) ->
has_protocol = parseInt($('#has_protocol').val())
li_count = parseInt($('#line_item_count').val())

Expand All @@ -33,15 +33,24 @@ window.cart =
$('#modal_place .yes-button').on 'click', (e) ->
$.ajax
type: 'POST'
data:
sub_service_request_id: ssrid
url: "/service_requests/#{srid}/add_service/#{id}"
else
$.ajax
type: 'POST'
data:
sub_service_request_id: ssrid
url: "/service_requests/#{srid}/add_service/#{id}"

removeService: (srid, id, move_on, spinner) ->
removeService: (srid, ssrid, id, move_on, spinner, editing_ssr) ->
if editing_ssr == 1
data = sub_service_request_id: ssrid
else
data = null
$.ajax
type: 'POST'
data: data
url: "/service_requests/#{srid}/remove_service/#{id}"
success: (data, textStatus, jqXHR) ->
if move_on
Expand All @@ -63,11 +72,12 @@ $(document).ready ->
return false

$(document).on 'click', '.add-service', ->
window.cart.selectService($(this).data('id'), $(this).data('srid'))
window.cart.selectService($(this).data('id'), $(this).data('srid'), $(this).data('ssrid'))

$(document).on 'click', '.remove-service', ->
id = $(this).data('id')
srid = $(this).data('srid')
ssrid = $(this).data('ssrid')
editing_ssr = $(this).data('editing-ssr')
li_count = parseInt($('#line_item_count').val())
request_submitted = $(this).data('request-submitted')
Expand All @@ -80,16 +90,16 @@ $(document).ready ->

$('#modal_place .yes-button').on 'click', (e) ->
button.replaceWith(spinner)
window.cart.removeService(srid, id, false, spinner)
window.cart.removeService(srid, ssrid, id, false, spinner, editing_ssr)
else if (editing_ssr == 1) && (li_count == 1) && (window.location.pathname.indexOf('catalog') != -1) # Redirect to the Dashboard if the user deletes the last Service on an SSR
$('#modal_place').html($('#remove-request-modal').html())
$('#modal_place').modal('show')

$('#modal_place .yes-button').on 'click', (e) ->
window.cart.removeService(srid, id, true, spinner)
window.cart.removeService(srid, ssrid, id, true, spinner, editing_ssr)
else if (li_count == 1) && (window.location.pathname.indexOf('catalog') == -1) # Do not allow the user to remove the last service except in the catalog
$('#modal_place').html($('#line-item-required-modal').html())
$('#modal_place').modal('show')
else
$(this).replaceWith(spinner)
window.cart.removeService(srid, id, false, spinner)
window.cart.removeService(srid, ssrid, id, false, spinner, editing_ssr)
3 changes: 2 additions & 1 deletion app/assets/javascripts/catalog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ $(document).ready ->
data =
process_ssr_found: $(this).data('process-ssr-found')
service_request_id: getSRId()
sub_service_request_id: $('input[name="sub_service_request_id"]').val()
$.ajax
type: 'POST'
data: data
Expand Down Expand Up @@ -95,7 +96,7 @@ $(document).ready ->
).on('typeahead:render', (event, a, b, c) ->
$('[data-toggle="tooltip"]').tooltip({ 'delay' : { show: 1000, hide: 500 } })
).on('typeahead:select', (event, suggestion) ->
window.cart.selectService(suggestion.value, $(this).data('srid'))
window.cart.selectService(suggestion.value, $(this).data('srid'), $(this).data('ssrid'))
)

### CONTINUE BUTTON ###
Expand Down
2 changes: 1 addition & 1 deletion app/views/catalogs/_catalog_center.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
-# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.col-md-6.catalog-center
#search.form-group
= text_field_tag 'service-query', nil, placeholder: t(:proper)[:catalog][:center][:search_placeholder], class: "search-services form-control input-lg", data: { srid: service_request.id }
= text_field_tag 'service-query', nil, placeholder: t(:proper)[:catalog][:center][:search_placeholder], class: "search-services form-control input-lg", data: { srid: service_request.id, ssrid: sub_service_request.try(:id) }
#welcome-message
- if organization
= render 'catalogs/description', organization: organization, service_request: service_request, from_portal: from_portal
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalogs/_description.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- if organization.type == "Program"
- if organization.services.any? && (sub_service_request.nil? || process_ssr_found || organization.parents.include?(ssr_org))
.program-services
= render 'catalogs/accordion/services', services: organization.services.order('`order`, `name`'), service_request: service_request
= render 'catalogs/accordion/services', services: organization.services.order('`order`, `name`'), service_request: service_request, sub_service_request: sub_service_request

- if organization.cores.any?
= render 'catalogs/accordion/cores', program: organization, cores: organization.cores.where(is_available: [nil, true]).order('`order`'), ssr_org: ssr_org, service_request: service_request, locked_ids: locked_org_ids, process_ssr_found: process_ssr_found
= render 'catalogs/accordion/cores', program: organization, cores: organization.cores.where(is_available: [nil, true]).order('`order`'), ssr_org: ssr_org, service_request: service_request, locked_ids: locked_org_ids, process_ssr_found: process_ssr_found, sub_service_request: sub_service_request
4 changes: 2 additions & 2 deletions app/views/catalogs/accordion/_cores.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
.description
= organization_description_display(c)
.core-services
= render 'catalogs/accordion/services', services: ssr_org.services, service_request: service_request
= render 'catalogs/accordion/services', services: ssr_org.services, service_request: service_request, sub_service_request: sub_service_request
- else
.panel-group{ id: "program-#{program.id}"}
- cores.each do |c|
Expand All @@ -42,5 +42,5 @@
.description
= organization_description_display(c)
.core-services
= render 'catalogs/accordion/services', services: c.services, service_request: service_request
= render 'catalogs/accordion/services', services: c.services, service_request: service_request, sub_service_request: sub_service_request

2 changes: 1 addition & 1 deletion app/views/catalogs/accordion/_services.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.name.col-sm-10
= link_to service.display_service_name, 'javascript:void(0)', class: "service service-#{service.id} btn btn-default full", data: { id: service.id }
.col-sm-2
%button.add-service.pull-right.btn.btn-success{ data: { id: service.id, srid: service_request.id } }
%button.add-service.pull-right.btn.btn-success{ data: { id: service.id, srid: service_request.id, ssrid: sub_service_request.try(:id) } }
= t(:actions)[:add]
.col-sm-12.service-description.hidden{ class: "service-description-#{service.id}" }
= organization_description_display(service)
2 changes: 1 addition & 1 deletion app/views/service_requests/catalog.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

= render 'catalogs/about_section'
= render 'catalogs/service_accordion', institutions: @institutions, ssr_org: @sub_service_request.try(:organization), locked_org_ids: @locked_org_ids
= render 'catalogs/catalog_center', service_request: @service_request, from_portal: @from_portal, organization: nil
= render 'catalogs/catalog_center', service_request: @service_request, sub_service_request: @sub_service_request, from_portal: @from_portal, organization: nil
= render 'catalogs/catalog_right', service_request: @service_request, sub_service_request: @sub_service_request, sub_service_requests: @sub_service_requests, line_items_count: @line_items_count
= render 'catalogs/back_to_top'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
= li.service.cpt_code? ? " (#{li.service.cpt_code})" : ""
.col-sm-3
- if sub_service_request.can_be_edited? && allow_delete && li.optional?
%button.btn.btn-xs.btn-danger.remove-service.pull-right{ type: 'button', data: { id: li.id, srid: service_request.id, editing_ssr: editing_ssr ? 1 : 0, request_submitted: service_request.submitted_at? ? 1 : 0, toggle: "tooltip", animation: 'false', placement: 'right'}, title: "Remove" }
%button.btn.btn-xs.btn-danger.remove-service.pull-right{ type: 'button', data: { id: li.id, srid: service_request.id, ssrid: sub_service_request.id, editing_ssr: editing_ssr ? 1 : 0, request_submitted: service_request.submitted_at? ? 1 : 0, toggle: "tooltip", animation: 'false', placement: 'right'}, title: "Remove" }
%span.glyphicon.glyphicon-remove{ aria: { hidden: 'true' } }