@@ -190,13 +190,8 @@ function handleVoteSubmitted(json, tr, theRow, button, valToShow) {
190190 button . className = "ichoice-o" ;
191191 button . checked = false ;
192192 cldrSurvey . hideLoader ( ) ;
193- if ( json . testResults && ( json . testWarnings || json . testErrors ) ) {
194- // Tried to submit, have errs or warnings.
195- // Caution: even though json is defined, it is NOT used here as the 5th argument
196- // for showProposedItem, which apparently depends on the 5th argument being
197- // undefined when called from here (handleVoteSubmitted), and only defined
198- // when called from handleVoteNotSubmitted.
199- showProposedItem ( tr , theRow , valToShow , json . testResults ) ;
193+ if ( json . testResults && ( json . hasTestWarnings || json . hasTestErrors ) ) {
194+ showProposedItem ( tr , theRow , valToShow , json ) ;
200195 }
201196 if ( CLDR_VOTE_DEBUG ) {
202197 console . log (
@@ -217,9 +212,9 @@ function handleVoteSubmitted(json, tr, theRow, button, valToShow) {
217212function handleVoteNotSubmitted ( json , tr , theRow , button , valToShow ) {
218213 if (
219214 ( json . statusAction && json . statusAction != "ALLOW" ) ||
220- ( json . testResults && ( json . testWarnings || json . testErrors ) )
215+ ( json . testResults && ( json . hasTestWarnings || json . hasTestErrors ) )
221216 ) {
222- showProposedItem ( tr , theRow , valToShow , json . testResults , json ) ;
217+ showVoteNotSubmitted ( tr , theRow , valToShow , json ) ;
223218 }
224219 button . className = "ichoice-o" ;
225220 button . checked = false ;
@@ -270,67 +265,64 @@ function getSubmitUrl(xpstrid) {
270265 return cldrAjax . makeApiUrl ( api , null ) ;
271266}
272267
273- /**
274- * Show an item that's not in the saved data, but has been proposed newly by the user.
275- * Used for "+" button in table.
276- *
277- * Caution: if called from handleVoteSubmitted, the fifth argument (json) is undefined
278- * (even though there is json from the server response), and that appears to be necessary
279- * for this function to work right, as it stands. The fifth argument (json) is only defined
280- * when called from handleVoteNotSubmitted. This function cries out to be thoroughly refactored,
281- * but that may only be feasible in conjunction with a thorough analysis or refactoring of the
282- * back end.
283- */
284- function showProposedItem ( tr , theRow , value , tests , json ) {
268+ function showVoteNotSubmitted ( tr , theRow , value , json ) {
269+ if ( ! cldrSurvey . parseStatusAction ( json . statusAction ) . vote ) {
270+ showVoteNotAllowed ( theRow , value , json ) ;
271+ } else if ( json . reasonNotSubmitted ) {
272+ const description = "Did not submit this value: " + json . reasonNotSubmitted ;
273+ cldrNotify . error ( "Not submitted" , description ) ;
274+ } else {
275+ showProposedItem ( tr , theRow , value , json ) ;
276+ }
277+ }
278+
279+ function showVoteNotAllowed ( theRow , value , json ) {
285280 const ourItem = cldrSurvey . findItemByValue ( theRow . items , value ) ;
286- if ( json && ! cldrSurvey . parseStatusAction ( json . statusAction ) . vote ) {
287- const replaceErrors =
288- json . statusAction === "FORBID_PERMANENT_WITHOUT_FORUM" ;
289- if ( replaceErrors ) {
290- /*
291- * Special case: for clarity, replace any warnings/errors that may be
292- * in tests[] with a single error message for this situation.
293- */
294- tests = [
295- {
296- type : "Error" ,
297- message : cldrText . get ( "StatusAction_" + json . statusAction ) ,
298- } ,
299- ] ;
300- }
281+ const replaceErrors = json . statusAction === "FORBID_PERMANENT_WITHOUT_FORUM" ;
282+ let tests = json . testResults ;
283+ if ( replaceErrors ) {
284+ /*
285+ * Special case: for clarity, replace any warnings/errors that may be
286+ * in tests[] with a single error message for this situation.
287+ */
288+ tests = [
289+ {
290+ type : "Error" ,
291+ message : cldrText . get ( "StatusAction_" + json . statusAction ) ,
292+ } ,
293+ ] ;
294+ }
301295
302- const valueMessage = value === "" ? "Abstention" : "Value: " + value ;
296+ const valueMessage = value === "" ? "Abstention" : "Value: " + value ;
303297
304- // TODO: modernize to obviate cldrSurvey.testsToHtml
305- // Reference: https://unicode-org.atlassian.net/browse/CLDR-18013
306- const testDescription = cldrSurvey . testsToHtml ( tests ) ;
307- if ( ourItem || ( replaceErrors && value === "" ) /* Abstain */ ) {
308- const statusAction = cldrText . get ( "StatusAction_" + json . statusAction ) ;
309- const message = cldrText . sub ( "StatusAction_msg" , [ statusAction ] ) ;
310- /*
311- * This may happen if, for example, the user types a space (" ") in
312- * the input pop-up window and presses Enter. The value has been rejected
313- * by the server. Then we show an additional pop-up window with the error message
314- * from the server like "Input Processor Error: DAIP returned a 0 length string"
315- */
316- const statusMessage = cldrText . sub ( "StatusAction_popupmsg" , [
317- statusAction ,
318- theRow . code ,
319- ] ) ;
320- const description =
321- valueMessage + "<br>" + statusMessage + " " + testDescription ;
322- cldrNotify . openWithHtml ( message , description ) ;
323- } else {
324- const description = valueMessage + "<br>" + testDescription ;
325- cldrNotify . openWithHtml ( "Response to voting" , description ) ;
326- }
327- return ;
328- } else if ( json ?. didNotSubmit ) {
329- const description = "Did not submit this value: " + json . didNotSubmit ;
330- cldrNotify . error ( "Not submitted" , description ) ;
331- return ;
298+ // TODO: modernize to obviate cldrSurvey.testsToHtml
299+ // Reference: https://unicode-org.atlassian.net/browse/CLDR-18013
300+ const testDescription = cldrSurvey . testsToHtml ( tests ) ;
301+ if ( ourItem || ( replaceErrors && value === "" ) /* Abstain */ ) {
302+ const statusAction = cldrText . get ( "StatusAction_" + json . statusAction ) ;
303+ const message = cldrText . sub ( "StatusAction_msg" , [ statusAction ] ) ;
304+ /*
305+ * This may happen if, for example, the user types a space (" ") in
306+ * the input pop-up window and presses Enter. The value has been rejected
307+ * by the server. Then we show an additional pop-up window with the error message
308+ * from the server like "Input Processor Error: DAIP returned a 0 length string"
309+ */
310+ const statusMessage = cldrText . sub ( "StatusAction_popupmsg" , [
311+ statusAction ,
312+ theRow . code ,
313+ ] ) ;
314+ const description =
315+ valueMessage + "<br>" + statusMessage + " " + testDescription ;
316+ cldrNotify . openWithHtml ( message , description ) ;
317+ } else {
318+ const description = valueMessage + "<br>" + testDescription ;
319+ cldrNotify . openWithHtml ( "Vote not allowed" , description ) ;
332320 }
333- // Note: it is possible to arrive here (as of 2025-09), for example, if the vote was accepted but has warnings
321+ }
322+
323+ function showProposedItem ( tr , theRow , value , json ) {
324+ const tests = json . testResults ;
325+ const ourItem = cldrSurvey . findItemByValue ( theRow . items , value ) ;
334326 const ourDiv = ourItem ? ourItem . div : document . createElement ( "div" ) ;
335327 const testKind = getTestKind ( tests ) ;
336328 cldrTable . setDivClassSelected ( ourDiv , testKind ) ;
@@ -345,7 +337,7 @@ function showProposedItem(tr, theRow, value, tests, json) {
345337 const newDiv = document . createElement ( "div" ) ;
346338 div3 . appendChild ( newDiv ) ;
347339 newDiv . innerHTML = cldrSurvey . testsToHtml ( tests ) ;
348- if ( json && ! parseStatusAction ( json . statusAction ) . vote ) {
340+ if ( ! json . didVote && ! parseStatusAction ( json . statusAction ) . vote ) {
349341 const text = cldrText . sub ( "StatusAction_msg" , [
350342 cldrText . get ( "StatusAction_" + json . statusAction ) ,
351343 ] ) ;
0 commit comments