fix some bug and add the feature that recovery ckeditor font list

This commit is contained in:
BOHUNG 2019-09-28 23:38:15 +08:00
parent 8b44d2cc6f
commit 7eb02f0d1c
3 changed files with 67 additions and 38 deletions

View File

@ -15,10 +15,6 @@ class Admin::PatchfilesController < OrbitAdminController
@categories = @module_app.categories.enabled
@filter_fields = filter_fields(@categories, @tags)
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
#@file_to_show= Filefield.new
#@file_to_show.save
#@file_to_show = Filefield.find().first
#@file_to_show = @file.file_show
if request.xhr?
render :partial => "index"
end
@ -78,17 +74,29 @@ class Admin::PatchfilesController < OrbitAdminController
redirect_to admin_patchfiles_showckeditor_path
end
def newfont
params["patchfilefield"]["new_add_font"] = params["patchfilefield"]["new_add_font"].gsub('\"','').gsub("\'",'').gsub(";",'')
@field.new_add_font = params["patchfilefield"]["new_add_font"] rescue (redirect_to admin_patchfiles_showckeditor_path and return)
params["patchfilefield"]["font_array"].each_with_index do |(font,istrue),index|
if istrue =="0"
@field.font_array[index.to_s][font] = false
elsif istrue =="1"
@field.font_array[index.to_s][font] = true
if params["patchfilefield"]["initial_btn"] == "true"
#render :html => @field.id and return
@field_to_copy = Patchfilefield.where("title"=>@app_title + "_back").first
@id = @field.id
@field = @field_to_copy
@field.id = @id
@field.title = @app_title
@field.update
redirect_to admin_patchfiles_editckeditor_path and return
else
params["patchfilefield"]["new_add_font"] = params["patchfilefield"]["new_add_font"].gsub('\"','').gsub("\'",'').gsub(";",'')
@field.new_add_font = params["patchfilefield"]["new_add_font"] rescue (redirect_to admin_patchfiles_showckeditor_path and return)
@key_arr = @field.font_array.keys
params["patchfilefield"]["font_array"].each_with_index do |(font,istrue),index|
if istrue =="0"
@field.font_array[@key_arr[index]][font] = false
elsif istrue =="1"
@field.font_array[@key_arr[index]][font] = true
end
end
@field.update
redirect_to admin_patchfiles_showckeditor_path and return
end
@field.update
redirect_to admin_patchfiles_showckeditor_path
end
def getfont
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
@ -130,6 +138,11 @@ class Admin::PatchfilesController < OrbitAdminController
end
end
def create_first_field
if Patchfilefield.where("title"=>@app_title + "_back").take_while{true}.count == 0
@field = Patchfilefield.new()
@field.title=@app_title +"_back"
@field.save
end
@field
if Patchfilefield.where("title"=>@app_title).take_while{true}.count == 0
@field = Patchfilefield.new()

View File

@ -17,12 +17,21 @@ class Patchfilefield
# before_destroy :destroy_email
scope :can_display, ->{where(:is_hidden=>false,:is_preview => false).any_of({:postdate.lt=>Time.now, :deadline.gt=>Time.now},{:postdate.lt=>Time.now, :deadline=>nil}).order_by([:is_top, :desc],[:postdate, :desc])}
scope :is_approved, ->{where(:approved => true)}
before_create :get_font_to_store,:set_un_used_font , :set_used_font
before_update :get_font_to_store,:set_un_used_font , :set_used_font
before_save :get_font_to_store,:set_un_used_font , :set_used_font
before_create :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
before_update :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
before_save :delete_empty_font ,:get_font_to_store,:set_un_used_font , :set_used_font
after_update :set_config
after_save :set_config
#before_create :set_expire
def delete_empty_font
self.font_array.each do |index,font_hash|
font_hash.each do |font,istrue|
if font.strip == ""
self.font_array.delete(index.to_s)
end
end
end
end
def get_font_to_store
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
@filedata = File.read(@ckeditor_path+"/config.js.erb")
@ -68,7 +77,7 @@ class Patchfilefield
break if @i == 1
end
if @i == 0
@count = self.font_array.count
@count = (self.font_array.keys[-1].to_i + 1).to_s
self.font_array = self.font_array.merge({@count =>{font => true}})
end
end
@ -83,7 +92,7 @@ class Patchfilefield
break if @i == 1
end
if @i == 0
@count = self.font_array.count
@count = (self.font_array.keys[-1].to_i + 1).to_s
self.font_array = self.font_array.merge({@count =>{self.new_add_font.strip => true}})
end
self.new_add_font = ""

View File

@ -1,26 +1,26 @@
<h3 title="CKEDITOR現有字形">CKEDITOR現有字形</h3>
<%=form_for @field,:url=>{:controller=>"patchfiles" ,:action=>"newfont"} do |f|%>
<% @i = 0 %>
<div style="padding-left:1em">
<%= f.fields_for :font_array do |fontfield|%>
<% @count = @field.font_array.count %>
<% for @i in 0...@count %>
<div style="float:left;">
<% if @field.font_array[@i.to_s].values.first == true%>
<%=fontfield.check_box @field.font_array[@i.to_s].keys.first,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<% else %>
<%=fontfield.check_box @field.font_array[@i.to_s].keys.first,{:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<% end %>
<%=fontfield.label @field.font_array[@i.to_s].keys.first,{:for=>"checkbox"+@i.to_s,:style=>"float:right;"}%>
</div>
<div style="padding-left:1em">
<%= f.fields_for :font_array do |fontfield|%>
<% @arr = @field.font_array.keys %>
<% for @i in @arr %>
<div style="float:left;">
<% if @field.font_array[@i.to_s].values.first == true%>
<%=fontfield.check_box @field.font_array[@i.to_s].keys.first,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<% else %>
<%=fontfield.check_box @field.font_array[@i.to_s].keys.first,{:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<% end %>
<%=fontfield.label @field.font_array[@i.to_s].keys.first,{:for=>"checkbox"+@i.to_s,:style=>"float:right;"}%>
</div>
<%end%>
<%end%>
<%end%>
</div>
<div style="clear:both;"></div>
<div style="padding-left:1em"><label for="newfont" style="float:left;"><%=t(:newfont)%>:</label><%=f.text_field :new_add_font,{:id=>"newfont",:placeholder=>t(:newfont)}%></div>
<%=f.submit "#{t(:updatefont)}"%>
</div>
<div style="clear:both;"></div>
<div style="padding-left:1em"><label for="newfont" style="float:left;"><%=t(:newfont)%>:</label><%=f.text_field :new_add_font,{:id=>"newfont",:placeholder=>t(:newfont)}%></div>
<%=f.submit "#{t(:updatefont)}",{:id=>"submitbtn"}%>
<button id="initialbtn"><%= (I18n.locale.to_s == "zh_tw") ? "點擊來恢復初始狀態" : "click to recovery initial state" %></button>
<%=f.text_field :initial_btn, {:id=>"hidden-initial",:type => "hidden",:value=>"false"} %>
<%end%>
<%@field.font_array%>
<style type="text/css">
.show_li,.show_li *{
@ -34,4 +34,11 @@
color:blue;
cursor:pointer;
}
</style>
</style>
<script>
$("#initialbtn").off("click").on("click",function(){
$("#hidden-initial").val("true");
$("#submitbtn").click();
});
</script>