Commit ec81051a
Changed files (3)
app
assets
javascripts
backbone
app/assets/javascripts/backbone/routers/photos_router.js.coffee
@@ -1,13 +1,7 @@
class CakeSide.Routers.PhotosRouter extends Backbone.Router
routes:
- "cakes/:cake_id/photos/new" : "newPhoto"
"cakes/:cake_id/photos/:id" : "show"
- newPhoto: (cake_id) ->
- @photos = CakeSide.Application.request('PhotosRepository', cake_id)
- @view = new CakeSide.Views.Photos.NewView(collection: @photos)
- $("#backbone-content").html(@view.render().el)
-
show: (cake_id, id) ->
@photos = CakeSide.Application.request('PhotosRepository', cake_id)
photo = new CakeSide.Models.Photo({cake_id: cake_id, id: id})
app/assets/javascripts/backbone/templates/photos/new.jst.ejs
@@ -1,16 +0,0 @@
-<h1>Upload photo</h1>
-
-<form id="new-photo" name="photo" class="form-horizontal">
- <fieldset>
- <div class="control-group">
- <label class="control-label" for="photo_attachment">Photo</label>
- <div class="controls">
- <input class="input-xxlarge" id="photo_attachment" name="attachment" type="file">
- </div>
- </div>
- <div class="form-actions">
- <button type="submit" class="btn btn-primary">Upload Photo</button>
- <a href="#cakes" class="btn">Cancel</a>
- </div>
- </fieldset>
-</form>
app/assets/javascripts/backbone/views/photos/new_view.js.coffee
@@ -1,38 +0,0 @@
-CakeSide.Views.Photos ||= {}
-
-class CakeSide.Views.Photos.NewView extends Backbone.View
- template: JST["backbone/templates/photos/new"]
-
- events:
- "submit #new-photo": "save"
-
- constructor: (options) ->
- super(options)
- @model = new @collection.model()
-
- @model.bind("change:errors", () =>
- this.render()
- )
-
- save: (e) ->
- e.preventDefault()
- e.stopPropagation()
-
- @model.unset("errors")
-
- fileObject = @$(':input[type="file"]')[0].files[0]
- @model.set('image', fileObject)
- @model.on('progress', console.log)
- @collection.create(@model.toJSON(),
- success: (photo) =>
- @model = photo
- window.location.hash = "cakes/#{@model.get('cake_id')}"
-
- error: (photo, jqXHR) =>
- @model.set({errors: $.parseJSON(jqXHR.responseText)})
- )
-
- render: ->
- $(@el).html(@template(@model.toJSON()))
- this.$("form").backboneLink(@model)
- return this