Commit d82fcf5a authored by Pascal Hartig's avatar Pascal Hartig

Merge pull request #616 from stephenplusplus/flight-bug

(flight) bug with clearCompleted.
parents d50f6e65 cceaffa8
/*global define */
'use strict';
define(
[
define([
'./data/todos',
'./data/stats',
'./ui/new_item',
......@@ -10,17 +9,7 @@ define(
'./ui/stats',
'./ui/main_selector',
'./ui/toggle_all'
],
function (
TodosData,
StatsData,
NewItemUI,
TodoListUI,
StatsUI,
MainSelectorUI,
ToggleAllUI) {
], function (TodosData, StatsData, NewItemUI, TodoListUI, StatsUI, MainSelectorUI, ToggleAllUI) {
var initialize = function () {
StatsData.attachTo(document);
TodosData.attachTo(document);
......@@ -34,5 +23,4 @@ define(
return {
initialize: initialize
};
}
);
});
/*global define */
'use strict';
define(
[
define([
'flight/component',
'../store'
],
function (defineComponent, dataStore) {
return defineComponent(stats);
], function (defineComponent, dataStore) {
function stats() {
this.recount = function () {
var todos = dataStore.all();
......@@ -35,5 +30,6 @@ define(
this.on(document, 'dataTodoToggledAll', this.recount);
});
}
}
);
return defineComponent(stats);
});
/*global define */
'use strict';
define(
[
define([
'flight/component',
'../store'
],
function (defineComponent, dataStore) {
return defineComponent(todos);
], function (defineComponent, dataStore) {
function todos() {
var filter;
......@@ -28,7 +23,7 @@ define(
this.trigger('dataTodoRemoved', todo);
};
this.load = function (e, data) {
this.load = function () {
var todos;
filter = localStorage.getItem('filter');
......@@ -74,8 +69,7 @@ define(
todos = dataStore.find(function (each) {
return (typeof each[filter] !== 'undefined') ? each.completed : !each.completed;
});
}
else {
} else {
todos = dataStore.all();
}
......@@ -83,11 +77,10 @@ define(
};
this.clearCompleted = function () {
var todos;
dataStore.destroyAll({ completed: true });
todos = dataStore.all();
this.trigger('dataClearedCompleted', { todos: todos });
this.trigger('uiFilterRequested', { filter: filter });
this.trigger('dataClearedCompleted');
};
this.after('initialize', function () {
......@@ -101,5 +94,6 @@ define(
this.on(document, 'uiFilterRequested', this.filter);
});
}
}
);
return defineComponent(todos);
});
/*global define */
'use strict';
define(
[
define([
'depot'
],
function (depot) {
], function (depot) {
return depot('todos', { idAttribute: 'id' });
}
);
});
/*global define */
'use strict';
define(
[
define([
'flight/component'
],
function (defineComponent) {
return defineComponent(mainSelector);
], function (defineComponent) {
function mainSelector() {
this.toggle = function (e, data) {
var toggle = data.all > 0;
......@@ -20,5 +15,6 @@ define(
this.on(document, 'dataStatsCounted', this.toggle);
});
}
}
);
return defineComponent(mainSelector);
});
/*global define */
'use strict';
define(
[
define([
'flight/component'
],
function (defineComponent) {
return defineComponent(newItem);
], function (defineComponent) {
function newItem() {
var ENTER_KEY = 13;
......@@ -29,5 +24,6 @@ define(
this.on('keydown', this.createOnEnter);
});
}
}
);
return defineComponent(newItem);
});
/*global define */
'use strict';
define(
[
define([
'flight/component',
'./with_filters',
'text!app/templates/stats.html',
'../utils'
],
function (defineComponent, withFilters, statsTmpl, utils) {
return defineComponent(stats, withFilters);
], function (defineComponent, withFilters, statsTmpl, utils) {
function stats() {
var template = utils.tmpl(statsTmpl);
......@@ -27,7 +22,7 @@ define(
this.markSelected(data.filter);
};
this.clearCompleted = function (e, data) {
this.clearCompleted = function () {
this.trigger('uiClearRequested');
};
......@@ -37,5 +32,6 @@ define(
this.on('click', { 'clearCompletedSelector': this.clearCompleted });
});
}
}
);
return defineComponent(stats, withFilters);
});
/*global define $ */
/*global define, $ */
'use strict';
define(
[
define([
'flight/component',
'text!app/templates/todo.html',
'../utils'
],
function (defineComponent, todoTmpl, utils) {
return defineComponent(todoList);
], function (defineComponent, todoTmpl, utils) {
function todoList() {
var ENTER_KEY = 13;
var template = utils.tmpl(todoTmpl);
......@@ -44,7 +39,7 @@ define(
this.select('editSelector').focus();
};
this.requestUpdate = function (e, data) {
this.requestUpdate = function (e) {
var $inputEl = $(e.currentTarget);
var $todoEl = $inputEl.parents('li');
var value = $inputEl.val().trim();
......@@ -54,7 +49,7 @@ define(
return;
}
!$todoEl.removeClass('editing');
$todoEl.removeClass('editing');
if (value) {
$todoEl.find('label').html(value);
......@@ -91,7 +86,6 @@ define(
this.on(document, 'dataTodoAdded', this.render);
this.on(document, 'dataTodosLoaded', this.renderAll);
this.on(document, 'dataTodosFiltered', this.renderAll);
this.on(document, 'dataClearedCompleted', this.renderAll);
this.on(document, 'dataTodoToggledAll', this.renderAll);
this.on(document, 'dataTodoRemoved', this.remove);
......@@ -109,5 +103,6 @@ define(
this.trigger('uiLoadRequested');
});
}
}
);
return defineComponent(todoList);
});
/*global define */
'use strict';
define(
[
define([
'flight/component'
],
function (defineComponent) {
return defineComponent(toggleAll);
], function (defineComponent) {
function toggleAll() {
this.toggleAllComplete = function () {
this.trigger('uiToggleAllRequested', {
......@@ -25,5 +20,6 @@ define(
this.on(document, 'dataStatsCounted', this.toggleCheckbox);
});
}
}
);
return defineComponent(toggleAll);
});
/*global define $ */
/*global define, $ */
'use strict';
define(
function () {
define(function () {
return function withFilters() {
this.defaultAttrs({
filterSelector: '#filters a'
......@@ -24,5 +23,4 @@ define(
this.on('click', { filterSelector: this.chooseFilter });
});
};
}
);
});
......@@ -4,7 +4,6 @@
// tmpl function scooped from underscore.
// http://documentcloud.github.com/underscore/#template
define(function () {
var _ = {};
// List of HTML entities for escaping.
......@@ -128,5 +127,7 @@ define(function () {
return template;
};
return { tmpl: template };
return {
tmpl: template
};
});
<span id="todo-count"><strong><%= remaining %></strong> <%= remaining == 1 ? 'item' : 'items' %> left</span>
<span id="todo-count">
<strong><%= remaining %></strong> <%= remaining == 1 ? 'item' : 'items' %> left
</span>
<ul id="filters">
<li>
<a href="#/">All</a>
......@@ -11,5 +13,5 @@
</li>
</ul>
<% if (completed) { %>
<button id="clear-completed">Clear completed (<%= completed %>)</button>
<button id="clear-completed">Clear completed (<%= completed %>)</button>
<% } %>
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