Commit df313401f78b57f722aac9bde520dcd20cbe91f6

  • avatar
  • arvind
  • Mon Mar 03 14:59:48 IST 2014
Basic functionalities of the application are ready.

FIXME: Fix threading of comments.
  • app.js 37 ---------------------++++++++++++++++
  • Diff rendering mode:
  • inline
  • side by side

app.js

11 var Comment = Backbone.Model.extend({11 var Comment = Backbone.Model.extend({
12 /* A model representing a comment. */12 /* A model representing a comment. */
13 defaults: function(){13 defaults: function(){
14 return {
15 what: C.what,
16 where: window.location.href,
17 how:{
18 comment:''
19 }
14 return {
15 'who':'',
16 'what': C.what,
17 'where': window.location.href,
18 'how':{
19 'comment':'',
20 'replyTo':''
21 }
20 };22 };
21 },23 },
22 url: "http://127.0.0.1:5001/sweets",24 url: "http://127.0.0.1:5001/sweets",
77 "click .save": "save"77 "click .save": "save"
78 },78 },
79 initialize: function(){79 initialize: function(){
80 // _.bindAll.apply(_, [this].concat(_.functions(this)));
81 // _.bind(this.render, this);
82 // this.listenTo(this.model, "change", this.render);
83 this.render();80 this.render();
84 },81 },
8582
87 save: function(e){87 save: function(e){
88 /* Create a sweet and send it to the sweet store.88 /* Create a sweet and send it to the sweet store.
89 Update the view to include the comment */89 Update the view to include the comment */
90 this.model.set({how:{comment:this.$("textarea.form-control").val(),
91 replyTo:this.model.get('how')['replyTo']}});
90 e.preventDefault();
91 this.model.set({'how':{'comment':this.$("textarea.form-control").val(),
92 'replyTo':this.model.get('how')['replyTo']}});
92 this.model.set({created: new Date().toUTCString().substr(0, 25)});93 this.model.set({created: new Date().toUTCString().substr(0, 25)});
93 new LoginView({model:this.model});94 new LoginView({model:this.model});
9495
110 _.each(this.collection.models, function(comment){110 _.each(this.collection.models, function(comment){
111 t = _.template($("#commented-template").html());111 t = _.template($("#commented-template").html());
112 $("#commented").append(t(comment.toJSON()));112 $("#commented").append(t(comment.toJSON()));
113 //comment.get("how").comment);
114 });113 });
115114
116 // content = this.model.toJSON()["how"]["comment"];
117 // $(this.el).append(this.template({content:content}));
118 },115 },
119 reply: function(e){116 reply: function(e){
120 var rep = new Comment({how:{replyTo:$(e.currentTarget).attr('for')}});
117 var rep = new Comment({'how':{'replyTo':$(e.currentTarget).attr('for')}});
121 $(e.currentTarget).parent().after("<div class='comment-reply'></div>");118 $(e.currentTarget).parent().after("<div class='comment-reply'></div>");
122 el = $("#commented .comment-reply");119 el = $("#commented .comment-reply");
123 new CommentView({model: rep, el:el });120 new CommentView({model: rep, el:el });
145 this.set({"who":username});145 this.set({"who":username});
146 $(".modal").modal('toggle');146 $(".modal").modal('toggle');
147 this.save(null,{success:function(model){147 this.save(null,{success:function(model){
148 C.comments.add(model);
149 $("textarea.form-control").val(""); //Reset the view to have no content.
148 C.comments.add(model);
149 $("textarea.form-control").val(""); //Reset the view to have no content.
150 }150 }
151 });
151 });
152152
153 }}).then(function(){
154
155 });
153 }});
156154
157 }155 }
158 });156 });