Skip to content

Commit

Permalink
Merge pull request #257 from sparc-request/kg-change_primary_pi
Browse files Browse the repository at this point in the history
KG - Change Primary PI
  • Loading branch information
jleonardw9 committed Jan 19, 2016
2 parents 51cf029 + 772c0f4 commit ac89efd
Show file tree
Hide file tree
Showing 20 changed files with 1,004 additions and 164 deletions.
165 changes: 157 additions & 8 deletions app/assets/javascripts/portal/associated_users.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,95 @@ $(document).ready ->
id: 'add_authorized_user_submit_button'
text: 'Submit'
click: ->
$("#new_project_role").submit()
$('#add_authorized_user_submit_button').attr('disabled', true)

role = $('#project_role_role').val()
primary_pi_pr_id = $('#primary_pi_pr_id').val()
pr_id = $('#pr_id').val()

if role == 'primary-pi' && primary_pi_pr_id != pr_id
button = $('#add_authorized_user_submit_button')
button_text = button.children('span')
title_text = $('.add_user_dialog_box .ui-dialog-titlebar').children('.ui-dialog-title')

if button_text.text() == 'Submit'
#Hide the form
$('.user-search-container').hide()
$('#add-user-form').hide()

#Add the new elements
primary_pi_full_name = $('#primary_pi_full_name').val()
pr_full_name = $('#full_name').val()
warning = I18n["protocol_information"]["change_primary_pi"]["warning"]
message1 = I18n["protocol_information"]["change_primary_pi"]["warning_prompt_1_1"]+
"(<strong>#{pr_full_name}</strong>)"+
I18n["protocol_information"]["change_primary_pi"]["warning_prompt_1_2"]+
"(<strong>#{primary_pi_full_name}</strong>)"+
I18n["protocol_information"]["change_primary_pi"]["warning_prompt_1_3"]
message2 = I18n["protocol_information"]["change_primary_pi"]["warning_prompt_2"]
$('.add-associated-user-dialog').append("<h1 class='change_ppi_prompt' style='color:red;'>#{warning}</h1><p class='change_ppi_prompt' style='font-size:14px;'>#{message1}</p><p class='change_ppi_prompt' style='font-size:14px;'>#{message2}</p>")

#Change the text
button_text.text('Yes')
button.siblings('button').children('span').text('No')
title_text.text('Change Primary PI')
else
#Enable removing the old Primary PI
$('#change_primary_pi').val(true)

#Remove the elements
$('.change_ppi_prompt').remove()

#Show the form
$('.user-search-container').show()
$('#add-user-form').show()

#Change the text
button_text.text('Submit')
button.siblings('button').children('span').text('Cancel')
title_text.text('Add an Authorized User')

$('#new_project_role').submit()
else
$('#new_project_role').submit()

$('#add_authorized_user_submit_button').attr('disabled', false)

'Cancel':
id: 'add_authorized_user_cancel_button'
text: 'Cancel'
click: ->
$(this).dialog('close')
$("#errorExplanation").remove()
button = $('#add_authorized_user_cancel_button')
button_text = button.children('span')
title_text = $('.add_user_dialog_box .ui-dialog-titlebar').children('.ui-dialog-title')

if button_text.text() == 'Cancel'
$(this).dialog('close')
$('#errorExplanation').remove()
else
#Remove the elements
$('.change_ppi_prompt').remove()

#Show the form
$('.user-search-container').show()
$('#add-user-form').show()

#Change the text
button_text.text('Cancel')
button.siblings('button').children('span').text('Submit')
title_text.text('Add an Authorized User')
open: ->
Sparc.associated_users.reset_fields()
$('.dialog-form input,.dialog-form select').attr('disabled',true)
# $('.ui-dialog .ui-dialog-buttonpane button:contains(Submit)').filter(":visible").attr('disabled',true).addClass('button-disabled')
close: ->
Sparc.associated_users.reset_fields()
$('#add_authorized_user_submit_button').children('span').text('Submit')
$('#add_authorized_user_cancel_button').children('span').text('Cancel')
$('.add_user_dialog_box .ui-dialog-titlebar').children('.ui-dialog-title').text('Add an Authorized User')
$('.change_ppi_prompt').remove()
$('.user-search-container').show()
$('#add-user-form').show()

create_edit_associated_user_dialog: () ->
$('.edit-associated-user-dialog').dialog
Expand All @@ -176,20 +252,93 @@ $(document).ready ->
id: 'edit_authorized_user_submit_button'
text: 'Submit'
click: ->
form = $(".edit-associated-user-dialog").children('form')
$('#edit_authorized_user_submit_button').attr('disabled', true)
form.submit()

role = $('#project_role_role').val()
primary_pi_pr_id = $('#primary_pi_pr_id').val()
pr_id = $('#pr_id').val()

if role == 'primary-pi' && primary_pi_pr_id != pr_id
button = $('#edit_authorized_user_submit_button')
button_text = button.children('span')
title_text = $('.edit_user_dialog_box .ui-dialog-titlebar').children('.ui-dialog-title')

if button_text.text() == 'Submit'
#Hide the form
$("#edit_project_role_#{pr_id}").hide()

#Add the new elements
primary_pi_full_name = $('#primary_pi_full_name').val()
pr_full_name = $('#full_name').val()
warning = I18n["protocol_information"]["change_primary_pi"]["warning"]
message1 = I18n["protocol_information"]["change_primary_pi"]["warning_prompt_1_1"]+
"(<strong>#{pr_full_name}</strong>)"+
I18n["protocol_information"]["change_primary_pi"]["warning_prompt_1_2"]+
"(<strong>#{primary_pi_full_name}</strong>)"+
I18n["protocol_information"]["change_primary_pi"]["warning_prompt_1_3"]
message2 = I18n["protocol_information"]["change_primary_pi"]["warning_prompt_2"]
$('.edit-associated-user-dialog').append("<h1 class='change_ppi_prompt' style='color:red;'>#{warning}</h1><p class='change_ppi_prompt' style='font-size:14px;'>#{message1}</p><p class='change_ppi_prompt' style='font-size:14px;'>#{message2}</p>")

#Change the text
button_text.text('Yes')
button.siblings('button').children('span').text('No')
title_text.text('Change Primary PI')
else
#Enable removing the old Primary PI
$('#change_primary_pi').val(true)

#Remove the elements
$('.change_ppi_prompt').remove()

#Show the form
$("#edit_project_role_#{pr_id}").show()

#Change the text
button_text.text('Submit')
button.siblings('button').children('span').text('Cancel')
title_text.text('Edit an Authorized User')

$('.edit-associated-user-dialog').children('form').submit()
else
$('.edit-associated-user-dialog').children('form').submit()

$('#edit_authorized_user_submit_button').attr('disabled', false)

'Cancel':
id: 'edit_authorized_user_cancel_button'
text: 'Cancel'
click: ->
$(this).dialog("close")
$("#errorExplanation").remove()
pr_id = $('#pr_id').val()

button = $('#edit_authorized_user_cancel_button')
button_text = button.children('span')
title_text = $('.edit_user_dialog_box .ui-dialog-titlebar').children('.ui-dialog-title')

if button_text.text() == 'Cancel'
$(this).dialog('close')
$("#errorExplanation").remove()
else
#Remove the elements
$('.change_ppi_prompt').remove()

#Show the form
$("#edit_project_role_#{pr_id}").show()

#Change the text
button_text.text('Cancel')
button.siblings('button').children('span').text('Submit')
title_text.text('Edit an Authorized User')
open: ->
$('#edit_authorized_user_submit_button').attr('disabled', false)
$('#associated_user_role').change()
close: ->
Sparc.associated_users.reset_fields()
$('#edit_authorized_user_submit_button').children('span').text('Submit')
$('#edit_authorized_user_cancel_button').children('span').text('Cancel')
$('.edit_user_dialog_box .ui-dialog-titlebar').children('.ui-dialog-title').text('Edit an Authorized User')
$('.change_ppi_prompt').remove()
pr_id = $('#pr_id').val()
$("#edit_project_role_#{pr_id}").show()

reset_fields: () ->
$('.errorExplanation').html('').hide()
Expand All @@ -198,7 +347,7 @@ $(document).ready ->
$('.add-associated-user-dialog input').val('')
$('.add-associated-user-dialog select').prop('selectedIndex', 0)
$('.add-associated-user-dialog #epic_access input').prop('checked', false)
$('.add-associated-user-dialog .rights_radios input').prop('checked', false)
$('.add-associated-user-dialog .rights input').prop('checked', false)

createTip: (element) ->
if $('#tip').length == 0
Expand Down
30 changes: 10 additions & 20 deletions app/assets/stylesheets/portal/associated_users.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,6 @@
width: 254px;
}
}

#project_rights {
ul.rights_labels {
list-style: none;
float: left;
padding-left: 15px;
}

ul.rights_radios {
list-style: none;
float: right;
padding-left: 10px;
}
}
}

#identity_details {
Expand All @@ -136,16 +122,20 @@
}

#project_rights {
ul.rights_labels {
ul.rights {
list-style: none;
float: left;
padding-left: 15px;
}

ul.rights_radios {
list-style: none;
float: right;
padding-left: 10px;
div {
padding: 0px !important;

input {
float: right;
margin-top: 3px !important;
margin-left: 7px !important;
}
}
}
}

Expand Down
12 changes: 9 additions & 3 deletions app/controllers/portal/associated_users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def create
@identity = Identity.find @protocol_role.identity_id

if @protocol_role.unique_to_protocol? && @protocol_role.fully_valid?
if params[:change_primary_pi] == "true"
ProjectRole.find(params[:primary_pi_pr_id]).destroy
end
@protocol_role.save
@identity.update_attributes params[:identity]
if SEND_AUTHORIZED_USER_EMAILS
Expand All @@ -83,7 +86,7 @@ def create
if params[:sub_service_request_id]
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
@protocol = @sub_service_request.service_request.protocol
render 'portal/admin/update_associated_users'
render 'portal/admin/create_authorized_users'
else
respond_to do |format|
format.js
Expand All @@ -102,6 +105,9 @@ def update
@protocol_role.assign_attributes params[:project_role]

if @protocol_role.fully_valid?
if params[:change_primary_pi] == "true"
ProjectRole.find(params[:primary_pi_pr_id]).destroy
end
@protocol_role.save
@identity.update_attributes params[:identity]
if SEND_AUTHORIZED_USER_EMAILS
Expand Down Expand Up @@ -129,7 +135,7 @@ def update
if params[:sub_service_request_id]
@protocol = Protocol.find(params[:protocol_id])
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
render 'portal/admin/update_associated_users'
render 'portal/admin/update_authorized_users'
else
respond_to do |format|
format.js
Expand All @@ -156,7 +162,7 @@ def destroy
if params[:sub_service_request_id]
@sub_service_request = SubServiceRequest.find(params[:sub_service_request_id])
@protocol = @sub_service_request.service_request.protocol
render 'portal/admin/update_associated_users'
render 'portal/admin/destroy_authorized_users'
else
respond_to do |format|
format.js
Expand Down
17 changes: 2 additions & 15 deletions app/models/project_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,14 @@ def validate_other_selections
end

def validate_one_primary_pi
if !protocol_has_primary_pi?
errors.add(:must, "include one Primary PI.")
return false
elsif self.role == 'primary-pi' && protocol_has_primary_pi?
errors.add(:role, "- This protocol already has a Primary PI.")
if self.protocol.project_roles.where(role: "primary-pi").include?(self) && self.role != "primary-pi"
errors.add(:role, "- Protocols must have a Primary PI.")
return false
else
return true
end
end

def protocol_has_primary_pi?
protocol = self.protocol
ProjectRole.where(protocol_id: protocol.id).each do |pr|
if pr.role == "primary-pi"
return true
end
return false
end
end

def is_only_primary_pi?
if self.role == 'primary-pi'
pi_project_roles = self.protocol.project_roles.select {|x| x.role == 'primary-pi'}
Expand Down
36 changes: 36 additions & 0 deletions app/views/portal/admin/create_authorized_users.js.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-# Copyright © 2011 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.
- if !@protocol_role.errors.messages.empty?
- @protocol_role.errors.messages.merge!(@identity.errors.messages)
- @entity_errors = @protocol_role.errors.to_json
:plain
$('#add_authorized_user_submit_button').attr('disabled', false)
Sparc.home.handle_ajax_errors("#{escape_javascript(@entity_errors)}", "Authorized User")
- else
:plain
$('.add-associated-user-dialog').dialog('close').dialog('destroy').remove()
$('.edit-associated-user-dialog').dialog('close').dialog('destroy').remove()

$("#associated_users").html("#{escape_javascript(render(partial: 'portal/sub_service_requests/associated_users'))}")
$('#information').html("#{escape_javascript(render(partial: 'portal/sub_service_requests/ssr_information', locals: {protocol: @protocol, sub_service_request: @sub_service_request}))}")

Sparc.associated_users.create_add_associated_user_dialog()
Sparc.associated_users.create_edit_associated_user_dialog()
23 changes: 23 additions & 0 deletions app/views/portal/admin/destroy_authorized_users.js.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-# Copyright © 2011 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.
:plain
$("#associated_users").html("#{escape_javascript(render(partial: 'portal/sub_service_requests/associated_users'))}")

0 comments on commit ac89efd

Please sign in to comment.