fix bug about recovery font and delete font and add edit all font
This commit is contained in:
parent
7eb02f0d1c
commit
44188cb614
|
@ -76,22 +76,50 @@ class Admin::PatchfilesController < OrbitAdminController
|
|||
def newfont
|
||||
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_to_copy = Patchfilefield.where("title"=>(@app_title + "_back")).take_while{true}.last
|
||||
@field_to_copy.attributes.each do |copy_field,value|
|
||||
if copy_field != "_id" || copy_field != "title"
|
||||
@field[copy_field] = value
|
||||
end
|
||||
end
|
||||
@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
|
||||
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|
|
||||
params["patchfilefield"]["font_array"] = {} if params["patchfilefield"]["font_array"].nil? == true
|
||||
params["patchfilefield"]["font_array"].each do |font,istrue|
|
||||
if istrue =="0"
|
||||
@field.font_array[@key_arr[index]][font] = false
|
||||
@field.font_array[font] = false
|
||||
elsif istrue =="1"
|
||||
@field.font_array[@key_arr[index]][font] = true
|
||||
@field.font_array[font] = true
|
||||
end
|
||||
end
|
||||
@field.update
|
||||
|
@ -138,9 +166,9 @@ class Admin::PatchfilesController < OrbitAdminController
|
|||
end
|
||||
end
|
||||
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.title=@app_title +"_back"
|
||||
@field.title = @app_title +"_back"
|
||||
@field.save
|
||||
end
|
||||
@field
|
||||
|
|
|
@ -168,22 +168,17 @@ class Fontfile
|
|||
def change_font_name
|
||||
if self.old_title !="" && self.old_title != self.title
|
||||
@field = Patchfilefield.where("title"=>"patchfile").first
|
||||
@index
|
||||
@font_old_name
|
||||
@field.font_array.each do |index,font_hash|
|
||||
font_hash.each do |font,istrue|
|
||||
@field.font_array.each do |font,istrue|
|
||||
if font == self.old_title
|
||||
@index = index
|
||||
@font_old_name = font
|
||||
break
|
||||
end
|
||||
end
|
||||
break if @index != nil
|
||||
end
|
||||
if @font_old_name.nil? == false && @index.nil? == false
|
||||
@istrue = @field.font_array[@index.to_s][@font_old_name]
|
||||
@field.font_array[@index.to_s][self.title] = @istrue
|
||||
@field.font_array[@index.to_s].delete(@font_old_name)
|
||||
if @font_old_name.nil? == false
|
||||
@istrue = @field.font_array[@font_old_name]
|
||||
@field.font_array[self.title] = @istrue
|
||||
@field.font_array.delete(@font_old_name)
|
||||
@field.delete_font = @font_old_name
|
||||
@field.update
|
||||
@field = Patchfilefield.where("title"=>"patchfile").first
|
||||
|
|
|
@ -24,11 +24,9 @@ class Patchfilefield
|
|||
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|
|
||||
self.font_array.each do |font,istrue|
|
||||
if font.strip == ""
|
||||
self.font_array.delete(index.to_s)
|
||||
end
|
||||
self.font_array.delete(font)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -70,30 +68,28 @@ class Patchfilefield
|
|||
@font_array.each do |font|
|
||||
@i = 0
|
||||
if font != self.delete_font
|
||||
self.font_array.values.each do |each_font|
|
||||
if each_font.keys.first == font
|
||||
self.font_array.keys.each do |each_font|
|
||||
if each_font == font
|
||||
@i = 1
|
||||
end
|
||||
break if @i == 1
|
||||
end
|
||||
if @i == 0
|
||||
@count = (self.font_array.keys[-1].to_i + 1).to_s
|
||||
self.font_array = self.font_array.merge({@count =>{font => true}})
|
||||
self.font_array = self.font_array.merge({font => true})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if self.new_add_font.strip !=""
|
||||
@i = 0
|
||||
self.font_array.values.each do |each_font|
|
||||
if each_font.keys.first == self.new_add_font
|
||||
self.font_array.keys.each do |each_font|
|
||||
if each_font == self.new_add_font
|
||||
@i = 1
|
||||
end
|
||||
break if @i == 1
|
||||
end
|
||||
if @i == 0
|
||||
@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}})
|
||||
self.font_array = self.font_array.merge({self.new_add_font.strip => true})
|
||||
end
|
||||
self.new_add_font = ""
|
||||
end
|
||||
|
@ -104,24 +100,20 @@ class Patchfilefield
|
|||
# end
|
||||
def set_un_used_font
|
||||
@un_use_font = []
|
||||
self.font_array.each do |index,font_hash|
|
||||
font_hash.each do |font,istrue|
|
||||
self.font_array.each do |font,istrue|
|
||||
if istrue == false
|
||||
@un_use_font.push font.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
self.un_used_font = @un_use_font
|
||||
end
|
||||
def set_used_font
|
||||
@use_font = []
|
||||
self.font_array.each do |index,font_hash|
|
||||
font_hash.each do |font,istrue|
|
||||
self.font_array.each do |font,istrue|
|
||||
if istrue == true
|
||||
@use_font.push font.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
@use_font.delete("")
|
||||
self.used_font = @use_font
|
||||
end
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
<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|%>
|
||||
<div style="padding-left:1em">
|
||||
<div style="padding-left:1em" class="allcheckbox">
|
||||
<%= 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;"} %>
|
||||
<% if @field.font_array[@i.to_s] == true%>
|
||||
<%=fontfield.check_box @i.to_s,{: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;"} %>
|
||||
<%=fontfield.check_box @i.to_s,{: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;"}%>
|
||||
<%=fontfield.label @i.to_s ,{:for=>"checkbox"+@i.to_s,:style=>"float:right;"}%>
|
||||
</div>
|
||||
<%end%>
|
||||
<%end%>
|
||||
|
@ -20,8 +23,20 @@
|
|||
<%=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"} %>
|
||||
<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%>
|
||||
|
||||
<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">
|
||||
.show_li,.show_li *{
|
||||
list-style:none;
|
||||
|
@ -40,5 +55,23 @@
|
|||
$("#hidden-initial").val("true");
|
||||
$("#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>
|
|
@ -4,7 +4,8 @@
|
|||
<a id="clicktosee" title="<%= @ckicktosee_str %>" class="Toggleclass"><%= @ckicktosee_str %></a>
|
||||
<ul>
|
||||
<% @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%>
|
||||
</ul>
|
||||
</li>
|
||||
|
|
Loading…
Reference in New Issue