I know that EmberJS recommends using Routes to tie together models, views and controllers and this is a very convenient to setup the main content of a page. However suppose I have a sidebar that will show information from a second source. e.g an rss feed. Or a status panel attached to some server stats, I want a view that can be added to any template {{ view MessageView }} that connects to a separate model.
What is the 'ember way' to do this.
So far the best I can do is to have explicit View and Controller objects overriding the init function to wire them together. for example:
/*
* The messages class is a free floating list of messages that can be plugged into any page.
* it is implemented as a view with a separate controller and model.
* As its not associated with a route we need to bind the view, controller and model together directly using
* init statements.
*/
/**************************
* Model
**************************/
App.Message = DS.Model.extend({
msg: DS.attr('string'),
author: DS.attr('string'),
date: DS.attr('date'),
display_class: DS.attr('string')
});
/**************************
* Route
**************************/
//App.MessageRoute = Ember.Route.extend({
// model : function() {
// return this.get('store').findAll('message');
// }
//});
/**************************
* Views
**************************/
App.MessageView = Em.View.extend({
init: function() {
// this._super();
this.set("controller", App.MessageController.create());
},
});
/**************************
* Controllers
**************************/
App.MessageController = Em.ArrayController.extend({
init: function() {
// this._super();
this.set("model", model : function() {
return this.get('store').findAll('message');
});
},
});
/**************************
* Fixture
**************************/
App.Message.FIXTURES = [{
id: 1,
msg: "App website will be down for maintenance for 4 hours on Friday 29th Nov",
author: { name: "Admin" },
date: new Date('2013-11-18T19:00:00Z'),
display_class: 'warning'
}, {
id: 2,
msg: "Tropical Cyclone may affect North Island net week [read more](http://www.bom.gov.au/cyclone/)",
author: { name: "WeatherMan" },
date: new Date('2013-11-18'),
},
];
However all I really need is some way to reproduce what the Route function already does.
Is there a better way?
Is there an example of a dashboard style page that has multiple independent view areas ?
Thanks Andrew