Skip to content

Commit

Permalink
disabled parameter listeners during acceptance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
AlNedorezov committed Jul 28, 2017
1 parent 743c4a6 commit 642f54e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 39 deletions.
72 changes: 37 additions & 35 deletions front/js/app/dom_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var selectDefaultParameters = [];

// Generate HTML code for classes and parameters described in json/classesandparameters.json
// Adds this HTML code to div with id="classes-and-parameters" in main.html
function generateHTMLCodeForClassesAndParameters(dom, phrase) {
function generateHTMLCodeForClassesAndParameters(dom, phrase, acceptMode=false) {

// alert(phrase);
let jsonResponse = JSON.parse(phrase);
Expand Down Expand Up @@ -108,41 +108,43 @@ function generateHTMLCodeForClassesAndParameters(dom, phrase) {

dom.getElementById("classes-and-parameters").innerHTML += html;

/*global onObjectClassUpdate*/
/*eslint no-undef: "error"*/
let classParams = document.getElementsByClassName("class-param");
Array.prototype.forEach.call(classParams, param => {
param.addEventListener("change", function () {
onObjectClassUpdate(param.value);
}, false);
});
if(!acceptMode) {
/*global onObjectClassUpdate*/
/*eslint no-undef: "error"*/
let classParams = document.getElementsByClassName("class-param");
Array.prototype.forEach.call(classParams, param => {
param.addEventListener("change", function () {
onObjectClassUpdate(param.value);
}, false);
});

/*global onBoolParamUpdate*/
/*eslint no-undef: "error"*/
let boolParams = document.getElementsByClassName("bool-param");
Array.prototype.forEach.call(boolParams, param => {
param.addEventListener("click", function () {
onBoolParamUpdate(param.name, param.checked);
}, false);
});
/*global onBoolParamUpdate*/
/*eslint no-undef: "error"*/
let boolParams = document.getElementsByClassName("bool-param");
Array.prototype.forEach.call(boolParams, param => {
param.addEventListener("click", function () {
onBoolParamUpdate(param.name, param.checked);
}, false);
});

/*global onStringParamUpdate*/
/*eslint no-undef: "error"*/
let stringParams = document.getElementsByClassName("string-param");
Array.prototype.forEach.call(stringParams, param => {
param.addEventListener("change", function () {
onStringParamUpdate(param.placeholder, param.value);
}, false);
});
/*global onStringParamUpdate*/
/*eslint no-undef: "error"*/
let stringParams = document.getElementsByClassName("string-param");
Array.prototype.forEach.call(stringParams, param => {
param.addEventListener("change", function () {
onStringParamUpdate(param.placeholder, param.value);
}, false);
});

/*global onSelectParamUpdate*/
/*eslint no-undef: "error"*/
let selectParams = document.getElementsByClassName("select-param");
Array.prototype.forEach.call(selectParams, param => {
param.addEventListener("change", function () {
onSelectParamUpdate(param.name, param.value);
}, false);
});
/*global onSelectParamUpdate*/
/*eslint no-undef: "error"*/
let selectParams = document.getElementsByClassName("select-param");
Array.prototype.forEach.call(selectParams, param => {
param.addEventListener("change", function () {
onSelectParamUpdate(param.name, param.value);
}, false);
});
}
}

/**
Expand Down Expand Up @@ -235,15 +237,15 @@ function replaceAll(str, find, replace) {
return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}

function initDOM() {
function initDOM(acceptMode) {
let jsonParams = document.getElementById("json_params").innerText;
// Toloka strips all strings of double quotes for reasons unknown so in order
// to get JSON.parse to work we need to replace all occurence of \ with "
// otherwise JSON.parse will fail. Need to clarify this with Y.T. manager,
// but until then this does the job

jsonParams = replaceAll(jsonParams, '\\', '"');
generateHTMLCodeForClassesAndParameters(document, jsonParams);
generateHTMLCodeForClassesAndParameters(document, jsonParams, acceptMode);
initRowsAdditionAndDeletion();
initColorScheme(jsonParams);
}
Expand Down
5 changes: 4 additions & 1 deletion front/js/app/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,22 @@ function initToolbar(acceptMode) {
/*eslint no-undef: "error"*/
initBrightness();
if (acceptMode) {
console.log("accept mode");
makeVisibleOrHideAnElementById(btnHand.id, true); // make a hand tool visible
makeVisibleOrHideAnElementById(btnPolygon.id, false); // make a polygon tool hidden
enableOrDisableAnElementById(btnHand.id, true); // make a hand tool enabled
enableOrDisableAnElementById(btnPolygon.id, false); // make a polygon tool disabled
changeButtonsSelectionState(btnHand); // hand tool is selected by default
activeTool = Tool.hand();
} else {
console.log("markup mode");
makeVisibleOrHideAnElementById(btnPolygon.id, true); // make a polygon tool visible
makeVisibleOrHideAnElementById(btnHand.id, false); // make a hand tool hidden
enableOrDisableAnElementById(btnPolygon.id, true); // make a polygon tool enabled
enableOrDisableAnElementById(btnHand.id, false); // make a hand tool disabled
changeButtonsSelectionState(btnPolygon); // polygon tool is selected by default
activeTool = Tool.polygon();
}

activeTool = Tool.polygon();
activeTool.onClick(true);
}
4 changes: 2 additions & 2 deletions front/js/toloka.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ exports.Task = extend(TolokaHandlebarsTask, function (options) {
}, {
onRender: function () {
$(document).ready(function () {
var acceptMode = document.referrer.includes("status=SUBMITTED");
let acceptMode = document.referrer.includes("status=SUBMITTED");

initDOM();
initDOM(acceptMode);
initMultiLanguageSupport();
initPresentationLayer(acceptMode);
initToolbar(acceptMode);
Expand Down
2 changes: 1 addition & 1 deletion front/main_local.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ <h3 class="panel-title">History</h3>
</div>
</div>
<script>
initDOM();
initDOM(false);
initPresentationLayer(false);
initToolbar(false);
initMultiLanguageSupport();
Expand Down

0 comments on commit 642f54e

Please sign in to comment.