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 CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "it-logica-application-backbone"
8
- s.version = "0.1.7"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ladas"]
@@ -1,14 +1,16 @@
1
- module ControllerMixins::CsvInstanceMethods
2
- require 'csv'
1
+ module ControllerMixins
2
+ module CsvInstanceMethods
3
+ require 'csv'
3
4
 
4
- def to_csv(objects, skip_attributes=[], delimiter= ",")
5
- return "" if objects.blank?
6
- objects_class = objects.first.class
7
- filtered_columns = objects_class.column_names - skip_attributes
8
- CSV.generate do |csv|
9
- csv << filtered_columns
10
- objects.each do |object|
11
- csv << filtered_columns.collect { |a| object.attributes[a].blank? ? '' : "'#{object.attributes[a]}'" }
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::RendererInstanceMethods
2
- def render_table_for(logged_user, template = nil, &proc)
3
- @settings[:template] = template unless template.blank?
4
- data = yield
5
- class_obj = data.respond_to?(:klass) ? data.klass : data
6
- if action_name == "filter"
7
- default_params = params
8
- default_params = @settings[:default] if !params.blank? && params["clear"]
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
- @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
11
- if !params.blank? && params["clear"]
12
- session["#{@settings[:form_id]}_params"] = ""
13
- render :layout => false, :action => :index
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
- # or there is template so i will return template rendered here in ruby
22
- returned_t_body = render_to_string(:partial => @settings[:template], :locals => {:settings => @settings})
23
- end
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
- render :layout => false, :json => {:settings => returned_t_body, :paginate => @paginate}.to_json
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
- def fill_settings_with opts
35
- settings = {}
36
- settings[:symlink_remote] = true
37
- unless opts.at(0).nil?
38
- opts = opts[0]
39
- settings[:symlink_controller] = opts.include?(:controller) ? opts[:controller] : controller_name
40
- settings[:symlink_outer_controller] = opts[:outer_controller] if opts.include?(:outer_controller)
41
- settings[:symlink_outer_id] = opts[:outer_id] if opts.include?(:outer_id)
42
- settings[:symlink_action] = opts[:action] if opts.include?(:action)
43
- settings[:symlink_id] = opts[:id] if opts.include?(:id)
44
- else
45
- settings[:symlink_controller] = controller_name
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
- opts = opts[0] unless opts.at(0).nil?
51
+ def build_url_path_method(opts)
52
+ path = ""
54
53
 
55
- path += '/' + opts[:outer_controller].to_s if opts.include?(:outer_controller)
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
- path
62
- end
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
- # redirect do indexu pokud neni zaznam v db
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
- # redirect do indexu po uspesnem smazani
74
- def redirect_destroy_ok(*opts)
75
- if request.xhr?
76
- render :json => {:status => "ok", :message => I18n.t("activerecord.info.messages.deleted"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
77
- else
78
- redirect_to build_url_path_method(opts), :status => :moved_permanently
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
- # redirect po uspesnem save
83
- def redirect_save_ok(*opts)
84
- if request.xhr?
85
- render :json => {:status => "ok", :message => I18n.t("activerecord.info.messages.saved"), :settings => fill_settings_with(opts)}, :status => :moved_permanently
86
- else
87
- redirect_to build_url_path_method(opts), :status => :moved_permanently
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
- end
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,5 +1,3 @@
1
-
2
-
3
1
  class ActiveRecord::Base
4
2
  extend ModelMixins::TableBuilderClassMethods
5
3
  end
@@ -1,189 +1,191 @@
1
- module ModelMixins::TableBuilderClassMethods
2
- def prepare_settings(logged_user, object, settings, params, per_page = 10)
3
- params[:page] = 1 if params[:page].blank?
4
- params[:order_by] = settings[:default][:order_by] if params[:order_by].blank?
5
- params[:order_by_direction] = settings[:default][:order_by_direction] if params[:order_by_direction].blank?
6
- params[:per_page] = per_page
7
-
8
- not_selected_items = object.filter(settings, params, per_page)
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
- end
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
- if settings[:template].blank?
17
- another_global_formats = []
18
- another_formats = []
19
- column_methods = []
20
- settings[:columns].each do |col|
21
- unless col[:global_format_method].blank?
22
- # ToDo dodelat moznost predani parametru do formatovaci metody
23
- another_global_format = {:global_format_method => col[:global_format_method],
24
- :name => col[:name].blank? ? col[:global_format_method] : col[:name],
25
- :table => col[:table]}
26
- another_global_formats << another_global_format
27
- end
28
- unless col[:format_method].blank?
29
- another_format = {:format_method => col[:format_method],
30
- :name => col[:name].blank? ? col[:format_method] : col[:name],
31
- :table => col[:table]}
32
- another_formats << another_format
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
- unless col[:column_method].blank?
35
- column_methods << {:column_method => col[:column_method],
36
- :name => col[:name],
37
- :table => col[:table],
38
- :column_class => col[:column_class],
39
- :column_params => col[:column_params]
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
- all_items = items.all # maybe can be done more optimal
46
- # same as template_items below, loads objects so column method are better to use
47
- # 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
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
- template_items = template_items.includes(settings[:includes])
56
-
57
- #template_items.all
58
- # todo dat do knowledge base, kdyz chci aby fungoval include nesmim volat all
59
- #template_items.each {|t| t.meeting_registrations.each {|x| puts x.inspect}}
60
-
61
- another_columns = {}
62
- unless column_methods.blank?
63
- column_method_settings = {:params => params}
64
- column_methods.each do |column_method|
65
- column_method_settings[:column_params] = column_method[:column_params]
66
- #all items == array of array items
67
- #template items == AREL
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
- another_columns[column_method[:column_method]] = object.send(column_method[:column_method], logged_user, all_items, template_items, column_method_settings)
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
- if another_global_formats.blank? && another_formats.blank? && column_methods.blank?
82
- items_array = items
83
- else
84
- items_array = []
85
- all_items.each do |i|
86
- attrs = i.attributes
87
- another_global_formats.each do |another_global_format|
88
- # todo udelat moznost predani dalsich parametru
89
- 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]}"])})
90
- end
91
- another_formats.each do |another_format|
92
- attrs.merge!({"#{another_format[:table]}_#{another_format[:name]}" => i.send(another_format[:format_method].to_sym, attrs["#{another_format[:table]}_#{another_format[:name]}"])})
93
- end
94
- column_methods.each do |column_method|
95
- another_column_row = "-"
96
- 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?
97
- attrs.merge!({"#{column_method[:table]}_#{column_method[:name]}" => another_column_row})
98
- end
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
- items_array << attrs
101
+ items_array << attrs
102
+ end
101
103
  end
102
- end
103
104
 
104
- settings.merge!({:data => items_array})
105
- else
106
- 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")
107
- settings.merge!({:data => template_items})
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
- def selection(settings)
115
- select_string = ""
116
- settings[:columns].each do |col|
117
- col[:table] = "unknown" if col[:table].blank?
118
- if col[:column_method].blank? && col[:row_method].blank? && !col[:name].blank?
119
- select_string += ", " unless select_string.blank?
120
- select_string += "#{col[:table]}.#{col[:name]} AS #{col[:table]}_#{col[:name]}"
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
- select_string += ", " unless select_string.blank?
125
- select_string += "#{settings[:row][:id]} AS row_id "
125
+ select_string += ", " unless select_string.blank?
126
+ select_string += "#{settings[:row][:id]} AS row_id "
126
127
 
127
- select(select_string)
128
- end
128
+ select(select_string)
129
+ end
129
130
 
130
- def filter(settings, params, per_page = 10)
131
- order_by = params[:order_by] +' '+ params[:order_by_direction]
131
+ def filter(settings, params, per_page = 10)
132
+ order_by = params[:order_by] +' '+ params[:order_by_direction]
132
133
 
133
134
 
134
- cond_str = ""
135
- cond_hash = {}
136
- if !params.blank? && params['find']
137
- params['find'].each_pair do |i, v|
138
- unless v.blank?
139
- cond_str += " AND " unless cond_str.blank?
140
- cond_id = "find_#{i.gsub(/\./, '_')}"
141
- cond_str += "#{i} LIKE :#{cond_id}" #OR guest_email LIKE :find"
142
- cond_hash.merge!({cond_id.to_sym => "%#{v}%"})
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
- if !params.blank? && params['multichoice']
148
- params['multichoice'].each_pair do |i, v|
149
- unless v.blank?
150
- cond_str += " AND " unless cond_str.blank?
151
- cond_id = "multichoice_#{i.gsub(/\./, '_')}"
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
- cond_str += "#{i} IN (:#{cond_id})" #OR guest_email LIKE :find"
154
- cond_hash.merge!({cond_id.to_sym => v})
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
- if !params.blank? && params['date_from']
160
- params['date_from'].each_pair do |i, v|
161
- unless v.blank?
162
- cond_str += " AND " unless cond_str.blank?
163
- cond_id = "date_from_#{i.gsub(/\./, '_')}"
164
- cond_str += "#{i} >= :#{cond_id}" #OR guest_email LIKE :find"
165
- cond_hash.merge!({cond_id.to_sym => "#{v}"})
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
- if !params.blank? && params['date_to']
171
- params['date_to'].each_pair do |i, v|
172
- unless v.blank?
173
- cond_str += " AND " unless cond_str.blank?
174
- cond_id = "date_to_#{i.gsub(/\./, '_')}"
175
- cond_str += "#{i} <= :#{cond_id}" #OR guest_email LIKE :find"
176
- cond_hash.merge!({cond_id.to_sym => "#{v}"})
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
- #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)
182
- #if params[:page].to_i > items.total_pages && items.total_pages > 0
183
- # params[:page] = 1
184
- # items = self.where(cond_str, cond_hash).paginate(:page => params[:page], :per_page => per_page).order(order_by).selection(settings)
185
- #end
186
- #items
187
- where(cond_str, cond_hash).paginate(:page => params[:page], :per_page => per_page).order(order_by)
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::Breadcrumb
2
- def breadcrumb_for(*args)
3
- # ToDo dodělat caching tohoto, invalidovat budu pokud nastane SAVE u OBJECT
4
- breadcrumb = []
5
- args.each do |object|
6
- if !object.blank?
7
- if is_tree_node?(object)
8
- tree_node = object
9
- unless tree_node.blank?
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
- end
19
- elsif object.kind_of?(Hash)
20
- breadcrumb << object
21
- elsif object.kind_of?(Array)
22
- object.each do |o|
23
- breadcrumb << o
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
- def bread_crumb_load_tree_recursive(breadcrumb, tree_node)
32
- unless tree_node.blank?
33
- if tree_node.parent_node_id > 0
34
- bread_crumb_load_tree_recursive(breadcrumb, tree_node.parent_node)
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
- def is_tree_node?(object)
41
- false
42
- #object.kind_of?(Intranet::TreeNode) #|| object.kind_of?(Web::TreeNode) || object.kind_of?(Organizer::TreeNode)
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
@@ -1,47 +1,49 @@
1
- module ViewMixins::Form
2
-
3
- def ajax_form_for(record, options = {}, &proc)
4
- raise ArgumentError, "Missing block" unless block_given?
5
-
6
- options[:html] ||= {}
7
-
8
- case record
9
- when String, Symbol
10
- object_name = record
11
- object = nil
12
- else
13
- object = record.is_a?(Array) ? record.last : record
14
- object_name = options[:as] || ActiveModel::Naming.param_key(object)
15
- apply_form_for_options!(record, options)
16
- end
17
- caller_id = options[:html][:id]
18
- options[:html][:remote] = options.delete(:remote) if options.has_key?(:remote)
19
- options[:html][:method] = options.delete(:method) if options.has_key?(:method)
20
- options[:html][:authenticity_token] = options.delete(:authenticity_token)
21
- ######### additional logic by ladas ##############
22
- #options[:html][:control_against_overwrite_by_another_user] = Time.now
23
- ################## end ###############3###########
24
-
25
- builder = options[:parent_builder] = instantiate_builder(object_name, object, options, &proc)
26
- fields_for = fields_for(object_name, object, options, &proc)
27
- default_options = builder.multipart? ? {:multipart => true} : {}
28
- output = form_tag(options.delete(:url) || {}, default_options.merge!(options.delete(:html)))
29
- ######### additional logic by ladas ##############
30
- if !object.blank? && !object.id.blank?
31
- output << "<fieldset><input type='hidden' name='#{ActiveModel::Naming.param_key(record)}[control_against_overwrite_by_another_user]' value='#{Time.now.utc}' /></fieldset>".html_safe
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
@@ -1,117 +1,119 @@
1
- module ViewMixins::Link
2
- def ajax_link_to(*args, &block)
3
- if block_given?
4
- options = args.first || {}
5
- html_options = args.second
6
- ######### additional logic by ladas ##############
7
- html_options ||= {}
8
- html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
9
- #########################################
10
- link_to(capture(&block), options, html_options)
11
- else
12
- name = args[0]
13
- options = args[1] || {}
14
- html_options = args[2]
15
- ######### additional logic by ladas ##############
16
- html_options ||= {}
17
- html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
18
- #########################################
19
- html_options = convert_options_to_data_attributes(options, html_options)
20
- url = url_for(options)
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
- href = html_options['href']
23
- tag_options = tag_options(html_options)
23
+ href = html_options['href']
24
+ tag_options = tag_options(html_options)
24
25
 
25
- href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
26
- "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
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
- def ajax_post_link_to(*args, &block)
31
- if block_given?
32
- options = args.first || {}
33
- html_options = args.second
34
- ######### additional logic by ladas ##############
35
- html_options ||= {}
36
- html_options['onclick'] = "parse_link_and_post($(this)); return false;"
37
- #########################################
38
- link_to(capture(&block), options, html_options)
39
- else
40
- name = args[0]
41
- options = args[1] || {}
42
- html_options = args[2]
43
- ######### additional logic by ladas ##############
44
- html_options ||= {}
45
- html_options['onclick'] = "parse_link_and_post($(this)); return false;"
46
- #########################################
47
- html_options = convert_options_to_data_attributes(options, html_options)
48
- url = url_for(options)
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
- href = html_options['href']
51
- tag_options = tag_options(html_options)
51
+ href = html_options['href']
52
+ tag_options = tag_options(html_options)
52
53
 
53
- href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
54
- "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
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
- # used only in jstree
59
- def link_tree(*args, &block)
60
- if block_given?
61
- options = args.first || {}
62
- html_options = args.second
63
- ######### additional logic by ladas ##############
64
- html_options ||= {}
65
- html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
66
- #########################################
67
- link_to(capture(&block), options, html_options)
68
- else
69
- name = args[0]
70
- options = args[1] || {}
71
- html_options = args[2]
72
- ######### additional logic by ladas ##############
73
- html_options ||= {}
74
- html_options['onclick'] = "parse_link_and_load_page($(this)); return false;"
75
- #########################################
76
- html_options = convert_options_to_data_attributes(options, html_options)
77
- url = url_for(options)
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
- href = html_options['href']
80
- tag_options = tag_options(html_options)
80
+ href = html_options['href']
81
+ tag_options = tag_options(html_options)
81
82
 
82
- href_attr = "href=\"#{ERB::Util.html_escape(url)}\"" unless href
83
- "<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
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
- def convert_settings_to_url settings_json
88
- # make sure its the same as build_url in ladas_loading.js
88
+ def convert_settings_to_url settings_json
89
+ # make sure its the same as build_url in ladas_loading.js
89
90
 
90
- settings = JSON.parse(settings_json)
91
- url = ""
92
- if settings['url']
93
- url += settings['url']
94
- else
95
- if settings['symlink_outer_controller']
96
- url += "/" + settings['symlink_outer_controller']
97
- end
98
- if settings['symlink_outer_id']
99
- url += "/" + settings['symlink_outer_id']
100
- end
101
- if settings['symlink_controller']
102
- url += "/" + settings['symlink_controller']
103
- end
104
- if settings['symlink_id']
105
- url += "/" + settings['symlink_id']
106
- end
107
- if settings['symlink_action']
108
- url += "/" + settings['symlink_action']
109
- end
110
- if settings['symlink_params']
111
- url += settings['params']
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
@@ -1,6 +1,8 @@
1
- module ViewMixins::Table
2
- def table_for(settings)
3
- #settings
4
- render :partial => '/helpers/build_table', :layout => false, :locals => {:settings => settings}
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.7
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: &84612880 !ruby/object:Gem::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: *84612880
24
+ version_requirements: *80440670
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &84612550 !ruby/object:Gem::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: *84612550
35
+ version_requirements: *80440410
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &84612230 !ruby/object:Gem::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: *84612230
46
+ version_requirements: *80440020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &84611910 !ruby/object:Gem::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: *84611910
57
+ version_requirements: *80439690
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: simplecov
60
- requirement: &84611590 !ruby/object:Gem::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: *84611590
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: 128780115
147
+ hash: -781184717
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements: