fix bug about recovery font and delete font and add edit all font

This commit is contained in:
BOHUNG 2019-09-29 12:18:19 +08:00
parent 7eb02f0d1c
commit 44188cb614
5 changed files with 103 additions and 54 deletions

View File

@ -76,22 +76,50 @@ class Admin::PatchfilesController < OrbitAdminController
def newfont def newfont
if params["patchfilefield"]["initial_btn"] == "true" if params["patchfilefield"]["initial_btn"] == "true"
#render :html => @field.id and return #render :html => @field.id and return
@field_to_copy = Patchfilefield.where("title"=>@app_title + "_back").first @field_to_copy = Patchfilefield.where("title"=>(@app_title + "_back")).take_while{true}.last
@id = @field.id @field_to_copy.attributes.each do |copy_field,value|
@field = @field_to_copy if copy_field != "_id" || copy_field != "title"
@field.id = @id @field[copy_field] = value
@field.title = @app_title end
end
@field.update @field.update
@field = Patchfilefield.where("title"=>@app_title).first
@field.update
@field = Patchfilefield.where("title"=>@app_title).first
@font_arr = []
@field.font_array.each do |font,istrue|
@font_arr.push font
end
@font_arr.each do |font,istrue|
if (@field_to_copy.font_array.keys.include? font) == false
@field.font_array.delete(font)
@field.delete_font = font
@field.update
@field = Patchfilefield.where("title"=>@app_title).first
end
end
redirect_to admin_patchfiles_editckeditor_path and return
elsif params["patchfilefield"]["delete_btn"] == "true"
params["patchfilefield"]["font_array"] = {} if params["patchfilefield"]["font_array"].nil? == true
params["patchfilefield"]["font_array"].each do |font,istrue|
if istrue =="1"
@field.font_array.delete(font)
@field.delete_font = font
@field.update
@field = Patchfilefield.where("title"=>@app_title).first
end
end
redirect_to admin_patchfiles_editckeditor_path and return redirect_to admin_patchfiles_editckeditor_path and return
else else
params["patchfilefield"]["new_add_font"] = params["patchfilefield"]["new_add_font"].gsub('\"','').gsub("\'",'').gsub(";",'') 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) @field.new_add_font = params["patchfilefield"]["new_add_font"] rescue (redirect_to admin_patchfiles_showckeditor_path and return)
@key_arr = @field.font_array.keys @key_arr = @field.font_array.keys
params["patchfilefield"]["font_array"].each_with_index do |(font,istrue),index| params["patchfilefield"]["font_array"] = {} if params["patchfilefield"]["font_array"].nil? == true
params["patchfilefield"]["font_array"].each do |font,istrue|
if istrue =="0" if istrue =="0"
@field.font_array[@key_arr[index]][font] = false @field.font_array[font] = false
elsif istrue =="1" elsif istrue =="1"
@field.font_array[@key_arr[index]][font] = true @field.font_array[font] = true
end end
end end
@field.update @field.update
@ -138,7 +166,7 @@ class Admin::PatchfilesController < OrbitAdminController
end end
end end
def create_first_field def create_first_field
if Patchfilefield.where("title"=>@app_title + "_back").take_while{true}.count == 0 if Patchfilefield.where("title"=>(@app_title + "_back")).take_while{true}.count == 0
@field = Patchfilefield.new() @field = Patchfilefield.new()
@field.title = @app_title +"_back" @field.title = @app_title +"_back"
@field.save @field.save

View File

@ -168,22 +168,17 @@ class Fontfile
def change_font_name def change_font_name
if self.old_title !="" && self.old_title != self.title if self.old_title !="" && self.old_title != self.title
@field = Patchfilefield.where("title"=>"patchfile").first @field = Patchfilefield.where("title"=>"patchfile").first
@index
@font_old_name @font_old_name
@field.font_array.each do |index,font_hash| @field.font_array.each do |font,istrue|
font_hash.each do |font,istrue|
if font == self.old_title if font == self.old_title
@index = index
@font_old_name = font @font_old_name = font
break break
end end
end end
break if @index != nil if @font_old_name.nil? == false
end @istrue = @field.font_array[@font_old_name]
if @font_old_name.nil? == false && @index.nil? == false @field.font_array[self.title] = @istrue
@istrue = @field.font_array[@index.to_s][@font_old_name] @field.font_array.delete(@font_old_name)
@field.font_array[@index.to_s][self.title] = @istrue
@field.font_array[@index.to_s].delete(@font_old_name)
@field.delete_font = @font_old_name @field.delete_font = @font_old_name
@field.update @field.update
@field = Patchfilefield.where("title"=>"patchfile").first @field = Patchfilefield.where("title"=>"patchfile").first

View File

@ -24,11 +24,9 @@ class Patchfilefield
after_save :set_config after_save :set_config
#before_create :set_expire #before_create :set_expire
def delete_empty_font def delete_empty_font
self.font_array.each do |index,font_hash| self.font_array.each do |font,istrue|
font_hash.each do |font,istrue|
if font.strip == "" if font.strip == ""
self.font_array.delete(index.to_s) self.font_array.delete(font)
end
end end
end end
end end
@ -70,30 +68,28 @@ class Patchfilefield
@font_array.each do |font| @font_array.each do |font|
@i = 0 @i = 0
if font != self.delete_font if font != self.delete_font
self.font_array.values.each do |each_font| self.font_array.keys.each do |each_font|
if each_font.keys.first == font if each_font == font
@i = 1 @i = 1
end end
break if @i == 1 break if @i == 1
end end
if @i == 0 if @i == 0
@count = (self.font_array.keys[-1].to_i + 1).to_s self.font_array = self.font_array.merge({font => true})
self.font_array = self.font_array.merge({@count =>{font => true}})
end end
end end
end end
end end
if self.new_add_font.strip !="" if self.new_add_font.strip !=""
@i = 0 @i = 0
self.font_array.values.each do |each_font| self.font_array.keys.each do |each_font|
if each_font.keys.first == self.new_add_font if each_font == self.new_add_font
@i = 1 @i = 1
end end
break if @i == 1 break if @i == 1
end end
if @i == 0 if @i == 0
@count = (self.font_array.keys[-1].to_i + 1).to_s self.font_array = self.font_array.merge({self.new_add_font.strip => true})
self.font_array = self.font_array.merge({@count =>{self.new_add_font.strip => true}})
end end
self.new_add_font = "" self.new_add_font = ""
end end
@ -104,24 +100,20 @@ class Patchfilefield
# end # end
def set_un_used_font def set_un_used_font
@un_use_font = [] @un_use_font = []
self.font_array.each do |index,font_hash| self.font_array.each do |font,istrue|
font_hash.each do |font,istrue|
if istrue == false if istrue == false
@un_use_font.push font.strip @un_use_font.push font.strip
end end
end end
end
self.un_used_font = @un_use_font self.un_used_font = @un_use_font
end end
def set_used_font def set_used_font
@use_font = [] @use_font = []
self.font_array.each do |index,font_hash| self.font_array.each do |font,istrue|
font_hash.each do |font,istrue|
if istrue == true if istrue == true
@use_font.push font.strip @use_font.push font.strip
end end
end end
end
@use_font.delete("") @use_font.delete("")
self.used_font = @use_font self.used_font = @use_font
end end

View File

@ -1,16 +1,19 @@
<h3 title="CKEDITOR現有字形">CKEDITOR現有字形</h3> <h3 title="CKEDITOR現有字形">CKEDITOR現有字形</h3>
<button id="clickall"><%= (I18n.locale.to_s == "zh_tw") ? "全選" : "select all" %></button>
<button id="unclickall"><%= (I18n.locale.to_s == "zh_tw") ? "取消全選" : "unselect all" %></button>
<div style="clear:both;"></div>
<%=form_for @field,:url=>{:controller=>"patchfiles" ,:action=>"newfont"} do |f|%> <%=form_for @field,:url=>{:controller=>"patchfiles" ,:action=>"newfont"} do |f|%>
<div style="padding-left:1em"> <div style="padding-left:1em" class="allcheckbox">
<%= f.fields_for :font_array do |fontfield|%> <%= f.fields_for :font_array do |fontfield|%>
<% @arr = @field.font_array.keys %> <% @arr = @field.font_array.keys %>
<% for @i in @arr %> <% for @i in @arr %>
<div style="float:left;"> <div style="float:left;">
<% if @field.font_array[@i.to_s].values.first == true%> <% if @field.font_array[@i.to_s] == true%>
<%=fontfield.check_box @field.font_array[@i.to_s].keys.first,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %> <%=fontfield.check_box @i.to_s,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<% else %> <% else %>
<%=fontfield.check_box @field.font_array[@i.to_s].keys.first,{:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %> <%=fontfield.check_box @i.to_s,{:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
<% end %> <% end %>
<%=fontfield.label @field.font_array[@i.to_s].keys.first,{:for=>"checkbox"+@i.to_s,:style=>"float:right;"}%> <%=fontfield.label @i.to_s ,{:for=>"checkbox"+@i.to_s,:style=>"float:right;"}%>
</div> </div>
<%end%> <%end%>
<%end%> <%end%>
@ -20,8 +23,20 @@
<%=f.submit "#{t(:updatefont)}",{:id=>"submitbtn"}%> <%=f.submit "#{t(:updatefont)}",{:id=>"submitbtn"}%>
<button id="initialbtn"><%= (I18n.locale.to_s == "zh_tw") ? "點擊來恢復初始狀態" : "click to recovery initial state" %></button> <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"} %> <%=f.text_field :initial_btn, {:id=>"hidden-initial",:type => "hidden",:value=>"false"} %>
<button id="deletebtn"><%= (I18n.locale.to_s == "zh_tw") ? "點擊來刪除所選字形" : "click to delete selected font" %></button>
<%=f.text_field :delete_btn, {:id=>"hidden-delete",:type => "hidden",:value=>"false"} %>
<%end%> <%end%>
<li id ="ckeditorFont" class="show_li">
<a title="CKEDITOR現有字形">CKEDITOR現有字形</a>
<% @ckicktosee_str = (I18n.locale.to_s == "en") ? "click me to see all font which CKEDITOR have now" : "點擊我來查看編輯器所有目前擁有的字形" %>
<a id="clicktosee" title="<%= @ckicktosee_str %>" class="Toggleclass"><%= @ckicktosee_str %></a>
<ul>
<% @field.font_array.each do |font,istrue|%>
<% @inform = (I18n.locale.to_s == "en") ? "click me to edit" : "點擊我來編輯" %>
<li><a title="<%= @inform+' '+font %>" href="<%= admin_patchfiles_path %>/editfontfile?font=<%= font %>"><%= font %></a></li>
<%end%>
</ul>
</li>
<style type="text/css"> <style type="text/css">
.show_li,.show_li *{ .show_li,.show_li *{
list-style:none; list-style:none;
@ -40,5 +55,23 @@
$("#hidden-initial").val("true"); $("#hidden-initial").val("true");
$("#submitbtn").click(); $("#submitbtn").click();
}); });
$("#deletebtn").off("click").on("click",function(){
$("#hidden-delete").val("true");
$("#submitbtn").click();
});
$("#clickall").off("click").on("click",function(){
for(var i =0;i<$(".allcheckbox input").length ; i++){
if($(".allcheckbox input").eq(i).is(":checked") == false)
$(".allcheckbox input").eq(i).click();
}
});
$("#unclickall").off("click").on("click",function(){
for(var i =0;i<$(".allcheckbox input").length ; i++){
if($(".allcheckbox input").eq(i).is(":checked") == true)
$(".allcheckbox input").eq(i).click();
}
});
$('.Toggleclass').off("click").on("click",function(){
$(this).parent().find(">ul").slideToggle();
});
</script> </script>

View File

@ -4,7 +4,8 @@
<a id="clicktosee" title="<%= @ckicktosee_str %>" class="Toggleclass"><%= @ckicktosee_str %></a> <a id="clicktosee" title="<%= @ckicktosee_str %>" class="Toggleclass"><%= @ckicktosee_str %></a>
<ul> <ul>
<% @font_array.each do |font|%> <% @font_array.each do |font|%>
<li><a title="<%= font %>" href="<%= admin_patchfiles_path %>/editfontfile?font=<%= font %>"><%= font %></a></li> <% @inform = (I18n.locale.to_s == "en") ? "click me to edit" : "點擊我來編輯" %>
<li><a title="<%= @inform+' '+font %>" href="<%= admin_patchfiles_path %>/editfontfile?font=<%= font %>"><%= font %></a></li>
<%end%> <%end%>
</ul> </ul>
</li> </li>