ct_table_for 0.1.12.beta → 0.1.13.beta

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2a7d0d6484646061c28ff85ae59ad56509c564d
4
- data.tar.gz: 34e0bc8965f42d14261eceeb1f4700b9fff485e6
3
+ metadata.gz: 2d919b7dfe484a4150f43f2a2679fafc718b80e1
4
+ data.tar.gz: 7b86f06ecafbca0bc9401aa6f29d50d2ee0e66f4
5
5
  SHA512:
6
- metadata.gz: 249d7282ad3527f3e7ba12a85a78f1f26ad657849235130d538d338d8ad94535ebc27620e8bc8abe3458fb18286525ee8c84580003a338f523481b839e4144ed
7
- data.tar.gz: bed34560a91d7dee7ecf5276e17fea7ea617537da3378eaac01de667e314b0120ed667038ddbc81860a75cd3a56f4ed63bd3cf5707b74847973537486a086e6f
6
+ metadata.gz: facae6310e063ca4d30b2c73beae3ad346e975f5d4f30bc87097a981e7952912d5271682212563100868fa4a18142ca25d006b8fb4f931283a65bf274fa526a5
7
+ data.tar.gz: 6a0321ab6e28ffad1abb2b67c69d944b2a582a859f7afe38d6ce46e0162fe0a19075e7fafc1e6e52a6cab37363a43b6be9b275022727fa886af858c5f9968592
data/README.md CHANGED
@@ -36,6 +36,12 @@ or in sass
36
36
  @import "table_for"
37
37
  ```
38
38
 
39
+ And require the necessary javascript in `application.js` if you are using the `clickable` row option (`jQuery` is required):
40
+
41
+ ```js
42
+ //= require table_for
43
+ ```
44
+
39
45
  ## Usage
40
46
 
41
47
  To get started, just use the `table_for_for` helper. Here's an example:
@@ -44,6 +50,22 @@ To get started, just use the `table_for_for` helper. Here's an example:
44
50
  <%= table_for Model, @collection %>
45
51
  ```
46
52
 
53
+ #### Clickable rows
54
+
55
+ To make rows clickable just add corresponding option to `table_for` helper:
56
+
57
+ ```erb
58
+ <%= table_for Model, @collection, options: { clickable: true } %>
59
+ ```
60
+
61
+ It builds a call to a named RESTful route for a given record from a collection.
62
+ Also, you can specify your own nested resources path by passing an `array` of symbols:
63
+
64
+ ```erb
65
+ <%= table_for Model, @collection, options: { clickable: [:bo, :admin] } %>
66
+ ```
67
+
68
+
47
69
  ### Customizing
48
70
 
49
71
  Create config variables in your app's /config/initializers/ct_table_for.rb
@@ -0,0 +1,20 @@
1
+ // Clickable table rows.
2
+ // Set the class 'table-clickable' in table and
3
+ // in tr set 'data-link' and (optional) 'data-target'
4
+ // in td set 'data-link-enabled' to false for disable in specicif cells
5
+ $('table.table-clickable').each(function(index, table){
6
+ $(table).find('tbody tr').each(function(index, trow){
7
+ $(trow).click(function(evnt){
8
+ var link = $(this).attr('data-link');
9
+ var linkTarget = $(this).attr('data-target');
10
+ var linkEnabled = true
11
+ if( $(evnt.target).attr('data-link-enabled') == 'false' ||
12
+ $(evnt.target).parents('td[data-link-enabled="false"]').length > 0 ){
13
+ linkEnabled= false
14
+ }
15
+
16
+ if( !linkTarget ){ linkTarget = '_self'; }
17
+ if( link && linkEnabled){ window.open(link, linkTarget); }
18
+ });
19
+ });
20
+ });
@@ -37,3 +37,13 @@ $table-for-breakpoint: <%= CtTableFor.table_for_breakpoint %> !default;
37
37
  }
38
38
  }
39
39
  }
40
+
41
+ // clickable options
42
+ .table-for.table-clickable {
43
+ tr[data-link] {
44
+ cursor: pointer;
45
+ td[data-link-enabled="false"] {
46
+ cursor: default;
47
+ }
48
+ }
49
+ }
@@ -18,13 +18,14 @@ module CtTableFor
18
18
  # id: "my-id", // String: adds custom id to <table> element
19
19
  # class: "my-custom-css", // String: add custom class to <table> element
20
20
  # tr_class: "my-custom-css" // String: add custom class to <tr> element
21
+ # clickable: true || Array // Boolean or Array of nested resources for polymorphic_url
21
22
  #}
22
23
  ####################################################################################
23
24
 
24
25
  def table_for model, collection, options: {}
25
26
  custom_id = options[:id].present? ? %Q{id="#{options[:id]}"} : ""
26
27
  html = %Q{<div class="table-for-wrapper #{CtTableFor.table_for_wrapper_default_class}">}
27
- html << %Q{<table #{custom_id} class="table-for #{CtTableFor.table_for_default_class} #{options[:class]}">}
28
+ html << %Q{<table #{custom_id} class="table-for #{CtTableFor.table_for_default_class} #{options[:class]} #{("table-clickable") if options[:clickable]}">}
28
29
  html << table_for_header(model, has_actions: options[:actions].present?, options: options)
29
30
  html << table_for_content(model, collection, options: options)
30
31
  html << %Q{</table>}
@@ -62,7 +63,7 @@ module CtTableFor
62
63
  if collection.present?
63
64
  custom_tr_class = options[:tr_class].present? ? %Q{class="#{options[:tr_class]}"} : ""
64
65
  collection.each do |record|
65
- html << %Q{<tr data-colection-id="#{record.try(:id)}" #{custom_tr_class}>}
66
+ html << %Q{<tr data-colection-id="#{record.try(:id)}" #{custom_tr_class} #{row_data_link(record, options)}>}
66
67
  table_for_attributes(model, options).each do |attribute|
67
68
  attribute, *params = attribute.split(":")
68
69
  html << table_for_cell( model, record, attribute, cell_options: params )
@@ -81,6 +82,16 @@ module CtTableFor
81
82
  html.html_safe
82
83
  end
83
84
 
85
+ def row_data_link(record, options)
86
+ return unless options[:clickable]
87
+ if options[:clickable].kind_of?(Array)
88
+ nested_resources = (options[:clickable] || []) + [record]
89
+ else
90
+ nested_resources = record
91
+ end
92
+ "data-link =" << polymorphic_url(nested_resources)
93
+ end
94
+
84
95
  def table_for_cell model, record, attribute, cell_options: {}
85
96
  html = ""
86
97
  value = record.try(attribute.to_sym)
@@ -125,8 +136,8 @@ module CtTableFor
125
136
  html << value.to_s
126
137
  else
127
138
  html << value.to_s.truncate(
128
- CtTableFor.table_for_truncate_length,
129
- separator: CtTableFor.table_for_truncate_separator,
139
+ CtTableFor.table_for_truncate_length,
140
+ separator: CtTableFor.table_for_truncate_separator,
130
141
  omission: CtTableFor.table_for_truncate_omission
131
142
  )
132
143
  end
@@ -143,7 +154,7 @@ module CtTableFor
143
154
  html << image_tag(record.send(attribute).url(size), class: CtTableFor.table_for_cell_for_image_image_class, style: "max-height: 100px;")
144
155
  html.html_safe
145
156
  end
146
-
157
+
147
158
  def table_for_cell_for_locale model, attribute, value, cell_options: {}
148
159
  html = model.human_attribute_name("#{attribute.underscore}.#{value.underscore}")
149
160
  end
@@ -152,7 +163,7 @@ module CtTableFor
152
163
  def table_for_actions(record, options: {} )
153
164
  return "" if options[:actions].blank?
154
165
  html = ""
155
- html << %Q{<td>}
166
+ html << %Q{<td data-link-enabled="false">}
156
167
  html << %Q{<div class="btn-group btn-group-sm" role="group" aria-label="#{I18n.t(:actions, scope: [:table_for]).capitalize}">}
157
168
  nesting = (options[:actions][:premodel] || []) + [record]
158
169
  buttons, *btn_options = options[:actions][:buttons].split(":")
@@ -1,3 +1,3 @@
1
1
  module CtTableFor
2
- VERSION = '0.1.12.beta'
2
+ VERSION = '0.1.13.beta'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ct_table_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12.beta
4
+ version: 0.1.13.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Agustí B.R.
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-07-05 00:00:00.000000000 Z
13
+ date: 2017-11-13 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -38,6 +38,7 @@ files:
38
38
  - LICENSE
39
39
  - README.md
40
40
  - Rakefile
41
+ - app/assets/javascripts/table_for.js
41
42
  - app/assets/stylesheets/table_for.scss.erb
42
43
  - app/helpers/ct_table_for/application_helper.rb
43
44
  - config/locales/ca.yml