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

77 lines
1.9 KiB
JavaScript
Raw Normal View History

2017-06-19 20:05:37 +08:00
//= require repositories/import/records_importer.js
(function(global) {
'use strict';
global.pageReload = function() {
animateSpinner();
location.reload();
}
function initImportRecordsModal() {
$('#importRecordsButton').off().on('click', function() {
$('#modal-import-records').modal('show');
_initParseRecordsModal();
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')
.on('hidden.bs.modal', function() {
animateSpinner();
location.reload();
});
repositoryRecordsImporter();
});
2017-06-19 20:05:37 +08:00
});
}
2017-06-14 15:11:20 +08:00
function loadRepositoryTab() {
var param;
2017-06-14 15:11:20 +08:00
$('#repository-tabs a').on("click", function(e) {
e.preventDefault();
var pane = $(this);
2017-06-14 15:11:20 +08:00
$.ajax({
url: $(this).attr("data-url"),
type: "GET",
dataType: "json",
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();
2017-06-14 15:11:20 +08:00
}
else {
// load first tab content
$('#repository-tabs a:first').click();
}
// clean tab content
$('a[data-toggle="tab"]').on('hide.bs.tab', function (e) {
2017-06-14 15:11:20 +08:00
$(".tab-content-body").html("");
})
}
$('.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();
initImportRecordsModal();
2017-06-08 17:44:24 +08:00
});
})(window);