lib/generators/templates/app/helpers/beautiful_helper.rb in beautiful_scaffold-0.1.4 vs lib/generators/templates/app/helpers/beautiful_helper.rb in beautiful_scaffold-0.1.5
- old
+ new
@@ -71,51 +71,69 @@
type_of_column = ar_model.columns_hash[attribute_name].type unless ar_model.columns_hash[attribute_name].nil?
type_of_column ||= :other
case type_of_column
when :date, :datetime then
- # DatePicker
+ dt = (type_of_column == :datetime)
+ interval = (dt ? (1..5) : (1..3))
+
+ # Greater than
response += '<div class="input-prepend input-append input-' + type_of_column.to_s + '">'
response += '<span class="add-on"><i class="icon-chevron-right"></i></span>'
- response += f.text_field((name_field + "_gteq").to_sym, :class => "span8 dpicker")
+ response += f.text_field(
+ (name_field + "_dp_gt").to_sym,
+ :value => (begin params[:q][(name_field + "_dp_gt").to_sym] rescue '' end),
+ :class => "span8 dpicker",
+ "data-id" => ("q_" + name_field + "_gteq"))
response += '<span class="add-on"><i class="icon-calendar"></i></span>'
response += '</div>'
- response += f.hidden_field(name_field + '_gteq(3i)', :id => ('q_' + name_field + '_gteq_3i')) # Day
- response += f.hidden_field(name_field + '_gteq(2i)', :id => ('q_' + name_field + '_gteq_2i')) # Mois
- response += f.hidden_field(name_field + '_gteq(1i)', :id => ('q_' + name_field + '_gteq_1i')) # Year
-
- if type_of_column == :datetime then
+ if dt then
response += '<div class="input-prepend input-append input-' + type_of_column.to_s + '">'
response += '<span class="add-on"><i class="icon-chevron-right"></i></span>'
- response += f.text_field((name_field + "_lteq").to_sym, :class => "span8 tpicker")
+ response += f.text_field(
+ (name_field + "_tp_gt").to_sym,
+ :value => (begin params[:q][(name_field + "_tp_gt").to_sym] rescue '' end),
+ :class => "span8 tpicker",
+ "data-id" => ("q_" + name_field + "_gteq"))
response += '<span class="add-on"><i class="icon-time"></i></span>'
response += '</div>'
+ end
- response += f.hidden_field(name_field + '_gteq(4i)', :id => ('q_' + name_field + '_gteq_4i')) # Hour
- response += f.hidden_field(name_field + '_gteq(5i)', :id => ('q_' + name_field + '_gteq_5i')) # Minute
+ for i in interval
+ response += f.hidden_field(name_field + "_gteq(#{i}i)",
+ :value => (begin params[:q][(name_field + "_gteq(#{i}i)").to_sym] rescue '' end),
+ :id => ('q_' + name_field + "_gteq_#{i}i"))
end
+ # Less than
response += '<div class="input-prepend input-append input-' + type_of_column.to_s + '">'
response += '<span class="add-on"><i class="icon-chevron-left"></i></span>'
- response += f.text_field((name_field + "_lteq").to_sym, :class => "span8 dpicker")
+ response += f.text_field(
+ (name_field + "_dp_lt").to_sym,
+ :value => (begin params[:q][(name_field + "_dp_lt").to_sym] rescue '' end),
+ :class => "span8 dpicker",
+ "data-id" => ("q_" + name_field + "_lteq"))
response += '<span class="add-on"><i class="icon-calendar"></i></span>'
response += '</div>'
- response += f.hidden_field(name_field + '_lteq(3i)', :id => ('q_' + name_field + '_lteq_3i')) # Day
- response += f.hidden_field(name_field + '_lteq(2i)', :id => ('q_' + name_field + '_lteq_2i')) # Mois
- response += f.hidden_field(name_field + '_lteq(1i)', :id => ('q_' + name_field + '_lteq_1i')) # Year
-
- if type_of_column == :datetime then
+ if dt then
response += '<div class="input-prepend input-append input-' + type_of_column.to_s + '">'
response += '<span class="add-on"><i class="icon-chevron-left"></i></span>'
- response += f.text_field((name_field + "_lteq").to_sym, :class => "span8 tpicker")
+ response += f.text_field(
+ (name_field + "_tp_lt").to_sym,
+ :value => (begin params[:q][(name_field + "_tp_lt").to_sym] rescue '' end),
+ :class => "span8 tpicker",
+ "data-id" => ("q_" + name_field + "_lteq"))
response += '<span class="add-on"><i class="icon-time"></i></span>'
response += '</div>'
+ end
- response += f.hidden_field(name_field + '_lteq(4i)', :id => ('q_' + name_field + '_lteq_4i')) # Hour
- response += f.hidden_field(name_field + '_lteq(5i)', :id => ('q_' + name_field + '_lteq_5i')) # Minute
+ for i in interval
+ response += f.hidden_field(name_field + "_lteq(#{i}i)",
+ :value => (begin params[:q][(name_field + "_lteq(#{i}i)").to_sym] rescue '' end),
+ :id => ('q_' + name_field + "_lteq_#{i}i"))
end
when :boolean then
# 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"
@@ -177,7 +195,23 @@
return true if column[-3,3] == "_id"
end
def get_belongs_to_model(column)
return column[0..-4]
+ end
+
+ def build_treeview(obj, child_relation)
+ out = '
+ <li id="treeelt_' + obj.id.to_s + '" data-id="' + obj.id.to_s + '">
+ <a href="#" class="nopjax">' + obj.caption + '</a>
+ <ul>'
+ ar = obj.send(child_relation.to_sym)
+ ar = ar.order('position') if obj.class.column_names.include?("position")
+ for o in ar.all
+ out += build_treeview(o, child_relation)
+ end
+ out += '
+ </ul>
+ </li>'
+ return out.html_safe
end
end