# -*- encoding : utf-8 -*-
class Admin::AlbumsController < ApplicationController

  def new
    @album = Album.new(:album_folder_id => params[:album_folder_id])
  end

  def create
    @album = Album.new(params.require(:album).permit!)
    @album_create = true
    
    if @album.save
      @albums = Album.all.order(:name)
    else
      render :action => :new
    
    end
  end

  def edit
    @album = Album.find(params[:id])  
  end

  def update
    @album = Album.find(params[:id])
    @album_update = true
    params[:remote] = true
    if @album.update_attributes(params.require(:album).permit!)
      @albums = Album.all
    else
      render :action => :edit
    
    end
  end

  def destroy
    @album = Album.find(params[:id])
    if @album.id != 1
      @album.delete
    end
  end
  
  def change_album
    @album = Album.find(params[:id])
    
    @image_files = ImageFile.where(:id => params[:image_files_id])
    
    past_album = @image_files[0].album
    
    @image_files.update_all :album_id => @album.id
    
    if past_album
      past_album.update_image_count
    end
    @album.update_image_count
    
    
    render :inline => "ok"
    
  end

end
