push my latest changes because I'm agile

This commit is contained in:
ansuz
2016-07-19 16:22:44 +02:00
parent cde239c97a
commit e3f4df7e0a
4 changed files with 265 additions and 10 deletions

View File

@@ -2,6 +2,7 @@ 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',
@@ -10,7 +11,7 @@ define([
'/common/notify.js',
'/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js'
], function (Config, Messages, Table, TextPatcher, Listmap, Crypto, Cryptpad, Visible, Notify) {
], function (Config, Messages, Table, Wizard, TextPatcher, Listmap, Crypto, Cryptpad, Visible, Notify) {
var $ = window.jQuery;
Cryptpad.styleAlerts();
@@ -39,6 +40,8 @@ define([
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');
@@ -87,7 +90,8 @@ define([
};
var Text = function () { return Input({type:'text'}); };
var table = module.table = Table($('table'), xy);
var table = module.table = Table($('#table'), xy);
var setEditable = function (bool) {
module.isEditable = bool;
items.forEach(function ($item) {
@@ -103,6 +107,49 @@ define([
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 makeUser = function (proxy, id, value) {
var $user = Input({
id: id,
@@ -118,12 +165,6 @@ define([
return $user;
};
$('#adduser').click(function () {
if (!module.isEditable) { return; }
var id = coluid();
makeUser(module.rt.proxy, id).focus();
});
var makeOption = function (proxy, id, value) {
var $option = Input({
type: 'text',
@@ -137,15 +178,42 @@ define([
addIfAbsent(proxy.table.rowsOrder, id);
table.addRow($option, Checkbox, id);
console.log(table.$[0]);
return $option;
};
$('#adduser').click(function () {
if (!module.isEditable) { return; }
var id = coluid();
makeUser(module.rt.proxy, id).focus();
});
$('#addoption').click(function () {
if (!module.isEditable) { return; }
var id = rowuid();
makeOption(module.rt.proxy, id).focus();
});
Wizard.$getOptions.click(function () {
Cryptpad.confirm("Are you really ready to add these options to your poll?", function (yes) {
if (!yes) { return; }
var options = Wizard.computeSlots(function (a, b) {
return a + ' ('+ b + ')'
});
var proxy = module.rt.proxy;
options.forEach(function (text) {
var id = rowuid();
makeOption(proxy, id).val(text);
});
console.log(options);
});
});
// notifications
var unnotify = function () {
if (!(module.tabNotification &&
@@ -357,6 +425,17 @@ define([
});
}));
$toolbar.append(Button({
id: 'wizard',
'class': 'wizard button action',
title: 'wizard!',
}).text('WIZARD').click(function () {
Wizard.show();
if (Wizard.hasBeenDisplayed) { return; }
Cryptpad.log("click the button in the top left to return to your poll");
Wizard.hasBeenDisplayed = true;
}));
setEditable(true);
};