Skip to content

Commit 81310a9

Browse files
committed
File widget update to style dropzone
Signed-off-by: Akash Manohar J <[email protected]>
1 parent e13cd8b commit 81310a9

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

app/assets/javascripts/backbone/plugins/attachments.js.coffee

+19-11
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ class Kandan.Plugins.Attachments
1010
</div>
1111
<input id="channel_id_<%= channel_id %>" name="channel_id[<%= channel_id %>]" type="hidden"/>
1212
<input id="file" name="file" type="file"/>
13-
<input name="commit" type="submit" value="Upload"/>
14-
<div class="dropzone" style="height: 100px;background-color: #000;"></div>
13+
<div class="dropzone">Drop files here to upload</div>
1514
</form>
1615
''')
1716

@@ -27,9 +26,9 @@ class Kandan.Plugins.Attachments
2726
@csrf_token: ->
2827
$('meta[name=csrf-token]').attr('content')
2928

30-
@file_item_template: _.template('''
31-
<li><a href="<%= url %>"><%= file_name %></a></li>
32-
''')
29+
@file_item_template: _.template '''
30+
<li><a href="<%= url %>"><%= file_name %></a></li>
31+
'''
3332

3433
# TODO this part is very bad for APIs! shoudnt be exposing a backbone collection in a plugin.
3534
@render: ($widget_el)->
@@ -38,8 +37,11 @@ class Kandan.Plugins.Attachments
3837
csrf_param: @csrf_param(),
3938
csrf_token: @csrf_token()
4039
})
41-
$widget_el.html($upload_form)
40+
41+
$widget_el.next().html($upload_form)
4242
@init_dropzone @channel_id()
43+
console.log $widget_el.next()
44+
$widget_el.next(".action_block").html($upload_form)
4345
$file_list = $("<ul></ul>")
4446
attachments = new Kandan.Collections.Attachments([], {channel_id: @channel_id()})
4547
attachments.fetch({success: (collection)=>
@@ -48,17 +50,23 @@ class Kandan.Plugins.Attachments
4850
file_name: model.get('file_file_name'),
4951
url: model.get('url')
5052
}))
51-
$widget_el.append($file_list)
53+
$widget_el.html($file_list)
5254
})
5355

5456

5557
@init_dropzone: (channel_id)->
5658
$(".dropzone").filedrop({
57-
fallback_id: "file",
58-
url: "/channels/#{channel_id}/attachments.json",
59-
paramname: 'file',
59+
fallback_id: "file"
60+
url : "/channels/#{channel_id}/attachments.json",
61+
paramname : "file"
62+
63+
uploadStarted: =>
64+
$(".dropzone").text("Uploading...")
65+
6066
uploadFinished: (i, file, response, time)->
61-
console.log "upload complete"
67+
$(".dropzone").text("Drop files here to upload")
68+
Kandan.Widgets.render "Kandan.Plugins.Attachments"
69+
6270
dragOver: ->
6371
console.log "reached dropzone!"
6472
})

app/assets/javascripts/backbone/widgets.js.coffee

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Kandan.Widgets
1515
<div class="widget" id="widget_<%= element_id %>">
1616
<div class="title"><%= title %></div>
1717
<div class="content" id="<%= element_id %>"></div>
18+
<div class="action_bar"></div>
1819
</div>
1920
'''
2021

app/assets/stylesheets/application.css.scss

+46-1
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,27 @@ body {
120120
}
121121

122122
.content {
123-
@include border-bottom-radius(7px);
124123
float: left;
125124
width: 100%;
125+
clear: both;
126126
background: #F3F8F9;
127127
padding-left: 10px;
128128
}
129+
130+
.action_bar {
131+
@include border-bottom-radius(7px);
132+
font-size: 13px;
133+
text-align: center;
134+
line-height: 20px;
135+
color: #808789;
136+
float: left;
137+
width: 100%;
138+
clear: both;
139+
height: 40px;
140+
min-height: 40px;
141+
border-top: 2px solid #D2D8D8;
142+
background: #E9EFF0;
143+
}
129144
}
130145
}
131146
}
@@ -293,6 +308,8 @@ body {
293308
.posted_at {
294309
float: left;
295310
width: 20%;
311+
text-align: right;
312+
296313
span {
297314
@include border-radius(4px);
298315
padding: 4px;
@@ -335,3 +352,31 @@ body {
335352
}
336353
}
337354
}
355+
356+
//
357+
// Attachments plugin
358+
//
359+
360+
#file {
361+
display: none;
362+
}
363+
364+
.action_bar {
365+
form {
366+
width: 100%;
367+
height: 100%;
368+
min-height: 100%;
369+
float: left;
370+
371+
.dropzone {
372+
display: block;
373+
float: left;
374+
width: 100%;
375+
min-height: 100%;
376+
height: 100%;
377+
text-align: center;
378+
line-height: 40px;
379+
}
380+
}
381+
}
382+

0 commit comments

Comments
 (0)