it-logica-application-backbone 0.2.10 → 0.2.11

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.10
1
+ 0.2.11
@@ -2,7 +2,7 @@ function formatLinkForPaginationURL(form_id) {
2
2
  var matchedString;
3
3
  var page_number;
4
4
  //$("#" + paginate_wrapper).find("a").each(function() {
5
- $("."+ form_id +"_pager").find("a").each(function() {
5
+ $("." + form_id + "_pager").find("a").each(function () {
6
6
  var linkElement = $(this);
7
7
  var paginationURL = linkElement.attr("href");
8
8
  var matchedString = paginationURL.match(/(\?|\&)page=(\d+)/);
@@ -12,11 +12,11 @@ function formatLinkForPaginationURL(form_id) {
12
12
  }
13
13
 
14
14
  linkElement.attr({
15
- "url": paginationURL,
16
- "href": "#"
15
+ "url":paginationURL,
16
+ "href":"#"
17
17
  });
18
18
 
19
- linkElement.click(function() {
19
+ linkElement.click(function () {
20
20
  $("#" + form_id + "_page").val(page_number);
21
21
  $("#" + form_id).submit();
22
22
  return false;
@@ -29,7 +29,7 @@ function formatLinkForPagination(container_class) {
29
29
  var matchedString;
30
30
  var page_number;
31
31
  //$("#" + paginate_wrapper).find("a").each(function() {
32
- $("."+ container_class).find("a").each(function() {
32
+ $("." + container_class).find("a").each(function () {
33
33
  var linkElement = $(this);
34
34
  var paginationURL = linkElement.attr("href");
35
35
  var matchedString = paginationURL.match(/(\?|\&)page=(\d+)/);
@@ -41,10 +41,12 @@ function formatLinkForPagination(container_class) {
41
41
  linkElement.attr({
42
42
  // "url": paginationURL,
43
43
  // "href": "#"
44
- "data-remote": true
44
+ "data-remote":true
45
45
  });
46
46
 
47
- linkElement.bind('ajax:beforeSend', function(evt, xhr, settings) { ajax_beforeSend_std(evt, xhr, settings) });
47
+ linkElement.bind('ajax:beforeSend', function (evt, xhr, settings) {
48
+ ajax_beforeSend_std(evt, xhr, settings)
49
+ });
48
50
  linkElement.bind('ajax:success', function (evt, data, status, xhr) {
49
51
  ajax_success_std(evt, data, status, xhr, ["list"]);
50
52
  set_anchors_to_alu_items();
@@ -52,7 +54,7 @@ function formatLinkForPagination(container_class) {
52
54
 
53
55
  }
54
56
  );
55
- linkElement.bind('ajax:error', function(evt, xhr, status, error) {
57
+ linkElement.bind('ajax:error', function (evt, xhr, status, error) {
56
58
  ajax_error_std(evt, xhr, status, error);
57
59
  $('#spinner').hide();
58
60
  });
@@ -93,17 +95,63 @@ function formatLinkForPagination(container_class) {
93
95
 
94
96
  function filter_sort(form_id, order_by_value, dir, obj) {
95
97
  var order_by_id = '#' + form_id + '_order_by';
96
- var order_by_direction_id = '#' + form_id + '_order_by_direction';
98
+ var default_order_by_val = $('#' + form_id + '_default_order_by').val();
99
+
100
+ var order_by_array = $(order_by_id).val().split(",");
101
+ //console.log(order_by_value)
102
+ //console.log(dir)
103
+ //console.log(order_by_array);
97
104
 
98
- $(order_by_id).val(order_by_value);
99
- $(order_by_direction_id).val(dir);
105
+ if (order_by_array.indexOf(order_by_value + " " + dir) >= 0) { // the value is already there, if I click on it again I want to cancel the sorting by this value
106
+ //console.log("mazu");
107
+ var index = order_by_array.indexOf(order_by_value + " " + dir);
108
+ order_by_array.splice(index, 1);
109
+ if (order_by_array.length <= 0) {
110
+ // the ordering is empty I will fill it with default
111
+ order_by_array.push(default_order_by_val);
112
+ }
113
+ //console.log(order_by_array);
114
+ }
115
+ else if ((dir == "DESC" && order_by_array.indexOf(order_by_value + " ASC") >= 0) || (dir == "ASC" && order_by_array.indexOf(order_by_value + " DESC") >= 0)) {
116
+ // there is other variant of the column DESC or ASC, I will swith it to the other variant
117
+ //console.log("menim dir");
118
+ if (dir == "DESC") {
119
+ var index = order_by_array.indexOf(order_by_value + " ASC");
120
+ order_by_array[index] = order_by_value + " DESC";
121
+ }
122
+ else {
123
+ var index = order_by_array.indexOf(order_by_value + " DESC");
124
+ order_by_array[index] = order_by_value + " ASC";
125
+ }
126
+ //console.log(order_by_array);
127
+ }
128
+ else { // i am not ordering by this value, I will append it to end
129
+ //console.log("pridavam");
130
+ order_by_array.push(order_by_value + " " + dir);
131
+ //console.log(order_by_array);
132
+ }
100
133
 
101
- $("#" + form_id + " .sort_button").each(function() {
134
+ $("#" + form_id + " .sort_button").each(function () {
102
135
  $(this).removeClass("active");
103
136
  $(this).addClass("inactive"); // give all disabled class
104
137
  });
105
- $(obj).removeClass("inactive"); // remove disabled from this one
106
- $(obj).addClass("active");
138
+
139
+ var new_order_by_val = "";
140
+ $.each(order_by_array, function (i, item) {
141
+ if (new_order_by_val != "") {
142
+ new_order_by_val += ",";
143
+ }
144
+ //console.log(item);
145
+ new_order_by_val += item;
146
+
147
+ var order_by_button_id = "#" + item.replace(" ", "___").replace(".", "___");
148
+ $(order_by_button_id).removeClass("inactive");
149
+ $(order_by_button_id).addClass("active");
150
+ });
151
+ //console.log(new_order_by_val);
152
+
153
+ $(order_by_id).val(new_order_by_val);
154
+
107
155
 
108
156
  $('#' + form_id).submit();
109
157
  return false;
@@ -5,8 +5,9 @@
5
5
  <%#= submit_tag "Filter",{:class => 'button'} %>
6
6
  </fieldset>
7
7
 
8
- <%= hidden_field_tag :order_by, settings[:default][:order_by], :id => settings[:form_id] + '_order_by' %>
9
- <%= hidden_field_tag :order_by_direction, settings[:default][:order_by_direction], :id => settings[:form_id] + '_order_by_direction' %>
8
+ <%= hidden_field_tag :default_order_by, settings[:default][:order].blank? ? settings[:default][:order_by] + " " + settings[:default][:order_by_direction] : settings[:default][:order], :id => settings[:form_id] + '_default_order_by' %>
9
+ <%= hidden_field_tag :order_by, settings[:params][:order_by], :id => settings[:form_id] + '_order_by' %>
10
+ <%#= hidden_field_tag :order_by_direction, settings[:default][:order_by_direction], :id => settings[:form_id] + '_order_by_direction' %>
10
11
  <%= hidden_field_tag :page, settings[:default][:page], :id => settings[:form_id] + '_page' %>
11
12
 
12
13
  <%# end %>
@@ -9,7 +9,10 @@
9
9
  <% if !settings[:row].blank? && !settings[:row][:functions].blank? %>
10
10
  <th></th>
11
11
  <% end %>
12
+ <% order_by_arr = settings[:params][:order_by].split(",") %>
12
13
  <% settings[:columns].each do |col| %>
14
+ <% order_asc_id = (col[:table] + "___" + col[:name] + "___ASC") %>
15
+ <% order_desc_id = (col[:table] + "___" + col[:name] + "___DESC") %>
13
16
  <th class="<%= col[:class] %>">
14
17
  <div class="th_label">
15
18
  <span><%= col[:label].html_safe %></span>
@@ -21,39 +24,41 @@
21
24
 
22
25
  <span onclick="filter_sort('<%= settings[:form_id] %>','<%= col[:table] + "." +col[:name] %>', 'ASC', this); return false;"
23
26
  title="Seřadit vzestupně"
24
- class="icon-arrow-up sort_button sort-up <%= (settings[:params][:order_by] == (col[:table] + "." + col[:name]) && settings[:params][:order_by_direction]=="ASC") ? "active" : "inactive" %>">
27
+ class="icon-arrow-up sort_button sort-up <%= (order_by_arr.include?(col[:table] + "." + col[:name] + " ASC")) ? "active" : "inactive" %>"
28
+ id="<%= order_asc_id %>">
25
29
  <span class="oos"></span></span>
26
30
  <span onclick="filter_sort('<%= settings[:form_id] %>','<%= col[:table] + "." +col[:name] %>', 'DESC', this); return false;"
27
31
  title="Seřadit sestupně"
28
- class="icon-arrow-down sort_button sort-down <%= (settings[:params][:order_by] == (col[:table] + "." + col[:name]) && settings[:params][:order_by_direction]=="DESC") ? "active" : "inactive" %>">
32
+ class="icon-arrow-down sort_button sort-down <%= (order_by_arr.include?(col[:table] + "." + col[:name] + " DESC")) ? "active" : "inactive" %>"
33
+ id="<%= order_desc_id %>">
29
34
  <span class="oos "></span></span>
30
35
  <% end %>
31
- <% case col[:filter] %>
36
+ <% case col[:filter] %>
32
37
  <% when :find %>
33
38
  <% saved_param = (!settings[:params].blank? && !settings[:params]['find'].blank? && !settings[:params]['find']["#{col[:table]}.#{col[:name]}"].blank?) ? settings[:params]['find']["#{col[:table]}.#{col[:name]}"] : "" %>
34
- <span><%= text_field_tag "find[#{col[:table]}.#{col[:name]}]", saved_param,
35
- {:class => "input-small text #{settings[:form_id] + '_column_find'}"} %>
39
+ <span><%= text_field_tag "find[#{col[:table]}.#{col[:name]}]", saved_param,
40
+ {:class => "input-small text #{settings[:form_id] + '_column_find'}"} %>
36
41
  </span>
37
42
  <% when :multichoice %>
38
43
  <% saved_param = (!settings[:params].blank? && !settings[:params]['multichoice'].blank? && !settings[:params]['multichoice']["#{col[:table]}.#{col[:name]}"].blank?) ? settings[:params]['multichoice']["#{col[:table]}.#{col[:name]}"] : [] %>
39
- <span><%= select_tag("multichoice[#{col[:table]}.#{col[:name]}]", options_for_select(col[:filter_data], saved_param),
40
- :onchange => "form_submit_watcher('#{settings[:form_id]}')",
41
- :multiple => true,
42
- :class => "multiselect_class") %></span>
44
+ <span><%= select_tag("multichoice[#{col[:table]}.#{col[:name]}]", options_for_select(col[:filter_data], saved_param),
45
+ :onchange => "form_submit_watcher('#{settings[:form_id]}')",
46
+ :multiple => true,
47
+ :class => "multiselect_class") %></span>
43
48
  <% when :date %>
44
49
  <% saved_param = (!settings[:params].blank? && !settings[:params]['date_from'].blank? && !settings[:params]['date_from']["#{col[:table]}.#{col[:name]}"].blank?) ? settings[:params]['date_from']["#{col[:table]}.#{col[:name]}"] : "" %>
45
- <%#= label_tag "date_from[#{col[:table]}.#{col[:name]}]", "Od", :class => "datetime_class_label" %>
46
- <%= text_field_tag "date_from[#{col[:table]}.#{col[:name]}]", saved_param, {:class => "datetime_class input-small",
50
+ <%#= label_tag "date_from[#{col[:table]}.#{col[:name]}]", "Od", :class => "datetime_class_label" %>
51
+ <%= text_field_tag "date_from[#{col[:table]}.#{col[:name]}]", saved_param, {:class => "datetime_class input-small",
52
+ :onchange => "form_submit_watcher('#{settings[:form_id]}')",
53
+ :title => "Datum od"} %>
54
+ <% saved_param = (!settings[:params].blank? && !settings[:params]['date_to'].blank? && !settings[:params]['date_to']["#{col[:table]}.#{col[:name]}"].blank?) ? settings[:params]['date_to']["#{col[:table]}.#{col[:name]}"] : "" %>
55
+ <%#= label_tag "date_to[#{col[:table]}.#{col[:name]}]", "Do", :class => "datetime_class_label" %>
56
+ <%= text_field_tag "date_to[#{col[:table]}.#{col[:name]}]", saved_param, {:class => "datetime_class input-small",
47
57
  :onchange => "form_submit_watcher('#{settings[:form_id]}')",
48
- :title => "Datum od"} %>
49
- <% saved_param = (!settings[:params].blank? && !settings[:params]['date_to'].blank? && !settings[:params]['date_to']["#{col[:table]}.#{col[:name]}"].blank?) ? settings[:params]['date_to']["#{col[:table]}.#{col[:name]}"] : "" %>
50
- <%#= label_tag "date_to[#{col[:table]}.#{col[:name]}]", "Do", :class => "datetime_class_label" %>
51
- <%= text_field_tag "date_to[#{col[:table]}.#{col[:name]}]", saved_param, {:class => "datetime_class input-small",
52
- :onchange => "form_submit_watcher('#{settings[:form_id]}')",
53
- :title => "Datum do"} %>
54
- <span></span>
58
+ :title => "Datum do"} %>
59
+ <span></span>
55
60
  <% else %>
56
- <% end %>
61
+ <% end %>
57
62
  </span>
58
63
  </div>
59
64
  </th>
@@ -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.2.10"
8
+ s.version = "0.2.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ladas"]
@@ -6,7 +6,11 @@ module ControllerMixins
6
6
  class_obj = data.respond_to?(:klass) ? data.klass : data
7
7
  if action_name == "filter"
8
8
  default_params = params
9
- default_params = @settings[:default] if !params.blank? && params["clear"]
9
+ if !params.blank? && params["clear"]
10
+ default_params = @settings[:default].dup
11
+ default_params[:order_by] = @settings[:default][:order_by] + " " + @settings[:default][:order_by_direction] if !@settings[:default][:order_by].blank? && !@settings[:default][:order_by_direction].blank?
12
+ default_params[:order_by] = @settings[:default][:order] if !@settings[:default][:order].blank?
13
+ end
10
14
 
11
15
  @settings = class_obj.prepare_settings(logged_user, data, @settings, default_params)
12
16
  if !params.blank? && params["clear"]
@@ -2,10 +2,15 @@ module ModelMixins
2
2
  module TableBuilderClassMethods
3
3
  def prepare_settings(logged_user, object, settings, params, per_page = 10)
4
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?
5
+ params[:order_by] = settings[:default][:order_by] + " " + settings[:default][:order_by_direction] if params[:order_by].blank? && !settings[:default][:order_by].blank? && !settings[:default][:order_by_direction].blank?
6
+
7
+ params[:order_by] = settings[:default][:order] if params[:order_by].blank? && !settings[:default][:order].blank?
8
+
9
+
7
10
  params[:per_page] = per_page
8
11
 
12
+ # method below can change this if there were some virtual non exixtent columns
13
+ params[:real_order_by] = params[:order_by]
9
14
  check_non_existing_colum_order_by(settings, params)
10
15
 
11
16
  not_selected_items = object.filter(settings, params, per_page)
@@ -147,7 +152,7 @@ module ModelMixins
147
152
  end
148
153
 
149
154
  def filter(settings, params, per_page = 10)
150
- order_by = params[:order_by] +' '+ params[:order_by_direction]
155
+ order_by = params[:real_order_by]
151
156
 
152
157
  cond_str = ""
153
158
  cond_hash = {}
@@ -239,19 +244,24 @@ module ModelMixins
239
244
 
240
245
 
241
246
  def check_non_existing_colum_order_by(settings, params)
242
- if params[:order_by].match(/^.*?non_existing_column___.*$/i)
243
- identifier = params[:order_by].split("non_existing_column___").second
244
- settings[:columns].each do |col|
245
- if !col[:select_as].blank? && !col[:format_method].blank? && col[:format_method] == identifier
246
- params[:order_by] = col[:order_by].gsub(",", " #{params[:order_by_direction]} ,")
247
- else
248
- ""
247
+ order_by_arr = params[:order_by].split(",")
248
+ order_by_arr.each_with_index do |one_order_by, index|
249
+ if one_order_by.match(/^.*?non_existing_column___.*$/i)
250
+ identifier_and_direction = one_order_by.split("non_existing_column___").second
251
+ identifier = identifier_and_direction.split(" ").first
252
+ order_by_direction = identifier_and_direction.split(" ").second
253
+ settings[:columns].each do |col|
254
+ if !col[:select_as].blank? && !col[:format_method].blank? && col[:format_method] == identifier
255
+ order_by_arr[index] = col[:order_by].gsub(",", " #{order_by_direction} ,") + " #{order_by_direction}"
256
+ else
257
+ ""
258
+ end
249
259
  end
260
+ else
261
+ ""
250
262
  end
251
- else
252
-
253
263
  end
254
-
264
+ params[:real_order_by] = order_by_arr*","
255
265
  end
256
266
  end
257
267
  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.2.10
4
+ version: 0.2.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: htmlentities
16
- requirement: &72065910 !ruby/object:Gem::Requirement
16
+ requirement: &83291580 !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: :runtime
23
23
  prerelease: false
24
- version_requirements: *72065910
24
+ version_requirements: *83291580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &72065660 !ruby/object:Gem::Requirement
27
+ requirement: &83291330 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *72065660
35
+ version_requirements: *83291330
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &72065350 !ruby/object:Gem::Requirement
38
+ requirement: &83291020 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.12'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *72065350
46
+ version_requirements: *83291020
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &72065060 !ruby/object:Gem::Requirement
49
+ requirement: &83290750 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.1.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *72065060
57
+ version_requirements: *83290750
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &72064800 !ruby/object:Gem::Requirement
60
+ requirement: &83290480 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.8.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *72064800
68
+ version_requirements: *83290480
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &72064550 !ruby/object:Gem::Requirement
71
+ requirement: &83290230 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *72064550
79
+ version_requirements: *83290230
80
80
  description: longer description of your gem
81
81
  email: ladislav.smola@it-logica.cz
82
82
  executables: []
@@ -560,7 +560,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
560
560
  version: '0'
561
561
  segments:
562
562
  - 0
563
- hash: 700838909
563
+ hash: -428679615
564
564
  required_rubygems_version: !ruby/object:Gem::Requirement
565
565
  none: false
566
566
  requirements: