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
4841d65f
Commit
4841d65f
authored
Jun 24, 2012
by
Sindre Sorhus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rAppid.js app: Enforce code style
parent
9803689b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
156 additions
and
104 deletions
+156
-104
labs/architecture-examples/rappidjs/app/Todo.xml
labs/architecture-examples/rappidjs/app/Todo.xml
+4
-6
labs/architecture-examples/rappidjs/app/TodoClass.js
labs/architecture-examples/rappidjs/app/TodoClass.js
+52
-34
labs/architecture-examples/rappidjs/app/collection/TodoList.js
...architecture-examples/rappidjs/app/collection/TodoList.js
+45
-24
labs/architecture-examples/rappidjs/app/model/Todo.js
labs/architecture-examples/rappidjs/app/model/Todo.js
+17
-11
labs/architecture-examples/rappidjs/app/view/TodoView.xml
labs/architecture-examples/rappidjs/app/view/TodoView.xml
+38
-29
No files found.
labs/architecture-examples/rappidjs/app/Todo.xml
View file @
4841d65f
...
...
@@ -18,8 +18,8 @@
<!-- HERE WE START TO DEFINE THE UI WITH HTML AND CUSTOM UI COMPONENTS -->
<section
id=
"todoapp"
>
<header
id=
"header"
>
<h1>
T
odos
</h1>
<input
id=
"new-todo"
placeholder=
"What needs to be done?"
type=
"text"
onkeyup=
"addNewTodo"
autofocus=
"autofocus"
/>
<h1>
t
odos
</h1>
<input
id=
"new-todo"
placeholder=
"What needs to be done?"
onkeyup=
"addNewTodo"
autofocus=
"autofocus"
/>
</header>
<section
id=
"main"
visible=
"{todoList.hasItems()}"
>
<input
id=
"toggle-all"
type=
"checkbox"
onclick=
"markAllComplete"
...
...
@@ -53,15 +53,13 @@
</footer>
</section>
<footer
id=
"info"
>
<p
visible=
"{todoList.hasItems()}"
>
Double
-
click to edit a todo
</p>
<p
visible=
"{todoList.hasItems()}"
>
Double
-
click to edit a todo
</p>
<p>
Template by
<a
href=
"http://github.com/sindresorhus"
>
Sindre Sorhus
</a></p>
<p>
Created by
<a
href=
"http://github.com/krebbl"
>
Marcus Krejpowicz
</a>
with
<a
href=
"http://rappidjs.com"
>
<
rAppid:js/
>
</a>
<br/>
Big credits to
<a
href=
"http://github.com/it-ony"
>
Tony Findeisen
</a>
</p>
<p>
Part of
<a
href=
"http://todomvc.com"
>
TodoMVC
</a>
</p>
<p>
Part of
<a
href=
"http://todomvc.com"
>
TodoMVC
</a></p>
</footer>
</app:TodoClass>
\ No newline at end of file
labs/architecture-examples/rappidjs/app/TodoClass.js
View file @
4841d65f
...
...
@@ -18,66 +18,82 @@ define([
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
)
{
var
title
=
e
.
target
.
get
(
"
value
"
).
trim
();
if
(
title
)
{
var
newTodo
=
this
.
$
.
dataSource
.
createEntity
(
Todo
);
newTodo
.
set
({
title
:
title
,
completed
:
false
});
this
.
get
(
"
todoList
"
).
add
(
newTodo
);
addNewTodo
:
function
(
e
)
{
if
(
e
.
domEvent
.
keyCode
===
ENTER_KEY
)
{
var
title
=
e
.
target
.
get
(
'
value
'
).
trim
();
if
(
title
)
{
var
newTodo
=
this
.
$
.
dataSource
.
createEntity
(
Todo
);
newTodo
.
set
({
title
:
title
,
completed
:
false
});
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
()
{
this
.
get
(
"
todoList
"
).
clearCompleted
();
clearCompleted
:
function
()
{
this
.
get
(
'
todoList
'
).
clearCompleted
();
},
removeTodo
:
function
(
e
)
{
var
todo
=
e
.
$
,
self
=
this
;
todo
.
remove
(
null
,
function
(
err
){
if
(
!
err
){
self
.
get
(
"
todoList
"
).
remove
(
todo
);
removeTodo
:
function
(
e
)
{
var
todo
=
e
.
$
,
self
=
this
;
todo
.
remove
(
null
,
function
(
err
)
{
if
(
!
err
)
{
self
.
get
(
'
todoList
'
).
remove
(
todo
);
}
});
},
/**
* 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
({
baseList
:
this
.
get
(
"
todoList
"
),
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
;
...
...
@@ -87,11 +103,13 @@ define([
// false - disables autostart
this
.
callBase
();
},
translateItems
:
function
(
num
){
return
(
num
===
1
)
?
"
item
"
:
"
items
"
;
translateItems
:
function
(
num
)
{
return
num
===
1
?
'
item
'
:
'
items
'
;
},
selectedClass
:
function
(
expected
,
current
)
{
return
expected
==
current
?
"
selected
"
:
""
;
selectedClass
:
function
(
expected
,
current
)
{
return
expected
===
current
?
'
selected
'
:
''
;
}
});
});
\ No newline at end of file
labs/architecture-examples/rappidjs/app/collection/TodoList.js
View file @
4841d65f
define
([
"
js/data/Collection
"
,
"
app/model/Todo
"
,
"
flow
"
],
function
(
Collection
,
Todo
,
flow
)
{
return
Collection
.
inherit
(
"
app.collection.TodoList
"
,
{
define
([
'
js/data/Collection
'
,
'
app/model/Todo
'
,
'
flow
'
],
function
(
Collection
,
Todo
,
flow
)
{
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
()
{
if
(
this
.
$items
.
length
===
0
)
{
areAllComplete
:
function
()
{
var
i
,
l
;
if
(
this
.
$items
.
length
)
{
return
false
;
}
for
(
var
i
=
0
;
i
<
this
.
$items
.
length
;
i
++
)
{
if
(
!
this
.
$items
[
i
].
isCompleted
())
{
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
())
{
flow
().
seqEach
(
this
.
$items
,
function
(
todo
,
cb
)
{
if
(
todo
.
isCompleted
()
)
{
// remove the todo
todo
.
remove
(
null
,
function
(
err
)
{
if
(
!
err
)
{
self
.
remove
(
todo
);
todo
.
remove
(
null
,
function
(
err
)
{
if
(
!
err
)
{
self
.
remove
(
todo
);
}
cb
(
err
);
cb
(
err
);
});
}
else
{
cb
();
}
}).
exec
();
},
numOpenTodos
:
function
()
{
var
num
=
0
;
for
(
var
i
=
0
;
i
<
this
.
$items
.
length
;
i
++
)
{
if
(
!
this
.
$items
[
i
].
isCompleted
())
{
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
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
),
numCompletedTodos
:
function
()
{
var
num
=
0
;
for
(
var
i
=
0
;
i
<
this
.
$items
.
length
;
i
++
)
{
if
(
this
.
$items
[
i
].
isCompleted
())
{
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
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
),
hasCompletedTodos
:
function
()
{
hasCompletedTodos
:
function
()
{
return
this
.
numCompletedTodos
()
>
0
;
}.
on
(
'
change
'
,
'
add
'
,
'
remove
'
)
});
...
...
labs/architecture-examples/rappidjs/app/model/Todo.js
View file @
4841d65f
define
([
"
js/data/Model
"
],
function
(
Model
)
{
return
Model
.
inherit
(
"
app.model.Todo
"
,
{
define
([
'
js/data/Model
'
],
function
(
Model
)
{
return
Model
.
inherit
(
'
app.model.Todo
'
,
{
defaults
:
{
title
:
""
,
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
()
{
return
this
.
$
.
completed
?
"
completed
"
:
''
;
}.
onChange
(
"
completed
"
),
hasTitle
:
function
()
{
status
:
function
()
{
return
this
.
$
.
completed
?
'
completed
'
:
''
;
}.
onChange
(
'
completed
'
),
hasTitle
:
function
()
{
return
this
.
$
.
title
.
trim
().
length
;
}.
onChange
(
"
title
"
)
}.
onChange
(
'
title
'
)
});
});
\ No newline at end of file
labs/architecture-examples/rappidjs/app/view/TodoView.xml
View file @
4841d65f
...
...
@@ -2,62 +2,72 @@
xmlns:js=
"js.core"
xmlns:ui=
"js.ui"
componentClass=
"{todo.status()}"
>
<js:Script>
<![CDATA[
(function
() {
(function() {
var ENTER_KEY = 13;
var INPUT_BLUR = "blur";
return {
defaults: {
editing: false
},
$classAttributes: ['todo', 'inputElement'],
events: ["remove"],
editTodo: function (e) {
this.set("editing", true);
events: ['remove'],
editTodo: function( e ) {
this.set( 'editing', true );
e.preventDefault();
this.$.inputElement.$el.select();
return false;
},
checkTodo: function () {
var todo = this.get("todo");
todo.setCompleted(!todo.isCompleted());
checkTodo: function() {
var todo = this.get('todo');
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 === INPUT_BLUR) {
todo = this.get("todo");
if (!todo.hasTitle()) {
this.trigger("remove", todo);
} else
{
this.set(
"editing", false
);
if ( e.domEvent.keyCode === ENTER_KEY || e.domEvent.type === 'blur' ) {
todo = this.get('todo');
if ( todo.hasTitle() )
{
this.set(
'editing', false
);
todo.save();
} else {
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) {
this.addClass("editing");
_renderEditing: function( editing ) {
if ( editing ) {
this.addClass('editing');
} else {
this.removeClass(
"editing"
);
this.removeClass(
'editing'
);
this.$.inputElement.$el.blur();
}
},
trim: function(title){
if(title){
trim: function( title ) {
if( title ) {
return title.trim();
}
return "";
}
return '';
}
};
})
]]>
</js:Script>
...
...
@@ -72,4 +82,3 @@
onkeyup=
"updateTodo"
onblur=
"updateTodo"
updateOnEvent=
"change"
/>
</js:Template>
</ui:View>
\ No newline at end of file
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