Changeset 6282c5 in indico


Ignore:
Timestamp:
06/24/11 14:31:49 (2 years ago)
Author:
Pedro Ferreira <jose.pedro.ferreira@…>
Branches:
master, hello-world-walkthrough, ipv6, v0.98-series, v0.98.2, v0.98.3, v0.98b2, v0.99, b8c30da8ebdbdcbd675a873997cc3e95f567de49, 4287315ec967a3da168d83963c14001db8487d53
Children:
75bea1
Parents:
cc169e
git-author:
Adrian Moennich <jerome.ernst.monnich@…> (06/14/11 15:19:20)
git-committer:
Pedro Ferreira <jose.pedro.ferreira@…> (06/24/11 14:31:49)
Message:

[REF] Get rid of prototype in room booking forms

Location:
indico
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • indico/MaKaC/webinterface/tpls/RoomBookingBookingForm.tpl

    r076d0a r6282c5  
    11<script type="text/javascript"> 
    2  
    3     // Function for checking and submitting the form when the user presses Enter. 
    4     // The JavaScript doesn't behave as expected in this case, since the checking is 
    5     // skipped. 
    6     function submit_on_enter(ev) { 
    7  
    8         var kc, e; 
    9         if (window.event) { 
    10             e = window.event; 
    11             kc = window.event.keyCode; 
    12         } 
    13         else if (ev) { 
    14             e = ev; 
    15             kc = ev.which; 
    16         } 
    17         else { 
    18             return true; 
    19         } 
    20  
    21         if (kc == 13) { 
    22             // If Enter was pressed in the "Reason" textarea, we don't want 
    23             // to submit the form 
    24             if (e.target == $('reason')) { 
    25                  return true; 
    26             } 
    27             if (forms_are_valid( true )) { 
    28                 submit_booking(); 
    29             } 
    30             else { 
    31                 alert( ${ _("'There are errors in the form. Please correct fields with red background.'")} ); 
    32             } 
    33             return false; 
    34         } 
    35         else { 
    36             return true; 
    37         } 
    38     } 
    39  
    402    // Reds out the invalid textboxes and returns false if something is invalid. 
    413    // Returns true if form may be submited. 
    42     function forms_are_valid( onSubmit ) 
    43     { 
    44         if ( onSubmit != true ) 
     4    function forms_are_valid(onSubmit) { 
     5        if (onSubmit != true) { 
    456            onSubmit = false; 
     7        } 
    468 
    479        // Init, clean up (make all textboxes white again) 
    48         var f1 = $('bookingForm') 
    49         period_clean_redouts( f1 ) 
    50         f1.bookedForName.className = f1.contactEmail.className = f1.contactPhone.className = f1.reason.className = '' 
    51  
    52         var isValid = true 
    53         isValid = validate_period( f1, true, ${ allowPast }  ) && isValid 
    54         isValid = required_fields( ['bookedForName', 'contactEmail', 'reason'] ) && isValid 
    55  
    56         if ( !Util.Validation.isEmailList( $F( 'contactEmail' ) ) ) 
    57         { 
    58             isValid = false 
    59             $('contactEmail').className = 'invalid' 
     10        var bookingForm = $j('#bookingForm'); 
     11        $j(':input', bookingForm).removeClass('invalid'); 
     12 
     13        var isValid = true; 
     14        isValid = validate_period(bookingForm[0], true, ${allowPast}) && isValid; 
     15        isValid = required_fields(['bookedForName', 'contactEmail', 'reason']) && isValid; 
     16 
     17        if (!Util.Validation.isEmailList($F('contactEmail'))) { 
     18            isValid = false; 
     19            $j('#contactEmail').addClass('invalid'); 
    6020        } 
    6121 
    6222        // Holidays warning 
    63         if ( isValid && !onSubmit ) 
    64         { 
    65             var holidaysWarning = indicoSource('roomBooking.getDateWarning', $(f1).serialize(true)); 
    66  
    67             holidaysWarning.state.observe(function(state) { 
    68                 if (state == SourceState.Loaded) { 
    69                     $E('holidays-warning').set(holidaysWarning.get()); 
     23        if (isValid && !onSubmit) { 
     24            var lastDateInfo = bookingForm.data('lastDateInfo'); 
     25            var dateInfo = $j('#sDay, #sMonth, #sYear, #eDay, #eMonth, #eYear').serialize(); 
     26            if (dateInfo != lastDateInfo) { 
     27                bookingForm.data('lastDateInfo', dateInfo); 
     28                var holidaysWarning = indicoSource('roomBooking.getDateWarning', bookingForm.serializeObject()); 
     29 
     30                holidaysWarning.state.observe(function(state) { 
     31                    if (state == SourceState.Loaded) { 
     32                        $E('holidays-warning').set(holidaysWarning.get()); 
     33                    } 
     34                }); 
     35            } 
     36        } 
     37 
     38        % if candResv.room.needsAVCSetup: 
     39            var vcIsValid = true; 
     40            if ($j('#usesAVC').is(':checked')) { 
     41                vcIsValid = $j('input.videoConferenceOption').is(':checked'); 
     42            } 
     43            $j('#vcSystemList').toggleClass('invalid', !vcIsValid); 
     44            isValid = isValid && vcIsValid; 
     45        % endif 
     46 
     47        return isValid; 
     48    } 
     49 
     50 
     51    $j(window).load(function() { 
     52        % if candResv.room.needsAVCSetup: 
     53            $j('.videoConferenceOption, #needsAVCSupport').change(function() { 
     54                if(this.checked) { 
     55                    $j('#usesAVC').prop('checked', true); 
    7056                } 
    7157            }); 
    72         } 
    73  
    74     % if candResv.room.needsAVCSetup: 
    75  
    76     $('vcSystemList').className='' 
    77  
    78     if ($('usesAVC').checked) { 
    79  
    80         var oneChecked = false; 
    81  
    82       $$('input.videoConferenceOption').each(function(elem){ 
    83         if (elem.checked) 
    84         { 
    85           oneChecked = true; 
    86         } 
    87       }); 
    88  
    89       if (!oneChecked) { 
    90         $( 'vcSystemList' ).className = 'invalid'; 
    91         isValid = false; 
    92       } 
    93  
    94     } 
    95     % endif 
    96  
    97  
    98         return isValid; 
    99     } 
    100  
    101     function submit_booking() 
    102     { 
    103         $('bookingForm').action = "${ saveBookingUH.getURL( conf ) }" 
    104         $('bookingForm').submit() 
    105     } 
    106  
    107  
    108  
    109  
     58            $j('#usesAVC').change(function() { 
     59                if(!this.checked) { 
     60                    $j('.videoConferenceOption, #needsAVCSupport').prop('checked', false); 
     61                } 
     62            }); 
     63        % endif 
     64 
     65        if (forms_are_valid()) { 
     66            set_repeatition_comment(); 
     67        } 
     68 
     69        $j('#bookingForm').delegate(':input', 'keyup change', function() { 
     70            forms_are_valid(); 
     71        }).submit(function(e) { 
     72            if (!forms_are_valid(true)) { 
     73                e.preventDefault(); 
     74                alert(${_("'There are errors in the form. Please correct the fields with red background.'")}); 
     75            }; 
     76        }).keydown(function(e) { 
     77            if(e.which == 13 && !$j(e.target).is('textarea, :submit')) { 
     78                e.preventDefault(); 
     79                $j('#saveBooking').click(); 
     80            } 
     81        }); 
     82 
     83        $j('#saveBooking').click(function(e) { 
     84            $j('#bookingForm').attr('action', '${saveBookingUH.getURL(conf)}'); 
     85        }); 
     86        $j('#checkBooking').click(function(e) { 
     87            $j('#bookingForm').attr('action', '${bookingFormURL}#conflicts'); 
     88            if (!validate_period($j('#bookingForm')[0], true, ${ allowPast })) { 
     89                alert(${_("'There are errors in the form. Please correct fields with red background.'")}); 
     90                e.preventDefault(); 
     91            } 
     92        }); 
     93 
     94        % if candResv.room.needsAVCSetup: 
     95            alert("The conference room you have chosen is equipped\nfor video-conferencing and video-projection.\nIf you need this equipment, DO NOT FORGET to select it.\nIf you don't need any of this equipment please choose\nanother room, if a suitable one is free on a suitable\nlocation for your meeting.\n\n\n                    Thank you for your understanding.") 
     96        % endif 
     97    }); 
    11098</script> 
    11199 
     
    129117    <!-- END OF CONTEXT HELP DIVS --> 
    130118 
    131     <form id="bookingForm" action="${bookingFormURL}#conflicts" method="post" onkeypress="return submit_on_enter(event);"> 
     119    <form id="bookingForm" action="${bookingFormURL}#conflicts" method="post"> 
    132120    <input type="hidden" id="afterCalPreview" name="afterCalPreview" value="True" /> 
    133121    <table cellpadding="0" cellspacing="0" border="0" width="80%"> 
     
    221209                                                            <% checked = """checked="checked" """ %> 
    222210                                                        % endif 
    223                                                         <% htmlCheckbox = """<br>\n<input id="vc_%s" name="vc_%s" class="videoConferenceOption" type="checkbox" onclick="if(this.checked){$(usesAVC).checked=true;}" %s /> %s""" %> 
     211                                                        <% htmlCheckbox = """<br>\n<input id="vc_%s" name="vc_%s" class="videoConferenceOption" type="checkbox" %s /> %s""" %> 
    224212                                                        ${ htmlCheckbox % (vc[:3], vc[:3], checked, vc) } 
    225213                                                    % endfor 
     
    230218                                                <td align="right" class="subFieldWidth" valign="top"><small><span style="color: Red;"> ${ _("I need assistance")}</span>&nbsp;&nbsp;</small></td> 
    231219                                                <td align="left" class="blacktext"> 
    232                                                     <input id="needsAVCSupport" name="needsAVCSupport" type="checkbox" ${' checked="checked" ' if candResv.needsAVCSupport else ""} onclick="if ( this.checked ) { $( 'usesAVC' ).checked = true; }" /> 
     220                                                    <input id="needsAVCSupport" name="needsAVCSupport" type="checkbox" ${' checked="checked" ' if candResv.needsAVCSupport else ""} /> 
    233221                                                    ${contextHelp('iNeedAVCSupport' )} 
    234222                                                </td> 
     
    245233                                       <input type="hidden" name="conf" value="${ conf.getId()  if conf else ""}" /> 
    246234                                    <input type="hidden" name="standalone" value="${ standalone }" /> 
    247                                        <input type="submit" class="btn" value="${ _("Re-check for conflicts")}" onclick="if (!validate_period(document.forms[0], true, ${ allowPast })) { alert( ${ _("'There are errors in the form. Please correct fields with red background.'")} ); return false; }"/> 
    248                                        <input type="submit" class="btn"  ${' value="Save" ' if formMode==FormMode.MODIF else ""} value="${ bookingMessage }" onclick="if (forms_are_valid( true )) { submit_booking(); } else { alert( ${ _("'There are errors in the form. Please correct fields with red background.'")} ); }; return false;" /> 
     235                                       <input type="submit" id="checkBooking" class="btn" value="${ _("Re-check for conflicts")}" /> 
     236                                       <input type="submit" id="saveBooking" class="btn"  ${' value="Save" ' if formMode==FormMode.MODIF else ""} value="${ bookingMessage }" /> 
    249237                                    ( 
    250238                                    <input type="checkbox" name="skipConflicting" id="skipConflicting" ${' checked="checked" ' if skipConflicting else ""} /> 
     
    270258    </form> 
    271259    <br /> 
    272     <!-- Just to initialize --> 
    273     <script type="text/javascript"> 
    274         Event.observe( window, 'load', 
    275             function () 
    276             { 
    277                 if ( forms_are_valid() ) 
    278                     set_repeatition_comment(); 
    279                 new Form.Observer( 'bookingForm', 0.4, forms_are_valid ); 
    280             } 
    281         ); 
    282         % if candResv.room.needsAVCSetup: 
    283             alert("The conference room you have chosen is equiped\nfor video-conferencing and video-projection.\nIf you need this equipment, DO NOT FORGET to select it.\nIf you don't need any of this equipment please choose\nanother room, if a suitable one is free on a suitable\nlocation for your meeting.\n\n\n                    Thank you for your understanding.") 
    284         % endif 
    285  
    286     </script> 
  • indico/MaKaC/webinterface/tpls/RoomBookingPeriodForm.tpl

    r988cfe r6282c5  
    22<script type="text/javascript"> 
    33 
    4     // Removes red background from form fields. 
    5     // Often calleed in the beginning of validation. 
    6     function period_clean_redouts( f1 ) 
    7     { 
    8         f1.sDay.className = f1.sMonth.className = f1.sYear.className = f1.sdate.className = ''; 
    9         f1.eDay.className = f1.eMonth.className = f1.eYear.className = f1.edate.className = ''; 
    10         f1.sTime.className = f1.eTime.className = ''; 
    11         f1.repeatability.className = ''; 
    12     } 
    13  
    144    // Comments the repeatition for user, to make it clear 
    15     function set_repeatition_comment() 
    16     { 
    17         var repTypeSel = $('repeatability') 
    18         var repCom = $('repComment') 
    19         var s = '' 
    20         var repType = parseInt( repTypeSel.value, 10 ) 
    21         if ( repType > 0 ) 
    22         { 
    23             date = new Date( parseInt( $F('sYear'), 10 ), parseInt( $F('sMonth')-1, 10 ), parseInt( $F('sDay'), 10 ) ) 
    24             weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] 
    25             s = 'on ' + weekDays[date.getDay()] 
    26             if ( repType == 4 ) 
    27             { 
    28                 weekNr = Math.floor( date.getDate() / 7 ) + 1 
    29                 postfix = ['st', 'nd', 'rd', 'th', 'th'] 
    30                 weekNrStr = 'the ' + weekNr + postfix[weekNr-1] + ' ' 
    31                 s = 'on ' + weekNrStr + weekDays[date.getDay()] + ' of a month' 
     5    function set_repeatition_comment() { 
     6        var s = ''; 
     7        var repType = parseInt($j('#repeatability').val(), 10); 
     8        if(repType > 0) { 
     9            date = new Date(parseInt($F('sYear'), 10), parseInt($F('sMonth')-1, 10), parseInt($F('sDay'), 10)); 
     10            weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; 
     11            s = 'on ' + weekDays[date.getDay()]; 
     12            if(repType == 4) { 
     13                weekNr = Math.floor( date.getDate() / 7 ) + 1; 
     14                postfix = ['st', 'nd', 'rd', 'th', 'th']; 
     15                weekNrStr = 'the ' + weekNr + postfix[weekNr-1] + ' '; 
     16                s = 'on ' + weekNrStr + weekDays[date.getDay()] + ' of a month'; 
    3217            } 
    3318        } 
    34         repCom.innerHTML = s 
    35  
    36 /* 
    37         skipConflicts = $( '' ); 
    38         if ( skipConflicts ) 
    39         { 
    40             if ( repType == 0 ) skipConflicts.hide(); 
    41             else skipConflicts.show(); 
    42         } 
    43 */ 
     19        $j('#repComment').html(s); 
    4420    } 
    4521 
  • indico/MaKaC/webinterface/tpls/RoomBookingSearch4Bookings.tpl

    rc0de5a r6282c5  
    44 
    55    // Displays div with dates and hours 
    6     function period_clean_redouts( f1 ) 
    7     { 
    8         f1.sDay.className = f1.sMonth.className = f1.sYear.className = f1.sdate.className = '' 
    9         f1.eDay.className = f1.eMonth.className = f1.eYear.className = f1.edate.className = '' 
    10         f1.sTime.className = f1.eTime.className = '' 
     6    function all_date_fields_are_blank() { 
     7        return ($F('sDay')=='' && $F('sMonth')=='' && $F('sYear')=='' && $F('sdate')=='' && 
     8                 $F('eDay')=='' && $F('eMonth')=='' && $F('eYear')=='' && $F('edate')==''); 
    119    } 
    12     function all_date_fields_are_blank() 
    13     { 
    14         return $F('sDay')=='' && $F('sMonth')=='' && $F('sYear')=='' && $F('sdate')=='' && $F('eDay')=='' && $F('eMonth')=='' && $F('eYear')=='' && $F('edate')=='' 
    15     } 
    16     function all_time_fields_are_blank() 
    17     { 
    18         return $F( 'sTime' ) == '' && $F( 'eTime' ) == '' 
     10    function all_time_fields_are_blank() { 
     11        return $F('sTime') == '' && $F('eTime') == ''; 
    1912    } 
    2013 
    2114    // Reds out the invalid textboxes and returns false if something is invalid. 
    2215    // Returns true if form may be submited. 
    23     function forms_are_valid( onSubmit ) 
    24     { 
    25         if ( onSubmit != true ) 
     16    function forms_are_valid(onSubmit) { 
     17        if (onSubmit != true) { 
    2618            onSubmit = false; 
     19        } 
    2720 
    2821        // Clean up - make all textboxes white again 
    29         var f1 = $('searchForm') 
    30         period_clean_redouts( f1 ) 
     22        var searchForm = $j('#searchForm'); 
     23        $j(':input', searchForm).removeClass('invalid'); 
    3124 
    3225        // Init 
    33         isValid = true 
     26        var isValid = true; 
    3427 
    3528        // Simple search 
    36         if ( !all_date_fields_are_blank() ) 
    37             isValid = validate_period( f1, false, true, 1 ) // 1: validate only dates 
    38         if ( !all_time_fields_are_blank() ) 
    39             isValid = isValid && validate_period( f1, false, true, 2 ) // 2: validate only times 
     29        if (!all_date_fields_are_blank()) { 
     30            isValid = validate_period(searchForm[0], false, true, 1) // 1: validate only dates 
     31        } 
     32        if (!all_time_fields_are_blank()) { 
     33            isValid = isValid && validate_period(searchForm[0], false, true, 2) // 2: validate only times 
     34        } 
    4035 
    4136        // Holidays warning 
    42         if ( isValid && !onSubmit ) 
    43         { 
    44             var holidaysWarning = indicoSource('roomBooking.getDateWarning', $(f1).serialize(true)); 
    45  
    46             holidaysWarning.state.observe(function(state) { 
    47                 if (state == SourceState.Loaded) { 
    48                     $E('holidays-warning').set(holidaysWarning.get()); 
    49                 } 
    50             }); 
    51         } 
    52  
    53         return isValid 
     37        if (isValid && !onSubmit) { 
     38            var lastDateInfo = searchForm.data('lastDateInfo'); 
     39            var dateInfo = $j('#sDay, #sMonth, #sYear, #eDay, #eMonth, #eYear').serialize(); 
     40            if (dateInfo != lastDateInfo) { 
     41                searchForm.data('lastDateInfo', dateInfo); 
     42                var holidaysWarning = indicoSource('roomBooking.getDateWarning', searchForm.serializeObject()); 
     43 
     44                holidaysWarning.state.observe(function(state) { 
     45                    if (state == SourceState.Loaded) { 
     46                        $E('holidays-warning').set(holidaysWarning.get()); 
     47                    } 
     48                }); 
     49            } 
     50        } 
     51 
     52        return isValid; 
    5453    } 
    5554 
    56     function confirm_search() 
    57     { 
    58         if ( $F('onlyMy') ) 
     55    function confirm_search() { 
     56        if ($F('onlyMy')) { 
    5957            return true; 
    60         if ( $F('roomGUID')[0] != undefined  &&  $F('roomGUID')[0].length > 0 ) 
     58        } 
     59        if ($F('roomGUID')[0] !== undefined && $F('roomGUID')[0].length > 0) { 
    6160            return true; 
    62         try { if ( $F('ofMyRooms') ) return true; } catch (err) {} 
    63         /*c = confirm( 'It is recommended to click "Cancel" and choose a room. Your query is very generic and it may take long time to process. Are you sure you want to continue?' ) 
    64         if ( c ) 
    65         { 
    66             $( 'submitBtn1' ).disabled = true; 
    67             $( 'submitBtn2' ).disabled = true; 
    68         }*/ 
    69         alert( 'Please select a room (or several rooms).' ) 
     61        } 
     62        try { if ($F('ofMyRooms')) { return true; } } catch (err) {} 
     63        alert('Please select a room (or several rooms).'); 
    7064        return false; 
    7165    } 
    7266 
    73     IndicoUI.executeOnLoad(function() 
    74     { 
    75  
    76         var startDate = IndicoUI.Widgets.Generic.dateField_sdate(false,null,['sDay', 'sMonth', 'sYear']); 
     67    $j(window).load(function() { 
     68        var startDate = IndicoUI.Widgets.Generic.dateField_sdate(false, null, ['sDay', 'sMonth', 'sYear']); 
    7769        $E('sDatePlace').set(startDate); 
    7870 
    79         var endDate = IndicoUI.Widgets.Generic.dateField_edate(false,null,['eDay', 'eMonth', 'eYear']); 
     71        var endDate = IndicoUI.Widgets.Generic.dateField_edate(false, null, ['eDay', 'eMonth', 'eYear']); 
    8072        $E('eDatePlace').set(endDate); 
    8173 
     
    8476        and if it's so we need to change it */ 
    8577        startDate.observe(function(value) { 
    86             if ( IndicoUtil.parseDate(startDate.get()) > IndicoUtil.parseDate(endDate.get()) ) { 
     78            if (IndicoUtil.parseDate(startDate.get()) > IndicoUtil.parseDate(endDate.get())) { 
    8779                endDate.set(startDate.get()); 
    88                 endDate.dom.onchange(); 
     80                endDate.dom.trigger('change'); 
    8981            } 
    9082        }); 
    9183 
    9284        endDate.observe(function(value) { 
    93             if ( IndicoUtil.parseDate(startDate.get()) > IndicoUtil.parseDate(endDate.get()) ) { 
     85            if (IndicoUtil.parseDate(startDate.get()) > IndicoUtil.parseDate(endDate.get())) { 
    9486                startDate.set(endDate.get()); 
    95                 startDate.dom.onchange(); 
    96             } 
    97         }); 
    98  
    99        % if today.day != '': 
     87                startDate.dom.trigger('change'); 
     88            } 
     89        }); 
     90 
     91        % if today.day != '': 
    10092            startDate.set('${ today.day }/${ today.month }/${ today.year }'); 
    10193        % endif 
     
    10597        % endif 
    10698 
    107      }); 
     99        $j('#onlyBookings').change(function() { 
     100            if(this.checked) { 
     101                $j('#onlyPrebookings').prop('checked', false); 
     102            } 
     103        }); 
     104 
     105        $j('#onlyPrebookings').change(function() { 
     106            if(this.checked) { 
     107                $j('#onlyBookings').prop('checked', false); 
     108            } 
     109        }); 
     110 
     111        $j('#searchForm').delegate(':input', 'keyup change', function() { 
     112            forms_are_valid(); 
     113        }).submit(function(e) { 
     114            if (!forms_are_valid(true)) { 
     115                alert(${_("'There are errors in the form. Please correct fields with red background.'")}); 
     116                e.preventDefault(); 
     117            } 
     118            else if(!confirm_search()) { 
     119                e.preventDefault(); 
     120            } 
     121        }); 
     122    }); 
    108123</script> 
    109124        <!-- CONTEXT HELP DIVS --> 
     
    152167                                                        ${inlineContextHelp(_("You can select multiple rooms the same way you select multiple files in Windows - press (and hold) left mouse button and move the cursor. Alternatively you can use keyboard - hold SHIFT and press up/down arrows.") )} 
    153168                                                        <input type="hidden" name="search" value="on" /> 
    154                                                         <!-- HACK to make form submitable with ENTER. This is just submit button copied and hidden. --> 
    155                                                         <input style="width: 0px; position:absolute; left: -50px;" type="submit" class="btn" onclick="if (!forms_are_valid( true )) { alert(  ${ _("'There are errors in the form. Please correct fields with red background.'")} ); return false; }; return confirm_search();" value="${ _('Search') }" /> 
    156169                                                    </td> 
    157170                                                </tr> 
     
    168181                                            <td class="blacktext"> 
    169182                                                <span id="sDatePlace"></span> 
    170                                                 <input type="hidden" value="${ today.day }" name="sDay" id="sDay" onchange="this.form.eDay.value=this.value;"/> 
    171                                                 <input type="hidden" value="${ today.month }" name="sMonth" id="sMonth" onchange="this.form.eMonth.value=this.value;"/> 
    172                                                 <input type="hidden" value="${ today.year }" name="sYear" id="sYear" onchange="this.form.eYear.value=this.value;"/> 
     183                                                <input type="hidden" value="${ today.day }" name="sDay" id="sDay" /> 
     184                                                <input type="hidden" value="${ today.month }" name="sMonth" id="sMonth" /> 
     185                                                <input type="hidden" value="${ today.year }" name="sYear" id="sYear" /> 
    173186                                            </td> 
    174187                                          </tr> 
     
    221234                                                    </tr> 
    222235                                                </table> 
    223                                                 <input id="submitBtn1" type="submit" class="btn" onclick="if (!forms_are_valid( true )) { alert(  ${ _("'There are errors in the form. Please correct fields with red background.'")} ); return false; }; return confirm_search();" value="${ _('Search') }" /> 
     236                                                <input id="submitBtn1" type="submit" class="btn" value="${ _('Search')}" /> 
    224237                                            </td> 
    225238                                        </tr> 
     
    237250                                                        <td width="165px" align="right" valign="top"><small>Only Bookings&nbsp;&nbsp;</small></td> 
    238251                                                        <td align="left" class="blacktext" > 
    239                                                             <input id="onlyBookings" name="onlyBookings" type="checkbox" onchange="javascript: if (this.checked) { $('onlyPrebookings').checked = false; }"/> 
     252                                                            <input id="onlyBookings" name="onlyBookings" type="checkbox" /> 
    240253                                                            ${inlineContextHelp(_("[v] Show only <b>Bookings</b>. If not checked, both pre-bookings and confirmed bookings will be shown.") )} 
    241254                                                            <br /> 
     
    245258                                                        <td width="165px" align="right" valign="top"><small>Only Pre-bookings&nbsp;&nbsp;</small></td> 
    246259                                                        <td align="left" class="blacktext" > 
    247                                                             <input id="onlyPrebookings" name="onlyPrebookings" type="checkbox" onchange="javascript: if (this.checked) { $('onlyBookings').checked = false; }" /> 
     260                                                            <input id="onlyPrebookings" name="onlyPrebookings" type="checkbox" /> 
    248261                                                            ${inlineContextHelp(_("[v] Show only <b>PRE-bookings</b>. If not checked, both pre-bookings and confirmed bookings will be shown.") )} 
    249262                                                            <br /> 
     
    311324                                                    </tr> 
    312325                                                </table> 
    313                                                 <input id="submitBtn2" type="submit" class="btn" onclick="if (!forms_are_valid( true )) { alert( ${ _("'There are errors in the form. Please correct fields with red background.'")} ); return false; }; return confirm_search();" value="${ _("Search")}" /> 
     326                                                <input id="submitBtn2" type="submit" class="btn" value="${ _('Search')}" /> 
    314327                                            </td> 
    315328                                        </tr> 
     
    326339        </tr> 
    327340        </table> 
    328         <!-- Just to initialize --> 
    329         <script type="text/javascript"> 
    330             Event.observe( window, 'load', 
    331                 function() { new Form.Observer( 'searchForm', 0.4, forms_are_valid ); } 
    332             ); 
    333         </script> 
  • indico/MaKaC/webinterface/tpls/RoomBookingSearch4Rooms.tpl

    rfb6f28 r6282c5  
    33 
    44    // Displays div with dates and hours 
    5     function display_availability( bool) 
    6     { 
    7         trs = $( 'sdatesTR', 'edatesTR', 'hoursTR', 'repTypeTR', 'includePrebookingsTR', 'includePendingBlockingsTR' ) 
    8         for ( i = 0; i < trs.length; i++ ) 
    9         { 
    10             if ( bool ) trs[i].style.display = ''      // Show 
    11             if ( !bool ) trs[i].style.display = 'none' // Hide 
    12         } 
     5    function display_availability(bool) { 
     6        $j('#sdatesTR, #edatesTR, #hoursTR, #repTypeTR, #includePrebookingsTR, #includePendingBlockingsTR').toggle(bool); 
    137    } 
    148    // Reds out the invalid textboxes and returns false if something is invalid. 
    159    // Returns true if form may be submited. 
    16     function forms_are_valid( onSubmit ) 
    17     { 
    18         if ( onSubmit != true ) 
     10    function forms_are_valid(onSubmit) { 
     11        if (onSubmit != true) { 
    1912            onSubmit = false; 
     13        } 
    2014 
    2115        // Clean up - make all textboxes white again 
    22         f1 = $('searchForm') 
    23         period_clean_redouts( f1 ) 
    24         f1.capacity.className = '' 
    25  
     16        var searchForm = $j('#searchForm'); 
     17        $j(':input', searchForm).removeClass('invalid'); 
    2618        // Init 
    27         isValid = true 
     19        var isValid = true; 
    2820 
    2921        // Simple search ------------------------------------- 
    3022        // Availability 
    31         if ( !$('searchForm').availability[2].checked ) // only if NOT "Don't care" 
    32         { 
    33             isValid = validate_period( f1 ) 
     23        if (!$j('input[name="availability"]', searchForm).is(':checked')) { // only if NOT "Don't care" 
     24            isValid = validate_period(searchForm[0]); 
    3425        } 
    3526        // capacity 
    36         if ( $F( 'capacity' ).length > 0 && parseInt( $F( 'capacity' ), 10 ).toString() == 'NaN' ) 
    37         { 
    38             f1.capacity.className = 'invalid' 
    39             isValid = false 
     27        if ($F('capacity').length > 0 && parseInt($F('capacity'), 10).toString() == 'NaN') { 
     28            $j('#capacity').addClass('invalid'); 
     29            isValid = false; 
    4030        } 
    4131 
    4232        // Holidays warning 
    43         if ( isValid && !onSubmit ) 
    44         { 
    45             var holidaysWarning = indicoSource('roomBooking.getDateWarning', $(f1).serialize(true)); 
    46  
    47             holidaysWarning.state.observe(function(state) { 
    48                 if (state == SourceState.Loaded) { 
    49                     $E('holidays-warning').set(holidaysWarning.get()); 
    50                 } 
    51             }); 
    52         } 
    53  
    54         if (f1.sdate.value == '' ){ 
    55               f1.sdate.className = 'invalid' 
    56               isValid = false; 
    57            } 
    58  
    59         if (f1.edate.value == ''){ 
    60               f1.edate.className = 'invalid' 
    61               isValid = false; 
    62            } 
    63  
    64         return isValid 
     33        if (isValid && !onSubmit) { 
     34            var lastDateInfo = searchForm.data('lastDateInfo'); 
     35            var dateInfo = $j('#sDay, #sMonth, #sYear, #eDay, #eMonth, #eYear').serialize(); 
     36            if (dateInfo != lastDateInfo) { 
     37                searchForm.data('lastDateInfo', dateInfo); 
     38                var holidaysWarning = indicoSource('roomBooking.getDateWarning', searchForm.serializeObject()); 
     39 
     40                holidaysWarning.state.observe(function(state) { 
     41                    if (state == SourceState.Loaded) { 
     42                        $E('holidays-warning').set(holidaysWarning.get()); 
     43                    } 
     44                }); 
     45            } 
     46        } 
     47 
     48        if (!$j('#sdate').val()) { 
     49            $j('#sdate').addClass('invalid'); 
     50            isValid = false; 
     51        } 
     52 
     53        if (!$j('#edate').val()) { 
     54            $j('#edate').addClass('invalid'); 
     55            isValid = false; 
     56        } 
     57 
     58        return isValid; 
    6559    } 
    6660    // Check whether a room can be booked (or pre-booked) by the user 
    6761    // If not, pop up a dialog 
    68     function isBookable() 
    69     { 
     62    function isBookable() { 
    7063        // Get the selected option in the SELECT 
    7164        var selectedURL = $F('roomName'); 
     
    10295            }); 
    10396    } 
     97 
     98    $j(window).load(function() { 
     99        $j('#searchForm').delegate(':input', 'keyup change', function() { 
     100            forms_are_valid(); 
     101        }).submit(function(e) { 
     102            if (!forms_are_valid(true)) { 
     103                e.preventDefault(); 
     104                alert(${_("'There are errors in the form. Please correct the fields with red background.'")}); 
     105            }; 
     106        }); 
     107 
     108        if (forms_are_valid()) { 
     109            set_repeatition_comment(); 
     110        } 
     111        if ($j('#searchForm input[name="availability"]').is(':checked')) { // if "Don't care" about availability 
     112            display_availability(false); 
     113        } 
     114        $j('#searchForm input[name="availability"]').change(function() { 
     115            display_availability($j(this).data('showAvailability')); 
     116        }); 
     117        $j('#freeSearch').focus(); 
     118    }); 
     119 
    104120 
    105121</script> 
     
    209225 
    210226                                                % if forNewBooking: 
    211                                                     <span id="bookButtonWrapper"><input id="bookButton" class="btn" type="button" value="${ _("Book")}" onclick="isBookable();" /></span> 
     227                                                    <span id="bookButtonWrapper"><input id="bookButton" class="btn" type="button" value="${_("Book")}" onclick="isBookable();" /></span> 
    212228                                                % endif 
    213229                                                % if not forNewBooking: 
    214                                                     <input class="btn" type="button" value="${ _("Room details")}" onclick="document.location = $F( 'roomName' ); return false;" /> 
     230                                                    <input class="btn" type="button" value="${ _("Room details")}" onclick="document.location = $F('roomName'); return false;" /> 
    215231                                                % endif 
    216232 
     
    243259                                                                % endfor 
    244260                                                            </select> 
    245                                                             <!-- HACK to make form submitable with ENTER. This is just submit button copied and hidden. --> 
    246                                                             <input style="width: 0px; position:absolute; left: -50px;" type="submit" class="btn" onclick="if (!forms_are_valid( true )) { alert(  ${ _("'There are errors in the form. Please correct fields with red background.'")} ); return false; };" value="" /> 
    247261                                                        </td> 
    248262                                                    </tr> 
     
    273287                                                        <td class="subFieldWidth" align="right" ><small> ${ _("Must be")}&nbsp;&nbsp;</small></td> 
    274288                                                        <td align="left" class="blacktext"> 
    275                                                             <input name="availability" type="radio" value="Available" onclick="display_availability( true ); " ${'checked="checked"' if forNewBooking else ""} /> ${ _("Available")} 
    276                                                             <input name="availability" type="radio" value="Booked" onclick="display_availability( true ); "/> ${ _("Booked")} 
    277                                                             <input name="availability" type="radio" value="Don't care" onclick="display_availability( false )" ${'checked="checked"' if not forNewBooking else ""}/> ${ _("Don't care")} 
     289                                                            <input name="availability" type="radio" value="Available" data-show-availability="true" ${'checked="checked"' if forNewBooking else ""} /> ${ _("Available")} 
     290                                                            <input name="availability" type="radio" value="Booked" data-show-availability="true" /> ${ _("Booked")} 
     291                                                            <input name="availability" type="radio" value="Don't care" data-show-availability="false" ${'checked="checked"' if not forNewBooking else ""}/> ${ _("Don't care")} 
    278292                                                            ${contextHelp('availabilityHelp' )} 
    279293                                                        </td> 
     
    331345                                        </tr> 
    332346                                        <tr> 
    333                                             <td nowrap class="titleCellTD" style="width: 125px;"><span class="titleCellFormat"> ${ _("Special attributes")}</td>                                    <td align="right"> 
     347                                            <td nowrap class="titleCellTD" style="width: 125px;"><span class="titleCellFormat"> ${ _("Special attributes")}</td> 
     348                                            <td align="right"> 
    334349                                                <table width="100%" cellspacing="4px"> 
    335350                                                    <tr> 
     
    372387                                            </td> 
    373388                                        </tr> 
    374                                         <tr><td colspan="2" style="padding-left:20px"><input type="submit" class="btn" onclick="if (!forms_are_valid( true )) {alert(  ${ _("'There are errors in the form. Please correct fields with red background.'")} ); return false; };" value="${ _('Search') }" /></td></tr> 
     389                                        <tr><td colspan="2" style="padding-left:20px"><input type="submit" class="btn" value="${ _('Search') }" /></td></tr> 
    375390                                    </table> 
    376391                                    </form> 
     
    385400        </tr> 
    386401        </table> 
    387         <!-- Just to initialize --> 
    388         <script type="text/javascript"> 
    389             Event.observe( window, 'load', 
    390                 function () { 
    391                     if ( forms_are_valid() ) 
    392                         set_repeatition_comment(); 
    393                     if ( $('searchForm').availability[2].checked ) // if "Don't care" about availability 
    394                         display_availability( false ); 
    395                     $( 'freeSearch' ).focus(); 
    396                     new Form.Observer( 'searchForm', 0.4, forms_are_valid ); 
    397                 } 
    398             ); 
    399         </script> 
  • indico/htdocs/js/indico/Legacy/Widgets.js

    r4bbdbe r6282c5  
    931931                if (update && p.inputField) { 
    932932                    p.inputField.value = cal.date.print(p.ifFormat); 
    933                     if (typeof p.inputField.onchange == "function") 
    934                         p.inputField.onchange(); 
     933                    $j(p.inputField).trigger('change'); 
    935934                } 
    936935                if (update && p.displayArea) 
Note: See TracChangeset for help on using the changeset viewer.