Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add order:integer to comments

  • Loading branch information...
commit fb94f9558453c3b5c7ff8fe02f987e83381b54e8 1 parent 7a35f67
@brownman authored
View
2  .gitignore
@@ -4,6 +4,8 @@
# Ignore the default SQLite database.
/db/*.sqlite3
+/db/migrate/*
+
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
View
15 .gitignore~
@@ -1,16 +1,19 @@
-# See http://help.github.com/ignore-files/ for more about ignoring files.
-#
-# If you find yourself ignoring temporary files generated by your text editor
-# or operating system, you probably want to add a global ignore instead:
-# git config --global core.excludesfile ~/.gitignore_global
-
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
+/db/migrate/*
+
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
+
+# Ignore other unneeded files.
+doc/
*.swp
+*~
+.project
+.DS_Store
+.idea
View
44 app/assets/javascripts/backbone/models/comment.js.coffee
@@ -6,7 +6,16 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel
content: 'content'
direction: true
title: 'title'
+ order: 0
+ validate: (attrs) ->
+
+ if (attrs.title == '')
+ return "title is empty"
+
+ if (attrs.content == '')
+ return "content is empty"
+
initialize: () ->
@@ -65,7 +74,20 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
#this.bind('add', @addModelCallback);
#console.log(this)
+ #
+
+
this.bind("add remove", @add1)
+
+ this.bind("change:order", @sort1)
+
+
+
+
+
+ this
+
+ #this.bind("reset", @sort1)
#this.bind("change", @change_ofer)
@@ -77,9 +99,16 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
-
-
+
+ sort1: () =>
+ console.log('sort1')
+ alert('sort1')
+ this.sort()
+
+ this.trigger('add2')
+
add1: () =>
+ #this.sort()
console.log(this)
length_i = this.models.length
if length_i > 0
@@ -101,9 +130,18 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
if ( num1 == length_i)
for i in [0...length_i]
this.models[i].array[j..j] = []
+
+
+ this.sort()
+
+
this.trigger('add2')
-
+ comparator: (comment) ->
+ #return comment.get('id')
+
+ return comment.get('order')
+
#localStorage: new Backbone.LocalStorage("CommentsCollection")
View
44 app/assets/javascripts/backbone/models/comment.js.coffee~
@@ -6,7 +6,16 @@ class RailsBackboneRelational.Models.Comment extends Backbone.RelationalModel
content: 'content'
direction: true
title: 'title'
+ order: 0
+ validate: (attrs) ->
+
+ if (attrs.title == '')
+ return "title is empty"
+
+ if (attrs.content == '')
+ return "content is empty"
+
initialize: () ->
@@ -65,7 +74,20 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
#this.bind('add', @addModelCallback);
#console.log(this)
+ #
+
+
this.bind("add remove", @add1)
+
+ this.bind("change:order", @sort1)
+
+
+
+
+
+ this
+
+ #this.bind("reset", @sort1)
#this.bind("change", @change_ofer)
@@ -77,9 +99,16 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
-
-
+
+ sort1: () =>
+ console.log('sort1')
+ alert('sort1')
+ this.sort()
+
+ this.trigger('add2')
+
add1: () =>
+ #this.sort()
console.log(this)
length_i = this.models.length
if length_i > 0
@@ -101,9 +130,18 @@ class RailsBackboneRelational.Collections.CommentsCollection extends Backbone.Co
if ( num1 == length_i)
for i in [0...length_i]
this.models[i].array[j..j] = []
+
+
+ this.sort()
+
+
this.trigger('add2')
-
+ comparator: (comment) =>
+ #return comment.get('id')
+
+ return comment.get('order')
+
#localStorage: new Backbone.LocalStorage("CommentsCollection")
View
13 app/assets/javascripts/backbone/templates/comments/comment.jst.ejs
@@ -6,13 +6,13 @@
<input type="checkbox" name="direction" class="span12 direction checkbox " <%= obj.direction ? 'checked="checked"' : '' %> ></input>
+order:
+<input label='order: ' tooltip='order..' class='order' height='1em' type='text' value='<%= obj5 %>'></input>
+<br>
+
id:
<input class='' height='1em' type='text' label='id' value='<%= obj.id %>'></input>
<br>
-title:
-<input class='title' height='1em' type='text' value='<%= obj.title %>'></input>
-<br>
-
@@ -28,6 +28,11 @@ span:
+title:
+<input class='title' height='1em' type='text' value='<%= obj.title %>'></input>
+<br>
+
+
content:
<textarea class="content" rows="4" height='1em' class='' name="content1" >
View
17 app/assets/javascripts/backbone/templates/comments/comment.jst.ejs~
@@ -6,13 +6,13 @@
<input type="checkbox" name="direction" class="span12 direction checkbox " <%= obj.direction ? 'checked="checked"' : '' %> ></input>
-id:
-<input class='' height='1em' type='text' label='id' value='<%= obj.id %>'></input>
-<br>
-title:
-<input class='title' height='1em' type='text' value='<%= obj.title %>'></input>
+order:
+<input label='order: ' tooltip='order..' class='order' height='1em' type='text' value='<%= obj5 %>'></input>
<br>
+id:
+<input class='' height='1em' type='button' label='id' value='<%= obj.id %>'></input>
+<br>
@@ -28,9 +28,14 @@ span:
+title:
+<input class='title' height='1em' type='text' value='<%= obj.title %>'></input>
+<br>
+
+
content:
-<textarea rows="4" height='1em' class='' name="content1" >
+<textarea class="content" rows="4" height='1em' class='' name="content1" >
<%= obj.content %>
</textarea>
View
11 app/assets/javascripts/backbone/views/comments/comment_view.js.coffee
@@ -18,6 +18,8 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
"blur .seconds" : "set_delay"
+ "blur .order" : "set_order"
+
"blur .content" : "set_content"
"keypress .title" : "updateOnEnter"
@@ -102,7 +104,9 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
status = @status.toString()
seconds = @seconds.toString()
+
spans = @el.className.toString()
+ order = comment.order
console.log(comment)
tmp = @template(
@@ -111,7 +115,9 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
'obj2': status
'obj3': seconds
+
'obj4': spans
+ 'obj5': order
)
$(@el).html(tmp)
@@ -189,5 +195,10 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
console.log(@seconds)
+ set_order: (ev) ->
+ order1 = ev.target.value
+ console.log(order1)
+ num = parseInt(order1, 10)
+ @model.save({ order: num })
View
10 app/assets/javascripts/backbone/views/comments/comment_view.js.coffee~
@@ -18,6 +18,8 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
"blur .seconds" : "set_delay"
+ "blur .order" : "set_order"
+
"blur .content" : "set_content"
"keypress .title" : "updateOnEnter"
@@ -102,7 +104,9 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
status = @status.toString()
seconds = @seconds.toString()
+
spans = @el.className.toString()
+ order = comment.order
console.log(comment)
tmp = @template(
@@ -111,7 +115,9 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
'obj2': status
'obj3': seconds
+
'obj4': spans
+ 'obj5': order
)
$(@el).html(tmp)
@@ -189,5 +195,9 @@ class RailsBackboneRelational.Views.Comments.CommentView extends Backbone.View
console.log(@seconds)
+ set_order: (ev) ->
+ order1 = ev.target.value
+ console.log(order1)
+ @model.save({ order: parseInt(order1, 10) })
View
4 app/assets/javascripts/backbone/views/comments/index_view.js.coffee
@@ -42,7 +42,9 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
#@$(".comments-list").html('<a>ZVV</a>')
tmp = @render()
- $(@el).append(tmp)
+ view = $(@el)
+ view.append(tmp)
+
#@$el.show()
#@el.html(tmp)
View
1  app/assets/javascripts/backbone/views/comments/index_view.js.coffee~
@@ -84,7 +84,6 @@ class RailsBackboneRelational.Views.Comments.IndexView extends Backbone.View
@$(".comments-list").append(view.render().el)
render: =>
-
comments = @options.comments.toJSON()
@num = @options.comments.length
View
5 app/assets/javascripts/backbone/views/comments/new_view.js.coffee
@@ -46,7 +46,10 @@ class RailsBackboneRelational.Views.Comments.NewView extends Backbone.View
errors: $.parseJSON(jqXHR.responseText)
@model.set(obj)
str = obj.errors
- @$('.errors').val(str)
+ @$('.errors').val(
+ 'title: ' + str['title'] + ': ' + ' content: ' + str['content']
+
+ )
#Backbone.history.navigate('', true);
View
9 app/assets/javascripts/backbone/views/comments/new_view.js.coffee~
@@ -44,9 +44,12 @@ class RailsBackboneRelational.Views.Comments.NewView extends Backbone.View
console.log(jqXHR)
obj =
errors: $.parseJSON(jqXHR.responseText)
- #@model.set(obj)
- #str = obj.errors
- #@$('.errors').val(str)
+ @model.set(obj)
+ str = obj.errors
+ @$('.errors').val(
+ 'title: ' + str['title'] + ': ' + ' content: ' + str['content']
+
+ )
#Backbone.history.navigate('', true);
View
6 app/models/comment.rb
@@ -1,3 +1,9 @@
class Comment < ActiveRecord::Base
belongs_to :post
+
+ validates :title, :presence => true
+
+ validates :content, :presence => true
+
+ validates :order, :numericality => { :only_integer => true }
end
View
2  app/models/post.rb
@@ -1,3 +1,5 @@
class Post < ActiveRecord::Base
has_many :comments, :dependent => :destroy
+
+ validates :title, :presence => true
end
View
4 db/schema.rb
@@ -11,8 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121029121212) do
-
+ActiveRecord::Schema.define(:version => 20121118143611) do
create_table "comments", :force => true do |t|
t.text "content"
@@ -21,6 +20,7 @@
t.integer "post_id"
t.boolean "direction"
t.string "title"
+ t.integer "order"
end
create_table "posts", :force => true do |t|
View
5 db/schema.rb~
@@ -11,15 +11,16 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20121029121212) do
+ActiveRecord::Schema.define(:version => 20121118143611) do
create_table "comments", :force => true do |t|
- t.text "content"
+ t.string "content"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "post_id"
t.boolean "direction"
t.string "title"
+ t.integer "order"
end
create_table "posts", :force => true do |t|
Please sign in to comment.
Something went wrong with that request. Please try again.