Implemented entry exclusions in UI.
* Resolved D0020: Add exclusion filter for entries. * Refactored ``timeline`` fields of several objects in ``ts.js`` to be ``timelineModel`` to be explicit. * Added support for exclusions in ``EntryListView.renderOne`` and ``EntryListView.render``.
This commit is contained in:
52
www/js/ts.js
52
www/js/ts.js
@ -48,15 +48,16 @@ $(document).ready(function(){
|
||||
comparator: function(entry) { return entry.get('timestamp'); },
|
||||
|
||||
initialize: function(model, options) {
|
||||
if (options.timeline == undefined) {
|
||||
if (options.timelineModel == undefined) {
|
||||
throw "Cannot create an EntryList without a TimelineModel reference."
|
||||
} else { this.timeline = options.timeline; }
|
||||
} else { this.timelineModel = options.timelineModel; }
|
||||
|
||||
_.bindAll(this, "url");
|
||||
},
|
||||
|
||||
url: function() {
|
||||
return "/ts_api/entries/" + this.timeline.get('user_id') + "/" + this.timeline.get('id');
|
||||
return "/ts_api/entries/" + this.timelineModel.get('user_id') + "/"
|
||||
+ this.timelineModel.get('id');
|
||||
}
|
||||
});
|
||||
|
||||
@ -312,10 +313,26 @@ $(document).ready(function(){
|
||||
},
|
||||
|
||||
renderOne: function(entry, nextEntry) {
|
||||
// exclude if any exclusion RegExps match
|
||||
var excluded = _.any(this.entryExclusions,
|
||||
function(exclusion) { return exclusion.test(entry.get("mark"))});
|
||||
|
||||
// create the view if it does not exist
|
||||
if (!entry.view) { new TS.EntryView(
|
||||
{model: entry, markdownConverter: this.markdownConverter}); }
|
||||
entry.view.nextModel = nextEntry
|
||||
this.entryContainer.prepend(entry.view.render().el);
|
||||
|
||||
// render the element
|
||||
var el = entry.view.render().el;
|
||||
|
||||
// add it to the container
|
||||
this.entryContainer.prepend(el);
|
||||
|
||||
// hide it if excluded
|
||||
if (excluded) {
|
||||
$(el).fadeOut('slow');
|
||||
$(el).addClass('excluded');
|
||||
}
|
||||
},
|
||||
|
||||
createNewEntryOnEnter: function(e) {
|
||||
@ -337,6 +354,19 @@ $(document).ready(function(){
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
||||
// get our user exclusions
|
||||
var userExclusions = TS.app.user.model.get("entry_exclusions") || [];
|
||||
|
||||
// get the current timeline exclusions
|
||||
var timelineExclusions =
|
||||
this.collection.timelineModel.get("entry_exclusions") || [];
|
||||
|
||||
// turn them into RegExps and store them
|
||||
this.entryExclusions = _.map(
|
||||
userExclusions.concat(timelineExclusions),
|
||||
function(exclusion) { return new RegExp(exclusion)} );
|
||||
|
||||
this.entryContainer.empty();
|
||||
for (var i = 0, len = this.collection.length; i < len; i++) {
|
||||
var entry = this.collection.at(i);
|
||||
@ -367,7 +397,7 @@ $(document).ready(function(){
|
||||
if (options.initialTimelineId == undefined) {
|
||||
throw "Can not create a TimelineListView without an initial timeline."
|
||||
} else {
|
||||
this.selected = this.collection.get(options.initialTimelineId);
|
||||
this.selectedModel = this.collection.get(options.initialTimelineId);
|
||||
}
|
||||
|
||||
this.collection.bind('add', this.renderOne);
|
||||
@ -381,10 +411,10 @@ $(document).ready(function(){
|
||||
|
||||
render: function() {
|
||||
// render the basic template
|
||||
$(this.el).html(ich.timelineTemplate(this.selected.toJSON()));
|
||||
$(this.el).html(ich.timelineTemplate(this.selectedModel.toJSON()));
|
||||
|
||||
// render the selection list
|
||||
_.each(this.collection.without([this.selected]), this.renderOne);
|
||||
_.each(this.collection.without([this.selectedModel]), this.renderOne);
|
||||
},
|
||||
|
||||
editId: function() {
|
||||
@ -400,7 +430,7 @@ $(document).ready(function(){
|
||||
},
|
||||
|
||||
close: function() {
|
||||
this.selected.save({
|
||||
this.selectedModel.save({
|
||||
id: this.$('.timeline-id-input').val(),
|
||||
description: this.$('.timeline-desc-input').val()});
|
||||
$(this.el).removeClass('edit-id edit-desc');
|
||||
@ -515,7 +545,7 @@ $(document).ready(function(){
|
||||
// create the entry collection
|
||||
this.entries = {};
|
||||
this.entries.collection = new TS.EntryList(entryModels,
|
||||
{timeline: this.timelines.view.selected});
|
||||
{timelineModel: this.timelines.view.selectedModel});
|
||||
this.entries.view = new TS.EntryListView(
|
||||
{collection: this.entries.collection});
|
||||
|
||||
@ -553,10 +583,10 @@ $(document).ready(function(){
|
||||
var tl = this.timelines.collection.get(e.srcElement.text);
|
||||
|
||||
// set the on the timeline view
|
||||
this.timelines.view.selected = tl;
|
||||
this.timelines.view.selectedModel = tl;
|
||||
|
||||
// set the timeline on the EntryList
|
||||
this.entries.collection.timeline = tl;
|
||||
this.entries.collection.timelineModel = tl;
|
||||
|
||||
// update the last_timeline field of the user model
|
||||
this.user.model.set({last_timeline: tl.get('id')});
|
||||
|
Reference in New Issue
Block a user