Commit 49f87bb8513b01ede9171bcbc7fe20bf3d009942
- app.js 25 ----------+++++++++++++++
- index.html 94 -------------------------------------------------+++++++++++++++++++++++++++++++++++++++++++++
- Diff rendering mode:
- inline
- side by side
app.js
85 | }); | 85 | }); |
---|---|---|---|
86 | }, | 86 | }, |
87 | comparator: function(model1, model2) { | 87 | comparator: function(model1, model2) { |
88 | |||
89 | |||
90 | 88 | if((new Date(model1.get('created')) < new Date(model2.get('created')))){ | |
91 | return 1; | 89 | return 1; |
90 | } | ||
91 | else{ | ||
92 | return -1; | ||
93 | } | ||
92 | } | 94 | } |
93 | 95 | ||
94 | }); | 96 | }); |
95 | 97 | ||
96 | var CommentView = Backbone.View.extend({ | 98 | var CommentView = Backbone.View.extend({ |
97 | |||
98 | tagName: 'div', | 99 | tagName: 'div', |
100 | attributes: { | ||
101 | 'class':'comments' | ||
102 | }, | ||
99 | template: _.template($("#commented-template").html()), | 103 | template: _.template($("#commented-template").html()), |
100 | edit_template: _.template($("#comment-template").html()), | 104 | edit_template: _.template($("#comment-template").html()), |
101 | events:{ | 105 | events:{ |
… | … | ||
107 | "click .comment button": "reply" | 107 | "click .comment button": "reply" |
108 | }, | 108 | }, |
109 | initialize: function() { | 109 | initialize: function() { |
110 | |||
110 | if(this.model.get('how').get('replyTo').length) { | 111 | if(this.model.get('how').get('replyTo').length) { |
111 | var item = '#' + this.model.get('how').get('replyTo'); | 112 | var item = '#' + this.model.get('how').get('replyTo'); |
112 | this.setElement($(item)); | 113 | this.setElement($(item)); |
113 | } | 114 | } |
114 | |||
115 | 115 | // this.render(); | |
116 | }, | 116 | }, |
117 | render: function() { | 117 | render: function() { |
118 | if(this.model.isNew()) { | 118 | if(this.model.isNew()) { |
… | … | ||
122 | $(this.el).append(this.template(this.model.toJSON())); | 122 | $(this.el).append(this.template(this.model.toJSON())); |
123 | 123 | ||
124 | } | 124 | } |
125 | return this; | ||
126 | }, | ||
125 | 127 | ||
126 | |||
127 | |||
128 | save: function(e) { | 128 | save: function(e) { |
129 | /* Create a sweet and send it to the sweet store. | 129 | /* Create a sweet and send it to the sweet store. |
130 | Update the view to include the comment */ | 130 | Update the view to include the comment */ |
… | … | ||
176 | }); | 176 | }); |
177 | 177 | ||
178 | var AppView = Backbone.View.extend({ | 178 | var AppView = Backbone.View.extend({ |
179 | el: $("#comments-container"), | ||
179 | initialize: function() { | 180 | initialize: function() { |
180 | this.listenTo(C.comments, "add", this.showOne); | 181 | this.listenTo(C.comments, "add", this.showOne); |
181 | 182 | ||
… | … | ||
186 | model.set({'how': new How(model.get('how'))}); | 186 | model.set({'how': new How(model.get('how'))}); |
187 | } | 187 | } |
188 | var view = new CommentView({model:model}); | 188 | var view = new CommentView({model:model}); |
189 | 189 | $(this.el).prepend(view.render().el); | |
190 | } | 190 | } |
191 | 191 | ||
192 | }); | 192 | }); |
index.html
3 | <link rel="stylesheet" | 3 | <link rel="stylesheet" |
---|---|---|---|
4 | href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" | 4 | href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" |
5 | type="text/css" media="screen" /> | 5 | type="text/css" media="screen" /> |
6 | <style> | ||
7 | .comment{ margin-left: 2em; } | ||
8 | </style> | ||
6 | </head> | 9 | </head> |
7 | <body class="container"> | 10 | <body class="container"> |
8 | <p>Comment below</p> | 11 | <p>Comment below</p> |
9 | |||
10 | 12 | <div id="comments-container"> | |
11 | 13 | ||
12 | |||
13 | |||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | 14 | </div> | |
15 | <script type="text/template" id="commented-template"> | ||
16 | <div class="comment" id=<%= id %> replyTo=<%= how.replyTo %>> | ||
17 | <p><%= how.comment %></p> | ||
18 | <p><small><i>Posted by <%= who %> at <%= created %></i></small></p> | ||
19 | <button type="button" class="btn btn-default btn-sm reply" for=<%= id | ||
20 | %>><span class="glyphicon glyphicon-comment"></span></button> | ||
21 | </div> | 21 | </div> |
22 | |||
23 | |||
24 | |||
25 | |||
26 | |||
27 | |||
28 | |||
29 | |||
30 | |||
31 | |||
32 | |||
33 | |||
34 | 22 | </script> | |
23 | <script type="text/template" id="comment-template"> | ||
24 | <div class="new-comment"> | ||
25 | <textarea class="form-control"><%= how.comment %></textarea> | ||
26 | <button class="btn btn-default btn-sm cancel"><span class="glyphicon | ||
27 | glyphicon-remove"></button> | ||
28 | <button class="btn btn-default btn-sm save"><span class="glyphicon | ||
29 | glyphicon-ok"></span></button> | ||
30 | </div> | ||
31 | </script> | ||
32 | <div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true"> | ||
33 | <div class="modal-dialog"> | ||
34 | <div class="modal-content"> | ||
35 | <div class="modal-header"> | ||
36 | <h4 class="modal-title" id="ModalLabel">Sign in!</h4> | ||
37 | </div> | ||
38 | <div class="modal-body"> | ||
39 | <div class="form-group"> | ||
40 | <label class="sr-only" for="username">Username</label> | ||
41 | <input type="text" class="form-control" id="username" placeholder="Enter username"> | ||
35 | </div> | 42 | </div> |
36 | |||
37 | |||
38 | |||
39 | |||
40 | |||
41 | |||
42 | |||
43 | |||
44 | 43 | <div class="form-group"> | |
44 | <label class="sr-only" for="password">Password</label> | ||
45 | <input type="password" class="form-control" id="password" placeholder="Password"> | ||
45 | </div> | 46 | </div> |
46 | |||
47 | |||
48 | |||
49 | |||
50 | |||
51 | |||
52 | </div> | 47 | </div> |
48 | <div class="modal-footer"> | ||
49 | <button type="button" class="btn btn-default" | ||
50 | data-dismiss="modal">Close</button> | ||
51 | <button type="button" id="saveButton" class="btn btn-primary" | ||
52 | data-dismiss="modal">Login</button> | ||
53 | </div> | ||
53 | </div> | 54 | </div> |
54 | </div> | 55 | </div> |
55 | <script type="text/javascript" | 56 | <script type="text/javascript" |
… | … | ||
58 | <script type="text/javascript" | 58 | <script type="text/javascript" |
59 | src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> | 59 | src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> |
60 | <script type="text/javascript"> | 60 | <script type="text/javascript"> |
61 | |||
62 | |||
63 | |||
64 | |||
65 | |||
66 | |||
67 | |||
68 | 61 | window.C = window.C || {}; window.onload = function(){ C.what = | |
62 | "swaracomment"; C.url = "http://127.0.0.1:5001"; C.auth = | ||
63 | "/authenticate"; C.sweet= "/sweets"; C.get = "/sweets/q"; C.init(); } | ||
69 | </script> | 64 | </script> |
70 | |||
71 | 65 | <script type="text/javascript" src="//underscorejs.org/underscore-min.js"></script> | |
66 | <script type="text/javascript" src="//backbonejs.org/backbone-min.js"></script> | ||
72 | <script type="text/javascript" src="app.js"></script> | 67 | <script type="text/javascript" src="app.js"></script> |
73 | 68 | ||
74 | </body> | 69 | </body> |