Skip to content

Commit

Permalink
Plugged edit and delete changes. Added issue filter, #46
Browse files Browse the repository at this point in the history
  • Loading branch information
YuliiaZaiats committed Aug 28, 2013
1 parent 24938f6 commit d2b672c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
3 changes: 2 additions & 1 deletion example_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ curl -X PUT http://localhost:5984/boards/_design/issues -H 'Content-Type: applic
}
},
"filters": {
"only_positions": "function(doc, req) { if(doc.type == \"position\") { return true; } }"
"only_positions": "function(doc, req) { if(doc.type == \"position\") { return true; } }",
"issue": "function(doc, req) {if(doc.type == \"issue\") { return true; } }"
}
}'
```
Expand Down
3 changes: 3 additions & 0 deletions example_app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ <h4 style="text-transform:capitalize;">{{name}}</h4>
{{else}}
{{text}}
<button type="submit" class="btn btn-xs btn-default"> Edit </button>
{{#view App.DeleteView contextBinding=this}}
<button class="btn btn-xs btn-default"> &times; </button>
{{/view}}
{{/if}}
</div>
{{/view}}
Expand Down
43 changes: 36 additions & 7 deletions example_app/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ App.IndexRoute = Ember.Route.extend({

setupController: function(controller, model) {
this._position();
this._issue();
//this._setupPosition();
},

Expand Down Expand Up @@ -58,7 +59,7 @@ App.IndexRoute = Ember.Route.extend({
params = { include_docs: true, timeout: 1000, filter: 'issues/only_positions'}
position = EmberCouchDBKit.ChangesFeed.create({ db: 'boards', content: params });

// all upcoming changes are passed to `_handlePositionChanges` callback through `longpool` strategy
// all upcoming changes are passed to `_handlePositionChanges` callback through `longpoll` strategy
position.longpoll(this._handlePositionChanges, this);
},

Expand All @@ -77,6 +78,28 @@ App.IndexRoute = Ember.Route.extend({
});
}
});
},

_issue: function(){
// create a CouchDB `/_change` issue listener which filtered only by issue documents
params = { include_docs: true, timeout: 1000, filter: 'issues/issue'}
issue = EmberCouchDBKit.ChangesFeed.create({ db: 'boards', content: params });

// all upcoming changes are passed to `_handleIssueChanges` callback through `fromTail` strategy
self = this;
issue.fromTail( (function(){
return issue.longpoll(self._handleIssueChanges, self);
}) );
},

_handleIssueChanges: function(data) {
self = this;
data.forEach(function(obj){
controller = self.controllerFor(obj.doc.board);
if ((controller.get('content').mapProperty('id').indexOf(obj.doc._id) >= 0)){
App.Issue.find(obj.doc._id).reload();
}
});
}
});

Expand All @@ -96,12 +119,10 @@ App.IndexController = Ember.ArrayController.extend({
},
saveMessage: function(model) {
model.save();
var position = this.get('content').toArray().indexOf(model)
this.get('content').removeObject(model);
thisArray = this.get('content').toArray().insertAt(position, model);
this.set('content.content', thisArray.getEach('_reference'));
this.set('position.issues.content', thisArray.getEach('_reference'));
this.get('position').save();
},
deleteMessage: function(message) {
message.deleteRecord();
message.get('store').commit();
},
needs: App.Boards
});
Expand Down Expand Up @@ -153,6 +174,14 @@ App.CancelView = Ember.View.extend({
}
});

App.DeleteView = Ember.View.extend({
tagName: "span",
click: function(event){
event.preventDefault();
this.get('controller').send('deleteMessage', this.get('context'));
}
});

App.IssueView = Ember.View.extend({
tagName: "form",

Expand Down

0 comments on commit d2b672c

Please sign in to comment.