Commit 480cf298 authored by Pascal Hartig's avatar Pascal Hartig

Foam: Various style fixes

parent 1655b316
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
name: 'TodoDAO', name: 'TodoDAO',
extendsModel: 'ProxyDAO', extendsModel: 'ProxyDAO',
methods: { methods: {
put: function(issue, s) { put: function (issue, s) {
// If the user tried to put an empty text, remove the entry instead. // If the user tried to put an empty text, remove the entry instead.
if (!issue.text) { if (!issue.text) {
this.remove(issue.id, { remove: s && s.put }); this.remove(issue.id, { remove: s && s.put });
...@@ -26,23 +26,23 @@ ...@@ -26,23 +26,23 @@
{ name: 'completed', model_: 'BooleanProperty' }, { name: 'completed', model_: 'BooleanProperty' },
{ name: 'text', preSet: function (_, text) { return text.trim(); } } { name: 'text', preSet: function (_, text) { return text.trim(); } }
], ],
templates: [ function toDetailHTML() {/* templates: [function toDetailHTML() {/*
<li id="%%id"> <li id="%%id">
<div class="view"> <div class="view">
$$completed{className: 'toggle'} $$completed{className: 'toggle'}
$$text{mode: 'read-only', tagName: 'label'} $$text{mode: 'read-only', tagName: 'label'}
<button class="destroy" id="<%= this.on('click', function() { this.parent.dao.remove(this.data); }) %>"></button> <button class="destroy" id="<%= this.on('click', function () { this.parent.dao.remove(this.data); }) %>"></button>
</div> </div>
$$text{className: 'edit'} $$text{className: 'edit'}
</li> </li>
<% <%
var toEdit = function() { DOM.setClass(this.$, 'editing'); this.textView.focus(); }.bind(this); var toEdit = function () { DOM.setClass(this.$, 'editing'); this.textView.focus(); }.bind(this);
var toDisplay = function() { DOM.setClass(this.$, 'editing', false); }.bind(this); var toDisplay = function () { DOM.setClass(this.$, 'editing', false); }.bind(this);
this.on('dblclick', toEdit, this.id); this.on('dblclick', toEdit, this.id);
this.on('blur', toDisplay, this.textView.id); this.on('blur', toDisplay, this.textView.id);
this.textView.subscribe(this.textView.ESCAPE, toDisplay); this.textView.subscribe(this.textView.ESCAPE, toDisplay);
this.setClass('completed', function() { return this.data.completed; }.bind(this), this.id); this.setClass('completed', function () { return this.data.completed; }.bind(this), this.id);
%> */} ] %> */}]
}); });
// Needed to massage the HTML to fit TodoMVC spec; it works without this. // Needed to massage the HTML to fit TodoMVC spec; it works without this.
...@@ -50,10 +50,10 @@ ...@@ -50,10 +50,10 @@
name: 'TodoFilterView', name: 'TodoFilterView',
extendsModel: 'ChoiceListView', extendsModel: 'ChoiceListView',
methods: { methods: {
choiceToHTML: function(id, choice) { choiceToHTML: function (id, choice) {
var self = this; var self = this;
this.setClass('selected', function() { return self.label === choice[1]; }, id); this.setClass('selected', function () { return self.label === choice[1]; }, id);
return '<li><a id="' + id + '" class="choice">' + choice[1] + '</a></li>'; return '<li><a id="' + id + '" class="choice" href="">' + choice[1] + '</a></li>';
} }
} }
}); });
...@@ -63,7 +63,7 @@ ...@@ -63,7 +63,7 @@
properties: [ properties: [
{ {
name: 'input', name: 'input',
setter: function(text) { setter: function (text) {
// This is a fake property that adds the todo when its value gets saved. // This is a fake property that adds the todo when its value gets saved.
if (!text) { return; } if (!text) { return; }
this.dao.put(Todo.create({text: text})); this.dao.put(Todo.create({text: text}));
...@@ -74,30 +74,30 @@ ...@@ -74,30 +74,30 @@
{ name: 'dao' }, { name: 'dao' },
{ name: 'filteredDAO', model_: 'DAOProperty', view: 'DAOListView' }, { name: 'filteredDAO', model_: 'DAOProperty', view: 'DAOListView' },
{ name: 'completedCount', model_: 'IntProperty' }, { name: 'completedCount', model_: 'IntProperty' },
{ name: 'activeCount', model_: 'IntProperty', postSet: function(_, c) { this.toggle = !c; }}, { name: 'activeCount', model_: 'IntProperty', postSet: function (_, c) { this.toggle = !c; }},
{ name: 'toggle', model_: 'BooleanProperty', postSet: function(_, n) { { name: 'toggle', model_: 'BooleanProperty', postSet: function (_, n) {
if (n === (this.activeCount > 0)) { this.dao.update(SET(Todo.COMPLETED, n)); } if (n === (this.activeCount > 0)) { this.dao.update(SET(Todo.COMPLETED, n)); }
}}, }},
{ {
name: 'query', name: 'query',
postSet: function(_, q) { this.filteredDAO = this.dao.where(q); }, postSet: function (_, q) { this.filteredDAO = this.dao.where(q); },
defaultValue: TRUE, defaultValue: TRUE,
view: { factory_: 'TodoFilterView', choices: [ [ TRUE, 'All' ], [ NOT(Todo.COMPLETED), 'Active' ], [ Todo.COMPLETED, 'Completed' ] ] } view: { factory_: 'TodoFilterView', choices: [[TRUE, 'All'], [NOT(Todo.COMPLETED), 'Active'], [Todo.COMPLETED, 'Completed']] }
} }
], ],
actions: [ actions: [
{ {
name: 'clear', name: 'clear',
labelFn: function() { return 'Clear completed (' + this.completedCount + ')'; }, labelFn: function () { return 'Clear completed (' + this.completedCount + ')'; },
isEnabled: function() { return this.completedCount; }, isEnabled: function () { return this.completedCount; },
action: function() { this.dao.where(Todo.COMPLETED).removeAll(); } action: function () { this.dao.where(Todo.COMPLETED).removeAll(); }
} }
], ],
listeners: [ listeners: [
{ {
name: 'onDAOUpdate', name: 'onDAOUpdate',
isFramed: true, isFramed: true,
code: function() { code: function () {
this.dao.select(GROUP_BY(Todo.COMPLETED, COUNT()))(function (q) { this.dao.select(GROUP_BY(Todo.COMPLETED, COUNT()))(function (q) {
this.completedCount = q.groups[true]; this.completedCount = q.groups[true];
this.activeCount = q.groups[false]; this.activeCount = q.groups[false];
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
} }
], ],
methods: { methods: {
init: function() { init: function () {
this.SUPER(); this.SUPER();
this.filteredDAO = this.dao = TodoDAO.create({ this.filteredDAO = this.dao = TodoDAO.create({
delegate: EasyDAO.create({model: Todo, seqNo: true, daoType: 'StorageDAO', name: 'todos-foam'}) }); delegate: EasyDAO.create({model: Todo, seqNo: true, daoType: 'StorageDAO', name: 'todos-foam'}) });
...@@ -141,18 +141,18 @@ ...@@ -141,18 +141,18 @@
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p> <p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer> </footer>
<% <%
var f = function() { return this.completedCount + this.activeCount == 0; }.bind(this.data); var f = function () { return this.completedCount + this.activeCount == 0; }.bind(this.data);
this.setClass('hidden', f, 'main'); this.setClass('hidden', f, 'main');
this.setClass('hidden', f, 'footer'); this.setClass('hidden', f, 'footer');
Events.relate(this.X.memento, this.queryView.label$, Events.relate(this.X.memento, this.queryView.label$,
function(memento) { function (memento) {
var s = memento && memento.substring(1); var s = memento && memento.substring(1);
var t = s ? s.capitalize() : 'All'; var t = s ? s.capitalize() : 'All';
console.log('memento->label', memento, s, t); console.log('memento->label', memento, s, t);
return t; return t;
}, },
function(label) { var s = '/' + label.toLowerCase(); console.log('label->memento', label, s); return s; }); function (label) { var s = '/' + label.toLowerCase(); console.log('label->memento', label, s); return s; });
this.addInitializer(function() { this.addInitializer(function () {
$('new-todo').focus(); $('new-todo').focus();
}); });
%> %>
......
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