zutils 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/zutils.js +22 -0
- data/app/views/shared/_fields.html.erb +31 -0
- data/app/views/shared/_form.html.erb +1 -25
- data/app/views/shared/_modal.html.erb +6 -4
- data/lib/zutils/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf846e9c312ebccb7cdbaef9c3c176c7e3d1dee47a79f080a95a6fdc8bfc6844
|
4
|
+
data.tar.gz: 99f5a3df431d93b9bc81ed1e7c8a3cd1d6395dffe4045e6716f7401a3a2c8b91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e0bd646795a8ac367228f3fc598e0a9b60c705b5fae90677d2d268493e45cf28caaed403c6904418d4a40f998e5879d788ff148ca5613f94baa6da2a41dd6f7
|
7
|
+
data.tar.gz: fb0f5bc28a532aebbf58bf4f7f12f354827dcb9b11d4bb6dbd8db9aa4f8c6dcdfbd230d6485d99a9268649eb35f785c71be745b683c987149a42339aecdc7959
|
@@ -26,6 +26,8 @@ $(document).ready(function () {
|
|
26
26
|
|
27
27
|
$("#new_" + $(item).data('model')).on("submit", function(e) {
|
28
28
|
e.preventDefault();
|
29
|
+
$("#new_" + $(item).data('model')).find('.has-error').removeClass('has-error');
|
30
|
+
$("#new_" + $(item).data('model')).find('.help-block').text("");
|
29
31
|
$.ajax({
|
30
32
|
method: "POST",
|
31
33
|
dataType: "json",
|
@@ -36,6 +38,16 @@ $(document).ready(function () {
|
|
36
38
|
selectizeCallback = null;
|
37
39
|
|
38
40
|
$("." + $(item).data('model') + "-modal").modal('toggle');
|
41
|
+
},
|
42
|
+
error: function(response) {
|
43
|
+
$.each(response.responseJSON, function(key, value) {
|
44
|
+
$("#new_" + $(item).data('model')).find("." + $(item).data('model') + '_' + key).addClass('has-error');
|
45
|
+
if (!($("#new_" + $(item).data('model') + " ." + $(item).data('model') + '_' + key).find('.help-block').length)) {
|
46
|
+
$("#new_" + $(item).data('model')).find("." + $(item).data('model') + '_' + key).append("<p class='help-block'></p>");
|
47
|
+
}
|
48
|
+
$("#new_" + $(item).data('model')).find("." + $(item).data('model') + '_' + key).find('.help-block').text(value);
|
49
|
+
});
|
50
|
+
$.rails.enableFormElements($("#new_" + $(item).data('model') + ""));
|
39
51
|
}
|
40
52
|
});
|
41
53
|
});
|
@@ -44,6 +56,8 @@ $(document).ready(function () {
|
|
44
56
|
$(".selectize_with_add_without_modal").each(function(i, item) {
|
45
57
|
$(item).selectize({
|
46
58
|
create: function(input, callback) {
|
59
|
+
$(item).parent().removeClass('has-error');
|
60
|
+
$(item).parent().find('.help-block').text("");
|
47
61
|
selectizeCallback = callback;
|
48
62
|
data = {};
|
49
63
|
data[$(item).data('model')] = {};
|
@@ -55,6 +69,14 @@ $(document).ready(function () {
|
|
55
69
|
data: data,
|
56
70
|
success: function(response) {
|
57
71
|
selectizeCallback({value: response.id, text: response.name});
|
72
|
+
},
|
73
|
+
error: function(response) {
|
74
|
+
$(item).parent().addClass('has-error');
|
75
|
+
if (!( $(item).parent().find('.help-block').length)) {
|
76
|
+
$(item).parent().append("<p class='help-block'></p>");
|
77
|
+
}
|
78
|
+
$(item).parent().find('.help-block').text("Valor já existente: " + input);
|
79
|
+
selectizeCallback();
|
58
80
|
}
|
59
81
|
});
|
60
82
|
selectizeCallback = callback;
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<% excluded_columns ||= [] %>
|
2
|
+
<% restricted_columns ||= {} %>
|
3
|
+
|
4
|
+
<% form_fields ||= (object.class.respond_to?('form_fields') ? object.class.form_fields : {}) %>
|
5
|
+
<% form_ordered_fields ||= (form_fields.empty? ? object.class.column_names : form_fields.keys) %>
|
6
|
+
|
7
|
+
<div class="row">
|
8
|
+
<% (form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns).each do |column| %>
|
9
|
+
<% wphtml = "col-md-#{(form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:size] : form_fields[column.to_sym] ) || 12}" %>
|
10
|
+
<% hint = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:hint] : '') %>
|
11
|
+
<% placeholder = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:placeholder] : '') %>
|
12
|
+
<% if object.class.column_for_attribute(column).type == :text %>
|
13
|
+
<%= f.input column, input_html: { rows: 10, cols: 20 }, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
14
|
+
<% elsif [:date, :datetime].include?(object.class.column_for_attribute(column).type) %>
|
15
|
+
<%= f.input column, html5: true, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
16
|
+
<% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
|
17
|
+
<% if restricted_columns.keys.include?(column.to_sym) %>
|
18
|
+
<%= f.association column.split("_id")[0],
|
19
|
+
label: restricted_columns[column.to_sym][:label],
|
20
|
+
collection: restricted_columns[column.to_sym][:collection],
|
21
|
+
wrapper_html: { class: wphtml },
|
22
|
+
hint: hint, placeholder: placeholder
|
23
|
+
%>
|
24
|
+
<% else %>
|
25
|
+
<%= f.association column.split("_id")[0], wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
26
|
+
<% end %>
|
27
|
+
<% else %>
|
28
|
+
<%= f.input column, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
29
|
+
<% end %>
|
30
|
+
<% end %>
|
31
|
+
</div>
|
@@ -22,31 +22,7 @@
|
|
22
22
|
</h3>
|
23
23
|
</div>
|
24
24
|
<div class="box-body">
|
25
|
-
|
26
|
-
<% (form_ordered_fields - ['id', 'created_at', 'updated_at', 'deleted_at'] - excluded_columns).each do |column| %>
|
27
|
-
<% wphtml = "col-md-#{(form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:size] : form_fields[column.to_sym] ) || 12}" %>
|
28
|
-
<% hint = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:hint] : '') %>
|
29
|
-
<% placeholder = (form_fields[column.to_sym].class == Hash ? form_fields[column.to_sym][:placeholder] : '') %>
|
30
|
-
<% if object.class.column_for_attribute(column).type == :text %>
|
31
|
-
<%= f.input column, input_html: { rows: 10, cols: 20 }, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
32
|
-
<% elsif [:date, :datetime].include?(object.class.column_for_attribute(column).type) %>
|
33
|
-
<%= f.input column, html5: true, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
34
|
-
<% elsif /_id$/ =~ column && object.respond_to?(column.split('_id')[0]) %>
|
35
|
-
<% if restricted_columns.keys.include?(column.to_sym) %>
|
36
|
-
<%= f.association column.split("_id")[0],
|
37
|
-
label: restricted_columns[column.to_sym][:label],
|
38
|
-
collection: restricted_columns[column.to_sym][:collection],
|
39
|
-
wrapper_html: { class: wphtml },
|
40
|
-
hint: hint, placeholder: placeholder
|
41
|
-
%>
|
42
|
-
<% else %>
|
43
|
-
<%= f.association column.split("_id")[0], wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
44
|
-
<% end %>
|
45
|
-
<% else %>
|
46
|
-
<%= f.input column, wrapper_html: { class: wphtml }, hint: hint, placeholder: placeholder %>
|
47
|
-
<% end %>
|
48
|
-
<% end %>
|
49
|
-
</div>
|
25
|
+
<%= render 'shared/fields', object: object, f: f, excluded_columns: excluded_columns, restricted_columns: restricted_columns %>
|
50
26
|
</div>
|
51
27
|
<div class="box-footer">
|
52
28
|
<% if back_link %>
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
1
|
+
<% partial ||= 'shared/fields' %>
|
2
|
+
|
3
|
+
<div class="modal fade in <%= object.model_name.singular %>-modal" id="modal-default">
|
2
4
|
<div class="modal-dialog">
|
3
5
|
<div class="modal-content">
|
4
6
|
<div class="modal-header">
|
5
7
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
6
8
|
<span aria-hidden="true">×</span></button>
|
7
|
-
<h4 class="modal-title"><%=t "helpers.links.new" %> <%=
|
9
|
+
<h4 class="modal-title"><%=t "helpers.links.new" %> <%= object.model_name.human %></h4>
|
8
10
|
</div>
|
9
|
-
<%= simple_form_for
|
11
|
+
<%= simple_form_for object do |f| %>
|
10
12
|
<div class="modal-body">
|
11
|
-
<%= render
|
13
|
+
<%= render partial, object: object, f: f %>
|
12
14
|
</div>
|
13
15
|
<div class="modal-footer">
|
14
16
|
<%= f.submit class: "btn btn-primary" %>
|
data/lib/zutils/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Viana
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- app/assets/javascripts/zutils.js
|
69
69
|
- app/assets/stylesheets/zutils.scss
|
70
70
|
- app/views/shared/_action_links.html.erb
|
71
|
+
- app/views/shared/_fields.html.erb
|
71
72
|
- app/views/shared/_form.html.erb
|
72
73
|
- app/views/shared/_index.html.erb
|
73
74
|
- app/views/shared/_list.html.erb
|