/* global TinyMCE I18n animateSpinner importProtocolFromFile */ /* global HelperModule DataTableHelpers GLOBAL_CONSTANTS */ /* eslint-disable no-use-before-define, no-alert, no-restricted-globals, no-underscore-dangle */ //= require my_modules //= require protocols/import_export/import // Currently selected row in "load from protocol" modal var selectedRow = null; function initEditMyModuleDescription() { var viewObject = $('#my_module_description_view'); viewObject.on('click', function(e) { if ($(e.target).hasClass('record-info-link')) return; TinyMCE.init('#my_module_description_textarea'); }).on('click', 'a', function(e) { if ($(this).hasClass('record-info-link')) return; e.stopPropagation(); }); setTimeout(function() { TinyMCE.wrapTables(viewObject); }, 100); } function initEditProtocolDescription() { var viewObject = $('#protocol_description_view'); viewObject.on('click', function(e) { if ($(e.target).hasClass('record-info-link')) return; TinyMCE.init('#protocol_description_textarea', { afterInitCallback: refreshProtocolStatusBar }); }).on('click', 'a', function(e) { if ($(this).hasClass('record-info-link')) return; e.stopPropagation(); }); } function initLinkUpdate() { var modal = $('#confirm-link-update-modal'); var modalTitle = modal.find('.modal-title'); var modalBody = modal.find('.modal-body'); var updateBtn = modal.find(".modal-footer [data-action='submit']"); $("[data-action='unlink'], [data-action='revert'], [data-action='update-parent'], [data-action='update-self']") .on('ajax:success', function(e, data) { modalTitle.html(data.title); modalBody.html(data.message); updateBtn.text(data.btn_text); modal.attr('data-url', data.url); modal.modal('show'); }); modal.on('hidden.bs.modal', function() { modalBody.html(''); }); if (!$._data(updateBtn[0], 'events')) { updateBtn.on('click', function() { // POST via ajax $.ajax({ url: modal.attr('data-url'), type: 'POST', dataType: 'json', success: function() { // Simply reload page location.reload(); }, error: function(ev) { // Display error message in alert() alert(ev.responseJSON.message); // Hide modal modal.modal('hide'); } }); }); } $('[data-role="protocol-status-bar"] .preview-protocol').click(function(e) { e.preventDefault(); }); } function initLoadFromRepository() { var modal = $('#load-from-repository-modal'); var modalBody = modal.find('.modal-body'); var loadBtn = modal.find(".modal-footer [data-action='submit']"); $("[data-action='load-from-repository']") .on('ajax:success', function(e, data) { modalBody.html(data.html); // Disable load btn loadBtn.attr('disabled', 'disabled'); modal.modal('show'); // Init Datatable on recent tab initLoadFromRepositoryTable(modalBody.find('#load-protocols-datatable')); loadBtn.on('click', function() { loadFromRepository(); }); }); modal.on('hidden.bs.modal', function() { // Destroy the current Datatable destroyLoadFromRepositoryTable(modalBody.find('#load-protocols-datatable')); loadBtn.off('click'); modalBody.html(''); }); } function initLoadFromRepositoryTable(content) { var tableEl = content.find("[data-role='datatable']"); var datatable = tableEl.DataTable({ dom: "R<'main-actions'<'toolbar'><'protocol-filters'f>>t" + "<'pagination-row'<'pagination-info'li><'pagination-actions'p>>", sScrollX: '100%', sScrollXInner: '100%', buttons: [], processing: true, serverSide: true, responsive: true, order: [[5, 'desc']], ajax: { url: tableEl.data('source'), type: 'POST' }, colReorder: { fixedColumnsLeft: 1000000 // Disable reordering }, columnDefs: [{ targets: [0, 3, 4], searchable: true, orderable: true }, { targets: [1, 2, 5], searchable: true, orderable: true, render: function(data) { return `
${data}