lato_media 2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +27 -0
- data/Rakefile +5 -0
- data/app/assets/config/lato_media_manifest.js +2 -0
- data/app/assets/javascripts/lato_media/application.js +18 -0
- data/app/assets/javascripts/lato_media/initializers/Inputs.js +62 -0
- data/app/assets/javascripts/lato_media/interfaces/MediaSelector.js +128 -0
- data/app/assets/stylesheets/lato_media/application.scss +17 -0
- data/app/assets/stylesheets/lato_media/cells/_cells.scss +2 -0
- data/app/assets/stylesheets/lato_media/cells/elements/_elements.scss +2 -0
- data/app/assets/stylesheets/lato_media/cells/elements/_preview.scss +67 -0
- data/app/assets/stylesheets/lato_media/cells/elements/_previews.scss +23 -0
- data/app/assets/stylesheets/lato_media/cells/inputs/_gallery.scss +13 -0
- data/app/assets/stylesheets/lato_media/cells/inputs/_inputs.scss +2 -0
- data/app/assets/stylesheets/lato_media/cells/inputs/_media.scss +25 -0
- data/app/assets/stylesheets/lato_media/pages/_medias.scss +20 -0
- data/app/assets/stylesheets/lato_media/pages/_pages.scss +1 -0
- data/app/assets/stylesheets/lato_media/partials/_media_selector.scss +53 -0
- data/app/assets/stylesheets/lato_media/partials/_partials.scss +1 -0
- data/app/assets/stylesheets/lato_media/theme.scss.erb +12 -0
- data/app/cells/lato_media/elements/preview/cell.rb +44 -0
- data/app/cells/lato_media/elements/preview/views/general.html.erb +14 -0
- data/app/cells/lato_media/elements/preview/views/image.html.erb +10 -0
- data/app/cells/lato_media/elements/preview/views/not_found.html.erb +15 -0
- data/app/cells/lato_media/elements/preview/views/show.html.erb +33 -0
- data/app/cells/lato_media/elements/previews/cell.rb +37 -0
- data/app/cells/lato_media/elements/previews/views/show.html.erb +43 -0
- data/app/cells/lato_media/inputs/gallery/cell.rb +80 -0
- data/app/cells/lato_media/inputs/gallery/views/show.html.erb +39 -0
- data/app/cells/lato_media/inputs/media/cell.rb +64 -0
- data/app/cells/lato_media/inputs/media/views/show.html.erb +40 -0
- data/app/controllers/lato_media/application_controller.rb +13 -0
- data/app/controllers/lato_media/back/back_controller.rb +13 -0
- data/app/controllers/lato_media/back/media_selector_controller.rb +43 -0
- data/app/controllers/lato_media/back/medias_controller.rb +101 -0
- data/app/controllers/lato_media/doc/cells_controller.rb +43 -0
- data/app/controllers/lato_media/doc/doc_controller.rb +17 -0
- data/app/controllers/lato_media/doc/general_controller.rb +9 -0
- data/app/helpers/lato_media/application_helper.rb +4 -0
- data/app/jobs/lato_media/application_job.rb +4 -0
- data/app/mailers/lato_media/application_mailer.rb +6 -0
- data/app/models/lato_media/application_record.rb +5 -0
- data/app/models/lato_media/media/entity_helpers.rb +15 -0
- data/app/models/lato_media/media.rb +26 -0
- data/app/views/lato_media/back/media_selector/load_form.js.erb +9 -0
- data/app/views/lato_media/back/media_selector/load_index.js.erb +6 -0
- data/app/views/lato_media/back/media_selector/load_inputs_gallery.js.erb +6 -0
- data/app/views/lato_media/back/media_selector/load_inputs_media.js.erb +6 -0
- data/app/views/lato_media/back/medias/edit.html.erb +51 -0
- data/app/views/lato_media/back/medias/index.html.erb +25 -0
- data/app/views/lato_media/back/medias/new.html.erb +25 -0
- data/app/views/lato_media/back/medias/refresh_index.js.erb +11 -0
- data/app/views/lato_media/back/medias/shared/_dropzone_modal.html.erb +12 -0
- data/app/views/lato_media/back/medias/shared/_form.html.erb +52 -0
- data/app/views/lato_media/back/medias/shared/_index.html.erb +14 -0
- data/app/views/lato_media/doc/cells/elements_preview.html.erb +241 -0
- data/app/views/lato_media/doc/cells/elements_previews.html.erb +87 -0
- data/app/views/lato_media/doc/cells/inputs_gallery.html.erb +63 -0
- data/app/views/lato_media/doc/cells/inputs_media.html.erb +63 -0
- data/app/views/lato_media/doc/doc/index.html.erb +59 -0
- data/app/views/lato_media/doc/general/installation.html.erb +49 -0
- data/app/views/lato_media/doc/general/personalization.html.erb +0 -0
- data/app/views/lato_media/partials/_media_selector.html.erb +12 -0
- data/app/views/lato_media/partials/media_selector/_modal.html.erb +16 -0
- data/app/views/lato_media/partials/media_selector/_modal_form.html.erb +6 -0
- data/app/views/lato_media/partials/media_selector/_modal_index.html.erb +18 -0
- data/config/configs.yml +50 -0
- data/config/initializers/assets.rb +4 -0
- data/config/languages/default.yml +39 -0
- data/config/languages/it.yml +39 -0
- data/config/routes/api.rb +3 -0
- data/config/routes/back.rb +9 -0
- data/config/routes/doc.rb +15 -0
- data/config/routes.rb +16 -0
- data/db/migrate/20160224181218_create_lato_media_media.rb +15 -0
- data/lib/lato_media/engine.rb +16 -0
- data/lib/lato_media/version.rb +3 -0
- data/lib/lato_media.rb +5 -0
- data/lib/tasks/lato_media_tasks.rake +4 -0
- metadata +179 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
|
3
|
+
class Elements::Previews::Cell < LatoCore::Cell
|
4
|
+
|
5
|
+
view_paths << "#{LatoMedia::Engine.root}/app/cells"
|
6
|
+
|
7
|
+
@@requested_args = [:medias]
|
8
|
+
|
9
|
+
@@default_args = {
|
10
|
+
class: '',
|
11
|
+
size: 'large',
|
12
|
+
url: nil,
|
13
|
+
remote: false,
|
14
|
+
onclick: ''
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(args = {})
|
18
|
+
@args = validate_args(
|
19
|
+
args: args,
|
20
|
+
requested_args: @@requested_args,
|
21
|
+
default_args: @@default_args
|
22
|
+
)
|
23
|
+
|
24
|
+
set_conditions
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
render 'show.html'
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def set_conditions; end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<% if @args[:url] %>
|
2
|
+
<a
|
3
|
+
href="<%= @args[:url] %>"
|
4
|
+
class="elements-previews <%= @args[:class] %>"
|
5
|
+
onclick="<%= @args[:onclick] %>"
|
6
|
+
<% if @args[:remote] %>
|
7
|
+
data-remote="true"
|
8
|
+
<% end %>
|
9
|
+
>
|
10
|
+
<% else %>
|
11
|
+
<div
|
12
|
+
class="elements-previews <%= @args[:class] %>"
|
13
|
+
onclick="<%= @args[:onclick] %>"
|
14
|
+
>
|
15
|
+
<% end %>
|
16
|
+
|
17
|
+
<% if @args[:medias].length > 0 %>
|
18
|
+
|
19
|
+
<div class="elements-previews__list row">
|
20
|
+
|
21
|
+
<% @args[:medias].each do |media| %>
|
22
|
+
|
23
|
+
<%= LatoMedia::Elements::Preview::Cell.new(media: media, size: @args[:size], class: 'xs-6 sm-4 md-3 lg-3') %>
|
24
|
+
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
</div>
|
28
|
+
|
29
|
+
<% else %>
|
30
|
+
|
31
|
+
<div class="elements-previews__not-found">
|
32
|
+
|
33
|
+
<span><%= LANGUAGES[:lato_media][:mixed][:no_media_to_show] %></span>
|
34
|
+
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<% end %>
|
38
|
+
|
39
|
+
<% if @args[:url] %>
|
40
|
+
</a>
|
41
|
+
<% else %>
|
42
|
+
</div>
|
43
|
+
<% end %>
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
|
3
|
+
class Inputs::Gallery::Cell < LatoCore::Cell
|
4
|
+
|
5
|
+
view_paths << "#{LatoMedia::Engine.root}/app/cells"
|
6
|
+
|
7
|
+
@@requested_args = [:name]
|
8
|
+
|
9
|
+
@@default_args = {
|
10
|
+
value: '',
|
11
|
+
label: '',
|
12
|
+
help: '',
|
13
|
+
class: 'md-12',
|
14
|
+
id: nil
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(args = {})
|
18
|
+
@args = validate_args(
|
19
|
+
args: args,
|
20
|
+
requested_args: @@requested_args,
|
21
|
+
default_args: @@default_args
|
22
|
+
)
|
23
|
+
|
24
|
+
set_conditions
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
render 'show.html'
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def set_conditions
|
34
|
+
# set show options
|
35
|
+
@show_label = !@args[:label].nil? && !@args[:label].blank?
|
36
|
+
@show_help = !@args[:help].nil? && !@args[:help].blank?
|
37
|
+
# set correct id
|
38
|
+
@id = @args[:id] ? @args[:id] : SecureRandom.hex(5) # generate random id if not custom id is set.
|
39
|
+
# set current media
|
40
|
+
medias = get_medias
|
41
|
+
@medias = medias ? medias : []
|
42
|
+
# set current value
|
43
|
+
@value = get_value
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_medias
|
47
|
+
if @args[:value].is_a?(String)
|
48
|
+
array = @args[:value].split(',')
|
49
|
+
get_medias_from_array(array)
|
50
|
+
elsif @args[:value].is_a?(Array)
|
51
|
+
get_medias_from_array(@args[:value])
|
52
|
+
else
|
53
|
+
raise 'Gallery value not accepted'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_medias_from_array(array)
|
58
|
+
medias = []
|
59
|
+
array.each do |element|
|
60
|
+
if element.is_a?(String)
|
61
|
+
medias.push(LatoMedia::Media.find_by(id: element.to_i))
|
62
|
+
elsif element.is_a?(Integer)
|
63
|
+
medias.push(LatoMedia::Media.find_by(id: element))
|
64
|
+
elsif element.class == LatoMedia::Media
|
65
|
+
medias.push(element)
|
66
|
+
else
|
67
|
+
raise 'Media value not accepted'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
medias
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_value
|
74
|
+
values = @medias.map { |m| m.id if m }
|
75
|
+
values.join(',')
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<div class="inputs-gallery inputs__container <%= @args[:class] %>" id="inputs-gallery-<%= @id %>">
|
2
|
+
|
3
|
+
<% # Label from lato_core cells %>
|
4
|
+
<% if @show_label %>
|
5
|
+
<label
|
6
|
+
class="inputs__label"
|
7
|
+
for="<%= @args[:name] %>"
|
8
|
+
>
|
9
|
+
<%= @args[:label] %>
|
10
|
+
</label>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<div class="inputs-gallery__preview">
|
14
|
+
|
15
|
+
<%=raw LatoMedia::Elements::Previews::Cell.new(medias: @medias, url: '#',
|
16
|
+
onclick: "MediaSelector.open('#{@id}', 99, event);") %>
|
17
|
+
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<% # Help from lato_core cells %>
|
21
|
+
<% if @show_help %>
|
22
|
+
<div
|
23
|
+
class="inputs__help"
|
24
|
+
>
|
25
|
+
<%= @args[:help] %>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<input
|
30
|
+
class="inputs-gallery__input"
|
31
|
+
type="hidden"
|
32
|
+
value="<%= @value %>"
|
33
|
+
name="<%= @args[:name] %>"
|
34
|
+
id="<%= @id %>"
|
35
|
+
/>
|
36
|
+
|
37
|
+
<%= link_to 'load_inputs_gallery_previews', '/lato/media/media_selector/load_inputs_gallery', remote: true, class: 'inputs-gallery__reload' %>
|
38
|
+
|
39
|
+
</div>
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
|
3
|
+
class Inputs::Media::Cell < LatoCore::Cell
|
4
|
+
|
5
|
+
view_paths << "#{LatoMedia::Engine.root}/app/cells"
|
6
|
+
|
7
|
+
@@requested_args = [:name]
|
8
|
+
|
9
|
+
@@default_args = {
|
10
|
+
value: '',
|
11
|
+
label: '',
|
12
|
+
help: '',
|
13
|
+
class: 'md-12',
|
14
|
+
id: nil
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(args = {})
|
18
|
+
@args = validate_args(
|
19
|
+
args: args,
|
20
|
+
requested_args: @@requested_args,
|
21
|
+
default_args: @@default_args
|
22
|
+
)
|
23
|
+
|
24
|
+
set_conditions
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
render 'show.html'
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def set_conditions
|
34
|
+
# set show options
|
35
|
+
@show_label = !@args[:label].nil? && !@args[:label].blank?
|
36
|
+
@show_help = !@args[:help].nil? && !@args[:help].blank?
|
37
|
+
# set correct id
|
38
|
+
@id = @args[:id] ? @args[:id] : SecureRandom.hex(5) # generate random id if not custom id is set.
|
39
|
+
# set current media
|
40
|
+
media = get_media
|
41
|
+
@media = media ? media : LatoMedia::Media.new
|
42
|
+
# set current value
|
43
|
+
@value = get_value
|
44
|
+
end
|
45
|
+
|
46
|
+
def get_media
|
47
|
+
if @args[:value].is_a?(String)
|
48
|
+
LatoMedia::Media.find_by(id: @args[:value].to_i)
|
49
|
+
elsif @args[:value].is_a?(Integer)
|
50
|
+
LatoMedia::Media.find_by(id: @args[:value])
|
51
|
+
elsif @args[:value].class == LatoMedia::Media
|
52
|
+
@args[:value]
|
53
|
+
else
|
54
|
+
raise 'Media value not accepted'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_value
|
59
|
+
@media.id if @media
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<div class="inputs-media inputs__container <%= @args[:class] %>" id="inputs-media-<%= @id %>">
|
2
|
+
|
3
|
+
<% # Label from lato_core cells %>
|
4
|
+
<% if @show_label %>
|
5
|
+
<label
|
6
|
+
class="inputs__label"
|
7
|
+
for="<%= @args[:name] %>"
|
8
|
+
>
|
9
|
+
<%= @args[:label] %>
|
10
|
+
</label>
|
11
|
+
<% end %>
|
12
|
+
|
13
|
+
<div class="inputs-media__preview">
|
14
|
+
|
15
|
+
<%=raw LatoMedia::Elements::Preview::Cell.new(media: @media, url: '#',
|
16
|
+
onclick: "MediaSelector.open('#{@id}', 1, event);") %>
|
17
|
+
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<% # Help from lato_core cells %>
|
21
|
+
<% if @show_help %>
|
22
|
+
<div
|
23
|
+
class="inputs__help"
|
24
|
+
>
|
25
|
+
<%= @args[:help] %>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<input
|
30
|
+
class="inputs-media__input"
|
31
|
+
type="hidden"
|
32
|
+
value="<%= @value %>"
|
33
|
+
name="<%= @args[:name] %>"
|
34
|
+
id="<%= @id %>"
|
35
|
+
/>
|
36
|
+
|
37
|
+
|
38
|
+
<%= link_to 'load_inputs_media_preview', '/lato/media/media_selector/load_inputs_media', remote: true, class: 'inputs-media__reload' %>
|
39
|
+
|
40
|
+
</div>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
class Back::BackController < ApplicationController
|
3
|
+
|
4
|
+
# Specific helpers import to fix not found functions bug
|
5
|
+
helper LatoMedia::ApplicationHelper
|
6
|
+
|
7
|
+
layout 'lato_core/admin'
|
8
|
+
|
9
|
+
before_action :core__cells_initialize
|
10
|
+
before_action :core__manage_superuser_session
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
|
3
|
+
# This class contains actions used by media cells.
|
4
|
+
class Back::MediaSelectorController < Back::BackController
|
5
|
+
|
6
|
+
def load_index
|
7
|
+
medias = LatoMedia::Media.all
|
8
|
+
# set data for view
|
9
|
+
@page = ((params[:page] && params[:page].to_i > 0) ? params[:page].to_i : 1)
|
10
|
+
@pagination_total = (medias.length / 12.to_f).ceil
|
11
|
+
@medias = core__paginate_array(medias.reverse, 12, @page)
|
12
|
+
|
13
|
+
respond_to do |r|
|
14
|
+
r.js
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_form
|
19
|
+
# reload cells settings
|
20
|
+
core__cells_initialize
|
21
|
+
|
22
|
+
respond_to do |r|
|
23
|
+
r.js
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_inputs_media
|
28
|
+
value = params[:value] ? params[:value].to_i : nil
|
29
|
+
media = LatoMedia::Media.find_by(id: params[:value])
|
30
|
+
# set values for render
|
31
|
+
@media = media ? media : LatoMedia::Media.new
|
32
|
+
@id = params[:id]
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_inputs_gallery
|
36
|
+
value = params[:value].split(',')
|
37
|
+
# set values for render
|
38
|
+
@medias = LatoMedia::Media.where(id: value)
|
39
|
+
@id = params[:id]
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
class Back::MediasController < Back::BackController
|
3
|
+
|
4
|
+
skip_before_action :verify_authenticity_token, only: [:create]
|
5
|
+
|
6
|
+
before_action do
|
7
|
+
core__set_menu_active_item('media_medias')
|
8
|
+
end
|
9
|
+
|
10
|
+
def index
|
11
|
+
core__set_header_active_page_title(LANGUAGES[:lato_media][:pages][:medias])
|
12
|
+
set_index_variables((params[:page] ? params[:page].to_i : 1))
|
13
|
+
end
|
14
|
+
|
15
|
+
def refresh_index
|
16
|
+
set_index_variables(1)
|
17
|
+
respond_to do |r|
|
18
|
+
r.js
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def show
|
23
|
+
# use edit as default media show page
|
24
|
+
redirect_to lato_media.edit_media_path(params[:id])
|
25
|
+
end
|
26
|
+
|
27
|
+
def new
|
28
|
+
core__set_header_active_page_title(LANGUAGES[:lato_media][:pages][:medias_new])
|
29
|
+
end
|
30
|
+
|
31
|
+
def create
|
32
|
+
@media = LatoMedia::Media.new(attachment: params[:file])
|
33
|
+
|
34
|
+
unless @media.save
|
35
|
+
render json: { error: @media.errors.full_messages.to_sentence }, status: 400
|
36
|
+
return
|
37
|
+
end
|
38
|
+
|
39
|
+
render json: {}, status: 200
|
40
|
+
end
|
41
|
+
|
42
|
+
def edit
|
43
|
+
core__set_header_active_page_title(LANGUAGES[:lato_media][:pages][:medias_edit])
|
44
|
+
@media = LatoMedia::Media.find_by(id: params[:id])
|
45
|
+
return unless check_media_presence
|
46
|
+
end
|
47
|
+
|
48
|
+
def update
|
49
|
+
@media = LatoMedia::Media.find_by(id: params[:id])
|
50
|
+
return unless check_media_presence
|
51
|
+
|
52
|
+
unless @media.update(media_params)
|
53
|
+
flash[:danger] = @media.errors.full_messages.to_sentence
|
54
|
+
redirect_to lato_media.medias_path
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
flash[:success] = LANGUAGES[:lato_media][:flashes][:media_update_success]
|
59
|
+
redirect_to lato_media.medias_path
|
60
|
+
end
|
61
|
+
|
62
|
+
def destroy
|
63
|
+
@media = LatoMedia::Media.find_by(id: params[:id])
|
64
|
+
return unless check_media_presence
|
65
|
+
|
66
|
+
unless @media.destroy
|
67
|
+
flash[:danger] = @media.errors.full_messages.to_sentence
|
68
|
+
redirect_to lato_media.medias_path
|
69
|
+
return
|
70
|
+
end
|
71
|
+
|
72
|
+
flash[:success] = LANGUAGES[:lato_media][:flashes][:media_destroy_success]
|
73
|
+
redirect_to lato_media.medias_path
|
74
|
+
end
|
75
|
+
|
76
|
+
private
|
77
|
+
|
78
|
+
# This function checks the @media variable is present and redirect to index if it not exist.
|
79
|
+
def check_media_presence
|
80
|
+
unless @media
|
81
|
+
flash[:warning] = LANGUAGES[:lato_media][:flashes][:media_not_found]
|
82
|
+
redirect_to lato_media.medias_path
|
83
|
+
return false
|
84
|
+
end
|
85
|
+
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
def media_params
|
90
|
+
params.require(:media).permit(:title, :description)
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_index_variables(page)
|
94
|
+
medias = LatoMedia::Media.all.order('created_at DESC')
|
95
|
+
@pagination_current = page
|
96
|
+
@pagination_total = (medias.length.to_f / 24.to_f).ceil
|
97
|
+
@medias = core__paginate_array(medias, 24, page)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
class Doc::CellsController < Doc::DocController
|
3
|
+
|
4
|
+
def elements_preview
|
5
|
+
set_random_media
|
6
|
+
end
|
7
|
+
|
8
|
+
def elements_previews
|
9
|
+
set_random_medias(10)
|
10
|
+
end
|
11
|
+
|
12
|
+
def inputs_media
|
13
|
+
set_random_media
|
14
|
+
end
|
15
|
+
|
16
|
+
def inputs_gallery
|
17
|
+
set_random_medias(10)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def set_random_media
|
23
|
+
medias = LatoMedia::Media.all
|
24
|
+
|
25
|
+
if medias.empty?
|
26
|
+
@media = LatoMedia::Media.new
|
27
|
+
else
|
28
|
+
@media = medias.sample
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def set_random_medias(qnt)
|
33
|
+
@medias = []
|
34
|
+
medias = LatoMedia::Media.all
|
35
|
+
qnt.times do
|
36
|
+
media = medias.sample
|
37
|
+
media = LatoMedia::Media.new unless media
|
38
|
+
@medias.push(media)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
class Doc::DocController < ApplicationController
|
3
|
+
|
4
|
+
layout 'lato_core/admin'
|
5
|
+
|
6
|
+
before_action :core__cells_initialize
|
7
|
+
before_action :core__manage_superuser_session
|
8
|
+
|
9
|
+
before_action do
|
10
|
+
core__set_menu_active_item('media_documentation')
|
11
|
+
core__set_header_active_page_title(LANGUAGES[:lato_media][:pages][:documentation])
|
12
|
+
end
|
13
|
+
|
14
|
+
def index; end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
module Media::EntityHelpers
|
3
|
+
|
4
|
+
# This function tells if the attachment exists.
|
5
|
+
def exists?
|
6
|
+
attachment.exists?
|
7
|
+
end
|
8
|
+
|
9
|
+
# This function tells if the attachment is an image.
|
10
|
+
def image?
|
11
|
+
attachment.content_type =~ /^image/
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module LatoMedia
|
2
|
+
class Media < ActiveRecord::Base
|
3
|
+
|
4
|
+
IMAGES_SIZES = {
|
5
|
+
large: "#{CONFIGS[:lato_media][:large_media_width]}x#{CONFIGS[:lato_media][:large_media_width]}>",
|
6
|
+
medium: "#{CONFIGS[:lato_media][:medium_media_width]}x#{CONFIGS[:lato_media][:medium_media_width]}>",
|
7
|
+
thumb: "#{CONFIGS[:lato_media][:thumb_media_width]}x#{CONFIGS[:lato_media][:thumb_media_width]}>"
|
8
|
+
}
|
9
|
+
|
10
|
+
# Dependencies:
|
11
|
+
|
12
|
+
include Media::EntityHelpers
|
13
|
+
|
14
|
+
# Other settings:
|
15
|
+
|
16
|
+
has_attached_file :attachment, styles: lambda { |a| a.content_type =~ /^image/ ? IMAGES_SIZES : {} }
|
17
|
+
do_not_validate_attachment_file_type :attachment
|
18
|
+
|
19
|
+
# Callbacks:
|
20
|
+
|
21
|
+
before_save do
|
22
|
+
self.title = attachment_file_name unless title
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// render partial
|
2
|
+
<% partial = render('lato_media/partials/media_selector/modal_form') %>
|
3
|
+
$('#media__media_selector .partials__media-selector-index-container').html('<%=j partial.html_safe %>')
|
4
|
+
|
5
|
+
// trigger event of change
|
6
|
+
$('#media__media_selector').trigger('loadIndexAction')
|
7
|
+
|
8
|
+
// initialize inputs
|
9
|
+
InputsInitializer.init()
|
@@ -0,0 +1,6 @@
|
|
1
|
+
// render partial
|
2
|
+
<% partial = render('lato_media/partials/media_selector/modal_index') %>
|
3
|
+
$('#media__media_selector .partials__media-selector-index-container').html('<%=j partial.html_safe %>')
|
4
|
+
|
5
|
+
// trigger event of change
|
6
|
+
$('#media__media_selector').trigger('loadIndexAction')
|
@@ -0,0 +1,6 @@
|
|
1
|
+
// find preview
|
2
|
+
var preview = $('#inputs-gallery-<%= @id %>').find('.inputs-gallery__preview')
|
3
|
+
|
4
|
+
// update preview
|
5
|
+
<% preview = LatoMedia::Elements::Previews::Cell.new(medias: @medias, url: '#', onclick: "MediaSelector.open('#{@id}', 99, event);") %>
|
6
|
+
$(preview).html('<%=j preview.show.html_safe %>')
|
@@ -0,0 +1,6 @@
|
|
1
|
+
// find preview
|
2
|
+
var preview = $('#inputs-media-<%= @id %>').find('.inputs-media__preview')
|
3
|
+
|
4
|
+
// update preview
|
5
|
+
<% preview = LatoMedia::Elements::Preview::Cell.new(media: @media, url: '#', onclick: "MediaSelector.open('#{@id}', 1, event);") %>
|
6
|
+
$(preview).html('<%=j preview.show.html_safe %>')
|