Add, delete, display a task in Todo

pull/1/head
Nicolas Lemoine 7 years ago
parent ac718b6dfa
commit f67fb32bf1

@ -13,7 +13,7 @@
<input type="text" id="newTodoName" />
<button class="btn btn-success">Add the task</button>
</div>
<div class="tasks-list">
<div id="tasksList">
</div>
</div>

@ -4,15 +4,14 @@ define([
'/bower_components/chainpad-listmap/chainpad-listmap.js',
'/common/toolbar2.js',
'/common/cryptpad-common.js',
'/common/visible.js',
'/common/notify.js',
'/todo/todo.js',
//'/common/media-tag.js',
//'/bower_components/file-saver/FileSaver.min.js',
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
'less!/customize/src/less/cryptpad.less',
], function ($, Crypto, Listmap, Toolbar, Cryptpad /*, Visible, Notify*/) {
], function ($, Crypto, Listmap, Toolbar, Cryptpad, Todo) {
var Messages = Cryptpad.Messages;
var APP = window.APP = {};
@ -24,16 +23,62 @@ define([
var onReady = function () {
var todo = Todo.init(APP.lm.proxy, Cryptpad);
var deleteTask = function(id) {
todo.remove(id);
APP.display();
};
var display = APP.display = function () {
var $list = $iframe.find('#tasksList');
$list.empty();
APP.lm.proxy.order.forEach(function(el) {
var $taskDiv = $('<div>', {
'class': 'cp-task'
}).appendTo($list);
$('<span>', {})
.text(APP.lm.proxy.data[el].task)
.appendTo($taskDiv);
$('<span>', {})
.text(new Date(APP.lm.proxy.data[el].ctime).toLocaleString())
.appendTo($taskDiv);
$('<button>', {
'class': 'fa fa-times'
}).appendTo($taskDiv).on('click', function() {
deleteTask(el);
});
});
};
var addTask = function () {
var $input = $iframe.find('#newTodoName');
var obj = {
"state": 0,
"task": $input.val(),
"ctime": +new Date(),
"mtime": +new Date()
};
todo.add(Cryptpad.createChannelId(), obj);
$input.empty();
display();
};
var editTask = function () {};
$iframe.find('.create-form button').on('click', addTask);
var display = function () {
var editTask = function () {
};
display();
Cryptpad.removeLoadingScreen();
};
@ -67,6 +112,8 @@ define([
if(obj.todo) {
hash = obj.todo;
} else {
obj.todo = hash;
}
var secret = Cryptpad.getSecrets('todo', hash);

@ -28,7 +28,7 @@ define([
var initialize = function (proxy) {
// run migration
if (typeof(proxy.data) !== 'object') { proxy.data = {}; }
if (Array.isArray(proxy.order)) { proxy.order = []; }
if (!Array.isArray(proxy.order)) { proxy.order = []; }
if (typeof(proxy.type) !== 'string') { proxy.type = 'todo'; }
};

Loading…
Cancel
Save