summaryrefslogtreecommitdiff
path: root/public/assets/js/lib
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-12-11 10:04:14 +0100
committerJules Laplace <julescarbon@gmail.com>2017-12-11 10:04:14 +0100
commit242eed0093c59047033c286d7a14608d0096b125 (patch)
tree71fddb93c5f2c65eb9a3b0a628b2b879eba0007c /public/assets/js/lib
parentc06f440e4a41853fc30ff5b231c68bd766ba96fa (diff)
comment edit form
Diffstat (limited to 'public/assets/js/lib')
-rw-r--r--public/assets/js/lib/router.js30
-rw-r--r--public/assets/js/lib/views/details/editcomment.js42
2 files changed, 60 insertions, 12 deletions
diff --git a/public/assets/js/lib/router.js b/public/assets/js/lib/router.js
index 6802a86..27c8617 100644
--- a/public/assets/js/lib/router.js
+++ b/public/assets/js/lib/router.js
@@ -3,18 +3,19 @@ var SiteRouter = Router.extend({
el: "body",
routes: {
- "/": 'login',
- "/index/:keyword": 'index',
- "/index": 'index',
- "/login": 'login',
- "/details/:id": 'details',
- "/post": 'post',
- "/post/:keyword": 'post',
- "/search": 'search',
- "/mail": 'mailbox',
- "/mail/:mailbox": 'mailbox',
- "/mail/compose": 'compose',
- "/message/:id": 'message',
+ "/": 'login',
+ "/index/:keyword": 'index',
+ "/index": 'index',
+ "/login": 'login',
+ "/details/:id": 'details',
+ "/post": 'post',
+ "/post/:keyword": 'post',
+ "/search": 'search',
+ "/mail": 'mailbox',
+ "/mail/:mailbox": 'mailbox',
+ "/mail/compose": 'compose',
+ "/message/:id": 'message',
+ "/comment/:id/edit": 'editComment',
},
initialize: function(){
@@ -34,6 +35,11 @@ var SiteRouter = Router.extend({
app.view.load(id)
},
+ editComment: function(id){
+ app.view = new EditCommentForm ()
+ app.view.load(id)
+ },
+
mailbox: function(box){
app.view = new MailboxView ()
app.view.load(box)
diff --git a/public/assets/js/lib/views/details/editcomment.js b/public/assets/js/lib/views/details/editcomment.js
new file mode 100644
index 0000000..1e1474f
--- /dev/null
+++ b/public/assets/js/lib/views/details/editcomment.js
@@ -0,0 +1,42 @@
+var EditCommentForm = FormView.extend({
+
+ el: "#comment_form",
+
+ events: {
+ "focus textarea": 'focus',
+ },
+
+ action: "",
+
+ initialize: function(){
+ this.__super__.initialize.call(this)
+ this.template = this.$(".template").html()
+ this.$comment = this.$("[name=comment]")
+ },
+
+ load: function(id){
+ this.action = "/api/comment/" + id
+ $.get(this.action, function(data){
+ console.log(data)
+ this.$comment.val(data.comment.comment).focus()
+ $("body").removeClass("loading")
+ }.bind(this))
+ },
+
+ focus: function(){
+ this.$el.addClass('focused')
+ },
+
+ validate: function(){
+ var errors = []
+ var comment = $("[name=comment]").val()
+ if (! comment || ! comment.length) {
+ errors.push("Please enter a comment.")
+ }
+ return errors.length ? errors : null
+ },
+
+ success: function(data){
+ window.location.href = "/details/" + data.comment.id
+ }
+}) \ No newline at end of file