From 6694d9df03d49c23b7e41442b8e6e0bdf1c1bcdb Mon Sep 17 00:00:00 2001 From: yflory Date: Fri, 28 May 2021 14:13:16 +0200 Subject: [PATCH] lint compliance --- www/common/common-interface.js | 9 +++--- www/common/cryptpad-common.js | 2 +- www/form/inner.js | 50 ++++++++++++++++------------------ www/form/main.js | 22 +++++---------- 4 files changed, 36 insertions(+), 47 deletions(-) diff --git a/www/common/common-interface.js b/www/common/common-interface.js index 4166c0902..9bdf9ec7a 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -1223,6 +1223,7 @@ define([ $.extend(markOpts, opts.mark || {}); var input = h('input', inputOpts); + var $input = $(input); var mark = h('span.cp-radio-mark', markOpts); var label = h('span.cp-checkmark-label', labelTxt); @@ -1231,13 +1232,13 @@ define([ if (e.which === 32) { e.stopPropagation(); e.preventDefault(); - if ($(input).is(':checked')) { return; } - $(input).prop('checked', !$(input).is(':checked')); - $(input).change(); + if ($input.is(':checked')) { return; } + $input.prop('checked', !$input.is(':checked')); + $input.change(); } }); - $(input).change(function () { $(mark).focus(); }); + $input.change(function () { $(mark).focus(); }); var radio = h('label', labelOpts, [ input, diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 973a27d6b..69ed47587 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -69,7 +69,7 @@ define([ }, cb); }; - common.getAccessKeys = function (cb, opts) { + common.getAccessKeys = function (cb) { var keys = []; Nthen(function (waitFor) { // Push account keys diff --git a/www/form/inner.js b/www/form/inner.js index 4dbe64df8..48a4bae93 100644 --- a/www/form/inner.js +++ b/www/form/inner.js @@ -23,7 +23,6 @@ define([ '/lib/datepicker/flatpickr.js', '/bower_components/sortablejs/Sortable.min.js', - '/bower_components/file-saver/FileSaver.min.js', 'css!/lib/datepicker/flatpickr.min.css', 'css!/bower_components/components-font-awesome/css/font-awesome.min.css', 'less!/form/app-form.less', @@ -49,12 +48,10 @@ define([ Sortable ) { - var SaveAs = window.saveAs; var APP = window.APP = { }; var is24h = false; - var dayFormat = "Y-m-d"; var dateFormat = "Y-m-d H:i"; try { is24h = !new Intl.DateTimeFormat(navigator.language, { hour: 'numeric' }).format(0).match(/AM/); @@ -142,7 +139,7 @@ define([ value: v.max, min: 1, max: v.values.length - }) + }); maxOptions = h('div.cp-form-edit-max-options', [ h('span', Messages.form_editMax), maxInput @@ -181,7 +178,7 @@ define([ } // Show existing options - var $add; + var $add, $addItem; var getOption = function (val, isItem, uid) { var input = h('input', {value:val}); if (uid) { $(input).data('uid', uid); } @@ -393,7 +390,7 @@ define([ var makePollTable = function (answers, opts) { // Create first line with options - var els = opts.values.map(function (data, i) { + var els = opts.values.map(function (data) { if (opts.type === "day") { var _date = new Date(data); data = _date.toLocaleDateString(); @@ -451,6 +448,15 @@ define([ return res; }; + var getBlockAnswers = function (answers, uid, filterCurve) { + return Object.keys(answers || {}).map(function (user) { + if (filterCurve && user === filterCurve) { return; } + try { + return answers[user].msg[uid]; + } catch (e) { console.error(e); } + }).filter(Boolean); + }; + var TYPES = { input: { get: function () { @@ -501,7 +507,7 @@ define([ tag: tag, getValue: function () { var res; - els.some(function (el, i) { + els.some(function (el) { var $i = $(el).find('input'); if (Util.isChecked($i)) { res = $i.data('val'); @@ -592,10 +598,10 @@ define([ getValue: function () { var res = {}; var l = lines.slice(1); - l.forEach(function (el, i) { + l.forEach(function (el) { var $el = $(el); var uid = $el.attr('data-uid'); - var $l = $el.find('input').each(function (i, input) { + $el.find('input').each(function (i, input) { var $i = $(input); if (res[uid]) { return; } if (Util.isChecked($i)) { res[uid] = $i.data('val'); } @@ -696,7 +702,7 @@ define([ tag: tag, getValue: function () { var res = []; - els.forEach(function (el, i) { + els.forEach(function (el) { var $i = $(el).find('input'); if (Util.isChecked($i)) { res.push($i.data('val')); @@ -801,11 +807,11 @@ define([ getValue: function () { var res = {}; var l = lines.slice(1); - l.forEach(function (el, i) { + l.forEach(function (el) { var $el = $(el); var uid = $el.attr('data-uid'); res[uid] = []; - var $l = $el.find('input').each(function (i, input) { + $el.find('input').each(function (i, input) { var $i = $(input); if (Util.isChecked($i)) { res[uid].push($i.data('val')); } }); @@ -881,13 +887,12 @@ define([ get: function (opts, answers, username) { if (!opts) { opts = TYPES.poll.defaultOpts; } if (!Array.isArray(opts.values)) { return; } - var name = Util.uid(); var lines = makePollTable(answers, opts); // Add form // XXX only if not already answered! - var addLine = opts.values.map(function (data, i) { + var addLine = opts.values.map(function (data) { var cell = h('div.cp-poll-cell.cp-form-poll-choice', [ h('i.fa.fa-times.cp-no'), h('i.fa.fa-check.cp-yes'), @@ -989,14 +994,6 @@ define([ $container.append(elements); }; - var getBlockAnswers = function (answers, uid, filterCurve) { - return Object.keys(answers || {}).map(function (user) { - if (filterCurve && user === filterCurve) { return; } - try { - return answers[user].msg[uid]; - } catch (e) { console.error(e); } - }).filter(Boolean); - }; var getFormResults = function () { if (!Array.isArray(APP.formBlocks)) { return; } var results = {}; @@ -1034,8 +1031,9 @@ define([ }); }); + var viewResults; if (content.answers.privateKey) { - var viewResults = h('button.btn.btn-primary', [ + viewResults = h('button.btn.btn-primary', [ h('span.cp-app-form-button-results', Messages.form_viewResults), ]); var sframeChan = framework._.sfCommon.getSframeChannel(); @@ -1181,7 +1179,7 @@ define([ $(editButtons).show(); UI.log(Messages.saved); var _answers = getBlockAnswers(APP.answers, uid); - data = model.get(newOpts, answers); + data = model.get(newOpts, _answers); if (!data) { data = {}; } $oldTag.before(data.tag).remove(); }); @@ -1306,8 +1304,6 @@ define([ if (endDate <= now) { text = Messages._getKey('form_isClosed', [date]); buttonTxt = Messages.form_open; - action = function () { - }; } else if (endDate > now) { text = Messages._getKey('form_willClose', [date]); buttonTxt = Messages.form_removeEnd; @@ -1481,7 +1477,7 @@ define([ } }; - framework.onReady(function (isNew) { + framework.onReady(function () { var priv = metadataMgr.getPrivateData(); if (APP.isEditor) { diff --git a/www/form/main.js b/www/form/main.js index c02921887..27e6552de 100644 --- a/www/form/main.js +++ b/www/form/main.js @@ -8,6 +8,7 @@ define([ ], function (nThen, ApiConfig, DomReady, SFCommonO) { var Nacl = window.nacl; + var href, hash; // Loaded in load #2 nThen(function (waitFor) { DomReady.onReady(waitFor()); @@ -44,8 +45,8 @@ define([ channel: Utils.secret.channel, keys: { viewKeyStr: Nacl.util.encodeBase64(keys.cryptKey) } }); - var parsed = Utils.Hash.parseTypeHash('pad', auditorHash); - meta.form_auditorHash = parsed.getHash({auditorKey: privateKey}); + var _parsed = Utils.Hash.parseTypeHash('pad', auditorHash); + meta.form_auditorHash = _parsed.getHash({auditorKey: privateKey}); }; var addRpc = function (sframeChan, Cryptpad, Utils) { @@ -67,7 +68,7 @@ define([ nThen(function (w) { require([ '/bower_components/chainpad-netflux/chainpad-netflux.js', - ], w(function (_CPNetflux, _Crypto) { + ], w(function (_CPNetflux) { CPNetflux = _CPNetflux; })); Cryptpad.getAccessKeys(w(function (_keys) { @@ -83,7 +84,7 @@ define([ Cryptpad.makeNetwork(w(function (err, nw) { network = nw; })); - }).nThen(function (w) { + }).nThen(function () { if (!network) { return void cb({error: "E_CONNECT"}); } var keys = Utils.secret && Utils.secret.keys; @@ -120,9 +121,6 @@ define([ }); }); sframeChan.on("Q_FETCH_MY_ANSWERS", function (data, cb) { - var keys; - var CPNetflux; - var network; var answer; var myKeys; nThen(function (w) { @@ -136,7 +134,7 @@ define([ } answer = obj; })); - }).nThen(function (w) { + }).nThen(function () { Cryptpad.getHistoryRange({ channel: data.channel, lastKnownHash: answer.hash, @@ -144,7 +142,6 @@ define([ }, function (obj) { if (obj && obj.error) { return void cb(obj); } var messages = obj.messages; - var ephemeral_priv = answer.curvePrivate; var res = Utils.Crypto.Mailbox.openOwnSecretLetter(messages[0].msg, { validateKey: data.validateKey, ephemeral_private: Nacl.util.decodeBase64(answer.curvePrivate), @@ -164,7 +161,7 @@ define([ Cryptpad.getFormKeys(w(function (keys) { myKeys = keys; })); - }).nThen(function (w) { + }).nThen(function () { var keys = Utils.secret && Utils.secret.keys; myKeys.signingKey = keys.secondarySignKey; @@ -191,11 +188,6 @@ define([ }); }); }); - sframeChan.on('EV_FORM_MAILBOX', function (data) { - var curvePair = Nacl.box.keyPair(); - publicKey = Nacl.util.encodeBase64(curvePair.publicKey); - privateKey = Nacl.util.encodeBase64(curvePair.secretKey); - }); }; SFCommonO.start({ addData: addData,