Commit 5e56786e authored by Peter Michaux's avatar Peter Michaux

update to latest maria.js and associated changes in the app

parent 343db310
...@@ -2,15 +2,19 @@ maria.addEventListener(window, 'load', function() { ...@@ -2,15 +2,19 @@ maria.addEventListener(window, 'load', function() {
var loading = document.getElementById('loading'); var loading = document.getElementById('loading');
loading.parentNode.removeChild(loading); loading.parentNode.removeChild(loading);
var model;
if ((typeof localStorage === 'object') && (typeof JSON === 'object')) { if ((typeof localStorage === 'object') && (typeof JSON === 'object')) {
var store = localStorage.getItem('todos-maria'); var store = localStorage.getItem('todos-maria');
var model = store ? checkit.TodosModel.fromJSON(JSON.parse(store)) : model = store ? checkit.TodosModel.fromJSON(JSON.parse(store)) :
new checkit.TodosModel(); new checkit.TodosModel();
evento.addEventListener(model, 'change', function() { evento.addEventListener(model, 'change', function() {
localStorage.setItem('todos-maria', JSON.stringify(model.toJSON())); localStorage.setItem('todos-maria', JSON.stringify(model.toJSON()));
}); });
} }
else {
model = new checkit.TodosModel();
}
var app = new checkit.TodosAppView(model); var view = new checkit.TodosAppView(model);
document.body.appendChild(app.getRootEl()); document.body.appendChild(view.build());
}); });
...@@ -10,22 +10,25 @@ maria.ElementView.subclass(checkit, 'TodoView', { ...@@ -10,22 +10,25 @@ maria.ElementView.subclass(checkit, 'TodoView', {
'blur .todo-input' : 'onBlurInput' 'blur .todo-input' : 'onBlurInput'
}, },
properties: { properties: {
update: function() { buildData: function() {
var model = this.getModel(); var model = this.getModel();
var content = model.getContent(); var content = model.getContent();
this.find('.todo-content').innerHTML = this.find('.todo-content').innerHTML =
content.replace('&', '&amp;').replace('<', '&lt;'); content.replace('&', '&amp;').replace('<', '&lt;');
this.find('.check').checked = model.isDone(); this.find('.check').checked = model.isDone();
aristocrat[model.isDone() ? 'addClass' : 'removeClass'](this.getRootEl(), 'done'); aristocrat[model.isDone() ? 'addClass' : 'removeClass'](this.find('.todo'), 'done');
},
update: function() {
this.buildData();
}, },
showEdit: function() { showEdit: function() {
var input = this.find('.todo-input'); var input = this.find('.todo-input');
input.value = this.getModel().getContent(); input.value = this.getModel().getContent();
aristocrat.addClass(this.getRootEl(), 'editing'); aristocrat.addClass(this.find('.todo'), 'editing');
input.select(); input.select();
}, },
showDisplay: function() { showDisplay: function() {
aristocrat.removeClass(this.getRootEl(), 'editing'); aristocrat.removeClass(this.find('.todo'), 'editing');
}, },
getInputValue: function() { getInputValue: function() {
return this.find('.todo-input').value; return this.find('.todo-input').value;
......
...@@ -8,10 +8,6 @@ maria.ElementView.subclass(checkit, 'TodosAppView', { ...@@ -8,10 +8,6 @@ maria.ElementView.subclass(checkit, 'TodosAppView', {
}, },
initialize: function() { initialize: function() {
var model = this.getModel(); var model = this.getModel();
if (!model) {
model = new checkit.TodosModel();
this.setModel(model);
}
this.appendChild(new checkit.TodosInputView(model)); this.appendChild(new checkit.TodosInputView(model));
this.appendChild(new checkit.TodosToolbarView(model)); this.appendChild(new checkit.TodosToolbarView(model));
this.appendChild(new checkit.TodosListView(model)); this.appendChild(new checkit.TodosListView(model));
......
maria.ElementView.subclass(checkit, 'TodosInputView', { maria.ElementView.subclass(checkit, 'TodosInputView', {
modelConstructor: checkit.TodosModel,
uiActions: { uiActions: {
'focus .new-todo': 'onFocusInput' , 'focus .new-todo': 'onFocusInput' ,
'blur .new-todo': 'onBlurInput' , 'blur .new-todo': 'onBlurInput' ,
......
maria.SetView.subclass(checkit, 'TodosListView', { maria.SetView.subclass(checkit, 'TodosListView', {
modelConstructor: checkit.TodosModel,
properties: { properties: {
createChildView: function(todoModel) { createChildView: function(todoModel) {
return new checkit.TodoView(todoModel); return new checkit.TodoView(todoModel);
......
maria.ElementView.subclass(checkit, 'TodosStatsView', { maria.ElementView.subclass(checkit, 'TodosStatsView', {
modelConstructor: checkit.TodosModel,
properties: { properties: {
update: function() { buildData: function() {
this.find('.todos-count').innerHTML = this.getModel().length; this.find('.todos-count').innerHTML = this.getModel().length;
},
update: function() {
this.buildData();
} }
} }
}); });
maria.ElementView.subclass(checkit, 'TodosToolbarView', { maria.ElementView.subclass(checkit, 'TodosToolbarView', {
modelConstructor: checkit.TodosModel,
uiActions: { uiActions: {
'click .allCheckbox' : 'onClickAllCheckbox' , 'click .allCheckbox' : 'onClickAllCheckbox' ,
'click .markallDone' : 'onClickMarkAllDone' , 'click .markallDone' : 'onClickMarkAllDone' ,
...@@ -7,11 +6,14 @@ maria.ElementView.subclass(checkit, 'TodosToolbarView', { ...@@ -7,11 +6,14 @@ maria.ElementView.subclass(checkit, 'TodosToolbarView', {
'click .deleteComplete': 'onClickDeleteDone' 'click .deleteComplete': 'onClickDeleteDone'
}, },
properties: { properties: {
update: function() { buildData: function() {
var model = this.getModel(); var model = this.getModel();
var checkbox = this.find('.allCheckbox'); var checkbox = this.find('.allCheckbox');
checkbox.checked = model.isAllDone(); checkbox.checked = model.isAllDone();
checkbox.disabled = model.isEmpty(); checkbox.disabled = model.isEmpty();
},
update: function() {
this.buildData();
} }
} }
}); });
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