Class Admin::VideosController
In: app/controllers/admin/videos_controller.rb
Parent: Sadmin::BaseController

Controlador para la administración de videos de la WebTV

Methods

Public Instance methods

Lista de tags para el auto-complete

[Source]

     # File app/controllers/admin/videos_controller.rb, line 125
125:   def auto_complete_for_video_tag_list_es
126:     auto_complete_for_tag_list(params[:video][:tag_list_es])
127:     if @tags.length > 0
128:       render :inline => "<%= content_tag(:ul, @tags.map {|t| content_tag(:li, t.nombre)}) %>"
129:     else
130:       render :nothing => true
131:     end  
132:   end

Crear un video

[Source]

    # File app/controllers/admin/videos_controller.rb, line 48
48:   def create
49:     @title = "Crear video"
50:     @video = Video.new(params[:video])
51:     
52:     if @video.save
53:       flash[:notice] = 'El video se ha guardado correctamente'
54:       redirect_to admin_video_path(@video)
55:     else
56:       render :action => 'new'
57:     end
58:   end

Eliminar un video

[Source]

    # File app/controllers/admin/videos_controller.rb, line 79
79:   def destroy
80:     @video = Video.find(params[:id])
81:     if @video.destroy
82:       flash[:notice] = "El video ha sido eliminado"
83:       redirect_to admin_videos_path
84:     else
85:       flash[:error] = "No hemos podido eliminar el video"
86:       redirect_to admin_video_path(@video)
87:     end
88:   end

Modificar un video

[Source]

    # File app/controllers/admin/videos_controller.rb, line 61
61:   def edit
62:     @title = "Modificar video"
63:     @video = Video.find(params[:id])
64:   end

Buscar el video en la ruta especificada

[Source]

     # File app/controllers/admin/videos_controller.rb, line 91
 91:   def find_video
 92:     v = Video.new(:video_path => params[:video_path])
 93:     if !v.valid? && v.errors.on("video_path")
 94:       render :update do |page|
 95:         page.replace_html :find_video, :text => "<span style='color:red'>Directorio incorrecto.<br/> #{v.errors.on('video_path')}</span>"
 96:       end
 97:     else        
 98:       logger.info "Buscando videos en #{Video::VIDEO_PATH + params[:video_path] + '*.flv'}"
 99:       found_videos = Video.videos_in_dir(params[:video_path])
100:       if found_videos.length > 0
101:         found_preview_photo = File.exists?("#{Video::VIDEO_PATH + params[:video_path]}.jpg")
102:         render :update do |page|
103:           page.replace_html :find_video, :text => "<span style='color:green'>#{found_videos.length} videos encontrados</span>"
104:           if found_preview_photo
105:             page.insert_html :bottom, :find_video, :text => ". <span style='color:green'>Foto para el preview encontrada</span>"
106:           else
107:             page.insert_html :bottom, :find_video, :text => ". <span style='color:red'>Foto para el preview NO encontrada</span>"
108:           end
109:         end
110:       else
111:         if File.exists?("#{Video::VIDEO_PATH + params[:video_path]}.jpg")
112:           render :update do |page|
113:             page.replace_html :find_video, :text => "<span style='color:green'>1 imagen encontrada</span>"
114:           end
115:         else
116:           render :update do |page|
117:             page.replace_html :find_video, :text => "<span style='color:red'>video NO encontrado</span>"
118:           end
119:         end
120:       end
121:     end
122:   end

Listado de videos

[Source]

    # File app/controllers/admin/videos_controller.rb, line 10
10:   def index
11:     @sort_order = params[:sort] ||  "update"
12:     
13:     case @sort_order
14:     when "update"
15:       order = "featured DESC, updated_at DESC, title_es, published_at DESC"
16:     when "publish"
17:       order = "featured DESC, published_at DESC, title_es, updated_at DESC"
18:     when "title"
19:       order = "featured DESC, lower(tildes(title_es)), published_at DESC, updated_at DESC"
20:     end
21:     
22:     conditions = []
23:     if params[:q].present?
24:       conditions << "lower(tildes(coalesce(title_es, '') || ' ' || coalesce(title_eu, ''))) like '%#{params[:q].tildes.downcase}%'"
25:     end   
26: 
27:     @videos = Video.paginate :page => params[:page], :per_page => 20, 
28:       :order => order,
29:       :conditions => conditions.join(' AND ')
30: 
31:     @title = "Videos"
32:     
33:   end

Formulario de nuevo video

[Source]

    # File app/controllers/admin/videos_controller.rb, line 42
42:   def new
43:     @title = "Nuevo video"
44:     @video = Video.new
45:   end

Vista de un video

[Source]

    # File app/controllers/admin/videos_controller.rb, line 36
36:   def show
37:     @video = Video.find(params[:id])
38:     @title = @video.title
39:   end

Actualizar un video

[Source]

    # File app/controllers/admin/videos_controller.rb, line 67
67:   def update
68:     @video = Video.find(params[:id])
69:     
70:     if @video.update_attributes(params[:video])
71:       flash[:notice] = 'El documento se ha guardado correctamente'
72:       redirect_to admin_video_path(@video)
73:     else
74:       render :action => params[:return_to] || 'edit'
75:     end
76:   end

[Validate]