chg: [attribute:type] Datetime value is forced to be a valid ISO format

- It is converted into UTC in the server
- /attribute/add Form includes javascript validation part
pull/5564/head
mokaddem 2020-01-28 14:38:58 +01:00
parent eb9b60032e
commit b03d86221b
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 32 additions and 0 deletions

View File

@ -1594,6 +1594,13 @@ class Attribute extends AppModel
}
$value = ($value) ? '1' : '0';
break;
case 'datetime':
try {
$value = (new DateTime($value))->setTimezone(new DateTimeZone('GMT'))->format('Y-m-d\TH:i:s.uO'); // ISO8601 formating with microseconds
} catch (Exception $e) {
// silently skip. Rejection will be done in runValidation()
}
break;
}
return $value;
}

View File

@ -141,6 +141,31 @@
endif;
?>
checkSharingGroup('Attribute');
var $form = $('#AttributeType').closest('form').submit(function( event ) {
if ($('#AttributeType').val() === 'datetime') {
// add timezone of the browser if not set
var allowLocalTZ = true;
var $valueInput = $('#AttributeValue')
var dateValue = moment($valueInput.val())
if (dateValue.isValid()) {
if (dateValue.creationData().format !== "YYYY-MM-DDTHH:mm:ssZ" && dateValue.creationData().format !== "YYYY-MM-DDTHH:mm:ss.SSSSZ") {
// Missing timezone data
var confirm_message = '<?php echo __('As no timezone has been entered, it has been auto-detected as: ') ?>' + dateValue.format('Z')
confirm_message += '<?php echo '\r\n' . __('This value will be submited instead: '); ?>' + dateValue.toISOString(allowLocalTZ)
if (confirm(confirm_message)) {
$valueInput.val(dateValue.toISOString(allowLocalTZ));
} else {
return false;
}
}
} else {
textStatus = '<?php echo __('Value is not a valid datetime. Excpected format YYYY-MM-DDTHH:mm:ssZ') ?>'
showMessage('fail', + ": " + '???');
return false;
}
}
});
});
</script>
<?php echo $this->element('form_seen_input'); ?>