lato_core 2.1.2 → 2.1.3
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/lato_core/application.js +18 -9
- data/app/assets/javascripts/lato_core/modules/CoreButton.js +38 -0
- data/app/assets/javascripts/lato_core/{initializers/Charts.js → modules/CoreChart.js} +12 -12
- data/app/assets/javascripts/lato_core/modules/CoreDatepicker.js +42 -0
- data/app/assets/javascripts/lato_core/modules/CoreEditor.js +27 -0
- data/app/assets/javascripts/lato_core/modules/CoreFlash.js +27 -0
- data/app/assets/javascripts/lato_core/modules/CoreFormValidator.js +110 -0
- data/app/assets/javascripts/lato_core/{initializers/Layout.js → modules/CoreLayout.js} +6 -5
- data/app/assets/javascripts/lato_core/modules/CoreMediapicker.js +140 -0
- data/app/assets/javascripts/lato_core/{interfaces/Modal.js → modules/CoreModal.js} +27 -2
- data/app/assets/javascripts/lato_core/modules/CoreSelect.js +110 -0
- data/app/assets/javascripts/lato_core/{initializers/inputs/SortableManager.js → modules/CoreSortableManager.js} +7 -6
- data/app/assets/javascripts/lato_core/modules/CoreTable.js +28 -0
- data/app/assets/stylesheets/lato_core/cells/inputs/_inputs.scss +1 -0
- data/app/assets/stylesheets/lato_core/cells/inputs/_multipleselect.scss +6 -0
- data/app/assets/stylesheets/lato_core/cells/widgets/_index.scss +9 -0
- data/app/cells/lato_core/inputs/dropzone/views/show.html.erb +24 -20
- data/app/cells/lato_core/inputs/multipleselect/cell.rb +52 -0
- data/app/cells/lato_core/inputs/multipleselect/views/show.html.erb +16 -0
- data/app/cells/lato_core/inputs/select/cell.rb +19 -1
- data/app/cells/lato_core/inputs/select/views/show.html.erb +10 -2
- data/app/cells/lato_core/widgets/index/cell.rb +1 -0
- data/app/cells/lato_core/widgets/index/views/partials/counter.html.erb +3 -0
- data/app/cells/lato_core/widgets/index/views/show.html.erb +2 -0
- data/app/controllers/lato_core/back/superusers_controller.rb +9 -9
- data/app/controllers/lato_core/doc/cells_inputs_controller.rb +28 -0
- data/app/views/lato_core/doc/cells_elements/button.html.erb +0 -4
- data/app/views/lato_core/doc/cells_elements/modal.html.erb +4 -4
- data/app/views/lato_core/doc/cells_inputs/multipleselect.html.erb +110 -0
- data/app/views/lato_core/doc/cells_inputs/select.html.erb +48 -2
- data/app/views/lato_core/doc/doc/index.html.erb +1 -0
- data/app/views/lato_core/doc/general/generators.html.erb +40 -0
- data/app/views/layouts/lato_core/partials/_logo.html.erb +7 -5
- data/config/languages/default.yml +2 -1
- data/config/languages/it.yml +2 -1
- data/config/routes/doc.rb +5 -0
- data/lib/generators/lato_core/crud_controller_generator.rb +35 -0
- data/lib/generators/lato_core/crud_generator.rb +31 -12
- data/lib/generators/lato_core/crud_views_generator.rb +52 -0
- data/lib/generators/lato_core/initializer_generator.rb +38 -28
- data/lib/generators/lato_core/scaffold_generator.rb +30 -0
- data/lib/generators/lato_core/templates/crud_controller/app/controllers/lato/crud_controller.rb +94 -0
- data/lib/generators/lato_core/templates/crud_views/app/views/lato/crud/edit.html.erb +24 -0
- data/lib/generators/lato_core/templates/crud_views/app/views/lato/crud/index.html.erb +35 -0
- data/lib/generators/lato_core/templates/crud_views/app/views/lato/crud/new.html.erb +24 -0
- data/lib/generators/lato_core/templates/crud_views/app/views/lato/crud/shared/_form.html.erb +42 -0
- data/lib/generators/lato_core/templates/crud_views/app/views/lato/crud/show.html.erb +22 -0
- data/lib/generators/lato_core/templates/{assets → initializer/assets}/images/logo.svg +0 -0
- data/lib/generators/lato_core/templates/{assets → initializer/assets}/javascripts/application.js +0 -0
- data/lib/generators/lato_core/templates/{assets → initializer/assets}/stylesheets/application.scss +0 -0
- data/lib/generators/lato_core/templates/{assets → initializer/assets}/stylesheets/theme.scss.erb +0 -0
- data/lib/generators/lato_core/templates/initializer/controllers/application_controller.rb +25 -0
- data/lib/generators/lato_core/templates/initializer/views/application/index.html.erb +20 -0
- data/lib/lato_core/interfaces/token.rb +4 -3
- data/lib/lato_core/version.rb +1 -1
- metadata +33 -16
- data/app/assets/javascripts/lato_core/initializers/Elements.js +0 -67
- data/app/assets/javascripts/lato_core/initializers/Inputs.js +0 -249
- data/app/assets/javascripts/lato_core/initializers/inputs/MultipleSelect.js +0 -0
- data/lib/generators/lato_core/templates/controllers/application_controller.rb +0 -13
- data/lib/generators/lato_core/templates/views/application/index.html.erb +0 -16
@@ -1,4 +1,4 @@
|
|
1
|
-
var
|
1
|
+
var CoreModal = (function () {
|
2
2
|
|
3
3
|
function open (modalId, event) {
|
4
4
|
$('#' + modalId + '.elements-modal').addClass('elements-modal--active')
|
@@ -20,9 +20,34 @@ var Modal = (function () {
|
|
20
20
|
}
|
21
21
|
}
|
22
22
|
|
23
|
+
function initializeModalCloseButton (modal) {
|
24
|
+
var closeButton = $(modal).find('.elements-modal__close-button')
|
25
|
+
$(closeButton).click(function (e) {
|
26
|
+
e.preventDefault()
|
27
|
+
// close modal
|
28
|
+
$(modal).removeClass('elements-modal--active')
|
29
|
+
$(modal).find('.elements-modal__modal').removeClass('elements-modal__modal--active')
|
30
|
+
// active body scrolling
|
31
|
+
$('body').removeClass('stop-scrolling')
|
32
|
+
})
|
33
|
+
}
|
34
|
+
|
35
|
+
function _initModalCloseButton () {
|
36
|
+
$('.elements-modal').each(function () {
|
37
|
+
initializeModalCloseButton(this)
|
38
|
+
})
|
39
|
+
}
|
40
|
+
|
41
|
+
// Init:
|
42
|
+
function init () {
|
43
|
+
_initModalCloseButton()
|
44
|
+
}
|
45
|
+
|
23
46
|
return {
|
47
|
+
init: init,
|
48
|
+
initializeModalCloseButton: initializeModalCloseButton,
|
24
49
|
open: open,
|
25
50
|
close: close
|
26
51
|
}
|
27
52
|
|
28
|
-
})()
|
53
|
+
})()
|
@@ -0,0 +1,110 @@
|
|
1
|
+
var CoreSelect = (function () {
|
2
|
+
|
3
|
+
function initializeSelect (select) {
|
4
|
+
var selectInput = $(select).find('.inputs__select')
|
5
|
+
$(selectInput).selectize({
|
6
|
+
create: $(selectInput).attr('data-create') === 'true',
|
7
|
+
maxItems: $(selectInput).attr('data-multiple') === 'true' ? null : 1,
|
8
|
+
delimiter: ','
|
9
|
+
})
|
10
|
+
}
|
11
|
+
|
12
|
+
function initializeMultipleSelect (multipleSelect) {
|
13
|
+
var selects = $(multipleSelect).find('select.inputs__select')
|
14
|
+
// manage every select
|
15
|
+
selects.each(function (index) {
|
16
|
+
_initMultipleSelectSelectize(index, selects)
|
17
|
+
})
|
18
|
+
// load options for first selectize
|
19
|
+
_loadMultipleSelectOptions(null, 0, selects)
|
20
|
+
}
|
21
|
+
|
22
|
+
function _initMultipleSelectSelectize (selectPosition, selects) {
|
23
|
+
var select = selects[selectPosition]
|
24
|
+
var value = $(select).attr('value')
|
25
|
+
console.log(value)
|
26
|
+
var position = $(select).attr('data-position')
|
27
|
+
// clear old selectize
|
28
|
+
var selectize = select.selectize
|
29
|
+
if (selectize) {
|
30
|
+
selectize.destroy()
|
31
|
+
}
|
32
|
+
// initialize selectize
|
33
|
+
$(select).selectize({
|
34
|
+
maxItems: 1,
|
35
|
+
valueField: 'value',
|
36
|
+
labelField: 'label',
|
37
|
+
searchField: 'label',
|
38
|
+
options: [],
|
39
|
+
onChange: function (value) {
|
40
|
+
_loadMultipleSelectOptions(value, parseInt(position) + 1, selects)
|
41
|
+
},
|
42
|
+
onInitialize: function () {
|
43
|
+
if (value) {
|
44
|
+
this.setValue(value)
|
45
|
+
_loadMultipleSelectOptions(value, parseInt(position) + 1, selects)
|
46
|
+
}
|
47
|
+
}
|
48
|
+
})
|
49
|
+
}
|
50
|
+
|
51
|
+
function _updateMultipleSelectSelectize (options, selectPosition, selects) {
|
52
|
+
var select = selects[selectPosition]
|
53
|
+
var value = $(select).attr('value')
|
54
|
+
var position = $(select).attr('data-position')
|
55
|
+
|
56
|
+
var selectize = $(select)[0].selectize
|
57
|
+
|
58
|
+
if (selectize) {
|
59
|
+
selectize.clear();
|
60
|
+
selectize.clearOptions();
|
61
|
+
selectize.load(function (callback) {
|
62
|
+
callback(options)
|
63
|
+
})
|
64
|
+
if (value) {
|
65
|
+
selectize.setValue(value)
|
66
|
+
_loadMultipleSelectOptions(value, parseInt(position) + 1, selects)
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
function _loadMultipleSelectOptions (filterValue, selectPosition, selects) {
|
72
|
+
var select = selects[selectPosition]
|
73
|
+
if (!select) { return }
|
74
|
+
var apiUrl = $(select).attr('data-api')
|
75
|
+
$.ajax({
|
76
|
+
url: apiUrl,
|
77
|
+
cache: false,
|
78
|
+
data: (filterValue ? {value: filterValue} : null),
|
79
|
+
success: function (response) {
|
80
|
+
_updateMultipleSelectSelectize(response, selectPosition, selects)
|
81
|
+
}
|
82
|
+
})
|
83
|
+
}
|
84
|
+
|
85
|
+
function _initSelect () {
|
86
|
+
$('.inputs-select').each(function () {
|
87
|
+
initializeSelect(this)
|
88
|
+
})
|
89
|
+
}
|
90
|
+
|
91
|
+
function _initMultipleSelect () {
|
92
|
+
$('.inputs-multipleselect').each(function () {
|
93
|
+
initializeMultipleSelect(this)
|
94
|
+
})
|
95
|
+
}
|
96
|
+
|
97
|
+
// Init:
|
98
|
+
function init () {
|
99
|
+
_initSelect()
|
100
|
+
_initMultipleSelect()
|
101
|
+
}
|
102
|
+
|
103
|
+
return {
|
104
|
+
init: init,
|
105
|
+
initializeSelect: initializeSelect,
|
106
|
+
initializeMultipleSelect: initializeMultipleSelect
|
107
|
+
}
|
108
|
+
|
109
|
+
})()
|
110
|
+
|
@@ -1,8 +1,9 @@
|
|
1
|
-
var
|
2
|
-
|
1
|
+
var CoreSortableManager = (function () {
|
2
|
+
|
3
|
+
function _initSortable () {
|
3
4
|
var sortableContainer = document.querySelectorAll('.js-sortable__main-container')
|
4
5
|
|
5
|
-
if(sortableContainer.length > 0) {
|
6
|
+
if (sortableContainer.length > 0) {
|
6
7
|
for (var i = 0; i < sortableContainer.length; i++) {
|
7
8
|
|
8
9
|
var sort = Sortable.create(sortableContainer[i], {
|
@@ -36,7 +37,7 @@ var SortableManager = (function () {
|
|
36
37
|
}
|
37
38
|
}
|
38
39
|
|
39
|
-
function updateOrder(container) {
|
40
|
+
function updateOrder (container) {
|
40
41
|
var sortableElements = container.querySelectorAll('.js-sortable__element')
|
41
42
|
for (var i = 0; i < sortableElements.length; i++) {
|
42
43
|
var sortableElement = sortableElements[i]
|
@@ -50,12 +51,12 @@ var SortableManager = (function () {
|
|
50
51
|
}
|
51
52
|
}
|
52
53
|
|
53
|
-
function destroySort(sortInstance) {
|
54
|
+
function destroySort (sortInstance) {
|
54
55
|
sortInstance.destroy()
|
55
56
|
}
|
56
57
|
|
57
58
|
function init () {
|
58
|
-
|
59
|
+
_initSortable()
|
59
60
|
}
|
60
61
|
|
61
62
|
return {
|
@@ -0,0 +1,28 @@
|
|
1
|
+
var CoreTable = (function () {
|
2
|
+
|
3
|
+
function initializeTableFixedHead (table) {
|
4
|
+
var tableElement = $(table).find('.elements-table__table')
|
5
|
+
$(tableElement).floatThead({
|
6
|
+
scrollContainer: function (table) {
|
7
|
+
return table.closest('.elements-table--fixed')
|
8
|
+
}
|
9
|
+
})
|
10
|
+
}
|
11
|
+
|
12
|
+
function _initTableFixedHead () {
|
13
|
+
$('.elements-table.elements-table--fixed').each(function () {
|
14
|
+
initializeTableFixedHead(this)
|
15
|
+
})
|
16
|
+
}
|
17
|
+
|
18
|
+
// Init:
|
19
|
+
function init () {
|
20
|
+
_initTableFixedHead()
|
21
|
+
}
|
22
|
+
|
23
|
+
return {
|
24
|
+
init: init,
|
25
|
+
initializeTableFixedHead: initializeTableFixedHead
|
26
|
+
}
|
27
|
+
|
28
|
+
})()
|
@@ -63,6 +63,15 @@
|
|
63
63
|
}
|
64
64
|
}
|
65
65
|
|
66
|
+
.widgets-index__counter {
|
67
|
+
height: 31px;
|
68
|
+
float: left;
|
69
|
+
padding-top: 10px;
|
70
|
+
padding-right: 15px;
|
71
|
+
border-bottom: solid 1px $color_grey;
|
72
|
+
font-size: 0.8em;
|
73
|
+
}
|
74
|
+
|
66
75
|
// Responsive layout:
|
67
76
|
|
68
77
|
@media(max-width:767px) {
|
@@ -1,24 +1,28 @@
|
|
1
|
-
|
1
|
+
<div class="inputs-dropzone inputs__container">
|
2
2
|
|
3
|
-
|
4
|
-
method="<%= @args[:method] %>"
|
5
|
-
action="<%= @args[:url] %>"
|
6
|
-
class="inputs__dropzone"
|
7
|
-
data-param-name="<%= @args[:param_name] %>"
|
8
|
-
data-max-size="<%= @args[:max_size] %>"
|
9
|
-
data-max-files="<%= @args[:max_files] %>"
|
10
|
-
>
|
3
|
+
<%= render '../../shared/label.html' %>
|
11
4
|
|
12
|
-
<
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
<form
|
6
|
+
method="<%= @args[:method] %>"
|
7
|
+
action="<%= @args[:url] %>"
|
8
|
+
class="inputs__dropzone"
|
9
|
+
data-param-name="<%= @args[:param_name] %>"
|
10
|
+
data-max-size="<%= @args[:max_size] %>"
|
11
|
+
data-max-files="<%= @args[:max_files] %>"
|
12
|
+
>
|
19
13
|
|
20
|
-
|
21
|
-
<
|
22
|
-
|
14
|
+
<input type="hidden" name="utf8" value="✓">
|
15
|
+
<input type="hidden" name="authenticity_token" value="<%= @core__cells_authenticity_token %>">
|
16
|
+
<input type="hidden" name="_method" value="<%= @args[:method] %>">
|
17
|
+
|
18
|
+
<div class="fallback">
|
19
|
+
<input name="<%= @args[:param_name] %>" type="file" multiple />
|
20
|
+
</div>
|
23
21
|
|
24
|
-
|
22
|
+
<div class="icon">
|
23
|
+
<i class="fa fa-file-o" aria-hidden="true"></i>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
</form>
|
27
|
+
|
28
|
+
</div>
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module LatoCore
|
2
|
+
|
3
|
+
class Inputs::Multipleselect::Cell < Cell
|
4
|
+
|
5
|
+
@@requested_args = [:name]
|
6
|
+
|
7
|
+
@@default_args = {
|
8
|
+
label: '',
|
9
|
+
help: '',
|
10
|
+
class: 'md-12',
|
11
|
+
selects: [] # {name: '', label: '', api: '', value: '', class: ''}
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize(args = {})
|
15
|
+
@args = validate_args(
|
16
|
+
args: args,
|
17
|
+
requested_args: @@requested_args,
|
18
|
+
default_args: @@default_args
|
19
|
+
)
|
20
|
+
|
21
|
+
set_conditions
|
22
|
+
end
|
23
|
+
|
24
|
+
def show
|
25
|
+
render 'show.html'
|
26
|
+
end
|
27
|
+
|
28
|
+
protected
|
29
|
+
|
30
|
+
def generate_select(select_settings, position)
|
31
|
+
LatoCore::Inputs::Select::Cell.new(
|
32
|
+
name: "#{@args[:name]}[#{select_settings[:name]}]",
|
33
|
+
label: select_settings[:label],
|
34
|
+
value: select_settings[:value],
|
35
|
+
class: select_settings[:class],
|
36
|
+
attributes: {
|
37
|
+
api: select_settings[:api],
|
38
|
+
position: position
|
39
|
+
}
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def set_conditions
|
46
|
+
@show_label = !@args[:label].nil? && !@args[:label].blank?
|
47
|
+
@show_help = !@args[:help].nil? && !@args[:help].blank?
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<div class="inputs-multipleselect inputs__container <%= @args[:class] %>">
|
2
|
+
|
3
|
+
<%= render '../../shared/label.html' %>
|
4
|
+
|
5
|
+
<div class="row">
|
6
|
+
|
7
|
+
<% @args[:selects].each_with_index do |select_settings, index| %>
|
8
|
+
<% select = generate_select(select_settings, index) %>
|
9
|
+
<%= select %>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
</div>
|
13
|
+
|
14
|
+
<%= render '../../shared/help.html' %>
|
15
|
+
|
16
|
+
</div>
|
@@ -16,7 +16,8 @@ module LatoCore
|
|
16
16
|
option_value: 'value',
|
17
17
|
option_name: 'name',
|
18
18
|
option_blank: true,
|
19
|
-
class: 'md-12'
|
19
|
+
class: 'md-12',
|
20
|
+
attributes: {}
|
20
21
|
}
|
21
22
|
|
22
23
|
def initialize(args = {})
|
@@ -33,12 +34,24 @@ module LatoCore
|
|
33
34
|
render 'show.html'
|
34
35
|
end
|
35
36
|
|
37
|
+
# This function return a string used on the HTML option to
|
38
|
+
# set a an option value selected or not.
|
39
|
+
def get_option_value_selected(option_value)
|
40
|
+
if @args[:multiple]
|
41
|
+
values = @args[:value].is_a?(Array) ? @args[:value] : @args[:value].split(',')
|
42
|
+
return values.include?(option_value) ? "selected='selected'" : ''
|
43
|
+
end
|
44
|
+
|
45
|
+
@args[:value] == option_value ? "selected='selected'" : ''
|
46
|
+
end
|
47
|
+
|
36
48
|
private
|
37
49
|
|
38
50
|
def set_conditions
|
39
51
|
@show_label = !@args[:label].nil? && !@args[:label].blank?
|
40
52
|
@show_help = !@args[:help].nil? && !@args[:help].blank?
|
41
53
|
@options = generate_options
|
54
|
+
@value = generate_value
|
42
55
|
end
|
43
56
|
|
44
57
|
def generate_options
|
@@ -53,6 +66,11 @@ module LatoCore
|
|
53
66
|
return options
|
54
67
|
end
|
55
68
|
|
69
|
+
def generate_value
|
70
|
+
return @args[:value].is_a?(Array) ? @args[:value].join(',') : @args[:value] if @args[:multiple]
|
71
|
+
@args[:value]
|
72
|
+
end
|
73
|
+
|
56
74
|
end
|
57
75
|
|
58
76
|
end
|
@@ -5,18 +5,26 @@
|
|
5
5
|
<select
|
6
6
|
class="inputs__select"
|
7
7
|
type="text"
|
8
|
-
value="<%= @
|
8
|
+
value="<%= @value %>"
|
9
9
|
name="<%= @args[:name] %>"
|
10
10
|
placeholder="<%= @args[:placeholder] %>"
|
11
11
|
data-required="<%= @args[:required] %>"
|
12
12
|
data-create="<%= @args[:create] %>"
|
13
13
|
data-multiple="<%= @args[:multiple] %>"
|
14
|
+
|
15
|
+
<% if @args[:multiple] %>
|
16
|
+
multiple="multiple"
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<% @args[:attributes].each do |key, value| %>
|
20
|
+
data-<%= key%>="<%= value %>"
|
21
|
+
<% end %>
|
14
22
|
>
|
15
23
|
<% if @args[:option_blank] %>
|
16
24
|
<option value=""></option>
|
17
25
|
<% end %>
|
18
26
|
<% @options.each do |option| %>
|
19
|
-
<option value="<%= option[:value] %>" <%=
|
27
|
+
<option value="<%= option[:value] %>" <%= get_option_value_selected(option[:value]) %>>
|
20
28
|
<%= option[:name] %>
|
21
29
|
</option>
|
22
30
|
<% end %>
|
@@ -38,6 +38,7 @@ module LatoCore
|
|
38
38
|
|
39
39
|
def set_conditions
|
40
40
|
@records = @args[:records].is_a?(Hash) ? @args[:records][:records] : @args[:records]
|
41
|
+
@total = @args[:records].is_a?(Hash) ? @args[:records][:total] : @args[:records].length
|
41
42
|
# conditions for show
|
42
43
|
@show_row_actions = @args[:index_url] && @args[:actions] && (@args[:actions][:show] || @args[:actions][:edit] || @args[:actions][:delete])
|
43
44
|
@show_row_actions_class = @show_row_actions ? 'widgets-index--actions' : ''
|