   @widget_icon_url: "/assets/media_icon.png"
   @plugin_namespace: "Kandan.Plugins.Attachments"
 
+  @dropzoneInit: false
+
   @options:
     maxFileNameLength: 20
+    defaultDropzoneText: "Drop file here to upload"
 
   @templates:
     no_files: _.template '''


  # TODO this part is very bad for APIs! shoudnt be exposing a backbone collection in a plugin.
  @render: ($widget_el)->
    $upload_form = @templates.dropzone({
      channel_id: @channel_id(),
      csrf_param: @csrf_param(),
      csrf_token: @csrf_token()
    })

    $widget_el.next().html($upload_form)
    @init_dropzone @channel_id()
    $widget_el.next(".action_block").html($upload_form)

    attachments = new Kandan.Collections.Attachments([], {channel_id: @channel_id()})
    attachments.fetch({
      success: (collection)=>

        if collection.models.length > 0
          $file_list = $("<div class='file_list'></div>")
          for model in collection.models
            $file_list.append(@file_item_template({
              fileName: @truncateName(model.get('file_file_name')),
              url: model.get('url')
              iconUrl: @fileIcon(model.get('file_file_name'))
            }))
        else
          $file_list = @templates.no_files()
        $widget_el.html($file_list)
    })


  @init_dropzone: (channel_id)->
    $(".dropzone").filedrop({
      fallback_id: "file"
      url        : "/channels/#{channel_id}/attachments.json",
      paramname  : "file"
      maxfilesize: 100
      queuefiles : 1

      uploadStarted: ->
        $(".dropzone").text("Uploading...")

      error: (err, file)->
        if err == "BrowserNotSupported"

          </div>
          <input id="channel_id_<%= channel_id %>" name="channel_id[<%= channel_id %>]" type="hidden"/>
          <input id="file" name="file" type="file"/>
          <div class="dropzone"><%= dropzoneText %></div>
      </form>
    '''

