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

KG - Update Core List When Chaning Service's Program #1466

Merged
merged 3 commits into from
Aug 7, 2018
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
13 changes: 13 additions & 0 deletions app/assets/javascripts/catalog_manager/form.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,19 @@ $ ->
email: new_submission_email
organization_id: org_id

##############################################
### Service General Info ###
##############################################
$(document).on 'change', '#service_program', ->
service_id = $(this).data('service-id')
program_id = $(this).find('option:selected').val()

$.ajax
type: 'GET'
dataType: 'script'
url: "/catalog_manager/services/#{service_id}/reload_core_dropdown"
data:
program_id: program_id

##############################################
### Service Components ###
Expand Down
5 changes: 5 additions & 0 deletions app/controllers/catalog_manager/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def search

####General Methods####

def reload_core_dropdown
@service = Service.find(params[:service_id])
@cores = Program.find(params[:program_id]).cores
end

private

def service_params
Expand Down
22 changes: 22 additions & 0 deletions app/views/catalog_manager/services/_core_dropdown.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-# Copyright © 2011-2018 MUSC Foundation for Research Development
-# All rights reserved.

-# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

-# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

-# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
-# disclaimer in the documentation and/or other materials provided with the distribution.

-# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
-# derived from this software without specific prior written permission.

-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
-# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
-# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
-# 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.

= fields_for service do |f|
= f.select :core, options_for_select(cores.map{|c| [c.name, c.id]}.insert(0, ['None',0]), (service.core.id if service.core)), {}, {class: 'form-control select-type selectpicker'}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
.form-group
= f.label :program, t(:catalog_manager)[:organization_form][:program], class: 'col-sm-3 control-label'
.col-sm-9
= f.select :program, options_for_select(@programs.map{|p| [p.name, p.id]}, service.program.id), {}, {class: 'form-control select-type selectpicker'}
= f.select :program, options_for_select(@programs.map{|p| [p.name, p.id]}, service.program.id), {}, {class: 'form-control select-type selectpicker', data: { service_id: service.id }}
.form-group
= f.label :core, t(:catalog_manager)[:organization_form][:core], class: 'col-sm-3 control-label'
.col-sm-9
= f.select :core, options_for_select(@cores.map{|c| [c.name, c.id]}.insert(0, ['None',0]), (service.core.id if service.core)), {}, {class: 'form-control select-type selectpicker'}
= render 'catalog_manager/services/core_dropdown', cores: @cores, service: service
.form-group
= f.label :name, t(:catalog_manager)[:organization_form][:name], class: 'col-sm-3 control-label'
.col-sm-9
Expand Down
22 changes: 22 additions & 0 deletions app/views/catalog_manager/services/reload_core_dropdown.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright © 2011-2018 MUSC Foundation for Research Development
# All rights reserved.

# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

# 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided with the distribution.

# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
# SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# 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.
$('#service_core').replaceWith("<%= j render 'catalog_manager/services/core_dropdown', cores: @cores, service: @service %>")
$('#service_core + .bootstrap-select').remove()
$('#service_core').selectpicker()
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
match 'pricing_maps/refresh_rates' => 'pricing_maps#refresh_rates', via: [:get]

resources :services, only: [:edit, :update, :create, :new] do
get :reload_core_dropdown
post :change_components
patch :update_epic_info
end
Expand Down