pagecontent/app/views/admin/page_contents/new.html.erb

121 lines
5.4 KiB
Plaintext
Raw Normal View History

2014-05-06 09:20:15 +00:00
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<% end %>
<% @page_context = @page.page_contexts.order(:version=>-1).first #take last version page_context %>
2014-05-06 09:20:15 +00:00
<%= form_for @page_content, :url => {:action => :create}, :html => {:class => 'form-horizontal main-forms'} do |f| %>
<fieldset>
<div class="input-area">
2014-05-16 09:21:44 +00:00
<div class="nav-name"><strong><%= t(:language) %></strong></div>
2014-05-06 09:20:15 +00:00
<ul class="nav nav-pills language-nav">
2014-05-16 09:21:44 +00:00
<% @site_in_use_locales.each_with_index do |locale, i| %>
2014-05-06 09:20:15 +00:00
<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 -->
2014-05-16 09:21:44 +00:00
<% @site_in_use_locales.each_with_index do |locale, i| %>
2016-08-24 13:28:22 +00:00
<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>
2014-05-06 09:20:15 +00:00
<div class="tab-pane fade in <%= (i == 0 ? 'active' : '') %> <%= locale %>">
<div class="control-group input-content">
<%= f.fields_for :content_translations do |con| %>
2014-05-16 09:21:44 +00:00
<%= label_tag(locale, t(:content), :class=>"control-label muted") %>
2014-05-06 09:20:15 +00:00
<div class="controls">
<div class="textarea">
<%= con.text_area locale, :class => "ckeditor input-block-level", :value => (@page_context.content_translations[locale] rescue nil)%>
2014-05-06 09:20:15 +00:00
</div>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
</div>
2016-08-24 13:28:22 +00:00
<div class="form-actions">
<%= f.hidden_field :page_id, :value=>@page.id.to_s %>
<input type="hidden" name="referer_url" value="<%= request.referer %>">
<%= f.submit t("page_content.save"), :class=> "btn btn-primary bt-form-save" %>
</div>
2014-05-06 09:20:15 +00:00
</fieldset>
2016-08-24 13:28:22 +00:00
<% 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>