Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
todomvc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Eugene Shen
todomvc
Commits
3aab99f3
Commit
3aab99f3
authored
Jun 03, 2013
by
Stephen Sawchuk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rappidjs select all bug + code style.
parent
45e8b94b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
110 deletions
+89
-110
labs/architecture-examples/rappidjs/app/TodoClass.js
labs/architecture-examples/rappidjs/app/TodoClass.js
+35
-35
labs/architecture-examples/rappidjs/app/collection/TodoList.js
...architecture-examples/rappidjs/app/collection/TodoList.js
+26
-52
labs/architecture-examples/rappidjs/app/model/Todo.js
labs/architecture-examples/rappidjs/app/model/Todo.js
+8
-6
labs/architecture-examples/rappidjs/app/view/TodoView.xml
labs/architecture-examples/rappidjs/app/view/TodoView.xml
+20
-17
No files found.
labs/architecture-examples/rappidjs/app/TodoClass.js
View file @
3aab99f3
...
...
@@ -4,8 +4,7 @@ define([
'
app/collection/TodoList
'
,
'
js/data/FilterDataView
'
,
'
js/data/LocalStorageDataSource
'
],
function
(
Application
,
Todo
,
TodoList
,
FilterDataView
,
DataSource
)
{
],
function
(
Application
,
Todo
,
TodoList
,
FilterDataView
,
DataSource
)
{
var
ENTER_KEY
=
13
;
return
Application
.
inherit
(
'
app.TodoClass
'
,
{
...
...
@@ -13,87 +12,88 @@ define([
* Initializes the app
* In this method we set the initial models
*/
initialize
:
function
()
{
this
.
set
(
'
todoList
'
,
null
);
this
.
set
(
'
filterList
'
,
null
);
initialize
:
function
()
{
this
.
set
(
'
todoList
'
,
null
);
this
.
set
(
'
filterList
'
,
null
);
this
.
callBase
();
},
/**
* Are triggered
*/
showAll
:
function
()
{
this
.
$
.
filterList
.
set
(
'
filter
'
,
'
all
'
);
showAll
:
function
()
{
this
.
$
.
filterList
.
set
(
'
filter
'
,
'
all
'
);
},
showActive
:
function
()
{
this
.
$
.
filterList
.
set
(
'
filter
'
,
'
active
'
);
showActive
:
function
()
{
this
.
$
.
filterList
.
set
(
'
filter
'
,
'
active
'
);
},
showCompleted
:
function
()
{
this
.
$
.
filterList
.
set
(
'
filter
'
,
'
completed
'
);
showCompleted
:
function
()
{
this
.
$
.
filterList
.
set
(
'
filter
'
,
'
completed
'
);
},
/**
* The rest is just controller stuff
*/
addNewTodo
:
function
(
e
)
{
if
(
e
.
domEvent
.
keyCode
===
ENTER_KEY
)
{
addNewTodo
:
function
(
e
)
{
if
(
e
.
domEvent
.
keyCode
===
ENTER_KEY
)
{
var
title
=
e
.
target
.
get
(
'
value
'
).
trim
();
var
newTodo
;
if
(
title
)
{
var
newTodo
=
this
.
$
.
dataSource
.
createEntity
(
Todo
);
if
(
title
)
{
newTodo
=
this
.
$
.
dataSource
.
createEntity
(
Todo
);
newTodo
.
set
({
title
:
title
,
completed
:
false
});
this
.
get
(
'
todoList
'
).
add
(
newTodo
);
this
.
get
(
'
todoList
'
).
add
(
newTodo
);
// save the new item
newTodo
.
save
();
e
.
target
.
set
(
'
value
'
,
''
);
e
.
target
.
set
(
'
value
'
,
''
);
}
}
},
markAllComplete
:
function
(
e
)
{
this
.
get
(
'
todoList
'
).
markAll
(
e
.
target
.
$el
.
checked
);
markAllComplete
:
function
(
e
)
{
this
.
get
(
'
todoList
'
).
markAll
(
e
.
target
.
$el
.
checked
);
},
clearCompleted
:
function
()
{
clearCompleted
:
function
()
{
this
.
get
(
'
todoList
'
).
clearCompleted
();
},
removeTodo
:
function
(
e
)
{
var
todo
=
e
.
$
,
self
=
this
;
removeTodo
:
function
(
e
)
{
var
todo
=
e
.
$
;
todo
.
remove
(
null
,
function
(
err
)
{
if
(
!
err
)
{
self
.
get
(
'
todoList
'
).
remove
(
todo
);
todo
.
remove
(
null
,
function
(
err
)
{
if
(
!
err
)
{
this
.
get
(
'
todoList
'
).
remove
(
todo
);
}
});
}
.
bind
(
this
)
);
},
/**
* Start the application and render it to the body ...
*/
start
:
function
(
parameter
,
callback
)
{
this
.
set
(
'
todoList
'
,
this
.
$
.
dataSource
.
createCollection
(
TodoList
)
);
start
:
function
(
parameter
,
callback
)
{
this
.
set
(
'
todoList
'
,
this
.
$
.
dataSource
.
createCollection
(
TodoList
)
);
// fetch all todos, can be done sync because we use localStorage
this
.
$
.
todoList
.
fetch
();
this
.
set
(
'
filterList
'
,
new
FilterDataView
({
this
.
set
(
'
filterList
'
,
new
FilterDataView
({
baseList
:
this
.
get
(
'
todoList
'
),
filter
:
'
all
'
,
filterFnc
:
function
(
item
)
{
filterFnc
:
function
(
item
)
{
var
filter
=
this
.
$
.
filter
;
if
(
filter
===
'
active
'
)
{
if
(
filter
===
'
active
'
)
{
return
!
item
.
isCompleted
();
}
else
if
(
filter
===
'
completed
'
)
{
}
else
if
(
filter
===
'
completed
'
)
{
return
item
.
isCompleted
();
}
else
{
return
true
;
...
...
@@ -104,11 +104,11 @@ define([
this
.
callBase
();
},
translateItems
:
function
(
num
)
{
translateItems
:
function
(
num
)
{
return
num
===
1
?
'
item
'
:
'
items
'
;
},
selectedClass
:
function
(
expected
,
current
)
{
selectedClass
:
function
(
expected
,
current
)
{
return
expected
===
current
?
'
selected
'
:
''
;
}
});
...
...
labs/architecture-examples/rappidjs/app/collection/TodoList.js
View file @
3aab99f3
...
...
@@ -2,46 +2,30 @@ define([
'
js/data/Collection
'
,
'
app/model/Todo
'
,
'
flow
'
],
function
(
Collection
,
Todo
,
flow
)
{
return
Collection
.
inherit
(
'
app.collection.TodoList
'
,
{
],
function
(
Collection
,
Todo
,
flow
)
{
'
use strict
'
;
return
Collection
.
inherit
(
'
app.collection.TodoList
'
,
{
$modelFactory
:
Todo
,
markAll
:
function
(
done
)
{
markAll
:
function
(
done
)
{
this
.
each
(
function
(
todo
)
{
todo
.
setCompleted
(
done
);
todo
.
setCompleted
(
done
);
todo
.
save
();
});
},
areAllComplete
:
function
()
{
var
i
,
l
;
if
(
this
.
$items
.
length
)
{
return
false
;
}
for
(
i
=
0
,
l
=
this
.
$items
.
length
;
i
<
l
;
i
++
)
{
if
(
!
this
.
$items
[
i
].
isCompleted
()
)
{
return
false
;
}
}
return
true
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
),
clearCompleted
:
function
()
{
clearCompleted
:
function
()
{
var
self
=
this
;
// remove all completed todos in a sequence
flow
().
seqEach
(
this
.
$items
,
function
(
todo
,
cb
)
{
if
(
todo
.
isCompleted
()
)
{
// remove the todo
todo
.
remove
(
null
,
function
(
err
)
{
if
(
!
err
)
{
self
.
remove
(
todo
);
flow
().
seqEach
(
this
.
$items
,
function
(
todo
,
cb
)
{
if
(
todo
.
isCompleted
())
{
todo
.
remove
(
null
,
function
(
err
)
{
if
(
!
err
)
{
self
.
remove
(
todo
);
}
cb
(
err
);
cb
(
err
);
});
}
else
{
cb
();
...
...
@@ -49,34 +33,24 @@ define([
}).
exec
();
},
numOpenTodos
:
function
()
{
var
i
,
l
,
num
=
0
;
for
(
i
=
0
,
l
=
this
.
$items
.
length
;
i
<
l
;
i
++
)
{
if
(
!
this
.
$items
[
i
].
isCompleted
()
)
{
num
++
;
}
}
return
num
;
numOpenTodos
:
function
()
{
return
this
.
$items
.
filter
(
function
(
item
)
{
return
!
item
.
isCompleted
();
}).
length
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
),
numCompletedTodos
:
function
()
{
var
i
,
l
,
num
=
0
;
for
(
i
=
0
,
l
=
this
.
$items
.
length
;
i
<
l
;
i
++
)
{
if
(
this
.
$items
[
i
].
isCompleted
()
)
{
num
++
;
}
}
return
num
;
numCompletedTodos
:
function
()
{
return
this
.
$items
.
filter
(
function
(
item
)
{
return
item
.
isCompleted
();
}).
length
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
),
hasCompletedTodos
:
function
()
{
hasCompletedTodos
:
function
()
{
return
this
.
numCompletedTodos
()
>
0
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
),
areAllComplete
:
function
()
{
return
this
.
numOpenTodos
()
===
0
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
)
});
});
labs/architecture-examples/rappidjs/app/model/Todo.js
View file @
3aab99f3
define
([
'
js/data/Model
'
],
function
(
Model
)
{
],
function
(
Model
)
{
'
use strict
'
;
return
Model
.
inherit
(
'
app.model.Todo
'
,
{
defaults
:
{
title
:
''
,
completed
:
false
},
setCompleted
:
function
(
completed
)
{
this
.
set
(
'
completed
'
,
completed
);
setCompleted
:
function
(
completed
)
{
this
.
set
(
'
completed
'
,
completed
);
},
isCompleted
:
function
()
{
isCompleted
:
function
()
{
return
this
.
$
.
completed
;
},
status
:
function
()
{
status
:
function
()
{
return
this
.
$
.
completed
?
'
completed
'
:
''
;
}.
onChange
(
'
completed
'
),
hasTitle
:
function
()
{
hasTitle
:
function
()
{
return
this
.
$
.
title
.
trim
().
length
;
}.
onChange
(
'
title
'
)
});
...
...
labs/architecture-examples/rappidjs/app/view/TodoView.xml
View file @
3aab99f3
...
...
@@ -2,7 +2,9 @@
xmlns:js=
"js.core"
xmlns:ui=
"js.ui"
componentClass=
"{todo.status()}"
>
<js:Script>
<![CDATA[
(function() {
(function () {
'use strict';
var ENTER_KEY = 13;
return {
...
...
@@ -14,46 +16,47 @@
events: ['remove'],
editTodo: function( e ) {
this.set( 'editing', true );
editTodo: function (e) {
e.preventDefault();
this.set('editing', true);
this.$.inputElement.$el.focus();
return false;
},
checkTodo: function() {
checkTodo: function
() {
var todo = this.get('todo');
todo.setCompleted(
!todo.isCompleted()
);
todo.setCompleted(
!todo.isCompleted()
);
todo.save();
},
preventEditing: function
( e
) {
preventEditing: function
(e
) {
e.stopPropagation();
},
updateTodo: function
( e
) {
updateTodo: function
(e
) {
var todo;
if (
e.domEvent.keyCode === ENTER_KEY || e.domEvent.type === 'blur'
) {
if (
e.domEvent.keyCode === ENTER_KEY || e.domEvent.type === 'blur'
) {
todo = this.get('todo');
if (
todo.hasTitle()
) {
this.set(
'editing', false
);
if (
todo.hasTitle()
) {
this.set(
'editing', false
);
todo.save();
} else {
this.trigger(
'remove', todo
);
this.trigger(
'remove', todo
);
}
}
},
triggerOnRemove: function() {
this.trigger(
'remove', this.get('todo')
);
triggerOnRemove: function
() {
this.trigger(
'remove', this.get('todo')
);
},
_renderEditing: function
( editing
) {
if (
editing
) {
_renderEditing: function
(editing
) {
if (
editing
) {
this.addClass('editing');
} else {
this.removeClass('editing');
...
...
@@ -61,8 +64,8 @@
}
},
trim: function
( title
) {
if
( title
) {
trim: function
(title
) {
if
(title
) {
return title.trim();
}
return '';
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment