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" /> <input type="text" id="newTodoName" />
<button class="btn btn-success">Add the task</button> <button class="btn btn-success">Add the task</button>
</div> </div>
<div class="tasks-list"> <div id="tasksList">
</div> </div>
</div> </div>

@ -4,15 +4,14 @@ define([
'/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-listmap/chainpad-listmap.js',
'/common/toolbar2.js', '/common/toolbar2.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/visible.js', '/todo/todo.js',
'/common/notify.js',
//'/common/media-tag.js', //'/common/media-tag.js',
//'/bower_components/file-saver/FileSaver.min.js', //'/bower_components/file-saver/FileSaver.min.js',
'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
'less!/customize/src/less/cryptpad.less', 'less!/customize/src/less/cryptpad.less',
], function ($, Crypto, Listmap, Toolbar, Cryptpad /*, Visible, Notify*/) { ], function ($, Crypto, Listmap, Toolbar, Cryptpad, Todo) {
var Messages = Cryptpad.Messages; var Messages = Cryptpad.Messages;
var APP = window.APP = {}; var APP = window.APP = {};
@ -24,16 +23,62 @@ define([
var onReady = function () { 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 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(); Cryptpad.removeLoadingScreen();
}; };
@ -67,6 +112,8 @@ define([
if(obj.todo) { if(obj.todo) {
hash = obj.todo; hash = obj.todo;
} else {
obj.todo = hash;
} }
var secret = Cryptpad.getSecrets('todo', hash); var secret = Cryptpad.getSecrets('todo', hash);

@ -28,7 +28,7 @@ define([
var initialize = function (proxy) { var initialize = function (proxy) {
// run migration // run migration
if (typeof(proxy.data) !== 'object') { proxy.data = {}; } 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'; } if (typeof(proxy.type) !== 'string') { proxy.type = 'todo'; }
}; };

Loading…
Cancel
Save