Commit a9860ea8 authored by Sam Saccone's avatar Sam Saccone

Merge pull request #1404 from kentcdodds/pr/jscs-fixes

Fix jscs issues found in #1403...
parents 8e849917 6da5aa7a
...@@ -9,40 +9,40 @@ ...@@ -9,40 +9,40 @@
* @param {object} view The view instance * @param {object} view The view instance
*/ */
function Controller(model, view) { function Controller(model, view) {
var that = this; var self = this;
that.model = model; self.model = model;
that.view = view; self.view = view;
that.view.bind('newTodo', function (title) { self.view.bind('newTodo', function (title) {
that.addItem(title); self.addItem(title);
}); });
that.view.bind('itemEdit', function (item) { self.view.bind('itemEdit', function (item) {
that.editItem(item.id); self.editItem(item.id);
}); });
that.view.bind('itemEditDone', function (item) { self.view.bind('itemEditDone', function (item) {
that.editItemSave(item.id, item.title); self.editItemSave(item.id, item.title);
}); });
that.view.bind('itemEditCancel', function (item) { self.view.bind('itemEditCancel', function (item) {
that.editItemCancel(item.id); self.editItemCancel(item.id);
}); });
that.view.bind('itemRemove', function (item) { self.view.bind('itemRemove', function (item) {
that.removeItem(item.id); self.removeItem(item.id);
}); });
that.view.bind('itemToggle', function (item) { self.view.bind('itemToggle', function (item) {
that.toggleComplete(item.id, item.completed); self.toggleComplete(item.id, item.completed);
}); });
that.view.bind('removeCompleted', function () { self.view.bind('removeCompleted', function () {
that.removeCompletedItems(); self.removeCompletedItems();
}); });
that.view.bind('toggleAll', function (status) { self.view.bind('toggleAll', function (status) {
that.toggleAll(status.completed); self.toggleAll(status.completed);
}); });
} }
...@@ -62,9 +62,9 @@ ...@@ -62,9 +62,9 @@
* todo-list * todo-list
*/ */
Controller.prototype.showAll = function () { Controller.prototype.showAll = function () {
var that = this; var self = this;
that.model.read(function (data) { self.model.read(function (data) {
that.view.render('showEntries', data); self.view.render('showEntries', data);
}); });
}; };
...@@ -72,9 +72,9 @@ ...@@ -72,9 +72,9 @@
* Renders all active tasks * Renders all active tasks
*/ */
Controller.prototype.showActive = function () { Controller.prototype.showActive = function () {
var that = this; var self = this;
that.model.read({ completed: false }, function (data) { self.model.read({ completed: false }, function (data) {
that.view.render('showEntries', data); self.view.render('showEntries', data);
}); });
}; };
...@@ -82,9 +82,9 @@ ...@@ -82,9 +82,9 @@
* Renders all completed tasks * Renders all completed tasks
*/ */
Controller.prototype.showCompleted = function () { Controller.prototype.showCompleted = function () {
var that = this; var self = this;
that.model.read({ completed: true }, function (data) { self.model.read({ completed: true }, function (data) {
that.view.render('showEntries', data); self.view.render('showEntries', data);
}); });
}; };
...@@ -93,15 +93,15 @@ ...@@ -93,15 +93,15 @@
* object and it'll handle the DOM insertion and saving of the new item. * object and it'll handle the DOM insertion and saving of the new item.
*/ */
Controller.prototype.addItem = function (title) { Controller.prototype.addItem = function (title) {
var that = this; var self = this;
if (title.trim() === '') { if (title.trim() === '') {
return; return;
} }
that.model.create(title, function () { self.model.create(title, function () {
that.view.render('clearNewTodo'); self.view.render('clearNewTodo');
that._filter(true); self._filter(true);
}); });
}; };
...@@ -109,9 +109,9 @@ ...@@ -109,9 +109,9 @@
* Triggers the item editing mode. * Triggers the item editing mode.
*/ */
Controller.prototype.editItem = function (id) { Controller.prototype.editItem = function (id) {
var that = this; var self = this;
that.model.read(id, function (data) { self.model.read(id, function (data) {
that.view.render('editItem', {id: id, title: data[0].title}); self.view.render('editItem', {id: id, title: data[0].title});
}); });
}; };
...@@ -119,13 +119,13 @@ ...@@ -119,13 +119,13 @@
* Finishes the item editing mode successfully. * Finishes the item editing mode successfully.
*/ */
Controller.prototype.editItemSave = function (id, title) { Controller.prototype.editItemSave = function (id, title) {
var that = this; var self = this;
if (title.trim()) { if (title.trim()) {
that.model.update(id, {title: title}, function () { self.model.update(id, {title: title}, function () {
that.view.render('editItemDone', {id: id, title: title}); self.view.render('editItemDone', {id: id, title: title});
}); });
} else { } else {
that.removeItem(id); self.removeItem(id);
} }
}; };
...@@ -133,9 +133,9 @@ ...@@ -133,9 +133,9 @@
* Cancels the item editing mode. * Cancels the item editing mode.
*/ */
Controller.prototype.editItemCancel = function (id) { Controller.prototype.editItemCancel = function (id) {
var that = this; var self = this;
that.model.read(id, function (data) { self.model.read(id, function (data) {
that.view.render('editItemDone', {id: id, title: data[0].title}); self.view.render('editItemDone', {id: id, title: data[0].title});
}); });
}; };
...@@ -147,26 +147,26 @@ ...@@ -147,26 +147,26 @@
* storage * storage
*/ */
Controller.prototype.removeItem = function (id) { Controller.prototype.removeItem = function (id) {
var that = this; var self = this;
that.model.remove(id, function () { self.model.remove(id, function () {
that.view.render('removeItem', id); self.view.render('removeItem', id);
}); });
that._filter(); self._filter();
}; };
/** /**
* Will remove all completed items from the DOM and storage. * Will remove all completed items from the DOM and storage.
*/ */
Controller.prototype.removeCompletedItems = function () { Controller.prototype.removeCompletedItems = function () {
var that = this; var self = this;
that.model.read({ completed: true }, function (data) { self.model.read({ completed: true }, function (data) {
data.forEach(function (item) { data.forEach(function (item) {
that.removeItem(item.id); self.removeItem(item.id);
}); });
}); });
that._filter(); self._filter();
}; };
/** /**
...@@ -179,16 +179,16 @@ ...@@ -179,16 +179,16 @@
* @param {boolean|undefined} silent Prevent re-filtering the todo items * @param {boolean|undefined} silent Prevent re-filtering the todo items
*/ */
Controller.prototype.toggleComplete = function (id, completed, silent) { Controller.prototype.toggleComplete = function (id, completed, silent) {
var that = this; var self = this;
that.model.update(id, { completed: completed }, function () { self.model.update(id, { completed: completed }, function () {
that.view.render('elementComplete', { self.view.render('elementComplete', {
id: id, id: id,
completed: completed completed: completed
}); });
}); });
if (!silent) { if (!silent) {
that._filter(); self._filter();
} }
}; };
...@@ -197,14 +197,14 @@ ...@@ -197,14 +197,14 @@
* Just pass in the event object. * Just pass in the event object.
*/ */
Controller.prototype.toggleAll = function (completed) { Controller.prototype.toggleAll = function (completed) {
var that = this; var self = this;
that.model.read({ completed: !completed }, function (data) { self.model.read({ completed: !completed }, function (data) {
data.forEach(function (item) { data.forEach(function (item) {
that.toggleComplete(item.id, completed, true); self.toggleComplete(item.id, completed, true);
}); });
}); });
that._filter(); self._filter();
}; };
/** /**
...@@ -212,16 +212,16 @@ ...@@ -212,16 +212,16 @@
* number of todos. * number of todos.
*/ */
Controller.prototype._updateCount = function () { Controller.prototype._updateCount = function () {
var that = this; var self = this;
that.model.getCount(function (todos) { self.model.getCount(function (todos) {
that.view.render('updateElementCount', todos.active); self.view.render('updateElementCount', todos.active);
that.view.render('clearCompletedButton', { self.view.render('clearCompletedButton', {
completed: todos.completed, completed: todos.completed,
visible: todos.completed > 0 visible: todos.completed > 0
}); });
that.view.render('toggleAll', {checked: todos.completed === todos.total}); self.view.render('toggleAll', {checked: todos.completed === todos.total});
that.view.render('contentBlockVisibility', {visible: todos.total > 0}); self.view.render('contentBlockVisibility', {visible: todos.total > 0});
}); });
}; };
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
return htmlEscapes[chr]; return htmlEscapes[chr];
}; };
var reUnescapedHtml = /[&<>"'`]/g, var reUnescapedHtml = /[&<>"'`]/g;
reHasUnescapedHtml = new RegExp(reUnescapedHtml.source); var reHasUnescapedHtml = new RegExp(reUnescapedHtml.source);
var escape = function (string) { var escape = function (string) {
return (string && reHasUnescapedHtml.test(string)) return (string && reHasUnescapedHtml.test(string))
......
This diff is collapsed.
...@@ -198,7 +198,7 @@ describe('controller', function () { ...@@ -198,7 +198,7 @@ describe('controller', function () {
view.trigger('toggleAll', {completed: false}); view.trigger('toggleAll', {completed: false});
expect(view.render).toHaveBeenCalledWith('elementComplete', {id : 42, completed : false}); expect(view.render).toHaveBeenCalledWith('elementComplete', {id: 42, completed: false});
}); });
}); });
......
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