ajout img_link_content

This commit is contained in:
Nicolas Bally 2011-07-08 17:38:26 +02:00
parent ec09f45d78
commit 9f14e9accf
8 changed files with 262 additions and 0 deletions

View File

@ -0,0 +1,14 @@
.img_link_portlet {
padding: 10px;
margin-bottom: 10px;
h3 {
color: RGB(91, 67, 46); }
.image_file {
float: left;
margin-right: 10px; }
.title, .description {
margin-left: 130px; }
.title a, .description a {
color: #604435;
text-decoration: none; } }

View File

@ -340,6 +340,22 @@ text-align:center;
color: #604435;
text-decoration: #604435; }
.img_link_portlet{
border: 1px solid RGB(91, 67, 46);
padding: 10px;
margin-bottom: 10px;
h3 {
color: RGB(91, 67, 46); }
.image_file {
float: left;
margin-right: 10px; }
.title, .description {
margin-left: 130px; }
.title a, .description a {
color: #604435;
text-decoration: none; } }
.portlet {
&.table_content table {
width: 100%;

View File

@ -0,0 +1,112 @@
# -*- encoding : utf-8 -*-
class Portlet::ImgLinkContentsController < ApplicationController
layout "admin"
def new
@img_link_content = ImgLinkContent.new
respond_to do |format|
format.html {
if request.xhr?
render :layout => false
end
}
format.js { render :template => "portlet/shared/new" }
end
end
def create
@img_link_content = ImgLinkContent.new(params[:img_link_content])
respond_to do |format|
if @img_link_content.save
@portlet = Portlet.create(:content => @img_link_content)
format.html { redirect_to([:admin, @portlet.block.blockable], :notice => 'Elément ajouté avec succès.') }
format.js { render :template => "portlet/shared/create" }
else
format.html { render :action => "new" }
format.js { render :template => "portlet/shared/new" }
end
end
end
def edit
@img_link_content = ImgLinkContent.find(params[:id])
@portlet = @img_link_content.portlet
puts "TESt"
respond_to do |format|
format.html {
if request.xhr?
render :template => "portlet/shared/edit", :layout => false
end
}
format.js { render :template => "portlet/shared/edit" }
end
end
def show
end
def update
@img_link_content = ImgLinkContent.find(params[:id])
@portlet = @img_link_content.portlet
respond_to do |format|
if @img_link_content.update_attributes(params[:img_link_content])
format.html { redirect_to([:admin, @portlet.block.blockable], :notice => 'Titre mis à jour.') }
format.js { render :template => "portlet/shared/update" }
else
format.html { render :action => "portlet/shared/edit" }
format.js { render :template => "portlet/shared/edit" }
end
end
end
def destroy
@portlet = Portlet.find(params[:portlet_id])
@img_link_content = ImgLinkContent.find(params[:id])
@img_link_content.destroy
if @portlet.block and @portlet.block.blockable
@portlet.block.blockable.updated_at = Time.now
@portlet.block.blockable.save
if @portlet.block.blockable_type == "Page"
to_my_log("[Page_"+@portlet.block.blockable.id.to_s+"] "+"Modification de la page "+@portlet.block.blockable.title.to_s+" (suppression d'un portlet)")
end
end
respond_to do |format|
format.html {}
format.js { render :template => "portlet/shared/destroy" }
end
end
end

View File

@ -0,0 +1,35 @@
# -*- encoding : utf-8 -*-
class ImgLinkContent < ActiveRecord::Base
belongs_to :image_file
belongs_to :item
belongs_to :cible, :polymorphic => true
has_one :portlet, :as => :content, :dependent => :destroy
validates :title, :presence => true
accepts_nested_attributes_for :cible, :reject_if => lambda { |a| 1 == 1 }
before_validation do
if !self.with_cible
self.cible_type = nil
self.cible_id = nil
end
end
def url
if self.cible
cible.url
else
""
end
end
STYLES = [["Style 1",1], ["Style 2",2]]
end

View File

@ -0,0 +1,21 @@
= semantic_form_for [:portlet, @img_link_content], :remote => true do |form|
.form1
= form.inputs do
= form.input :image_file_id, :label => "Image :" , :as => :qi_image_select
= form.input :title, :label => "Title :" , :as => :string
= form.input :description, :label => "Description :", :as => :text, :input_html => {:class => "text_editor"}
= form.input :with_cible, :as => :boolean, :label => "Avec lien ?", :input_html => {:id => "with_cible", :onchange => "if ($(this).attr('checked') == 'checked') { $(this).closest('form').find('.cible_space').show(); }else{ $(this).closest('form').find('.cible_space').hide(); }" }
.cible_space{:style => ("display:none;" if !@img_link_content.cible and !@img_link_content.with_cible )}
= form.inputs do
= form.input :cible, :label => "Cible :" , :as => :qi_cible_select
= form.buttons do
= form.commit_button "Sauvegarder"

View File

@ -0,0 +1,16 @@
.img_link_portlet
.image_file
=image_tag(img_link_content.image_file.file.square.url) if img_link_content.image_file
.title
%h3=img_link_content.title
.description
= simple_format(img_link_content.description)
.clear
- if img_link_content.cible
%strong
Liens vers
= img_link_content.cible.cible_name

View File

@ -0,0 +1,27 @@
.img_link_portlet
- if input.cible
-url = input.cible.cible_url
.image_file
=link_to image_tag(input.image_file.file.square.url), url if input.image_file
.title
%h3=link_to input.title, url
.description
= link_to simple_format(input.description), url
.clear
-else
.image_file
=image_tag(input.image_file.file.square.url) if input.image_file
.title
%h3=input.title
.description
= simple_format(input.description)
.clear

View File

@ -0,0 +1,21 @@
class CreateImgLinkContents < ActiveRecord::Migration
def self.up
create_table :img_link_contents do |t|
t.text :title
t.text :description
t.references :image_file
t.integer :cible_id
t.string :cible_type
t.boolean :with_cible
t.timestamps
end
ContentType.create(:slug => "ImgLinkContent", :name => "Lien avec image")
end
def self.down
drop_table :img_link_contents
end
end