Module: Zena::Use::Upload::ViewMethods

Includes:
RubyLess
Defined in:
lib/zena/use/upload.rb

Overview

ControllerMethods

Constant Summary collapse

UPLOAD_KEY =
defined?(Mongrel) ? 'upload_id' : "X-Progress-ID"

Instance Method Summary collapse

Instance Method Details

#upload_field(opts = {}) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/zena/use/upload.rb', line 167

def upload_field(opts = {})
  case opts[:type].to_s
  when 'onclick'
    link = link_to_remote(_("change"), :update=>'upload_field', :url => get_uf_documents_path(:uuid => @uuid), :method => :get, :complete=>"['file', 'upload_field'].each(Element.toggle);")
    <<-TXT
<label for='attachment'>#{_('file')}</label>
<div id="file" class='toggle_div'>#{link}</div>
<div id="upload_field" class='toggle_div' style='display:none;'></div>
TXT
  else
    attach_file_id, attach_url_id = "af#{@uuid}", "au#{@uuid}"
    onchange = %Q{onchange="Zena.get_filename(this,'node_title'); $('node_title').focus(); $('node_title').select();"}
    <<-TXT
<div id='#{attach_file_id}' class='attach'><label for='attachment' onclick=\"['#{attach_file_id}', '#{attach_url_id}'].each(Element.toggle);\">#{_('file')} / <span class='off'>#{_('url')}</span></label>
<input  style='line-height:1.5em;' id="attachment#{@uuid}" name="attachment" #{onchange} class='file' type="file" /></div>

<div id='#{attach_url_id}' class='attach' style='display:none;'><label for='url' onclick=\"['#{attach_file_id}', '#{attach_url_id}'].each(Element.toggle);\"><span class='off'>#{_('file')}</span> / #{_('url')}</label>
<input  style='line-height:1.5em;' size='30' id='attachment_url' type='text' #{onchange} name='attachment_url'/><br/></div>
TXT
  end
end

#upload_form_tag(url_opts, html_opts = {}) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/zena/use/upload.rb', line 151

def upload_form_tag(url_opts, html_opts = {})
  @uuid = UUIDTools::UUID.random_create.to_s.gsub('-','')
  html_opts.reverse_merge!(:multipart => true, :id => "UploadForm#{@uuid}")
  if html_opts[:multipart]
    html_opts[:onsubmit] = "submitUploadForm('#{html_opts[:id]}', '#{@uuid}');"
    url_opts[UPLOAD_KEY] = @uuid
  end
  if block_given?
    form_tag( url_opts, html_opts ) do |f|
      yield(f)
    end
  else
    form_tag( url_opts, html_opts )
  end
end