/* global TinyMCE Prism 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 && $(e.target).prop("tagName") === 'A') return; if (e && $(e.target).hasClass('atwho-user-popover')) return; if (e && $(e.target).hasClass('record-info-link')) return; if (e && $(e.target).parent().hasClass('record-info-link')) return; if (e && $(e.target).parent().hasClass('atwho-inserted')) return; TinyMCE.init( '#my_module_description_textarea', { onSaveCallback: () => { Prism.highlightAllUnder(viewObject.get(0)); }, assignableMyModuleId: $('#my_module_description_textarea').data('object-id') } ); }); 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 modalMessage = modal.find('.modal-body .message'); var updateBtn = modal.find(".modal-footer [data-action='submit']"); $('.protocol-options-dropdown') .on('ajax:success', "[data-action='unlink'], [data-action='revert'], [data-action='update-parent']," + "[data-action='update-self']", function(e, data) { modalTitle.text(data.title); modalMessage.text(data.message); updateBtn.text(data.btn_text); modal.attr('data-url', data.url); modal.modal('show'); }); modal.on('hidden.bs.modal', function() { modalMessage.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 `