[ Index ]
 

Code source de phpMyAdmin 2.10.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/js/ -> tbl_change.js (source)

   1  /* $Id: tbl_change.js 10474 2007-07-08 17:39:06Z lem9 $ */
   2  
   3  
   4  /**
   5   * Modify from controls when the "NULL" checkbox is selected
   6   *
   7   * @param   string   the MySQL field type
   8   * @param   string   the urlencoded field name
   9   * @param   string   the md5 hashed field name
  10   *
  11   * @return  boolean  always true
  12   */
  13  function nullify(theType, urlField, md5Field, multi_edit)
  14  {
  15      var rowForm = document.forms['insertForm'];
  16  
  17      if (typeof(rowForm.elements['funcs' + multi_edit + '[' + urlField + ']']) != 'undefined') {
  18          rowForm.elements['funcs' + multi_edit + '[' + urlField + ']'].selectedIndex = -1;
  19      }
  20  
  21      // "SET" field , "ENUM" field with more than 20 characters
  22      // or foreign key field
  23      if (theType == 1 || theType == 3 || theType == 4) {
  24          rowForm.elements['field_' + md5Field + multi_edit + '[]'].selectedIndex = -1;
  25      }
  26      // Other "ENUM" field
  27      else if (theType == 2) {
  28          var elts     = rowForm.elements['field_' + md5Field + multi_edit + '[]'];
  29          // when there is just one option in ENUM:
  30          if (elts.checked) {
  31              elts.checked = false;
  32          } else {
  33              var elts_cnt = elts.length;
  34              for (var i = 0; i < elts_cnt; i++ ) {
  35                  elts[i].checked = false;
  36              } // end for
  37  
  38          } // end if
  39      }
  40      // Other field types
  41      else /*if (theType == 5)*/ {
  42          rowForm.elements['fields' + multi_edit + '[' + urlField + ']'].value = '';
  43      } // end if... else if... else
  44  
  45      return true;
  46  } // end of the 'nullify()' function
  47  
  48  
  49  /**
  50   * Unchecks the "NULL" control when a function has been selected or a value
  51   * entered
  52   *
  53   * @param   string   the urlencoded field name
  54   *
  55   * @return  boolean  always true
  56   */
  57  function unNullify(urlField, multi_edit)
  58  {
  59      var rowForm = document.forms['insertForm'];
  60  
  61      if (typeof(rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']']) != 'undefined') {
  62          rowForm.elements['fields_null[multi_edit][' + multi_edit + '][' + urlField + ']'].checked = false
  63      } // end if
  64  
  65      if (typeof(rowForm.elements['insert_ignore_' + multi_edit]) != 'undefined') {
  66          rowForm.elements['insert_ignore_' + multi_edit].checked = false
  67      } // end if
  68  
  69      return true;
  70  } // end of the 'unNullify()' function
  71  
  72  var day;
  73  var month;
  74  var year;
  75  var hour;
  76  var minute;
  77  var second;
  78  var clock_set = 0;
  79  
  80  /**
  81   * Opens calendar window.
  82   *
  83   * @param   string      calendar.php parameters
  84   * @param   string      form name
  85   * @param   string      field name
  86   * @param   string      edit type - date/timestamp
  87   */
  88  function openCalendar(params, form, field, type) {
  89      window.open("./calendar.php?" + params, "calendar", "width=400,height=200,status=yes");
  90      dateField = eval("document." + form + "." + field);
  91      dateType = type;
  92  }
  93  
  94  /**
  95   * Formats number to two digits.
  96   *
  97   * @param   int number to format.
  98   * @param   string type of number
  99   */
 100  function formatNum2(i, valtype) {
 101      f = (i < 10 ? '0' : '') + i;
 102      if (valtype && valtype != '') {
 103          switch(valtype) {
 104              case 'month':
 105                  f = (f > 12 ? 12 : f);
 106                  break;
 107  
 108              case 'day':
 109                  f = (f > 31 ? 31 : f);
 110                  break;
 111  
 112              case 'hour':
 113                  f = (f > 24 ? 24 : f);
 114                  break;
 115  
 116              default:
 117              case 'second':
 118              case 'minute':
 119                  f = (f > 59 ? 59 : f);
 120                  break;
 121          }
 122      }
 123  
 124      return f;
 125  }
 126  
 127  /**
 128   * Formats number to two digits.
 129   *
 130   * @param   int number to format.
 131   * @param   int default value
 132   * @param   string type of number
 133   */
 134  function formatNum2d(i, default_v, valtype) {
 135      i = parseInt(i, 10);
 136      if (isNaN(i)) return default_v;
 137      return formatNum2(i, valtype)
 138  }
 139  
 140  /**
 141   * Formats number to four digits.
 142   *
 143   * @param   int number to format.
 144   */
 145  function formatNum4(i) {
 146      i = parseInt(i, 10)
 147      return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
 148  }
 149  
 150  /**
 151   * Initializes calendar window.
 152   */
 153  function initCalendar() {
 154      if (!year && !month && !day) {
 155          /* Called for first time */
 156          if (window.opener.dateField.value) {
 157              value = window.opener.dateField.value;
 158              if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
 159                  if (window.opener.dateType == 'datetime') {
 160                      parts   = value.split(' ');
 161                      value   = parts[0];
 162  
 163                      if (parts[1]) {
 164                          time    = parts[1].split(':');
 165                          hour    = parseInt(time[0],10);
 166                          minute  = parseInt(time[1],10);
 167                          second  = parseInt(time[2],10);
 168                      }
 169                  }
 170                  date        = value.split("-");
 171                  day         = parseInt(date[2],10);
 172                  month       = parseInt(date[1],10) - 1;
 173                  year        = parseInt(date[0],10);
 174              } else {
 175                  year        = parseInt(value.substr(0,4),10);
 176                  month       = parseInt(value.substr(4,2),10) - 1;
 177                  day         = parseInt(value.substr(6,2),10);
 178                  hour        = parseInt(value.substr(8,2),10);
 179                  minute      = parseInt(value.substr(10,2),10);
 180                  second      = parseInt(value.substr(12,2),10);
 181              }
 182          }
 183  
 184          if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
 185              dt      = new Date();
 186              year    = dt.getFullYear();
 187              month   = dt.getMonth();
 188              day     = dt.getDate();
 189          }
 190          if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
 191              dt      = new Date();
 192              hour    = dt.getHours();
 193              minute  = dt.getMinutes();
 194              second  = dt.getSeconds();
 195          }
 196      } else {
 197          /* Moving in calendar */
 198          if (month > 11) {
 199              month = 0;
 200              year++;
 201          }
 202          if (month < 0) {
 203              month = 11;
 204              year--;
 205          }
 206      }
 207  
 208      if (document.getElementById) {
 209          cnt = document.getElementById("calendar_data");
 210      } else if (document.all) {
 211          cnt = document.all["calendar_data"];
 212      }
 213  
 214      cnt.innerHTML = "";
 215  
 216      str = ""
 217  
 218      //heading table
 219      str += '<table class="calendar"><tr><th width="50%">';
 220      str += '<form method="NONE" onsubmit="return 0">';
 221      str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
 222      str += '<select id="select_month" name="monthsel" onchange="month = parseInt(document.getElementById(\'select_month\').value); initCalendar();">';
 223      for (i =0; i < 12; i++) {
 224          if (i == month) selected = ' selected="selected"';
 225          else selected = '';
 226          str += '<option value="' + i + '" ' + selected + '>' + month_names[i] + '</option>';
 227      }
 228      str += '</select>';
 229      str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
 230      str += '</form>';
 231      str += '</th><th width="50%">';
 232      str += '<form method="NONE" onsubmit="return 0">';
 233      str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
 234      str += '<select id="select_year" name="yearsel" onchange="year = parseInt(document.getElementById(\'select_year\').value); initCalendar();">';
 235      for (i = year - 25; i < year + 25; i++) {
 236          if (i == year) selected = ' selected="selected"';
 237          else selected = '';
 238          str += '<option value="' + i + '" ' + selected + '>' + i + '</option>';
 239      }
 240      str += '</select>';
 241      str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
 242      str += '</form>';
 243      str += '</th></tr></table>';
 244  
 245      str += '<table class="calendar"><tr>';
 246      for (i = 0; i < 7; i++) {
 247          str += "<th>" + day_names[i] + "</th>";
 248      }
 249      str += "</tr>";
 250  
 251      var firstDay = new Date(year, month, 1).getDay();
 252      var lastDay = new Date(year, month + 1, 0).getDate();
 253  
 254      str += "<tr>";
 255  
 256      dayInWeek = 0;
 257      for (i = 0; i < firstDay; i++) {
 258          str += "<td>&nbsp;</td>";
 259          dayInWeek++;
 260      }
 261      for (i = 1; i <= lastDay; i++) {
 262          if (dayInWeek == 7) {
 263              str += "</tr><tr>";
 264              dayInWeek = 0;
 265          }
 266  
 267          dispmonth = 1 + month;
 268  
 269          if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
 270              actVal = "" + formatNum4(year) + "-" + formatNum2(dispmonth, 'month') + "-" + formatNum2(i, 'day');
 271          } else {
 272              actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
 273          }
 274          if (i == day) {
 275              style = ' class="selected"';
 276              current_date = actVal;
 277          } else {
 278              style = '';
 279          }
 280          str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
 281          dayInWeek++;
 282      }
 283      for (i = dayInWeek; i < 7; i++) {
 284          str += "<td>&nbsp;</td>";
 285      }
 286  
 287      str += "</tr></table>";
 288  
 289      cnt.innerHTML = str;
 290  
 291      // Should we handle time also?
 292      if (window.opener.dateType != 'date' && !clock_set) {
 293  
 294          if (document.getElementById) {
 295              cnt = document.getElementById("clock_data");
 296          } else if (document.all) {
 297              cnt = document.all["clock_data"];
 298          }
 299  
 300          str = '';
 301          init_hour = hour;
 302          init_minute = minute;
 303          init_second = second;
 304          str += '<fieldset>';
 305          str += '<form method="NONE" class="clock" onsubmit="returnDate(\'' + current_date + '\')">';
 306          str += '<input id="hour"    type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_hour, \'hour\'); init_hour = this.value;" value="' + formatNum2(hour, 'hour') + '" />:';
 307          str += '<input id="minute"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_minute, \'minute\'); init_minute = this.value;" value="' + formatNum2(minute, 'minute') + '" />:';
 308          str += '<input id="second"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2d(this.value, init_second, \'second\'); init_second = this.value;" value="' + formatNum2(second, 'second') + '" />';
 309          str += '&nbsp;&nbsp;';
 310          str += '<input type="submit" value="' + submit_text + '"/>';
 311          str += '</form>';
 312          str += '</fieldset>';
 313  
 314          cnt.innerHTML = str;
 315          clock_set = 1;
 316      }
 317  
 318  }
 319  
 320  /**
 321   * Returns date from calendar.
 322   *
 323   * @param   string     date text
 324   */
 325  function returnDate(d) {
 326      txt = d;
 327      if (window.opener.dateType != 'date') {
 328          // need to get time
 329          h = parseInt(document.getElementById('hour').value,10);
 330          m = parseInt(document.getElementById('minute').value,10);
 331          s = parseInt(document.getElementById('second').value,10);
 332          if (window.opener.dateType == 'datetime') {
 333              txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
 334          } else {
 335              // timestamp
 336              txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
 337          }
 338      }
 339  
 340      window.opener.dateField.value = txt;
 341      window.close();
 342  }


Généré le : Mon Nov 26 15:18:20 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics