From 9f14e9accf0c3c9fd49bfa1d67afc96e90a74cf9 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Fri, 8 Jul 2011 17:38:26 +0200 Subject: [PATCH] ajout img_link_content --- .../stylesheets/admin/portlets.css.scss | 14 +++ app/assets/stylesheets/public/public.css.scss | 16 +++ .../portlet/img_link_contents_controller.rb | 112 ++++++++++++++++++ app/models/portlets/img_link_content.rb | 35 ++++++ .../portlet/img_link_contents/_form.html.haml | 21 ++++ .../_img_link_content.html.haml | 16 +++ .../render_public/_imglinkcontent.html.haml | 27 +++++ ...20110630181623_create_img_link_contents.rb | 21 ++++ 8 files changed, 262 insertions(+) create mode 100644 app/assets/stylesheets/admin/portlets.css.scss create mode 100644 app/controllers/portlet/img_link_contents_controller.rb create mode 100644 app/models/portlets/img_link_content.rb create mode 100644 app/views/portlet/img_link_contents/_form.html.haml create mode 100644 app/views/portlet/img_link_contents/_img_link_content.html.haml create mode 100644 app/views/portlets/render_public/_imglinkcontent.html.haml create mode 100644 db/migrate/20110630181623_create_img_link_contents.rb diff --git a/app/assets/stylesheets/admin/portlets.css.scss b/app/assets/stylesheets/admin/portlets.css.scss new file mode 100644 index 0000000..211a173 --- /dev/null +++ b/app/assets/stylesheets/admin/portlets.css.scss @@ -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; } } \ No newline at end of file diff --git a/app/assets/stylesheets/public/public.css.scss b/app/assets/stylesheets/public/public.css.scss index f2fcb74..510f302 100644 --- a/app/assets/stylesheets/public/public.css.scss +++ b/app/assets/stylesheets/public/public.css.scss @@ -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%; diff --git a/app/controllers/portlet/img_link_contents_controller.rb b/app/controllers/portlet/img_link_contents_controller.rb new file mode 100644 index 0000000..89b8bd6 --- /dev/null +++ b/app/controllers/portlet/img_link_contents_controller.rb @@ -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 diff --git a/app/models/portlets/img_link_content.rb b/app/models/portlets/img_link_content.rb new file mode 100644 index 0000000..5d7eaaa --- /dev/null +++ b/app/models/portlets/img_link_content.rb @@ -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 diff --git a/app/views/portlet/img_link_contents/_form.html.haml b/app/views/portlet/img_link_contents/_form.html.haml new file mode 100644 index 0000000..82cceab --- /dev/null +++ b/app/views/portlet/img_link_contents/_form.html.haml @@ -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" + + diff --git a/app/views/portlet/img_link_contents/_img_link_content.html.haml b/app/views/portlet/img_link_contents/_img_link_content.html.haml new file mode 100644 index 0000000..ed06422 --- /dev/null +++ b/app/views/portlet/img_link_contents/_img_link_content.html.haml @@ -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 \ No newline at end of file diff --git a/app/views/portlets/render_public/_imglinkcontent.html.haml b/app/views/portlets/render_public/_imglinkcontent.html.haml new file mode 100644 index 0000000..673a185 --- /dev/null +++ b/app/views/portlets/render_public/_imglinkcontent.html.haml @@ -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 + diff --git a/db/migrate/20110630181623_create_img_link_contents.rb b/db/migrate/20110630181623_create_img_link_contents.rb new file mode 100644 index 0000000..ab0f672 --- /dev/null +++ b/db/migrate/20110630181623_create_img_link_contents.rb @@ -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