From 642f54efb10d39d88117d01f5008b981c9bd5d89 Mon Sep 17 00:00:00 2001 From: Aleksandr Nedorezov Date: Fri, 28 Jul 2017 16:35:08 +0300 Subject: [PATCH] disabled parameter listeners during acceptance mode --- front/js/app/dom_manager.js | 72 +++++++++++++++++++------------------ front/js/app/toolbar.js | 5 ++- front/js/toloka.js | 4 +-- front/main_local.html | 2 +- 4 files changed, 44 insertions(+), 39 deletions(-) diff --git a/front/js/app/dom_manager.js b/front/js/app/dom_manager.js index defcd85..fea0db1 100644 --- a/front/js/app/dom_manager.js +++ b/front/js/app/dom_manager.js @@ -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); @@ -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); + }); + } } /** @@ -235,7 +237,7 @@ 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 " @@ -243,7 +245,7 @@ function initDOM() { // but until then this does the job jsonParams = replaceAll(jsonParams, '\\', '"'); - generateHTMLCodeForClassesAndParameters(document, jsonParams); + generateHTMLCodeForClassesAndParameters(document, jsonParams, acceptMode); initRowsAdditionAndDeletion(); initColorScheme(jsonParams); } diff --git a/front/js/app/toolbar.js b/front/js/app/toolbar.js index 2b28b6c..7f550df 100644 --- a/front/js/app/toolbar.js +++ b/front/js/app/toolbar.js @@ -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); } diff --git a/front/js/toloka.js b/front/js/toloka.js index ece1185..743803d 100644 --- a/front/js/toloka.js +++ b/front/js/toloka.js @@ -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); diff --git a/front/main_local.html b/front/main_local.html index 702d578..e7c6f9f 100644 --- a/front/main_local.html +++ b/front/main_local.html @@ -209,7 +209,7 @@

History