Last active
April 29, 2016 13:36
-
-
Save a0viedo/1121cf0d4fbfdbc9eaa0a8bed4c066d4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodoController = createController(); | |
TodoController.prototype.onClickCheckbox = function() { | |
this.getModel().toggleDone(); | |
}; | |
checkit.TodoController = TodoController; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodosInputController = createController(); | |
TodosInputController.prototype.onFocusInput = function() { | |
this.onKeyupInput(); | |
}; | |
TodosInputController.prototype.onBlurInput = function() { | |
this.getView().setPending(false); | |
}; | |
TodosInputController.prototype.onKeyupInput = function() { | |
var view = this.getView(); | |
view.setPending(!checkit.isBlank(view.getInputValue())); | |
} | |
TodosInputController.prototype.onKeypressInput = function() { | |
if (evt.keyCode == 13) { | |
var view = this.getView(); | |
var value = view.getInputValue(); | |
if (!checkit.isBlank(value)) { | |
var todo = new checkit.TodoModel(); | |
todo.setContent(value); | |
this.getModel().add(todo); | |
view.clearInput(); | |
} | |
}} | |
}; | |
checkit.TodosInputController = TodosInputController; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodoModel = createModel(); | |
TodoModel.prototype.content = { | |
type: 'string', | |
trim: true | |
}; | |
checkit.TodoModel = TodoModel; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodosInputView = createView(); | |
TodosInputView.prototype.uiActions = [ | |
{ | |
selector: '.content', | |
methodName: 'onFocusInput', | |
eventName: 'focus' | |
}, | |
{ | |
selector: '.content', | |
methodName: 'onBlurInput', | |
eventName: 'blur' | |
}, | |
{ | |
selector: '.content', | |
methodName: 'onKeyupInput', | |
eventName: 'keyup' | |
}, | |
{ | |
selector: '.content', | |
methodName: 'onKeypressInput', | |
eventName: 'keypress' | |
} | |
] | |
TodosInputView.prototype.getInputValue = function() { | |
return this.find('.content').value; | |
}; | |
TodosInputView.prototype.clearInput = function() { | |
this.find('.content').value = ''; | |
}; | |
TodosInputView.prototype.setPending = function() { | |
aristocrat[pending ? 'addClass' : 'removeClass']( | |
this.find('.TodosInput'), 'TodosInputPending'); | |
}; | |
checkit.TodosInputView = TodosInputView; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodosListView = createView(); | |
TodosListView.prototype.createChildView = function(todoModel) { | |
return new checkit.TodoView(todoModel); | |
}; | |
checkit.TodosListView = TodosListView; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodosModel = createModel(); | |
TodosModel.prototype.isAllUndone = function() { | |
return this.every(function (todo) { | |
return !todo.isDone(); | |
}); | |
}; | |
TodosModel.prototype.isAllDone = function() { | |
return (this.size > 0) && | |
this.every(function (todo) { | |
return todo.isDone(); | |
}); | |
}; | |
TodosModel.prototype.markAllUndone = function() { | |
this.forEach(function (todo) { | |
todo.setDone(false); | |
}); | |
}; | |
TodosModel.prototype.markAllDone = function() { | |
this.forEach(function (todo) { | |
todo.setDone(true); | |
}); | |
}; | |
TodosModel.prototype.deleteDone = function() { | |
var doneTodos = []; | |
this.forEach(function (todo) { | |
if (todo.isDone()) { | |
doneTodos.push(todo); | |
} | |
}); | |
this['delete'].apply(this, doneTodos); | |
}; | |
checkit.TodosModel = TodosModel; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodosToolbarView = createView(); | |
TodosToolbarView.prototype.buildData = function() { | |
var model = this.getModel(); | |
var checkbox = this.find('.allCheckbox'); | |
var button = this.find('.deleteDone'); | |
var isAllDone = model.isAllDone(); | |
aristocrat[isAllDone ? 'addClass' : 'removeClass']( | |
this.find('.allCheckbox'), 'allCheckboxAllDone'); | |
button.disabled = model.isAllUndone(); | |
}; | |
TodosToolbarView.prototype.update = function() { | |
this.buildData(); | |
}; | |
checkit.TodosToolbarView = TodosToolbarView; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodosToolbarController = createController(); | |
TodosToolbarController.prototype.onClickDeleteDone = function() { | |
this.getModel().deleteDone(); | |
}; | |
TodosToolbarController.prototype.onClickAllCheckbox = function() { | |
var model = this.getModel(); | |
if (model.isAllDone()) { | |
model.markAllUndone(); | |
} else { | |
model.markAllDone(); | |
} | |
}; | |
TodosToolbarController.checkit = TodosToolbarController; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var TodoView = createView(); | |
TodoView.prototype.uiActions = [ | |
{ | |
selector: '.checkbox', | |
eventName: 'click', | |
methodName: 'onClickCheckbox' | |
} | |
]; | |
TodoView.prototype.buildData = function() { | |
var model = this.getModel(); | |
this.find('.content').innerHTML = checkit.escapeHTML(model.getContent()); | |
aristocrat[model.isDone() ? 'addClass' : 'removeClass']( | |
this.find('.Todo'), 'TodoDone'); | |
}; | |
TodoView.prototype.update = function() { | |
this.buildData(); | |
}; | |
checkit.TodoView = TodoView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment