cryptpad/www/todo/main.js

143 lines
3.9 KiB
JavaScript
Raw Normal View History

2017-07-23 14:27:47 +02:00
define([
'jquery',
'/bower_components/chainpad-crypto/crypto.js',
2017-07-23 16:28:49 +03:00
'/bower_components/chainpad-listmap/chainpad-listmap.js',
2017-07-23 14:27:47 +02:00
'/common/toolbar2.js',
'/common/cryptpad-common.js',
2017-07-24 16:23:53 +03:00
'/todo/todo.js',
2017-07-23 14:27:47 +02:00
//'/common/media-tag.js',
//'/bower_components/file-saver/FileSaver.min.js',
2017-07-23 16:08:49 +03:00
'css!/bower_components/components-font-awesome/css/font-awesome.min.css',
2017-07-23 14:27:47 +02:00
'less!/customize/src/less/cryptpad.less',
2017-07-24 16:23:53 +03:00
], function ($, Crypto, Listmap, Toolbar, Cryptpad, Todo) {
2017-07-23 14:27:47 +02:00
var Messages = Cryptpad.Messages;
var APP = window.APP = {};
$(function () {
2017-07-24 15:35:29 +03:00
var $iframe = $('#pad-iframe').contents();
var $body = $iframe.find('body');
var ifrw = $('#pad-iframe')[0].contentWindow;
2017-07-23 14:27:47 +02:00
2017-07-24 15:35:29 +03:00
var onReady = function () {
2017-07-24 16:23:53 +03:00
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);
2017-07-24 16:14:49 +02:00
$('<span>', { 'class': 'cp-task-text' })
2017-07-24 16:23:53 +03:00
.text(APP.lm.proxy.data[el].task)
.appendTo($taskDiv);
2017-07-24 16:14:49 +02:00
$('<span>', { 'class': 'cp-task-date' })
2017-07-24 16:23:53 +03:00
.text(new Date(APP.lm.proxy.data[el].ctime).toLocaleString())
.appendTo($taskDiv);
$('<button>', {
2017-07-24 16:14:49 +02:00
'class': 'fa fa-times cp-task-remove'
2017-07-24 16:23:53 +03:00
}).appendTo($taskDiv).on('click', function() {
deleteTask(el);
});
});
};
2017-07-24 15:35:29 +03:00
var addTask = function () {
2017-07-24 16:23:53 +03:00
var $input = $iframe.find('#newTodoName');
var obj = {
"state": 0,
"task": $input.val(),
"ctime": +new Date(),
"mtime": +new Date()
};
todo.add(Cryptpad.createChannelId(), obj);
2017-07-24 16:14:49 +02:00
$input.val("");
2017-07-24 16:23:53 +03:00
display();
2017-07-24 15:35:29 +03:00
};
2017-07-24 14:13:47 +02:00
2017-07-24 16:14:49 +02:00
$iframe.find('.cp-create-form button').on('click', addTask);
2017-07-24 16:23:53 +03:00
var editTask = function () {
2017-07-23 14:27:47 +02:00
2017-07-24 14:13:47 +02:00
};
2017-07-24 15:35:29 +03:00
2017-07-24 16:23:53 +03:00
display();
2017-07-24 15:35:29 +03:00
Cryptpad.removeLoadingScreen();
2017-07-24 14:13:47 +02:00
};
var onInit = function () {
2017-07-23 14:27:47 +02:00
Cryptpad.addLoadingScreen();
2017-07-24 14:13:47 +02:00
$body.on('dragover', function (e) { e.preventDefault(); });
$body.on('drop', function (e) { e.preventDefault(); });
2017-07-23 14:27:47 +02:00
var Title;
var $bar = $iframe.find('.toolbar-container');
Title = Cryptpad.createTitle({}, function(){}, Cryptpad);
var configTb = {
2017-07-23 16:08:49 +03:00
displayed: ['useradmin', 'newpad', 'limit', 'upgrade', 'pageTitle'],
2017-07-23 14:27:47 +02:00
ifrw: ifrw,
common: Cryptpad,
//hideDisplayName: true,
$container: $bar,
2017-07-23 16:08:49 +03:00
pageTitle: Messages.todo_title
2017-07-23 14:27:47 +02:00
};
2017-07-23 14:36:41 +02:00
APP.toolbar = Toolbar.create(configTb);
2017-07-23 16:28:49 +03:00
APP.toolbar.$rightside.html(''); // Remove the drawer if we don't use it to hide the toolbar
2017-07-23 14:27:47 +02:00
};
2017-07-23 16:28:49 +03:00
var createTodo = function() {
var obj = Cryptpad.getProxy();
var hash = Cryptpad.createRandomHash();
if(obj.todo) {
hash = obj.todo;
2017-07-24 16:23:53 +03:00
} else {
obj.todo = hash;
2017-07-23 16:28:49 +03:00
}
2017-07-24 14:13:47 +02:00
var secret = Cryptpad.getSecrets('todo', hash);
2017-07-23 16:28:49 +03:00
var listmapConfig = {
data: {},
websocketURL: Cryptpad.getWebsocketURL(),
channel: secret.channel,
validateKey: secret.keys.validateKey || undefined,
crypto: Crypto.createEncryptor(secret.keys),
userName: 'todo',
logLevel: 1,
};
2017-07-24 15:35:29 +03:00
2017-07-24 14:13:47 +02:00
var lm = APP.lm = Listmap.create(listmapConfig);
2017-07-24 15:35:29 +03:00
lm.proxy.on('create', onInit)
.on('ready', onReady);
};
2017-07-23 16:28:49 +03:00
2017-07-23 14:27:47 +02:00
Cryptpad.ready(function () {
2017-07-24 14:13:47 +02:00
createTodo();
Cryptpad.reportAppUsage();
2017-07-23 14:27:47 +02:00
});
});
});