[#212,views][s]: refactor views and tutorial so that no render call in initialize and view element can be passed in externally (fixes #212).

This commit is contained in:
Rufus Pollock
2012-08-15 12:33:59 +01:00
parent c75e31a856
commit bc414e9f8c
5 changed files with 16 additions and 24 deletions

View File

@@ -156,6 +156,7 @@ var graph = new recline.View.Graph({
} }
}); });
$el.append(graph.el); $el.append(graph.el);
graph.render();
graph.redraw(); graph.redraw();
{% endhighlight %} {% endhighlight %}
@@ -174,6 +175,7 @@ var graph = new recline.View.Graph({
} }
}); });
$el.append(graph.el); $el.append(graph.el);
graph.render();
graph.redraw(); graph.redraw();
</script> </script>
@@ -213,7 +215,7 @@ var map = new recline.View.Map({
model: dataset model: dataset
}); });
$el.append(map.el); $el.append(map.el);
map.redraw(); map.render();
{% endhighlight %} {% endhighlight %}
<div id="mymap">&nbsp;</div> <div id="mymap">&nbsp;</div>

View File

@@ -21,10 +21,8 @@ this.recline.View = this.recline.View || {};
// NB: should *not* provide an el argument to the view but must let the view // NB: should *not* provide an el argument to the view but must let the view
// generate the element itself (you can then append view.el to the DOM. // generate the element itself (you can then append view.el to the DOM.
my.Graph = Backbone.View.extend({ my.Graph = Backbone.View.extend({
tagName: "div",
className: "recline-graph",
template: ' \ template: ' \
<div class="recline-graph"> \
<div class="panel graph" style="display: block;"> \ <div class="panel graph" style="display: block;"> \
<div class="js-temp-notice alert alert-block"> \ <div class="js-temp-notice alert alert-block"> \
<h3 class="alert-heading">Hey there!</h3> \ <h3 class="alert-heading">Hey there!</h3> \
@@ -65,7 +63,6 @@ my.Graph = Backbone.View.extend({
self.redraw(); self.redraw();
}); });
this.elSidebar = this.editor.el; this.elSidebar = this.editor.el;
this.render();
}, },
render: function() { render: function() {

View File

@@ -14,9 +14,6 @@ this.recline.View = this.recline.View || {};
// //
// NB: you need an explicit height on the element for slickgrid to work // NB: you need an explicit height on the element for slickgrid to work
my.SlickGrid = Backbone.View.extend({ my.SlickGrid = Backbone.View.extend({
tagName: "div",
className: "recline-slickgrid",
initialize: function(modelEtc) { initialize: function(modelEtc) {
var self = this; var self = this;
this.el = $(this.el); this.el = $(this.el);

View File

@@ -13,8 +13,6 @@ if (typeof VMM !== 'undefined') {
// //
// Timeline view using http://timeline.verite.co/ // Timeline view using http://timeline.verite.co/
my.Timeline = Backbone.View.extend({ my.Timeline = Backbone.View.extend({
tagName: 'div',
template: ' \ template: ' \
<div class="recline-timeline"> \ <div class="recline-timeline"> \
<div id="vmm-timeline-id"></div> \ <div id="vmm-timeline-id"></div> \
@@ -46,18 +44,17 @@ my.Timeline = Backbone.View.extend({
); );
this.state = new recline.Model.ObjectState(stateData); this.state = new recline.Model.ObjectState(stateData);
this._setupTemporalField(); this._setupTemporalField();
this.render();
// can only call _initTimeline once view in DOM as Timeline uses $
// internally to look up element
if ($(this.elementId).length > 0) {
this._initTimeline();
}
}, },
render: function() { render: function() {
var tmplData = {}; var tmplData = {};
var htmls = Mustache.render(this.template, tmplData); var htmls = Mustache.render(this.template, tmplData);
this.el.html(htmls); this.el.html(htmls);
// can only call _initTimeline once view in DOM as Timeline uses $
// internally to look up element
if ($(this.elementId).length > 0) {
this._initTimeline();
}
}, },
show: function() { show: function() {

View File

@@ -36,7 +36,6 @@ my.Transform = Backbone.View.extend({
initialize: function(options) { initialize: function(options) {
this.el = $(this.el); this.el = $(this.el);
this.render();
}, },
render: function() { render: function() {