Skip to content

Commit

Permalink
show ajax errors on new_comment_view
Browse files Browse the repository at this point in the history
  • Loading branch information
brownman committed Nov 17, 2012
1 parent 6b81744 commit 38c7ce6
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 42 deletions.
Expand Up @@ -15,5 +15,5 @@


<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>

<input type='text' class='errors'>errors: </input>
</div> </div>
@@ -1,4 +1,4 @@
<div class="new-comment form span3"> <div class="new_comment form span3">




<form class="field1" height='1em' > <form class="field1" height='1em' >
Expand All @@ -15,5 +15,5 @@


<input type="submit" value="Submit"> <input type="submit" value="Submit">
</form> </form>

<input type='text' class='errors'>errors: </input>
</div> </div>
4 changes: 2 additions & 2 deletions app/assets/javascripts/backbone/templates/posts/post.jst.ejs
Expand Up @@ -19,9 +19,9 @@
<div id="collapseOne<%= post.id %>" class="accordion-body collapse"> <div id="collapseOne<%= post.id %>" class="accordion-body collapse">
<div class="accordion-inner"> <div class="accordion-inner">


<div class="new_comment"></div> <div class="new_comment">new_comment:</div>


<div class="comments" ></div> <div class="comments" >comments:</div>




</div> </div>
Expand Down
10 changes: 6 additions & 4 deletions app/assets/javascripts/backbone/templates/posts/post.jst.ejs~
@@ -1,7 +1,7 @@
<div class="accordion-heading"> <div class="accordion-heading">
<div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>"> <div class="accordion-toggle" data-toggle="collapse" data-parent="#posts-list" href="#collapseOne<%= post.id %>">


<button class='open btn span2' >open</button> <button class='open btn span2' >fetch</button>
<a class="id"><%= post.id %></a> <a class="id"><%= post.id %></a>
<input class="title" value=<%= post.title %> >title: </input> <input class="title" value=<%= post.title %> >title: </input>


Expand All @@ -18,10 +18,12 @@
</div> </div>
<div id="collapseOne<%= post.id %>" class="accordion-body collapse"> <div id="collapseOne<%= post.id %>" class="accordion-body collapse">
<div class="accordion-inner"> <div class="accordion-inner">
<a>
new_comment:
</a>
<div class="new_comment">new_comment:</div>


<div class="new_comment"></div> <div class="comments" >comments:</div>

<div class="comments" ></div>




</div> </div>
Expand Down
Expand Up @@ -9,7 +9,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View


events: events:
"click .destroy" : "destroy" "click .destroy" : "destroy"
"dblclick .todo-array button": "push_index" #"dblclick .todo-array button": "push_index"


"click .todo-array button": "whiteSpaceCheck" "click .todo-array button": "whiteSpaceCheck"


Expand All @@ -22,7 +22,8 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View


"keypress .title" : "updateOnEnter" "keypress .title" : "updateOnEnter"





#"hover .todo-array button": "show_tooltip" #"hover .todo-array button": "show_tooltip"
set_content: (e) -> set_content: (e) ->
console.log(e) console.log(e)
Expand All @@ -31,19 +32,19 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
#this.$(".content"); #this.$(".content");
console.log(input) console.log(input)


@model.set({ content: input }) @model.save({ content: input })
#@render() #@render()




updateOnEnter: (e) -> updateOnEnter: (e) ->


#this.trigger('somethingHappened') #this.trigger('somethingHappened')
if e.keyCode is 13 #if e.keyCode is 13
console.log(e) console.log(e)
@input = this.$(".title"); input = this.$(".title");
console.log(@input) console.log(input)


@model.save({ title: @input.val() }) @model.save({ title: input.val() })


#$(@el).removeClass("editing") #$(@el).removeClass("editing")
initialize: () -> initialize: () ->
Expand Down Expand Up @@ -94,6 +95,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View




render: -> render: ->

listed2 = this.splitted2() listed2 = this.splitted2()


comment = @model.toJSON() comment = @model.toJSON()
Expand Down Expand Up @@ -170,14 +172,17 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
whiteSpaceCheck: (ev) -> whiteSpaceCheck: (ev) ->
item = ev.target item = ev.target
str = $(item).context.innerText str = $(item).context.innerText
if(str != '=')
tmp1 = $(item).hasClass("test1")
#alert(tmp1)
if(str != '=' && !tmp1)
_.delay(_.bind(this.something, item), @seconds * 1000 , 'logged later') _.delay(_.bind(this.something, item), @seconds * 1000 , 'logged later')
$(item).toggleClass("test1") $(item).addClass("test1")
else else
@push_index(ev) @push_index(ev)


something: (msg) -> something: (msg) ->
$(this).toggleClass("test1") $(this).removeClass("test1")


set_delay: (ev) -> set_delay: (ev) ->
@seconds = ev.target.value @seconds = ev.target.value
Expand Down
Expand Up @@ -9,7 +9,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View


events: events:
"click .destroy" : "destroy" "click .destroy" : "destroy"
"dblclick .todo-array button": "push_index" #"dblclick .todo-array button": "push_index"


"click .todo-array button": "whiteSpaceCheck" "click .todo-array button": "whiteSpaceCheck"


Expand All @@ -22,7 +22,8 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View


"keypress .title" : "updateOnEnter" "keypress .title" : "updateOnEnter"





#"hover .todo-array button": "show_tooltip" #"hover .todo-array button": "show_tooltip"
set_content: (e) -> set_content: (e) ->
console.log(e) console.log(e)
Expand All @@ -38,12 +39,12 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
updateOnEnter: (e) -> updateOnEnter: (e) ->


#this.trigger('somethingHappened') #this.trigger('somethingHappened')
if e.keyCode is 13 #if e.keyCode is 13
console.log(e) console.log(e)
@input = this.$(".title"); input = this.$(".title");
console.log(@input) console.log(input)


@model.save({ title: @input.val() }) @model.save({ title: input.val() })


#$(@el).removeClass("editing") #$(@el).removeClass("editing")
initialize: () -> initialize: () ->
Expand Down Expand Up @@ -94,6 +95,7 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View




render: -> render: ->

listed2 = this.splitted2() listed2 = this.splitted2()


comment = @model.toJSON() comment = @model.toJSON()
Expand Down Expand Up @@ -170,14 +172,17 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
whiteSpaceCheck: (ev) -> whiteSpaceCheck: (ev) ->
item = ev.target item = ev.target
str = $(item).context.innerText str = $(item).context.innerText
if(str != '=')
tmp1 = $(item).hasClass("test1")
#alert(tmp1)
if(str != '=' && !tmp1)
_.delay(_.bind(this.something, item), @seconds * 1000 , 'logged later') _.delay(_.bind(this.something, item), @seconds * 1000 , 'logged later')
$(item).toggleClass("test1") $(item).addClass("test1")
else else
@push_index(ev) @push_index(ev)


something: (msg) -> something: (msg) ->
$(this).toggleClass("test1") $(this).removeClass("test1")


set_delay: (ev) -> set_delay: (ev) ->
@seconds = ev.target.value @seconds = ev.target.value
Expand Down
Expand Up @@ -16,7 +16,7 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
#@options.comments.each(@update_span(num)) #@options.comments.each(@update_span(num))
#.on('add2', this.alert_parent); #.on('add2', this.alert_parent);


@options.comments.bind('reset', @addAll) #@options.comments.bind('reset', @addAll)


@options.comments.bind('add2', @add2_view) @options.comments.bind('add2', @add2_view)
#@options.comments.bind('remove', @addAll) #@options.comments.bind('remove', @addAll)
Expand Down Expand Up @@ -84,6 +84,7 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
@$(".comments-list").append(view.render().el) @$(".comments-list").append(view.render().el)


render: => render: =>

comments = @options.comments.toJSON() comments = @options.comments.toJSON()


@num = @options.comments.length @num = @options.comments.length
Expand Down
Expand Up @@ -42,10 +42,16 @@ class RailsBackboneRelational.Views.Comments.NewView extends Backbone.View
alert('error') alert('error')
console.log(comment) console.log(comment)
console.log(jqXHR) console.log(jqXHR)
@model.set({errors: $.parseJSON(jqXHR.responseText)}) obj =
errors: $.parseJSON(jqXHR.responseText)
@model.set(obj)
str = obj.errors
@$('.errors').val(str)



#Backbone.history.navigate('', true); #Backbone.history.navigate('', true);
) )
#@render()


render: -> render: ->
$(@el).html(@template(@model.toJSON() )) $(@el).html(@template(@model.toJSON() ))
Expand Down
Expand Up @@ -42,12 +42,19 @@ class RailsBackboneRelational.Views.Comments.NewView extends Backbone.View
alert('error') alert('error')
console.log(comment) console.log(comment)
console.log(jqXHR) console.log(jqXHR)
@model.set({errors: $.parseJSON(jqXHR.responseText)}) obj =
errors: $.parseJSON(jqXHR.responseText)
#@model.set(obj)
#str = obj.errors
#@$('.errors').val(str)



#Backbone.history.navigate('', true); #Backbone.history.navigate('', true);
) )
#@render()


render: -> render: ->
$(@el).html(@template(@model.toJSON() )) $(@el).html(@template(@model.toJSON() ))


return this return this

Expand Up @@ -22,8 +22,8 @@ class RailsBackboneRelational.Views.Posts.IndexView extends Backbone.View


#comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc) #comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
#view.$(".comments").html(comments_view.render().el) #view.$(".comments").html(comments_view.render().el)
#new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments')) new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
#view.$(".new_comment").html(new_comment_view.render().el) view.$(".new_comment").html(new_comment_view.render().el)


render: => render: =>
$(@el).html(@template(posts: @options.posts.toJSON() )) $(@el).html(@template(posts: @options.posts.toJSON() ))
Expand Down
Expand Up @@ -22,8 +22,8 @@ class RailsBackboneRelational.Views.Posts.IndexView extends Backbone.View


#comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc) #comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
#view.$(".comments").html(comments_view.render().el) #view.$(".comments").html(comments_view.render().el)
new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments')) #new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments'))
view.$(".new_comment").html(new_comment_view.render().el) #view.$(".new_comment").html(new_comment_view.render().el)


render: => render: =>
$(@el).html(@template(posts: @options.posts.toJSON() )) $(@el).html(@template(posts: @options.posts.toJSON() ))
Expand Down
14 changes: 11 additions & 3 deletions app/assets/javascripts/backbone/views/posts/post_view.js.coffee
Expand Up @@ -32,14 +32,16 @@ class RailsBackboneRelational.Views.Posts.PostView extends Backbone.View
comments1 = post.get('comments') comments1 = post.get('comments')
num = comments1.length num = comments1.length
view = @ view = @
console.log(view)
abc = abc =
comments: comments1 comments: comments1
ofer_length: num ofer_length: num


comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc) comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
view.$(".comments").html(comments_view.render().$el) view.$(".comments").append(comments_view.render().$el)
new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments')) new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: comments1)
view.$(".new_comment").html(new_comment_view.render().el) view.$(".new_comment").append(new_comment_view.render().el)



destroy: () -> destroy: () ->
@model.destroy() @model.destroy()
Expand Down Expand Up @@ -77,6 +79,12 @@ class RailsBackboneRelational.Views.Posts.PostView extends Backbone.View
'length': num 'length': num
) )
$(@el).html(tmp) $(@el).html(tmp)
view = $(@el)

comments1 = @model.get('comments')
#new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: comments1)
#view.find(".new_comment").html(new_comment_view.render().el)

return this return this


not_render2: => not_render2: =>
Expand Down
16 changes: 12 additions & 4 deletions app/assets/javascripts/backbone/views/posts/post_view.js.coffee~
Expand Up @@ -32,14 +32,16 @@ class RailsBackboneRelational.Views.Posts.PostView extends Backbone.View
comments1 = post.get('comments') comments1 = post.get('comments')
num = comments1.length num = comments1.length
view = @ view = @
console.log(view)
abc = abc =
comments: comments1 comments: comments1
ofer_length: num ofer_length: num


comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc) comments_view = new RailsBackboneRelational.Views.Comments.IndexView(abc)
view.$(".comments").html(comments_view.render().$el) view.$(".comments").append(comments_view.render().$el)
new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: post.get('comments')) new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: comments1)
view.$(".new_comment").html(new_comment_view.render().el) view.$(".new_comment").append(new_comment_view.render().el)



destroy: () -> destroy: () ->
@model.destroy() @model.destroy()
Expand All @@ -56,7 +58,7 @@ class RailsBackboneRelational.Views.Posts.PostView extends Backbone.View
# #
updateOnEnter: (e) -> updateOnEnter: (e) ->


this.trigger('somethingHappened') #this.trigger('somethingHappened')
if e.keyCode is 13 if e.keyCode is 13
console.log(e) console.log(e)
@input = this.$(".title"); @input = this.$(".title");
Expand All @@ -77,6 +79,12 @@ class RailsBackboneRelational.Views.Posts.PostView extends Backbone.View
'length': num 'length': num
) )
$(@el).html(tmp) $(@el).html(tmp)
view = $(@el)

comments1 = @model.get('comments')
#new_comment_view = new RailsBackboneRelational.Views.Comments.NewView(collection: comments1)
#view.find(".new_comment").html(new_comment_view.render().el)

return this return this


not_render2: => not_render2: =>
Expand Down

0 comments on commit 38c7ce6

Please sign in to comment.