From 55bdbb93b84264a2cb7adae54e062317ff288261 Mon Sep 17 00:00:00 2001 From: Nicolas Bally Date: Fri, 8 Jul 2011 17:41:12 +0200 Subject: [PATCH] gestion des cibles --- app/controllers/admin/cibles_controller.rb | 5 +++ app/controllers/admin/folders_controller.rb | 6 ++++ .../admin/menu_items_controller.rb | 33 +++++++++++++++++++ app/models/article.rb | 21 ++++++++++-- app/models/folder.rb | 19 +++++++++-- app/models/menus/menu_item.rb | 12 +++++-- app/views/admin/cibles/_cible_place.html.haml | 7 ++++ app/views/admin/cibles/index.html.haml | 1 + app/views/admin/cibles/index.js.erb | 2 ++ app/views/admin/folders/cible.html.haml | 11 +++++++ app/views/admin/menu_items/cible.html.haml | 6 ++++ 11 files changed, 115 insertions(+), 8 deletions(-) create mode 100644 app/views/admin/cibles/_cible_place.html.haml create mode 100644 app/views/admin/cibles/index.html.haml create mode 100644 app/views/admin/cibles/index.js.erb create mode 100644 app/views/admin/folders/cible.html.haml create mode 100644 app/views/admin/menu_items/cible.html.haml diff --git a/app/controllers/admin/cibles_controller.rb b/app/controllers/admin/cibles_controller.rb index 5f572ba..46aa4bb 100644 --- a/app/controllers/admin/cibles_controller.rb +++ b/app/controllers/admin/cibles_controller.rb @@ -2,6 +2,11 @@ class Admin::CiblesController < ApplicationController before_filter :authenticate_admin! + + def index + @cible_type = params[:cible_type] || "MenuItem" + @cible_id = params[:cible_id] || nil + end def new @resource = params[:resource_type].to_s.constantize.new() diff --git a/app/controllers/admin/folders_controller.rb b/app/controllers/admin/folders_controller.rb index bac8359..4ac2ceb 100644 --- a/app/controllers/admin/folders_controller.rb +++ b/app/controllers/admin/folders_controller.rb @@ -77,4 +77,10 @@ class Admin::FoldersController < ApplicationController flash[:notice] = "Le dossier à bien été supprimé." end + + def cible + @folders = Folder.all + + render :layout => false + end end diff --git a/app/controllers/admin/menu_items_controller.rb b/app/controllers/admin/menu_items_controller.rb index c016953..269d09f 100644 --- a/app/controllers/admin/menu_items_controller.rb +++ b/app/controllers/admin/menu_items_controller.rb @@ -170,5 +170,38 @@ class Admin::MenuItemsController < ApplicationController def show @menu_item= MenuItem.find(params[:id]) end + + def cible + + params[:menu_id] = params[:menu_id] || 1 + + if params[:menu_id] and params[:menu_id] != "" and @menu = Menu.find(params[:menu_id]) + + + params[:parent_id] = nil if !params[:parent_id] + + @menu_parent = MenuItem.find(params[:parent_id]) if params[:parent_id] + + + + @order = "position ASC" + + @menu_items = @menu.menu_items.where(:parent_id => params[:parent_id]).order(@order).page(magick_page()).per(magick_per_page()) + + if @menu_items.num_pages.to_i < magick_page().to_i + params[:page] = @menu_items.num_pages + @menu_items = @menu.menu_items.where(:parent_id => params[:parent_id]).order(@order).page(magick_page()).per(magick_per_page()) + end + + + + + else + redirect_to admin_root_path, :alert => "Un menu doit être séléctionné." + end + + render :layout => false + + end end diff --git a/app/models/article.rb b/app/models/article.rb index bcd3ae9..7d6767d 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -1,8 +1,10 @@ # -*- encoding : utf-8 -*- class Article < ActiveRecord::Base - belongs_to :image_file -belongs_to :folder - + include Rails.application.routes.url_helpers + + belongs_to :image_file + belongs_to :folder + after_create :after_creation @@ -15,6 +17,19 @@ belongs_to :folder validates :title, :presence => true validates :slug, :presence => true, :uniqueness => {:scope => :folder_id} + + def cible_url + + article_path(:slug => self.slug, :folder_slug => self.folder.slug) + + + end + + + def cible_name + "Article : #{self.title}" + end + def after_creation @block = Block.new(:block_name => "Contenu") @block.blockable = self diff --git a/app/models/folder.rb b/app/models/folder.rb index 21ad64d..c098f98 100644 --- a/app/models/folder.rb +++ b/app/models/folder.rb @@ -1,5 +1,7 @@ # -*- encoding : utf-8 -*- class Folder < ActiveRecord::Base + include Rails.application.routes.url_helpers + belongs_to :image_file @@ -14,6 +16,19 @@ class Folder < ActiveRecord::Base validates :title, :presence => true validates :slug, :presence => true, :uniqueness => true + + + def cible_url + + folder_path(:slug => self.slug) + + + end + + def cible_name + "Dossier : #{self.title}" + end + def after_creation @block = Block.new(:block_name => "en tête") @block.blockable = self @@ -21,9 +36,7 @@ class Folder < ActiveRecord::Base ContentType.all.each do |content_type| @block.content_types << content_type - - end - + end end before_validation do diff --git a/app/models/menus/menu_item.rb b/app/models/menus/menu_item.rb index ce5c74d..7d2cdcb 100644 --- a/app/models/menus/menu_item.rb +++ b/app/models/menus/menu_item.rb @@ -1,6 +1,8 @@ # -*- encoding : utf-8 -*- class MenuItem < ActiveRecord::Base - + + include Rails.application.routes.url_helpers + belongs_to :menu_content, :polymorphic => true belongs_to :menu validates :name, :presence => true @@ -22,6 +24,10 @@ class MenuItem < ActiveRecord::Base "/404.html" end end + + def cible_url + menu_item_path(:url => self.permalink) + end before_validation do self.slug = self.slug.to_slug @@ -88,7 +94,9 @@ class MenuItem < ActiveRecord::Base end - + def cible_name + "Elément de menu : #{self.name}" + end diff --git a/app/views/admin/cibles/_cible_place.html.haml b/app/views/admin/cibles/_cible_place.html.haml new file mode 100644 index 0000000..ebbc1da --- /dev/null +++ b/app/views/admin/cibles/_cible_place.html.haml @@ -0,0 +1,7 @@ +#select_cible_type_bar.bar.dark_blue + -CibleType.all.each do |cible_type| + =link_to cible_type.name, admin_cibles_path(:cible_type => cible_type.slug, :i_cible_type => params[:i_cible_type], :i_cible_id => params[:i_cible_id],:manager => params[:manager] ), :remote => true, :class => ("active" if cible_type.slug == @cible_type).to_s + + + +=auto_load_div(eval("cible_admin_#{@cible_type.tableize}_path(:i_cible_type => params[:i_cible_type], :i_cible_id => params[:i_cible_id],:manager => params[:manager])"),"cible_#{@cible_type}") \ No newline at end of file diff --git a/app/views/admin/cibles/index.html.haml b/app/views/admin/cibles/index.html.haml new file mode 100644 index 0000000..af03351 --- /dev/null +++ b/app/views/admin/cibles/index.html.haml @@ -0,0 +1 @@ +#cible_place= render :partial => "cible_place" diff --git a/app/views/admin/cibles/index.js.erb b/app/views/admin/cibles/index.js.erb new file mode 100644 index 0000000..9c67b54 --- /dev/null +++ b/app/views/admin/cibles/index.js.erb @@ -0,0 +1,2 @@ + +$('#cible_place').html("<%=escape_javascript(render(:partial => "cible_place"))%>"); \ No newline at end of file diff --git a/app/views/admin/folders/cible.html.haml b/app/views/admin/folders/cible.html.haml new file mode 100644 index 0000000..ad5230d --- /dev/null +++ b/app/views/admin/folders/cible.html.haml @@ -0,0 +1,11 @@ + +-Folder.all.each do |folder| + + %h4 + =folder.title + = link_to i(:check_alt, :gray_light,12), "#",:onclick => "manager_send_cible("+folder.id.to_s+", 'Folder', '#{escape_javascript(folder.cible_name)}');return false;" if params[:manager] + + -folder.articles.each do |article| + %p + =article.title + = link_to i(:check_alt, :gray_light,12), "#",:onclick => "manager_send_cible("+article.id.to_s+", 'Article', '#{escape_javascript(article.cible_name)}');return false;" if params[:manager] diff --git a/app/views/admin/menu_items/cible.html.haml b/app/views/admin/menu_items/cible.html.haml new file mode 100644 index 0000000..573721a --- /dev/null +++ b/app/views/admin/menu_items/cible.html.haml @@ -0,0 +1,6 @@ + +-@menu_items.each do |menu_item| + .menu_item_cible_line + =menu_item.name + = link_to i(:check_alt, :gray_light,12), "#",:onclick => "manager_send_cible("+menu_item.id.to_s+", 'MenuItem', '#{escape_javascript(menu_item.cible_name)}');return false;" if params[:manager] + \ No newline at end of file