Module: Desktop::Finder
- Defined in:
- lib/desktop/finder.rb,
lib/desktop/finder/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
- .create(params, simple = false, form = nil) ⇒ Object
- .label_tag(id, label, o) ⇒ Object
- .select_tag(name, o, value) ⇒ Object
- .submit_tag(label, o) ⇒ Object
- .test ⇒ Object
- .text_field_tag(name, value, o) ⇒ Object
- .where(params) ⇒ Object
Class Method Details
.create(params, simple = false, form = nil) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/desktop/finder.rb', line 9 def Finder.create(params, simple=false, form=nil) puts '---------------finder create--------------------' record = Kernel.const_get(params[:controller].classify).new.attributes = record.each_key.collect{|key| value = [] type = "text" if key.include?("_id") begin value = Kernel.const_get(key.to_s.classify.sub('Id', '')).all.collect{|p|[p.id, p.name]} rescue next end type = "select" end {:type=>type, :name=>key, :label=>key, :value=>value} } #options = options || [{:type=>"text", :name=>"title", :label=>t('Title'), :value=>''},{:type=>'select', :name=>'issue_type_id', :label=>t('Issue Type'), :value=>IssueType.all}] = || {} if .empty? return '' end html = '<a href="#" class="pull-right" onclick="$(\'#J_searchWhere\').slideToggle();">.</a>' if form html << "<form method='get'>" end first = .first search_params = params[:search_where] || {} html << '<div class="search-where" id="J_searchWhere" style="'+ (search_params ? '' : 'display:none;') + '">' select_option = [] .each do |option| next if option.blank? case simple when false html << Desktop::Finder.label_tag("", option[:label], {:class=>"search-label"}) else select_option = select_option.push([option[:name], option[:label]]) end html << '<div class="seach-value">' case option[:type] when 'select' html << Desktop::Finder.select_tag(option[:name], option[:value], search_params[option[:name]]) else html << Desktop::Finder.text_field_tag(option[:name], search_params[option[:name]], {:class=>"span2"}) end html << '</div>' end html << Desktop::Finder.submit_tag('Search', {:class=>"btn"}) html << '</div>' if form html << '</form>' end html.html_safe end |
.label_tag(id, label, o) ⇒ Object
92 93 94 |
# File 'lib/desktop/finder.rb', line 92 def Finder.label_tag(id, label, o) "<label class='#{o[:class]}'>#{label}</label>" end |
.select_tag(name, o, value) ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/desktop/finder.rb', line 82 def Finder.select_tag(name, o, value) s = "<select name=\"search_where[#{name}]\">" s << "<option value=''></option>" o.each do|p| s << '<option value="' << p.fetch(0).to_s << '" ' << (p.fetch(0).to_s==value.to_s ? 'selected="selected"' : '') << '>' << (p.many? ? p.fetch(1).to_s : p.fetch(0).to_s) << '</option>' end s << '</select>' s end |
.submit_tag(label, o) ⇒ Object
74 75 76 |
# File 'lib/desktop/finder.rb', line 74 def Finder.submit_tag(label, o) "<input type=\"button\" value='#{label}' class='#{o[:class]}' onclick=\"$(this).parents('form:first').submit();\" />" end |
.test ⇒ Object
5 6 7 |
# File 'lib/desktop/finder.rb', line 5 def Finder.test puts '-----------test finder gem--------------' end |
.text_field_tag(name, value, o) ⇒ Object
78 79 80 |
# File 'lib/desktop/finder.rb', line 78 def Finder.text_field_tag(name, value, o) "<input type='text' name='search_where[#{name}]' value='#{value}' class='#{o[:class]}' />" end |
.where(params) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/desktop/finder.rb', line 65 def Finder.where(params) #where = params.reject{|p,v| p=='controller' or p=='action' or p=='search' or p=='commit' or v.empty?} if !params.has_key?("search_where") return {} end where = params[:search_where].reject{|p,v| v.empty?} where end |