Projet

Général

Profil

Paste
Télécharger (2,52 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / date / date_admin.js @ 599a39cd

1
/**
2
 * @file
3
 */
4
(function ($) {
5

    
6
  Drupal.behaviors.dateAdmin = {};
7

    
8
  Drupal.behaviors.dateAdmin.attach = function (context, settings) {
9
    // Remove timezone handling options for fields without hours granularity.
10
    var $hour = $('#edit-field-settings-granularity-hour').once('date-admin');
11
    if ($hour.length) {
12
      new Drupal.dateAdmin.TimezoneHandler($hour);
13
    }
14
  };
15

    
16
  Drupal.dateAdmin = {};
17

    
18
  /**
19
 * Constructor for the TimezoneHandler object.
20
 *
21
 * This object is responsible for showing the timezone handling options dropdown
22
 * when the user has chosen to collect hours as part of the date field, and
23
 * hiding it otherwise.
24
 */
25
  Drupal.dateAdmin.TimezoneHandler = function ($checkbox) {
26
    this.$checkbox = $checkbox;
27
    this.$dropdown = $('#edit-field-settings-tz-handling');
28
    this.$timezoneDiv = $('.form-item-field-settings-tz-handling');
29
    // Store the initial value of the timezone handling dropdown.
30
    this.storeTimezoneHandling();
31
    // Toggle the timezone handling section when the user clicks the "Hour"
32
    // checkbox.
33
    this.$checkbox.bind('click', $.proxy(this.clickHandler, this));
34
    // Trigger the click handler so that if the checkbox is unchecked on initial
35
    // page load, the timezone handling section will be hidden.
36
    this.clickHandler();
37
  };
38

    
39
  /**
40
   * Event handler triggered when the user clicks the "Hour" checkbox.
41
   */
42
  Drupal.dateAdmin.TimezoneHandler.prototype.clickHandler = function () {
43
    if (this.$checkbox.is(':checked')) {
44
      this.restoreTimezoneHandlingOptions();
45
    }
46
    else {
47
      this.hideTimezoneHandlingOptions();
48
    }
49
  };
50

    
51
  /**
52
   * Hide the timezone handling options section of the form.
53
   */
54
  Drupal.dateAdmin.TimezoneHandler.prototype.hideTimezoneHandlingOptions = function () {
55
    this.storeTimezoneHandling();
56
    this.$dropdown.val('none');
57
    this.$timezoneDiv.hide();
58
  };
59

    
60
  /**
61
   * Show the timezone handling options section of the form.
62
   */
63
  Drupal.dateAdmin.TimezoneHandler.prototype.restoreTimezoneHandlingOptions = function () {
64
    var val = this.getTimezoneHandling();
65
    this.$dropdown.val(val);
66
    this.$timezoneDiv.show();
67
  };
68

    
69
  /**
70
   * Store the current value of the timezone handling dropdown.
71
   */
72
  Drupal.dateAdmin.TimezoneHandler.prototype.storeTimezoneHandling = function () {
73
    this._timezoneHandling = this.$dropdown.val();
74
  };
75

    
76
  /**
77
   * Return the stored value of the timezone handling dropdown.
78
   */
79
  Drupal.dateAdmin.TimezoneHandler.prototype.getTimezoneHandling = function () {
80
    return this._timezoneHandling;
81
  };
82

    
83
})(jQuery);