Changeset 1108 for trunk


Ignore:
Timestamp:
03/15/10 01:12:37 (2 years ago)
Author:
bogdan2412
Message:

Fix "undefined" showing up as a round when submitting.

Ran JSLint on the submit.js script and fixed what was suggested there.
We should probably do this on all js files.

The problem was caused by the for (var key in rounds) loop which
iterated through properties from the "rounds" object's prototype.
Was fixed by adding a if (rounds.hasOwnProperty(key)).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/static/js/submit.js

    r1036 r1108  
    55 
    66var Submit_CompilerDisplay; 
    7  
    8 function Submit_Init() { 
    9     if (!$('task_submit')) { 
    10         // no such form on this page 
    11         return; 
    12     } 
    13  
    14     var fSolution = $('form_solution'); 
    15     var fTask = $('form_task'); 
    16  
    17     Submit_CompilerDisplay = $('field_compiler').style.display; 
    18     Submit_RoundDisplay = $('field_round').style.display; 
    19  
    20     connect(fSolution, 'onchange', Submit_UpdateSolution); 
    21     if ('hidden' != fTask.type) { 
    22         connect(fTask, 'onchange', Submit_UpdateTask); 
    23     } 
    24  
    25     Submit_UpdateTask(); 
    26 } 
    277 
    288function Submit_HasCompiler(taskId) { 
     
    5434    } 
    5535    else { 
    56         alert('Atentie! Pentru fisierul selectat nu am putut alege automat '  
    57               + 'un compilator.'); 
     36        alert('Atentie! Pentru fisierul selectat nu am putut alege automat ' + 
     37            'un compilator.'); 
    5838        compiler.value = '-'; 
    5939    } 
     
    9777                } 
    9878            } 
    99             for (key in rounds) { 
    100                 var option = document.createElement("option"); 
    101                 option.value = rounds[key]["id"]; 
    102                 if (rounds[key]["id"] == default_round) { 
    103                     option.selected = "selected"; 
     79            for (var key in rounds) { 
     80                if (rounds.hasOwnProperty(key)) { 
     81                    var option = document.createElement('option'); 
     82                    option.value = rounds[key]["id"]; 
     83                    if (rounds[key]["id"] == default_round) { 
     84                        option.selected = 'selected'; 
     85                    } 
     86                    var text = document.createTextNode(rounds[key]["title"]); 
     87                    option.appendChild(text); 
     88                    $('form_round').appendChild(option); 
    10489                } 
    105                 var text = document.createTextNode(rounds[key]["title"]) 
    106                 option.appendChild(text); 
    107                 $('form_round').appendChild(option); 
    10890            } 
    109         } 
     91        }; 
    11092 
    11193        var error = function(error) { 
    11294            window.alert('Eroare! Nu pot determina rundele. Incercati din nou.'); 
    113         } 
     95        }; 
    11496 
    11597        d.addCallbacks(ready, error); 
     
    124106} 
    125107 
     108function Submit_Init() { 
     109    if (!$('task_submit')) { 
     110        // no such form on this page 
     111        return; 
     112    } 
     113 
     114    var fSolution = $('form_solution'); 
     115    var fTask = $('form_task'); 
     116 
     117    Submit_CompilerDisplay = $('field_compiler').style.display; 
     118    Submit_RoundDisplay = $('field_round').style.display; 
     119 
     120    connect(fSolution, 'onchange', Submit_UpdateSolution); 
     121    if ('hidden' != fTask.type) { 
     122        connect(fTask, 'onchange', Submit_UpdateTask); 
     123    } 
     124 
     125    Submit_UpdateTask(); 
     126} 
     127 
    126128connect(window, 'onload', Submit_Init); 
    127129 
Note: See TracChangeset for help on using the changeset viewer.