Class: DocumentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/documents_controller.rb

Instance Method Summary collapse

Methods included from Zena::App

included

Instance Method Details

#createObject

create a document (direct upload). Used when javascript is disabled.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/documents_controller.rb', line 30

def create
  create_document

  respond_to do |format|
    if @node.new_record?
      @node.skin_id ||= current_site.root_node.skin_id

      flash.now[:error] = _("Upload failed.")
      unless @node.respond_to?('target_klass')
        # Could we find another way to fake the new object as acting like a template ?
        class << @node
          def target_klass; nil; end
        end
      end
      format.html { render :action => 'new'}
    else
      flash.now[:notice] = _("Upload succeeded.")
      format.html { redirect_to document_url(@node[:zip]) }
    end
  end
end

#crop_formObject

TODO: test display the image editor



83
84
85
86
87
# File 'app/controllers/documents_controller.rb', line 83

def crop_form
  respond_to do |format|
    format.js
  end
end

#get_ufObject

TODO: test display an upload field.



77
78
79
# File 'app/controllers/documents_controller.rb', line 77

def get_uf
  render_get_uf
end

#newObject

add a new document to the current node



13
14
15
16
17
18
19
20
# File 'app/controllers/documents_controller.rb', line 13

def new
  # Use the Template class so that we can use the same object in forms which need the Template properties.
  @node = @parent.new_child(:class => Template)

  respond_to do |format|
    format.html
  end
end

#showObject

show the result of an upload



23
24
25
26
27
# File 'app/controllers/documents_controller.rb', line 23

def show
  respond_to do |format|
    format.html
  end
end

#uploadObject

Create a document with upload progression (upload in mongrel)



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/documents_controller.rb', line 53

def upload
  create_document

  responds_to_parent do # execute the redirect in the iframe's parent window
    render :update do |page|
      if @node.new_record?
        page.replace_html 'form_errors', error_messages_for(:node, :object => @node)
        page.call 'UploadProgress.setAsError'
      else
        page.call 'UploadProgress.setAsFinished'
        page.delay(1) do # allow the progress bar fade to complete
          page.redirect_to document_url(@node[:zip])
        end
      end
    end
  end
end

#upload_progressObject



71
72
73
# File 'app/controllers/documents_controller.rb', line 71

def upload_progress
  render_upload_progress
end