2014-05-14 11:52:06 +00:00
|
|
|
class Admin::ArchiveFilesController < OrbitAdminController
|
|
|
|
|
2014-05-08 06:03:33 +00:00
|
|
|
def index
|
2014-08-07 10:46:24 +00:00
|
|
|
@table_fields = [:status, :category, :title, :update_at,:last_modified]
|
2014-05-14 11:52:06 +00:00
|
|
|
@categories = @module_app.categories
|
|
|
|
@tags = @module_app.tags
|
2014-08-07 10:46:24 +00:00
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
2014-05-14 11:52:06 +00:00
|
|
|
|
2014-08-07 10:46:24 +00:00
|
|
|
@archives = ArchiveFile.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_tags(filters("tag"))
|
|
|
|
.with_status(filters("status"))
|
2014-05-14 11:52:06 +00:00
|
|
|
|
2014-08-07 10:46:24 +00:00
|
|
|
@archives = search_data(@archives,[:title]).page(params[:page]).per(10)
|
|
|
|
|
|
|
|
render :partial => "index" if request.xhr?
|
2014-05-14 11:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2014-08-07 10:46:24 +00:00
|
|
|
@archive_file = ArchiveFile.new
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories
|
2014-05-14 11:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2014-07-31 12:40:44 +00:00
|
|
|
@archive_file = ArchiveFile.find(params[:id])
|
|
|
|
if can_edit_or_delete?(@archive_file)
|
|
|
|
@tags = @module_app.tags
|
|
|
|
@categories = @module_app.categories
|
|
|
|
else
|
|
|
|
render_401
|
|
|
|
end
|
2014-05-14 11:52:06 +00:00
|
|
|
end
|
|
|
|
|
2014-08-07 10:46:24 +00:00
|
|
|
def create
|
2014-05-14 11:52:06 +00:00
|
|
|
@archive_file = ArchiveFile.new(archive_vars)
|
|
|
|
@archive_file.create_user_id = current_user.id
|
|
|
|
@archive_file.update_user_id = current_user.id
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @archive_file.save
|
|
|
|
format.html { redirect_to(admin_archive_files_path) }
|
|
|
|
format.xml { render :xml => @archive_file, :status => :created, :location => @archive_file }
|
|
|
|
else
|
|
|
|
@tags = @module_app.tags
|
|
|
|
format.html { render :action => "new" }
|
|
|
|
format.xml { render :xml => @archive_file.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# PUT /archive_files/1
|
|
|
|
# PUT /archive_files/1.xml
|
|
|
|
def update
|
|
|
|
@archive_file = ArchiveFile.find(params[:id])
|
2014-08-07 10:46:24 +00:00
|
|
|
|
2014-05-14 11:52:06 +00:00
|
|
|
@archive_file.update_user_id = current_user.id
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @archive_file.update_attributes(archive_vars)
|
|
|
|
format.html { redirect_to(admin_archive_files_path(:page => params[:page])) }
|
|
|
|
format.xml { head :ok }
|
|
|
|
else
|
|
|
|
format.html { render :action => "edit" }
|
|
|
|
format.xml { render :xml => @archive_file.errors, :status => :unprocessable_entity }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-03 10:56:02 +00:00
|
|
|
def destroy
|
|
|
|
archive_file = ArchiveFile.find(params[:id])
|
|
|
|
archive_file.destroy
|
|
|
|
redirect_to admin_archive_files_path
|
|
|
|
end
|
|
|
|
|
2014-05-14 11:52:06 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def archive_vars
|
2014-08-07 10:46:24 +00:00
|
|
|
params[:archive_file][:tags] ||=[]
|
|
|
|
params.require(:archive_file).permit!
|
2014-05-14 11:52:06 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup_vars
|
2014-08-07 10:46:24 +00:00
|
|
|
@module_app = ModuleApp.where(:key => "archive").first
|
2014-05-14 11:52:06 +00:00
|
|
|
end
|
|
|
|
def sort
|
|
|
|
unless params[:sort].blank?
|
|
|
|
case params[:sort]
|
|
|
|
when "status"
|
|
|
|
@sort = [[:is_top, params[:order]],
|
|
|
|
[:is_hot, params[:order]],
|
|
|
|
[:is_hidden,params[:order]]]
|
|
|
|
when "category"
|
|
|
|
@sort = {:category_id=>params[:order]}
|
|
|
|
when "title"
|
|
|
|
@sort = {:title=>params[:order]}
|
|
|
|
when "last_modified"
|
|
|
|
@sort = {:update_user_id=>params[:order]}
|
2014-08-07 10:46:24 +00:00
|
|
|
end
|
2014-05-14 11:52:06 +00:00
|
|
|
else
|
|
|
|
@sort = {:created_at=>'desc'}
|
|
|
|
end
|
|
|
|
@sort
|
2014-05-08 06:03:33 +00:00
|
|
|
end
|
|
|
|
end
|