#1261: avoid duplicate code
This commit is contained in:
parent
ef694294ee
commit
c15fd8878e
1 changed files with 15 additions and 25 deletions
|
@ -4514,6 +4514,19 @@ define([
|
|||
$('.cp-toolbar-icon-snapshots').hide();
|
||||
}
|
||||
|
||||
var initializeAnswers = function() {
|
||||
// Initialize the answers channel if it doesn't exist yet
|
||||
if (!APP.isEditor) { return; }
|
||||
if (content.answers && content.answers.channel && content.answers.publicKey && content.answers.validateKey) { return; }
|
||||
// Don't override other settings (anonymous, makeAnonymous, etc.) from templates
|
||||
content.answers = content.answers || {};
|
||||
content.answers.channel = Hash.createChannelId();
|
||||
content.answers.publicKey = priv.form_public;
|
||||
content.answers.validateKey = priv.form_answerValidateKey;
|
||||
content.answers.version = 2;
|
||||
framework.localChange();
|
||||
}
|
||||
|
||||
var makeFormSettings = function () {
|
||||
var previewBtn = h('button.btn.btn-primary', [
|
||||
h('i.fa.fa-eye'),
|
||||
|
@ -4534,21 +4547,6 @@ define([
|
|||
});
|
||||
});
|
||||
|
||||
// Perform a sanity check on refresh (for instance on template imports)
|
||||
var checkAnswersValidity = function() {
|
||||
if (APP.isEditor) {
|
||||
if (!content.answers || !content.answers.channel || !content.answers.publicKey || !content.answers.validateKey) {
|
||||
// Don't override other settings (anonymous, makeAnonymous, etc.) from templates
|
||||
content.answers = content.answers || {};
|
||||
content.answers.channel = Hash.createChannelId();
|
||||
content.answers.publicKey = priv.form_public;
|
||||
content.answers.validateKey = priv.form_answerValidateKey;
|
||||
content.answers.version = 2;
|
||||
framework.localChange();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Private / public status
|
||||
var resultsType = h('div.cp-form-results-type-container');
|
||||
var resultsStr = h('div');
|
||||
|
@ -4884,7 +4882,7 @@ define([
|
|||
};
|
||||
refreshColorTheme();
|
||||
|
||||
evOnChange.reg(checkAnswersValidity);
|
||||
evOnChange.reg(initializeAnswers);
|
||||
evOnChange.reg(refreshPublic);
|
||||
evOnChange.reg(refreshPrivacy);
|
||||
evOnChange.reg(refreshAnon);
|
||||
|
@ -5152,15 +5150,7 @@ define([
|
|||
content.order = ["1", "2"];
|
||||
framework.localChange();
|
||||
}
|
||||
if (!content.answers || !content.answers.channel || !content.answers.publicKey || !content.answers.validateKey) {
|
||||
// Don't override other settings (anonymous, makeAnonymous, etc.) from templates
|
||||
content.answers = content.answers || {};
|
||||
content.answers.channel = Hash.createChannelId();
|
||||
content.answers.publicKey = priv.form_public;
|
||||
content.answers.validateKey = priv.form_answerValidateKey;
|
||||
content.answers.version = 2;
|
||||
framework.localChange();
|
||||
}
|
||||
initializeAnswers();
|
||||
checkIntegrity();
|
||||
}
|
||||
if (isNew && content.answers && typeof(content.answers.anonymous) === "undefined") {
|
||||
|
|
Loading…
Reference in a new issue