This commit is contained in:
Nicolas Bally 2016-02-16 10:32:04 +01:00
parent 12c0d91f5e
commit fea44b6c50
43 changed files with 627 additions and 117 deletions

View File

@ -204,4 +204,15 @@ function select_video_from_manager(input_id){
}
function select_realisation_images_from_manager(realisation_id){
manager_prompt("/admin/image_files/?manager=true&multiple=true",function(m_return){
$.ajax({url:"/admin/realisation_images/", type: "POST", data : { image_file_ids : m_return, realisation_id : realisation_id }});
});
}

View File

@ -64,11 +64,11 @@
.rea-gal{
padding-left:0px;
margin-right:-5px;
margin-bottom:-5px;
margin-right:-25px;
margin-bottom:-25px;
img{
padding-right:5px;
padding-bottom:5px;
padding-right:25px;
padding-bottom:25px;
width:200px;
float:left;
box-sizing: border-box;

View File

@ -171,4 +171,42 @@ h1,h2,h3{
}
}
.tag-gal{
.element{
float:left;
width:16%;
margin:2%;
text-align:center;
}
img{
width:100%;
border-radius:50%;
}
p{
margin:0;
}
}
.realisation_list{
padding-left:0px;
margin-right:-25px;
margin-bottom:-25px;
.realisation{
padding-right:25px;
padding-bottom:25px;
width:33%;
float:left;
box-sizing: border-box;
.img{
height:250px;
overflow:hidden;
width:100%;
background: no-repeat center center;
background-size:100%;
background-size:cover;
}
color:#8d8d8d;
}}

View File

@ -0,0 +1,82 @@
# -*- encoding : utf-8 -*-
class Admin::RealisationImagesController < ApplicationController
layout "admin"
def reorder
i = 0
params[:order].each do |realisation_image_id|
i += 1
realisation_image = RealisationImage.find(realisation_image_id)
realisation_image.position = i
realisation_image.save
end
end
def create
@realisation = Realisation.find(params[:realisation_id])
@realisation_images = []
if params[:image_file_ids].kind_of?(Array)
params[:image_file_ids].each do |image_file_id|
image_file = ImageFile.find(image_file_id)
realisation_image = RealisationImage.create(:image_file_id => image_file.id, :title => image_file.name, :description => image_file.description, :realisation_id => @realisation.id )
@realisation_images << realisation_image
end
end
respond_to do |format|
format.js
end
end
def edit
@realisation_image = RealisationImage.find(params[:id])
if request.xhr?
render :layout => false
end
end
def show
end
def update
@realisation_image = RealisationImage.find(params[:id])
respond_to do |format|
if @realisation_image.update_attributes(params.require(:realisation_image).permit!)
format.js
else
format.html { render :action => "edit", :layout => false}
format.js { render :action => "edit" }
end
end
end
def destroy
@realisation_image = RealisationImage.find(params[:id])
@realisation_image.destroy
end
end

View File

@ -0,0 +1,136 @@
# -*- encoding : utf-8 -*-
class Admin::RealisationsController < ApplicationController
before_filter :auth_admin
layout "admin"
before_filter :find_realisations
def index
end
def cible
@realisations = Realisation.all
render :layout => false
end
def new
@realisation = Realisation.new()
end
def edit
@realisation = Realisation.find(params[:id])
end
def show
@realisation = Realisation.find(params[:id])
end
def create
@realisation = Realisation.new(params.require(:realisation).permit!)
if @realisation.save
self.find_realisations
flash[:notice] = "La catégorie à été ajouté avec succès."
else
render :action => "new"
end
end
def update
@realisation = Realisation.find(params[:id])
@reorder = true if params[:reorder]
respond_to do |format|
if @realisation.update_attributes(params.require(:realisation).permit!)
#Realisation.all.each do |mi|
# mi.set_permalink
#end
flash[:notice] = "Le menu à été modifié avec succès."
format.html { redirect_to(admin_realisations_path(:parent_id => @realisation.parent_id)) }
if @reorder
format.js {
render :action => "update" }
else
format.js {
@realisation = Realisation.find(@realisation.id)
render :action => "update_row" }
end
else
flash[:error] = "Cet élément de menu n'a pas pu être déplacé. Vérifiez que son lien permanent n'éxiste pas déjà dans l'élément cible."
if @reorder
format.js { render :action => "update_reorder_failled" }
else
format.html { render :action => "edit" }
format.js { render :action => "edit" }
end
end
end
end
def destroy
@realisation = Realisation.find(params[:id])
@realisation.destroy
flash[:notice] = "Le produit à bien été supprimé."
end
protected
def find_realisations
@realisations = Realisation.all
end
end

View File

@ -0,0 +1,11 @@
# -*- encoding : utf-8 -*-
class Public::RealisationsController < ApplicationController
layout "public"
def show
@realisation = Realisation.find_by_slug(params[:id])
end
end

View File

@ -4,7 +4,7 @@ class DynamicContent < ActiveRecord::Base
belongs_to :item
NAMES = {"historique_monde" => "Historique monde"}
NAMES = {"realisations" => "Liste des réalisations"}
def self.picto
"cog"

View File

@ -4,7 +4,7 @@ class GalleryContent < ActiveRecord::Base
has_one :portlet, :as => :content, :dependent => :destroy
STYLES = [["Petites miniatures",1], ["Diaporama",2], ["Petits carrés",3], ["Réalisations",4]]
STYLES = [["Petits carrés",3],["Petites miniatures",1], ["\"Tags\"",4]]
def dup
@new = GalleryContent.new(self.attributes)

12
app/models/realisation.rb Normal file
View File

@ -0,0 +1,12 @@
class Realisation < ActiveRecord::Base
has_many :realisation_images, :dependent => :destroy
belongs_to :default_image, :class_name => "RealisationImage"
before_validation do
self.slug = self.title.to_slug
end
end

View File

@ -0,0 +1,26 @@
class RealisationImage < ActiveRecord::Base
belongs_to :image_file
belongs_to :realisation
after_save do
realisation_default_image
end
after_destroy do
realisation_default_image
end
def realisation_default_image
if !self.realisation.default_image
self.realisation.default_image = self.realisation.realisation_images.order("position").first
self.realisation.save
else
self.realisation.default_image = nil
self.realisation.save
end
end
end

View File

@ -0,0 +1,19 @@
= semantic_form_for [:portlet, @realisation_image], :remote => true do |form|
.content
%h3 Modifier les infos
= form.inputs do
= form.input :title, :label => "Titre :"
= form.input :tags, :label => "Tags :"
= form.input :description, :label => "Description :", :as => :text, :input_html => {:class => "text_editor"}
.actions
=form.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,9 @@
-if realisation_image.image_file
.realisation_image.image_square#realisation_image{:id => realisation_image.id, :data => { :title => realisation_image.title , :description => realisation_image.description, :id => realisation_image.id} }
.img{:style => "background-image : url('#{realisation_image.image_file.file.large.medium.small.thumb.url}');"}
.actions
=link_to i(:"trash-o"), [:admin, realisation_image], :data => {:confirm => 'Voulez-vous vraiment supprimer cette image ?'}, :method => :delete, :remote => true
=#link_to i(:pencil), edit_admin_realisation_image_path(realisation_image), :remote => true

View File

@ -0,0 +1 @@
$('#realisation_images').prepend("<%= escape_javascript(render(@realisation_images)) %>");

View File

@ -0,0 +1,4 @@
$("#realisation_image_<%= @realisation_image.id.to_s %>").fadeOut(500).delay(6000).remove();
<%= flash_js %>

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>");

View File

@ -0,0 +1,5 @@
close_pane_hover();
$('#realisation_image_<%= @realisation_image.id %>').effect("highlight", 1000);
<%= flash_js %>

View File

@ -0,0 +1,11 @@
= semantic_form_for [:admin,@realisation], :remote => true do |form|
.content
= form.input :title, :as => :string, :label => "Nom :"
= form.input :description, :label => "Descirption :"
.actions
= form.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -0,0 +1,9 @@
%table.table#realisations
%tr
%th
%th
Catégorie
%th
Nom du réalisation
%th
=render @realisations

View File

@ -0,0 +1,16 @@
%tr#realisation_row.realisation_row{:id => realisation.id}
%td{:style => "width:200px;"}
=image_tag realisation.default_image.image_file.file.large.medium.small.thumb.url if realisation.default_image
%td
=realisation.title
%td.actions
= link_to i(:"trash-o"), [:admin, realisation], :data =>{:remote => true, :confirm => 'Voulez-vous vraiment supprimer cet élément de menu ?'}, :method => :delete #, if current_admin.super_admin? || !realisation.super_admin
= link_to i(:eye), [:admin, realisation]
= link_to i(:pencil), edit_admin_realisation_path(realisation), :data => {:remote => true}

View File

@ -0,0 +1,6 @@
-Event.all.each do |event|
%h4
=event.title
= link_to i(:check_alt, :gray_light,12), "#",:onclick => "manager_send_cible("+event.id.to_s+", 'Folder', '#{escape_javascript(event.cible_name)}');return false;" if params[:manager]

View File

@ -0,0 +1,4 @@
$('#realisations').html("<%= escape_javascript(render(:partial => "index_block")) %>");
close_pane_hover();

View File

@ -0,0 +1,2 @@
$('#realisation_row_<%= @realisation.id %>').remove();
<%= flash_js %>

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",550,600);

View File

@ -0,0 +1,6 @@
.header
.right= link_to 'Ajouter un réalisation', new_admin_realisation_path, :class => "btn btn-success", :remote => true
%h1 Liste des réalisations
.padding
=render :partial => "index_block"

View File

@ -0,0 +1,13 @@
if($('#realisation_index').length > 0){
$('#realisation_index').replaceWith("<%= escape_javascript(render(:partial => "index_block")) %>");
}
else{
$('body').html("<%= escape_javascript(render(:template => 'admin/realisations/index.html.haml')) %>");
}

View File

@ -0,0 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "form"))%>",550,600);

View File

@ -0,0 +1,59 @@
.header
%h1
Réalisation
="|"
=@realisation.title
.padding
%p
=link_to "Ajouter des images", "#", :onclick => "select_realisation_images_from_manager('#{@realisation.id.to_s}');return false;", :class => "btn btn-primary"
%br
#realisation_images
=render :collection => @realisation.realisation_images.order("position"), :partial => "admin/realisation_images/realisation_image"
%p{:style => "clear:both;"}
:coffeescript
adjustment = ""
$('#realisation_images').sortable({
itemSelector:".realisation_image",
containerSelector :"#realisation_images",
nested:true,
placeholder:"<div class='placeholder' style='display:inline-block;width:50px;height:170px;'></div>",
onDragStart: ($item, container, _super) ->
$("body").addClass("dragging")
offset = $item.offset()
pointer = container.rootGroup.pointer
adjustment = {
left: pointer.left - offset.left,
top: pointer.top - offset.top
}
onDrag: ($item, position, _super) ->
$item.css({
left: position.left - adjustment.left,
top: position.top - adjustment.top - $(window).scrollTop()
})
onDrop: ($item, container, _super) ->
$item.removeClass("dragged").removeAttr("style")
$("body").removeClass("dragging")
result = []
container.el.find(".realisation_image").each ->
result.push $(this).data("id")
$.ajax({
url:"/admin/realisation_images/reorder.js",
type: "GET",
data: {
order : result
}
})
});

View File

@ -0,0 +1,4 @@
$('#realisation_index').replaceWith("<%= escape_javascript(render(:partial => "index_block")) %>");
close_pane_hover();
<%= flash_js %>

View File

@ -0,0 +1,2 @@
$('#realisation_row_<%= @realisation.id %>').replaceWith("<%= escape_javascript(render(@realisation))%>");
close_pane_hover();

View File

@ -63,7 +63,8 @@
%li= link_to "Images", admin_image_files_path
%li= link_to "Fichiers", admin_data_files_path
=#%li= link_to "Vidéos", admin_video_files_path
=#%li= link_to "Sliders", admin_home_sliders_path
%li= link_to "Sliders", admin_home_sliders_path
%li= link_to "Réalisations", admin_realisations_path()

View File

@ -1,106 +0,0 @@
.timeline_container
.timeline_line
.timeline_block
.tm_date 1998
.tm_point
.tm_content
%ul
%li
%p
One Voice/Talis se mobilise aux côtés de PETA et des associations du monde entier en faveur des chiens de Taïwan et organise une action de sensibilisation sur le parvis du musée dOrsay. La campagne reçoit le soutien de nombreuses célébrités telles que Brad Pitt, Kim Basinger, Michelle Pfeiffer, Peter Falk, Burt Reynolds, Oliver Stone, Jacky Chan, Steven Seagal, Alec Baldwin et bien dautres.
%p
La mobilisation internationale aboutit au vote de la première loi de protection animale du pays et des mesures importantes en faveur des chiens errants sont prises.
.timeline_block
.tm_date 2002
.tm_point
.tm_content
%ul
%li
=image_tag "/historique/monde/2002.jpg"
%p
One Voice révèle le trafic de chiots et de chatons des pays de lEst, vendus illégalement en France après avoir transité en Belgique où leurs papiers sont falsifiés. Lassociation est accompagnée pour une partie de son enquête par des journalistes de France 2, France 5 et du Figaro. De très nombreux médias relaieront linformation.
%li
%p
Création avec Wildlife SOS du sanctuaire dAgra pour les ours en Inde (voir lhistorique de notre campagne pour les ours).
%li
%p
One Voice apporte son soutien à HELP Congo, au Congo Brazzaville, où Aliette Jamart réhabilite des chimpanzés à la vie sauvage ; ainsi quà ABC, au Congo Kinshasa, où Claudine André a créé le sanctuaire Lola ya Bonobo pour accueillir les bonobos orphelins sauvés du trafic et de la guerre.
%li
%p
Campagne pour les animaux du zoo de Kinshasa.
.timeline_block
.tm_date 2003
.tm_point
.tm_content
%ul
%li
=image_tag "/historique/monde/2003.jpg"
%p
Enquête au Vietnam dans les « fermes à bile » et sur les chiens tués pour leur viande.
%li
%p
En Inde, un programme de reconversion des Kalandars qui nous confient les ours en leur possession est initié, et la cellule antibraconnage ForestWatch est créée avec Wildlife SOS.
%li
%p
Une enquête exclusive de One Voice au Japon prouve pour la première fois le lien entre les massacres de Taiji et lindustrie de la captivité. (voir lhistorique de notre combat pour les cétacés)
%li
%p
One Voice enquête sur les élevages danimaux pour leur fourrure, en Croatie. Elle sauve 33 chinchillas et obtient la fermeture de la structure qui les élevait. (voir lhistorique de notre combat contre la fourrure)
%li
%p
One Voice enquête avec TF1 dans deux centres de transit belges pour le trafic de chiots et de chatons en provenance des pays de lEst. Une deuxième enquête la conduit jusquen Tchéquie via lEspagne. Elle sauvera une trentaine de chiots et chatons qui y sont nés.
.timeline_block
.tm_date 2004
.tm_point
.tm_content
%ul
%li
%p
Une enquête de One Voice révèle les conditions sordides délevage des chiens en Hongrie avant dêtre illégalement importés en France.
%li
=image_tag "/historique/monde/2004-2.jpg"
%p
One Voice fait à nouveau la preuve du trafic européen de chiots en remontant une filière de la France à la Slovaquie, en passant par lEspagne, où un entrepôt permet le transit de 500 chiots par mois. Son enquête fera lobjet dun sujet au Journal de 20 heures sur France 2.
%li
%p
Création du Fonds dAction Solidaire pour financer des interventions urgentes. À peine 15 jours plus tard, il permettra à nos vétérinaires de se rendre sur le terrain après le tsunami qui a ravagé lAsie du Sud-Est.
%li
=image_tag "/historique/monde/2004.jpg"
%p
Avec le soutien des autorités haïtiennes, One Voice supervise la libération de six dauphins et de six tortues qui avaient été capturés pour lindustrie des loisirs.
.timeline_block
.tm_date 2005
.tm_point
.tm_content
%ul
%li
=image_tag "/historique/monde/2005-1.jpg"
%p
One Voice répond à lappel durgence de lassociation Kalaweït qui sauve et réintroduit des gibbons en Indonésie. Le partenariat permet la création du sanctuaire dHampapak où vivent notamment des orangs-outans sauvages.
%li
=image_tag "/historique/monde/2005-3.jpg"
%p
Grâce au FAS, One Voice permet le sauvetage, avec Wildlife SOS, de nombreux animaux après les inondations et les torrents de boue qui ont dévasté lÉtat du Maharashtra en Inde. Cinq lions affamés sont notamment sortis du zoo où ils se mouraient pour être emmenés dans un centre de sauvetage.
%li
=image_tag "/historique/monde/2005-2.jpg"
%p
À la suite au tsunami, notre action continue. Un refuge mis en place à Port Blair permet dhéberger et de nourrir des animaux errants qui sont stérilisés et relâchés dès que leur état le permet. Au Sri Lanka, One Voice aide Turtle Conservation Project à reconstruire le sanctuaire marin qui a été dévasté. En Thaïlande, notre équipe vient en aide aux chiens errants qui survivaient grâce aux touristes.

View File

@ -0,0 +1,7 @@
.realisation_list
-Realisation.all.each do |realisation|
=link_to public_realisation_path(:id => realisation.slug) do
.realisation
.img{:style => "background-image :url('"+(realisation.default_image.image_file.file.large.medium.url if realisation.default_image).to_s+"');"}
%h3=realisation.title

View File

@ -74,6 +74,18 @@
-input.gallery_images.each do |gallery_images|
=link_to image_tag(gallery_images.image_file.file.square.url, :alt => "#{gallery_images.title}"), gallery_images.image_file.file.large.url, :title => gallery_images.title
.clear
-if input.style == 4
.portlet.input
.tag-gal
-input.gallery_images.each do |gallery_images|
.element
=image_tag(gallery_images.image_file.file.square.url, :alt => "#{gallery_images.title}")
%p
=gallery_images.title
.clear
-elsif input.style==2

View File

@ -0,0 +1,8 @@
.center
%h1=@realisation.title
=simple_format @realisation.description
.rea-gal
-@realisation.realisation_images.each do |realisation_images|
=link_to image_tag(realisation_images.image_file.file.square.url, :alt => "#{realisation_images.title}"), realisation_images.image_file.file.large.url, :title => realisation_images.title
.clear

View File

@ -1,5 +1,5 @@
Rails.application.routes.draw do
get "/realisations/:id.html" => "public/realisations#show", :as => :public_realisation
get "fr/newsletters/:id.html" => "public/newsletters#show", :as => :public_newsletter
get "/fr/assurance-vie.html"=> "public/home#assurance"
@ -22,8 +22,17 @@ Rails.application.routes.draw do
get "fr/presse" => "public/press_releases#index", :as => :public_press_releases
get "fr/presse/:id" => "public/press_releases#show", :as => :public_press_release
namespace :admin do
resources :donators
resources :donator_transactions
resources :realisation_images do
collection do
get :reorder
end
end
resources :realisations
end
namespace :admin do

View File

@ -0,0 +1,13 @@
class CreateRealisations < ActiveRecord::Migration
def change
create_table :realisations do |t|
t.string :title
t.text :description
t.string :slug
t.boolean :enabled
t.datetime :realised_at
t.integer :default_image_id
t.timestamps null: false
end
end
end

View File

@ -0,0 +1,13 @@
class CreateRealisationImages < ActiveRecord::Migration
def change
create_table :realisation_images do |t|
t.string :title
t.text :description
t.references :realisation, index: true
t.integer :position
t.references :image_file
t.timestamps null: false
end
add_foreign_key :realisation_images, :realisations
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160125135733) do
ActiveRecord::Schema.define(version: 20160216085123) do
create_table "admins", force: :cascade do |t|
t.string "name", limit: 255
@ -517,6 +517,29 @@ ActiveRecord::Schema.define(version: 20160125135733) do
t.datetime "updated_at", null: false
end
create_table "realisation_images", force: :cascade do |t|
t.string "title", limit: 255
t.text "description", limit: 65535
t.integer "realisation_id", limit: 4
t.integer "position", limit: 4
t.integer "image_file_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "realisation_images", ["realisation_id"], name: "index_realisation_images_on_realisation_id", using: :btree
create_table "realisations", force: :cascade do |t|
t.string "title", limit: 255
t.text "description", limit: 65535
t.string "slug", limit: 255
t.boolean "enabled", limit: 1
t.datetime "realised_at"
t.integer "default_image_id", limit: 4
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "registrants", force: :cascade do |t|
t.string "token", limit: 255
t.string "name", limit: 255
@ -684,5 +707,6 @@ ActiveRecord::Schema.define(version: 20160125135733) do
add_foreign_key "lang_pages", "lang_sites"
add_foreign_key "lang_pages", "pages"
add_foreign_key "menu_item_langs", "lang_sites"
add_foreign_key "realisation_images", "realisations"
add_foreign_key "video_files", "image_files"
end

11
test/fixtures/realisation_images.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
description: MyText
realisation_id:
two:
title: MyString
description: MyText
realisation_id:

15
test/fixtures/realisations.yml vendored Normal file
View File

@ -0,0 +1,15 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
description: MyText
slug: MyString
enabled: false
realised_at: 2016-02-16 09:50:31
two:
title: MyString
description: MyText
slug: MyString
enabled: false
realised_at: 2016-02-16 09:50:31

View File

@ -0,0 +1,7 @@
require 'test_helper'
class RealisationImageTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class RealisationTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end