it-logica-application-backbone 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/it-logica-application-backbone.gemspec +1 -1
- data/lib/controller_mixins/csv_instance_methods.rb +12 -10
- data/lib/controller_mixins/renderer_instance_methods.rb +81 -79
- data/lib/initializers/initialize.rb +0 -2
- data/lib/model_mixins/table_builder_class_methods.rb +152 -150
- data/lib/view_mixins/breadcrumb.rb +33 -31
- data/lib/view_mixins/form.rb +43 -41
- data/lib/view_mixins/link.rb +102 -100
- data/lib/view_mixins/table.rb +6 -4
- metadata +12 -12
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
@@ -1,14 +1,16 @@
|
|
1
|
-
module ControllerMixins
|
2
|
-
|
1
|
+
module ControllerMixins
|
2
|
+
module CsvInstanceMethods
|
3
|
+
require 'csv'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
def to_csv(objects, skip_attributes=[], delimiter= ",")
|
6
|
+
return "" if objects.blank?
|
7
|
+
objects_class = objects.first.class
|
8
|
+
filtered_columns = objects_class.column_names - skip_attributes
|
9
|
+
CSV.generate do |csv|
|
10
|
+
csv << filtered_columns
|
11
|
+
objects.each do |object|
|
12
|
+
csv << filtered_columns.collect { |a| object.attributes[a].blank? ? '' : "'#{object.attributes[a]}'" }
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,101 +1,103 @@
|
|
1
|
-
module ControllerMixins
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module ControllerMixins
|
2
|
+
module RendererInstanceMethods
|
3
|
+
def render_table_for(logged_user, template = nil, &proc)
|
4
|
+
@settings[:template] = template unless template.blank?
|
5
|
+
data = yield
|
6
|
+
class_obj = data.respond_to?(:klass) ? data.klass : data
|
7
|
+
if action_name == "filter"
|
8
|
+
default_params = params
|
9
|
+
default_params = @settings[:default] if !params.blank? && params["clear"]
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
else
|
15
|
-
@paginate = render_to_string(:partial => "/helpers/build_table_pager", :locals => {:settings => @settings})
|
16
|
-
session["#{@settings[:form_id]}_params"] = params
|
17
|
-
if @settings[:template].blank?
|
18
|
-
# if there is no template a will return json and tbody renders in javascript template
|
19
|
-
returned_t_body = @settings.to_json
|
11
|
+
@settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
|
12
|
+
if !params.blank? && params["clear"]
|
13
|
+
session["#{@settings[:form_id]}_params"] = ""
|
14
|
+
render :layout => false, :action => :index
|
20
15
|
else
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
@paginate = render_to_string(:partial => "/helpers/build_table_pager", :locals => {:settings => @settings})
|
17
|
+
session["#{@settings[:form_id]}_params"] = params
|
18
|
+
if @settings[:template].blank?
|
19
|
+
# if there is no template a will return json and tbody renders in javascript template
|
20
|
+
returned_t_body = @settings.to_json
|
21
|
+
else
|
22
|
+
# or there is template so i will return template rendered here in ruby
|
23
|
+
returned_t_body = render_to_string(:partial => @settings[:template], :locals => {:settings => @settings})
|
24
|
+
end
|
24
25
|
|
25
|
-
|
26
|
+
render :layout => false, :json => {:settings => returned_t_body, :paginate => @paginate}.to_json
|
27
|
+
end
|
28
|
+
elsif action_name == "index"
|
29
|
+
default_params = @settings[:default]
|
30
|
+
default_params = session["#{@settings[:form_id]}_params"] unless session["#{@settings[:form_id]}_params"].blank?
|
31
|
+
@settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
|
26
32
|
end
|
27
|
-
elsif action_name == "index"
|
28
|
-
default_params = @settings[:default]
|
29
|
-
default_params = session["#{@settings[:form_id]}_params"] unless session["#{@settings[:form_id]}_params"].blank?
|
30
|
-
@settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
|
31
33
|
end
|
32
|
-
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
def fill_settings_with opts
|
36
|
+
settings = {}
|
37
|
+
settings[:symlink_remote] = true
|
38
|
+
unless opts.at(0).nil?
|
39
|
+
opts = opts[0]
|
40
|
+
settings[:symlink_controller] = opts.include?(:controller) ? opts[:controller] : controller_name
|
41
|
+
settings[:symlink_outer_controller] = opts[:outer_controller] if opts.include?(:outer_controller)
|
42
|
+
settings[:symlink_outer_id] = opts[:outer_id] if opts.include?(:outer_id)
|
43
|
+
settings[:symlink_action] = opts[:action] if opts.include?(:action)
|
44
|
+
settings[:symlink_id] = opts[:id] if opts.include?(:id)
|
45
|
+
else
|
46
|
+
settings[:symlink_controller] = controller_name
|
47
|
+
end
|
48
|
+
settings
|
46
49
|
end
|
47
|
-
settings
|
48
|
-
end
|
49
|
-
|
50
|
-
def build_url_path_method(opts)
|
51
|
-
path = ""
|
52
50
|
|
53
|
-
|
51
|
+
def build_url_path_method(opts)
|
52
|
+
path = ""
|
54
53
|
|
55
|
-
|
56
|
-
path += '/' + opts[:outer_id].to_s if opts.include?(:outer_id)
|
57
|
-
path += opts.include?(:controller) ? '/' + opts[:controller].to_s : '/' + controller_name
|
58
|
-
path += '/' + opts[:id].to_s if opts.include?(:id)
|
59
|
-
path += '/' + opts[:action].to_s if opts.include?(:action)
|
54
|
+
opts = opts[0] unless opts.at(0).nil?
|
60
55
|
|
61
|
-
|
62
|
-
|
56
|
+
path += '/' + opts[:outer_controller].to_s if opts.include?(:outer_controller)
|
57
|
+
path += '/' + opts[:outer_id].to_s if opts.include?(:outer_id)
|
58
|
+
path += opts.include?(:controller) ? '/' + opts[:controller].to_s : '/' + controller_name
|
59
|
+
path += '/' + opts[:id].to_s if opts.include?(:id)
|
60
|
+
path += '/' + opts[:action].to_s if opts.include?(:action)
|
63
61
|
|
64
|
-
|
65
|
-
def redirect_not_found(*opts)
|
66
|
-
if request.xhr?
|
67
|
-
render :json => {:message => I18n.t("activerecord.errors.messages.record_not_found"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
|
68
|
-
else
|
69
|
-
redirect_to build_url_path_method(opts), :status => :moved_permanently
|
62
|
+
path
|
70
63
|
end
|
71
|
-
end
|
72
64
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
65
|
+
# redirect do indexu pokud neni zaznam v db
|
66
|
+
def redirect_not_found(*opts)
|
67
|
+
if request.xhr?
|
68
|
+
render :json => {:message => I18n.t("activerecord.errors.messages.record_not_found"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
|
69
|
+
else
|
70
|
+
redirect_to build_url_path_method(opts), :status => :moved_permanently
|
71
|
+
end
|
79
72
|
end
|
80
|
-
end
|
81
73
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
74
|
+
# redirect do indexu po uspesnem smazani
|
75
|
+
def redirect_destroy_ok(*opts)
|
76
|
+
if request.xhr?
|
77
|
+
render :json => {:status => "ok", :message => I18n.t("activerecord.info.messages.deleted"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
|
78
|
+
else
|
79
|
+
redirect_to build_url_path_method(opts), :status => :moved_permanently
|
80
|
+
end
|
88
81
|
end
|
89
82
|
|
90
|
-
|
83
|
+
# redirect po uspesnem save
|
84
|
+
def redirect_save_ok(*opts)
|
85
|
+
if request.xhr?
|
86
|
+
render :json => {:status => "ok", :message => I18n.t("activerecord.info.messages.saved"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
|
87
|
+
else
|
88
|
+
redirect_to build_url_path_method(opts), :status => :moved_permanently
|
89
|
+
end
|
91
90
|
|
92
|
-
# redirect po uspesnem save
|
93
|
-
def redirect_save_failed(*opts)
|
94
|
-
if request.xhr?
|
95
|
-
render :json => {:status => "ok", :message => I18n.t("activerecord.errors.messages.save_failed"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
|
96
|
-
else
|
97
|
-
redirect_to build_url_path_method(opts), :status => :moved_permanently
|
98
91
|
end
|
99
92
|
|
93
|
+
# redirect po uspesnem save
|
94
|
+
def redirect_save_failed(*opts)
|
95
|
+
if request.xhr?
|
96
|
+
render :json => {:status => "ok", :message => I18n.t("activerecord.errors.messages.save_failed"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
|
97
|
+
else
|
98
|
+
redirect_to build_url_path_method(opts), :status => :moved_permanently
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
100
102
|
end
|
101
103
|
end
|
@@ -1,189 +1,191 @@
|
|
1
|
-
module ModelMixins
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
items = not_selected_items.selection(settings)
|
10
|
-
if params[:page].to_i > items.total_pages && items.total_pages > 0
|
11
|
-
params[:page] = 1
|
1
|
+
module ModelMixins
|
2
|
+
module TableBuilderClassMethods
|
3
|
+
def prepare_settings(logged_user, object, settings, params, per_page = 10)
|
4
|
+
params[:page] = 1 if params[:page].blank?
|
5
|
+
params[:order_by] = settings[:default][:order_by] if params[:order_by].blank?
|
6
|
+
params[:order_by_direction] = settings[:default][:order_by_direction] if params[:order_by_direction].blank?
|
7
|
+
params[:per_page] = per_page
|
8
|
+
|
12
9
|
not_selected_items = object.filter(settings, params, per_page)
|
13
10
|
items = not_selected_items.selection(settings)
|
14
|
-
|
11
|
+
if params[:page].to_i > items.total_pages && items.total_pages > 0
|
12
|
+
params[:page] = 1
|
13
|
+
not_selected_items = object.filter(settings, params, per_page)
|
14
|
+
items = not_selected_items.selection(settings)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
17
|
+
if settings[:template].blank?
|
18
|
+
another_global_formats = []
|
19
|
+
another_formats = []
|
20
|
+
column_methods = []
|
21
|
+
settings[:columns].each do |col|
|
22
|
+
unless col[:global_format_method].blank?
|
23
|
+
# ToDo dodelat moznost predani parametru do formatovaci metody
|
24
|
+
another_global_format = {:global_format_method => col[:global_format_method],
|
25
|
+
:name => col[:name].blank? ? col[:global_format_method] : col[:name],
|
26
|
+
:table => col[:table]}
|
27
|
+
another_global_formats << another_global_format
|
28
|
+
end
|
29
|
+
unless col[:format_method].blank?
|
30
|
+
another_format = {:format_method => col[:format_method],
|
31
|
+
:name => col[:name].blank? ? col[:format_method] : col[:name],
|
32
|
+
:table => col[:table]}
|
33
|
+
another_formats << another_format
|
34
|
+
end
|
35
|
+
unless col[:column_method].blank?
|
36
|
+
column_methods << {:column_method => col[:column_method],
|
37
|
+
:name => col[:name],
|
38
|
+
:table => col[:table],
|
39
|
+
:column_class => col[:column_class],
|
40
|
+
:column_params => col[:column_params]
|
41
|
+
}
|
42
|
+
end
|
33
43
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
|
45
|
+
|
46
|
+
all_items = items.all # maybe can be done more optimal
|
47
|
+
# same as template_items below, loads objects so column method are better to use
|
48
|
+
# todo think about, but I dont need object, because it's making the same query twice, I just need class and with one outer join it return filtered data, and i include includes to it
|
49
|
+
#template_items = object.joins("RIGHT OUTER JOIN (" + not_selected_items.select(settings[:row][:id] + " AS row_id").to_sql + ") temp_template_query ON #{settings[:row][:id]} = temp_template_query.row_id")
|
50
|
+
if object.respond_to?(:klass)
|
51
|
+
template_items = object.klass.joins("RIGHT OUTER JOIN (" + not_selected_items.uniq.select(settings[:row][:id] + " AS row_id").to_sql + ") temp_template_query ON #{settings[:row][:id]} = temp_template_query.row_id")
|
52
|
+
else
|
53
|
+
template_items = object.joins("RIGHT OUTER JOIN (" + not_selected_items.uniq.select(settings[:row][:id] + " AS row_id").to_sql + ") temp_template_query ON #{settings[:row][:id]} = temp_template_query.row_id")
|
41
54
|
end
|
42
|
-
end
|
43
55
|
|
56
|
+
template_items = template_items.includes(settings[:includes])
|
44
57
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
#template_items = object.joins("RIGHT OUTER JOIN (" + not_selected_items.select(settings[:row][:id] + " AS row_id").to_sql + ") temp_template_query ON #{settings[:row][:id]} = temp_template_query.row_id")
|
49
|
-
if object.respond_to?(:klass)
|
50
|
-
template_items = object.klass.joins("RIGHT OUTER JOIN (" + not_selected_items.uniq.select(settings[:row][:id] + " AS row_id").to_sql + ") temp_template_query ON #{settings[:row][:id]} = temp_template_query.row_id")
|
51
|
-
else
|
52
|
-
template_items = object.joins("RIGHT OUTER JOIN (" + not_selected_items.uniq.select(settings[:row][:id] + " AS row_id").to_sql + ") temp_template_query ON #{settings[:row][:id]} = temp_template_query.row_id")
|
53
|
-
end
|
58
|
+
#template_items.all
|
59
|
+
# todo dat do knowledge base, kdyz chci aby fungoval include nesmim volat all
|
60
|
+
#template_items.each {|t| t.meeting_registrations.each {|x| puts x.inspect}}
|
54
61
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
if column_method[:column_class].blank?
|
69
|
-
if object.respond_to?(:klass)
|
70
|
-
another_columns[column_method[:column_method]] = object.klass.send(column_method[:column_method], logged_user, all_items, template_items, column_method_settings)
|
62
|
+
another_columns = {}
|
63
|
+
unless column_methods.blank?
|
64
|
+
column_method_settings = {:params => params}
|
65
|
+
column_methods.each do |column_method|
|
66
|
+
column_method_settings[:column_params] = column_method[:column_params]
|
67
|
+
#all items == array of array items
|
68
|
+
#template items == AREL
|
69
|
+
if column_method[:column_class].blank?
|
70
|
+
if object.respond_to?(:klass)
|
71
|
+
another_columns[column_method[:column_method]] = object.klass.send(column_method[:column_method], logged_user, all_items, template_items, column_method_settings)
|
72
|
+
else
|
73
|
+
another_columns[column_method[:column_method]] = object.send(column_method[:column_method], logged_user, all_items, template_items, column_method_settings)
|
74
|
+
end
|
71
75
|
else
|
72
|
-
|
76
|
+
column_method[:column_class] = column_method[:column_class].constantize if column_method[:column_class].kind_of?(String)
|
77
|
+
another_columns[column_method[:column_method]] = column_method[:column_class].send(column_method[:column_method], logged_user, all_items, template_items, column_method_settings)
|
73
78
|
end
|
74
|
-
else
|
75
|
-
column_method[:column_class] = column_method[:column_class].constantize if column_method[:column_class].kind_of?(String)
|
76
|
-
another_columns[column_method[:column_method]] = column_method[:column_class].send(column_method[:column_method], logged_user, all_items, template_items, column_method_settings)
|
77
79
|
end
|
78
80
|
end
|
79
|
-
end
|
80
81
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
82
|
+
if another_global_formats.blank? && another_formats.blank? && column_methods.blank?
|
83
|
+
items_array = items
|
84
|
+
else
|
85
|
+
items_array = []
|
86
|
+
all_items.each do |i|
|
87
|
+
attrs = i.attributes
|
88
|
+
another_global_formats.each do |another_global_format|
|
89
|
+
# todo udelat moznost predani dalsich parametru
|
90
|
+
attrs.merge!({"#{another_global_format[:table]}_#{another_global_format[:name]}" => i.send(another_global_format[:global_format_method].to_sym, attrs["#{another_global_format[:table]}_#{another_global_format[:name]}"])})
|
91
|
+
end
|
92
|
+
another_formats.each do |another_format|
|
93
|
+
attrs.merge!({"#{another_format[:table]}_#{another_format[:name]}" => i.send(another_format[:format_method].to_sym, attrs["#{another_format[:table]}_#{another_format[:name]}"])})
|
94
|
+
end
|
95
|
+
column_methods.each do |column_method|
|
96
|
+
another_column_row = "-"
|
97
|
+
another_column_row = another_columns[column_method[:column_method]][attrs['row_id']] if !another_columns.blank? && !another_columns[column_method[:column_method]].blank? && !another_columns[column_method[:column_method]][attrs['row_id']].blank?
|
98
|
+
attrs.merge!({"#{column_method[:table]}_#{column_method[:name]}" => another_column_row})
|
99
|
+
end
|
99
100
|
|
100
|
-
|
101
|
+
items_array << attrs
|
102
|
+
end
|
101
103
|
end
|
102
|
-
end
|
103
104
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
settings.merge!({:data => items_array})
|
106
|
+
else
|
107
|
+
template_items = object.joins("RIGHT OUTER JOIN (" + not_selected_items.uniq.select(settings[:row][:id] + " AS row_id").to_sql + ") temp_template_query ON #{settings[:row][:id]} = temp_template_query.row_id")
|
108
|
+
settings.merge!({:data => template_items})
|
109
|
+
end
|
110
|
+
settings.merge!({:data_paginate => items})
|
111
|
+
settings.merge!({:params => params})
|
112
|
+
settings
|
108
113
|
end
|
109
|
-
settings.merge!({:data_paginate => items})
|
110
|
-
settings.merge!({:params => params})
|
111
|
-
settings
|
112
|
-
end
|
113
114
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
115
|
+
def selection(settings)
|
116
|
+
select_string = ""
|
117
|
+
settings[:columns].each do |col|
|
118
|
+
col[:table] = "unknown" if col[:table].blank?
|
119
|
+
if col[:column_method].blank? && col[:row_method].blank? && !col[:name].blank?
|
120
|
+
select_string += ", " unless select_string.blank?
|
121
|
+
select_string += "#{col[:table]}.#{col[:name]} AS #{col[:table]}_#{col[:name]}"
|
122
|
+
end
|
121
123
|
end
|
122
|
-
end
|
123
124
|
|
124
|
-
|
125
|
-
|
125
|
+
select_string += ", " unless select_string.blank?
|
126
|
+
select_string += "#{settings[:row][:id]} AS row_id "
|
126
127
|
|
127
|
-
|
128
|
-
|
128
|
+
select(select_string)
|
129
|
+
end
|
129
130
|
|
130
|
-
|
131
|
-
|
131
|
+
def filter(settings, params, per_page = 10)
|
132
|
+
order_by = params[:order_by] +' '+ params[:order_by_direction]
|
132
133
|
|
133
134
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
135
|
+
cond_str = ""
|
136
|
+
cond_hash = {}
|
137
|
+
if !params.blank? && params['find']
|
138
|
+
params['find'].each_pair do |i, v|
|
139
|
+
unless v.blank?
|
140
|
+
cond_str += " AND " unless cond_str.blank?
|
141
|
+
cond_id = "find_#{i.gsub(/\./, '_')}"
|
142
|
+
cond_str += "#{i} LIKE :#{cond_id}" #OR guest_email LIKE :find"
|
143
|
+
cond_hash.merge!({cond_id.to_sym => "%#{v}%"})
|
144
|
+
end
|
143
145
|
end
|
144
146
|
end
|
145
|
-
end
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
148
|
+
if !params.blank? && params['multichoice']
|
149
|
+
params['multichoice'].each_pair do |i, v|
|
150
|
+
unless v.blank?
|
151
|
+
cond_str += " AND " unless cond_str.blank?
|
152
|
+
cond_id = "multichoice_#{i.gsub(/\./, '_')}"
|
152
153
|
|
153
|
-
|
154
|
-
|
154
|
+
cond_str += "#{i} IN (:#{cond_id})" #OR guest_email LIKE :find"
|
155
|
+
cond_hash.merge!({cond_id.to_sym => v})
|
156
|
+
end
|
155
157
|
end
|
156
158
|
end
|
157
|
-
end
|
158
159
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
160
|
+
if !params.blank? && params['date_from']
|
161
|
+
params['date_from'].each_pair do |i, v|
|
162
|
+
unless v.blank?
|
163
|
+
cond_str += " AND " unless cond_str.blank?
|
164
|
+
cond_id = "date_from_#{i.gsub(/\./, '_')}"
|
165
|
+
cond_str += "#{i} >= :#{cond_id}" #OR guest_email LIKE :find"
|
166
|
+
cond_hash.merge!({cond_id.to_sym => "#{v}"})
|
167
|
+
end
|
166
168
|
end
|
167
169
|
end
|
168
|
-
end
|
169
170
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
171
|
+
if !params.blank? && params['date_to']
|
172
|
+
params['date_to'].each_pair do |i, v|
|
173
|
+
unless v.blank?
|
174
|
+
cond_str += " AND " unless cond_str.blank?
|
175
|
+
cond_id = "date_to_#{i.gsub(/\./, '_')}"
|
176
|
+
cond_str += "#{i} <= :#{cond_id}" #OR guest_email LIKE :find"
|
177
|
+
cond_hash.merge!({cond_id.to_sym => "#{v}"})
|
178
|
+
end
|
177
179
|
end
|
178
180
|
end
|
179
|
-
end
|
180
181
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
182
|
+
#items = self.joins("LEFT OUTER JOIN intranet_text_pages ON resource_id = intranet_text_pages.id").where(cond_str, cond_hash).paginate(:page => params[:page], :per_page => per_page).order(order_by).selection(settings)
|
183
|
+
#if params[:page].to_i > items.total_pages && items.total_pages > 0
|
184
|
+
# params[:page] = 1
|
185
|
+
# items = self.where(cond_str, cond_hash).paginate(:page => params[:page], :per_page => per_page).order(order_by).selection(settings)
|
186
|
+
#end
|
187
|
+
#items
|
188
|
+
where(cond_str, cond_hash).paginate(:page => params[:page], :per_page => per_page).order(order_by)
|
189
|
+
end
|
188
190
|
end
|
189
191
|
end
|
@@ -1,44 +1,46 @@
|
|
1
|
-
module ViewMixins
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
if
|
8
|
-
|
9
|
-
|
10
|
-
bread_crumb_load_tree_recursive(breadcrumb, tree_node)
|
11
|
-
end
|
12
|
-
elsif object.respond_to?(:tree_nodes)
|
13
|
-
if !object.tree_nodes.blank? && !object.tree_nodes.first.blank? && is_tree_node?(object.tree_nodes.first)
|
14
|
-
tree_node = object.tree_nodes.first if !object.tree_nodes.blank? && !object.tree_nodes.first.blank?
|
1
|
+
module ViewMixins
|
2
|
+
module Breadcrumb
|
3
|
+
def breadcrumb_for(*args)
|
4
|
+
# ToDo dodělat caching tohoto, invalidovat budu pokud nastane SAVE u OBJECT
|
5
|
+
breadcrumb = []
|
6
|
+
args.each do |object|
|
7
|
+
if !object.blank?
|
8
|
+
if is_tree_node?(object)
|
9
|
+
tree_node = object
|
15
10
|
unless tree_node.blank?
|
16
11
|
bread_crumb_load_tree_recursive(breadcrumb, tree_node)
|
17
12
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
elsif object.respond_to?(:tree_nodes)
|
14
|
+
if !object.tree_nodes.blank? && !object.tree_nodes.first.blank? && is_tree_node?(object.tree_nodes.first)
|
15
|
+
tree_node = object.tree_nodes.first if !object.tree_nodes.blank? && !object.tree_nodes.first.blank?
|
16
|
+
unless tree_node.blank?
|
17
|
+
bread_crumb_load_tree_recursive(breadcrumb, tree_node)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
elsif object.kind_of?(Hash)
|
21
|
+
breadcrumb << object
|
22
|
+
elsif object.kind_of?(Array)
|
23
|
+
object.each do |o|
|
24
|
+
breadcrumb << o
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
26
28
|
end
|
29
|
+
render :partial => '/helpers/build_breadcrumb', :layout => false, :locals => {:breadcrumb => breadcrumb}
|
27
30
|
end
|
28
|
-
render :partial => '/helpers/build_breadcrumb', :layout => false, :locals => {:breadcrumb => breadcrumb}
|
29
|
-
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
def bread_crumb_load_tree_recursive(breadcrumb, tree_node)
|
33
|
+
unless tree_node.blank?
|
34
|
+
if tree_node.parent_node_id > 0
|
35
|
+
bread_crumb_load_tree_recursive(breadcrumb, tree_node.parent_node)
|
36
|
+
end
|
37
|
+
breadcrumb << tree_node
|
35
38
|
end
|
36
|
-
breadcrumb << tree_node
|
37
39
|
end
|
38
|
-
end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
def is_tree_node?(object)
|
42
|
+
false
|
43
|
+
#object.kind_of?(Intranet::TreeNode) #|| object.kind_of?(Web::TreeNode) || object.kind_of?(Organizer::TreeNode)
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
data/lib/view_mixins/form.rb
CHANGED
@@ -1,47 +1,49 @@
|
|
1
|
-
module ViewMixins
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
module ViewMixins
|
2
|
+
module Form
|
3
|
+
|
4
|
+
def ajax_form_for(record, options = {}, &proc)
|
5
|
+
raise ArgumentError, "Missing block" unless block_given?
|
6
|
+
|
7
|
+
options[:html] ||= {}
|
8
|
+
|
9
|
+
case record
|
10
|
+
when String, Symbol
|
11
|
+
object_name = record
|
12
|
+
object = nil
|
13
|
+
else
|
14
|
+
object = record.is_a?(Array) ? record.last : record
|
15
|
+
object_name = options[:as] || ActiveModel::Naming.param_key(object)
|
16
|
+
apply_form_for_options!(record, options)
|
17
|
+
end
|
18
|
+
caller_id = options[:html][:id]
|
19
|
+
options[:html][:remote] = options.delete(:remote) if options.has_key?(:remote)
|
20
|
+
options[:html][:method] = options.delete(:method) if options.has_key?(:method)
|
21
|
+
options[:html][:authenticity_token] = options.delete(:authenticity_token)
|
22
|
+
######### additional logic by ladas ##############
|
23
|
+
#options[:html][:control_against_overwrite_by_another_user] = Time.now
|
24
|
+
################## end ###############3###########
|
25
|
+
|
26
|
+
builder = options[:parent_builder] = instantiate_builder(object_name, object, options, &proc)
|
27
|
+
fields_for = fields_for(object_name, object, options, &proc)
|
28
|
+
default_options = builder.multipart? ? {:multipart => true} : {}
|
29
|
+
output = form_tag(options.delete(:url) || {}, default_options.merge!(options.delete(:html)))
|
30
|
+
######### additional logic by ladas ##############
|
31
|
+
if !object.blank? && !object.id.blank?
|
32
|
+
output << "<fieldset><input type='hidden' name='#{ActiveModel::Naming.param_key(record)}[control_against_overwrite_by_another_user]' value='#{Time.now.utc}' /></fieldset>".html_safe
|
33
|
+
end
|
34
|
+
################## end ###############3###########
|
35
|
+
|
36
|
+
output << fields_for
|
37
|
+
######### additional logic by ladas ##############
|
38
|
+
output.safe_concat(build_ajax_callback_code(caller_id))
|
39
|
+
################## end ###############3###########
|
40
|
+
output.safe_concat('</form>')
|
32
41
|
end
|
33
|
-
################## end ###############3###########
|
34
42
|
|
35
|
-
output << fields_for
|
36
|
-
######### additional logic by ladas ##############
|
37
|
-
output.safe_concat(build_ajax_callback_code(caller_id))
|
38
|
-
################## end ###############3###########
|
39
|
-
output.safe_concat('</form>')
|
40
|
-
end
|
41
43
|
|
44
|
+
def build_ajax_callback_code(caller_id)
|
45
|
+
render :partial => '/helpers/build_ajax_callback_code', :layout => false, :locals => {:caller_id => caller_id}
|
46
|
+
end
|
42
47
|
|
43
|
-
def build_ajax_callback_code(caller_id)
|
44
|
-
render :partial => '/helpers/build_ajax_callback_code', :layout => false, :locals => {:caller_id => caller_id}
|
45
48
|
end
|
46
|
-
|
47
49
|
end
|
data/lib/view_mixins/link.rb
CHANGED
@@ -1,117 +1,119 @@
|
|
1
|
-
module ViewMixins
|
2
|
-
def
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
1
|
+
module ViewMixins
|
2
|
+
def Link
|
3
|
+
def ajax_link_to(*args, &block)
|
4
|
+
if block_given?
|
5
|
+
options = args.first || {}
|
6
|
+
html_options = args.second
|
7
|
+
######### additional logic by ladas ##############
|
8
|
+
html_options ||= {}
|
9
|
+
html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
|
10
|
+
#########################################
|
11
|
+
link_to(capture(&block), options, html_options)
|
12
|
+
else
|
13
|
+
name = args[0]
|
14
|
+
options = args[1] || {}
|
15
|
+
html_options = args[2]
|
16
|
+
######### additional logic by ladas ##############
|
17
|
+
html_options ||= {}
|
18
|
+
html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
|
19
|
+
#########################################
|
20
|
+
html_options = convert_options_to_data_attributes(options, html_options)
|
21
|
+
url = url_for(options)
|
21
22
|
|
22
|
-
|
23
|
-
|
23
|
+
href = html_options['href']
|
24
|
+
tag_options = tag_options(html_options)
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
|
27
|
+
"<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
|
28
|
+
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
31
|
+
def ajax_post_link_to(*args, &block)
|
32
|
+
if block_given?
|
33
|
+
options = args.first || {}
|
34
|
+
html_options = args.second
|
35
|
+
######### additional logic by ladas ##############
|
36
|
+
html_options ||= {}
|
37
|
+
html_options['onclick'] = "parse_link_and_post($(this)); return false;"
|
38
|
+
#########################################
|
39
|
+
link_to(capture(&block), options, html_options)
|
40
|
+
else
|
41
|
+
name = args[0]
|
42
|
+
options = args[1] || {}
|
43
|
+
html_options = args[2]
|
44
|
+
######### additional logic by ladas ##############
|
45
|
+
html_options ||= {}
|
46
|
+
html_options['onclick'] = "parse_link_and_post($(this)); return false;"
|
47
|
+
#########################################
|
48
|
+
html_options = convert_options_to_data_attributes(options, html_options)
|
49
|
+
url = url_for(options)
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
href = html_options['href']
|
52
|
+
tag_options = tag_options(html_options)
|
52
53
|
|
53
|
-
|
54
|
-
|
54
|
+
href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
|
55
|
+
"<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
|
56
|
+
end
|
55
57
|
end
|
56
|
-
end
|
57
58
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
59
|
+
# used only in jstree
|
60
|
+
def link_tree(*args, &block)
|
61
|
+
if block_given?
|
62
|
+
options = args.first || {}
|
63
|
+
html_options = args.second
|
64
|
+
######### additional logic by ladas ##############
|
65
|
+
html_options ||= {}
|
66
|
+
html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
|
67
|
+
#########################################
|
68
|
+
link_to(capture(&block), options, html_options)
|
69
|
+
else
|
70
|
+
name = args[0]
|
71
|
+
options = args[1] || {}
|
72
|
+
html_options = args[2]
|
73
|
+
######### additional logic by ladas ##############
|
74
|
+
html_options ||= {}
|
75
|
+
html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
|
76
|
+
#########################################
|
77
|
+
html_options = convert_options_to_data_attributes(options, html_options)
|
78
|
+
url = url_for(options)
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
href = html_options['href']
|
81
|
+
tag_options = tag_options(html_options)
|
81
82
|
|
82
|
-
|
83
|
-
|
83
|
+
href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
|
84
|
+
"<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
|
85
|
+
end
|
84
86
|
end
|
85
|
-
end
|
86
87
|
|
87
|
-
|
88
|
-
|
88
|
+
def convert_settings_to_url settings_json
|
89
|
+
# make sure its the same as build_url in ladas_loading.js
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
91
|
+
settings = JSON.parse(settings_json)
|
92
|
+
url = ""
|
93
|
+
if settings['url']
|
94
|
+
url += settings['url']
|
95
|
+
else
|
96
|
+
if settings['symlink_outer_controller']
|
97
|
+
url += "/" + settings['symlink_outer_controller']
|
98
|
+
end
|
99
|
+
if settings['symlink_outer_id']
|
100
|
+
url += "/" + settings['symlink_outer_id']
|
101
|
+
end
|
102
|
+
if settings['symlink_controller']
|
103
|
+
url += "/" + settings['symlink_controller']
|
104
|
+
end
|
105
|
+
if settings['symlink_id']
|
106
|
+
url += "/" + settings['symlink_id']
|
107
|
+
end
|
108
|
+
if settings['symlink_action']
|
109
|
+
url += "/" + settings['symlink_action']
|
110
|
+
end
|
111
|
+
if settings['symlink_params']
|
112
|
+
url += settings['params']
|
113
|
+
end
|
112
114
|
end
|
115
|
+
url
|
113
116
|
end
|
114
|
-
url
|
115
|
-
end
|
116
117
|
|
118
|
+
end
|
117
119
|
end
|
data/lib/view_mixins/table.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
module ViewMixins
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module ViewMixins
|
2
|
+
module Table
|
3
|
+
def table_for(settings)
|
4
|
+
#settings
|
5
|
+
render :partial => '/helpers/build_table', :layout => false, :locals => {:settings => settings}
|
6
|
+
end
|
5
7
|
end
|
6
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: it-logica-application-backbone
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-07-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
16
|
-
requirement: &
|
16
|
+
requirement: &80440670 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *80440670
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &80440410 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.12'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *80440410
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &80440020 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.1.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *80440020
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &80439690 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.8.4
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *80439690
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &80439410 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *80439410
|
69
69
|
description: longer description of your gem
|
70
70
|
email: ladislav.smola@it-logica.cz
|
71
71
|
executables: []
|
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
segments:
|
146
146
|
- 0
|
147
|
-
hash:
|
147
|
+
hash: -781184717
|
148
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
149
|
none: false
|
150
150
|
requirements:
|