Commit 8da22268 authored by Stas SUȘCOV's avatar Stas SUȘCOV

Update todos controller to initalize secondary views upon content attribute setup.

TODO: Refactor this to be part of `ApplicationView` as child views.
parent 43d57107
define('app/controllers/todos', [
'app/controllers/entries',
'app/views/items',
'app/views/stats',
'app/views/filters',
'app/views/clear_button',
'app/views/clear_button'
],
/**
* Todos controller
......@@ -11,24 +9,23 @@ define('app/controllers/todos', [
* Main controller inherits the `Entries` class
* which is an `ArrayProxy` linked with the `Store` model
*
* @param Class Entries, the Entries class
* @param Class ItemsView, items view class
* @param Class StatsView, stats view class
* @param Class FiltersView, filters view class
* @param Class ClearBtnView, clear button view class
* @returns Class
*/
function( Entries, ItemsView, StatsView, FiltersView, ClearBtnView ) {
return Entries.extend({
function( StatsView, FiltersView, ClearBtnView ) {
return Ember.Controller.extend({
viewsLoaded: false,
// New todo input
InputView: Ember.TextField.extend({
placeholder: 'What needs to be done?',
elementId: 'new-todo',
// Bind this to newly inserted line
insertNewline: function() {
var value = this.get( 'value' );
if ( value ) {
this.get( 'controller' ).createNew( value );
this.get( 'content' ).createNew( value );
this.set( 'value', '' );
}
}
......@@ -36,33 +33,36 @@ define('app/controllers/todos', [
// Handle visibility of some elements as items totals change
visibilityObserver: function() {
$( '#main, #footer' ).toggle( !!this.get( 'total' ) );
}.observes( 'total' ),
$( '#main, #footer' ).toggle( !!this.getPath( 'content.total' ) );
}.observes( 'content.total' ),
// Checkbox to mark all todos done.
MarkAllChkbox: Ember.Checkbox.extend({
elementId: 'toggle-all',
checkedBinding: 'controller.allAreDone'
checkedBinding: 'content.allAreDone'
}),
// Activates the views and other initializations
init: function() {
this._super();
// Activates secondary views when content was set
initViews: function() {
var entries = this.get( 'content' );
if ( this.get( 'viewsLoaded' ) || Ember.none( entries ) )
return;
this.set( 'inputView', this.InputView.create({ controller: this }) );
this.set( 'markAllChkbox', this.MarkAllChkbox.create({ controller: this }) );
this.set( 'itemsView', ItemsView.create({ controller: this }) );
this.set( 'statsView', StatsView.create({ controller: this }) );
this.set( 'inputView', this.InputView.create({ content: entries }) );
this.set( 'markAllChkbox', this.MarkAllChkbox.create({ content: entries }) );
// this.set( 'itemsView', ItemsView.create({ controller: this }) );
this.set( 'statsView', StatsView.create({ controller: entries }) );
this.set( 'filtersView', FiltersView.create() );
this.set( 'clearBtnView', ClearBtnView.create({ controller: this }) );
this.set( 'clearBtnView', ClearBtnView.create({ controller: entries }) );
this.get( 'inputView' ).appendTo( 'header' );
this.get( 'markAllChkbox' ).appendTo( '#main' );
this.get( 'itemsView' ).appendTo( '#main' );
// this.get( 'itemsView' ).appendTo( '#main' );
this.get( 'statsView' ).appendTo( '#footer' );
this.get( 'filtersView' ).appendTo( '#footer' );
this.get( 'clearBtnView' ).appendTo( '#footer' );
}
}.observes( 'content' )
});
}
);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment