fix some bug and add the feature that recovery ckeditor font list
This commit is contained in:
parent
8b44d2cc6f
commit
7eb02f0d1c
|
@ -15,10 +15,6 @@ class Admin::PatchfilesController < OrbitAdminController
|
||||||
@categories = @module_app.categories.enabled
|
@categories = @module_app.categories.enabled
|
||||||
@filter_fields = filter_fields(@categories, @tags)
|
@filter_fields = filter_fields(@categories, @tags)
|
||||||
@table_fields = [:status, :category, :title, :start_date, :end_date, :last_modified]
|
@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?
|
if request.xhr?
|
||||||
render :partial => "index"
|
render :partial => "index"
|
||||||
end
|
end
|
||||||
|
@ -78,17 +74,29 @@ class Admin::PatchfilesController < OrbitAdminController
|
||||||
redirect_to admin_patchfiles_showckeditor_path
|
redirect_to admin_patchfiles_showckeditor_path
|
||||||
end
|
end
|
||||||
def newfont
|
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.update
|
||||||
|
redirect_to admin_patchfiles_editckeditor_path and return
|
||||||
|
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
|
||||||
params["patchfilefield"]["font_array"].each_with_index do |(font,istrue),index|
|
params["patchfilefield"]["font_array"].each_with_index do |(font,istrue),index|
|
||||||
if istrue =="0"
|
if istrue =="0"
|
||||||
@field.font_array[index.to_s][font] = false
|
@field.font_array[@key_arr[index]][font] = false
|
||||||
elsif istrue =="1"
|
elsif istrue =="1"
|
||||||
@field.font_array[index.to_s][font] = true
|
@field.font_array[@key_arr[index]][font] = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@field.update
|
@field.update
|
||||||
redirect_to admin_patchfiles_showckeditor_path
|
redirect_to admin_patchfiles_showckeditor_path and return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
def getfont
|
def getfont
|
||||||
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
|
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
|
||||||
|
@ -130,6 +138,11 @@ 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
|
||||||
|
@field = Patchfilefield.new()
|
||||||
|
@field.title=@app_title +"_back"
|
||||||
|
@field.save
|
||||||
|
end
|
||||||
@field
|
@field
|
||||||
if Patchfilefield.where("title"=>@app_title).take_while{true}.count == 0
|
if Patchfilefield.where("title"=>@app_title).take_while{true}.count == 0
|
||||||
@field = Patchfilefield.new()
|
@field = Patchfilefield.new()
|
||||||
|
|
|
@ -17,12 +17,21 @@ class Patchfilefield
|
||||||
# before_destroy :destroy_email
|
# 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 :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)}
|
scope :is_approved, ->{where(:approved => true)}
|
||||||
before_create :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 :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 :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_update :set_config
|
||||||
after_save :set_config
|
after_save :set_config
|
||||||
#before_create :set_expire
|
#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
|
def get_font_to_store
|
||||||
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
|
@ckeditor_path = ENV['PWD'] + '/app/assets/javascripts/ckeditor'
|
||||||
@filedata = File.read(@ckeditor_path+"/config.js.erb")
|
@filedata = File.read(@ckeditor_path+"/config.js.erb")
|
||||||
|
@ -68,7 +77,7 @@ class Patchfilefield
|
||||||
break if @i == 1
|
break if @i == 1
|
||||||
end
|
end
|
||||||
if @i == 0
|
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}})
|
self.font_array = self.font_array.merge({@count =>{font => true}})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,7 +92,7 @@ class Patchfilefield
|
||||||
break if @i == 1
|
break if @i == 1
|
||||||
end
|
end
|
||||||
if @i == 0
|
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}})
|
self.font_array = self.font_array.merge({@count =>{self.new_add_font.strip => true}})
|
||||||
end
|
end
|
||||||
self.new_add_font = ""
|
self.new_add_font = ""
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
<h3 title="CKEDITOR現有字形">CKEDITOR現有字形</h3>
|
<h3 title="CKEDITOR現有字形">CKEDITOR現有字形</h3>
|
||||||
<%=form_for @field,:url=>{:controller=>"patchfiles" ,:action=>"newfont"} do |f|%>
|
<%=form_for @field,:url=>{:controller=>"patchfiles" ,:action=>"newfont"} do |f|%>
|
||||||
<% @i = 0 %>
|
|
||||||
<div style="padding-left:1em">
|
<div style="padding-left:1em">
|
||||||
<%= f.fields_for :font_array do |fontfield|%>
|
<%= f.fields_for :font_array do |fontfield|%>
|
||||||
<% @count = @field.font_array.count %>
|
<% @arr = @field.font_array.keys %>
|
||||||
<% for @i in 0...@count %>
|
<% 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].values.first == 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 @field.font_array[@i.to_s].keys.first,{:checked=>true,:id=>"checkbox"+@i.to_s,:style=>"float:left;"} %>
|
||||||
|
@ -18,9 +17,10 @@
|
||||||
</div>
|
</div>
|
||||||
<div style="clear:both;"></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>
|
<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)}"%>
|
<%=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%>
|
<%end%>
|
||||||
<%@field.font_array%>
|
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
.show_li,.show_li *{
|
.show_li,.show_li *{
|
||||||
|
@ -35,3 +35,10 @@
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script>
|
||||||
|
$("#initialbtn").off("click").on("click",function(){
|
||||||
|
$("#hidden-initial").val("true");
|
||||||
|
$("#submitbtn").click();
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
Loading…
Reference in New Issue