2020-06-01 16:24:03 +08:00
|
|
|
//= require repositories/import/records_importer.js
|
|
|
|
|
|
|
|
/*
|
2023-05-16 15:34:36 +08:00
|
|
|
global animateSpinner repositoryRecordsImporter I18n
|
2022-02-01 21:37:13 +08:00
|
|
|
RepositoryDatatable PerfectScrollbar HelperModule repositoryFilterObject
|
2020-06-01 16:24:03 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
(function(global) {
|
2018-03-20 21:45:57 +08:00
|
|
|
'use strict';
|
|
|
|
|
2023-05-16 15:34:36 +08:00
|
|
|
function pageReload() {
|
2020-06-01 16:24:03 +08:00
|
|
|
animateSpinner();
|
|
|
|
location.reload();
|
2023-05-16 15:34:36 +08:00
|
|
|
}
|
2020-06-01 16:24:03 +08:00
|
|
|
|
|
|
|
function handleErrorSubmit(XHR) {
|
|
|
|
var formGroup = $('#form-records-file').find('.form-group');
|
|
|
|
formGroup.addClass('has-error');
|
|
|
|
formGroup.find('.help-block').remove();
|
2024-02-20 17:58:09 +08:00
|
|
|
$('#form-records-file input[type="submit"]').removeAttr('disabled');
|
|
|
|
$('#parse-sheet-loader').addClass('hidden');
|
2020-06-01 16:24:03 +08:00
|
|
|
formGroup.append(
|
|
|
|
'<span class="help-block">' + XHR.responseJSON.message + '</span>'
|
|
|
|
);
|
2023-12-18 18:27:08 +08:00
|
|
|
HelperModule.flashAlertMsg(XHR.responseJSON.message, 'danger');
|
2020-06-01 16:24:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function handleSuccessfulSubmit(data) {
|
2024-02-20 17:58:09 +08:00
|
|
|
$('#form-records-file input[type="submit"]').removeAttr('disabled');
|
|
|
|
$('#parse-sheet-loader').addClass('hidden');
|
2020-06-01 16:24:03 +08:00
|
|
|
$('#modal-import-records').modal('hide');
|
|
|
|
$(data.html).appendTo('body').promise().done(function() {
|
2023-10-20 18:53:34 +08:00
|
|
|
$('#parse-records-modal').modal('show');
|
2020-06-01 16:24:03 +08:00
|
|
|
repositoryRecordsImporter();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-08 16:58:28 +08:00
|
|
|
function initTable() {
|
|
|
|
RepositoryDatatable.destroy();
|
|
|
|
RepositoryDatatable.init('#' + $('.repository-table table').attr('id'));
|
|
|
|
RepositoryDatatable.redrawTableOnSidebarToggle();
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
function initParseRecordsModal() {
|
2020-06-01 16:24:03 +08:00
|
|
|
var form = $('#form-records-file');
|
|
|
|
var submitBtn = form.find('input[type="submit"]');
|
|
|
|
form.on('ajax:success', function(ev, data) {
|
2018-03-20 21:45:57 +08:00
|
|
|
$('#modal-import-records').modal('hide');
|
|
|
|
$(data.html).appendTo('body').promise().done(function() {
|
|
|
|
repositoryRecordsImporter();
|
|
|
|
});
|
|
|
|
}).on('ajax:error', function(ev, data) {
|
|
|
|
$(this).find('.form-group').addClass('has-error');
|
|
|
|
$(this).find('.form-group').find('.help-block').remove();
|
|
|
|
$(this).find('.form-group').append("<span class='help-block'>" +
|
|
|
|
data.responseJSON.message + '</span>');
|
|
|
|
});
|
2020-06-01 16:24:03 +08:00
|
|
|
|
|
|
|
submitBtn.on('click', function(event) {
|
|
|
|
var data = new FormData();
|
2024-02-20 17:58:09 +08:00
|
|
|
submitBtn.attr('disabled', true);
|
|
|
|
$('#parse-sheet-loader').removeClass('hidden');
|
2020-06-01 16:24:03 +08:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
data.append('file', document.getElementById('file').files[0]);
|
|
|
|
data.append('team_id', document.getElementById('team_id').value);
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: form.attr('action'),
|
|
|
|
data: data,
|
|
|
|
success: handleSuccessfulSubmit,
|
|
|
|
error: handleErrorSubmit,
|
|
|
|
processData: false,
|
|
|
|
contentType: false
|
|
|
|
});
|
|
|
|
});
|
2018-03-20 21:45:57 +08:00
|
|
|
}
|
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
function initImportRecordsModal() {
|
2022-03-18 21:10:34 +08:00
|
|
|
$('.repository-show').on('click', '#importRecordsButton', function() {
|
2018-07-19 23:56:42 +08:00
|
|
|
$('#modal-import-records').modal('show');
|
|
|
|
initParseRecordsModal();
|
|
|
|
});
|
2018-03-20 21:45:57 +08:00
|
|
|
}
|
|
|
|
|
2020-06-17 20:05:23 +08:00
|
|
|
$('.repository-title-name .inline-editing-container').on('inlineEditing::updated', function(e, value, viewValue) {
|
|
|
|
$('.repository-archived-title-name')
|
2020-07-08 19:42:27 +08:00
|
|
|
.text(I18n.t('repositories.show.archived_inventory_items', { repository_name: viewValue }));
|
2020-06-17 20:05:23 +08:00
|
|
|
$('#toolbarButtonsDatatable .archived-label')
|
|
|
|
.text(I18n.t('repositories.show.archived_view_label.active', { repository_name: viewValue }));
|
|
|
|
});
|
|
|
|
|
2020-06-24 17:32:20 +08:00
|
|
|
function initArchivingActionsInDropdown() {
|
|
|
|
$('.archive-repository-option').on('click', function(event) {
|
2020-06-24 04:59:21 +08:00
|
|
|
event.preventDefault();
|
2020-06-24 17:32:20 +08:00
|
|
|
animateSpinner(null, true);
|
|
|
|
|
2020-06-24 04:59:21 +08:00
|
|
|
$.ajax({
|
2020-06-24 17:32:20 +08:00
|
|
|
type: 'POST',
|
|
|
|
url: $(this).attr('href'),
|
|
|
|
dataType: 'json',
|
|
|
|
data: { repository_ids: [$(this).data('repositoryId')] },
|
|
|
|
success: pageReload,
|
|
|
|
error: function(ev) {
|
|
|
|
if (ev.status === 403) {
|
|
|
|
HelperModule.flashAlertMsg(I18n.t('repositories.js.permission_error'), ev.responseJSON.style);
|
|
|
|
} else if (ev.status === 422) {
|
|
|
|
HelperModule.flashAlertMsg(ev.responseJSON.error, 'danger');
|
|
|
|
}
|
|
|
|
animateSpinner(null, false);
|
|
|
|
}
|
2020-06-24 04:59:21 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-05 22:02:09 +08:00
|
|
|
function initFilterSaving() {
|
2022-02-11 20:32:27 +08:00
|
|
|
$(document).on('click', '#newFilterLink', function() {
|
|
|
|
$('#modalSaveRepositoryTableFilter #repository_table_filter_name').val('');
|
|
|
|
});
|
|
|
|
|
2022-02-15 22:03:25 +08:00
|
|
|
$('#modalSaveRepositoryTableFilter').on('shown.bs.modal', function() {
|
|
|
|
$('#repository_table_filter_name').focus();
|
|
|
|
});
|
|
|
|
|
2022-01-05 22:02:09 +08:00
|
|
|
$(document).on('click', '#overwriteFilterLink', function() {
|
|
|
|
var $modal = $('#modalSaveRepositoryTableFilter');
|
|
|
|
|
|
|
|
// set overwrite flag
|
|
|
|
$modal.data('overwrite', true);
|
|
|
|
|
|
|
|
// revert to 'create' form
|
|
|
|
$modal.on('hidden.bs.modal', function() {
|
|
|
|
$modal.removeData('overwrite');
|
|
|
|
});
|
2022-02-11 20:32:27 +08:00
|
|
|
|
2022-02-15 22:03:25 +08:00
|
|
|
|
2022-02-11 20:32:27 +08:00
|
|
|
$('#modalSaveRepositoryTableFilter #repository_table_filter_name')
|
|
|
|
.val($modal.data('repositoryTableFilterName'));
|
2022-01-05 22:02:09 +08:00
|
|
|
});
|
|
|
|
|
2022-02-23 21:30:28 +08:00
|
|
|
$('#saveRepositoryTableFilterButton').on('click', function() {
|
2022-01-05 22:02:09 +08:00
|
|
|
var $modal = $('#modalSaveRepositoryTableFilter');
|
2022-02-11 17:14:19 +08:00
|
|
|
var $button = $(this);
|
2022-01-05 22:02:09 +08:00
|
|
|
var url = $modal.data().saveUrl;
|
|
|
|
var method;
|
|
|
|
|
|
|
|
if ($modal.data().overwrite) {
|
|
|
|
method = 'PUT';
|
|
|
|
url = url + '/' + $modal.data().repositoryTableFilterId;
|
|
|
|
} else {
|
|
|
|
method = 'POST';
|
|
|
|
}
|
|
|
|
|
2022-02-11 17:14:19 +08:00
|
|
|
$button.addClass('disabled');
|
|
|
|
|
2022-01-05 22:02:09 +08:00
|
|
|
$.ajax({
|
|
|
|
type: method,
|
|
|
|
url: url,
|
|
|
|
contentType: 'application/json; charset=utf-8',
|
|
|
|
data: JSON.stringify({
|
|
|
|
repository_table_filter: {
|
|
|
|
name: $('#repository_table_filter_name').val(),
|
|
|
|
repository_table_filter_elements_json: $('#repository_table_filter_elements_json').val()
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
success: function(response) {
|
2022-02-01 21:37:13 +08:00
|
|
|
var existingFilterIndex = repositoryFilterObject.savedFilters.findIndex((f) => {
|
|
|
|
return f.id === response.data.id;
|
|
|
|
});
|
|
|
|
|
2022-01-05 22:02:09 +08:00
|
|
|
var $overwriteLink = $('#overwriteFilterLink');
|
|
|
|
$modal.modal('hide');
|
|
|
|
$overwriteLink.removeClass('hidden');
|
2022-02-01 21:37:13 +08:00
|
|
|
$modal.data('repositoryTableFilterId', response.data.id);
|
2022-02-11 20:32:27 +08:00
|
|
|
$modal.data('repositoryTableFilterName', response.data.attributes.name);
|
2023-03-09 18:38:47 +08:00
|
|
|
$('#currentFilterName').text(response.data.attributes.name);
|
2022-01-12 21:39:42 +08:00
|
|
|
|
2022-02-11 20:32:27 +08:00
|
|
|
|
2022-02-01 21:37:13 +08:00
|
|
|
if (existingFilterIndex > -1) {
|
|
|
|
repositoryFilterObject.savedFilters = repositoryFilterObject.savedFilters.map((f) => {
|
|
|
|
return f.id === response.data.id ? response.data : f;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
repositoryFilterObject.savedFilters = repositoryFilterObject.savedFilters.concat([response.data]);
|
|
|
|
}
|
|
|
|
|
|
|
|
repositoryFilterObject.filterName = response.data.attributes.name;
|
2022-02-11 17:14:19 +08:00
|
|
|
$button.removeClass('disabled');
|
2022-01-05 22:02:09 +08:00
|
|
|
},
|
|
|
|
error: function(response) {
|
|
|
|
HelperModule.flashAlertMsg(response.responseJSON.message, 'danger');
|
2022-02-11 17:14:19 +08:00
|
|
|
$button.removeClass('disabled');
|
2022-02-11 20:32:27 +08:00
|
|
|
$modal.modal('hide');
|
2022-01-05 22:02:09 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
initImportRecordsModal();
|
|
|
|
initTable();
|
2020-06-24 04:59:21 +08:00
|
|
|
initArchivingActionsInDropdown();
|
2022-01-05 22:02:09 +08:00
|
|
|
initFilterSaving();
|
2020-06-01 16:24:03 +08:00
|
|
|
}(window));
|