zutils 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64a2ebbb9e87c1305e9b3983fc7ee644e06d86df468aa1facd3b5f6129d4a7df
4
- data.tar.gz: 5b461925540c49b78ca1ea2309c38f95036bcd3b0c4370b3271cd8cdc70c8805
3
+ metadata.gz: ba4c33f9ee3a6cb1d3fe38ae66444b74316565e35077166c1637356ec6a0af12
4
+ data.tar.gz: 07d346dfbcfbf646ba7734615910106ab1b1c3ffafc8b18261ab839971a24e94
5
5
  SHA512:
6
- metadata.gz: d7ce40487cf3664f224f118481bfbd982febe1cf711e8fbaf3078669e2b6422a04efc59bc83b3f90b910b2db63033a51e10e145851be7b7bc37440b9f6a432c0
7
- data.tar.gz: 1d489306f34a3146dfbedad2acdb523d8424bd8311b76db93b67271f4dbc62302ecb61efddf1c7684cfd5b17c2760449818489ba3e4faac012096f78ca47991e
6
+ metadata.gz: 0f501a7638548dbe39f9ffb37eecc4067491da65a18dacb633b5d1cafcd9b534bdeed749abcee1327ce83f27ff6fda90f454fa44989934381baab55a1a794145
7
+ data.tar.gz: a14a48a120b6dfc03d48acb32c34bc86d09f818d21a59c7ccfe33da92beb6d9dbd51cf10539faa46e69ec2780fd4f2dfc6a6756528063f5c1461cd061ae64434
@@ -0,0 +1,64 @@
1
+ //= require selectize
2
+
3
+ $(document).ready(function () {
4
+ var selectizeCallback = null;
5
+
6
+ $(".selectize_with_add").each(function(i, item) {
7
+ $(item).selectize({
8
+ create: function(input, callback) {
9
+ selectizeCallback = callback;
10
+
11
+ $("." + $(item).data('model') + "-modal").modal();
12
+ $("#" + $(item).data('model') + "_name").val(input);
13
+ }
14
+ });
15
+
16
+ $("." + $(item).data('model') + "-modal").on("hide.bs.modal", function(e) {
17
+ if (selectizeCallback != null) {
18
+ selectizeCallback();
19
+ selecitzeCallback = null;
20
+ }
21
+
22
+ $("#new_" + $(item).data('model') + "").trigger("reset");
23
+ $("#new_" + $(item).data('model') + " select").val(null).trigger('change');
24
+ $.rails.enableFormElements($("#new_" + $(item).data('model') + ""));
25
+ });
26
+
27
+ $("#new_" + $(item).data('model')).on("submit", function(e) {
28
+ e.preventDefault();
29
+ $.ajax({
30
+ method: "POST",
31
+ dataType: "json",
32
+ url: $(this).attr("action"),
33
+ data: $(this).serialize(),
34
+ success: function(response) {
35
+ selectizeCallback({value: response.id, text: response.name});
36
+ selectizeCallback = null;
37
+
38
+ $("." + $(item).data('model') + "-modal").modal('toggle');
39
+ }
40
+ });
41
+ });
42
+ });
43
+
44
+ $(".selectize_with_add_without_modal").each(function(i, item) {
45
+ $(item).selectize({
46
+ create: function(input, callback) {
47
+ selectizeCallback = callback;
48
+ data = {};
49
+ data[$(item).data('model')] = {};
50
+ data[$(item).data('model')][$(item).data('field')] = input;
51
+ $.ajax({
52
+ method: "POST",
53
+ dataType: "json",
54
+ url: "/" + $(item).data('pluralized'),
55
+ data: data,
56
+ success: function(response) {
57
+ selectizeCallback({value: response.id, text: response.name});
58
+ }
59
+ });
60
+ selectizeCallback = callback;
61
+ }
62
+ });
63
+ });
64
+ });
@@ -0,0 +1,2 @@
1
+ @import 'selectize';
2
+ @import 'selectize.bootstrap3';
@@ -1,3 +1,5 @@
1
+ <% additional_actions ||= {} %>
2
+
1
3
  <div class="btn-group">
2
4
  <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
3
5
  Ações
@@ -5,26 +7,43 @@
5
7
  <span class="sr-only">Toggle Dropdown</span>
6
8
  </button>
7
9
  <ul class="dropdown-menu" role="menu">
8
- <li>
9
- <%= link_to object, data: { toggle: 'tooltip', placement: 'top', title: 'Visualizar' } do %>
10
- <i class="fa fa-eye"></i> Visualizar
11
- <% end %>
10
+ <% if can? :read, object.class %>
11
+ <li>
12
+ <%= link_to object, data: { toggle: 'tooltip', placement: 'top', title: 'Visualizar' } do %>
13
+ <i class="fa fa-eye"></i> Visualizar
14
+ <% end %>
15
+ <% end %>
12
16
  </li>
13
- <li>
14
- <% if object.class == Array %>
15
- <%= link_to eval_with_rescue("edit_#{[object].flatten.map{|x| x.class.to_s.underscore}.join("_")}_path(#{object[0].id}, #{object[1].id})"), data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %>
16
- <i class="fa fa-pencil"></i> Editar
17
+ <% if can? :edit, object.class %>
18
+ <li>
19
+ <% if object.class == Array %>
20
+ <%= link_to eval_with_rescue("edit_#{[object].flatten.map{|x| x.class.to_s.underscore}.join("_")}_path(#{object[0].id}, #{object[1].id})"), data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %>
21
+ <i class="fa fa-pencil"></i> Editar
22
+ <% end %>
23
+ <% else %>
24
+ <%= link_to eval_with_rescue("edit_#{[object].flatten.map{|x| x.class.to_s.underscore}.join("_")}_path(#{object.id})"), data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %>
25
+ <i class="fa fa-pencil"></i> Editar
26
+ <% end %>
17
27
  <% end %>
18
- <% else %>
19
- <%= link_to eval_with_rescue("edit_#{[object].flatten.map{|x| x.class.to_s.underscore}.join("_")}_path(#{object.id})"), data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %>
20
- <i class="fa fa-pencil"></i> Editar
28
+ </li>
29
+ <% end %>
30
+ <% if can? :destroy, object.class %>
31
+ <li>
32
+ <%= link_to object, method: :delete, data: { confirm: 'Tem certeza?', toggle: 'tooltip', placement: 'top', title: 'Apagar' } do %>
33
+ <i class="fa fa-trash"></i> Apagar
34
+ <% end %>
35
+ </li>
36
+ <% end %>
37
+ <% unless additional_actions.empty? %>
38
+ <% additional_actions.each do |key, value| %>
39
+ <% if can? key, object.class %>
40
+ <li>
41
+ <%= link_to eval_with_rescue("#{value[:link]}(#{object.id})"), value[:options] do %>
42
+ <i class="fa fa-<%= value[:icon] %>"></i> <%= value[:title] %>
43
+ <% end %>
44
+ </li>
21
45
  <% end %>
22
46
  <% end %>
23
- </li>
24
- <li>
25
- <%= link_to object, method: :delete, data: { confirm: 'Tem certeza?', toggle: 'tooltip', placement: 'top', title: 'Apagar' } do %>
26
- <i class="fa fa-trash"></i> Apagar
27
- <% end %>
28
- </li>
47
+ <% end %>
29
48
  </ul>
30
49
  </div>
@@ -1,14 +1,16 @@
1
- <% exceptions ||= ['id', 'created_at', 'updated_at', 'deleted_at'] %>
1
+ <% exceptions ||= ['created_at', 'updated_at', 'deleted_at'] %>
2
2
  <% search_fields ||= [] %>
3
3
  <% sort_fields ||= [] %>
4
+ <% sort_all ||= false %>
4
5
  <% nested_resource ||= false %>
5
6
  <% excluded_columns ||= [] %>
7
+ <% additional_columns ||= [] %>
6
8
  <% box_class ||= 'primary' %>
7
9
 
8
10
  <div class='box box-<%= box_class %>'>
9
11
  <div class="box-header with-border">
10
12
  <h3 class="box-title">
11
- <%= Kernel.const_get(controller_name.singularize.camelize).model_name.human.pluralize %>
13
+ <%=t Kernel.const_get(controller_name.singularize.camelize).model_name.human.pluralize %>
12
14
  </h3>
13
15
  </div>
14
16
  <div class="box-body">
@@ -23,7 +25,6 @@
23
25
  </div>
24
26
  <% end %>
25
27
  </div>
26
- <hr>
27
28
  <% end %>
28
29
  <% if list.empty? %>
29
30
  <table class="table table-striped datatables">
@@ -34,7 +35,8 @@
34
35
  </tbody>
35
36
  </table>
36
37
  <% else %>
37
- <%= render 'shared/list', list: list, exceptions: exceptions, excluded_columns: excluded_columns, sort_fields: sort_fields %>
38
+ <%= render 'shared/list', list: list, exceptions: exceptions, excluded_columns: excluded_columns,
39
+ additional_columns: additional_columns, sort_fields: sort_fields, sort_all: sort_all %>
38
40
  <% if defined? list.total_pages %>
39
41
  <div class='col-md-4'>
40
42
  <%= page_entries_info list, entry_name: 'resultado(s)' %>
@@ -49,8 +51,8 @@
49
51
  <% end %>
50
52
  </div>
51
53
 
52
- <div class="box-footer">
53
- <% unless controller_name == 'users' %>
54
+ <% unless controller_name == 'users' %>
55
+ <div class="box-footer">
54
56
  <% if can? :new, controller_name.singularize %>
55
57
  <% if nested_resource == true %>
56
58
  <% if parent_resource %>
@@ -64,7 +66,7 @@
64
66
  <% end %>
65
67
  <% end %>
66
68
  <% end %>
67
- <% end %>
68
- </div>
69
+ </div>
70
+ <% end %>
69
71
 
70
72
  </div>
@@ -1,61 +1,69 @@
1
- <% exceptions ||= ['id', 'created_at', 'updated_at', 'deleted_at'] %>
1
+ <% exceptions ||= ['created_at', 'updated_at', 'deleted_at'] %>
2
2
  <% excluded_columns ||= [] %>
3
+ <% additional_columns ||= [] %>
3
4
  <% hide_actions ||= false %>
4
5
  <% sort_fields ||= [] %>
6
+ <% sort_all ||= false %>
5
7
 
6
- <% unless list.empty? %>
7
- <% form_fields ||= (list.first.class.respond_to?('form_fields') ? list.first.class.form_fields : {}) %>
8
- <% form_ordered_fields ||= (form_fields.empty? ? list.first.class.column_names : form_fields.keys) %>
9
-
10
- <table class="table table-striped datatables">
11
- <thead>
12
- <tr>
13
- <% unless list.empty? %>
14
- <% (form_ordered_fields - exceptions - excluded_columns).each do |column| %>
15
- <% if sort_fields.include?(column) || sort_fields.include?(column.to_s) || sort_fields.include?(column.to_sym) %>
16
- <% if /_id$/ =~ column %>
17
- <th><%= sort_link(@q, column, list.first.class.human_attribute_name(column.split("_id")[0])) %></th>
18
- <% else %>
19
- <th><%= sort_link(@q, column, list.first.class.human_attribute_name(column)) %></th>
20
- <% end %>
8
+ <table class="table table-striped datatables">
9
+ <thead>
10
+ <tr>
11
+ <% unless list.empty? %>
12
+ <% (list.first.class.column_names - exceptions - excluded_columns + additional_columns).each do |column| %>
13
+ <% if sort_all || sort_fields.include?(column) %>
14
+ <% if /_id$/ =~ column %>
15
+ <th><%= sort_link(@q, column, list.first.class.human_attribute_name(column.split("_id")[0])) %></th>
16
+ <% elsif /_cents$/ =~ column %>
17
+ <th><%= sort_link(@q, column, list.first.class.human_attribute_name(column.split("_cents")[0])) %></th>
18
+ <% elsif /_currency$/ =~ column %>
21
19
  <% else %>
22
- <% if /_id$/ =~ column %>
23
- <th><%= list.first.class.human_attribute_name(column.split("_id")[0]) %></th>
24
- <% else %>
25
- <th><%= list.first.class.human_attribute_name(column) %></th>
26
- <% end %>
20
+ <th><%= sort_link(@q, column, list.first.class.human_attribute_name(column)) %></th>
27
21
  <% end %>
28
- <% end %>
29
- <% unless hide_actions %>
30
- <th>Ações</th>
31
- <% end %>
32
- <% end %>
33
- </tr>
34
- </thead>
35
- <tbody>
36
- <% list.each do |object| %>
37
- <tr>
38
- <% (form_ordered_fields - exceptions - excluded_columns).each do |column| %>
39
- <td>
40
- <% if object.send(column).class == Date or
41
- object.send(column).class == DateTime or
42
- object.send(column).class == ActiveSupport::TimeWithZone or
43
- object.send(column).class == Time %>
44
- <%=l object.send(column) %>
45
- <% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
46
- <%= object.send(column.split("_id")[0])&.name %>
47
22
  <% else %>
48
- <%= object.send(column) %>
23
+ <% if /_id$/ =~ column %>
24
+ <th><%= list.first.class.human_attribute_name(column.split("_id")[0]) %></th>
25
+ <% elsif /_cents$/ =~ column %>
26
+ <th><%= list.first.class.human_attribute_name(column.split("_cents")[0]) %></th>
27
+ <% elsif /_currency$/ =~ column %>
28
+ <% else %>
29
+ <th><%= list.first.class.human_attribute_name(column) %></th>
30
+ <% end %>
49
31
  <% end %>
50
- </td>
51
32
  <% end %>
52
33
  <% unless hide_actions %>
53
- <td>
54
- <%= render 'shared/action_links', object: object %>
55
- </td>
34
+ <th>Ações</th>
35
+ <% end %>
36
+ <% end %>
37
+ </tr>
38
+ </thead>
39
+ <tbody>
40
+ <% list.each do |object| %>
41
+ <tr>
42
+ <% (list.first.class.column_names - exceptions - excluded_columns + additional_columns).each do |column| %>
43
+ <% next if /_currency$/ =~ column %>
44
+ <td>
45
+ <% if object.send(column).class == Date or
46
+ object.send(column).class == DateTime or
47
+ object.send(column).class == ActiveSupport::TimeWithZone or
48
+ object.send(column).class == Time %>
49
+ <%=l object.send(column) %>
50
+ <% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
51
+ <%= object.send(column.split("_id")[0])&.name %>
52
+ <% elsif /_cents$/ =~ column %>
53
+ <%= number_to_currency object.send(column.split("_cents")[0]) %>
54
+ <% elsif column == 'id' %>
55
+ <%= link_to object.id, object %>
56
+ <% else %>
57
+ <%= object.send(column) %>
56
58
  <% end %>
57
- </tr>
59
+ </td>
60
+ <% end %>
61
+ <% unless hide_actions %>
62
+ <td>
63
+ <%= render 'shared/action_links', object: object %>
64
+ </td>
58
65
  <% end %>
59
- </tbody>
60
- </table>
61
- <% end %>
66
+ </tr>
67
+ <% end %>
68
+ </tbody>
69
+ </table>
@@ -0,0 +1,21 @@
1
+ <div class="modal fade in <%= model.name.underscore %>-modal" id="modal-default">
2
+ <div class="modal-dialog">
3
+ <div class="modal-content">
4
+ <div class="modal-header">
5
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
6
+ <span aria-hidden="true">×</span></button>
7
+ <h4 class="modal-title"><%=t "helpers.links.new" %> <%= model.model_name.human %></h4>
8
+ </div>
9
+ <%= simple_form_for model.new do |f| %>
10
+ <div class="modal-body">
11
+ <%= render "#{model.name.underscore.pluralize}/fields", f: f %>
12
+ </div>
13
+ <div class="modal-footer">
14
+ <%= f.submit class: "btn btn-primary" %>
15
+ </div>
16
+ <% end %>
17
+ </div>
18
+ <!-- /.modal-content -->
19
+ </div>
20
+ <!-- /.modal-dialog -->
21
+ </div>
@@ -3,7 +3,6 @@
3
3
  <% relationships ||= {} %>
4
4
  <% box_class ||= 'primary' %>
5
5
  <% display_mode ||= 'table' %>
6
- <% show_buttons ||= true %>
7
6
 
8
7
  <% form_fields ||= (object.class.respond_to?('form_fields') ? object.class.form_fields : {}) %>
9
8
  <% form_ordered_fields ||= (form_fields.empty? ? object.class.column_names : form_fields.keys) %>
@@ -11,18 +10,21 @@
11
10
  <div class="box box-<%= box_class %>">
12
11
  <div class="box-header with-border">
13
12
  <h3 class="box-title"><%= object.class.model_name.human %></h3>
14
- <% if show_buttons %>
15
- <% if can? :edit, object %> <!--verificando se o usuario esta logado-->
16
- <%= link_to eval_with_rescue("edit_#{controller_name.singularize}_path(#{object.id})"), class: "btn btn-warning btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %>
17
- <i class="fa fa-pencil"></i> Editar
18
- <% end %>
13
+ <% if can? :edit, object %> <!--verificando se o usuario esta logado-->
14
+ <%= link_to eval_with_rescue("new_#{controller_name.singularize}_path"), class: "btn btn-#{box_class} btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Cadastrar' } do %>
15
+ <i class="fa fa-plus"></i> Cadastrar
19
16
  <% end %>
20
- <% if nested_resource %>
21
- <%= link_to 'Listagem', eval_with_rescue("#{parent_resource.class.model_name.to_s.downcase}_#{controller_name}_path(#{parent_resource.id})"), class: "btn btn-default btn-xs" %>
22
- <% else %>
23
- <%= link_to 'Listagem', eval_with_rescue("#{controller_name}_path"), class: "btn btn-default btn-xs" %>
17
+ <% end %>
18
+ <% if can? :edit, object %> <!--verificando se o usuario esta logado-->
19
+ <%= link_to eval_with_rescue("edit_#{controller_name.singularize}_path(#{object.id})"), class: "btn btn-warning btn-xs", data: { toggle: 'tooltip', placement: 'top', title: 'Editar' } do %>
20
+ <i class="fa fa-pencil"></i> Editar
24
21
  <% end %>
25
22
  <% end %>
23
+ <% if nested_resource %>
24
+ <%= link_to 'Listagem', eval_with_rescue("#{parent_resource.class.model_name.to_s.downcase}_#{controller_name}_path(#{parent_resource.id})"), class: "btn btn-default btn-xs" %>
25
+ <% else %>
26
+ <%= link_to 'Listagem', eval_with_rescue("#{controller_name}_path"), class: "btn btn-default btn-xs" %>
27
+ <% end %>
26
28
  </div>
27
29
  <div class="box-body <%= 'no-padding' if display_mode == 'table' %>">
28
30
  <% if display_mode == 'dt' %>
@@ -93,7 +95,7 @@
93
95
  <div class="box box-<%= box_class %>">
94
96
  <div class="box-header with-border">
95
97
  <h3 class="box-title">
96
- <%=t Kernel.const_get(key.to_s.singularize.camelize).model_name.human.pluralize %>
98
+ <%= Kernel.const_get(key.to_s.singularize.camelize).model_name.human.pluralize %>
97
99
  </h3>
98
100
  </div>
99
101
  <div class="box-body no-padding">
@@ -1,3 +1,3 @@
1
1
  module Zutils
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ricardo Viana
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-07 00:00:00.000000000 Z
11
+ date: 2019-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -65,10 +65,13 @@ files:
65
65
  - LICENSE.txt
66
66
  - README.md
67
67
  - Rakefile
68
+ - app/assets/javascripts/zutils.js
69
+ - app/assets/stylesheets/zutils.scss
68
70
  - app/views/shared/_action_links.html.erb
69
71
  - app/views/shared/_form.html.erb
70
72
  - app/views/shared/_index.html.erb
71
73
  - app/views/shared/_list.html.erb
74
+ - app/views/shared/_modal.html.erb
72
75
  - app/views/shared/_show.html.erb
73
76
  - bin/console
74
77
  - bin/setup