big ugly commit that will be really hard to audit
This changeset applies new styles to the poll. it also uses the new asynchronous wrappers around the localStorage api. this is necessary because we're migrating to a storage system that will use an async api. The changes to the poll just happened to coincide with the async stuff. My apologies to anyone who wants to read this whole thing
This commit is contained in:
@@ -35,17 +35,21 @@
|
||||
<div id="toolbar" class="buttons">
|
||||
<sub><a href="/"></a></sub>
|
||||
</div>
|
||||
<h1>CryptPoll </h1>
|
||||
<h2>Schedule or vote in <em>real time</em></h2>
|
||||
<h1>CryptPoll</h1>
|
||||
<h2>Zero Knowledge, <em>realtime</em> scheduling</h2>
|
||||
|
||||
<p>Enter your name in the input field below and check the box for times when you are available</p>
|
||||
<p>Your settings are updated instantly, so you never need to save.</p>
|
||||
<p>All your input is encrypted so only people who have the link can access it. Even the server cannot see what you change.</p>
|
||||
|
||||
<hr>
|
||||
<br>
|
||||
|
||||
<form class="realtime">
|
||||
<input type="text" id="title" placeholder="title"><br />
|
||||
<textarea id="description" placeholder="description"></textarea>
|
||||
|
||||
<p>Enter your name in the input field below and check the box for times when you are available</p>
|
||||
|
||||
<!-- Table markup-->
|
||||
<table id="table">
|
||||
|
||||
|
||||
168
www/poll/main.js
168
www/poll/main.js
@@ -78,15 +78,33 @@ define([
|
||||
|
||||
var proxy = module.rt.proxy;
|
||||
|
||||
var $div = $('<div>', {
|
||||
'class': 'checkbox-contain',
|
||||
});
|
||||
|
||||
var $label = $('<label>', {
|
||||
'for': id,
|
||||
});
|
||||
|
||||
var $check = Input({
|
||||
id: id,
|
||||
name: id,
|
||||
type:'checkbox'
|
||||
}).click(function () {
|
||||
type:'checkbox',
|
||||
}).on('change', function () {
|
||||
console.log("(%s, %s) => %s", p.x, p.y, $check[0].checked);
|
||||
proxy.table.cells[id] = $check[0].checked? 1: 0;
|
||||
var checked = proxy.table.cells[id] = $check[0].checked? 1: 0;
|
||||
if (checked) {
|
||||
$label.addClass('yes');
|
||||
}
|
||||
else {
|
||||
$label.removeClass('yes');
|
||||
}
|
||||
});
|
||||
return $check;
|
||||
|
||||
$div.append($check);
|
||||
$check.after($label);
|
||||
|
||||
return $div; //$check;
|
||||
};
|
||||
var Text = function () { return Input({type:'text'}); };
|
||||
|
||||
@@ -163,7 +181,9 @@ define([
|
||||
proxy.table.cols[id] = $user.val() || "";
|
||||
});
|
||||
|
||||
var $wrapper = $('<div>')
|
||||
var $wrapper = $('<div>', {
|
||||
'class': 'text-cell',
|
||||
})
|
||||
.append($user)
|
||||
.append($('<span>', {
|
||||
'class': 'remove',
|
||||
@@ -198,7 +218,9 @@ define([
|
||||
proxy.table.rows[id] = $option.val();
|
||||
});
|
||||
|
||||
var $wrapper = $('<div>')
|
||||
var $wrapper = $('<div>', {
|
||||
'class': 'text-cell',
|
||||
})
|
||||
.append($option)
|
||||
.append($('<span>', {
|
||||
'class': 'remove',
|
||||
@@ -267,9 +289,15 @@ define([
|
||||
|
||||
var proxy = module.rt.proxy;
|
||||
|
||||
var First = false;
|
||||
|
||||
// ensure that proxy.info and proxy.table exist
|
||||
['info', 'table'].forEach(function (k) {
|
||||
if (typeof(proxy[k]) === 'undefined') { proxy[k] = {}; }
|
||||
if (typeof(proxy[k]) === 'undefined') {
|
||||
// you seem to be the first person to have visited this pad...
|
||||
First = true;
|
||||
proxy[k] = {};
|
||||
}
|
||||
});
|
||||
|
||||
// table{cols,rows,cells}
|
||||
@@ -305,8 +333,16 @@ define([
|
||||
|
||||
// cells
|
||||
Object.keys(proxy.table.cells).forEach(function (uid) {
|
||||
var p = parseXY(uid);
|
||||
document.getElementById(uid).checked = proxy.table.cells[uid] ? true : false;
|
||||
//var p = parseXY(uid);
|
||||
var box = document.getElementById(uid);
|
||||
if (!box) {
|
||||
console.log("Couldn't find an element with uid [%s]", uid);
|
||||
return;
|
||||
}
|
||||
var checked = box.checked = proxy.table.cells[uid] ? true : false;
|
||||
if (checked) {
|
||||
$(box).parent().find('label').addClass('yes');
|
||||
}
|
||||
});
|
||||
|
||||
items.forEach(function ($item) {
|
||||
@@ -330,6 +366,9 @@ define([
|
||||
}
|
||||
|
||||
proxy
|
||||
.on('change', [], function () {
|
||||
notify();
|
||||
})
|
||||
.on('change', ['info'], function (o, n, p) {
|
||||
var $target = $('#' + p[1]);
|
||||
var el = $target[0];
|
||||
@@ -352,7 +391,6 @@ define([
|
||||
}
|
||||
|
||||
console.log("change: (%s, %s, [%s])", o, n, p.join(', '));
|
||||
notify();
|
||||
})
|
||||
.on('change', ['table'], function (o, n, p) {
|
||||
var id = p[p.length -1];
|
||||
@@ -393,7 +431,18 @@ define([
|
||||
break;
|
||||
case 'cells':
|
||||
console.log("[Table.cell change] %s (%s => %s)@[%s]", id, o, n, p.slice(0, -1).join(', '));
|
||||
el.checked = proxy.table.cells[id] ? true: false;
|
||||
var checked = el.checked = proxy.table.cells[id] ? true: false;
|
||||
|
||||
var $parent = $(el).parent();
|
||||
|
||||
if (!$parent.length) { console.log("couldn't find parent element of checkbox"); return; }
|
||||
|
||||
if (checked) {
|
||||
$parent.find('label').addClass('yes');
|
||||
//$(el).parent().
|
||||
} else {
|
||||
$parent.find('label').removeClass('yes');
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log("[Table change] (%s => %s)@[%s]", o, n, p.join(', '));
|
||||
@@ -401,14 +450,61 @@ define([
|
||||
}
|
||||
})
|
||||
.on('remove', [], function (o, p, root) {
|
||||
console.log("remove: (%s, [%s])", o, p.join(', '));
|
||||
//console.log("remove: (%s, [%s])", o, p.join(', '));
|
||||
//console.log(p, o, p.length);
|
||||
|
||||
switch (p[1]) {
|
||||
case 'cols':
|
||||
console.log("[Table.cols removal] [%s]", p[2]);
|
||||
table.removeColumn(p[2]);
|
||||
return false;
|
||||
case 'rows':
|
||||
console.log("[Table.rows removal] [%s]", p[2]);
|
||||
table.removeRow(p[2]);
|
||||
return false;
|
||||
case 'rowsOrder':
|
||||
Object.keys(proxy.table.rows)
|
||||
.forEach(function (rowId) {
|
||||
if (proxy.table.rowsOrder.indexOf(rowId) === -1) {
|
||||
proxy.table.rows[rowId] = undefined;
|
||||
delete proxy.table.rows[rowId];
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'colsOrder':
|
||||
Object.keys(proxy.table.cols)
|
||||
.forEach(function (colId) {
|
||||
if (proxy.table.colsOrder.indexOf(colId) === -1) {
|
||||
proxy.table.cols[colId] = undefined;
|
||||
delete proxy.table.cols[colId];
|
||||
}
|
||||
|
||||
});
|
||||
break;
|
||||
case 'cells':
|
||||
// cool story bro
|
||||
break;
|
||||
default:
|
||||
console.log("[Table removal] [%s]", p.join(', '));
|
||||
break;
|
||||
}
|
||||
|
||||
})
|
||||
.on('disconnect', function (info) {
|
||||
setEditable(false);
|
||||
});
|
||||
|
||||
var title = document.title = Cryptpad.getPadTitle();
|
||||
Cryptpad.rememberPad(title);
|
||||
Cryptpad.getPadTitle(function (err, title) {
|
||||
title = document.title = title || window.location.hash.slice(1, 9);
|
||||
|
||||
Cryptpad.rememberPad(title, function (err, data) {
|
||||
if (err) {
|
||||
console.log("unable to remember pad");
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var $toolbar = $('#toolbar');
|
||||
|
||||
@@ -434,8 +530,14 @@ define([
|
||||
var href = window.location.href;
|
||||
Cryptpad.confirm(Messages.forgetPrompt, function (yes) {
|
||||
if (!yes) { return; }
|
||||
Cryptpad.forgetPad(href);
|
||||
document.title = window.location.hash.slice(1, 9);
|
||||
Cryptpad.forgetPad(href, function (err, data) {
|
||||
if (err) {
|
||||
console.log("unable to forget pad");
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
document.title = window.location.hash.slice(1, 9);
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -448,12 +550,21 @@ define([
|
||||
Cryptpad.prompt(Messages.renamePrompt,
|
||||
suggestion, function (title, ev) {
|
||||
if (title === null) { return; }
|
||||
if (Cryptpad.causesNamingConflict(title)) {
|
||||
Cryptpad.alert(Messages.renameConflict);
|
||||
return;
|
||||
}
|
||||
Cryptpad.setPadTitle(title);
|
||||
document.title = title;
|
||||
|
||||
Cryptpad.causesNamingConflict(title, function (err, conflicts) {
|
||||
if (conflicts) {
|
||||
Cryptpad.alert(Messages.renameConflict);
|
||||
return;
|
||||
}
|
||||
Cryptpad.setPadTitle(title, function (err, data) {
|
||||
if (err) {
|
||||
console.log("unable to set pad title");
|
||||
console.error(err);
|
||||
return;
|
||||
}
|
||||
document.title = title;
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
@@ -469,6 +580,19 @@ define([
|
||||
}));
|
||||
|
||||
setEditable(true);
|
||||
|
||||
if (First) {
|
||||
// assume the first user to the poll wants to be the administrator...
|
||||
// TODO prompt them with questions to set up their poll...
|
||||
}
|
||||
/* TODO
|
||||
even if the user isn't the first, check their storage to see if
|
||||
they've visited before and if they 'own' a column in the table.
|
||||
if they do, make it editable and suggest that they fill it in.
|
||||
|
||||
if they have not visited, make a column for them.
|
||||
don't propogate changes from this column until they make changes
|
||||
*/
|
||||
};
|
||||
|
||||
var config = {
|
||||
|
||||
@@ -18,7 +18,9 @@ define([
|
||||
|
||||
$head.find('th').each(function (i) {
|
||||
var colId = $(this).data('rt-uid');
|
||||
$row.append($('<td>').append(Rest(xy(colId, uid))));
|
||||
$row.append($('<td>', {
|
||||
'class': 'checkbox-cell',
|
||||
}).append(Rest(xy(colId, uid))));
|
||||
});
|
||||
|
||||
rows.push(uid);
|
||||
@@ -35,7 +37,9 @@ define([
|
||||
var $width = $body.find('tr').each(function (i) {
|
||||
// each checkbox needs a uid corresponding to its role
|
||||
var rowId = $(this).data('rt-uid');
|
||||
$(this).append($('<td>').append(Rest(xy(uid, rowId))));
|
||||
$(this).append($('<td>', {
|
||||
'class': 'checkbox-cell',
|
||||
}).append(Rest(xy(uid, rowId))));
|
||||
});
|
||||
|
||||
cols.push(uid);
|
||||
@@ -92,6 +96,14 @@ define([
|
||||
removeFromArray(rows, uid);
|
||||
};
|
||||
|
||||
var colExists = function (uid) {
|
||||
return cols.indexOf(uid) !== -1;
|
||||
};
|
||||
|
||||
var rowExists = function (uid) {
|
||||
return rows.indexOf(uid) !== -1;
|
||||
};
|
||||
|
||||
return {
|
||||
$: $t,
|
||||
addRow: addRow,
|
||||
@@ -99,7 +111,9 @@ define([
|
||||
removeRow: removeRow,
|
||||
removeColumn: removeColumn,
|
||||
rows: rows,
|
||||
rowExists: rowExists,
|
||||
cols: cols,
|
||||
colExists: colExists,
|
||||
};
|
||||
};
|
||||
return Table;
|
||||
|
||||
Reference in New Issue
Block a user