mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 07:16:39 +00:00
[API] Check/uncheck todos
This commit is contained in:
parent
a79e958ffc
commit
0525ba6b0b
@ -56,5 +56,11 @@ define([
|
|||||||
main: "MAIN"
|
main: "MAIN"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
MCT.prototype.verbs = {
|
||||||
|
mutate: function (domainObject, mutator) {
|
||||||
|
return domainObject.useCapability('mutation', mutator);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return MCT;
|
return MCT;
|
||||||
});
|
});
|
||||||
|
@ -54,7 +54,7 @@ define([
|
|||||||
complete: $els.find('.example-todo-button-complete')
|
complete: $els.find('.example-todo-button-complete')
|
||||||
};
|
};
|
||||||
var filters = {
|
var filters = {
|
||||||
all: function (task) {
|
all: function () {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
incomplete: function (task) {
|
incomplete: function (task) {
|
||||||
@ -71,12 +71,20 @@ define([
|
|||||||
tasks = tasks.filter(filters[state.filter]);
|
tasks = tasks.filter(filters[state.filter]);
|
||||||
|
|
||||||
$list.empty();
|
$list.empty();
|
||||||
tasks.forEach(function (task) {
|
tasks.forEach(function (task, index) {
|
||||||
var $taskEls = $(taskTemplate);
|
var $taskEls = $(taskTemplate);
|
||||||
$taskEls.find('.example-task-checked')
|
var $checkbox = $taskEls.find('.example-task-checked');
|
||||||
.prop('checked', task.completed);
|
$checkbox.prop('checked', task.completed);
|
||||||
$taskEls.find('.example-task-description')
|
$taskEls.find('.example-task-description')
|
||||||
.text(task.description);
|
.text(task.description);
|
||||||
|
|
||||||
|
$checkbox.on('change', function () {
|
||||||
|
var checked = !!$checkbox.prop('checked');
|
||||||
|
mct.verbs.mutate(domainObject, function (model) {
|
||||||
|
model.tasks[index].completed = checked;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$list.append($taskEls);
|
$list.append($taskEls);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user