forked from saurabh/orbit4-5
Import RSS2 UI
This commit is contained in:
parent
94ad217259
commit
218e7f16df
|
@ -21,8 +21,8 @@ $(function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
// Initialize the jQuery File Upload widget:
|
// Initialize the jQuery File Upload widget:
|
||||||
$('#fileupload').fileupload({
|
$('#fileupload').fileupload({
|
||||||
maxFileSize: 5000000,
|
maxFileSize: 10000000,
|
||||||
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|doc|docx|ppt|pptx|xls|xlsx)$/i,
|
acceptFileTypes: /(\.|\/)(gif|jpe?g|png|pdf|doc|docx|ppt|pptx|xls|xlsx|csv|txt |zip|rar|tar|gz)$/i,
|
||||||
dropZone: $('#dropzone'),
|
dropZone: $('#dropzone'),
|
||||||
headers:{
|
headers:{
|
||||||
'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content")
|
'X-CSRF-Token': $('meta[name="csrf-token"]').attr("content")
|
||||||
|
|
|
@ -4,186 +4,191 @@ require "uri"
|
||||||
require 'json'
|
require 'json'
|
||||||
|
|
||||||
class Admin::ImportController < OrbitAdminController
|
class Admin::ImportController < OrbitAdminController
|
||||||
before_action :get_data ,:except=>'index'
|
layout "structure"
|
||||||
|
|
||||||
|
def check_url
|
||||||
|
params['url'] = params['url']+"/" if params['url'].last!="/"
|
||||||
|
uri = URI.parse(params['url'])
|
||||||
|
|
||||||
def rss2_news
|
begin
|
||||||
@new_category_ids = {}
|
@host = uri.host
|
||||||
module_id = ModuleApp.where(:key=>"announcement").first.id
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
@categories.each do |category|
|
response = http.request(request)
|
||||||
x = Category.where(:title => category["zh_tw"]).first
|
data = response.body
|
||||||
if x.nil?
|
data = JSON.parse(data)
|
||||||
cat = Category.new
|
msg = data['status']
|
||||||
titles = {}
|
rescue
|
||||||
@site_valid_locales.each do |locale|
|
msg = "Failed to connect to RSS2 (#{uri.to_s})"
|
||||||
titles[locale] = category[locale.to_s]
|
|
||||||
end
|
|
||||||
cat.title_translations = titles
|
|
||||||
cat.module_app_id = module_id
|
|
||||||
cat.save!
|
|
||||||
@new_category_ids[category["id"]] = cat.id
|
|
||||||
else
|
|
||||||
@new_category_ids[category["id"]] = x.id
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@data.each do |row|
|
render :json=>{"status"=>msg}
|
||||||
bulletin = Bulletin.new
|
|
||||||
bulletin.update_user = @user
|
|
||||||
bulletin.title_translations = row['Title']
|
|
||||||
bulletin.subtitle_translations = row['Summary']
|
|
||||||
|
|
||||||
next if row['Title']==[] and row['Summary']==[] and row['Content']==[]
|
|
||||||
|
|
||||||
@site_valid_locales.each do |locale|
|
|
||||||
locale = locale.to_s
|
|
||||||
if row['Content'][locale]=="" and row['Summary'][locale]!=""
|
|
||||||
row['Content'][locale] = row['Summary'][locale]
|
|
||||||
row['Summary'][locale] = " "
|
|
||||||
end
|
|
||||||
|
|
||||||
temp = row['Content'][locale]
|
|
||||||
|
|
||||||
urls = Nokogiri::HTML(temp).css("img").map do |link|
|
|
||||||
|
|
||||||
if URI.parse(link.attr("src")).host == @host
|
|
||||||
link.attr("src")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
urls.each do |url|
|
|
||||||
next if url.nil?
|
|
||||||
a = Asset.new
|
|
||||||
a.remote_data_url = url
|
|
||||||
a.title_translations = {"en" => a.data.filename, "zh_tw" => a.data.filename}
|
|
||||||
a.save!
|
|
||||||
@user.assets << a
|
|
||||||
temp.gsub!(CGI::escapeHTML(url), a.data.to_s)
|
|
||||||
end
|
|
||||||
row['Content'][locale] = temp
|
|
||||||
end
|
|
||||||
|
|
||||||
bulletin.text_translations = row['Content']
|
|
||||||
bulletin.category = Category.find(@new_category_ids[row["Category"]])
|
|
||||||
bulletin.view_count = row["Visits"].blank? ? 0 : row["Visits"]
|
|
||||||
bulletin.postdate = row["PostDate"]
|
|
||||||
bulletin.deadline = row['Deadline']
|
|
||||||
bulletin.remote_image_url = row["Pic"] if row["Pic"]
|
|
||||||
|
|
||||||
if row["URL"] && row['URL'] != ""
|
|
||||||
bl = BulletinLink.new
|
|
||||||
bl.url = row["URL"]
|
|
||||||
bl.title_translations = {"en" => "Link", "zh_tw" => "Link"}
|
|
||||||
bl.save!
|
|
||||||
bulletin.bulletin_links << bl
|
|
||||||
end
|
|
||||||
row['files'].each do |f|
|
|
||||||
bf = BulletinFile.new
|
|
||||||
if f['url'].split('title=').size == 1
|
|
||||||
f['url'] = f['url']+"檔案下載"
|
|
||||||
end
|
|
||||||
|
|
||||||
f['title'] = "檔案下載" if f['title'].blank?
|
|
||||||
|
|
||||||
bf.remote_file_url = f['url']
|
|
||||||
bf.title_translations = {"en" => f['title'], "zh_tw" => f['title']}
|
|
||||||
bf.save!
|
|
||||||
|
|
||||||
# Rename uploaded file
|
|
||||||
file_ext = File.extname(f['url'].split('&')[0])
|
|
||||||
file = File.new("tmp/uploads/#{bf.title}#{file_ext}","w+b")
|
|
||||||
file.write(bf.file.read)
|
|
||||||
bf.file.cache!(file)
|
|
||||||
bf.save!
|
|
||||||
|
|
||||||
bulletin.bulletin_files << bf
|
|
||||||
|
|
||||||
File.delete(file)
|
|
||||||
end
|
|
||||||
|
|
||||||
bulletin.save!
|
|
||||||
end
|
|
||||||
|
|
||||||
I18n.locale = @org_locale
|
|
||||||
|
|
||||||
redirect_to('/admin/announcements')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def rss2_archive
|
def module_categories
|
||||||
unless @site_url.nil?
|
module_app = ModuleApp.find_by(:key=>params['module'])
|
||||||
module_app = ModuleApp.where(:key=>"archive").first
|
uri = URI.parse(params['url'])
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
|
response = http.request(request)
|
||||||
|
data = response.body
|
||||||
|
categories = JSON.parse(data)
|
||||||
|
|
||||||
@new_categories = {}
|
|
||||||
@categories.each do |id, category|
|
|
||||||
old_cate = Category.where(:title => category['title']["zh-tw"]).first
|
|
||||||
if old_cate.nil?
|
|
||||||
cate = Category.new
|
|
||||||
titles = {}
|
|
||||||
@site_valid_locales.each do |locale|
|
|
||||||
titles[locale] = category['title'][locale.to_s.gsub('_', '-')]
|
|
||||||
end
|
|
||||||
cate.title_translations = titles
|
|
||||||
cate.save!
|
|
||||||
module_app.categories << cate
|
|
||||||
@new_categories[id] = cate.id
|
|
||||||
else
|
|
||||||
@new_categories[id] = old_cate.id
|
|
||||||
end
|
|
||||||
end
|
|
||||||
I18n.locale = :en
|
|
||||||
|
|
||||||
@data.each do |id, file|
|
|
||||||
titles = {}
|
|
||||||
@site_valid_locales.each do |locale|
|
|
||||||
titles[locale] = file['title'][locale.to_s.gsub('_', '-')]
|
|
||||||
end
|
|
||||||
|
|
||||||
the_file = ArchiveFileMultiple.new({
|
|
||||||
:file_title_translations=>titles,
|
|
||||||
:choose_lang => @site_valid_locales,
|
|
||||||
:remote_file_url => @site_url+file['url'],
|
|
||||||
:sort_number=>file['sort_number']
|
|
||||||
})
|
|
||||||
the_file.save
|
|
||||||
|
|
||||||
archive_file = ArchiveFile.new({
|
|
||||||
:title_translations=>titles,
|
|
||||||
:sort_number=>file['sort_number']
|
|
||||||
})
|
|
||||||
archive_file.category = Category.find(@new_categories[file["category"]])
|
|
||||||
|
|
||||||
archive_file.create_user_id = current_user.id
|
|
||||||
archive_file.update_user_id = current_user.id
|
|
||||||
|
|
||||||
archive_file.save
|
|
||||||
archive_file.archive_file_multiples << the_file
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
I18n.locale = @org_locale
|
|
||||||
|
|
||||||
redirect_to admin_archive_files_path
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def get_data
|
|
||||||
@org_locale = I18n.locale
|
|
||||||
I18n.locale = :zh_tw
|
I18n.locale = :zh_tw
|
||||||
|
categories.each do |id, category|
|
||||||
|
old_cate = module_app.categories.where(:title => category["zh_tw"]).first
|
||||||
|
if old_cate.nil?
|
||||||
|
cat = Category.new
|
||||||
|
cat.title_translations = category
|
||||||
|
cat.save!
|
||||||
|
module_app.categories << cat
|
||||||
|
categories[id]['id'] = cat.id.to_s
|
||||||
|
else
|
||||||
|
categories[id]['id'] = old_cate.id.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
render :json=>categories
|
||||||
|
end
|
||||||
|
|
||||||
@site_url = params['site_url']
|
def module_data_list
|
||||||
@url = params['url']
|
uri = URI.parse(params['url'])
|
||||||
uri = URI.parse(@url)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
@host = uri.host
|
response = http.request(request)
|
||||||
|
data = response.body
|
||||||
|
data = JSON.parse(data)
|
||||||
|
render :json=>data
|
||||||
|
end
|
||||||
|
|
||||||
|
def module_data
|
||||||
|
uri = URI.parse(params['url'])
|
||||||
http = Net::HTTP.new(uri.host, uri.port)
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
request = Net::HTTP::Get.new(uri.request_uri)
|
request = Net::HTTP::Get.new(uri.request_uri)
|
||||||
response = http.request(request)
|
response = http.request(request)
|
||||||
data = response.body
|
data = response.body
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
|
|
||||||
@categories = data['categories']
|
case params['module']
|
||||||
@data = data['data']
|
when 'archive'
|
||||||
|
import_archive(data)
|
||||||
|
when 'announcement'
|
||||||
|
import_announcement(data)
|
||||||
|
end
|
||||||
|
render :json=>['status'=>'ok']
|
||||||
|
end
|
||||||
|
|
||||||
|
def import_archive(file)
|
||||||
|
archive_file = ArchiveFile.where(:rss2_sn=>file['Sn']).first
|
||||||
|
if archive_file.nil?
|
||||||
|
archive_file = ArchiveFile.new
|
||||||
|
archive_file.rss2_sn = file['Sn']
|
||||||
|
end
|
||||||
|
|
||||||
|
archive_file.title_translations = file['title']
|
||||||
|
archive_file.sort_number = file['sort_number']
|
||||||
|
archive_file.category = Category.find(params["category"])
|
||||||
|
archive_file.create_user_id = current_user.id
|
||||||
|
archive_file.update_user_id = current_user.id
|
||||||
|
archive_file.save
|
||||||
|
|
||||||
|
if(file['url'])
|
||||||
|
archive = ArchiveFileMultiple.new({
|
||||||
|
:file_title_translations=>file['title'],
|
||||||
|
:choose_lang => @site_valid_locales,
|
||||||
|
:remote_file_url => file['url'],
|
||||||
|
:sort_number=>file['sort_number']
|
||||||
|
})
|
||||||
|
archive.save
|
||||||
|
archive_file.archive_file_multiples << archive
|
||||||
|
end
|
||||||
|
|
||||||
|
if(file['url2'])
|
||||||
|
archive = ArchiveFileMultiple.new({
|
||||||
|
:file_title_translations=>file['title'],
|
||||||
|
:choose_lang => @site_valid_locales,
|
||||||
|
:remote_file_url => file['url2'],
|
||||||
|
:sort_number=>file['sort_number']
|
||||||
|
})
|
||||||
|
archive.save
|
||||||
|
archive_file.archive_file_multiples << archive
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def import_announcement(news)
|
||||||
|
bulletin = Bulletin.where(:rss2_sn=>news['Sn']).first
|
||||||
|
if bulletin.nil?
|
||||||
|
bulletin = Bulletin.new
|
||||||
|
bulletin.rss2_sn = news['Sn']
|
||||||
|
end
|
||||||
|
bulletin.update_user = current_user
|
||||||
|
bulletin.title_translations = news['Title']
|
||||||
|
bulletin.subtitle_translations = news['Summary']
|
||||||
|
|
||||||
|
@site_valid_locales.each do |locale|
|
||||||
|
locale = locale.to_s
|
||||||
|
if news['Content'][locale]=="" and news['Summary'][locale]!=""
|
||||||
|
news['Content'][locale] = news['Summary'][locale]
|
||||||
|
news['Summary'][locale] = " "
|
||||||
|
end
|
||||||
|
|
||||||
|
temp = news['Content'][locale]
|
||||||
|
|
||||||
|
urls = Nokogiri::HTML(temp).css("img").map do |link|
|
||||||
|
|
||||||
|
if URI.parse(link.attr("src")).host == @host
|
||||||
|
link.attr("src")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
urls.each do |url|
|
||||||
|
next if url.nil?
|
||||||
|
a = Asset.new
|
||||||
|
a.remote_data_url = url
|
||||||
|
a.title_translations = {"en" => a.data.filename, "zh_tw" => a.data.filename}
|
||||||
|
a.save!
|
||||||
|
@user.assets << a
|
||||||
|
temp.gsub!(CGI::escapeHTML(url), a.data.to_s)
|
||||||
|
end
|
||||||
|
news['Content'][locale] = temp
|
||||||
|
end
|
||||||
|
|
||||||
|
bulletin.text_translations = news['Content']
|
||||||
|
bulletin.category = Category.find(params["category"])
|
||||||
|
bulletin.view_count = news["Visits"].blank? ? 0 : news["Visits"]
|
||||||
|
bulletin.postdate = news["PostDate"]
|
||||||
|
bulletin.deadline = news['Deadline']
|
||||||
|
bulletin.remote_image_url = news["Pic"] if news["Pic"]
|
||||||
|
|
||||||
|
if news["URL"] && news['URL'] != ""
|
||||||
|
bl = BulletinLink.new
|
||||||
|
bl.url = news["URL"]
|
||||||
|
bl.title_translations = {"en" => "Link", "zh_tw" => "Link"}
|
||||||
|
bl.save!
|
||||||
|
bulletin.bulletin_links << bl
|
||||||
|
end
|
||||||
|
news['files'].each do |f|
|
||||||
|
bf = BulletinFile.new
|
||||||
|
if f['url'].split('title=').size == 1
|
||||||
|
f['url'] = f['url']+"檔案下載"
|
||||||
|
end
|
||||||
|
|
||||||
|
f['title'] = "檔案下載" if f['title'].blank?
|
||||||
|
|
||||||
|
bf.remote_file_url = f['url']
|
||||||
|
bf.title_translations = {"en" => f['title'], "zh_tw" => f['title']}
|
||||||
|
bf.save!
|
||||||
|
|
||||||
|
# Rename uploaded file
|
||||||
|
file_ext = File.extname(f['url'].split('&')[0])
|
||||||
|
file = File.new("tmp/uploads/#{bf.title}#{file_ext}","w+b")
|
||||||
|
file.write(bf.file.read)
|
||||||
|
bf.file.cache!(file)
|
||||||
|
bf.save!
|
||||||
|
|
||||||
|
bulletin.bulletin_files << bf
|
||||||
|
|
||||||
|
File.delete(file)
|
||||||
|
end
|
||||||
|
|
||||||
@user = User.where(:user_name => "rulingcom").first
|
bulletin.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,31 +1,291 @@
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.import_wrapper{
|
.import-wrapper{
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
.import_wrapper .import-url{
|
.import-wrapper .import-url{
|
||||||
width: 500px;
|
width: 565px;
|
||||||
}
|
}
|
||||||
.import_wrapper .btn{
|
.import-wrapper .btn{
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
.lead{
|
#import-container{
|
||||||
border-bottom: 1px solid #DDD;
|
width: 600px;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
#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{
|
||||||
|
}
|
||||||
|
.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>
|
</style>
|
||||||
|
|
||||||
<div class="import_wrapper">
|
<div id="import-container">
|
||||||
<div class="lead muted"><i class="icons-megaphone"></i><%= t("announcement.announcement") %></div>
|
<div id="import-head" class="muted">
|
||||||
<form method="post" action="/admin/import/rss2_news">
|
<i class='icon-cloud-download'></i><br/>
|
||||||
<input type="text" class="import-url" name="url" placeholder="RSS2 Export URL ex: http://rss2.rulingcom.com/DEMO24_ALL/export_news/"><br/>
|
Import RSS2
|
||||||
<input type="submit" class="btn btn-primary" value="<%= t(:submit) %>">
|
</div>
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="import_wrapper">
|
<div id="loading">
|
||||||
<div class="lead muted"><i class="icons-archive"></i><%= t("archive.archive") %></div>
|
<%= image_tag 'preloader.gif' %><br/>
|
||||||
<form method="post" action="/admin/import/rss2_archive">
|
<span id="progress_msg"></span>
|
||||||
<input type="text" class="import-url" name="site_url" placeholder="RSS2 Site URL ex: http://rss2.rulingcom.com/DEMO24_ALL"><br/>
|
</div>
|
||||||
<input type="text" class="import-url" name="url" placeholder="RSS2 Export URL ex: http://rss2.rulingcom.com/DEMO24_ALL/export_archive/"><br/>
|
|
||||||
<input type="submit" class="btn btn-primary" value="<%= t(:submit) %>">
|
<div id="site-url-wrapper" class="import-wrapper">
|
||||||
</form>
|
<input type="text" class="import-url" name="url" placeholder="http://www.rulingcom.com">
|
||||||
</div>
|
<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="member-module" class="module" onclick="importModule('member')">
|
||||||
|
<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="page-module" class="module" onclick="importModule('page')">
|
||||||
|
<div class="lead muted">
|
||||||
|
<i class="icons-newspaper"></i><br/>
|
||||||
|
<%= t("page_content.page") %>
|
||||||
|
</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=null;
|
||||||
|
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(){getModuleCategories()});
|
||||||
|
$("#import-back-btn").click(function(){
|
||||||
|
$("#import-progress").fadeOut(300,function(){
|
||||||
|
$("#import-head").fadeIn(0);
|
||||||
|
$("#import-modules").fadeIn(300);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var importModule = function(m){
|
||||||
|
module = m;
|
||||||
|
dataList=null;
|
||||||
|
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 .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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var importModuleDatas = function(){
|
||||||
|
$("#import-progress .bar").css('width','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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
setTimeout("importModuleDatas()", 3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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>
|
|
@ -20,6 +20,8 @@
|
||||||
<li title="<%= t('update_manager') %>"><%= link_to admin_site_update_manager_path(current_site), :class => active_for_action('sites', 'update_manager') do %><span><i class="icon-refresh"></i></span><%end%></li>
|
<li title="<%= t('update_manager') %>"><%= link_to admin_site_update_manager_path(current_site), :class => active_for_action('sites', 'update_manager') do %><span><i class="icon-refresh"></i></span><%end%></li>
|
||||||
|
|
||||||
<li title="<%= t("site.system_preference") %>"><%= link_to admin_site_system_info_path(current_site), :class => active_for_action('sites', 'system_info') do %><span><i class="icons-info-2"></i></span><%end%></li>
|
<li title="<%= t("site.system_preference") %>"><%= link_to admin_site_system_info_path(current_site), :class => active_for_action('sites', 'system_info') do %><span><i class="icons-info-2"></i></span><%end%></li>
|
||||||
|
|
||||||
|
<li title="<%= t("site.import_rss2") %>"><%= link_to admin_import_path, :class => active_for_action('import','') do %><span><i class="icon-cloud-download"></i></span><%end%></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="sub-nav-arrow"></div>
|
<div class="sub-nav-arrow"></div>
|
||||||
|
|
|
@ -484,6 +484,7 @@ en:
|
||||||
frontend_open: Frontend Open
|
frontend_open: Frontend Open
|
||||||
disable_personal_desktop: Disable Personal Desktop
|
disable_personal_desktop: Disable Personal Desktop
|
||||||
header: Site header
|
header: Site header
|
||||||
|
import_rss2: Import RSS2
|
||||||
info: Site information
|
info: Site information
|
||||||
keywords: Site keywords
|
keywords: Site keywords
|
||||||
keywords_help: Keyword Guide
|
keywords_help: Keyword Guide
|
||||||
|
|
|
@ -480,6 +480,7 @@ zh_tw:
|
||||||
footer: 網站頁尾
|
footer: 網站頁尾
|
||||||
footer_help: 網站頁尾說明
|
footer_help: 網站頁尾說明
|
||||||
header: 網站頁首
|
header: 網站頁首
|
||||||
|
import_rss2: 匯入RSS2
|
||||||
info: 網站資訊
|
info: 網站資訊
|
||||||
keywords: 搜尋關鍵字
|
keywords: 搜尋關鍵字
|
||||||
keywords_help: 關鍵字說明
|
keywords_help: 關鍵字說明
|
||||||
|
|
|
@ -199,6 +199,10 @@ Orbit::Application.routes.draw do
|
||||||
get 'module_store' => 'module_store#index'
|
get 'module_store' => 'module_store#index'
|
||||||
|
|
||||||
get "import" => "import#index"
|
get "import" => "import#index"
|
||||||
|
get "import/check_url" => "import#check_url"
|
||||||
|
get "import/module_categories" => "import#module_categories"
|
||||||
|
get "import/module_data_list" => "import#module_data_list"
|
||||||
|
get "import/module_data" => "import#module_data"
|
||||||
post "import/rss2_news" => "import#rss2_news"
|
post "import/rss2_news" => "import#rss2_news"
|
||||||
post "import/rss2_archive" => "import#rss2_archive"
|
post "import/rss2_archive" => "import#rss2_archive"
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue