Update import announcement and archive

This commit is contained in:
manson 2014-06-17 11:45:08 +08:00
parent 5a88f5dd47
commit 264e61df15
2 changed files with 57 additions and 39 deletions

View File

@ -85,6 +85,8 @@ class Admin::ImportController < OrbitAdminController
if archive_file.nil?
archive_file = ArchiveFile.new
archive_file.rss2_sn = file['Sn']
else
archive_file.archive_file_multiples.destroy_all
end
archive_file.title_translations = file['title']
@ -122,6 +124,9 @@ class Admin::ImportController < OrbitAdminController
if bulletin.nil?
bulletin = Bulletin.new
bulletin.rss2_sn = news['Sn']
else
bulletin.bulletin_links.destroy_all
bulletin.bulletin_files.destroy_all
end
bulletin.update_user = current_user
bulletin.title_translations = news['Title']

View File

@ -148,7 +148,7 @@
<div id="links-module" class="module" onclick="importModule('links')">
<div class="lead muted">
<i class="icons-link"></i><br/>
<%= t("web_link.web_link") %>
<%= t("web_resource") %>
</div>
</div>
</div>
@ -175,7 +175,7 @@
<script type="text/javascript">
var url;
var categories=null;
var dataList=null;
var dataList=Array();
var module;
var progress = 0;
@ -364,7 +364,7 @@
var importModule = function(m){
module = m;
dataList=null;
dataList=Array();
categories=null;
$('#import-progress i').attr('class', $('#'+m+'-module i').attr('class')+' module-icon');
@ -379,69 +379,82 @@
}
var getModuleCategories= function(){
$("#import-progress .bar").css('width','0%');
$("#import-progress-text").html("Importing Categories<br/><br/>");
$.ajax({
type: 'GET',
dataType: 'json',
url: '<%= admin_import_module_categories_path %>',
data: {module: module, url: url+'?module='+module+'&type=categories'},
success: function(data){
$("#import-progress .bar").css('width','100%');
$("#import-progress-text").html("Done<br/><br/>");
categories = data;
getModuleDataList();
}
data: {module: module, url: url+'?module='+module+'&type=categories'}
}).done(function(data){
$("#import-progress-text").html("Done<br/><br/>");
categories = data;
getModuleDataList();
});
}
var getModuleDataList = function(){
$("#import-progress .bar").css('width','0%');
$.ajax({
type: 'GET',
dataType: 'json',
url: '<%= admin_import_module_data_list_path %>',
data: {module: module, url: url+'?module='+module+'&type=dataList'},
success: function(data){
dataList = data;
importModuleDatas();
data: {module: module, url: url+'?module='+module+'&type=dataList'}
}).done(function(data){
for(Sn in data){
dataList.push({'Sn':Sn, 'category':data[Sn]});
}
importModuleDatas();
});
}
var importModuleDatas = function(){
$("#import-progress .bar").css('width','0%');
progress = 0;
$("#import-progress-text").html("Start import...<br/><br/>");
if(dataList!=null && categories!=null){
$.each(dataList, function(key, val){
$.ajax({
type: 'GET',
dataType: 'json',
async: true,
url: '<%= admin_import_module_data_path %>?&category='+categories[val]['id'],
data: {module: module, url: url+'?module='+module+'&type=data&Sn='+key},
success: function(data){
progress++;
percentage = parseInt((progress/Object.keys(dataList).length)*100)+'%';
$("#import-progress .bar").css('width',percentage);
$("#import-progress-text").html(progress+' / '+Object.keys(dataList).length+'<br/>'+percentage);
if(percentage=="100%"){
$("#import-progress").delay(1000).fadeOut(300,function(){
$("#import-head").fadeIn(0);
$("#import-modules").fadeIn(300);
});
}
}
});
});
importModuleData();
}else{
setTimeout("importModuleDatas()", 3000);
}
}
var importModuleData = function(){
if(progress>=dataList.length) return;
var data = dataList[progress];
var category_id = categories[data['category']]['id'];
var Sn = data['Sn'];
percentage = parseInt((progress/dataList.length)*100)+'%';
$("#import-progress-text").html(progress+' / '+dataList.length+'<br/>'+percentage);
$.ajax({
type: 'GET',
dataType: 'json',
url: '<%= admin_import_module_data_path %>',
data: {
module: module,
url: url+'?module='+module+'&type=data&Sn='+Sn,
type: 'data',
category: category_id
}
}).done(function(data){
progress++;
percentage = parseInt((progress/dataList.length)*100)+'%';
$("#import-progress .bar").css('width',percentage);
$("#import-progress-text").html(progress+' / '+dataList.length+'<br/>'+percentage);
if(percentage=="100%"){
$("#import-progress").delay(1000).fadeOut(300,function(){
$("#import-head").fadeIn(0);
$("#import-modules").fadeIn(300);
});
}
importModuleData();
});
}
var checkSiteUrl = function(){
url = $(".import-url").val();
url = (url[url.length-1]=='/') ? url+'export/' : url+'/export/';