define([ 'jquery', '/bower_components/chainpad-crypto/crypto.js', '/common/sframe-chainpad-listmap.js', '/common/toolbar3.js', '/common/cryptpad-common.js', '/bower_components/nthen/index.js', '/common/sframe-common.js', '/common/common-interface.js', '/todo/todo.js', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'less!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/customize/src/less2/main.less', ], function ( $, Crypto, Listmap, Toolbar, Cryptpad, nThen, SFCommon, UI, Todo ) { var Messages = Cryptpad.Messages; var APP = window.APP = {}; var onConnectError = function () { UI.errorLoadingScreen(Messages.websocketError); }; var common; var sFrameChan; nThen(function (waitFor) { $(waitFor(UI.addLoadingScreen)); SFCommon.create(waitFor(function (c) { APP.common = common = c; })); }).nThen(function (waitFor) { sFrameChan = common.getSframeChannel(); sFrameChan.onReady(waitFor()); }).nThen(function (/*waitFor*/) { Cryptpad.onError(function (info) { if (info && info.type === "store") { onConnectError(); } }); var $body = $('body'); var $list = $('#cp-app-todo-taskslist'); var removeTips = function () { UI.clearTooltips(); }; var onReady = function () { var todo = Todo.init(APP.lm.proxy); var deleteTask = function(id) { todo.remove(id); var $els = $list.find('.cp-app-todo-task').filter(function (i, el) { return $(el).data('id') === id; }); $els.fadeOut(null, function () { $els.remove(); removeTips(); }); //APP.display(); }; // TODO make this actually work, and scroll to bottom... var scrollTo = function (t) { $list.animate({ scrollTop: t, }); }; scrollTo = scrollTo; var makeCheckbox = function (id, cb) { var entry = APP.lm.proxy.data[id]; var checked = entry.state === 1 ? 'cp-app-todo-task-checkbox-checked fa-check-square-o': 'cp-app-todo-task-checkbox-unchecked fa-square-o'; var title = entry.state === 1? Messages.todo_markAsIncompleteTitle: Messages.todo_markAsCompleteTitle; title = title; removeTips(); return $('', { 'class': 'cp-app-todo-task-checkbox fa ' + checked, //title: title, }).on('click', function () { entry.state = (entry.state + 1) % 2; if (typeof(cb) === 'function') { cb(entry.state); } }); }; var addTaskUI = function (el, animate) { var $taskDiv = $('
', { 'class': 'cp-app-todo-task' }); if (animate) { $taskDiv.prependTo($list); } else { $taskDiv.appendTo($list); } $taskDiv.data('id', el); makeCheckbox(el, function (/*state*/) { APP.display(); }) .appendTo($taskDiv); var entry = APP.lm.proxy.data[el]; if (entry.state) { $taskDiv.addClass('cp-app-todo-task-complete'); } $('', { 'class': 'cp-app-todo-task-text' }) .text(entry.task) .appendTo($taskDiv); /*$('', { 'class': 'cp-app-todo-task-date' }) .text(new Date(entry.ctime).toLocaleString()) .appendTo($taskDiv);*/ $('