Class | Admin::PhotosController
In: | app/controllers/admin/photos_controller.rb
Parent: | Sadmin::BaseController

### Methods

add_to_album auto_complete_for_photo_tag_list_es batch_edit batch_update create destroy edit find_photos orphane show update

### Public Instance methods

add_to_album()

[Source]

         # File app/controllers/admin/photos_controller.rb, line 89
     89:   def add_to_album
     90:     @photo = Photo.find(params[:id])
     91:     respond_to do |format|
     92:       format.js do
     93:         render :update do |page|
     94:           if params[:album_id].present?
     95:             @photo.albums << Album.find(params[:album_id])
     96:             page.replace "albums_for_#{@photo.id}", :partial => "albums_select", :locals => {:photo => @photo}
     97:           end
     98:           page.visual_effect :highlight, "albums_for_#{@photo.id}"
     99:         end
    100:       end
    101:     end
    102:   end

auto_complete_for_photo_tag_list_es()

[Source]

         # File app/controllers/admin/photos_controller.rb, line 146
    146:   def auto_complete_for_photo_tag_list_es
    147:     auto_complete_for_tag_list(params[:photo][:tag_list_es])
    148:     if @tags.length > 0
    149:       render :inline => "<%= content_tag(:ul, @tags.map {|t| content_tag(:li, t.nombre)}) %>"
    150:     else
    151:       render :nothing => true
    152:     end
    153:   end

batch_edit()

[Source]

        # File app/controllers/admin/photos_controller.rb, line 64
    64:   def batch_edit
    65:     @photos = Photo.find(params[:ids])
    66:   end

batch_update()

[Source]

        # File app/controllers/admin/photos_controller.rb, line 68
    68:   def batch_update
    69:     @photos = Photo.find(params[:photos].keys.collect(&:to_i))
    70:
    71:     if params[:cancel].blank?
    72:       begin
    73:         Photo.transaction do
    74:           @photos.each do |photo|
    75:             photo.update_attributes!(params[:photos][photo.id.to_s])
    76:           end
    77:           flash[:notice] = "Las fotos se han actualizado correctamente"
    78:           redirect_to admin_albums_path
    79:         end
    80:       rescue
    81:         flash[:error] = "Las fotos no se han actualizado"
    82:         render :action => "batch_edit"
    83:       end
    84:     else
    85:       redirect_to admin_albums_path
    86:     end
    87:   end

create()

[Source]

        # File app/controllers/admin/photos_controller.rb, line 26
    26:   def create
    27:     @photo = Photo.new(params[:photo].merge(:file_path => params[:dir_path], :dir_path => params[:dir_path]))
    28:
    29:     if @photo.valid? && params[:dir_path].present?
    30:       if params[:album_id].to_i == 0
    31:         album_title = params[:dir_path].camelize
    32:         @album = Album.create(:title_es => album_title, :title_eu => album_title, :title_en => album_title)
    33:       else
    34:         @album = Album.find(params[:album_id])
    35:       end
    36:
    37:       import_photos
    38:     else
    39:       logger.info "AAAAAAAAAAA"
    40:       @photo.errors.add_to_base("No ha indicado ningún directorio") if params[:dir_path].blank?
    41:       render :action => "new" and return
    42:     end
    43:   end

destroy()

[Source]

         # File app/controllers/admin/photos_controller.rb, line 126
    126:   def destroy
    127:     @album = Album.find(params[:album_id]) if params[:album_id]
    128:     @photo = Photo.find(params[:id])
    129:     if @photo.destroy
    130:       flash[:notice] = "La foto ha sido eliminada"
    131:       if @album
    132:         redirect_to admin_album_path(@album)
    133:       else
    134:         redirect_to orphane_admin_photos_path
    135:       end
    136:     else
    137:       flash[:error] = "La foto no ha podido ser eliminada"
    138:       if @album
    139:         redirect_to admin_album_photo_path(@album, @photo)
    140:       else
    141:         redirect_to orphane_admin_photos_path
    142:       end
    143:     end
    144:   end

edit()

[Source]

        # File app/controllers/admin/photos_controller.rb, line 45
    45:   def edit
    46:     @album = Album.find(params[:album_id]) if params[:album_id]
    47:     @photo = Photo.find(params[:id])
    48:   end

find_photos()

[Source]

         # File app/controllers/admin/photos_controller.rb, line 104
    104:   def find_photos
    105:     p = Photo.new(:dir_path => params[:dir_path])
    106:     if !p.valid? && p.errors.on("dir_path")
    107:       render :update do |page|
    108:         page.replace_html :find_photos, :text => "<span style='color:red'>Directorio incorrecto.<br/> #{p.errors.on('dir_path')}</span>"
    109:       end
    110:     else
    111:       dir = Photo::PHOTOS_PATH
    112:
    113:       logger.info "Buscando fotos #{dir + params[:dir_path] + "*.jpg"}"
    114:       if (found_files = Dir.glob(dir + params[:dir_path] + "*.jpg") + Dir.glob(dir + params[:dir_path] + "solo_irekia/*.jpg")) && found_files.length>0
    115:         render :update do |page|
    116:           page.replace_html :find_photos, :text => "<span style='color:green'>#{found_files.length} fotos encontradas</span>"
    117:         end
    118:       else
    119:         render :update do |page|
    120:           page.replace_html :find_photos, :text => "<span style='color:red'>fotos NO encontradas</span>"
    121:         end
    122:       end
    123:     end
    124:   end

orphane()

before_filter :get_album, :only => [:destroy, :update]

[Source]

        # File app/controllers/admin/photos_controller.rb, line 8
     8:   def orphane
     9:     @photos = Photo.paginate :page => params[:page], :order => "created_at DESC",
    10:       :conditions => "NOT EXISTS (SELECT 1 FROM album_photos WHERE album_photos.photo_id=photos.id)"
    11:   end

show()

[Source]

        # File app/controllers/admin/photos_controller.rb, line 13
    13:   def show
    14:     if params[:album_id]
    15:       @album = Album.find(params[:album_id])
    16:       @photo = @album.photos.find(params[:id])
    17:
    18:       all_photos = @album.photos.ordered_by_title
    19:       @next_photo = all_photos[all_photos.index(@photo) + 1]
    20:       @prev_photo = all_photos[all_photos.index(@photo) - 1] unless all_photos.index(@photo) == 0
    21:     else
    22:       @photo = Photo.find(params[:id])
    23:     end
    24:   end

update()

[Source]

        # File app/controllers/admin/photos_controller.rb, line 50
    50:   def update
    51:     @album = Album.find(params[:album_id]) if params[:album_id]
    52:     @photo = Photo.find(params[:id])
    53:     if @photo.update_attributes(params[:photo])
    54:       if @album && @album.photos.exists?(@photo.id)
    55:         redirect_to admin_photo_path(@photo, :album_id => @album.id)
    56:       else
    57:         redirect_to admin_photo_path(@photo)
    58:       end
    59:     else
    60:       render :action => "new"
    61:     end
    62:   end

[Validate]