pagecontent/app/views/admin/wiki_pages/edit.html.erb

76 lines
2.8 KiB
Plaintext
Raw Normal View History

2016-08-24 13:28:22 +00:00
<%= 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>