Changeset 7847


Ignore:
Timestamp:
Nov 23, 2010, 12:58:57 AM (13 years ago)
Author:
LucMorizur
Message:

Finalize date & time controls -- with some jQuery code!

Location:
extensions/event_cats
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/event_cats/admin/template/autolog_new.js

    r7832 r7847  
    1717var ec_selected_old_group       = false;
    1818var ec_validity_on              = false;
    19 var m_offset                    = 0; /* // Inutile a priori
    20 var valid_annee                 = 0;
    21 var valid_mois                  = 0;
    22 var valid_date                  = 0;
    23 var valid_heures                = 0;
    24 var valid_minutes               = 0; */
    25 var valid_timestamp             = 0;
    2619var ec_err                      = '';
    2720var ec_selected_img             = '';
     
    703696}
    704697
    705 /* // Inutile a priori
    706 function ec_update_ts(c) {
    707   if (c && de('ec_valid_date_on_id').checked == '')
    708    de('ec_valid_date_on_id').checked = 'checked';
    709   valid_timestamp = validity_date.getTime();
    710   // For tests purpose, must be removed
    711   de('ec_span_tst_id').innerHTML = 'valid_timestamp : ' + valid_timestamp;
    712   // For tests purpose, must be removed
    713 }
    714 */
    715 
    716 function ec_add_time(v2, k) {
    717   var v = (isNaN(v2)) ? 0 : Number(v2);
    718   var m = 0;
    719   if (v < 0) v = 0;
     698function ec_get_validity() {
    720699  validity_date.setFullYear(de('ec_validity_year_id').value);
    721700  validity_date.setMonth(de('ec_validity_month_id').selectedIndex - 1);
     
    725704  validity_date.setSeconds(0);
    726705  validity_date.setMilliseconds(0);
    727   valid_timestamp = validity_date.getTime();
     706}
     707
     708function ec_set_validity() {
     709  de("ec_validity_year_id").value          = validity_date.getFullYear();
     710  de("ec_validity_month_id").selectedIndex = validity_date.getMonth() + 1;
     711  de("ec_validity_day_id").selectedIndex   = validity_date.getDate();
     712  de("ec_validity_time_id").value          =
     713   ec_add_0(validity_date.getHours()) +
     714   ":" +
     715   ec_add_0(validity_date.getMinutes());
     716}
     717
     718function ec_mark_now() {
     719  maintenant = new Date();
     720  validity_date.setTime(maintenant.getTime() + 120000); // Validity
     721  // [date & time] cannot be less than two minutes
     722  ec_set_validity();
     723}
     724
     725function ec_validity_check_min() {
     726  var tp = new Date();
     727  maintenant = tp;
     728  tp.setTime(maintenant.getTime() + 120000); // PHP will not allow that
     729  // [date & time] is less than [one minute more than current [date & time]].
     730  // Thus considering processing time, JavaScript should not allow a date
     731  // less than [two minutes more than current [date & time]] (due to the fact
     732  // that base unit for this value is one minute).
     733  de("ec_min_year_id").value          = tp.getFullYear();
     734  de("ec_min_month_id").selectedIndex = tp.getMonth() + 1;
     735  de("ec_min_day_id").selectedIndex   = tp.getDate();
     736  ec_get_validity();
     737  if (Number(validity_date.getTime()) < Number(tp.getTime())) {
     738    validity_date = tp;
     739    ec_set_validity();
     740  }
     741}
     742
     743function ec_validity_set_min() {
     744  ec_validity_check_min();
     745  // Run again this whole function after 1 mn
     746  window.setTimeout("ec_validity_set_min()", 60000);
     747}
     748
     749function ec_add_time(v2, k) {
     750  var m = 0; var ts = 0;
     751  var v = (isNaN(v2)) ? 0 : Number(v2);
     752  if (v < 0) v = 0;
     753  ec_get_validity();
     754  ts = Number(validity_date.getTime());
    728755  switch (k) {
    729756    case 0  : // minute(s)
    730       validity_date.setTime(valid_timestamp + (v *    60000));
     757      validity_date.setTime(ts + (v *    60000));
    731758    break;
    732759    case 1  : // hour(s)
    733       validity_date.setTime(valid_timestamp + (v *  3600000));
     760      validity_date.setTime(ts + (v *  3600000));
    734761    break;
    735762    case 2  : // day(s)
    736       validity_date.setTime(valid_timestamp + (v * 86400000));
     763      validity_date.setTime(ts + (v * 86400000));
    737764    break;
    738765    case 3  : // month(s)
    739       m = de('ec_validity_month_id').selectedIndex + v;
     766      m = Number(de('ec_validity_month_id').selectedIndex + v);
    740767      validity_date.setFullYear(
    741768        Number(de('ec_validity_year_id').value) + Math.floor(m / 12)
     
    747774    break;
    748775  }
    749   de("ec_validity_year_id").value          = validity_date.getFullYear();
    750   de("ec_validity_month_id").selectedIndex = validity_date.getMonth() + 1;
    751   de("ec_validity_day_id").selectedIndex   = validity_date.getDate();
    752   de("ec_validity_time_id").value          =
    753    ec_add_0(validity_date.getHours()) +
    754    ":" +
    755    ec_add_0(validity_date.getMinutes());
     776  ec_set_validity();
     777}
     778
     779function ec_valid_set_time_to(v) {
     780  var tp = new Date();
     781  var ts = 0;
     782  maintenant = tp;
     783  tp.setTime(maintenant.getTime() + 120000); // PHP will not allow that
     784  // [date & time] is less than [one minute more than current [date & time]].
     785  // Thus considering processing time, JavaScript should not allow a date
     786  // less than [two minutes more than current [date & time]] (due to the fact
     787  // that base unit for this value is one minute).
     788  ec_get_validity();
     789  validity_date.setHours(v);
     790  validity_date.setMinutes(0);
     791  ts = Number(validity_date.getTime());
     792  if (ts < Number(tp.getTime()))
     793   validity_date.setTime(ts + 86400000); // Add 1 day
     794  ec_set_validity();
     795  ec_validity_check_min();
    756796}
    757797
     
    774814  ec_selected_user                                = '-1';
    775815  ec_selected_code                                = '-1';
    776   m_offset                                   = maintenant.getTimezoneOffset();
     816  de('ec_valid_offset_id').value             = maintenant.getTimezoneOffset();
    777817  de('ec_style_forced_id').innerHTML              = ec_up_code_lbl_forced_txt;
    778818  de('ec_act1_id').value                          = ec_default_action;
     
    791831  de('ec_input_action_home').checked              = 'checked';
    792832  de('ec_input_action_home').checked              = '';
    793   de("ec_min_year_id").value                      = maintenant.getFullYear();
    794   de("ec_min_month_id").selectedIndex             = maintenant.getMonth() + 1;
    795   de("ec_min_day_id").selectedIndex               = maintenant.getDate();
    796   de("ec_validity_year_id").value                 = maintenant.getFullYear();
    797   de("ec_validity_month_id").selectedIndex        = maintenant.getMonth() + 1;
    798   de("ec_validity_day_id").selectedIndex          = maintenant.getDate();
    799   de("ec_validity_time_id").value                 =
    800    ec_add_0(maintenant.getHours()) +
    801    ":" +
    802    ec_add_0(maintenant.getMinutes());
     833  ec_mark_now();
     834  ec_validity_set_min();
    803835  pwg_initialization_datepicker("#ec_min_day_id", "#ec_min_month_id",
    804836   "#ec_min_year_id", "#ec_min_date_id", null, null, null);
     
    806838   "#ec_validity_month_id", "#ec_validity_year_id", "#ec_linked_date_id",
    807839   null, "#ec_min_date_id", null);
     840  $(document).ready(function(){
     841    $('.ui-datepicker').click(function(){
     842      ec_validity_check_min();
     843    });
     844    $('.ec_datepicker').change(function(){
     845      ec_validity_check_min();
     846    });
     847  });
    808848 
    809849  if (ec_is_creation) { // Entry creation
  • extensions/event_cats/admin/template/autolog_new.tpl

    r7835 r7847  
    88{* <!-- Remove a strange unwanted line at the bottom of the screen --> *}
    99{html_head} {literal}
     10  <link rel = "stylesheet" type = "text/css" href = "{$RACINE_URL}themes/default/js/ui/theme/ui.datepicker.css">
    1011  <style type = "text/css"> #ui-datepicker-div { display:none; } </style>
    1112{/literal} {/html_head}
     
    329330       
    330331        <td style="vertical-align:top; margin-top:0;">
    331           <p style = "text-align: left; padding-bottom: 1em; padding-top: 0; margin-top: 0pt; font-weight: bold;">
     332          <p style = "text-align:left; padding-bottom: 1em; padding-top: 0; margin-top: 0pt; font-weight: bold;">
    332333            <label for = "ec_valid_date_on_id">
    333334              <input type = "checkbox" name = "ec_valid_date_on" id = "ec_valid_date_on_id">
     
    337338          <p style = "text-align:left;">
    338339            <input id = "ec_date_today_btn_id" type = "button" value = "{'Now + 2 mn'|@translate}"
    339              class = "submit" title = "{'Now button tooltip'|@translate}" onclick = "">
     340             class = "submit" title = "{'Now button tooltip'|@translate}" onclick = "ec_mark_now();">&nbsp;—&nbsp;
     341            <input id = "ec_set_time_to_btn_id" type = "button" value = "{'Set time to'|@translate}"
     342             class = "submit" onclick = "ec_valid_set_time_to(document.getElementById('ec_set_time_to_id').selectedIndex);">&nbsp;
     343            <select id = "ec_set_time_to_id" name = "ec_set_time_to" onchange = "ec_valid_set_time_to(this.selectedIndex);">
     344              {section name=time start=0 loop=24}
     345                <option label = "{if strlen($smarty.section.time.index) lt 2}0{/if}{$smarty.section.time.index}:00" value = "{$smarty.section.time.index}">
     346                  {if strlen($smarty.section.time.index) lt 2}0{/if}{$smarty.section.time.index}:00
     347                </option>
     348              {/section}
     349            </select>
    340350          </p>
    341351          <p style = "text-align:left;">
    342             <select id = "ec_validity_day_id" name = "ec_validity_day">
     352            <select id = "ec_validity_day_id" name = "ec_validity_day" class = "ec_datepicker">
    343353              <option value = "0">--</option>
    344354              {section name=day start=1 loop=32}
     
    348358              {/section}
    349359            </select>
    350             <select id = "ec_validity_month_id" name = "ec_validity_month">
     360            <select id = "ec_validity_month_id" name = "ec_validity_month" class = "ec_datepicker">
    351361              {html_options options=$month_list}
    352362            </select>
    353             <input id = "ec_validity_year_id" name = "ec_validity_year" type = "text" size = "4" maxlength = "4">
    354             <input id = "ec_validity_time_id" name = "ec_validity_time" type = "text" size = "5" maxlength = "5" title = "{'Hours field tooltip'|@translate}">
     363            <input id = "ec_validity_year_id" name = "ec_validity_year" type = "text" size = "4" maxlength = "4" style = "text-align:right;" class = "ec_datepicker">
     364            <input id = "ec_validity_time_id" name = "ec_validity_time" type = "text" class = "ec_datepicker"
     365             size = "5" maxlength = "5" title = "{'Hours field tooltip'|@translate}" style = "text-align:right;">
    355366            <input id = "ec_linked_date_id" name = "ec_linked_date_id" type = "hidden" size = "10" disabled = "disabled">
    356367          </p>
     
    358369            <input id = "ec_date_add_btn_id" type = "button" value = "{'Add'|@translate}" title = "{'Add button tooltip'|@translate}" class = "submit"
    359370             onclick = "ec_add_time(document.getElementById('ec_date_add_val_id').value, document.getElementById('ec_date_add_kind_id').selectedIndex);">&nbsp;
    360             <input id = "ec_date_add_val_id" type = "text" size = "5" maxlength = "5" value = "">&nbsp;
     371            <input id = "ec_date_add_val_id" type = "text" size = "5" maxlength = "5" value = "" style = "text-align:right;">&nbsp;
    361372            <select id = "ec_date_add_kind_id" name = "ec_date_add_kind">
    362373              <option label = "{'Minutes'|@translate}" value = "minutes">{'Minutes'|@translate}</option>
     
    367378            </select>
    368379          </p>
    369           <p>
    370             <table>
    371               <tr>
    372                 <td style = "text-align:right; vertical-align:top; font-weight:bold;">
    373                   <label for = "ec_notify_id" title = "{'Notify label tooltip'|@translate}">
    374                     <input type = "checkbox" name = "ec_notify" id = "ec_notify_id" disabled = "disabled">
    375                     {'Do notify'|@translate}
    376                   </label>
    377                 </td>
    378                 <td style = "text-align:left;">
    379                   <ul style = "list-style-type:none; list-style-position:inside; padding-left: 0.5em;">
    380                     <li style = "margin-bottom:0;">
    381                       <label for = "ec_notify_user_id">
    382                         <input type = "checkbox" name = "ec_notify_user" id = "ec_notify_user_id">
    383                         {'The user'|@translate}
    384                       </label>
    385                     </li>
    386                     <li style = "margin-bottom:0;">
    387                       <label for = "ec_notify_webm_id">
    388                         <input type = "checkbox" name = "ec_notify_webm" id = "ec_notify_webm_id">
    389                         {'The webmaster'|@translate}
    390                       </label>
    391                     </li>
    392                     <li style = "margin-bottom:0;">
    393                       <label for = "ec_notify_admins_id">
    394                         <input type = "checkbox" name = "ec_notify_admins" id = "ec_notify_admins_id">
    395                         {'All administrators'|@translate}
    396                       </label>
    397                     </li>
    398                   </ul>
    399                 </td>
    400               </tr>
    401             </table>
    402           </p>
     380          <br>
     381          <table>
     382            <tr>
     383              <td style = "text-align:right; vertical-align:top; font-weight:bold;">
     384                <label for = "ec_notify_id" title = "{'Notify label tooltip'|@translate}">
     385                  <input type = "checkbox" name = "ec_notify" id = "ec_notify_id" disabled = "disabled">
     386                  {'Do notify'|@translate}
     387                </label>
     388              </td>
     389              <td style = "text-align:left;">
     390                <ul style = "list-style-type:none; list-style-position:inside; padding-left:0.5em;">
     391                  <li style = "margin-bottom:0;">
     392                    <label for = "ec_notify_user_id">
     393                      <input type = "checkbox" name = "ec_notify_user" id = "ec_notify_user_id">
     394                      {'The user'|@translate}
     395                    </label>
     396                  </li>
     397                  <li style = "margin-bottom:0;">
     398                    <label for = "ec_notify_webm_id">
     399                      <input type = "checkbox" name = "ec_notify_webm" id = "ec_notify_webm_id">
     400                      {'The webmaster'|@translate}
     401                    </label>
     402                  </li>
     403                  <li style = "margin-bottom:0;">
     404                    <label for = "ec_notify_admins_id">
     405                      <input type = "checkbox" name = "ec_notify_admins" id = "ec_notify_admins_id">
     406                      {'All administrators'|@translate}
     407                    </label>
     408                  </li>
     409                </ul>
     410              </td>
     411            </tr>
     412          </table>
    403413          <p style = "display:none;">
    404414            <!-- jQuery datepicker: see (french) http://fr.piwigo.org/forum/viewtopic.php?id=19042 -->
     
    415425            </select>
    416426            <input id = "ec_min_year_id" name = "ec_min_year" type = "text" size = "4" maxlength = "4">
    417             <input id = "ec_min_date_id" name = "ec_min_date_id" type = "hidden" size = "10" disabled = "disabled">
     427            <input id = "ec_min_date_id" name = "ec_min_date_id" type = "hidden" disabled = "disabled">
     428            <input id = "ec_valid_offset_id" name = "ec_valid_offset" type = "text">
    418429          </p>
    419430          {* <!-- For tests purpose; must be removed --> *}
  • extensions/event_cats/language/en_UK/plugin.lang.php

    r7835 r7847  
    8484$lang['Now + 2 mn']                = 'Now + 2 mn';
    8585$lang['Now button tooltip']        = 'Validity period can\'t be less than 1 mn. Considering processing time, 2 mn are required here.';
     86$lang['Set time to']               = 'Set time to';
    8687$lang['Hours field tooltip']       = 'Format: hh:mm or h:m';
    8788$lang['Add']                       = 'Add';
     
    9798$lang['The webmaster']             = 'the webmaster';
    9899$lang['All administrators']        = 'all administrators';
    99 $lang['Page once code outdated']   = 'Page to use once<br>the code has expired';
     100$lang['Page once code outdated']   = 'Page to assign to the code,<br>once it has expired';
    100101
    101102// Duplication page
  • extensions/event_cats/language/fr_FR/plugin.lang.php

    r7835 r7847  
    8383$lang['Activate']                  = 'Activer';
    8484$lang['Now + 2 mn']                = 'Maintenant + 2 mn';
    85 $lang['Now button tooltip']        = 'La période de validité est forcément d\'au moins 1 mn. Avec les temps de traitement, 2 mn sont nécessaires ici.';
     85$lang['Now button tooltip']        = 'La période de validité ne peut être inférieure à 1 mn. Compte tenu des temps de traitement, 2 mn sont nécessaires ici.';
     86$lang['Set time to']               = 'Régler l\'heure à';
    8687$lang['Hours field tooltip']       = 'Format : hh:mm ou h:m';
    8788$lang['Add']                       = 'Ajouter';
     
    9798$lang['The webmaster']             = 'le webmestre';
    9899$lang['All administrators']        = 'tous les administrateurs';
    99 $lang['Page once code outdated']   = 'Page à affecter au<br>code une fois expiré';
     100$lang['Page once code outdated']   = 'Page à affecter au code,<br>une fois qu\'il a expiré';
    100101
    101102// Duplication page
Note: See TracChangeset for help on using the changeset viewer.