2019-06-20 04:54:20 +08:00
|
|
|
function applyClickCallbackOnProtocolCards() {
|
|
|
|
$('.protocol-card').off('click').on('click', function(e) {
|
|
|
|
$.ajax({
|
|
|
|
url: $(this).data('show-url'),
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
protocol_source: $(this).data('protocol-source'),
|
|
|
|
protocol_id: $(this).data('show-protocol-id')
|
|
|
|
},
|
2019-06-27 01:43:35 +08:00
|
|
|
beforeSend: animateSpinner($('.protocol-preview-panel'), true),
|
2019-06-20 05:37:04 +08:00
|
|
|
success: function(data) {
|
2019-06-20 04:54:20 +08:00
|
|
|
$('.empty-preview-panel').hide();
|
|
|
|
$('.full-preview-panel').show();
|
|
|
|
$('.preview-iframe').contents().find('body').html(data.html);
|
2019-06-27 01:43:35 +08:00
|
|
|
animateSpinner($('.protocol-preview-panel'), false);
|
2019-06-20 04:54:20 +08:00
|
|
|
},
|
2019-06-20 05:37:04 +08:00
|
|
|
error: function(_error) {
|
2019-06-20 04:54:20 +08:00
|
|
|
// TODO: we should probably show some alert bubble
|
2019-06-28 04:48:56 +08:00
|
|
|
resetPreviewPanel();
|
2019-06-27 01:43:35 +08:00
|
|
|
animateSpinner($('.protocol-preview-panel'), false);
|
2019-06-20 04:54:20 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-28 04:48:56 +08:00
|
|
|
// Resets preview to the default state
|
|
|
|
function resetPreviewPanel() {
|
|
|
|
$('.empty-preview-panel').show();
|
|
|
|
$('.full-preview-panel').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function setDefaultViewState() {
|
|
|
|
resetPreviewPanel();
|
|
|
|
$('.empty-text').show();
|
|
|
|
$('.list-wrapper').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Apply AJAX callbacks onto the search box
|
|
|
|
function applySearchCallback() {
|
|
|
|
// Submit form on every input in the search box
|
|
|
|
$('input[name="key"]').off('input').on('input', function() {
|
|
|
|
$('form.protocols-search-bar').submit();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Submit form when clicking on sort buttons
|
|
|
|
$('.protocol-sort label').off('click').on('click', function () {
|
|
|
|
$('form.protocols-search-bar').submit();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Bind ajax calls on the form
|
|
|
|
$('form.protocols-search-bar').off('ajax:success').off('ajax:error')
|
|
|
|
.bind('ajax:success', function(evt, data, status, xhr) {
|
|
|
|
if (data.html) {
|
|
|
|
resetPreviewPanel();
|
|
|
|
$('.empty-text').hide();
|
|
|
|
$('.list-wrapper').show();
|
|
|
|
|
|
|
|
$('.list-wrapper').html(data.html)
|
|
|
|
applyClickCallbackOnProtocolCards();
|
|
|
|
} else {
|
|
|
|
setDefaultViewState();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind("ajax:error", function(evt, xhr, status, error) {
|
|
|
|
setDefaultViewState();
|
|
|
|
|
|
|
|
console.log(xhr.responseText);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
applySearchCallback();
|