|
Line 0
Link Here
|
| 0 |
- |
1 |
$(document).ready(function() { |
|
|
2 |
|
| 3 |
// Detect that we were redirected here after login and re-open modal |
| 4 |
let urlParams = new URLSearchParams(window.location.search); |
| 5 |
if (urlParams.has('modal')) { |
| 6 |
let modal = urlParams.get('modal'); |
| 7 |
history.replaceState && history.replaceState( |
| 8 |
null, '', location.pathname + location.search.replace(/[\?&]modal=[^&]+/, '').replace(/^&/, '?') |
| 9 |
); |
| 10 |
if (modal == 'problem') { |
| 11 |
$("#reportProblemModal").modal('show'); |
| 12 |
} |
| 13 |
} |
| 14 |
|
| 15 |
$('#reportProblemModal').on('show.bs.modal', function(e) { |
| 16 |
// Redirect to login modal if not logged in |
| 17 |
if (logged_in_user_id === "") { |
| 18 |
$('#modalAuth').append('<input type="hidden" name="return" value="' + window.location.pathname + window.location.search + '&modal=problem" />'); |
| 19 |
$('#loginModal').modal('show'); |
| 20 |
return false; |
| 21 |
} |
| 22 |
|
| 23 |
$('.addConfirm').prop('disabled', false); |
| 24 |
}); |
| 25 |
|
| 26 |
$('#reportProblemModal').on('click', '.addConfirm', function(e) { |
| 27 |
let problem_title = $('#problem_subject').val(); |
| 28 |
let problem_body = $('#problem_body').val(); |
| 29 |
let reporter_id = $('#problem_reporter').val(); |
| 30 |
|
| 31 |
params = { |
| 32 |
source: 'opac_problem', |
| 33 |
title: problem_title, |
| 34 |
body: problem_body, |
| 35 |
biblio_id: null, |
| 36 |
reporter_id: reporter_id, |
| 37 |
extended_attributes: [ |
| 38 |
{ |
| 39 |
field_id: 1, |
| 40 |
value: window.location.pathname + window.location.search |
| 41 |
} |
| 42 |
] |
| 43 |
}; |
| 44 |
|
| 45 |
$('#problem-submit-spinner').show(); |
| 46 |
$('.addConfirm').prop('disabled', true); |
| 47 |
$.ajax({ |
| 48 |
url: '/api/v1/public/tickets', |
| 49 |
type: 'POST', |
| 50 |
data: JSON.stringify(params), |
| 51 |
success: function(data) { |
| 52 |
$('#problem-submit-spinner').hide(); |
| 53 |
$('#reportProblemModal').modal('hide'); |
| 54 |
$('#problem_body').val(''); |
| 55 |
$('#problem_title').val(''); |
| 56 |
$('h1:first').before('<div class="alert alert-success">' + __("Your problem was sucessfully submitted.") + '</div>'); |
| 57 |
}, |
| 58 |
error: function(data) { |
| 59 |
$('#problem-submit-spinner').hide(); |
| 60 |
$('#reportProblemModal').modal('hide'); |
| 61 |
$('h1:first').before('<div class="alert alert-error">' + __("There was an error when submitting your problem, please contact a librarian.") + '</div>'); |
| 62 |
}, |
| 63 |
contentType: "json" |
| 64 |
}); |
| 65 |
}); |
| 66 |
}); |