lib/generators/templates/app/helpers/beautiful_helper.rb in beautiful_scaffold-1.0.0.pre vs lib/generators/templates/app/helpers/beautiful_helper.rb in beautiful_scaffold-1.0.1
- old
+ new
@@ -1,10 +1,20 @@
# encoding : utf-8
+<%
+if !engine_name.blank?
+b_module = "module #{engine_camel}"
+e_module = "end"
+else
+b_module = ""
+e_module = ""
+end
+%>
+<%= b_module %>
module BeautifulHelper
def visible_column(model_name, field_name, display_default = 'table-cell', other_css = "")
- return ('style="display:' + ((session[:fields][model_name].to_a.include?(field_name)) ? display_default : 'none') + ';' + other_css + '"').html_safe
+ return ('style="display:' + ((session['fields'][model_name].to_a.include?(field_name)) ? display_default : 'none') + ';' + other_css + '"').html_safe
end
def dropdown_submenu(link_caption, &block)
the_link = link_to((link_caption + ' <b class="caret"></b>').html_safe, "#", :class => "dropdown-toggle", "data-toggle" => "dropdown")
contents = (block_given?) ? content_tag_string(:ul, capture(&block), :class => "dropdown-menu") : ''
@@ -52,17 +62,17 @@
eval(strpath) + "?" +
CGI.unescape({:sorting => {:attribute => attribute_name.downcase,:sorting => opposite_sortstr}}.to_query)
).html_safe
end
- def ransack_field(path_of_model, attribute_name, f, caption = nil)
+ def ransack_field(path_of_model, attribute_name, f, caption = nil, engine = nil)
model_path = path_of_model.split("/")
model_name = model_path.last
model_path.delete(model_path.first)
model_name_for_ransack = model_path.join("_")
- ar_model = model_name.camelize.constantize
+ ar_model = (engine.blank? ? model_name.camelize.constantize : "#{engine.camelize}::#{model_name.camelize}".constantize)
default_caption = caption
if default_caption.blank? then
default_caption = attribute_name.capitalize
if is_belongs_to_column?(default_caption) then
@@ -156,18 +166,20 @@
# Specify a default value (false) in rails migration
response += f.label name_field + "_eq_true", raw(f.radio_button((name_field + "_eq").to_sym, true)) + " " + h(t(:yes, :default => "Yes")), :class => "checkbox inline"
response += f.label name_field + "_eq_false", raw(f.radio_button((name_field + "_eq").to_sym, false)) + " " + h(t(:no, :default => "No")), :class => "checkbox inline"
response += f.label name_field + "_eq", raw(f.radio_button((name_field + "_eq").to_sym, nil)) + " " + h(t(:all, :default => "All")), :class => "checkbox inline"
- infostr = (begin session[:search][model_name.to_sym][(name_field + "_eq").to_sym] == "on" ? "" : "info" rescue "" end)
+ infostr = (begin session['search'][model_name][(name_field + "_eq").to_sym] == "on" ? "" : "info" rescue "" end)
when :string then
response += f.text_field((name_field + "_cont").to_sym, :class => "filter col-md-12 form-control")
infostr = info_input(model_name, (name_field + "_cont").to_sym)
when :integer, :float, :decimal then
if is_belongs_to_column?(name_field_bk) then
- btmodel = get_belongs_to_model(name_field_bk).camelize.constantize
+ bt_model_name = get_belongs_to_model(name_field_bk).camelize
+ bt_model_name = "#{engine.camelize}::#{bt_model_name}" if !engine.blank?
+ btmodel = bt_model_name.constantize
response += f.collection_select((name_field + "_eq").to_sym, btmodel.all, :id, :caption, { :include_blank => t(:all, :default => "All") }, { :class => "col-md-12 form-control" })
infostr = info_input(model_name, (name_field + "_eq").to_sym)
elsif name_field == "id" then
response += f.text_field((name_field + "_eq").to_sym, :class => "filter col-md-12 form-control")
@@ -197,17 +209,17 @@
return response.html_safe
end
def info_input(modname, attr)
- model_name = modname.to_sym
+ model_name = modname
rep = false
- if not session[:search].blank? and not session[:search][model_name].blank? then
+ if not session['search'].blank? and not session['search'][model_name].blank? then
if attr.kind_of?(Array) then
- rep = (attr.any? { |elt| (not session[:search][model_name][elt].blank?) })
+ rep = (attr.any? { |elt| (not session['search'][model_name][elt].blank?) })
else
- rep = (not session[:search][model_name][attr].blank?)
+ rep = (not session['search'][model_name][attr].blank?)
end
end
return (rep ? "info" : "")
end
@@ -262,10 +274,11 @@
end
def clean_params
params.delete :q
params.delete :fields
+ params.delete :scope
end
def i18n_translate_path(model, attr)
"app.models.#{model}.bs_attributes.#{attr}"
end
@@ -276,5 +289,6 @@
def i18n_translate_path_model_plural(model)
"app.models.#{model}.bs_caption_plural"
end
end
+<%= e_module %>
\ No newline at end of file