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
428dc1ae
Commit
428dc1ae
authored
Jun 19, 2012
by
Stas SUȘCOV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move some of the views to separate files.
Initialize controller views upon `init`.
parent
ea6780df
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
140 additions
and
53 deletions
+140
-53
dependency-examples/emberjs_require/js/app/controllers/todos.js
...ency-examples/emberjs_require/js/app/controllers/todos.js
+30
-52
dependency-examples/emberjs_require/js/app/templates/clear_button.html
...amples/emberjs_require/js/app/templates/clear_button.html
+1
-0
dependency-examples/emberjs_require/js/app/templates/filters.html
...cy-examples/emberjs_require/js/app/templates/filters.html
+11
-0
dependency-examples/emberjs_require/js/app/templates/items.html
...ency-examples/emberjs_require/js/app/templates/items.html
+13
-0
dependency-examples/emberjs_require/js/app/templates/stats.html
...ency-examples/emberjs_require/js/app/templates/stats.html
+5
-0
dependency-examples/emberjs_require/js/app/views/clear_button.html
...y-examples/emberjs_require/js/app/views/clear_button.html
+0
-1
dependency-examples/emberjs_require/js/app/views/clear_button.js
...ncy-examples/emberjs_require/js/app/views/clear_button.js
+26
-0
dependency-examples/emberjs_require/js/app/views/filters.js
dependency-examples/emberjs_require/js/app/views/filters.js
+16
-0
dependency-examples/emberjs_require/js/app/views/items.js
dependency-examples/emberjs_require/js/app/views/items.js
+16
-0
dependency-examples/emberjs_require/js/app/views/stats.js
dependency-examples/emberjs_require/js/app/views/stats.js
+22
-0
No files found.
dependency-examples/emberjs_require/js/app/controllers/todos.js
View file @
428dc1ae
define
(
'
app/controllers/todos
'
,
[
'
app/controllers/entries
'
,
'
text!app/views/clear_button.html
'
,
'
text!app/views/items.html
'
'
app/views/items
'
,
'
app/views/stats
'
,
'
app/views/filters
'
,
'
app/views/clear_button
'
,
],
/**
* Todos controller
...
...
@@ -10,75 +12,42 @@ define('app/controllers/todos', [
* which is an `ArrayProxy` linked with the `Store` model
*
* @param Class Entries, the Entries class
* @param String button_html, the html view for the clearCompletedButton
* @param String items_html, the html view for the `Todos` items
* @param Class ItemsView, items view class
* @param Class StatsView, stats view class
* @param Class FiltersView, filters view class
* @param Class ClearBtnView, clear button view class
* @returns Class
*/
function
(
Entries
,
button_html
,
items_html
)
{
function
(
Entries
,
ItemsView
,
StatsView
,
FiltersView
,
ClearBtnView
)
{
return
Entries
.
extend
({
// New todo input
inputView
:
Ember
.
TextField
.
create
({
InputView
:
Ember
.
TextField
.
extend
({
placeholder
:
'
What needs to be done?
'
,
elementId
:
'
new-todo
'
,
storageBinding
:
'
Todos.todosController
'
,
// Bind this to newly inserted line
insertNewline
:
function
()
{
var
value
=
this
.
get
(
'
value
'
);
if
(
value
)
{
this
.
get
(
'
storage
'
).
createNew
(
value
);
this
.
get
(
'
controller
'
).
createNew
(
value
);
this
.
set
(
'
value
'
,
''
);
}
}
}),
// Stats report
statsView
:
Ember
.
View
.
create
({
elementId
:
'
todo-count
'
,
tagName
:
'
span
'
,
contentBinding
:
'
Todos.todosController
'
,
remainingBinding
:
'
Todos.todosController.remaining
'
,
template
:
Ember
.
Handlebars
.
compile
(
'
<strong>{{remaining}}</strong> {{remainingString}} left
'
),
remainingString
:
function
()
{
var
remaining
=
this
.
get
(
'
remaining
'
);
return
(
remaining
===
1
?
'
item
'
:
'
items
'
);
}.
property
(
'
remaining
'
)
}),
// Handle visibility of some elements as items totals change
visibilityObserver
:
function
()
{
$
(
'
#main, #footer
'
).
toggle
(
!!
this
.
get
(
'
total
'
)
);
}.
observes
(
'
total
'
),
// Clear completed tasks button
clearCompletedButton
:
Ember
.
Button
.
create
({
template
:
Ember
.
Handlebars
.
compile
(
button_html
),
target
:
'
Todos.todosController
'
,
action
:
'
clearCompleted
'
,
completedCountBinding
:
'
Todos.todosController.completed
'
,
elementId
:
'
clear-completed
'
,
classNameBindings
:
'
buttonClass
'
,
// Observer to update class if completed value changes
buttonClass
:
function
()
{
if
(
!
this
.
get
(
'
completedCount
'
)
)
return
'
hidden
'
;
}.
property
(
'
completedCount
'
)
}),
// Checkbox to mark all todos done.
allDoneCheckbox
:
Ember
.
Checkbox
.
create
({
MarkAllChkbox
:
Ember
.
Checkbox
.
extend
({
elementId
:
'
toggle-all
'
,
checkedBinding
:
'
Todos.todosController.allAreDone
'
}),
// Compile and render the todos view
todosView
:
Ember
.
View
.
create
({
template
:
Ember
.
Handlebars
.
compile
(
items_html
)
checkedBinding
:
'
controller.allAreDone
'
}),
// Todo list item view
todoView
:
Ember
.
View
.
extend
({
ItemView
:
Ember
.
View
.
extend
({
contentBinding
:
'
controller
'
,
classNames
:
[
'
view
'
],
doubleClick
:
function
()
{
this
.
get
(
'
content
'
).
set
(
'
editing
'
,
true
);
...
...
@@ -86,8 +55,8 @@ define('app/controllers/todos', [
}),
// Todo list item editing view
todo
Editor
:
Ember
.
TextField
.
extend
({
storageBinding
:
'
Todos.todosController
'
,
Item
Editor
:
Ember
.
TextField
.
extend
({
storageBinding
:
'
content
'
,
classNames
:
[
'
edit
'
],
whenDone
:
function
()
{
this
.
get
(
'
todo
'
).
set
(
'
editing
'
,
false
);
...
...
@@ -109,12 +78,21 @@ define('app/controllers/todos', [
// Activates the views and other initializations
init
:
function
()
{
this
.
_super
();
this
.
set
(
'
inputView
'
,
this
.
InputView
.
create
({
controller
:
this
})
);
this
.
set
(
'
markAllChkbox
'
,
this
.
MarkAllChkbox
.
create
({
controller
:
this
})
);
this
.
set
(
'
itemsView
'
,
ItemsView
.
create
({
controller
:
this
})
);
this
.
set
(
'
statsView
'
,
StatsView
.
create
({
controller
:
this
})
);
this
.
set
(
'
filtersView
'
,
FiltersView
.
create
()
);
this
.
set
(
'
clearBtnView
'
,
ClearBtnView
.
create
({
controller
:
this
})
);
this
.
get
(
'
inputView
'
).
appendTo
(
'
header
'
);
this
.
get
(
'
allDoneChec
kbox
'
).
appendTo
(
'
#main
'
);
this
.
get
(
'
todo
sView
'
).
appendTo
(
'
#main
'
);
this
.
get
(
'
markAllCh
kbox
'
).
appendTo
(
'
#main
'
);
this
.
get
(
'
item
sView
'
).
appendTo
(
'
#main
'
);
this
.
get
(
'
statsView
'
).
appendTo
(
'
#footer
'
);
this
.
get
(
'
clearCompletedButton
'
).
appendTo
(
'
#footer
'
);
this
.
get
(
'
clearBtnView
'
).
appendTo
(
'
#footer
'
);
this
.
get
(
'
filtersView
'
).
appendTo
(
'
#footer
'
);
}
});
}
);
\ No newline at end of file
);
dependency-examples/emberjs_require/js/app/templates/clear_button.html
0 → 100644
View file @
428dc1ae
Clear completed ({{completed}})
dependency-examples/emberjs_require/js/app/templates/filters.html
0 → 100644
View file @
428dc1ae
<ul
id=
"filters"
>
<li>
<a
{{
action
showAll
href=
true}}
>
All
</a>
</li>
<li>
<a
{{
action
showActive
href=
true}}
>
Active
</a>
</li>
<li>
<a
{{
action
showCompleted
href=
true}}
>
Completed
</a>
</li>
</ul>
dependency-examples/emberjs_require/js/app/
view
s/items.html
→
dependency-examples/emberjs_require/js/app/
template
s/items.html
View file @
428dc1ae
{{#collection
id="todo-list" contentBinding="Todos.todosController
" tagName="ul" itemClassBinding="content.completed content.editing" }}
{{#collection
contentBinding="controller" controllerBinding="controller" id="todo-list
" tagName="ul" itemClassBinding="content.completed content.editing" }}
{{#unless content.editing}}
{{#view
Todos.todosController.todo
View contentBinding="content" }}
{{#view
controller.Item
View contentBinding="content" }}
{{view Ember.Checkbox valueBinding="content.completed" class="toggle"}}
{{#view Ember.View tagName="label" todoBinding="content"}}
{{todo.title}}
{{/view}}
{{view Ember.Button target="
Todos.todosC
ontroller" action="removeObject" class="destroy" todoBinding="content"}}
{{view Ember.Button target="
c
ontroller" action="removeObject" class="destroy" todoBinding="content"}}
{{/view}}
{{else}}
{{view
Todos.todosController.todo
Editor todoBinding="content" valueBinding="content.title"}}
{{view
controller.Item
Editor todoBinding="content" valueBinding="content.title"}}
{{/unless}}
{{/collection}}
\ No newline at end of file
{{/collection}}
dependency-examples/emberjs_require/js/app/templates/stats.html
0 → 100644
View file @
428dc1ae
{{#if oneLeft }}
<strong>
{{remaining}}
</strong>
item left
{{else}}
<strong>
{{remaining}}
</strong>
items left
{{/if}}
dependency-examples/emberjs_require/js/app/views/clear_button.html
deleted
100644 → 0
View file @
ea6780df
Clear completed ({{completedCount}})
\ No newline at end of file
dependency-examples/emberjs_require/js/app/views/clear_button.js
0 → 100644
View file @
428dc1ae
define
(
'
app/views/clear_button
'
,
[
'
text!app/templates/clear_button.html
'
,
'
ember
'
],
/**
* View to clear completed tasks
*
* @param String button_html, the html for view
* @returns Class
*/
function
(
button_html
)
{
return
Ember
.
Button
.
extend
({
template
:
Ember
.
Handlebars
.
compile
(
button_html
),
target
:
'
controller
'
,
action
:
'
clearCompleted
'
,
completedBinding
:
'
controller.completed
'
,
elementId
:
'
clear-completed
'
,
classNameBindings
:
'
buttonClass
'
,
// Observer to update class if completed value changes
buttonClass
:
function
()
{
if
(
!
this
.
get
(
'
completed
'
)
)
return
'
hidden
'
;
}.
property
(
'
completed
'
)
})
}
);
dependency-examples/emberjs_require/js/app/views/filters.js
0 → 100644
View file @
428dc1ae
define
(
'
app/views/filters
'
,
[
'
text!app/templates/filters.html
'
,
'
ember
'
],
/**
* View to render filter links
*
* @param String filters_html, filter links html view
* @returns Class
*/
function
(
filters_html
)
{
return
Ember
.
View
.
extend
({
template
:
Ember
.
Handlebars
.
compile
(
filters_html
)
})
}
);
dependency-examples/emberjs_require/js/app/views/items.js
0 → 100644
View file @
428dc1ae
define
(
'
app/views/items
'
,
[
'
text!app/templates/items.html
'
,
'
ember
'
],
/**
* View to render todos items
*
* @param String items_html, the html view for the `Todos` items
* @returns Class
*/
function
(
items_html
)
{
return
Ember
.
View
.
extend
({
template
:
Ember
.
Handlebars
.
compile
(
items_html
)
})
}
);
dependency-examples/emberjs_require/js/app/views/stats.js
0 → 100644
View file @
428dc1ae
define
(
'
app/views/stats
'
,
[
'
text!app/templates/stats.html
'
,
'
ember
'
],
/**
* View to render todos stats
*
* @param String stats_html, stats indicator view
* @returns Class
*/
function
(
stats_html
)
{
return
Ember
.
View
.
extend
({
elementId
:
'
todo-count
'
,
tagName
:
'
span
'
,
remainingBinding
:
'
controller.remaining
'
,
template
:
Ember
.
Handlebars
.
compile
(
stats_html
),
oneLeft
:
function
()
{
return
this
.
get
(
'
remaining
'
)
===
1
;
}.
observes
(
'
remaining
'
)
})
}
);
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