forked from saurabh/orbit4-5
633 lines
21 KiB
Plaintext
633 lines
21 KiB
Plaintext
<style type="text/css">
|
|
.import-wrapper{
|
|
padding: 10px;
|
|
}
|
|
.import-wrapper .import-url{
|
|
width: 565px;
|
|
}
|
|
.import-wrapper .btn{
|
|
margin-bottom: 10px;
|
|
}
|
|
#import-container{
|
|
width: auto;
|
|
margin: 0 auto;
|
|
}
|
|
#loading{
|
|
margin: 20px 0;
|
|
text-align: center;
|
|
display:none;
|
|
}
|
|
#loading img{
|
|
width: 50px;
|
|
}
|
|
#import-head{
|
|
font-size: 18px;
|
|
text-align: center;
|
|
text-shadow: 1px 1px 1px #FFF;
|
|
padding-bottom: 10px;
|
|
margin-top: 100px;
|
|
}
|
|
#import-head i{
|
|
font-size: 64px;
|
|
}
|
|
#site-url-wrapper{
|
|
height: 100px;
|
|
width: 600px;
|
|
margin: 0 auto;
|
|
}
|
|
#import-modules{
|
|
margin-top: 30px;
|
|
text-align: center;
|
|
}
|
|
.module{
|
|
text-align: center;
|
|
width: 120px;
|
|
display: inline-block;
|
|
margin: 8px 5px;
|
|
padding: 15px 0px;
|
|
}
|
|
.module i{
|
|
font-size: 48px;
|
|
border-radius: 10px;
|
|
border: 1px solid #FFF;
|
|
background: #888;
|
|
cursor: pointer;
|
|
padding: 15px 18px;
|
|
box-shadow: 0 0 10px #555 inset;
|
|
color: #FFF;
|
|
}
|
|
.module i:hover{
|
|
background: #438CDB;
|
|
box-shadow: none;
|
|
}
|
|
#import-modules .lead{
|
|
margin-bottom: 0px;
|
|
font-size: 12px;
|
|
}
|
|
.alert{
|
|
width: 500px;
|
|
margin: 20px auto 0;
|
|
}
|
|
.module-icon{
|
|
font-size: 64px;
|
|
border-radius: 10px;
|
|
padding: 15px 18px;
|
|
color: #888;
|
|
}
|
|
#import-progress{
|
|
border: 0px solid #CCC;
|
|
text-align: center;
|
|
width: 400px;
|
|
margin: 100px auto 0 auto;
|
|
}
|
|
#import-progress .progress{
|
|
margin-bottom: 0px;
|
|
}
|
|
#import-progress-text{
|
|
font-size: 16px;
|
|
line-height: 25px;
|
|
color: #666;
|
|
height: 50px;
|
|
margin-bottom: 5px;
|
|
}
|
|
</style>
|
|
|
|
<div id="import-container">
|
|
<div id="import-head" class="muted">
|
|
<i class='icon-cloud-download'></i><br/>
|
|
Import RSS2
|
|
</div>
|
|
|
|
<div id="loading">
|
|
<%= image_tag 'preloader.gif' %><br/>
|
|
<span id="progress_msg"></span>
|
|
</div>
|
|
|
|
<div id="site-url-wrapper" class="import-wrapper">
|
|
<input type="text" class="import-url" name="url" value="" placeholder="http://www.rulingcom.com">
|
|
<button id="check-site-url" class="btn btn-primary pull-right">Next <i class="icons-arrow-right"></i></button>
|
|
<span><a href='http://installer.tp.rulingcom.com/rss2-export-api.zip'>Download Rss2 Export API</a></span>
|
|
</div>
|
|
|
|
<div id="import-modules" class="hide">
|
|
<div id="members-module" class="module" onclick="importModule('members')">
|
|
<div class="lead muted">
|
|
<i class="icons-users"></i><br/>
|
|
<%= t("member_") %>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="announcement-module" class="module" onclick="importModule('announcement')">
|
|
<div class="lead muted">
|
|
<i class="icons-megaphone"></i><br/>
|
|
<%= t("announcement.announcement") %>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="archive-module" class="module" onclick="importModule('archive')">
|
|
<div class="lead muted">
|
|
<i class="icons-archive"></i><br/>
|
|
<%= t("archive.archive") %>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="pages-module" class="module" onclick="importModule('pages')">
|
|
<div class="lead muted">
|
|
<i class="icons-newspaper"></i><br/>
|
|
<%= t("page_content.page") %>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="gallery-module" class="module" onclick="importModule('gallery')">
|
|
<div class="lead muted">
|
|
<i class="icons-pictures"></i><br/>
|
|
<%= t("gallery.gallery") %>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="links-module" class="module" onclick="importModule('links')">
|
|
<div class="lead muted">
|
|
<i class="icons-link"></i><br/>
|
|
<%= t("web_resource") %>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="import-progress" class="hide">
|
|
<div class="head" style="border: 0px solid #CCC; margin: 5px; text-align: center;">
|
|
<i class=""></i>
|
|
</div>
|
|
<div class="content" style="border: 0px solid #CCC; height: 100px; margin: 5px">
|
|
<div class="progress">
|
|
<div class="bar" style="width: 0%;"></div>
|
|
</div>
|
|
<div id="import-progress-text"></div>
|
|
<button id="import-start-btn" class="btn btn-primary pull-right">Start</i></button>
|
|
<button id="import-back-btn" class="btn pull-left">Back</i></button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="alert alert-danger hide">
|
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
|
<span id="alert-msg"><%= @msg %></span>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">
|
|
var url;
|
|
var categories=null;
|
|
var dataList=Array();
|
|
var module;
|
|
var progress = 0;
|
|
|
|
$(".import-url").keyup(function(e){
|
|
var code = (e.keyCode ? e.keyCode : e.which);
|
|
if (code==13) { checkSiteUrl(); }
|
|
});
|
|
|
|
$("#check-site-url").click(function(){checkSiteUrl();});
|
|
|
|
$("#import-start-btn").click(function(){
|
|
switch(module){
|
|
case "pages":
|
|
importPages();
|
|
break;
|
|
case "gallery":
|
|
importGallery();
|
|
break;
|
|
case "links":
|
|
importLinks();
|
|
break;
|
|
case "members":
|
|
importMembers();
|
|
break;
|
|
default:
|
|
getModuleCategories();
|
|
}
|
|
});
|
|
$("#import-back-btn").click(function(){
|
|
$("#import-progress").fadeOut(300,function(){
|
|
$("#import-head").fadeIn(0);
|
|
$('#import-start-btn').show();
|
|
$("#import-modules").fadeIn(300);
|
|
});
|
|
});
|
|
|
|
var importPages = function(){
|
|
$("#import-progress .bar").css('width','0%');
|
|
$("#import-progress-text").html("Importing Pages...<br/>");
|
|
$.ajax({
|
|
type: "post",
|
|
dataType: "json",
|
|
url: '<%= admin_import_rss2_pages_path %>',
|
|
data : {"url" : url+'?module='+module}
|
|
}).done(function(){
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("There was an unknown error");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
})
|
|
startCheckingImportStatus();
|
|
}
|
|
|
|
var importLinks = function(){
|
|
$("#import-progress .bar").css('width','0%');
|
|
$("#import-progress-text").html("Importing Links...<br/>");
|
|
$.ajax({
|
|
type: "post",
|
|
dataType: "json",
|
|
url: '<%= admin_import_rss2_links_path %>',
|
|
data : {"url" : url+'?module='+module}
|
|
}).done(function(){
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("There was an unknown error");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
})
|
|
startCheckinglinksImportStatus();
|
|
}
|
|
var gallery_data = null;
|
|
var importGallery = function(){
|
|
$("#import-progress .bar").css('width','0%');
|
|
$("#import-progress-text").html("Importing Galleries...<br/>").delay(1000).html("Creating albums...<br />");
|
|
$.ajax({
|
|
type: "post",
|
|
dataType: "json",
|
|
url: '<%= admin_import_rss2_galleries_path %>',
|
|
data : {"url" : url+'?module='+module}
|
|
}).done(function(data){
|
|
$("#import-progress-text").html("Importing Images...<br/>");
|
|
gallery_data = data.images;
|
|
importImagesForAlbums(0);
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("There was an unknown error");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
|
|
})
|
|
}
|
|
|
|
var importImagesForAlbums = function(number){
|
|
var image = gallery_data[number],
|
|
total = gallery_data.length;
|
|
$("#import-progress-text").html("Importing Album " + image.album_name + "..." + (number + 1) + "/" + total + "<br/>");
|
|
$.ajax({
|
|
type: "post",
|
|
url: "<%= admin_import_rss2_album_image_path %>",
|
|
dataType : "json",
|
|
data : image
|
|
}).done(function(status){
|
|
if(status.success == true){
|
|
var percent = ((number + 1) * 100) / total;
|
|
$("#import-progress .bar").css('width',percent + "%");
|
|
if(number != (total - 1)){
|
|
setTimeout(importImagesForAlbums(number + 1),300)
|
|
}else{
|
|
$("#import-progress-text").html("Finished importing albums.");
|
|
}
|
|
}
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Error importing album " + image.album_name);
|
|
$("#alert-msg").text("Error importing album " + image.album_name);
|
|
$(".alert-danger").removeClass("hide").show();
|
|
})
|
|
|
|
}
|
|
|
|
|
|
var sto = null;
|
|
var new_members_data = null;
|
|
var importMembers = function(){
|
|
$("#import-progress .bar").css('width', '0%');
|
|
$("#import-progress-text").html("Importing Member..<br/>");
|
|
$.ajax({
|
|
type: "post",
|
|
url: '<%= admin_import_rss2_members_path %>',
|
|
data : {"url" : url+'?module='+module}
|
|
}).done(function(data){
|
|
if(data.success == true){
|
|
// clearTimeout(sto);
|
|
$("#import-progress-text").html("Finished importing Members.<br/>");
|
|
$("#import-progress .bar").css('width', '100%');
|
|
new_members_data = data.members;
|
|
importPlugins(0);
|
|
}
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("There was an unknown error");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
clearTimeout(sto);
|
|
})
|
|
// sto = setTimeout("startCheckingMemberImportStatus()",700);
|
|
}
|
|
var plugins = ["patents","books", "projects", "researches", "honors", "diplomas", "experiences", "journalpapers", "conferencespapers"];
|
|
var failed_plugins = [];
|
|
var importPlugins = function(number){
|
|
var member = new_members_data[number],
|
|
member_status = (member.name == null ? "Importing plugins for id " + member.rss2_id : "Importing plugins for member " + member.name);
|
|
$("#import-progress .bar").css('width', '0%');
|
|
$("#import-progress-text").html(member_status + "<br/><div id='plugin_name'></div>");
|
|
importplugin(member.rss2_id, 0,number)
|
|
}
|
|
|
|
var importplugin = function(id,p,number){
|
|
var plugin = plugins[p];
|
|
$("#import-progress-text #plugin_name").html(plugin.charAt(0).toUpperCase() + plugin.slice(1));
|
|
$.ajax({
|
|
url : "/admin/import/import_plugin",
|
|
type : "get",
|
|
data : {"rss2_id" : id, "plugin" : plugin, "url" : url},
|
|
dataType : "json"
|
|
}).done(function(){
|
|
var percent = ((p + 1) * 100) / plugins.length;
|
|
$("#import-progress .bar").css('width', percent + '%');
|
|
if(p != plugins.length - 1){
|
|
importplugin(id, p + 1,number);
|
|
}else if(p == plugins.length - 1){
|
|
if((number + 1) != new_members_data.length){
|
|
importPlugins(number + 1);
|
|
}else{
|
|
$("#import-progress-text").html("Importing members finished.");
|
|
}
|
|
}
|
|
}).fail(function(){
|
|
failed_plugins.push(plugin);
|
|
$("#alert-msg").text("There was an unknown error importing " + plugin + ".");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
if(p != plugins.length - 1){
|
|
importplugin(id, p + 1, number);
|
|
}else if(p == plugins.length - 1){
|
|
if((number + 1) != new_members_data.length){
|
|
importPlugins(number + 1);
|
|
}else{
|
|
$("#import-progress-text").html("Importing members finished.");
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
var importfailedplugin = function(id,p){
|
|
var plugin = failed_plugins[p];
|
|
$("#import-progress-text").append("Retrying " + plugin);
|
|
$.ajax({
|
|
url : "/admin/import_plugin",
|
|
type : "get",
|
|
data : {"rss2_id" : id, "plugin" : plugin},
|
|
dataType : "json"
|
|
}).done(function(){
|
|
var percent = ((p + failed_plugins.length + 1) * 100) / plugins.length;
|
|
$("#import-progress .bar").css('width', percent + '%');
|
|
if(p != failed_plugins.length - 1){
|
|
importfailedplugin(id, p + 1);
|
|
}
|
|
}).fail(function(){
|
|
$("#alert-msg").text("There was an unknown error importing" + plugin + ".");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
if(p != failed_plugins.length - 1){
|
|
importfailedplugin(id, p + 1);
|
|
}
|
|
})
|
|
return true;
|
|
}
|
|
|
|
var startCheckingMemberImportStatus = function(){
|
|
$.ajax({
|
|
type : "get",
|
|
dataType : "json",
|
|
data : {"module" : module},
|
|
url : "<%= admin_import_get_import_status_path %>"
|
|
}).done(function(status){
|
|
if(status.success == true){
|
|
if(status.total_members != null){
|
|
var percent = (status.current_status * 100) / status.total_members;
|
|
$("#import-progress .bar").css('width',percent + "%");
|
|
$("#import-progress-text").html("Importing Member " + status.current_member_name + " .. " + status.current_status + "/" + status.total_members + "<br/>");
|
|
}
|
|
if(status.total_members != status.current_status){
|
|
sto = setTimeout("startCheckingMemberImportStatus()",700);
|
|
}else{
|
|
if(status.total_members == null){
|
|
sto = setTimeout("startCheckingMemberImportStatus()",700);
|
|
}
|
|
$("#import-progress-text").html("Finished importing Members.<br/>");
|
|
}
|
|
}else if(status.success == false){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("Error importing member " + status.current_member_name + " Email : " + status.current_member)
|
|
$(".alert-danger").removeClass("hide").show();
|
|
}
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("There was an unknown error");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
})
|
|
}
|
|
|
|
var startCheckinglinksImportStatus = function(){
|
|
$.ajax({
|
|
type : "get",
|
|
dataType : "json",
|
|
data : {"module" : module},
|
|
url : "<%= admin_import_get_import_status_path %>"
|
|
}).done(function(status){
|
|
if(status.success == true){
|
|
if(status.current_import == "categories"){
|
|
$("#import-progress-text").html("Importing categories <br/>");
|
|
setTimeout("startCheckinglinksImportStatus()",700);
|
|
}else{
|
|
if(status.total_links != null){
|
|
var percent = (status.current_status * 100) / status.total_links;
|
|
$("#import-progress .bar").css('width',percent + "%");
|
|
$("#import-progress-text").html("Importing links " + status.current_link_name + " .. " + status.current_status + "/" + status.total_links + "<br/>");
|
|
}
|
|
if(status.total_links != status.current_status){
|
|
setTimeout("startCheckinglinksImportStatus()",700);
|
|
}else{
|
|
if(status.total_links == null){
|
|
setTimeout("startCheckinglinksImportStatus()",700);
|
|
}
|
|
$("#import-progress-text").html("Finished importing links.<br/>");
|
|
}
|
|
}
|
|
}else if(status.success == false){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("Error importing link " + status.current_link_name + " ID : " + status.current_link_id)
|
|
$(".alert-danger").removeClass("hide").show();
|
|
}
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("There was an unknown error");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
})
|
|
}
|
|
|
|
var startCheckingImportStatus = function(){
|
|
$.ajax({
|
|
type : "get",
|
|
dataType : "json",
|
|
data : {"module" : module},
|
|
url : "<%= admin_import_get_import_status_path %>"
|
|
}).done(function(status){
|
|
if(status.success == true){
|
|
if(status.total_pages != null){
|
|
var percent = (status.current_status * 100) / status.total_pages;
|
|
$("#import-progress .bar").css('width',percent + "%");
|
|
$("#import-progress-text").html("Importing page " + status.current_page_name + " .. " + status.current_status + "/" + status.total_pages + "<br/>");
|
|
}
|
|
if(status.total_pages != status.current_status){
|
|
setTimeout("startCheckingImportStatus()",700);
|
|
}else{
|
|
if(status.total_pages == null){
|
|
setTimeout("startCheckingImportStatus()",700);
|
|
}
|
|
$("#import-progress-text").html("Finished importing pages.<br/>");
|
|
}
|
|
}else if(status.success == false){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("Error importing page " + status.current_page_name + " ID : " + status.current_page)
|
|
$(".alert-danger").removeClass("hide").show();
|
|
}
|
|
}).fail(function(){
|
|
$("#import-progress-text").html("Importing failed, click on start to try again.");
|
|
$("#alert-msg").text("There was an unknown error");
|
|
$(".alert-danger").removeClass("hide").show();
|
|
})
|
|
}
|
|
|
|
var importModule = function(m){
|
|
module = m;
|
|
progress = 0;
|
|
dataList=Array();
|
|
categories=null;
|
|
|
|
$('#import-progress i').attr('class', $('#'+m+'-module i').attr('class')+' module-icon');
|
|
$("#import-progress .bar").css('width','0%');
|
|
$("#import-progress-text").html("");
|
|
|
|
$("#import-modules").fadeOut(300,function(){
|
|
$("#import-head").fadeOut(0);
|
|
$("#import-progress").fadeIn(300,function(){
|
|
});
|
|
});
|
|
}
|
|
|
|
var getModuleCategories= function(){
|
|
$("#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'}
|
|
}).done(function(data){
|
|
$("#import-progress-text").html("Done<br/><br/>");
|
|
categories = data;
|
|
getModuleDataList();
|
|
});
|
|
}
|
|
|
|
var getModuleDataList = function(){
|
|
$.ajax({
|
|
type: 'GET',
|
|
dataType: 'json',
|
|
url: '<%= admin_import_module_data_list_path %>',
|
|
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(){
|
|
progress = 0;
|
|
$('#import-start-btn').hide();
|
|
$("#import-progress-text").html("Start import...<br/><br/>");
|
|
|
|
if(dataList!=null && categories!=null){
|
|
importModuleData();
|
|
}else{
|
|
setTimeout("importModuleDatas()", 3000);
|
|
}
|
|
}
|
|
|
|
var importModuleData = function(){
|
|
if(progress>=dataList.length) return;
|
|
|
|
var data = dataList[progress];
|
|
if(data['category']==0){
|
|
progress++;
|
|
importModuleData();
|
|
return;
|
|
}
|
|
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){
|
|
}).fail(function(data){
|
|
$("#alert-msg").html('Faild to import Sn:'+progress+'<br/>Message:'+data['status']+'-'+data['statusText']);
|
|
$(".alert").fadeIn(300).delay(5000).fadeOut(300);
|
|
}).always(function(){
|
|
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);
|
|
$('#import-start-btn').show();
|
|
});
|
|
}
|
|
|
|
importModuleData();
|
|
});
|
|
}
|
|
|
|
var checkSiteUrl = function(){
|
|
url = $(".import-url").val();
|
|
url = (url[url.length-1]=='/') ? url+'export/' : url+'/export/';
|
|
|
|
$(".alert").hide();
|
|
|
|
if(/http[s]?:\/\/[a-zA-Z0-9.-\/]+/.test(url)){
|
|
$("#site-url-wrapper").fadeOut(300, function(){
|
|
$("#progress_msg").html("Checking connection...");
|
|
$("#loading").fadeIn(0);
|
|
$.getJSON('<%= admin_import_check_url_path %>', {url: url},function(data){
|
|
$("#loading").fadeOut(function(){
|
|
if(data['status']=="ok"){
|
|
$("#import-head").animate({ marginTop: '0px' },{
|
|
duration: 300,
|
|
complete: function() {
|
|
$("#import-modules").fadeIn(300);
|
|
}
|
|
});
|
|
}else{
|
|
$("#alert-msg").html(data['status']);
|
|
$(".alert").fadeIn(300);
|
|
$("#site-url-wrapper").fadeIn(300);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}else{
|
|
$("#alert-msg").html("Invalid URL");
|
|
$(".alert").fadeIn(300).delay(2000).fadeOut(300);
|
|
}
|
|
}
|
|
</script> |