desktop-finder 0.0.1.1 → 0.0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/desktop/finder/version.rb +1 -1
- data/lib/desktop/finder.rb +49 -43
- metadata +1 -1
data/lib/desktop/finder.rb
CHANGED
@@ -8,55 +8,61 @@ module Desktop
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def Finder.create(params, simple=false, form=nil)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
record = Kernel.const_get(params[:controller].classify).new.attributes
|
12
|
+
options = record.each_key.collect{|key|
|
13
|
+
value = []
|
14
|
+
type = "text"
|
15
|
+
if key.include?("_id")
|
16
|
+
begin
|
17
|
+
value = Kernel.const_get(key.to_s.classify.sub('Id', '')).all.collect{|p|[p.id, p.name]}
|
18
|
+
rescue
|
19
|
+
next
|
20
|
+
end
|
21
|
+
type = "select"
|
16
22
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
{:type=>type, :name=>key, :label=>t(key), :value=>value}
|
24
|
+
}
|
25
|
+
#options = options || [{:type=>"text", :name=>"title", :label=>t('Title'), :value=>''},{:type=>'select', :name=>'issue_type_id', :label=>t('Issue Type'), :value=>IssueType.all}]
|
26
|
+
options = options || {}
|
27
|
+
if options.empty?
|
28
|
+
return ''
|
29
|
+
end
|
30
|
+
html = '<a href="#" class="pull-right" onclick="$(\'#J_searchWhere\').slideToggle();">.</a>'
|
31
|
+
if form
|
32
|
+
html << "<form method='get'>"
|
33
|
+
end
|
34
|
+
first = options.first
|
35
|
+
html << '<div class="search-where" id="J_searchWhere" style="'+ (params[first[:name]] ? '' : 'display:none;') + '">'
|
36
|
+
select_option = []
|
37
|
+
options.each do |option|
|
38
|
+
case simple
|
39
|
+
when false
|
40
|
+
html << label_tag("", option[:label], {:class=>"search-label"})
|
41
|
+
else
|
42
|
+
select_option = select_option.push([option[:name], option[:label]])
|
20
43
|
end
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
html << label_tag("", option[:label], {:class=>"search-label"})
|
28
|
-
else
|
29
|
-
select_option = select_option.push([option[:name], option[:label]])
|
30
|
-
end
|
31
|
-
html << '<div class="seach-value">'
|
32
|
-
case option[:type]
|
33
|
-
when 'select'
|
34
|
-
html << select_tag(option[:name], options_from_collection_for_select(option[:value], "id", "name", params[option[:name]]), {:include_blank=>true})
|
35
|
-
else
|
36
|
-
html << text_field_tag(option[:name], params[option[:name]], {:class=>"span2"})
|
37
|
-
end
|
38
|
-
html << '</div>'
|
44
|
+
html << '<div class="seach-value">'
|
45
|
+
case option[:type]
|
46
|
+
when 'select'
|
47
|
+
html << select_tag(option[:name], options_from_collection_for_select(option[:value], "id", "name", params[option[:name]]), {:include_blank=>true})
|
48
|
+
else
|
49
|
+
html << text_field_tag(option[:name], params[option[:name]], {:class=>"span2"})
|
39
50
|
end
|
40
|
-
html << submit_tag(t('Search'), {:class=>"btn"})
|
41
51
|
html << '</div>'
|
42
|
-
|
43
|
-
if form
|
44
|
-
html << '</form>'
|
45
|
-
end
|
46
|
-
|
47
|
-
html.html_safe
|
48
|
-
#<a href="#" onclick="$(this).parent('form').find('.search-where').show();" class="pull-right">.</a>
|
49
|
-
# <div class="search-where" style="display:none;">
|
50
|
-
# <table width="100%" class="table-form">
|
51
|
-
# <tr>
|
52
|
-
# </tr>
|
53
|
-
# </table>
|
54
|
-
# </div>
|
55
52
|
end
|
53
|
+
html << submit_tag(t('Search'), {:class=>"btn"})
|
54
|
+
html << '</div>'
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
#where = params.reject{|p,v| p=='controller' or p=='action' or p=='search' or p=='commit' or v.empty?}
|
56
|
+
if form
|
57
|
+
html << '</form>'
|
60
58
|
end
|
59
|
+
|
60
|
+
html.html_safe
|
61
|
+
end
|
62
|
+
|
63
|
+
def Finder.where(params)
|
64
|
+
where = params.reject{|p,v| p=='controller' or p=='action' or p=='search' or p=='commit' or v.empty?}
|
65
|
+
where
|
66
|
+
end
|
61
67
|
end
|
62
68
|
end
|