class Backbone.Form.editors.File extends Backbone.Form.editors.Base
tagName: 'div',
events:
change: (evt) ->
@trigger "change", @
focus: ->
@trigger "focus", @
blur: ->
@trigger "blur", @
'click [data-action=remove-document]': 'removeDocument'
removeDocument: (evt) ->
evt.preventDefault()
docid = @$('.uploaded-file').data "id"
(new DocumentDestroyRequester @, docid).execute()
removeDocumentDOM: ->
@$('.uploaded-file').hide()
@$('.uploaded-file .uploaded-file-name').text ""
@$('.uploaded-file').data 'id', ""
@$('.file-upload').show()
setProgressBar: ( context, value ) ->
context.$('.progress .bar').css 'width', value + '%'
context.$('.progress .bar').text value + '%'
initialize: (options) ->
Backbone.Form.editors.Base.prototype.initialize.call @, options
input = @$el.append ""
prbar = @$el.append "
"
upfil = @$el.append ""
@$('.progress').hide()
@$('.uploaded-file').hide()
@on "destroyDocument:done", @removeDocumentDOM, @
that = @
@$('.file-upload').fileupload
url: "/proxy/documents"
type: "POST"
dataType: "json"
formData:
title: that.schema.title
api_token: window.api_token
progressall: (evt, data) ->
progress = parseInt data.loaded / data.total * 100, 10
that.setProgressBar that, progress
send: (evt, data) ->
that.$('.file-upload').hide()
that.$('.progress').show()
done: (evt, data) ->
that.setProgressBar that, "100"
that.$('.progress').hide()
that.$('.uploaded-file').show()
that.$('.uploaded-file .uploaded-file-name').text data.result.file_file_name
that.$('.uploaded-file').data 'id', data.result.id
debug data
render: ->
@setValue(@value)
@
getValue: ->
@$('.uploaded-file').data 'id'
setValue: (value) ->
@$('.uploaded-file').data 'id', value
focus: ->
return if @hasFocus
blur: ->
return unless @hasFocus
@$el.blur()