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
(16 / 21)
  
1111 var Comment = Backbone.Model.extend({
1212 /* A model representing a comment. */
1313 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 }
2022 };
2123 },
2224 url: "http://127.0.0.1:5001/sweets",
7777 "click .save": "save"
7878 },
7979 initialize: function(){
80 // _.bindAll.apply(_, [this].concat(_.functions(this)));
81 // _.bind(this.render, this);
82 // this.listenTo(this.model, "change", this.render);
8380 this.render();
8481 },
8582
8787 save: function(e){
8888 /* Create a sweet and send it to the sweet store.
8989 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']}});
9293 this.model.set({created: new Date().toUTCString().substr(0, 25)});
9394 new LoginView({model:this.model});
9495
110110 _.each(this.collection.models, function(comment){
111111 t = _.template($("#commented-template").html());
112112 $("#commented").append(t(comment.toJSON()));
113 //comment.get("how").comment);
114113 });
115114
116 // content = this.model.toJSON()["how"]["comment"];
117 // $(this.el).append(this.template({content:content}));
118115 },
119116 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')}});
121118 $(e.currentTarget).parent().after("<div class='comment-reply'></div>");
122119 el = $("#commented .comment-reply");
123120 new CommentView({model: rep, el:el });
145145 this.set({"who":username});
146146 $(".modal").modal('toggle');
147147 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.
150150 }
151 });
151 });
152152
153 }}).then(function(){
154
155 });
153 }});
156154
157155 }
158156 });