[timeline][s]: make it easy to customize timeline info in client apps by providing convertRecord method.

This commit is contained in:
Rufus Pollock 2012-06-11 12:46:10 +01:00
parent 399172b8f4
commit 7b07a9558b
2 changed files with 60 additions and 22 deletions

41
dist/recline.js vendored
View File

@ -2755,6 +2755,8 @@ this.recline = this.recline || {};
this.recline.View = this.recline.View || {};
(function($, my) {
// turn off unnecessary logging from VMM Timeline
VMM.debug = false;
// ## Timeline
//
@ -2833,6 +2835,30 @@ my.Timeline = Backbone.View.extend({
}
},
// Convert record to JSON for timeline
//
// Designed to be overridden in client apps
convertRecord: function(record, fields) {
return this._convertRecord(record, fields);
},
// Internal method to generate a Timeline formatted entry
_convertRecord: function(record, fields) {
var start = this._parseDate(record.get(this.state.get('startField')));
var end = this._parseDate(record.get(this.state.get('endField')));
if (start) {
var tlEntry = {
"startDate": start,
"endDate": end,
"headline": String(record.get('title') || ''),
"text": record.get('description') || record.summary()
};
return tlEntry;
} else {
return null;
}
},
_timelineJSON: function() {
var self = this;
var out = {
@ -2843,17 +2869,10 @@ my.Timeline = Backbone.View.extend({
]
}
};
this.model.currentRecords.each(function(doc) {
var start = self._parseDate(doc.get(self.state.get('startField')));
var end = self._parseDate(doc.get(self.state.get('endField')));
if (start) {
var tlEntry = {
"startDate": start,
"endDate": end,
"headline": String(doc.get('title') || ''),
"text": doc.summary()
};
out.timeline.date.push(tlEntry);
this.model.currentRecords.each(function(record) {
var newEntry = self.convertRecord(record, self.fields);
if (newEntry) {
out.timeline.date.push(newEntry);
}
});
// if no entries create a placeholder entry to prevent Timeline crashing with error

View File

@ -4,6 +4,8 @@ this.recline = this.recline || {};
this.recline.View = this.recline.View || {};
(function($, my) {
// turn off unnecessary logging from VMM Timeline
VMM.debug = false;
// ## Timeline
//
@ -82,6 +84,30 @@ my.Timeline = Backbone.View.extend({
}
},
// Convert record to JSON for timeline
//
// Designed to be overridden in client apps
convertRecord: function(record, fields) {
return this._convertRecord(record, fields);
},
// Internal method to generate a Timeline formatted entry
_convertRecord: function(record, fields) {
var start = this._parseDate(record.get(this.state.get('startField')));
var end = this._parseDate(record.get(this.state.get('endField')));
if (start) {
var tlEntry = {
"startDate": start,
"endDate": end,
"headline": String(record.get('title') || ''),
"text": record.get('description') || record.summary()
};
return tlEntry;
} else {
return null;
}
},
_timelineJSON: function() {
var self = this;
var out = {
@ -92,17 +118,10 @@ my.Timeline = Backbone.View.extend({
]
}
};
this.model.currentRecords.each(function(doc) {
var start = self._parseDate(doc.get(self.state.get('startField')));
var end = self._parseDate(doc.get(self.state.get('endField')));
if (start) {
var tlEntry = {
"startDate": start,
"endDate": end,
"headline": String(doc.get('title') || ''),
"text": doc.summary()
};
out.timeline.date.push(tlEntry);
this.model.currentRecords.each(function(record) {
var newEntry = self.convertRecord(record, self.fields);
if (newEntry) {
out.timeline.date.push(newEntry);
}
});
// if no entries create a placeholder entry to prevent Timeline crashing with error