Commit df313401f78b57f722aac9bde520dcd20cbe91f6
- Diff rendering mode:
- inline
- side by side
app.js
(16 / 21)
  | |||
11 | 11 | var Comment = Backbone.Model.extend({ | |
12 | 12 | /* A model representing a comment. */ | |
13 | 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 | 24 | url: "http://127.0.0.1:5001/sweets", | |
… | … | ||
77 | 77 | "click .save": "save" | |
78 | 78 | }, | |
79 | 79 | initialize: function(){ | |
80 | // _.bindAll.apply(_, [this].concat(_.functions(this))); | ||
81 | // _.bind(this.render, this); | ||
82 | // this.listenTo(this.model, "change", this.render); | ||
83 | 80 | this.render(); | |
84 | 81 | }, | |
85 | 82 | ||
… | … | ||
87 | 87 | save: function(e){ | |
88 | 88 | /* Create a sweet and send it to the sweet store. | |
89 | 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 | 93 | this.model.set({created: new Date().toUTCString().substr(0, 25)}); | |
93 | 94 | new LoginView({model:this.model}); | |
94 | 95 | ||
… | … | ||
110 | 110 | _.each(this.collection.models, function(comment){ | |
111 | 111 | t = _.template($("#commented-template").html()); | |
112 | 112 | $("#commented").append(t(comment.toJSON())); | |
113 | //comment.get("how").comment); | ||
114 | 113 | }); | |
115 | 114 | ||
116 | // content = this.model.toJSON()["how"]["comment"]; | ||
117 | // $(this.el).append(this.template({content:content})); | ||
118 | 115 | }, | |
119 | 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 | 118 | $(e.currentTarget).parent().after("<div class='comment-reply'></div>"); | |
122 | 119 | el = $("#commented .comment-reply"); | |
123 | 120 | new CommentView({model: rep, el:el }); | |
… | … | ||
145 | 145 | this.set({"who":username}); | |
146 | 146 | $(".modal").modal('toggle'); | |
147 | 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 | }); | ||
152 | 152 | ||
153 | }}).then(function(){ | ||
154 | |||
155 | }); | ||
153 | }}); | ||
156 | 154 | ||
157 | 155 | } | |
158 | 156 | }); |