scinote-web/app/assets/javascripts/repositories/index.js

103 lines
2.7 KiB
JavaScript
Raw Normal View History

2017-06-19 20:05:37 +08:00
//= require repositories/import/records_importer.js
(function() {
'use strict';
2017-06-19 20:05:37 +08:00
function showNewRepository() {
$('#create-repo-modal').on('ajax:success', function(data) {
var location = data.url;
window.location.replace(location);
});
}
function initCreateRepository() {
$('.create-repository').off().on('click', function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
$.ajax({
url: $(this).attr('href'),
type: 'GET',
dataType: 'json',
success: function(data) {
$(data.html).appendTo('body').promise().done(function() {
$('#create-repo-modal').modal('show');
});
},
error: function() {
location.reload();
}
})
});
}
2017-06-14 15:11:20 +08:00
function loadRepositoryTab() {
var param, pane;
$('#repository-tabs a').on("click", function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
pane = $(this);
$.ajax({
2017-06-14 16:55:24 +08:00
url: pane.attr('data-url'),
2017-06-14 15:11:20 +08:00
type: 'GET',
dataType: 'json',
2017-06-14 16:55:24 +08:00
success: function(data) {
var tabBody = $(pane.context.hash).find('.tab-content-body');
2017-06-14 15:11:20 +08:00
tabBody.html(data.html);
2017-06-19 20:05:37 +08:00
pane.tab('show').promise().done(function() {
initImportRecordsModal();
});
2017-06-14 15:11:20 +08:00
},
error: function (error) {
// TODO
}
});
});
// on page load
if( param = getParam('repository') ){
// load selected tab
$('a[href="#custom_repo_' + param + '"]').click();
}
else {
// load first tab content
$('#repository-tabs a:first').click();
}
// clean tab content
2017-06-19 20:05:37 +08:00
$('a[data-toggle="tab"]').on('hide.bs.tab', function(e) {
2017-06-14 15:11:20 +08:00
$(".tab-content-body").html("");
})
}
2017-06-19 20:05:37 +08:00
function initImportRecordsModal() {
$('#importRecordsButton').off().on('click', function() {
$('#modal-import-records').modal('show');
initParseRecordsModal();
2017-06-14 16:55:24 +08:00
});
}
2017-06-19 20:05:37 +08:00
function initParseRecordsModal() {
$('#form-records-file').on('ajax:success', function(ev, data) {
$('#modal-import-records').modal('hide');
$(data.html).appendTo('body').promise().done(function() {
$('#parse-records_modal').modal('show');
repositoryRecordsImporter();
});
});
};
$('.delete-repo-option').initializeModal('#delete-repo-modal');
$('.rename-repo-option').initializeModal('#rename-repo-modal');
2017-06-08 00:43:48 +08:00
$('.copy-repo-option').initializeModal('#copy-repo-modal');
2017-06-19 20:05:37 +08:00
// $('.create-repository').initializeModal('#create-repo-modal');
2017-06-08 17:44:24 +08:00
2017-06-14 15:11:20 +08:00
$(document).ready(function() {
loadRepositoryTab();
2017-06-19 20:05:37 +08:00
// showParsedRecords();
initCreateRepository();
2017-06-08 17:44:24 +08:00
});
2017-06-14 15:11:20 +08:00
})();