diff options
Diffstat (limited to 'public/assets/js/lib/views/UploadView.js')
| -rw-r--r-- | public/assets/js/lib/views/UploadView.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/public/assets/js/lib/views/UploadView.js b/public/assets/js/lib/views/UploadView.js new file mode 100644 index 0000000..5acc39a --- /dev/null +++ b/public/assets/js/lib/views/UploadView.js @@ -0,0 +1,54 @@ +var UploadView = View.extend({ + + events: { + "change input": "handleFileSelect", + }, + + initialize: function(){ + this.$input = this.$('input') + }, + + loaded: false, + ready: function(){ + this.canvas = document.createElement("canvas") + this.ctx = this.canvas.getContext('2d') + this.$overlayer.append(this.canvas) + this.draw() + }, + + handleFileSelect: function(e) { + e.stopPropagation() + e.preventDefault() + + var files = e.dataTransfer ? e.dataTransfer.files : e.target.files + + var file = files[0] + + if (! file) return + if ( ! file.type.match('image.*')) return + + this.file = file + app.views.home.PhotoView.load( file ) + }, + + upload: function(file){ + var fd = new FormData() + var _csrf = $("meta[name='_csrf']").attr('content') + fd.append('_csrf', _csrf) + fd.append('image', file) + + var request = $.ajax({ + url: "/_irc/image?_csrf=" + _csrf, + type: "post", + data: fd, + processData: false, + contentType: false, + }) + request.done(this.success.bind(this)) + }, + + success: function(data){ + // probably append image.. + }, + +})
\ No newline at end of file |
