[timeline][s]: make it easy to customize timeline info in client apps by providing convertRecord method.
This commit is contained in:
41
dist/recline.js
vendored
41
dist/recline.js
vendored
@@ -2755,6 +2755,8 @@ this.recline = this.recline || {};
|
|||||||
this.recline.View = this.recline.View || {};
|
this.recline.View = this.recline.View || {};
|
||||||
|
|
||||||
(function($, my) {
|
(function($, my) {
|
||||||
|
// turn off unnecessary logging from VMM Timeline
|
||||||
|
VMM.debug = false;
|
||||||
|
|
||||||
// ## Timeline
|
// ## 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() {
|
_timelineJSON: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var out = {
|
var out = {
|
||||||
@@ -2843,17 +2869,10 @@ my.Timeline = Backbone.View.extend({
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.model.currentRecords.each(function(doc) {
|
this.model.currentRecords.each(function(record) {
|
||||||
var start = self._parseDate(doc.get(self.state.get('startField')));
|
var newEntry = self.convertRecord(record, self.fields);
|
||||||
var end = self._parseDate(doc.get(self.state.get('endField')));
|
if (newEntry) {
|
||||||
if (start) {
|
out.timeline.date.push(newEntry);
|
||||||
var tlEntry = {
|
|
||||||
"startDate": start,
|
|
||||||
"endDate": end,
|
|
||||||
"headline": String(doc.get('title') || ''),
|
|
||||||
"text": doc.summary()
|
|
||||||
};
|
|
||||||
out.timeline.date.push(tlEntry);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// if no entries create a placeholder entry to prevent Timeline crashing with error
|
// if no entries create a placeholder entry to prevent Timeline crashing with error
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ this.recline = this.recline || {};
|
|||||||
this.recline.View = this.recline.View || {};
|
this.recline.View = this.recline.View || {};
|
||||||
|
|
||||||
(function($, my) {
|
(function($, my) {
|
||||||
|
// turn off unnecessary logging from VMM Timeline
|
||||||
|
VMM.debug = false;
|
||||||
|
|
||||||
// ## Timeline
|
// ## 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() {
|
_timelineJSON: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var out = {
|
var out = {
|
||||||
@@ -92,17 +118,10 @@ my.Timeline = Backbone.View.extend({
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.model.currentRecords.each(function(doc) {
|
this.model.currentRecords.each(function(record) {
|
||||||
var start = self._parseDate(doc.get(self.state.get('startField')));
|
var newEntry = self.convertRecord(record, self.fields);
|
||||||
var end = self._parseDate(doc.get(self.state.get('endField')));
|
if (newEntry) {
|
||||||
if (start) {
|
out.timeline.date.push(newEntry);
|
||||||
var tlEntry = {
|
|
||||||
"startDate": start,
|
|
||||||
"endDate": end,
|
|
||||||
"headline": String(doc.get('title') || ''),
|
|
||||||
"text": doc.summary()
|
|
||||||
};
|
|
||||||
out.timeline.date.push(tlEntry);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// if no entries create a placeholder entry to prevent Timeline crashing with error
|
// if no entries create a placeholder entry to prevent Timeline crashing with error
|
||||||
|
|||||||
Reference in New Issue
Block a user