2017-06-19 20:05:37 +08:00
|
|
|
//= require repositories/import/records_importer.js
|
2018-07-19 23:56:42 +08:00
|
|
|
|
|
|
|
/*
|
2019-08-29 19:45:27 +08:00
|
|
|
global animateSpinner repositoryRecordsImporter getParam
|
|
|
|
RepositoryDatatable PerfectScrollbar HelperModule
|
2018-07-19 23:56:42 +08:00
|
|
|
*/
|
|
|
|
|
2017-06-22 20:43:01 +08:00
|
|
|
(function(global) {
|
2017-05-30 21:11:28 +08:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-22 20:43:01 +08:00
|
|
|
global.pageReload = function() {
|
|
|
|
animateSpinner();
|
|
|
|
location.reload();
|
2019-08-12 21:02:16 +08:00
|
|
|
};
|
2017-06-22 20:43:01 +08:00
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
function handleErrorSubmit(XHR) {
|
|
|
|
var formGroup = $('#form-records-file').find('.form-group');
|
|
|
|
formGroup.addClass('has-error');
|
|
|
|
formGroup.find('.help-block').remove();
|
|
|
|
formGroup.append(
|
|
|
|
'<span class="help-block">' + XHR.responseJSON.message + '</span>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleSuccessfulSubmit(data) {
|
|
|
|
$('#modal-import-records').modal('hide');
|
|
|
|
$(data.html).appendTo('body').promise().done(function() {
|
|
|
|
$('#parse-records-modal')
|
|
|
|
.modal('show')
|
|
|
|
.on('hidden.bs.modal', function() {
|
|
|
|
animateSpinner();
|
|
|
|
location.reload();
|
|
|
|
});
|
|
|
|
repositoryRecordsImporter();
|
2018-05-08 15:41:40 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
function initParseRecordsModal() {
|
2018-05-08 15:41:40 +08:00
|
|
|
var form = $('#form-records-file');
|
|
|
|
var submitBtn = form.find('input[type="submit"]');
|
|
|
|
submitBtn.on('click', function(event) {
|
2018-07-19 23:56:42 +08:00
|
|
|
var data = new FormData();
|
2018-05-08 15:41:40 +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,
|
2018-07-19 23:56:42 +08:00
|
|
|
success: handleSuccessfulSubmit,
|
|
|
|
error: handleErrorSubmit,
|
2018-05-08 15:41:40 +08:00
|
|
|
processData: false,
|
2018-07-19 23:56:42 +08:00
|
|
|
contentType: false
|
2018-05-08 15:41:40 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-19 23:56:42 +08:00
|
|
|
function initImportRecordsModal() {
|
|
|
|
$('#importRecordsButton').off().on('click', function() {
|
|
|
|
$('#modal-import-records').modal('show');
|
|
|
|
initParseRecordsModal();
|
2018-05-08 15:41:40 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadRepositoryTab() {
|
2018-07-19 23:56:42 +08:00
|
|
|
var param = getParam('repository');
|
|
|
|
$('#repository-tabs a').on('click', function(e) {
|
2018-05-08 15:41:40 +08:00
|
|
|
var pane = $(this);
|
2018-07-19 23:56:42 +08:00
|
|
|
e.preventDefault();
|
2018-05-08 15:41:40 +08:00
|
|
|
$.ajax({
|
2018-07-19 23:56:42 +08:00
|
|
|
url: $(this).attr('data-url'),
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
|
|
|
var tabBody = $(pane.context.hash).find('.tab-content-body');
|
2018-05-08 15:41:40 +08:00
|
|
|
tabBody.html(data.html);
|
|
|
|
pane.tab('show').promise().done(function(el) {
|
|
|
|
initImportRecordsModal();
|
2018-07-19 23:56:42 +08:00
|
|
|
RepositoryDatatable.destroy();
|
2018-05-08 15:41:40 +08:00
|
|
|
RepositoryDatatable.init(el.attr('data-repo-table'));
|
|
|
|
});
|
|
|
|
},
|
2018-07-19 23:56:42 +08:00
|
|
|
error: function() {
|
2018-05-08 15:41:40 +08:00
|
|
|
// TODO
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// on page load
|
2018-07-19 23:56:42 +08:00
|
|
|
if (param) {
|
2018-05-08 15:41:40 +08:00
|
|
|
// load selected tab
|
2018-07-19 23:56:42 +08:00
|
|
|
$('a[href="#custom_repo_' + param + '"]').click();
|
|
|
|
} else {
|
2018-05-08 15:41:40 +08:00
|
|
|
// load first tab content
|
|
|
|
$('#repository-tabs a:first').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
// clean tab content
|
2018-07-19 23:56:42 +08:00
|
|
|
$('a[data-toggle="tab"]').on('hide.bs.tab', function() {
|
|
|
|
$('.tab-content-body').html('');
|
|
|
|
});
|
2018-05-08 15:41:40 +08:00
|
|
|
}
|
|
|
|
|
2019-08-05 19:07:29 +08:00
|
|
|
function initShareModal() {
|
2019-08-12 21:02:16 +08:00
|
|
|
var form = $('.share-repo-modal').find('form');
|
2019-08-06 21:17:13 +08:00
|
|
|
var sharedCBs = form.find("input[name='share_team_ids[]']");
|
|
|
|
var permissionCBs = form.find("input[name='write_permissions[]']");
|
|
|
|
var permissionChanges = form.find("input[name='permission_changes']");
|
|
|
|
var submitBtn = form.find('input[type="submit"]');
|
2020-01-24 22:43:13 +08:00
|
|
|
var selectAllCheckbox = form.find('.all-teams .sci-checkbox');
|
2019-08-12 21:02:16 +08:00
|
|
|
|
2020-01-24 22:43:13 +08:00
|
|
|
form.find('.teams-list').find('input.sci-checkbox, .permission-selector')
|
2019-08-13 20:05:55 +08:00
|
|
|
.toggleClass('hidden', selectAllCheckbox.is(':checked'));
|
2020-01-24 22:43:13 +08:00
|
|
|
form.find('.all-teams .sci-toggle-checkbox')
|
2019-08-13 20:05:55 +08:00
|
|
|
.toggleClass('hidden', !selectAllCheckbox.is(':checked'))
|
|
|
|
.attr('disabled', !selectAllCheckbox.is(':checked'));
|
|
|
|
|
2019-08-12 21:02:16 +08:00
|
|
|
selectAllCheckbox.change(function() {
|
2020-01-24 22:43:13 +08:00
|
|
|
form.find('.teams-list').find('input.sci-checkbox, .permission-selector')
|
2019-08-13 20:05:55 +08:00
|
|
|
.toggleClass('hidden', this.checked);
|
2020-01-24 22:43:13 +08:00
|
|
|
form.find('.all-teams .sci-toggle-checkbox').toggleClass('hidden', !this.checked)
|
2019-08-12 21:02:16 +08:00
|
|
|
.attr('disabled', !this.checked);
|
|
|
|
});
|
2019-08-05 19:07:29 +08:00
|
|
|
|
|
|
|
sharedCBs.change(function() {
|
2020-02-12 17:37:29 +08:00
|
|
|
var selectedTeams = form.find('.teams-list .sci-checkbox:checked').length;
|
|
|
|
form.find('#select_all_teams').prop('indeterminate', selectedTeams > 0);
|
2019-08-12 21:02:16 +08:00
|
|
|
$('#editable_' + this.value).toggleClass('hidden', !this.checked)
|
|
|
|
.attr('disabled', !this.checked);
|
2019-08-05 19:07:29 +08:00
|
|
|
});
|
2019-08-06 21:17:13 +08:00
|
|
|
|
2019-10-22 16:46:16 +08:00
|
|
|
if (form.find('.teams-list').length) new PerfectScrollbar(form.find('.teams-list')[0]);
|
2019-08-12 21:02:16 +08:00
|
|
|
|
2019-08-06 21:17:13 +08:00
|
|
|
permissionCBs.change(function() {
|
|
|
|
var changes = JSON.parse(permissionChanges.val());
|
|
|
|
changes[this.value] = 'true';
|
|
|
|
permissionChanges.val(JSON.stringify(changes));
|
|
|
|
});
|
|
|
|
|
|
|
|
submitBtn.on('click', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: form.attr('action'),
|
|
|
|
data: form.serialize(),
|
|
|
|
success: function(data) {
|
|
|
|
if (data.warnings) {
|
|
|
|
alert(data.warnings);
|
|
|
|
}
|
2019-08-26 17:24:22 +08:00
|
|
|
$(`#slide-panel li.active .repository-share-status,
|
|
|
|
#repository-toolbar .repository-share-status
|
|
|
|
`).toggleClass('hidden', !data.status);
|
2019-08-29 19:45:27 +08:00
|
|
|
HelperModule.flashAlertMsg(form.data('success-message'), 'success');
|
2019-08-12 21:02:16 +08:00
|
|
|
$('.share-repo-modal').modal('hide');
|
2019-08-06 21:17:13 +08:00
|
|
|
},
|
|
|
|
error: function(data) {
|
|
|
|
alert(data.responseJSON.errors);
|
2019-08-12 21:02:16 +08:00
|
|
|
$('.share-repo-modal').modal('hide');
|
2019-08-06 21:17:13 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-08-05 19:07:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$('#shareRepoBtn').on('ajax:success', function() {
|
|
|
|
initShareModal();
|
|
|
|
});
|
|
|
|
|
2019-08-19 20:01:48 +08:00
|
|
|
$('.create-new-repository').initializeModal('#create-repo-modal');
|
2018-07-19 23:56:42 +08:00
|
|
|
loadRepositoryTab();
|
|
|
|
initImportRecordsModal();
|
|
|
|
}(window));
|