define([ '/api/config?cb=' + Math.random().toString(16).substring(2), '/customize/messages.js', '/poll/table.js', '/poll/wizard.js', '/bower_components/textpatcher/TextPatcher.js', '/bower_components/chainpad-listmap/chainpad-listmap.js', '/bower_components/chainpad-crypto/crypto.js', '/common/cryptpad-common.js', '/common/visible.js', '/common/notify.js', '/bower_components/jquery/dist/jquery.min.js', '/customize/pad.js' ], function (Config, Messages, Table, Wizard, TextPatcher, Listmap, Crypto, Cryptpad, Visible, Notify) { var $ = window.jQuery; Cryptpad.styleAlerts(); console.log("Initializing your realtime session..."); /* TODO * set range of dates/times * (pair of date pickers) * hide options within that range * show hidden options * add notes to a particular time slot * check or uncheck options for a particular user * mark preference level? (+1, 0, -1) * delete/hide columns/rows // let users choose what they want the default input to be... * date - http://foxrunsoftware.github.io/DatePicker/ ? * ??? */ var secret = Cryptpad.getSecrets(); var module = window.APP = {}; module.Wizard = Wizard; // special UI elements var $title = $('#title').attr('placeholder', Messages.dateTitleHint || 'title'); var $location = $('#location').attr('placeholder', Messages.dateLocationHint || 'location'); var $description = $('#description').attr('placeholder', Messages.dateDescription || 'description'); var items = [$title, $location, $description]; var Uid = function (prefix, f) { f = f || function () { return Number(Math.random() * Number.MAX_SAFE_INTEGER) .toString(32).replace(/\./g, ''); }; return function () { return prefix + '-' + f(); }; }; var xy = function (x, y) { return x + '_' + y; }; var parseXY = function (id) { var p = id.split('_'); return { x: p[0], y: p[1], }; }; var find = function (map, path) { return (map && path.reduce(function (p, n) { return typeof p[n] !== 'undefined' && p[n]; }, map)) || undefined; }; var Input = function (opt) { return $('', opt); }; var Checkbox = function (id) { var p = parseXY(id); var proxy = module.rt.proxy; var $check = Input({ id: id, name: id, type:'checkbox' }).click(function () { console.log("(%s, %s) => %s", p.x, p.y, $check[0].checked); proxy.table.cells[id] = $check[0].checked? 1: 0; }); return $check; }; var Text = function () { return Input({type:'text'}); }; var table = module.table = Table($('#table'), xy); var setEditable = function (bool) { module.isEditable = bool; items.forEach(function ($item) { $item.attr('disabled', !bool); }); }; var coluid = Uid('x'); var rowuid = Uid('y'); var addIfAbsent = function (A, e) { if (A.indexOf(e) !== -1) { return; } A.push(e); }; var removeRow = function (proxy, uid) { // remove proxy.table.rows[uid] proxy.table.rows[uid] = undefined; delete proxy.table.rows[uid]; // remove proxy.table.rowsOrder var order = proxy.table.rowsOrder; order.splice(order.indexOf(uid), 1); // remove all cells including uid // proxy.table.cells Object.keys(proxy.table.cells).forEach(function (cellUid) { if (cellUid.indexOf(uid) === -1) { return; } proxy.table.cells[cellUid] = undefined; delete proxy.table.cells[cellUid]; }); // remove elements from DOM table.removeRow(uid); }; var removeColumn = function (proxy, uid) { // remove proxy.table.cols[uid] proxy.table.cols[uid] = undefined; delete proxy.table.rows[uid]; // remove proxy.table.colsOrder var order = proxy.table.colsOrder; order.splice(order.indexOf(uid), 1); // remove all cells including uid Object.keys(proxy.table.cells).forEach(function (cellUid) { if (cellUid.indexOf(uid) === -1) { return; } proxy.table.cells[cellUid] = undefined; delete proxy.table.cells[cellUid]; }); // remove elements from DOM table.removeColumn(uid); }; var removeFromArray = function (A, e) { var i = A.indexOf(e); if (i === -1) { return; } A.splice(i, 1); }; var makeUser = function (proxy, id, value) { var $user = Input({ id: id, type: 'text', placeholder: 'your name', }).on('keyup change', function () { proxy.table.cols[id] = $user.val() || ""; }); var $wrapper = $('