Anexos aninhados
This commit is contained in:
@@ -19,6 +19,7 @@ require 'yaml'
|
|||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
include AuthenticationSystem
|
include AuthenticationSystem
|
||||||
|
helper :all
|
||||||
|
|
||||||
before_filter :startup
|
before_filter :startup
|
||||||
around_filter :set_timezone
|
around_filter :set_timezone
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class AttachmentsController < ApplicationController
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@attachment.course_id = @course.id
|
@attachment.course_id = @course.id
|
||||||
|
@attachment.path = params[:attachment][:path]
|
||||||
@attachment.description = params[:attachment][:description]
|
@attachment.description = params[:attachment][:description]
|
||||||
unless params[:attachment][:file].kind_of?(String)
|
unless params[:attachment][:file].kind_of?(String)
|
||||||
@attachment.file = params[:attachment][:file]
|
@attachment.file = params[:attachment][:file]
|
||||||
@@ -54,6 +55,7 @@ class AttachmentsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
@attachment.path = params[:attachment][:path]
|
||||||
@attachment.description = params[:attachment][:description]
|
@attachment.description = params[:attachment][:description]
|
||||||
unless params[:attachment][:file].kind_of?(String)
|
unless params[:attachment][:file].kind_of?(String)
|
||||||
@attachment.file = params[:attachment][:file]
|
@attachment.file = params[:attachment][:file]
|
||||||
|
|||||||
@@ -15,4 +15,55 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
module AttachmentsHelper
|
module AttachmentsHelper
|
||||||
|
|
||||||
|
def attachments_to_nested_hash(atts)
|
||||||
|
paths = atts.collect { |item| item.path.nil? ? [] : item.path.split("/") }
|
||||||
|
return nest_path(atts, paths, 0, paths.size-1, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def nest_path(items, paths, from, to, level)
|
||||||
|
result = {}
|
||||||
|
|
||||||
|
base = from - 1
|
||||||
|
base = base + 1 while base+1 <= to and paths[base+1][level].nil?
|
||||||
|
if base >= from then
|
||||||
|
result['/'] = items[from..base]
|
||||||
|
end
|
||||||
|
|
||||||
|
start = base+1
|
||||||
|
|
||||||
|
return result if start > to
|
||||||
|
|
||||||
|
folder = paths[start][level]
|
||||||
|
(base+1).upto(to) do |i|
|
||||||
|
if paths[i][level] != folder
|
||||||
|
result[folder] = nest_path(items, paths, start, i-1, level+1)
|
||||||
|
start = i
|
||||||
|
folder = paths[i][level]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if start <= to then
|
||||||
|
result[folder] = nest_path(items, paths, start, to, level+1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
def nested_attachments_to_html(atts, level=0)
|
||||||
|
out = (level > 0 ? "<ul class='nested' style='display: none'>" : "<ul>")
|
||||||
|
keys = atts.keys.sort
|
||||||
|
|
||||||
|
for att in atts['/'] do
|
||||||
|
out = out + "<li class='#{mime_class(att.content_type)}'>#{link_to h(att.file_name), course_attachment_url(@course, att)}</li>"
|
||||||
|
end if atts['/']
|
||||||
|
|
||||||
|
for key in keys - ['/'] do
|
||||||
|
out = out + "<li class='mime_folder' onclick='new Effect.toggle(this.next(), \"blind\"); return false;'>#{link_to h(key), '#'} </li>"
|
||||||
|
out = out + nested_attachments_to_html(atts[key], level+1)
|
||||||
|
end
|
||||||
|
|
||||||
|
out = out + "</ul>"
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ class Attachment < ActiveRecord::Base
|
|||||||
# modificar a descrição, ou algo assim..
|
# modificar a descrição, ou algo assim..
|
||||||
errors.add("file", "is needed"[]) if not self.id
|
errors.add("file", "is needed"[]) if not self.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
errors.add("path", "muito longo") if !@path.nil? and @path.split('/').size > 10
|
||||||
end
|
end
|
||||||
|
|
||||||
# Salva o arquivo fisicamente no HD
|
# Salva o arquivo fisicamente no HD
|
||||||
@@ -69,4 +71,5 @@ class Attachment < ActiveRecord::Base
|
|||||||
# @file_path = "#{RAILS_ROOT}/public/upload/#{course.id}/#{self.id}"
|
# @file_path = "#{RAILS_ROOT}/public/upload/#{course.id}/#{self.id}"
|
||||||
# File.delete(@file_path) if File.exists?(@file_path)
|
# File.delete(@file_path) if File.exists?(@file_path)
|
||||||
#end
|
#end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class Course < ActiveRecord::Base
|
|||||||
|
|
||||||
# Associacoes
|
# Associacoes
|
||||||
has_many :attachments,
|
has_many :attachments,
|
||||||
:order => "file_name",
|
:order => "path, file_name",
|
||||||
:dependent => :destroy
|
:dependent => :destroy
|
||||||
|
|
||||||
has_many :events,
|
has_many :events,
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
%p.grey= "Tamanho máximo: #{number_to_human_size(App.max_upload_file_size)}"
|
%p.grey= "Tamanho máximo: #{number_to_human_size(App.max_upload_file_size)}"
|
||||||
%dd= file_field 'attachment', 'file'
|
%dd= file_field 'attachment', 'file'
|
||||||
|
|
||||||
|
%dt
|
||||||
|
%label{:for => 'attachment_path'} Pasta
|
||||||
|
%dd= text_field 'attachment', 'path'
|
||||||
|
|
||||||
%dt
|
%dt
|
||||||
%label{:for => "attachment_description"} Descrição
|
%label{:for => "attachment_description"} Descrição
|
||||||
%dd= preserve(text_area 'attachment', 'description')
|
%dd= preserve(text_area 'attachment', 'description')
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
%dt Arquivo
|
%dt Arquivo
|
||||||
%dd= link_to h(@attachment.file_name), download_course_attachment_url
|
%dd= link_to h(@attachment.file_name), download_course_attachment_url
|
||||||
|
|
||||||
|
%dt Pasta
|
||||||
|
%dd= h(@attachment.path)
|
||||||
|
|
||||||
%dt Descrição
|
%dt Descrição
|
||||||
%dd= h(@attachment.description)
|
%dd= h(@attachment.description)
|
||||||
|
|
||||||
|
|||||||
@@ -32,10 +32,8 @@
|
|||||||
|
|
||||||
%h3 Repositório de Arquivos
|
%h3 Repositório de Arquivos
|
||||||
.repositorio
|
.repositorio
|
||||||
%ul.wiki
|
= nested_attachments_to_html(attachments_to_nested_hash(@course.attachments))
|
||||||
- @course.attachments.each do |att|
|
- if @course.attachments.empty?
|
||||||
%li{:class => mime_class(att.content_type)}
|
%ul.wiki
|
||||||
= link_to h(att.file_name), course_attachment_url(@course, att)
|
|
||||||
- if @course.attachments.empty?
|
|
||||||
%li.no_itens Nenhum arquivo
|
%li.no_itens Nenhum arquivo
|
||||||
|
|
||||||
|
|||||||
@@ -461,6 +461,7 @@ h4.title, h1.title {
|
|||||||
.repositorio .mime_document { background-image: url(<%= App.base_path %>/images/tango/x-office-document.png); }
|
.repositorio .mime_document { background-image: url(<%= App.base_path %>/images/tango/x-office-document.png); }
|
||||||
.repositorio .mime_binary { background-image: url(<%= App.base_path %>/images/tango/application-x-executable.png); }
|
.repositorio .mime_binary { background-image: url(<%= App.base_path %>/images/tango/application-x-executable.png); }
|
||||||
.repositorio .mime_zip { background-image: url(<%= App.base_path %>/images/tango/package-x-generic.png); }
|
.repositorio .mime_zip { background-image: url(<%= App.base_path %>/images/tango/package-x-generic.png); }
|
||||||
|
.repositorio .mime_folder { background-image: url(<%= App.base_path %>/images/tango/folder.png); }
|
||||||
|
|
||||||
.spinner {
|
.spinner {
|
||||||
float: right;
|
float: right;
|
||||||
@@ -827,6 +828,15 @@ form dt p {
|
|||||||
margin: 9px 0px;
|
margin: 9px 0px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul.nested {
|
||||||
|
padding-left: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul.nested li {
|
||||||
|
padding-top: 5px !important;
|
||||||
|
padding-bottom: 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
xbody { background-image: url(<%= App.base_path %>/prototype/line.png); background-repeat: repeat; }
|
xbody { background-image: url(<%= App.base_path %>/prototype/line.png); background-repeat: repeat; }
|
||||||
xhtml * { background-color: transparent !important; }
|
xhtml * { background-color: transparent !important; }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 35) do
|
ActiveRecord::Schema.define(:version => 36) do
|
||||||
|
|
||||||
create_table "attachments", :force => true do |t|
|
create_table "attachments", :force => true do |t|
|
||||||
t.string "file_name", :null => false
|
t.string "file_name", :null => false
|
||||||
@@ -19,6 +19,7 @@ ActiveRecord::Schema.define(:version => 35) do
|
|||||||
t.integer "size"
|
t.integer "size"
|
||||||
t.integer "course_id"
|
t.integer "course_id"
|
||||||
t.datetime "deleted_at"
|
t.datetime "deleted_at"
|
||||||
|
t.string "path"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "courses", :force => true do |t|
|
create_table "courses", :force => true do |t|
|
||||||
|
|||||||
Reference in New Issue
Block a user