Changeset 7693


Ignore:
Timestamp:
Nov 8, 2010, 1:56:51 AM (10 years ago)
Author:
LucMorizur
Message:

JS on validity date

Location:
extensions/event_cats/admin/template
Files:
2 edited

Legend:

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

    r7661 r7693  
    77// of .tpl file, thus some values below are modified during the HTML page
    88// "reading and displaying"
     9
    910var ec_avoid_infinite_loop      = true;
    1011var ec_is_creation              = true;
     
    1516var ec_dont_check               = false;
    1617var ec_selected_old_group       = false;
     18var ec_validity_on              = false;
     19var m_offset                    = 0;
     20var valid_annee                 = 0;
     21var valid_mois                  = 0;
     22var valid_date                  = 0;
     23var valid_heures                = 0;
     24var valid_minutes               = 0;
     25var valid_timestamp             = 0;
    1726var ec_err                      = '';
    1827var ec_selected_img             = '';
     
    3746var ec_selected_code            = '-1';
    3847var ec_selected_action          = '-1';
     48var maintenant                  = new Date();
    3949var ec_JS_message               = new Array();
    4050var ec_duplic_codes             = new Array();
     
    4959    ec_lists['comment']         = new Array();
    5060var d                           = document;
    51 
    52 /*
    53 // Function defined in ./plugins/event_cats/admin/template/autolog_new.tpl
     61var validity_date               = maintenant;
     62
     63
    5464function de(ec_id) {
    5565  return document.getElementById(ec_id);
    5666}
    57 */
     67
     68function ec_add_0(s) {
     69  var s2 = String(s);
     70  return (s2.length == 1) ? "0" + s2 : s2 ;
     71}
    5872
    5973function ec_check_exist_value(ec_id, ec_val) {
     
    690704}
    691705
     706function ec_update_ts() {
     707  if (de('ec_valid_date_on_id').checked == '')
     708   de('ec_valid_date_on_id').checked = 'checked';
     709  valid_annee     = Number(de('ec_validity_year_id').value);
     710  valid_mois      = de('ec_validity_month_id').selectedIndex;
     711  valid_date      = de('ec_validity_day_id').selectedIndex;
     712  valid_heures    = Number(de('ec_validity_time_id').value.match(/^\d+/));
     713  valid_minutes   = Number(de('ec_validity_time_id').value.match(/\d+$/));
     714  validity_date.setFullYear(valid_annee);
     715  validity_date.setMonth(valid_mois);
     716  validity_date.setDate(valid_date);
     717  validity_date.setHours(valid_heures);
     718  validity_date.setMinutes(valid_minutes);
     719  validity_date.setSeconds(0);
     720  validity_date.setMilliseconds(0);
     721  valid_timestamp = validity_date.getTime();
     722  // For tests purpose, must be removed
     723  de('ec_span_tst_id').innerHTML = 'valid_timestamp : ' + valid_timestamp;
     724  // For tests purpose, must be removed
     725}
     726
     727function ec_update_date(v2, k) { // Validity period cannot be less than one minute
     728  var v = (isNaN(v2)) ? 0 : Number(v2);
     729  if (v < 0) v = 0;
     730  switch (k) {
     731    case 0  :
     732      valid_timestamp += v * 60000;
     733      validity_date.setTime(valid_timestamp);
     734    break;
     735    case 1  :
     736      valid_timestamp += v * 3600000;
     737      validity_date.setTime(valid_timestamp);
     738    break;
     739    case 2  :
     740      valid_timestamp += v * 86400000;
     741      validity_date.setTime(valid_timestamp);
     742    break;
     743    case 3  :
     744      valid_annee  = Number(de('ec_validity_year_id').value);
     745      var m        = de('ec_validity_month_id').selectedIndex + v;
     746      valid_mois   = m % 12;
     747      valid_annee += Math.floor(m / 12);
     748      validity_date.setFullYear(valid_annee);
     749      validity_date.setMonth(valid_mois);
     750      valid_timestamp = validity_date.getTime();
     751    break;
     752    case 4  :
     753      valid_annee  = Number(de('ec_validity_year_id').value) + v;
     754      validity_date.setFullYear(valid_annee);
     755      valid_timestamp = validity_date.getTime();
     756    break;
     757  }
     758  valid_annee   = validity_date.getFullYear();
     759  valid_mois    = validity_date.getMonth();
     760  valid_date    = validity_date.getDate();
     761  valid_heures  = validity_date.getHours();
     762  valid_minutes = validity_date.getMinutes();
     763  de("ec_validity_year_id").value          = valid_annee;
     764  de("ec_validity_month_id").selectedIndex = valid_mois - 1;
     765  de("ec_validity_day_id").selectedIndex   = valid_date - 1;
     766  de("ec_validity_time_id").value          =
     767   ec_add_0(valid_heures) + ":" + ec_add_0(valid_minutes);
     768}
     769
    692770function ec_init() {
    693771  ec_selected_old_group                           = false;
     
    708786  ec_selected_user                                = '-1';
    709787  ec_selected_code                                = '-1';
     788  m_offset                                   = maintenant.getTimezoneOffset();
    710789  de('ec_style_forced_id').innerHTML              = ec_up_code_lbl_forced_txt;
    711790  de('ec_act1_id').value                          = ec_default_action;
     
    724803  de('ec_input_action_home').checked              = 'checked';
    725804  de('ec_input_action_home').checked              = '';
     805 
    726806 
    727807  if (ec_is_creation) { // Entry creation
  • extensions/event_cats/admin/template/autolog_new.tpl

    r7663 r7693  
    6363    {if $ec_is_creation}
    6464      <br><br>
    65       <input class = "submit" type = "button" name = "ec_submit_gen_full_auto" value = "{'Full auto'|@translate}"
     65      <input class = "submit" type = "button" value = "{'Full auto'|@translate}"
    6666       id = "ec_submit_gen_full_auto_id" onclick = "ec_gen_full_auto();" style = "margin-top:0;"/>
    6767    {/if}
     
    8888          <span {$ec_hidden_when_no_code} >&nbsp;</span>
    8989          <label for = "ec_in_up_code_id" style = "margin:0;">
    90             <input class = "submit" type = "button" name = "ec_submit_gen_code" value = "{'Auto code button'|@translate}"
     90            <input class = "submit" type = "button" value = "{'Auto code button'|@translate}"
    9191             id = "ec_submit_gen_code_id" onclick = "ec_gen_code();" style = "margin:0;"
    9292           >
     
    194194          <span {$ec_hidden_when_no_user} >&nbsp;</span>
    195195          <label for = "ec_in_up_usr_txt_id" style = "margin:0;">
    196             <input class = "submit" type = "button" name = "ec_submit_gen_user" value = "{'Generate username'|@translate}"
     196            <input class = "submit" type = "button" value = "{'Generate username'|@translate}"
    197197             id = "ec_submit_gen_user_id" onclick = "ec_gen_user();"
    198198           >
     
    315315    <table style = "margin-left: 0px; text-align:left;">
    316316      <tr>
    317         <td style="vertical-align:top;">
     317        <td style="vertical-align:top; margin-top:0;">
    318318          <p style = "text-align:left; margin-bottom:0.5em;">
    319319            <label for = "ec_valid_date_on_id">
     
    323323          </p>
    324324          <p style = "text-align:left;">
    325             <select id = "ec_validity_day_id" name = "ec_validity_day">
     325            <select id = "ec_validity_day_id" name = "ec_validity_day" onchange = "ec_update_ts();">
    326326              <option value = "0">--</option>
    327327              {section name=day start=1 loop=32}
     
    331331              {/section}
    332332            </select>
    333             <select id = "ec_validity_month_id" name = "ec_validity_month">
     333            <select id = "ec_validity_month_id" name = "ec_validity_month" onchange = "ec_update_ts();">
    334334              {html_options options=$month_list}
    335335            </select>
    336             <input id = "ec_validity_year_id" name = "ec_validity_year" type = "text" size = "4" maxlength = "4" value = "">
    337             <input id = "ec_validity_time_id" name = "ec_validity_time" type = "text" size = "5" maxlength = "5" value = "">
    338            
    339             <script type = "text/javascript"><!--
    340               {literal}
    341                 function de(ec_id) {
    342                   return document.getElementById(ec_id);
    343                 }
    344                 var maintenant = new Date();
    345                 var local_date = maintenant;
    346                 var m_offset = maintenant.getTimezoneOffset();
    347                 local_date.setTime(maintenant.getTime() + m_offset);
    348                 var mlocal_annee = local_date.getFullYear();
    349                 var mlocal_mois = local_date.getMonth() + 1; // In JavaScript, January is 0 and December is 11
    350                 var mlocal_date = local_date.getDay();
    351                 var mlocal_heures = local_date.getHours();
    352                 var mlocal_minutes = local_date.getMinutes() + 1; // Validity period cannot be less than one minute
    353                 de("ec_validity_day_id").selectedIndex = mlocal_date - 1;
    354                 de("ec_validity_month_id").selectedIndex = mlocal_mois - 1;
    355                 de("ec_validity_year_id").value = mlocal_annee;
    356                 de("ec_validity_time_id").value = mlocal_heures + ":" + mlocal_minutes;
    357               {/literal}
    358               // -->
    359             </script>
     336            <input id = "ec_validity_year_id" name = "ec_validity_year" type = "text" size = "4" maxlength = "4" value = "" onchange = "ec_update_ts();">
     337            <input id = "ec_validity_time_id" name = "ec_validity_time" type = "text" size = "5" maxlength = "5" value = "" onchange = "ec_update_ts();">
    360338           
    361339            {* <!-- ec_linked_date_id représente la date indiquée par les listes déroulantes, et permet de limiter
    362340                    le choix dans la date, en l'occurrence à des dates uniquement postérieures (grâce au 6° paramètre de pwg_initialization_datepicker) --> *}
    363341            <input id = "ec_linked_date_id" name = "ec_linked_date" type = "hidden" size = "10" disabled = "disabled">
    364             <script type = "text/javascript">
    365             </script><br>
    366342          </p>
     343          <p style = "text-align:left;">
     344            <input id = "ec_date_add_btn_id" type = "button" value = "Ajouter"
     345             onclick = "ec_update_date(document.getElementById('ec_date_add_val_id').value, document.getElementById('ec_date_add_kind_id').selectedIndex);">&nbsp;
     346            <input id = "ec_date_add_val_id" type = "text" size = "5" maxlength = "5" value = "">&nbsp;
     347            <select id = "ec_date_add_kind_id" name = "ec_date_add_kind">
     348              <option label = "minute(s)" value = "minutes">minute(s)</option>
     349              <option label = "heure(s)"  value = "hours"  >heure(s)</option>
     350              <option label = "jour(s)"   value = "days"   >jour(s)</option>
     351              <option label = "mois"      value = "months" >mois</option>
     352              <option label = "année(s)"  value = "years"  >année(s)</option>
     353            </select>
     354          </p>
     355          <p style = "text-align:left;">
     356            <input id = "ec_date_today_btn_id" type = "button" value = "Aujourd'hui" onclick = "">
     357          </p>
     358          {* <!-- For tests purpose ; must be removed --> *}
     359          <p style = "text-align:left;">
     360            <span id = "ec_span_tst_id"></span>
     361          </p>
     362          {* <!-- /For tests purpose ; must be removed --> *}
    367363        </td>
    368364       
     
    411407<script type = "text/javascript"><!--
    412408  ec_is_creation                          = {if $ec_is_creation}true{else}false{/if};
     409  ec_validity_on                          = {if $ec_validity_on}true{else}false{/if};
     410  valid_timestamp                         = 0{$valid_timestamp};
    413411  ec_up_code_lbl_forced_txt               = "{'Forced'|@translate}";
    414412  ec_JS_message['ec_gen_user_act_miss']   = "{'ec_gen_user_act_miss'|@translate|@escape:javascript}";
     
    441439  {/foreach}
    442440  ec_build_ec_lists();
    443   ec_init();
    444441  pwg_initialization_datepicker("#ec_validity_day_id", "#ec_validity_month_id",
    445442   "#ec_validity_year_id", "#ec_linked_date_id", null, "#ec_linked_date_id");
     443  ec_init();
    446444  //-->
    447445</script>
Note: See TracChangeset for help on using the changeset viewer.