', {id: 'cp-sidebarlayout-leftside'}).appendTo(APP.$container);
+ APP.$rightside = $('
', {id: 'cp-sidebarlayout-rightside'}).appendTo(APP.$container);
+ sFrameChan = common.getSframeChannel();
+ sFrameChan.onReady(waitFor());
+ }).nThen(function (/*waitFor*/) {
+ createToolbar();
+
+ var hint = h('p.cp-convert-hint', Messages.convert_hint);
+
+ var picker = h('input', {
+ type: 'file'
+ });
+ APP.$rightside.append([hint, picker]);
+
+ $(picker).on('change', function () {
+ var file = picker.files[0];
+ var name = file && file.name;
+ var reader = new FileReader();
+ var parsed = file && file.name && /.+\.([^.]+)$/.exec(file.name);
+ var ext = parsed && parsed[1];
+ reader.onload = function (e) {
+ if (CONVERTERS[ext]) {
+ Object.keys(CONVERTERS[ext]).forEach(function (to) {
+ var button = h('button.btn', to);
+ $(button).click(function () {
+ CONVERTERS[ext][to](new Uint8Array(e.target.result), name, function (a) {
+ var n = name.slice(0, -ext.length) + to;
+ var blob = new Blob([a], {type: "application/bin;charset=utf-8"});
+ window.saveAs(blob, n);
+ });
+
+ }).appendTo(APP.$rightside);
+ });
+ }
+ };
+ reader.readAsArrayBuffer(file, 'application/octet-stream');
+ });
+
+ UI.removeLoadingScreen();
+
+ });
+});
diff --git a/www/convert/main.js b/www/convert/main.js
new file mode 100644
index 000000000..236290b13
--- /dev/null
+++ b/www/convert/main.js
@@ -0,0 +1,28 @@
+// Load #1, load as little as possible because we are in a race to get the loading screen up.
+define([
+ '/bower_components/nthen/index.js',
+ '/api/config',
+ '/common/dom-ready.js',
+ '/common/sframe-common-outer.js'
+], function (nThen, ApiConfig, DomReady, SFCommonO) {
+
+ // Loaded in load #2
+ nThen(function (waitFor) {
+ DomReady.onReady(waitFor());
+ }).nThen(function (waitFor) {
+ SFCommonO.initIframe(waitFor, true);
+ }).nThen(function (/*waitFor*/) {
+ var category;
+ if (window.location.hash) {
+ category = window.location.hash.slice(1);
+ window.location.hash = '';
+ }
+ var addData = function (obj) {
+ if (category) { obj.category = category; }
+ };
+ SFCommonO.start({
+ noRealtime: true,
+ addData: addData
+ });
+ });
+});
diff --git a/www/form/app-form.less b/www/form/app-form.less
index 433316448..95802e18b 100644
--- a/www/form/app-form.less
+++ b/www/form/app-form.less
@@ -470,7 +470,11 @@
//padding: 10px;
}
+ .cp-form-creator-results-export {
+ margin-bottom: 20px;
+ }
.cp-form-creator-results-content {
+ padding-bottom: 100px;
.cp-form-block {
background: @cp_form-bg1;
padding: 10px;
diff --git a/www/form/export.js b/www/form/export.js
new file mode 100644
index 000000000..4afc4170a
--- /dev/null
+++ b/www/form/export.js
@@ -0,0 +1,72 @@
+define([
+ '/common/common-util.js',
+ '/customize/messages.js'
+], function (Util, Messages) {
+ var Export = {};
+
+ var escapeCSV = function (v) {
+ if (!/("|,|\n|;)/.test(v)) {
+ return v || '';
+ }
+ var value = '';
+ var vv = (v || '').replaceAll('"', '""');
+ value += '"' + vv + '"';
+ return value;
+ };
+ Export.results = function (content, answers, TYPES) {
+ if (!content || !content.form) { return; }
+ var csv = "";
+ var form = content.form;
+
+ var questions = [Messages.form_poll_time, Messages.share_formView];
+
+ content.order.forEach(function (key) {
+ var obj = form[key];
+ if (!obj) { return; }
+ var type = obj.type;
+ if (!TYPES[type]) { return; } // Ignore static types
+ var c;
+ if (TYPES[type] && TYPES[type].exportCSV) { c = TYPES[type].exportCSV(false, obj); }
+ if (!c) { c = [obj.q || Messages.form_default]; }
+ Array.prototype.push.apply(questions, c);
+ });
+
+ questions.forEach(function (v, i) {
+ if (i) { csv += ','; }
+ csv += escapeCSV(v);
+ });
+
+ Object.keys(answers || {}).forEach(function (key) {
+ var obj = answers[key];
+ csv += '\n';
+ var time = new Date(obj.time).toISOString();
+ var msg = obj.msg || {};
+ var user = msg._userdata || {};
+ csv += escapeCSV(time);
+ csv += ',' + escapeCSV(user.name || Messages.anonymous);
+ content.order.forEach(function (key) {
+ var type = form[key].type;
+ if (!TYPES[type]) { return; } // Ignore static types
+ if (TYPES[type].exportCSV) {
+ var res = TYPES[type].exportCSV(msg[key], form[key]).map(function (str) {
+ return escapeCSV(str);
+ }).join(',');
+ csv += ',' + res;
+ return;
+ }
+ csv += ',' + escapeCSV(String(msg[key] || ''));
+ });
+ });
+ return csv;
+ };
+
+ Export.main = function (content, cb) {
+ var json = Util.clone(content || {});
+ delete json.answers;
+ cb(new Blob([JSON.stringify(json, 0, 2)], {
+ type: 'application/json;charset=utf-8'
+ }));
+ };
+
+ return Export;
+});
diff --git a/www/form/inner.js b/www/form/inner.js
index 80c50a0d6..2a1501ecb 100644
--- a/www/form/inner.js
+++ b/www/form/inner.js
@@ -4,6 +4,7 @@ define([
'/bower_components/chainpad-crypto/crypto.js',
'/common/sframe-app-framework.js',
'/common/toolbar.js',
+ '/form/export.js',
'/bower_components/nthen/index.js',
'/common/sframe-common.js',
'/common/common-util.js',
@@ -30,6 +31,8 @@ define([
'cm/mode/gfm/gfm',
'css!cm/lib/codemirror.css',
+ '/bower_components/file-saver/FileSaver.min.js',
+
'css!/bower_components/codemirror/lib/codemirror.css',
'css!/bower_components/codemirror/addon/dialog/dialog.css',
'css!/bower_components/codemirror/addon/fold/foldgutter.css',
@@ -42,6 +45,7 @@ define([
Crypto,
Framework,
Toolbar,
+ Exporter,
nThen,
SFCommon,
Util,
@@ -76,8 +80,11 @@ define([
timeFormat = "h:i K";
}
- var MAX_OPTIONS = 15; // XXX
- var MAX_ITEMS = 10; // XXX
+ // multi-line radio, checkboxes, and possibly other things have a max number of items
+ // we'll consider increasing this restriction if people are unhappy with it
+ // but as a general rule we expect users will appreciate having simpler questions
+ var MAX_OPTIONS = 15;
+ var MAX_ITEMS = 10;
var saveAndCancelOptions = function (getRes, cb) {
// Cancel changes
@@ -1208,6 +1215,20 @@ define([
return h('div.cp-form-results-type-radio', results);
},
+ exportCSV: function (answer, form) {
+ var opts = form.opts || {};
+ var q = form.q || Messages.form_default;
+ if (answer === false) {
+ return (opts.items || []).map(function (obj) {
+ return q + ' | ' + obj.v;
+ });
+ }
+ if (!answer) { return ['']; }
+ return (opts.items || []).map(function (obj) {
+ var uid = obj.uid;
+ return String(answer[uid] || '');
+ });
+ },
icon: h('i.cptools.cptools-form-grid-radio')
},
checkbox: {
@@ -1422,6 +1443,20 @@ define([
return h('div.cp-form-results-type-radio', results);
},
+ exportCSV: function (answer, form) {
+ var opts = form.opts || {};
+ var q = form.q || Messages.form_default;
+ if (answer === false) {
+ return (opts.items || []).map(function (obj) {
+ return q + ' | ' + obj.v;
+ });
+ }
+ if (!answer) { return ['']; }
+ return (opts.items || []).map(function (obj) {
+ var uid = obj.uid;
+ return String(answer[uid] || '');
+ });
+ },
icon: h('i.cptools.cptools-form-grid-check')
},
sort: {
@@ -1642,6 +1677,16 @@ define([
return h('div.cp-form-type-poll', lines);
},
+ exportCSV: function (answer) {
+ if (answer === false) { return; }
+ if (!answer || !answer.values) { return ['']; }
+ var str = '';
+ Object.keys(answer.values).sort().forEach(function (k, i) {
+ if (i !== 0) { str += ';'; }
+ str += k.replace(';', '').replace(':', '') + ':' + answer.values[k];
+ });
+ return [str];
+ },
icon: h('i.cptools.cptools-form-poll')
},
};
@@ -1656,9 +1701,21 @@ define([
var controls = h('div.cp-form-creator-results-controls');
var $controls = $(controls).appendTo($container);
+ var exportButton = h('button.btn.btn-secondary', Messages.exportButton); // XXX form_exportCSV;
+ var exportCSV = h('div.cp-form-creator-results-export', exportButton);
+ $(exportCSV).appendTo($container);
var results = h('div.cp-form-creator-results-content');
var $results = $(results).appendTo($container);
+ $(exportButton).click(function () {
+ var csv = Exporter.results(content, answers, TYPES);
+ if (!csv) { return void UI.warn(Messages.error); }
+ var suggestion = APP.framework._.title.suggestTitle('cryptpad-document');
+ var title = Util.fixFileName(suggestion) + '.csv';
+ window.saveAs(new Blob([csv], {
+ type: 'text/csv'
+ }), title);
+ });
var summary = true;
var form = content.form;
@@ -2315,6 +2372,7 @@ define([
var andThen = function (framework) {
framework.start();
+ APP.framework = framework;
var evOnChange = Util.mkEvent();
var content = {};
@@ -2739,6 +2797,17 @@ define([
return content;
});
+ framework.setFileImporter({ accept: ['.json'] }, function (newContent) {
+ var parsed = JSON.parse(newContent || {});
+ parsed.answers = content.answers;
+ return parsed;
+ });
+
+ framework.setFileExporter(['.json'], function(cb, ext) {
+ Exporter.main(content, cb, ext);
+ }, true);
+
+
};
Framework.create({
diff --git a/www/form/templates.js b/www/form/templates.js
new file mode 100644
index 000000000..6ff3249b8
--- /dev/null
+++ b/www/form/templates.js
@@ -0,0 +1,20 @@
+define([
+ '/customize/messages.js'
+], function (Messages) {
+ return [{
+ id: 'a',
+ used: 1,
+ name: Messages.form_type_poll,
+ content: {
+ form: {
+ "1": {
+ type: 'md'
+ },
+ "2": {
+ type: 'poll'
+ }
+ },
+ order: ["1", "2"]
+ }
+ }];
+});
diff --git a/www/kanban/export.js b/www/kanban/export.js
index 9ee770ac7..694724cf4 100644
--- a/www/kanban/export.js
+++ b/www/kanban/export.js
@@ -13,6 +13,73 @@ define([
}));
};
+ module.import = function (content) {
+ // Import from Trello
+
+ var c = {
+ data: {},
+ items: {},
+ list: []
+ };
+
+ var colorMap = {
+ red: 'color1',
+ orange: 'color2',
+ yellow: 'color3',
+ lime: 'color4',
+ green: 'color5',
+ sky: 'color6',
+ blue: 'color7',
+ purple: 'color8',
+ pink: 'color9',
+ black: 'nocolor'
+ };
+ content.cards.forEach(function (obj, i) {
+ var tags;
+ var color;
+ if (Array.isArray(obj.labels)) {
+ obj.labels.forEach(function (l) {
+ if (!color) {
+ color = colorMap[l.color] || '';
+ }
+ if (l.name) {
+ tags = tags || [];
+ var n = l.name.toLowerCase().trim();
+ if (tags.indexOf(n) === -1) { tags.push(n); }
+ }
+ });
+ }
+ c.items[(i+1)] = {
+ id: (i+1),
+ title: obj.name,
+ body: obj.desc,
+ color: color,
+ tags: tags
+ };
+ });
+
+ var id = 1;
+ content.lists.forEach(function (obj) {
+ var _id = obj.id;
+ var cards = [];
+ content.cards.forEach(function (card, i) {
+ if (card.idList === _id) {
+ cards.push(i+1);
+ }
+ });
+ c.data[id] = {
+ id: id,
+ title: obj.name,
+ item: cards
+ };
+ c.list.push(id);
+
+ id++;
+ });
+
+ return c;
+ };
+
return module;
});
diff --git a/www/kanban/inner.js b/www/kanban/inner.js
index 76a9fe1cc..4832adcca 100644
--- a/www/kanban/inner.js
+++ b/www/kanban/inner.js
@@ -18,6 +18,7 @@ define([
'/bower_components/marked/marked.min.js',
'cm/lib/codemirror',
'/kanban/jkanban_cp.js',
+ '/kanban/export.js',
'cm/mode/gfm/gfm',
'cm/addon/edit/closebrackets',
@@ -50,7 +51,8 @@ define([
ChainPad,
Marked,
CodeMirror,
- jKanban)
+ jKanban,
+ Export)
{
var verbose = function (x) { console.log(x); };
@@ -287,7 +289,7 @@ define([
var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey);
- var mt = '
';
+ var mt = UI.mediaTag(src, key).outerHTML;
editor.replaceSelection(mt);
}
};
@@ -1060,6 +1062,11 @@ define([
var parsed;
try { parsed = JSON.parse(content); }
catch (e) { return void console.error(e); }
+
+ if (parsed && parsed.id && parsed.lists && parsed.cards) {
+ return { content: Export.import(parsed) };
+ }
+
return { content: parsed };
});
diff --git a/www/lib/changelog.md b/www/lib/changelog.md
new file mode 100644
index 000000000..86ef6ec22
--- /dev/null
+++ b/www/lib/changelog.md
@@ -0,0 +1,4 @@
+This file is intended to be used as a log of what third-party source we have vendored, where we got it, and what modifications we have made to it (if any).
+
+* [turndown v7.1.1](https://github.com/mixmark-io/turndown/releases/tag/v7.1.1) built from unmodified source as per its build scripts.
+
diff --git a/www/lib/turndown.browser.umd.js b/www/lib/turndown.browser.umd.js
new file mode 100644
index 000000000..a812101ae
--- /dev/null
+++ b/www/lib/turndown.browser.umd.js
@@ -0,0 +1,976 @@
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+ typeof define === 'function' && define.amd ? define(factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.TurndownService = factory());
+}(this, (function () { 'use strict';
+
+ function extend (destination) {
+ for (var i = 1; i < arguments.length; i++) {
+ var source = arguments[i];
+ for (var key in source) {
+ if (source.hasOwnProperty(key)) destination[key] = source[key];
+ }
+ }
+ return destination
+ }
+
+ function repeat (character, count) {
+ return Array(count + 1).join(character)
+ }
+
+ function trimLeadingNewlines (string) {
+ return string.replace(/^\n*/, '')
+ }
+
+ function trimTrailingNewlines (string) {
+ // avoid match-at-end regexp bottleneck, see #370
+ var indexEnd = string.length;
+ while (indexEnd > 0 && string[indexEnd - 1] === '\n') indexEnd--;
+ return string.substring(0, indexEnd)
+ }
+
+ var blockElements = [
+ 'ADDRESS', 'ARTICLE', 'ASIDE', 'AUDIO', 'BLOCKQUOTE', 'BODY', 'CANVAS',
+ 'CENTER', 'DD', 'DIR', 'DIV', 'DL', 'DT', 'FIELDSET', 'FIGCAPTION', 'FIGURE',
+ 'FOOTER', 'FORM', 'FRAMESET', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'HEADER',
+ 'HGROUP', 'HR', 'HTML', 'ISINDEX', 'LI', 'MAIN', 'MENU', 'NAV', 'NOFRAMES',
+ 'NOSCRIPT', 'OL', 'OUTPUT', 'P', 'PRE', 'SECTION', 'TABLE', 'TBODY', 'TD',
+ 'TFOOT', 'TH', 'THEAD', 'TR', 'UL'
+ ];
+
+ function isBlock (node) {
+ return is(node, blockElements)
+ }
+
+ var voidElements = [
+ 'AREA', 'BASE', 'BR', 'COL', 'COMMAND', 'EMBED', 'HR', 'IMG', 'INPUT',
+ 'KEYGEN', 'LINK', 'META', 'PARAM', 'SOURCE', 'TRACK', 'WBR'
+ ];
+
+ function isVoid (node) {
+ return is(node, voidElements)
+ }
+
+ function hasVoid (node) {
+ return has(node, voidElements)
+ }
+
+ var meaningfulWhenBlankElements = [
+ 'A', 'TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TH', 'TD', 'IFRAME', 'SCRIPT',
+ 'AUDIO', 'VIDEO'
+ ];
+
+ function isMeaningfulWhenBlank (node) {
+ return is(node, meaningfulWhenBlankElements)
+ }
+
+ function hasMeaningfulWhenBlank (node) {
+ return has(node, meaningfulWhenBlankElements)
+ }
+
+ function is (node, tagNames) {
+ return tagNames.indexOf(node.nodeName) >= 0
+ }
+
+ function has (node, tagNames) {
+ return (
+ node.getElementsByTagName &&
+ tagNames.some(function (tagName) {
+ return node.getElementsByTagName(tagName).length
+ })
+ )
+ }
+
+ var rules = {};
+
+ rules.paragraph = {
+ filter: 'p',
+
+ replacement: function (content) {
+ return '\n\n' + content + '\n\n'
+ }
+ };
+
+ rules.lineBreak = {
+ filter: 'br',
+
+ replacement: function (content, node, options) {
+ return options.br + '\n'
+ }
+ };
+
+ rules.heading = {
+ filter: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'],
+
+ replacement: function (content, node, options) {
+ var hLevel = Number(node.nodeName.charAt(1));
+
+ if (options.headingStyle === 'setext' && hLevel < 3) {
+ var underline = repeat((hLevel === 1 ? '=' : '-'), content.length);
+ return (
+ '\n\n' + content + '\n' + underline + '\n\n'
+ )
+ } else {
+ return '\n\n' + repeat('#', hLevel) + ' ' + content + '\n\n'
+ }
+ }
+ };
+
+ rules.blockquote = {
+ filter: 'blockquote',
+
+ replacement: function (content) {
+ content = content.replace(/^\n+|\n+$/g, '');
+ content = content.replace(/^/gm, '> ');
+ return '\n\n' + content + '\n\n'
+ }
+ };
+
+ rules.list = {
+ filter: ['ul', 'ol'],
+
+ replacement: function (content, node) {
+ var parent = node.parentNode;
+ if (parent.nodeName === 'LI' && parent.lastElementChild === node) {
+ return '\n' + content
+ } else {
+ return '\n\n' + content + '\n\n'
+ }
+ }
+ };
+
+ rules.listItem = {
+ filter: 'li',
+
+ replacement: function (content, node, options) {
+ content = content
+ .replace(/^\n+/, '') // remove leading newlines
+ .replace(/\n+$/, '\n') // replace trailing newlines with just a single one
+ .replace(/\n/gm, '\n '); // indent
+ var prefix = options.bulletListMarker + ' ';
+ var parent = node.parentNode;
+ if (parent.nodeName === 'OL') {
+ var start = parent.getAttribute('start');
+ var index = Array.prototype.indexOf.call(parent.children, node);
+ prefix = (start ? Number(start) + index : index + 1) + '. ';
+ }
+ return (
+ prefix + content + (node.nextSibling && !/\n$/.test(content) ? '\n' : '')
+ )
+ }
+ };
+
+ rules.indentedCodeBlock = {
+ filter: function (node, options) {
+ return (
+ options.codeBlockStyle === 'indented' &&
+ node.nodeName === 'PRE' &&
+ node.firstChild &&
+ node.firstChild.nodeName === 'CODE'
+ )
+ },
+
+ replacement: function (content, node, options) {
+ return (
+ '\n\n ' +
+ node.firstChild.textContent.replace(/\n/g, '\n ') +
+ '\n\n'
+ )
+ }
+ };
+
+ rules.fencedCodeBlock = {
+ filter: function (node, options) {
+ return (
+ options.codeBlockStyle === 'fenced' &&
+ node.nodeName === 'PRE' &&
+ node.firstChild &&
+ node.firstChild.nodeName === 'CODE'
+ )
+ },
+
+ replacement: function (content, node, options) {
+ var className = node.firstChild.getAttribute('class') || '';
+ var language = (className.match(/language-(\S+)/) || [null, ''])[1];
+ var code = node.firstChild.textContent;
+
+ var fenceChar = options.fence.charAt(0);
+ var fenceSize = 3;
+ var fenceInCodeRegex = new RegExp('^' + fenceChar + '{3,}', 'gm');
+
+ var match;
+ while ((match = fenceInCodeRegex.exec(code))) {
+ if (match[0].length >= fenceSize) {
+ fenceSize = match[0].length + 1;
+ }
+ }
+
+ var fence = repeat(fenceChar, fenceSize);
+
+ return (
+ '\n\n' + fence + language + '\n' +
+ code.replace(/\n$/, '') +
+ '\n' + fence + '\n\n'
+ )
+ }
+ };
+
+ rules.horizontalRule = {
+ filter: 'hr',
+
+ replacement: function (content, node, options) {
+ return '\n\n' + options.hr + '\n\n'
+ }
+ };
+
+ rules.inlineLink = {
+ filter: function (node, options) {
+ return (
+ options.linkStyle === 'inlined' &&
+ node.nodeName === 'A' &&
+ node.getAttribute('href')
+ )
+ },
+
+ replacement: function (content, node) {
+ var href = node.getAttribute('href');
+ var title = cleanAttribute(node.getAttribute('title'));
+ if (title) title = ' "' + title + '"';
+ return '[' + content + '](' + href + title + ')'
+ }
+ };
+
+ rules.referenceLink = {
+ filter: function (node, options) {
+ return (
+ options.linkStyle === 'referenced' &&
+ node.nodeName === 'A' &&
+ node.getAttribute('href')
+ )
+ },
+
+ replacement: function (content, node, options) {
+ var href = node.getAttribute('href');
+ var title = cleanAttribute(node.getAttribute('title'));
+ if (title) title = ' "' + title + '"';
+ var replacement;
+ var reference;
+
+ switch (options.linkReferenceStyle) {
+ case 'collapsed':
+ replacement = '[' + content + '][]';
+ reference = '[' + content + ']: ' + href + title;
+ break
+ case 'shortcut':
+ replacement = '[' + content + ']';
+ reference = '[' + content + ']: ' + href + title;
+ break
+ default:
+ var id = this.references.length + 1;
+ replacement = '[' + content + '][' + id + ']';
+ reference = '[' + id + ']: ' + href + title;
+ }
+
+ this.references.push(reference);
+ return replacement
+ },
+
+ references: [],
+
+ append: function (options) {
+ var references = '';
+ if (this.references.length) {
+ references = '\n\n' + this.references.join('\n') + '\n\n';
+ this.references = []; // Reset references
+ }
+ return references
+ }
+ };
+
+ rules.emphasis = {
+ filter: ['em', 'i'],
+
+ replacement: function (content, node, options) {
+ if (!content.trim()) return ''
+ return options.emDelimiter + content + options.emDelimiter
+ }
+ };
+
+ rules.strong = {
+ filter: ['strong', 'b'],
+
+ replacement: function (content, node, options) {
+ if (!content.trim()) return ''
+ return options.strongDelimiter + content + options.strongDelimiter
+ }
+ };
+
+ rules.code = {
+ filter: function (node) {
+ var hasSiblings = node.previousSibling || node.nextSibling;
+ var isCodeBlock = node.parentNode.nodeName === 'PRE' && !hasSiblings;
+
+ return node.nodeName === 'CODE' && !isCodeBlock
+ },
+
+ replacement: function (content) {
+ if (!content) return ''
+ content = content.replace(/\r?\n|\r/g, ' ');
+
+ var extraSpace = /^`|^ .*?[^ ].* $|`$/.test(content) ? ' ' : '';
+ var delimiter = '`';
+ var matches = content.match(/`+/gm) || [];
+ while (matches.indexOf(delimiter) !== -1) delimiter = delimiter + '`';
+
+ return delimiter + extraSpace + content + extraSpace + delimiter
+ }
+ };
+
+ rules.image = {
+ filter: 'img',
+
+ replacement: function (content, node) {
+ var alt = cleanAttribute(node.getAttribute('alt'));
+ var src = node.getAttribute('src') || '';
+ var title = cleanAttribute(node.getAttribute('title'));
+ var titlePart = title ? ' "' + title + '"' : '';
+ return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : ''
+ }
+ };
+
+ function cleanAttribute (attribute) {
+ return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : ''
+ }
+
+ /**
+ * Manages a collection of rules used to convert HTML to Markdown
+ */
+
+ function Rules (options) {
+ this.options = options;
+ this._keep = [];
+ this._remove = [];
+
+ this.blankRule = {
+ replacement: options.blankReplacement
+ };
+
+ this.keepReplacement = options.keepReplacement;
+
+ this.defaultRule = {
+ replacement: options.defaultReplacement
+ };
+
+ this.array = [];
+ for (var key in options.rules) this.array.push(options.rules[key]);
+ }
+
+ Rules.prototype = {
+ add: function (key, rule) {
+ this.array.unshift(rule);
+ },
+
+ keep: function (filter) {
+ this._keep.unshift({
+ filter: filter,
+ replacement: this.keepReplacement
+ });
+ },
+
+ remove: function (filter) {
+ this._remove.unshift({
+ filter: filter,
+ replacement: function () {
+ return ''
+ }
+ });
+ },
+
+ forNode: function (node) {
+ if (node.isBlank) return this.blankRule
+ var rule;
+
+ if ((rule = findRule(this.array, node, this.options))) return rule
+ if ((rule = findRule(this._keep, node, this.options))) return rule
+ if ((rule = findRule(this._remove, node, this.options))) return rule
+
+ return this.defaultRule
+ },
+
+ forEach: function (fn) {
+ for (var i = 0; i < this.array.length; i++) fn(this.array[i], i);
+ }
+ };
+
+ function findRule (rules, node, options) {
+ for (var i = 0; i < rules.length; i++) {
+ var rule = rules[i];
+ if (filterValue(rule, node, options)) return rule
+ }
+ return void 0
+ }
+
+ function filterValue (rule, node, options) {
+ var filter = rule.filter;
+ if (typeof filter === 'string') {
+ if (filter === node.nodeName.toLowerCase()) return true
+ } else if (Array.isArray(filter)) {
+ if (filter.indexOf(node.nodeName.toLowerCase()) > -1) return true
+ } else if (typeof filter === 'function') {
+ if (filter.call(rule, node, options)) return true
+ } else {
+ throw new TypeError('`filter` needs to be a string, array, or function')
+ }
+ }
+
+ /**
+ * The collapseWhitespace function is adapted from collapse-whitespace
+ * by Luc Thevenard.
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2014 Luc Thevenard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+ /**
+ * collapseWhitespace(options) removes extraneous whitespace from an the given element.
+ *
+ * @param {Object} options
+ */
+ function collapseWhitespace (options) {
+ var element = options.element;
+ var isBlock = options.isBlock;
+ var isVoid = options.isVoid;
+ var isPre = options.isPre || function (node) {
+ return node.nodeName === 'PRE'
+ };
+
+ if (!element.firstChild || isPre(element)) return
+
+ var prevText = null;
+ var keepLeadingWs = false;
+
+ var prev = null;
+ var node = next(prev, element, isPre);
+
+ while (node !== element) {
+ if (node.nodeType === 3 || node.nodeType === 4) { // Node.TEXT_NODE or Node.CDATA_SECTION_NODE
+ var text = node.data.replace(/[ \r\n\t]+/g, ' ');
+
+ if ((!prevText || / $/.test(prevText.data)) &&
+ !keepLeadingWs && text[0] === ' ') {
+ text = text.substr(1);
+ }
+
+ // `text` might be empty at this point.
+ if (!text) {
+ node = remove(node);
+ continue
+ }
+
+ node.data = text;
+
+ prevText = node;
+ } else if (node.nodeType === 1) { // Node.ELEMENT_NODE
+ if (isBlock(node) || node.nodeName === 'BR') {
+ if (prevText) {
+ prevText.data = prevText.data.replace(/ $/, '');
+ }
+
+ prevText = null;
+ keepLeadingWs = false;
+ } else if (isVoid(node) || isPre(node)) {
+ // Avoid trimming space around non-block, non-BR void elements and inline PRE.
+ prevText = null;
+ keepLeadingWs = true;
+ } else if (prevText) {
+ // Drop protection if set previously.
+ keepLeadingWs = false;
+ }
+ } else {
+ node = remove(node);
+ continue
+ }
+
+ var nextNode = next(prev, node, isPre);
+ prev = node;
+ node = nextNode;
+ }
+
+ if (prevText) {
+ prevText.data = prevText.data.replace(/ $/, '');
+ if (!prevText.data) {
+ remove(prevText);
+ }
+ }
+ }
+
+ /**
+ * remove(node) removes the given node from the DOM and returns the
+ * next node in the sequence.
+ *
+ * @param {Node} node
+ * @return {Node} node
+ */
+ function remove (node) {
+ var next = node.nextSibling || node.parentNode;
+
+ node.parentNode.removeChild(node);
+
+ return next
+ }
+
+ /**
+ * next(prev, current, isPre) returns the next node in the sequence, given the
+ * current and previous nodes.
+ *
+ * @param {Node} prev
+ * @param {Node} current
+ * @param {Function} isPre
+ * @return {Node}
+ */
+ function next (prev, current, isPre) {
+ if ((prev && prev.parentNode === current) || isPre(current)) {
+ return current.nextSibling || current.parentNode
+ }
+
+ return current.firstChild || current.nextSibling || current.parentNode
+ }
+
+ /*
+ * Set up window for Node.js
+ */
+
+ var root = (typeof window !== 'undefined' ? window : {});
+
+ /*
+ * Parsing HTML strings
+ */
+
+ function canParseHTMLNatively () {
+ var Parser = root.DOMParser;
+ var canParse = false;
+
+ // Adapted from https://gist.github.com/1129031
+ // Firefox/Opera/IE throw errors on unsupported types
+ try {
+ // WebKit returns null on unsupported types
+ if (new Parser().parseFromString('', 'text/html')) {
+ canParse = true;
+ }
+ } catch (e) {}
+
+ return canParse
+ }
+
+ function createHTMLParser () {
+ var Parser = function () {};
+
+ {
+ if (shouldUseActiveX()) {
+ Parser.prototype.parseFromString = function (string) {
+ var doc = new window.ActiveXObject('htmlfile');
+ doc.designMode = 'on'; // disable on-page scripts
+ doc.open();
+ doc.write(string);
+ doc.close();
+ return doc
+ };
+ } else {
+ Parser.prototype.parseFromString = function (string) {
+ var doc = document.implementation.createHTMLDocument('');
+ doc.open();
+ doc.write(string);
+ doc.close();
+ return doc
+ };
+ }
+ }
+ return Parser
+ }
+
+ function shouldUseActiveX () {
+ var useActiveX = false;
+ try {
+ document.implementation.createHTMLDocument('').open();
+ } catch (e) {
+ if (window.ActiveXObject) useActiveX = true;
+ }
+ return useActiveX
+ }
+
+ var HTMLParser = canParseHTMLNatively() ? root.DOMParser : createHTMLParser();
+
+ function RootNode (input, options) {
+ var root;
+ if (typeof input === 'string') {
+ var doc = htmlParser().parseFromString(
+ // DOM parsers arrange elements in the and .
+ // Wrapping in a custom element ensures elements are reliably arranged in
+ // a single element.
+ '' + input + '',
+ 'text/html'
+ );
+ root = doc.getElementById('turndown-root');
+ } else {
+ root = input.cloneNode(true);
+ }
+ collapseWhitespace({
+ element: root,
+ isBlock: isBlock,
+ isVoid: isVoid,
+ isPre: options.preformattedCode ? isPreOrCode : null
+ });
+
+ return root
+ }
+
+ var _htmlParser;
+ function htmlParser () {
+ _htmlParser = _htmlParser || new HTMLParser();
+ return _htmlParser
+ }
+
+ function isPreOrCode (node) {
+ return node.nodeName === 'PRE' || node.nodeName === 'CODE'
+ }
+
+ function Node (node, options) {
+ node.isBlock = isBlock(node);
+ node.isCode = node.nodeName === 'CODE' || node.parentNode.isCode;
+ node.isBlank = isBlank(node);
+ node.flankingWhitespace = flankingWhitespace(node, options);
+ return node
+ }
+
+ function isBlank (node) {
+ return (
+ !isVoid(node) &&
+ !isMeaningfulWhenBlank(node) &&
+ /^\s*$/i.test(node.textContent) &&
+ !hasVoid(node) &&
+ !hasMeaningfulWhenBlank(node)
+ )
+ }
+
+ function flankingWhitespace (node, options) {
+ if (node.isBlock || (options.preformattedCode && node.isCode)) {
+ return { leading: '', trailing: '' }
+ }
+
+ var edges = edgeWhitespace(node.textContent);
+
+ // abandon leading ASCII WS if left-flanked by ASCII WS
+ if (edges.leadingAscii && isFlankedByWhitespace('left', node, options)) {
+ edges.leading = edges.leadingNonAscii;
+ }
+
+ // abandon trailing ASCII WS if right-flanked by ASCII WS
+ if (edges.trailingAscii && isFlankedByWhitespace('right', node, options)) {
+ edges.trailing = edges.trailingNonAscii;
+ }
+
+ return { leading: edges.leading, trailing: edges.trailing }
+ }
+
+ function edgeWhitespace (string) {
+ var m = string.match(/^(([ \t\r\n]*)(\s*))[\s\S]*?((\s*?)([ \t\r\n]*))$/);
+ return {
+ leading: m[1], // whole string for whitespace-only strings
+ leadingAscii: m[2],
+ leadingNonAscii: m[3],
+ trailing: m[4], // empty for whitespace-only strings
+ trailingNonAscii: m[5],
+ trailingAscii: m[6]
+ }
+ }
+
+ function isFlankedByWhitespace (side, node, options) {
+ var sibling;
+ var regExp;
+ var isFlanked;
+
+ if (side === 'left') {
+ sibling = node.previousSibling;
+ regExp = / $/;
+ } else {
+ sibling = node.nextSibling;
+ regExp = /^ /;
+ }
+
+ if (sibling) {
+ if (sibling.nodeType === 3) {
+ isFlanked = regExp.test(sibling.nodeValue);
+ } else if (options.preformattedCode && sibling.nodeName === 'CODE') {
+ isFlanked = false;
+ } else if (sibling.nodeType === 1 && !isBlock(sibling)) {
+ isFlanked = regExp.test(sibling.textContent);
+ }
+ }
+ return isFlanked
+ }
+
+ var reduce = Array.prototype.reduce;
+ var escapes = [
+ [/\\/g, '\\\\'],
+ [/\*/g, '\\*'],
+ [/^-/g, '\\-'],
+ [/^\+ /g, '\\+ '],
+ [/^(=+)/g, '\\$1'],
+ [/^(#{1,6}) /g, '\\$1 '],
+ [/`/g, '\\`'],
+ [/^~~~/g, '\\~~~'],
+ [/\[/g, '\\['],
+ [/\]/g, '\\]'],
+ [/^>/g, '\\>'],
+ [/_/g, '\\_'],
+ [/^(\d+)\. /g, '$1\\. ']
+ ];
+
+ function TurndownService (options) {
+ if (!(this instanceof TurndownService)) return new TurndownService(options)
+
+ var defaults = {
+ rules: rules,
+ headingStyle: 'setext',
+ hr: '* * *',
+ bulletListMarker: '*',
+ codeBlockStyle: 'indented',
+ fence: '```',
+ emDelimiter: '_',
+ strongDelimiter: '**',
+ linkStyle: 'inlined',
+ linkReferenceStyle: 'full',
+ br: ' ',
+ preformattedCode: false,
+ blankReplacement: function (content, node) {
+ return node.isBlock ? '\n\n' : ''
+ },
+ keepReplacement: function (content, node) {
+ return node.isBlock ? '\n\n' + node.outerHTML + '\n\n' : node.outerHTML
+ },
+ defaultReplacement: function (content, node) {
+ return node.isBlock ? '\n\n' + content + '\n\n' : content
+ }
+ };
+ this.options = extend({}, defaults, options);
+ this.rules = new Rules(this.options);
+ }
+
+ TurndownService.prototype = {
+ /**
+ * The entry point for converting a string or DOM node to Markdown
+ * @public
+ * @param {String|HTMLElement} input The string or DOM node to convert
+ * @returns A Markdown representation of the input
+ * @type String
+ */
+
+ turndown: function (input) {
+ if (!canConvert(input)) {
+ throw new TypeError(
+ input + ' is not a string, or an element/document/fragment node.'
+ )
+ }
+
+ if (input === '') return ''
+
+ var output = process.call(this, new RootNode(input, this.options));
+ return postProcess.call(this, output)
+ },
+
+ /**
+ * Add one or more plugins
+ * @public
+ * @param {Function|Array} plugin The plugin or array of plugins to add
+ * @returns The Turndown instance for chaining
+ * @type Object
+ */
+
+ use: function (plugin) {
+ if (Array.isArray(plugin)) {
+ for (var i = 0; i < plugin.length; i++) this.use(plugin[i]);
+ } else if (typeof plugin === 'function') {
+ plugin(this);
+ } else {
+ throw new TypeError('plugin must be a Function or an Array of Functions')
+ }
+ return this
+ },
+
+ /**
+ * Adds a rule
+ * @public
+ * @param {String} key The unique key of the rule
+ * @param {Object} rule The rule
+ * @returns The Turndown instance for chaining
+ * @type Object
+ */
+
+ addRule: function (key, rule) {
+ this.rules.add(key, rule);
+ return this
+ },
+
+ /**
+ * Keep a node (as HTML) that matches the filter
+ * @public
+ * @param {String|Array|Function} filter The unique key of the rule
+ * @returns The Turndown instance for chaining
+ * @type Object
+ */
+
+ keep: function (filter) {
+ this.rules.keep(filter);
+ return this
+ },
+
+ /**
+ * Remove a node that matches the filter
+ * @public
+ * @param {String|Array|Function} filter The unique key of the rule
+ * @returns The Turndown instance for chaining
+ * @type Object
+ */
+
+ remove: function (filter) {
+ this.rules.remove(filter);
+ return this
+ },
+
+ /**
+ * Escapes Markdown syntax
+ * @public
+ * @param {String} string The string to escape
+ * @returns A string with Markdown syntax escaped
+ * @type String
+ */
+
+ escape: function (string) {
+ return escapes.reduce(function (accumulator, escape) {
+ return accumulator.replace(escape[0], escape[1])
+ }, string)
+ }
+ };
+
+ /**
+ * Reduces a DOM node down to its Markdown string equivalent
+ * @private
+ * @param {HTMLElement} parentNode The node to convert
+ * @returns A Markdown representation of the node
+ * @type String
+ */
+
+ function process (parentNode) {
+ var self = this;
+ return reduce.call(parentNode.childNodes, function (output, node) {
+ node = new Node(node, self.options);
+
+ var replacement = '';
+ if (node.nodeType === 3) {
+ replacement = node.isCode ? node.nodeValue : self.escape(node.nodeValue);
+ } else if (node.nodeType === 1) {
+ replacement = replacementForNode.call(self, node);
+ }
+
+ return join(output, replacement)
+ }, '')
+ }
+
+ /**
+ * Appends strings as each rule requires and trims the output
+ * @private
+ * @param {String} output The conversion output
+ * @returns A trimmed version of the ouput
+ * @type String
+ */
+
+ function postProcess (output) {
+ var self = this;
+ this.rules.forEach(function (rule) {
+ if (typeof rule.append === 'function') {
+ output = join(output, rule.append(self.options));
+ }
+ });
+
+ return output.replace(/^[\t\r\n]+/, '').replace(/[\t\r\n\s]+$/, '')
+ }
+
+ /**
+ * Converts an element node to its Markdown equivalent
+ * @private
+ * @param {HTMLElement} node The node to convert
+ * @returns A Markdown representation of the node
+ * @type String
+ */
+
+ function replacementForNode (node) {
+ var rule = this.rules.forNode(node);
+ var content = process.call(this, node);
+ var whitespace = node.flankingWhitespace;
+ if (whitespace.leading || whitespace.trailing) content = content.trim();
+ return (
+ whitespace.leading +
+ rule.replacement(content, node, this.options) +
+ whitespace.trailing
+ )
+ }
+
+ /**
+ * Joins replacement to the current output with appropriate number of new lines
+ * @private
+ * @param {String} output The current conversion output
+ * @param {String} replacement The string to append to the output
+ * @returns Joined output
+ * @type String
+ */
+
+ function join (output, replacement) {
+ var s1 = trimTrailingNewlines(output);
+ var s2 = trimLeadingNewlines(replacement);
+ var nls = Math.max(output.length - s1.length, replacement.length - s2.length);
+ var separator = '\n\n'.substring(0, nls);
+
+ return s1 + separator + s2
+ }
+
+ /**
+ * Determines whether an input can be converted
+ * @private
+ * @param {String|HTMLElement} input Describe this parameter
+ * @returns Describe what it returns
+ * @type String|Object|Array|Boolean|Number
+ */
+
+ function canConvert (input) {
+ return (
+ input != null && (
+ typeof input === 'string' ||
+ (input.nodeType && (
+ input.nodeType === 1 || input.nodeType === 9 || input.nodeType === 11
+ ))
+ )
+ )
+ }
+
+ return TurndownService;
+
+})));
diff --git a/www/pad/export.js b/www/pad/export.js
index f1e3497c9..01ac27d7e 100644
--- a/www/pad/export.js
+++ b/www/pad/export.js
@@ -1,12 +1,24 @@
define([
'jquery',
'/common/common-util.js',
+ '/common/diffMarked.js',
+ '/common/hyperscript.js',
'/bower_components/hyperjson/hyperjson.js',
'/bower_components/nthen/index.js',
-], function ($, Util, Hyperjson, nThen) {
+ '/lib/turndown.browser.umd.js'
+], function ($, Util, DiffMd, h, Hyperjson, nThen, Turndown) {
var module = {
ext: '.html', // default
- exts: ['.html', '.doc']
+ exts: ['.html', '.md', '.doc']
+ };
+
+ module.importMd = function (md, common) {
+ var html = DiffMd.render(md, true, false, true);
+ var div = h('div#cp-temp');
+ DiffMd.apply(html, $(div), common);
+ var body = h('body');
+ body.innerHTML = div.innerHTML;
+ return body;
};
var exportMediaTags = function (inner, cb) {
@@ -77,6 +89,15 @@ define([
});
return void cb(blob);
}
+ if (ext === ".md") {
+ var md = Turndown({
+ headingStyle: 'atx'
+ }).turndown(toExport);
+ var mdBlob = new Blob([md], {
+ type: 'text/markdown;charset=utf-8'
+ });
+ return void cb(mdBlob);
+ }
var html = module.getHTML(toExport);
cb(new Blob([ html ], { type: "text/html;charset=utf-8" }));
});
diff --git a/www/pad/inner.js b/www/pad/inner.js
index 47ab5dbe3..304e9abe4 100644
--- a/www/pad/inner.js
+++ b/www/pad/inner.js
@@ -1115,7 +1115,7 @@ define([
framework._.sfCommon.isPadStored(function(err, val) {
if (!val) { return; }
- var b64images = $inner.find('img[src^="data:image"]:not(.cke_reset)');
+ var b64images = $inner.find('img[src^="data:image"]:not(.cke_reset), img[src^="data:application/octet-stream"]:not(.cke_reset)');
if (b64images.length && framework._.sfCommon.isLoggedIn()) {
var no = h('button.cp-corner-cancel', Messages.cancel);
var yes = h('button.cp-corner-primary', Messages.ok);
@@ -1169,7 +1169,14 @@ define([
});
cb($dom[0]);
};
- framework.setFileImporter({ accept: 'text/html' }, function(content, f, cb) {
+ framework.setFileImporter({ accept: ['.md', 'text/html'] }, function(content, f, cb) {
+ if (!f) { return; }
+ if (/\.md$/.test(f.name)) {
+ var mdDom = Exporter.importMd(content, framework._.sfCommon);
+ return importMediaTags(mdDom, function(dom) {
+ cb(Hyperjson.fromDOM(dom));
+ });
+ }
importMediaTags(domFromHTML(content).body, function(dom) {
cb(Hyperjson.fromDOM(dom));
});
@@ -1320,6 +1327,7 @@ define([
$(waitFor());
}).nThen(function(waitFor) {
Ckeditor.config.toolbarCanCollapse = true;
+ Ckeditor.config.language = Messages._getLanguage();
if (screen.height < 800) {
Ckeditor.config.toolbarStartupExpanded = false;
$('meta[name=viewport]').attr('content',
diff --git a/www/poll/inner.js b/www/poll/inner.js
index 6d4e0590e..53faea7e9 100644
--- a/www/poll/inner.js
+++ b/www/poll/inner.js
@@ -955,7 +955,7 @@ define([
var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey);
- var mt = '';
+ var mt = UI.mediaTag(src, key).outerHTML;
APP.editor.replaceSelection(mt);
}
};
@@ -1235,7 +1235,7 @@ define([
common.openFilePicker(pickerCfg, function (data) {
if (data.type === 'file' && APP.editor) {
common.setPadAttribute('atime', +new Date(), null, data.href);
- var mt = '';
+ var mt = UI.mediaTag(data.src, data.key).outerHTML;
APP.editor.replaceSelection(mt);
return;
}
diff --git a/www/register/main.js b/www/register/main.js
index 4c63e4482..4d9274253 100644
--- a/www/register/main.js
+++ b/www/register/main.js
@@ -47,7 +47,11 @@ define([
var I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME = false;
var registerClick = function () {
- var uname = $uname.val();
+ var uname = $uname.val().trim();
+ // trim whitespace surrounding the username since it is otherwise included in key derivation
+ // most people won't realize that its presence is significant
+ $uname.val(uname);
+
var passwd = $passwd.val();
var confirmPassword = $confirm.val();
diff --git a/www/slide/app-slide.less b/www/slide/app-slide.less
index 7e518a1c7..ce12b1de3 100644
--- a/www/slide/app-slide.less
+++ b/www/slide/app-slide.less
@@ -356,6 +356,7 @@
}
.markdown_main();
+ .markdown_cryptpad();
.markdown_preformatted-code;
.markdown_gfm-table();
diff --git a/www/slide/inner.js b/www/slide/inner.js
index 3eb1435ed..e40bd6d79 100644
--- a/www/slide/inner.js
+++ b/www/slide/inner.js
@@ -556,7 +556,7 @@ define([
var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(secret.channel);
var key = Hash.encodeBase64(secret.keys.cryptKey);
- var mt = '';
+ var mt = UI.mediaTag(src, key).outerHTML;
editor.replaceSelection(mt);
}
};
diff --git a/www/support/inner.js b/www/support/inner.js
index f466e7693..6d9e5eae8 100644
--- a/www/support/inner.js
+++ b/www/support/inner.js
@@ -272,19 +272,27 @@ define([
APP.$rightside = $('', {id: 'cp-sidebarlayout-rightside'}).appendTo(APP.$container);
var sFrameChan = common.getSframeChannel();
sFrameChan.onReady(waitFor());
+ }).nThen(function (waitFor) {
+ metadataMgr = common.getMetadataMgr();
+ privateData = metadataMgr.getPrivateData();
common.getPinUsage(null, waitFor(function (err, data) {
if (err) { return void console.error(err); }
APP.pinUsage = data;
}));
+ APP.teamsUsage = {};
+ Object.keys(privateData.teams).forEach(function (teamId) {
+ common.getPinUsage(teamId, waitFor(function (err, data) {
+ if (err) { return void console.error(err); }
+ APP.teamsUsage[teamId] = data;
+ }));
+ });
}).nThen(function (/*waitFor*/) {
createToolbar();
- metadataMgr = common.getMetadataMgr();
- privateData = metadataMgr.getPrivateData();
common.setTabTitle(Messages.supportPage);
APP.origin = privateData.origin;
APP.readOnly = privateData.readOnly;
- APP.support = Support.create(common, false, APP.pinUsage);
+ APP.support = Support.create(common, false, APP.pinUsage, APP.teamsUsage);
// Content
var $rightside = APP.$rightside;
diff --git a/www/support/ui.js b/www/support/ui.js
index 679776c59..90fd43fa5 100644
--- a/www/support/ui.js
+++ b/www/support/ui.js
@@ -31,9 +31,7 @@ define([
if (typeof(ctx.pinUsage) === 'object') {
// pass pin.usage, pin.limit, and pin.plan if supplied
- Object.keys(ctx.pinUsage).forEach(function (k) {
- data.sender[k] = ctx.pinUsage[k];
- });
+ data.sender.quota = ctx.pinUsage;
}
data.id = id;
@@ -45,11 +43,14 @@ define([
data.sender.blockLocation = privateData.blockLocation || '';
data.sender.teams = Object.keys(teams).map(function (key) {
var team = teams[key];
- if (!teams) { return; }
+ if (!team) { return; }
var ret = {};
- ['edPublic', 'owner', 'viewer', 'hasSecondaryKey', 'validKeys'].forEach(function (k) {
+ ['channel', 'roster', 'numberPads', 'numberSf', 'edPublic', 'curvePublic', 'owner', 'viewer', 'hasSecondaryKey', 'validKeys'].forEach(function (k) {
ret[k] = team[k];
});
+ if (ctx.teamsUsage && ctx.teamsUsage[key]) {
+ ret.quota = ctx.teamsUsage[key];
+ }
return ret;
}).filter(Boolean);
@@ -430,12 +431,13 @@ define([
]);
};
- var create = function (common, isAdmin, pinUsage) {
+ var create = function (common, isAdmin, pinUsage, teamsUsage) {
var ui = {};
var ctx = {
common: common,
isAdmin: isAdmin,
pinUsage: pinUsage || false,
+ teamsUsage: teamsUsage || false,
adminKeys: Array.isArray(ApiConfig.adminKeys)? ApiConfig.adminKeys.slice(): [],
};
diff --git a/www/teams/inner.js b/www/teams/inner.js
index 4b0532628..373a27998 100644
--- a/www/teams/inner.js
+++ b/www/teams/inner.js
@@ -768,7 +768,7 @@ define([
$(demote).hide();
describeUser(common, data.curvePublic, {
role: role
- }, promote);
+ }, demote);
};
if (isMe) {
return void UI.confirm(Messages.team_demoteMeConfirm, function (yes) {
@@ -901,22 +901,23 @@ define([
$header.append(invite);
}
- if (me && (me.role !== 'OWNER')) {
- var leave = h('button.cp-online.btn.btn-danger', Messages.team_leaveButton);
- $(leave).click(function () {
- UI.confirm(Messages.team_leaveConfirm, function (yes) {
- if (!yes) { return; }
- APP.module.execCommand('LEAVE_TEAM', {
- teamId: APP.team
- }, function (obj) {
- if (obj && obj.error) {
- return void UI.warn(Messages.error);
- }
- });
+ var leave = h('button.cp-online.btn.btn-danger', Messages.team_leaveButton);
+ $(leave).click(function () {
+ if (me && me.role === 'OWNER') {
+ return void UI.alert(Messages.team_leaveOwner);
+ }
+ UI.confirm(Messages.team_leaveConfirm, function (yes) {
+ if (!yes) { return; }
+ APP.module.execCommand('LEAVE_TEAM', {
+ teamId: APP.team
+ }, function (obj) {
+ if (obj && obj.error) {
+ return void UI.warn(Messages.error);
+ }
});
});
- $header.append(leave);
- }
+ });
+ $header.append(leave);
var table = h('button.btn.btn-primary', Messages.teams_table);
$(table).click(function (e) {