Commit 6ea74bfe authored by Gábor Hojtsy's avatar Gábor Hojtsy

#149092 by Gurpartap Singh slightly modified: Usability: generalize timezone...

#149092 by Gurpartap Singh slightly modified: Usability: generalize timezone discovery to use on user registration
parent 739a8574
......@@ -914,7 +914,7 @@ function install_configure_form() {
if (Drupal.jsEnabled) {
$(document).ready(function() {
Drupal.cleanURLsInstallCheck();
Drupal.installDefaultTimezone();
Drupal.setDefaultTimezone();
});
}', 'inline');
......
......@@ -60,11 +60,6 @@ Drupal.cleanURLsInstallCheck = function() {
$("#clean-url").addClass('clean-url-processed');
};
Drupal.installDefaultTimezone = function() {
var offset = new Date().getTimezoneOffset() * -60;
$("#edit-date-default-timezone").val(offset);
};
/**
* Show/hide custom format sections on the date-time settings page.
*/
......@@ -85,4 +80,4 @@ Drupal.behaviors.dateTime = function(context) {
// Trigger the event handler to show the form input if necessary.
$('select.date-format', context).trigger('change');
};
\ No newline at end of file
};
......@@ -167,6 +167,14 @@ Drupal.evaluatePasswordStrength = function(value) {
return { strength: strength, message: msg };
};
/**
* Set the client's system timezone as default values of form fields.
*/
Drupal.setDefaultTimezone = function() {
var offset = new Date().getTimezoneOffset() * -60;
$("#edit-date-default-timezone, #edit-user-register-timezone").val(offset);
};
/**
* On the admin/user/settings page, conditionally show all of the
* picture-related form elements depending on the current value of the
......
......@@ -269,7 +269,7 @@ function user_save($account, $array = array(), $category = 'account') {
$values[] = md5($value);
$s[] = "'%s'";
break;
case 'mode': case 'sort':
case 'mode': case 'sort': case 'timezone':
case 'threshold': case 'created': case 'access':
case 'login': case 'status':
$fields[] = $key;
......@@ -1360,6 +1360,26 @@ function user_register() {
else {
$form = array_merge($form, $extra);
}
if (variable_get('configurable_timezones', 1)) {
// Override field ID, so we only change timezone on user registration,
// and never touch it on user edit pages.
$form['timezone'] = array(
'#type' => 'hidden',
'#default_value' => variable_get('date_default_timezone', NULL),
'#id' => 'edit-user-register-timezone',
);
// Add the JavaScript callback to automatically set the timezone.
drupal_add_js('
// Global Killswitch
if (Drupal.jsEnabled) {
$(document).ready(function() {
Drupal.setDefaultTimezone();
});
}', 'inline');
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Create new account'), '#weight' => 30);
$form['#validate'][] = 'user_register_validate';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment