root / drupal7 / sites / all / modules / date / date_admin.js @ 64ad485a
1 | 85ad3d82 | Assos Assos | (function ($) { |
---|---|---|---|
2 | |||
3 | Drupal.behaviors.dateAdmin = {}; |
||
4 | |||
5 | Drupal.behaviors.dateAdmin.attach = function (context, settings) { |
||
6 | // Remove timezone handling options for fields without hours granularity.
|
||
7 | var $hour = $('#edit-field-settings-granularity-hour').once('date-admin'); |
||
8 | if ($hour.length) { |
||
9 | new Drupal.dateAdmin.TimezoneHandler($hour); |
||
10 | } |
||
11 | }; |
||
12 | |||
13 | |||
14 | Drupal.dateAdmin = {}; |
||
15 | |||
16 | /**
|
||
17 | * Constructor for the TimezoneHandler object.
|
||
18 | *
|
||
19 | * This object is responsible for showing the timezone handling options dropdown
|
||
20 | * when the user has chosen to collect hours as part of the date field, and
|
||
21 | * hiding it otherwise.
|
||
22 | */
|
||
23 | Drupal.dateAdmin.TimezoneHandler = function ($checkbox) { |
||
24 | this.$checkbox = $checkbox; |
||
25 | this.$dropdown = $('#edit-field-settings-tz-handling'); |
||
26 | this.$timezoneDiv = $('.form-item-field-settings-tz-handling'); |
||
27 | // Store the initial value of the timezone handling dropdown.
|
||
28 | this.storeTimezoneHandling();
|
||
29 | // Toggle the timezone handling section when the user clicks the "Hour"
|
||
30 | // checkbox.
|
||
31 | this.$checkbox.bind('click', $.proxy(this.clickHandler, this)); |
||
32 | // Trigger the click handler so that if the checkbox is unchecked on initial
|
||
33 | // page load, the timezone handling section will be hidden.
|
||
34 | this.clickHandler();
|
||
35 | }; |
||
36 | |||
37 | /**
|
||
38 | * Event handler triggered when the user clicks the "Hour" checkbox.
|
||
39 | */
|
||
40 | Drupal.dateAdmin.TimezoneHandler.prototype.clickHandler = function () { |
||
41 | if (this.$checkbox.is(':checked')) { |
||
42 | this.restoreTimezoneHandlingOptions();
|
||
43 | } |
||
44 | else {
|
||
45 | this.hideTimezoneHandlingOptions();
|
||
46 | } |
||
47 | }; |
||
48 | |||
49 | /**
|
||
50 | * Hide the timezone handling options section of the form.
|
||
51 | */
|
||
52 | Drupal.dateAdmin.TimezoneHandler.prototype.hideTimezoneHandlingOptions = function () { |
||
53 | this.storeTimezoneHandling();
|
||
54 | this.$dropdown.val('none'); |
||
55 | this.$timezoneDiv.hide(); |
||
56 | }; |
||
57 | |||
58 | /**
|
||
59 | * Show the timezone handling options section of the form.
|
||
60 | */
|
||
61 | Drupal.dateAdmin.TimezoneHandler.prototype.restoreTimezoneHandlingOptions = function () { |
||
62 | var val = this.getTimezoneHandling(); |
||
63 | this.$dropdown.val(val); |
||
64 | this.$timezoneDiv.show(); |
||
65 | }; |
||
66 | |||
67 | /**
|
||
68 | * Store the current value of the timezone handling dropdown.
|
||
69 | */
|
||
70 | Drupal.dateAdmin.TimezoneHandler.prototype.storeTimezoneHandling = function () { |
||
71 | this._timezoneHandling = this.$dropdown.val(); |
||
72 | }; |
||
73 | |||
74 | /**
|
||
75 | * Return the stored value of the timezone handling dropdown.
|
||
76 | */
|
||
77 | Drupal.dateAdmin.TimezoneHandler.prototype.getTimezoneHandling = function () { |
||
78 | return this._timezoneHandling; |
||
79 | }; |
||
80 | |||
81 | })(jQuery); |