added wiki functionality
This commit is contained in:
parent
4f53f41cc9
commit
c460cb51f3
|
@ -23,6 +23,10 @@ class Admin::PageContentsController < OrbitAdminController
|
||||||
@page = Page.find(params[:page_id])
|
@page = Page.find(params[:page_id])
|
||||||
if can_edit_or_delete?(@page)
|
if can_edit_or_delete?(@page)
|
||||||
@page_content = PageContext.new
|
@page_content = PageContext.new
|
||||||
|
@options = {}
|
||||||
|
@site_in_use_locales.each do |l|
|
||||||
|
@options[l.to_s] = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid]}
|
||||||
|
end
|
||||||
else
|
else
|
||||||
render_401
|
render_401
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
class Admin::WikiPagesController < OrbitAdminController
|
||||||
|
before_action ->(module_app = @app_title) { set_variables module_app }
|
||||||
|
|
||||||
|
def initialize
|
||||||
|
super
|
||||||
|
@app_title = "page_content"
|
||||||
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
@table_fields = [:title, :created_at, "page_content.parent_page", :last_modified]
|
||||||
|
@filter_fields = {}
|
||||||
|
@page = Page.find(params[:page_id]) rescue nil
|
||||||
|
if !@page.nil?
|
||||||
|
@wikis = @page.wiki_pages.order_by(sort)
|
||||||
|
@wikis = search_data(@wikis,[:name, :page_id]).page(params[:page]).per(10)
|
||||||
|
else
|
||||||
|
@wikis = WikiPage.all.order_by(sort)
|
||||||
|
@wikis = search_data(@wikis,[:title]).page(params[:page]).per(10)
|
||||||
|
end
|
||||||
|
render :partial => "index" if request.xhr?
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_on_the_go
|
||||||
|
wiki = WikiPage.create(wiki_page_params)
|
||||||
|
render :json => {"title" => wiki.title_translations, "id" => wiki.id.to_s}.to_json
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@page = Page.find(params[:page_id]) rescue nil
|
||||||
|
@wiki = WikiPage.new
|
||||||
|
@options = {}
|
||||||
|
@site_in_use_locales.each do |l|
|
||||||
|
@options[l.to_s] = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid]}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@page = Page.find(params[:page_id]) rescue nil
|
||||||
|
@wiki = WikiPage.find(params[:id])
|
||||||
|
@options = {}
|
||||||
|
@site_in_use_locales.each do |l|
|
||||||
|
t = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid] if wp.id != @wiki.id}
|
||||||
|
t.delete(nil)
|
||||||
|
@options[l.to_s] = t
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
wiki = WikiPage.create(wiki_page_params)
|
||||||
|
redirect_to admin_wiki_pages_path(:page_id => wiki.page.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
wiki = WikiPage.find(params[:id])
|
||||||
|
wiki.update_attributes(wiki_page_params)
|
||||||
|
redirect_to admin_wiki_pages_path(:page_id => wiki.page.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def wiki_page_params
|
||||||
|
params.require(:wiki_page).permit!
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,11 +1,21 @@
|
||||||
class PageContentsController < OrbitAdminController
|
class PageContentsController < OrbitAdminController
|
||||||
def index
|
def index
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
page = Page.where(:page_id => params[:page_id]).first
|
if params["wiki"].present?
|
||||||
url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : ""
|
page = WikiPage.where(:uid => params["wiki"]).first
|
||||||
|
name = page.title rescue ""
|
||||||
|
html = page.content rescue ""
|
||||||
|
url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/wiki_pages/#{page.id}/edit?page_id=#{page.page.id.to_s}" : ""
|
||||||
|
else
|
||||||
|
page = Page.where(:page_id => params[:page_id]).first
|
||||||
|
name = page.name rescue ""
|
||||||
|
html = page.page_contexts.last.content rescue ""
|
||||||
|
url_to_edit = OrbitHelper.user_can_edit?(page) ? "/admin/page_contents/new?page_id=#{page.id.to_s}" : ""
|
||||||
|
end
|
||||||
|
|
||||||
{
|
{
|
||||||
"html" => (page.page_contexts.last.content rescue ""),
|
"html" => html,
|
||||||
"title" => (page.name rescue ""),
|
"title" => name,
|
||||||
"view_count" => (page.view_count rescue ""),
|
"view_count" => (page.view_count rescue ""),
|
||||||
"view-count-head" =>t('page_content.view_count'),
|
"view-count-head" =>t('page_content.view_count'),
|
||||||
"url_to_edit" => url_to_edit
|
"url_to_edit" => url_to_edit
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
class WikiPage
|
||||||
|
include Mongoid::Document
|
||||||
|
include Mongoid::Timestamps
|
||||||
|
include OrbitModel::Impression
|
||||||
|
include Slug
|
||||||
|
|
||||||
|
field :update_user_id
|
||||||
|
field :view_count, :type => Integer, :default => 0
|
||||||
|
field :content, localize: true
|
||||||
|
field :title, localize: true
|
||||||
|
|
||||||
|
belongs_to :page
|
||||||
|
end
|
|
@ -16,6 +16,7 @@
|
||||||
<ul class="nav nav-pills">
|
<ul class="nav nav-pills">
|
||||||
<% if can_edit_or_delete?(page) %>
|
<% if can_edit_or_delete?(page) %>
|
||||||
<li><a href="/admin/page_contents/new?page_id=<%= page.id.to_s %>"><%= t(:edit) %></a></li>
|
<li><a href="/admin/page_contents/new?page_id=<%= page.id.to_s %>"><%= t(:edit) %></a></li>
|
||||||
|
<li><a href="/admin/wiki_pages/?page_id=<%= page.id.to_s %>"><%= t("page_content.wiki") %></a></li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,7 +15,16 @@
|
||||||
<div class="tab-content language-area">
|
<div class="tab-content language-area">
|
||||||
<!-- Language Tabs -->
|
<!-- Language Tabs -->
|
||||||
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||||
|
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
|
||||||
|
<div class="control-group input-content">
|
||||||
|
<%= label_tag(locale, t("page_content.wiki_pages"), :class=>"control-label muted") %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= select_tag "wikis[#{locale.to_s}]", options_for_select(@options[locale.to_s]), {:prompt => "----Select a WIKI----"} %>
|
||||||
|
<a href="#createWiki" class="btn btn-info" data-toggle="modal">Create</a>
|
||||||
|
<a href="" class="btn btn-primary insert_wiki_page <%= @options[locale.to_s].blank? ? "hide" : "" %>" >Insert</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
|
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
|
||||||
<div class="control-group input-content">
|
<div class="control-group input-content">
|
||||||
<%= f.fields_for :content_translations do |con| %>
|
<%= f.fields_for :content_translations do |con| %>
|
||||||
|
@ -30,12 +39,83 @@
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions">
|
|
||||||
<%= f.hidden_field :page_id, :value=>@page.id.to_s %>
|
|
||||||
<%= f.hidden_field :version, :value=>((@page.page_contexts.last.version + 1) rescue 1)%>
|
|
||||||
<input type="hidden" name="referer_url" value="<%= request.referer %>">
|
|
||||||
<%= f.submit t("page_content.save"), :class=> "btn btn-primary bt-form-save" %>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.hidden_field :page_id, :value=>@page.id.to_s %>
|
||||||
|
<%= f.hidden_field :version, :value=>((@page.page_contexts.last.version + 1) rescue 1)%>
|
||||||
|
<input type="hidden" name="referer_url" value="<%= request.referer %>">
|
||||||
|
<%= f.submit t("page_content.save"), :class=> "btn btn-primary bt-form-save" %>
|
||||||
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<div id="createWiki" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="createWikiLabel" aria-hidden="true">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h3 id="createWikiLabel">Add Wiki Page</h3>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="inside_wiki_page_form" class="form-horizontal main-forms">
|
||||||
|
<div class="input-area">
|
||||||
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||||
|
<div class="control-group input-content">
|
||||||
|
<label for="" class="control-label muted"><%= t(:title) + " " + t(locale) %></label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" name="wiki_page[title_translations][<%= locale.to_s %>]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<input type="hidden" name="wiki_page[update_user_id]" value="<%= current_user.id.to_s %>" />
|
||||||
|
<input type="hidden" name="wiki_page[page_id]" value="<%= params[:page_id] %>" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||||
|
<button class="btn btn-primary" id="createWikiPage">Create</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#createWikiPage").on("click",function(){
|
||||||
|
var form = $("#inside_wiki_page_form");
|
||||||
|
$.ajax({
|
||||||
|
url : "/admin/wiki_pages/create_on_the_go",
|
||||||
|
data : form.serializeArray(),
|
||||||
|
type : "post",
|
||||||
|
dataType : "json"
|
||||||
|
}).done(function(data){
|
||||||
|
$("#wikis_en").append("<option value='" + data.id + "'>" + data.title["en"] + "</option>");
|
||||||
|
$("#wikis_zh_tw").append("<option value='" + data.id + "'>" + data.title["zh_tw"] + "</option>");
|
||||||
|
$("#createWiki").modal("hide");
|
||||||
|
$(".insert_wiki_page").removeClass("hide");
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
|
||||||
|
$(".insert_wiki_page").on("click",function(){
|
||||||
|
var url = "/<%= I18n.locale.to_s + @page.url %>",
|
||||||
|
language = $(".language-nav li.active a").attr("href").replace(".",""),
|
||||||
|
editor = CKEDITOR.instances["page_context_content_translations_" + language],
|
||||||
|
val = $("#wikis_" + language).val(),
|
||||||
|
text = $("#wikis_" + language).find("option:selected").text(),
|
||||||
|
mySelection = editor.getSelection();
|
||||||
|
if (val != ""){
|
||||||
|
if (CKEDITOR.env.ie) {
|
||||||
|
mySelection.unlock(true);
|
||||||
|
selectedText = mySelection.getNative().createRange().text;
|
||||||
|
} else {
|
||||||
|
selectedText = mySelection.getNative().toString();
|
||||||
|
}
|
||||||
|
if(selectedText != ""){
|
||||||
|
editor.insertHtml("<a href='" + url + "/?wiki=" + val + "'>" + selectedText + "</a>");
|
||||||
|
}else{
|
||||||
|
editor.insertHtml("<a href='" + url + "/?wiki=" + val + "'>" + text + "</a>");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
alert("Please select a wiki page to insert.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
|
@ -0,0 +1,59 @@
|
||||||
|
<% content_for :page_specific_css do %>
|
||||||
|
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<div class="input-area">
|
||||||
|
<div class="nav-name"><strong><%= t(:language) %></strong></div>
|
||||||
|
<ul class="nav nav-pills language-nav">
|
||||||
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||||
|
<li <%= (i == 0 ? 'class=active' : '') %>>
|
||||||
|
<a href=".<%= locale %>" data-toggle="tab"><%= t(locale.to_s) %></a>
|
||||||
|
</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<div class="tab-content language-area">
|
||||||
|
<!-- Language Tabs -->
|
||||||
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||||
|
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
|
||||||
|
<div class="control-group input-content">
|
||||||
|
<%= f.fields_for :title_translations do |con| %>
|
||||||
|
<%= label_tag(locale, t(:title), :class=>"control-label muted") %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= con.text_field locale, :class => "input-block-level", :value => (@wiki.title_translations[locale] rescue nil)%>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
|
||||||
|
<div class="control-group input-content">
|
||||||
|
<%= label_tag(locale, t("page_content.wiki_pages"), :class=>"control-label muted") %>
|
||||||
|
<div class="controls">
|
||||||
|
<%= select_tag "wikis[#{locale.to_s}]", options_for_select(@options[locale.to_s]), {:prompt => "----Select a WIKI----"} %>
|
||||||
|
<a href="#createWiki" class="btn btn-info" data-toggle="modal">Create</a>
|
||||||
|
<a href="" class="btn btn-primary insert_wiki_page <%= @options[locale.to_s].blank? ? "hide" : "" %>" >Insert</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
|
||||||
|
<div class="control-group input-content">
|
||||||
|
<%= f.fields_for :content_translations do |con| %>
|
||||||
|
<%= label_tag(locale, t(:content), :class=>"control-label muted") %>
|
||||||
|
<div class="controls">
|
||||||
|
<div class="textarea">
|
||||||
|
<%= con.text_area locale, :class => "ckeditor input-block-level", :value => (@wiki.content_translations[locale] rescue nil)%>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-actions">
|
||||||
|
<%= f.hidden_field :update_user_id, :value=>current_user.id.to_s %>
|
||||||
|
<%= f.hidden_field :page_id, :value=>params[:page_id] %>
|
||||||
|
<input type="hidden" name="referer_url" value="<%= request.referer %>">
|
||||||
|
<%= f.submit t("page_content.save"), :class=> "btn btn-primary bt-form-save" %>
|
||||||
|
</div>
|
|
@ -0,0 +1,38 @@
|
||||||
|
<table class="table table-striped table-hover main-list">
|
||||||
|
<thead>
|
||||||
|
<tr class="sort-header">
|
||||||
|
<% @table_fields.each do |f| %>
|
||||||
|
<%= thead(f) %>
|
||||||
|
<% end %>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<% @wikis.each do |page| %>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="" target="_blank"><%= page.title %></a>
|
||||||
|
<div class="quick-edit">
|
||||||
|
<ul class="nav nav-pills">
|
||||||
|
<% if can_edit_or_delete?(page.page) %>
|
||||||
|
<li><a href="<%= edit_admin_wiki_page_path(page.id, :page_id => page.page.id) %>"><%= t(:edit) %></a></li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td><%= format_value page.created_at rescue nil %></td>
|
||||||
|
<td><%= page.page.page_id rescue "" %></td>
|
||||||
|
<td><%= User.find(page.update_user_id).user_name rescue nil %></td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="bottomnav clearfix">
|
||||||
|
<%= content_tag :div, paginate(@wikis), class: "pagination pagination-centered" %>
|
||||||
|
<div class="action pull-right">
|
||||||
|
<% if !@page.nil? && can_edit_or_delete?(@page) %>
|
||||||
|
<a href="<%= new_admin_wiki_page_path(:page_id => @page.id) %>" class="btn btn-small btn-info order-btn-class" id="edit-order-btn">Add</a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,76 @@
|
||||||
|
<%= form_for @wiki, :url => {:action => :update}, :html => {:class => 'form-horizontal main-forms'} do |f| %>
|
||||||
|
<fieldset>
|
||||||
|
<%= render :partial => "form", :locals => {:f => f} %>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
||||||
|
<div id="createWiki" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="createWikiLabel" aria-hidden="true">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h3 id="createWikiLabel">Add Wiki Page</h3>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="inside_wiki_page_form" class="form-horizontal main-forms">
|
||||||
|
<div class="input-area">
|
||||||
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||||
|
<div class="control-group input-content">
|
||||||
|
<label for="" class="control-label muted"><%= t(:title) + " " + t(locale) %></label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" name="wiki_page[title_translations][<%= locale.to_s %>]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<input type="hidden" name="wiki_page[update_user_id]" value="<%= current_user.id.to_s %>" />
|
||||||
|
<input type="hidden" name="wiki_page[page_id]" value="<%= params[:page_id] %>" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||||
|
<button class="btn btn-primary" id="createWikiPage">Create</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#createWikiPage").on("click",function(){
|
||||||
|
var form = $("#inside_wiki_page_form");
|
||||||
|
$.ajax({
|
||||||
|
url : "/admin/wiki_pages/create_on_the_go",
|
||||||
|
data : form.serializeArray(),
|
||||||
|
type : "post",
|
||||||
|
dataType : "json"
|
||||||
|
}).done(function(data){
|
||||||
|
$("#wikis_en").append("<option value='" + data.id + "'>" + data.title["en"] + "</option>");
|
||||||
|
$("#wikis_zh_tw").append("<option value='" + data.id + "'>" + data.title["zh_tw"] + "</option>");
|
||||||
|
$("#createWiki").modal("hide");
|
||||||
|
$(".insert_wiki_page").removeClass("hide");
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
|
||||||
|
$(".insert_wiki_page").on("click",function(){
|
||||||
|
var url = "/<%= I18n.locale.to_s + @page.url %>",
|
||||||
|
language = $(".language-nav li.active a").attr("href").replace(".",""),
|
||||||
|
editor = CKEDITOR.instances["wiki_page_content_translations_" + language],
|
||||||
|
val = $("#wikis_" + language).val(),
|
||||||
|
text = $("#wikis_" + language).find("option:selected").text(),
|
||||||
|
mySelection = editor.getSelection();
|
||||||
|
if (val != ""){
|
||||||
|
if (CKEDITOR.env.ie) {
|
||||||
|
mySelection.unlock(true);
|
||||||
|
selectedText = mySelection.getNative().createRange().text;
|
||||||
|
} else {
|
||||||
|
selectedText = mySelection.getNative().toString();
|
||||||
|
}
|
||||||
|
if(selectedText != ""){
|
||||||
|
editor.insertHtml("<a href='" + url + "/?wiki=" + val + "'>" + selectedText + "</a>");
|
||||||
|
}else{
|
||||||
|
editor.insertHtml("<a href='" + url + "/?wiki=" + val + "'>" + text + "</a>");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
alert("Please select a wiki page to insert.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
|
@ -0,0 +1,5 @@
|
||||||
|
<%= render_filter @filter_fields, "index_table" %>
|
||||||
|
<span id="index_table">
|
||||||
|
<%= render 'index'%>
|
||||||
|
</span>
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
<%= form_for @wiki, :url => {:action => :create}, :html => {:class => 'form-horizontal main-forms'} do |f| %>
|
||||||
|
<fieldset>
|
||||||
|
<%= render :partial => "form", :locals => {:f => f} %>
|
||||||
|
</fieldset>
|
||||||
|
<% end %>
|
||||||
|
<div id="createWiki" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="createWikiLabel" aria-hidden="true">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||||
|
<h3 id="createWikiLabel">Add Wiki Page</h3>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<form id="inside_wiki_page_form" class="form-horizontal main-forms">
|
||||||
|
<div class="input-area">
|
||||||
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
||||||
|
<div class="control-group input-content">
|
||||||
|
<label for="" class="control-label muted"><%= t(:title) + " " + t(locale) %></label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="text" name="wiki_page[title_translations][<%= locale.to_s %>]" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<input type="hidden" name="wiki_page[update_user_id]" value="<%= current_user.id.to_s %>" />
|
||||||
|
<input type="hidden" name="wiki_page[page_id]" value="<%= params[:page_id] %>" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||||
|
<button class="btn btn-primary" id="createWikiPage">Create</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
$("#createWikiPage").on("click",function(){
|
||||||
|
var form = $("#inside_wiki_page_form");
|
||||||
|
$.ajax({
|
||||||
|
url : "/admin/wiki_pages/create_on_the_go",
|
||||||
|
data : form.serializeArray(),
|
||||||
|
type : "post",
|
||||||
|
dataType : "json"
|
||||||
|
}).done(function(data){
|
||||||
|
$("#wikis_en").append("<option value='" + data.id + "'>" + data.title["en"] + "</option>");
|
||||||
|
$("#wikis_zh_tw").append("<option value='" + data.id + "'>" + data.title["zh_tw"] + "</option>");
|
||||||
|
$("#createWiki").modal("hide");
|
||||||
|
$(".insert_wiki_page").removeClass("hide");
|
||||||
|
})
|
||||||
|
return false;
|
||||||
|
})
|
||||||
|
|
||||||
|
$(".insert_wiki_page").on("click",function(){
|
||||||
|
var url = "/<%= I18n.locale.to_s + @page.url %>",
|
||||||
|
language = $(".language-nav li.active a").attr("href").replace(".",""),
|
||||||
|
editor = CKEDITOR.instances["wiki_page_content_translations_" + language],
|
||||||
|
val = $("#wikis_" + language).val(),
|
||||||
|
text = $("#wikis_" + language).find("option:selected").text(),
|
||||||
|
mySelection = editor.getSelection();
|
||||||
|
if (val != ""){
|
||||||
|
if (CKEDITOR.env.ie) {
|
||||||
|
mySelection.unlock(true);
|
||||||
|
selectedText = mySelection.getNative().createRange().text;
|
||||||
|
} else {
|
||||||
|
selectedText = mySelection.getNative().toString();
|
||||||
|
}
|
||||||
|
if(selectedText != ""){
|
||||||
|
editor.insertHtml("<a href='" + url + "/?wiki=" + val + "'>" + selectedText + "</a>");
|
||||||
|
}else{
|
||||||
|
editor.insertHtml("<a href='" + url + "/?wiki=" + val + "'>" + text + "</a>");
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
alert("Please select a wiki page to insert.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
</script>
|
|
@ -5,6 +5,8 @@ en:
|
||||||
view_count: View count
|
view_count: View count
|
||||||
save: Save
|
save: Save
|
||||||
all: All
|
all: All
|
||||||
|
wiki: Wiki Pages
|
||||||
|
parent_page: Parent Page Id
|
||||||
create_page_content_success: Page content was successfully created
|
create_page_content_success: Page content was successfully created
|
||||||
editing_page_content: Editing page content
|
editing_page_content: Editing page content
|
||||||
frontend:
|
frontend:
|
||||||
|
|
|
@ -4,6 +4,8 @@ zh_tw:
|
||||||
context: 內文
|
context: 內文
|
||||||
view_count: 瀏覽人次
|
view_count: 瀏覽人次
|
||||||
save: 送出
|
save: 送出
|
||||||
|
wiki: Wiki Pages
|
||||||
|
parent_page: Parent Page Id
|
||||||
create_page_content_success: 建立頁面內容成功
|
create_page_content_success: 建立頁面內容成功
|
||||||
editing_page_content: 編輯頁面內容
|
editing_page_content: 編輯頁面內容
|
||||||
all: All
|
all: All
|
||||||
|
|
|
@ -9,6 +9,9 @@ Rails.application.routes.draw do
|
||||||
get "view" => "page_contents#view"
|
get "view" => "page_contents#view"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :wiki_pages
|
||||||
|
post "/wiki_pages/create_on_the_go", to: 'wiki_pages#create_on_the_go'
|
||||||
|
|
||||||
post "/page_contents/save_category" => "page_contents#save_category"
|
post "/page_contents/save_category" => "page_contents#save_category"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ module PageContent
|
||||||
side_bar do
|
side_bar do
|
||||||
head_label_i18n 'page_content.page', icon_class: "icons-newspaper"
|
head_label_i18n 'page_content.page', icon_class: "icons-newspaper"
|
||||||
available_for "users"
|
available_for "users"
|
||||||
active_for_controllers (['admin/page_contents'])
|
active_for_controllers (['admin/page_contents', 'admin/wiki_pages'])
|
||||||
head_link_path "admin_page_contents_path"
|
head_link_path "admin_page_contents_path"
|
||||||
|
|
||||||
context_link 'page_content.all',
|
context_link 'page_content.all',
|
||||||
|
|
Loading…
Reference in New Issue