personal_plugin_generator/app/views/admin/personal_plugin_fields/_form.html.erb

255 lines
11 KiB
Plaintext

<% # encoding: utf-8 %>
<% content_for :page_specific_css do %>
<%= stylesheet_link_tag "lib/main-forms" %>
<%= stylesheet_link_tag "lib/fileupload" %>
<%= stylesheet_link_tag "lib/main-list" %>
<%= stylesheet_link_tag "lib/main-form-col2" %>
<style type="text/css">
.ui-helper-hidden-accessible{
display: none;
}
</style>
<% end %>
<% content_for :page_specific_javascript do %>
<%= javascript_include_tag "lib/bootstrap-datetimepicker" %>
<%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %>
<%= javascript_include_tag "lib/bootstrap-fileupload" %>
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<!-- Input Area -->
<div class="input-area">
<!-- Language Tabs -->
<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 class="<%= 'active' if i == 0 %>">
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
</li>
<% end %>
<li class="pull-right">
<%= copy_to_all_language_button(".language-nav", ".language-area") %>
</li>
</ul>
<!-- Language -->
<div class="tab-content language-area">
<% @site_in_use_locales.each_with_index do |locale, i| %>
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
<!-- personal_plugin_field title-->
<div class="control-group input-title">
<label class="control-label muted"><%= t("personal_plugin_generator.personal_plugin_name") %></label>
<div class="controls">
<%= f.fields_for :title_translations do |f| %>
<%= f.text_field locale, class: "input-block-level", placeholder: t("personal_plugin_generator.personal_plugin_name"), value: (@personal_plugin_field.title_translations[locale] rescue nil) %>
<% end %>
</div>
</div>
</div>
<% end %>
</div>
<div class="nav-name"><strong><%= t(:module) %></strong></div>
<ul class="nav nav-pills module-nav">
<li></li>
<li class="active">
<a href="#basic" data-toggle="tab"><%= t(:basic) %></a>
</li>
<li>
<a href="#status" data-toggle="tab"><%= t(:status) %></a>
</li>
</ul>
<!-- Module -->
<div class="tab-content module-area">
<!-- Basic Module -->
<div class="tab-pane fade in active" id="basic">
<div class="control-group">
<label class="control-label muted"><%=thead_field("module_name")%></label>
<div class="controls">
<%= f.text_field :module_name, placeholder: thead_field("module_name") %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%=thead_field("primary_modal_name")%></label>
<div class="controls">
<%= f.text_field :primary_modal_name, placeholder: thead_field("primary_modal_name"), class: "primary_modal_name" %>
</div>
</div>
<div class="control-group">
<label class="control-label muted"><%=thead_field("related_modal_name")%></label>
<div class="controls">
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
<div>
<%= text_field_tag "#{f.object_name}[related_modal_name][]", related_modal_name,placeholder: thead_field("related_modal_name"), class: "related_modal_name" %>
<button type="button" class="remove_related_modal" index="<%=i%>"><%=t(:remove)%></button>
</div>
<% end %>
<button type="button" class="btn btn-primary" id="add_related_modal"><%= t(:add) %></button>
</div>
</div>
</div>
<!-- Status Module -->
<div class="tab-pane fade" id="status">
<div class="control-group">
<label class="control-label muted"><%= t(:status) %></label>
<div class="controls" data-toggle="buttons-checkbox">
<label class="checkbox inline btn <%= 'active' if @personal_plugin_field.is_hidden? %>">
<%= f.check_box :is_hidden %> <%= t(:hide) %>
</label>
</div>
</div>
</div>
</div>
<% field_types = ["text_field","text_editor","file","select","year","date","time","date_time"].map{|field| [thead_field(field),field]}
field_types1 = field_types.select{|a| a[1] != "file"}
%>
<div class="tab-content language-area">
<div id="primary_modal_plane">
<h4><%=thead_field("primary_modal_name")%> : <span class="primary_modal_name"><%= f.object.primary_modal_name%></span></h4>
<% if f.object.primary_modal_fields.present? %>
<%= render :partial => 'render_table',locals: {:f => f,:root_name => "primary_modal_fields",:field_values => f.object.primary_modal_fields,:field_types => field_types } %>
<% else %>
<%= render :partial => 'render_table',locals: {:f => f,:root_name => "primary_modal_fields",:field_values => [nil,nil],:field_types => field_types,:@include_blank => true} %>
<% end %>
<button type="button" onclick="add_primary_modal_field()" class="btn btn-primary"><%= thead_field('add_field') %></button>
</div>
<div id="related_modal_plane">
<% if f.object.related_modal_name.present? %>
<% f.object.related_modal_name.each_with_index do |related_modal_name,i| %>
<% field_values = f.object.related_modal_fields[i].to_a %>
<div index="<%= i %>">
<h4><%=thead_field("related_modal_name")%> : <span class="related_modal_name"><%= related_modal_name %></span></h4>
<%= render :partial => 'render_table',locals: {:f => f,:root_name => "related_modal_fields][#{i}",:field_values => field_values,:field_types => field_types1 } %>
</div>
<% end %>
<% end %>
</div>
</div>
</div>
<!-- Form Actions -->
<div class="form-actions">
<%= f.hidden_field :user_id, :value => params[:user_id] if !params[:user_id].blank? %>
<input type="hidden" name="referer_url" value="<%= request.referer %>">
<%= f.submit t('submit'), class: 'btn btn-primary' %>
<%= link_to t('cancel'), request.referer, :class=>"btn" %>
</div>
<script type="text/javascript">
$(document).on('click', '.delete_file', function(){
$(this).parents('.input-prepend').remove();
});
$(document).on('click', '.remove_existing_record', function(){
if(window.confirm("<%= I18n.t(:sure?)%>")){
$(this).children('.should_destroy').attr('value', 1);
$(this).parents('.start-line').hide();
}
});
var related_modal_name_html = '<%= text_field_tag "#{f.object_name}[related_modal_name][]", '',placeholder: thead_field("related_modal_name"), class: "related_modal_name" %>';
related_modal_name_html = $("<div></div>").append(related_modal_name_html);
related_modal_name_html.append("<button type=\"button\" class=\"remove_related_modal\"><%=t(:remove) %></button>")
$(".remove_btn").off("click").on("click",function(){
if(window.confirm("<%=thead_field('remove_text')%>")){
$(this).parent().parent().remove();
}
})
<%
related_modal_fields_html = "<div index=\"new_index\"><h4>#{thead_field("related_modal_name")} : <span class=\"related_modal_name\"></span></h4>"
related_modal_fields_html += render(:partial => 'render_table',locals: {:f => f,:root_name => "related_modal_fields][new_index",:field_values => [nil],:field_types => field_types1})
related_modal_fields_html += "</div>"
primary_modal_field_html = render(:partial => 'render_table',locals: {:f => f,:root_name => "primary_modal_fields",:field_values => [nil],:field_types => field_types})
%>
var related_modal_fields_html = "<%= escape_javascript(related_modal_fields_html.html_safe) %>";
var primary_modal_field_html = $("<%= escape_javascript(primary_modal_field_html.html_safe) %>").find("tbody tr")[0].outerHTML;
var add_related_modal_field_btn = '<button type="button" onclick="add_related_modal_field(this)" class="btn btn-primary"><%=thead_field('add_field')%></button>';
$("#add_related_modal").click(function(){
var clone_modal = related_modal_name_html.clone();
var new_index = $("#related_modal_plane > div").length;
clone_modal.find(".remove_related_modal").attr("index",new_index);
$(this).before(clone_modal);
$("#related_modal_plane").append(related_modal_fields_html.replaceAll("new_index",new_index).replaceAll("new_field_index",0));
$("#related_modal_plane >").eq(-1).append(add_related_modal_field_btn);
clone_modal.find(".remove_related_modal").click(function(){
remove_related_modal_func(this);
});
})
$("#related_modal_plane >").append(add_related_modal_field_btn);
$(".remove_related_modal").click(function(){
remove_related_modal_func(this);
});
function remove_related_modal_func(item){
if(window.confirm("<%=thead_field('remove_text')%>")){
var index = $(item).attr("index");
$(item).parent().remove();
console.log(index);
$("#related_modal_plane > div[index=\""+index+"\"]").remove();
$("#related_modal_plane > div").each(function(i,v){
$(v).attr("index",i);
})
$(".remove_related_modal").each(function(i,v){
$(v).attr("index",i);
})
}
}
function add_related_modal_field(item){
var current_index = $(item).parent().attr("index");
var related_modal = $(related_modal_fields_html.replaceAll("new_field_index",$(item).parent().find("tbody tr").length));
$(item).parent().find("tbody").append(related_modal.find("tbody tr")[0].outerHTML.replaceAll("new_index",current_index));
$(".remove_btn").off("click").on("click",function(){
if(window.confirm("<%=thead_field('remove_text')%>")){
$(this).parent().parent().remove();
}
})
}
function add_primary_modal_field(){
var primary_modal = $(primary_modal_field_html.replaceAll("new_field_index",$("#primary_modal_plane tbody tr").length));
$("#primary_modal_plane tbody").append(primary_modal);
$(".remove_btn").off("click").on("click",function(){
if(window.confirm("<%=thead_field('remove_text')%>")){
$(this).parent().parent().remove();
}
})
}
$("form").submit(function(){
if($("#primary_modal_plane .slug_title:checked").length == 0){
alert("<%=thead_field('please_choose_one_slug_title')%>");
}else if($("#primary_modal_plane .slug_title:checked").length > 1){
alert("<%=thead_field('slug_title_can_only_choose_one')%>");
}else{
return true;
}
$('tr >:last-child').css( 'border', '2px solid red');
return false;
})
$('.slug_title').click(function(){
if($('.slug_title:checked').length == 1){
$('tr >:last-child').css( 'border','');
}
})
</script>
<style type="text/css">
.module-area .control-group {
width: 100%;
}
span.fade{
display: none;
}
span.fade.in{
display: block;
}
.remove_btn{
cursor: pointer;
color: red;
font-weight: bold;
}
</style>