Add UI/models to allow uploading images

This commit is contained in:
Andrew Miner
2015-06-05 22:47:40 -07:00
parent 94cd133748
commit dd760018df
12 changed files with 361 additions and 10 deletions
+46
View File
@@ -0,0 +1,46 @@
###
Crafting Guide - markdown_image.coffee
Copyright (c) 2015 by Redwood Labs
All rights reserved.
###
BaseModel = require './base_model'
{Event} = require '../constants'
########################################################################################################################
module.exports = class MarkdownImage extends BaseModel
@MIMETYPES = [
{patern:/\.png$/i, text:'image/png'}
{patern:/\.gif$/i, text:'image/gif'}
{patern:/\.jpg$/i, text:'image/jpeg'}
{patern:/\.jpeg$/i, text:'image/jpeg'}
]
constructor: (attributes={}, options={})->
attributes.encodedData ?= null
attributes.fileName ?= ''
attributes.path ?= ''
attributes.sha ?= null
super
@on Event.change + ':fileName', => @_mimeType = null
# Property Methods #############################################################################
getFullPath: ->
return "#{@path}/#{@fileName}"
getMimeType: ->
if not @_mimeType?
for mimeType in MarkdownImage.MIMETYPES
if mimeType.pattern.test @fileName
@_mimeType = mimeType.text
break
return @_mimeType
Object.defineProperties @prototype,
fullPath: {get:@prototype.getFullPath}