sibu 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: de5cda6f4ef051d7e724abb03090d7cb7057edba
4
- data.tar.gz: 0d768bddd8641ec038babb501e9d7a9b78f1e60b
3
+ metadata.gz: b7888abe9ddb32391de3695fe43f06a5e4d6cb95
4
+ data.tar.gz: e14e12d53f591b8c2ca71599de672d56e8422d92
5
5
  SHA512:
6
- metadata.gz: 473a8590fe208a18be9f598bc0f5d3cbbdb712d631c135b71e95e65547999dd4da57e9d9b9c2a9027e7a5a072d63704727ad0e060d19793e57295e675664e8f3
7
- data.tar.gz: 80adac713e3c3bedf4da2a37a3941403fc546b434b6997e24dc2262388fb128b4f601cc3b4a623f29365e9bd8adbfe0727263a0383746f78f50f2d34e294acea
6
+ metadata.gz: 5a06716af55ec6f6c0a12dcc4686bc7e549d0d13d02652c5b9b53f8626cfb054e22001629fe089f3dd382d3cc67c96eac03e330759584239ca64833103862408
7
+ data.tar.gz: 6e0de7ab878681deaa8f35e3bcc5649511a52f986ea6787bf7b4e1ace4d4bdc06d1e2bfc0c6b70dbf0e7efc109430b25f7fb94040d99664b622a1f136ef35f66
@@ -2,7 +2,8 @@ require_dependency "sibu/application_controller"
2
2
 
3
3
  module Sibu
4
4
  class ImagesController < ApplicationController
5
- before_action :set_site, only: [:index, :new, :create, :edit]
5
+ before_action :set_site, only: [:index, :new, :create, :edit, :update, :destroy]
6
+ before_action :set_image, only: [:edit, :update, :destroy]
6
7
  before_action :set_edition_context, only: [:new, :create]
7
8
 
8
9
  def index
@@ -16,7 +17,7 @@ module Sibu
16
17
  def create
17
18
  @image = Sibu::Image.new(image_params)
18
19
  if @image.save
19
- if @page_id && @section_id && @element_id && @size
20
+ if !@page_id.blank? && !@section_id.blank? && !@element_id.blank? && !@size.blank?
20
21
  entity = @entity_type == 'site' ? @site : Sibu::Page.find(@page_id)
21
22
  ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
22
23
  elt = entity.update_element(*ids, {"id" => @img_id, "src" => @image.file_url(@size.to_sym), "alt" => @image.alt})
@@ -42,9 +43,17 @@ module Sibu
42
43
  end
43
44
 
44
45
  def update
46
+ if @image.update(image_params)
47
+ redirect_to site_images_url(@site.id), notice: "L'image a bien été mise à jour."
48
+ else
49
+ flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de l'image."
50
+ render :index
51
+ end
45
52
  end
46
53
 
47
54
  def destroy
55
+ @image.destroy
56
+ redirect_to site_images_url(@site.id), notice: "L'image a bien été supprimée."
48
57
  end
49
58
 
50
59
  private
@@ -53,6 +62,10 @@ module Sibu
53
62
  @site = Sibu::Site.find(params[:site_id])
54
63
  end
55
64
 
65
+ def set_image
66
+ @image = Sibu::Image.find(params[:id])
67
+ end
68
+
56
69
  def set_edition_context
57
70
  @page_id = params[:page_id]
58
71
  @entity_type = params[:entity_type]
@@ -0,0 +1,17 @@
1
+ <div class="sibu_image_preview">
2
+ <%= image_tag @image.file_url(:medium) %>
3
+ </div>
4
+ <%= form_for([@site, @image]) do |f| %>
5
+ <div class="sibu_field">
6
+ <%= f.label :alt, "Légende / texte alternatif" %>
7
+ <div>
8
+ <%= f.text_field :alt %>
9
+ <small>Renseignez un texte décrivant l'image</small>
10
+ </div>
11
+ </div>
12
+ <%= f.hidden_field :site_id %>
13
+ <div class="sibu_actions">
14
+ <%= f.submit 'Mettre à jour' %>
15
+ <%= link_to 'Supprimer', site_image_path(@image.site_id, @image.id), method: :delete, data: {confirm: "Supprimer l'image ?", disable_with: "Suppression en cours..."} %>
16
+ </div>
17
+ <% end %>
@@ -22,7 +22,7 @@
22
22
  <%= hidden_field_tag :img_id, @img_id %>
23
23
  <%= hidden_field_tag :size, @size %>
24
24
  <div class="sibu_actions">
25
- <%= f.submit 'Valider' %>
25
+ <%= f.submit 'Valider', data: {disable_with: "Téléchargement de l'image en cours..."} %>
26
26
  <%= link_to 'Annuler', :back %>
27
27
  </div>
28
28
  <% end %>
@@ -0,0 +1,3 @@
1
+ $(".sibu_edit_image").html("<%= j(render 'edit_form') %>");
2
+ $(".sibu_image").removeClass("selected");
3
+ $("<%= "#sibu_image_#{@image.id}" %>").addClass("selected");
@@ -3,8 +3,11 @@
3
3
  <%= link_to 'Télécharger une image', new_site_image_path(@site.id) %> <%= link_to 'Retour', :back %>
4
4
  </div>
5
5
  <h2>Images du site "<%= @site.name %>"</h2>
6
- <% @images.each do |image| %>
7
- <div class="sibu_image"><%= image_tag image.file_url(:small) %></div>
8
- <% end %>
6
+ <div class="sibu_images">
7
+ <% @images.each do |image| %>
8
+ <%= link_to image_tag(image.file_url(:small)), edit_site_image_path(@site.id, image.id), class: 'sibu_image', id: "sibu_image_#{image.id}", remote: true %>
9
+ <% end %>
10
+ </div>
11
+ <div class="sibu_edit_image">Sélectionnez une image pour voir ses informations.</div>
9
12
  </div>
10
13
 
@@ -20,8 +20,8 @@
20
20
  <td><%= l p.updated_at %></td>
21
21
  <td colspan="2">
22
22
  <%= link_to 'Voir', site_page_path(@site.id, p), target: '_blank' %> |
23
- <%= link_to 'Editer', site_page_edit_content_path(site_id: @site.id, page_id: p.id) %> |
24
- <%= link_to 'Modifier', edit_site_page_path(@site.id, p) %> |
23
+ <%= link_to 'Modifier', site_page_edit_content_path(site_id: @site.id, page_id: p.id) %> |
24
+ <%= link_to 'Paramétrer', edit_site_page_path(@site.id, p) %> |
25
25
  <%= link_to 'Supprimer', site_page_path(@site.id, p), method: :delete, data: {confirm: "Supprimer la page \"#{p.name}\" ?"} %>
26
26
  </td>
27
27
  </tr>
data/lib/sibu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sibu
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sibu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain
@@ -152,8 +152,9 @@ files:
152
152
  - app/views/layouts/sibu/application.html.erb
153
153
  - app/views/layouts/sibu/edit_content.html.erb
154
154
  - app/views/layouts/sibu/site.html.erb
155
+ - app/views/sibu/images/_edit_form.html.erb
155
156
  - app/views/sibu/images/_form.html.erb
156
- - app/views/sibu/images/edit.html.erb
157
+ - app/views/sibu/images/edit.js.erb
157
158
  - app/views/sibu/images/index.html.erb
158
159
  - app/views/sibu/images/new.html.erb
159
160
  - app/views/sibu/images/show.html.erb
@@ -1,2 +0,0 @@
1
- <h1>Images#edit</h1>
2
- <p>Find me in app/views/sibu/images/edit.html.erb</p>