var autocompleteModule = require('hyrax/autocomplete'); Blacklight.onLoad(function () { /** * Post modal data via Ajax to avoid nesting in edit collections tabs screen * @param {string} url URL where to submit the AJAX request * @param {string} type The type of network request: 'POST', 'DELETE', etc. * @param {object} data Data object to send with network request. Should default to {} * @param {jQuery object} $self Reference to the jQuery context ie. $(this) of calling statemnt * @return {void} */ function submitModalAjax(url, type, data, $self) { $.ajax({ type: type, url: url, data: data }).done(function(response) { }).fail(function(err) { var alertNode = buildModalErrorAlert(err); var $alert = $self.closest('.modal').find('.modal-ajax-alert'); $alert.html(alertNode); }); } /** * HTML for ajax error alert message, in case the AJAX request fails * @param {object} err AJAX response object * @return {string} The constructed HTML alert string */ function buildModalErrorAlert(err) { var message = (err.responseText ? err.responseText : 'An unknown error has occurred'); var elHtml = ''; return elHtml; } /** * Handle delete collection submit button click from within a generic modal * @return {void} */ function handleModalDeleteCollection() { var $self = $(this), $modal = $self.closest('.modal'), url = $modal.data('postDeleteUrl'), data = {}; if (url.length === 0) { return; } $self.prop('disabled', true); submitModalAjax(url, 'DELETE', data, $self); } /** * Sync collection data attributes to the singular instance of the modal so it knows what data to post * @param {string} modalId - The id of modal to target, ie. #add_collection_modal * @param {[string]} dataAttributes - An string array of "data-xyz" data attributes WITHOUT * the "data-" prefix. ie. ['id', 'some-var'] * @param {jquery Object} $dataEl - jQuery object reference which has values of data attributes we're copying over * @return {void} */ function addDataAttributesToModal(modalId, dataAttributes, $dataEl) { // Remove and add new data attributes dataAttributes.forEach(function(attribute) { $(modalId).removeAttr('data-' + attribute).attr('data-' + attribute, $dataEl.data(attribute)); }); } /** * Build