desktop-finder 0.0.1.6 → 0.0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/desktop/finder/version.rb +1 -1
- data/lib/desktop/finder.rb +55 -52
- metadata +1 -1
data/lib/desktop/finder.rb
CHANGED
|
@@ -5,67 +5,70 @@ require "action_support/core_ext"
|
|
|
5
5
|
module Desktop
|
|
6
6
|
class Finder
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
class << self
|
|
9
|
+
|
|
10
|
+
def Finder.test
|
|
11
|
+
puts '-----------test finder gem--------------'
|
|
12
|
+
end
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
def create(params, simple=false, form=nil)
|
|
15
|
+
puts '---------------finder create--------------------'
|
|
16
|
+
record = Kernel.const_get(params[:controller].classify).new.attributes
|
|
17
|
+
options = record.each_key.collect{|key|
|
|
18
|
+
value = []
|
|
19
|
+
type = "text"
|
|
20
|
+
if key.include?("_id")
|
|
21
|
+
begin
|
|
22
|
+
value = Kernel.const_get(key.to_s.classify.sub('Id', '')).all.collect{|p|[p.id, p.name]}
|
|
23
|
+
rescue
|
|
24
|
+
next
|
|
25
|
+
end
|
|
26
|
+
type = "select"
|
|
23
27
|
end
|
|
24
|
-
type
|
|
28
|
+
{:type=>type, :name=>key, :label=>key, :value=>value}
|
|
29
|
+
}
|
|
30
|
+
#options = options || [{:type=>"text", :name=>"title", :label=>t('Title'), :value=>''},{:type=>'select', :name=>'issue_type_id', :label=>t('Issue Type'), :value=>IssueType.all}]
|
|
31
|
+
options = options || {}
|
|
32
|
+
if options.empty?
|
|
33
|
+
return ''
|
|
25
34
|
end
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
options = options || {}
|
|
30
|
-
if options.empty?
|
|
31
|
-
return ''
|
|
32
|
-
end
|
|
33
|
-
html = '<a href="#" class="pull-right" onclick="$(\'#J_searchWhere\').slideToggle();">.</a>'
|
|
34
|
-
if form
|
|
35
|
-
html << "<form method='get'>"
|
|
36
|
-
end
|
|
37
|
-
first = options.first
|
|
38
|
-
html << '<div class="search-where" id="J_searchWhere" style="'+ (params[first[:name]] ? '' : 'display:none;') + '">'
|
|
39
|
-
select_option = []
|
|
40
|
-
options.each do |option|
|
|
41
|
-
case simple
|
|
42
|
-
when false
|
|
43
|
-
html << label_tag("", option[:label], {:class=>"search-label"})
|
|
44
|
-
else
|
|
45
|
-
select_option = select_option.push([option[:name], option[:label]])
|
|
35
|
+
html = '<a href="#" class="pull-right" onclick="$(\'#J_searchWhere\').slideToggle();">.</a>'
|
|
36
|
+
if form
|
|
37
|
+
html << "<form method='get'>"
|
|
46
38
|
end
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
first = options.first
|
|
40
|
+
html << '<div class="search-where" id="J_searchWhere" style="'+ (params[first[:name]] ? '' : 'display:none;') + '">'
|
|
41
|
+
select_option = []
|
|
42
|
+
options.each do |option|
|
|
43
|
+
case simple
|
|
44
|
+
when false
|
|
45
|
+
html << label_tag("", option[:label], {:class=>"search-label"})
|
|
46
|
+
else
|
|
47
|
+
select_option = select_option.push([option[:name], option[:label]])
|
|
48
|
+
end
|
|
49
|
+
html << '<div class="seach-value">'
|
|
50
|
+
case option[:type]
|
|
51
|
+
when 'select'
|
|
52
|
+
html << select_tag(option[:name], options_from_collection_for_select(option[:value], "id", "name", params[option[:name]]), {:include_blank=>true})
|
|
53
|
+
else
|
|
54
|
+
html << text_field_tag(option[:name], params[option[:name]], {:class=>"span2"})
|
|
55
|
+
end
|
|
56
|
+
html << '</div>'
|
|
53
57
|
end
|
|
58
|
+
html << submit_tag(t('Search'), {:class=>"btn"})
|
|
54
59
|
html << '</div>'
|
|
55
|
-
end
|
|
56
|
-
html << submit_tag(t('Search'), {:class=>"btn"})
|
|
57
|
-
html << '</div>'
|
|
58
60
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
if form
|
|
62
|
+
html << '</form>'
|
|
63
|
+
end
|
|
62
64
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
html.html_safe
|
|
66
|
+
end
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
def where(params)
|
|
69
|
+
where = params.reject{|p,v| p=='controller' or p=='action' or p=='search' or p=='commit' or v.empty?}
|
|
70
|
+
where
|
|
71
|
+
end
|
|
69
72
|
end
|
|
70
73
|
end
|
|
71
74
|
end
|