Permalink
Browse files

Refactored KO Feature.addComment

  • Loading branch information...
1 parent cae0793 commit f340de4ed72e0842a962b915ae9dd5a94ba1e88b @arafatm committed Aug 16, 2011
Showing with 22 additions and 25 deletions.
  1. +21 −24 public/js/kokanban.js
  2. +1 −1 views/index.erb
View
@@ -15,23 +15,28 @@ var Feature = function(id, title, status, state) {
this.state = ko.observable(state);
this.comments = ko.observableArray([]);
- this.addComment = function(comment, created_at) {
- var f = this;
+ this.addComment = function(form) {
+ var newComment;
+ if (form['newComment'].value.length > 0){
+ newComment = form['newComment'].value;
+ var f = this;
- $.ajax({
- type: "PUT",
- url: '/feature/'+this.id+'/comment',
- data: { "comment": comment },
- dataType: 'json',
- success: function(data) {
- $.each(data, function(fk, fv) {
- f.comments.unshift(new Comment(fv.comment, fv.user, fv.created_at));
- });
- },
- error: function(msg) {
- console.log( msg.responseText );
- }
- });
+ $.ajax({
+ type: "PUT",
+ url: '/feature/'+this.id+'/comment',
+ data: { "comment": newComment },
+ dataType: 'json',
+ success: function(data) {
+ $.each(data, function(fk, fv) {
+ f.comments.unshift(new Comment(fv.comment, fv.user, fv.created_at));
+ });
+ form['newComment'].value = '';
+ },
+ error: function(msg) {
+ console.log( msg.responseText );
+ }
+ });
+ }
}
this.state.subscribe(function(newstate) {
@@ -52,14 +57,6 @@ var Feature = function(id, title, status, state) {
});
}, this);
- // Comments
- this.updateFeature = function(form) {
- if (form['newComment'].value.length > 0){
- this.addComment(form['newComment'].value);
- form['newComment'].value = '';
- }
- }
-
// Swimming
this.canSwimForward = ko.dependentObservable(function() {
if (this.status() != statuses[statuses.length - 1]) {
View
@@ -44,7 +44,7 @@
<a class="showComment" data-bind="text: title, click: function(e) { showDetails(e) }" />
<div class="details" data-bind="visible: false">
<select data-bind="options: states, value: state" />
- <form data-bind="submit: updateFeature">
+ <form data-bind="submit: addComment">
<input id="newComment" class='newComment' />
</form>
<div class="comments" data-bind="template: {name: 'comments', foreach: $data.comments}" />

0 comments on commit f340de4

Please sign in to comment.