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
Sven Franck
todomvc
Commits
8c48866b
Commit
8c48866b
authored
Aug 04, 2013
by
Pascal Hartig
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firebase-angular: refactor controller
parent
20100b51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
65 deletions
+68
-65
labs/architecture-examples/firebase-angular/js/controllers/todoCtrl.js
...ture-examples/firebase-angular/js/controllers/todoCtrl.js
+68
-65
No files found.
labs/architecture-examples/firebase-angular/js/controllers/todoCtrl.js
View file @
8c48866b
/*global todomvc, angular */
/*global todomvc, angular
, Firebase
*/
'
use strict
'
;
/**
...
...
@@ -7,79 +7,82 @@
* - exposes the model to the template and provides event handlers
*/
todomvc
.
controller
(
'
TodoCtrl
'
,
function
TodoCtrl
(
$scope
,
$location
,
angularFire
)
{
var
url
=
'
https://todomvc-angular.firebaseio.com/
'
;
$scope
.
newTodo
=
''
;
$scope
.
editedTodo
=
null
;
this
.
onDataLoaded
=
function
onDataLoaded
(
$scope
,
$location
,
url
)
{
$scope
.
$watch
(
'
todos
'
,
function
()
{
var
total
=
0
;
var
remaining
=
0
;
angular
.
forEach
(
$scope
.
todos
,
function
(
todo
)
{
total
++
;
if
(
todo
.
completed
===
false
)
{
remaining
++
;
}
});
$scope
.
remainingCount
=
remaining
;
$scope
.
completedCount
=
total
-
remaining
;
$scope
.
allChecked
=
!
$scope
.
remainingCount
;
},
true
);
if
(
$location
.
path
()
===
''
)
{
$location
.
path
(
'
/
'
);
}
$scope
.
location
=
$location
;
$scope
.
addTodo
=
function
()
{
var
newTodo
=
$scope
.
newTodo
.
trim
();
if
(
!
newTodo
.
length
)
{
return
;
}
$scope
.
todos
[
new
Firebase
(
url
).
push
().
name
()]
=
{
title
:
newTodo
,
completed
:
false
};
$scope
.
newTodo
=
''
;
};
angularFire
(
url
,
$scope
,
'
todos
'
,
{}).
then
(
function
(
)
{
onDataLoaded
(
$scope
,
$location
,
url
)
;
}
);
})
;
$scope
.
editTodo
=
function
(
id
)
{
$scope
.
editedTodo
=
$scope
.
todos
[
id
]
;
$scope
.
originalTodo
=
angular
.
extend
({},
$scope
.
editedTodo
);
}
;
function
onDataLoaded
(
$scope
,
$location
,
url
)
{
$scope
.
$watch
(
'
todos
'
,
function
()
{
var
total
=
0
;
var
remaining
=
0
;
angular
.
forEach
(
$scope
.
todos
,
function
(
todo
)
{
total
++
;
if
(
todo
.
completed
===
false
)
remaining
++
;
});
$scope
.
remainingCount
=
remaining
;
$scope
.
completedCount
=
total
-
remaining
;
$scope
.
allChecked
=
!
$scope
.
remainingCount
;
},
true
);
$scope
.
doneEditing
=
function
(
id
)
{
$scope
.
editedTodo
=
null
;
var
title
=
$scope
.
todos
[
id
].
title
.
trim
();
if
(
!
title
)
{
$scope
.
removeTodo
(
id
);
}
};
$scope
.
addTodo
=
function
()
{
var
newTodo
=
$scope
.
newTodo
.
trim
();
if
(
!
newTodo
.
length
)
{
return
;
}
$scope
.
todos
[
new
Firebase
(
url
).
push
().
name
()]
=
{
title
:
newTodo
,
completed
:
false
$scope
.
revertEditing
=
function
(
id
)
{
$scope
.
todos
[
id
]
=
$scope
.
originalTodo
;
$scope
.
doneEditing
(
id
);
};
$scope
.
newTodo
=
''
;
};
$scope
.
editTodo
=
function
(
id
)
{
$scope
.
editedTodo
=
$scope
.
todos
[
id
];
$scope
.
originalTodo
=
angular
.
extend
({},
$scope
.
editedTodo
);
};
$scope
.
removeTodo
=
function
(
id
)
{
delete
$scope
.
todos
[
id
];
};
$scope
.
doneEditing
=
function
(
id
)
{
$scope
.
editedTodo
=
null
;
var
title
=
$scope
.
todos
[
id
].
title
.
trim
();
if
(
!
title
)
{
$scope
.
removeTodo
(
id
);
}
};
$scope
.
clearCompletedTodos
=
function
()
{
var
notCompleted
=
{};
angular
.
forEach
(
$scope
.
todos
,
function
(
todo
,
id
)
{
if
(
!
todo
.
completed
)
{
notCompleted
[
id
]
=
todo
;
}
});
$scope
.
todos
=
notCompleted
;
};
$scope
.
revertEditing
=
function
(
id
)
{
$scope
.
todos
[
id
]
=
$scope
.
originalTodo
;
$scope
.
doneEditing
(
id
);
$scope
.
markAll
=
function
(
completed
)
{
angular
.
forEach
(
$scope
.
todos
,
function
(
todo
)
{
todo
.
completed
=
completed
;
});
};
};
$scope
.
removeTodo
=
function
(
id
)
{
delete
$scope
.
todos
[
id
]
;
}
;
var
url
=
'
https://todomvc-angular.firebaseio.com/
'
;
$scope
.
newTodo
=
''
;
$scope
.
editedTodo
=
null
;
$scope
.
clearCompletedTodos
=
function
()
{
var
notCompleted
=
{};
angular
.
forEach
(
$scope
.
todos
,
function
(
todo
,
id
)
{
if
(
!
todo
.
completed
)
notCompleted
[
id
]
=
todo
;
});
$scope
.
todos
=
notCompleted
;
};
if
(
$location
.
path
()
===
''
)
{
$location
.
path
(
'
/
'
);
}
$scope
.
location
=
$location
;
$scope
.
markAll
=
function
(
completed
)
{
angular
.
forEach
(
$scope
.
todos
,
function
(
todo
)
{
todo
.
completed
=
completed
;
});
};
}
\ No newline at end of file
angularFire
(
url
,
$scope
,
'
todos
'
,
{}).
then
(
function
()
{
this
.
onDataLoaded
(
$scope
,
$location
,
url
);
}.
bind
(
this
));
});
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