template today now

This commit is contained in:
yuri
2018-03-20 12:00:46 +02:00
parent ea5d873cc3
commit 42f5d28369
4 changed files with 60 additions and 6 deletions
+8 -1
View File
@@ -260,13 +260,20 @@ class Htmlizer
$data = $this->getDataFromEntity($entity, $skipLinks);
if (!array_key_exists('today', $data)) {
$data['today'] = $this->dateTime->getTodayString();
}
if (!array_key_exists('now', $data)) {
$data['now'] = $this->dateTime->getNowString();
}
foreach ($additionalData as $k => $value) {
$data[$k] = $value;
}
$html = $renderer($data);
$html = str_replace('?entryPoint=attachment&', '?entryPoint=attachment&', $html);
if ($this->getEntityManager()) {
+34
View File
@@ -189,4 +189,38 @@ class DateTime
{
return date($this->getInternalDateFormat());
}
public function getTodayString($timezone = null)
{
if ($timezone) {
$timezoneObj = new \DateTimeZone($timezone);
} else {
$timezoneObj = $this->timezone;
}
$dateTime = new \DateTime();
$dateTime->setTimezone($timezoneObj);
return $dateTime->format($this->getPhpDateFormat());
}
public function getNowString($timezone = null, $format = null)
{
if ($timezone) {
$timezoneObj = new \DateTimeZone($timezone);
} else {
$timezoneObj = $this->timezone;
}
$dateTime = new \DateTime();
$dateTime->setTimezone($timezoneObj);
if ($format) {
$phpFormat = $this->convertFormatToPhp($format);
} else {
$phpFormat = $this->getPhpDateTimeFormat();
}
return $dateTime->format($phpFormat);
}
}
@@ -24,6 +24,10 @@
"pageOrientation": {
"Portrait": "Portrait",
"Landscape": "Landscape"
},
"placeholders": {
"today": "Today (date)",
"now": "Now (date-time)"
}
},
"tooltips": {
+14 -5
View File
@@ -86,12 +86,15 @@ Espo.define('views/template/fields/variables', 'views/fields/base', function (De
this.attributeList = attributeList;
attributeList.unshift('');
if (!~this.attributeList.indexOf('now')) {
this.attributeList.unshift('now');
}
this.translatedOptions = {};
attributeList.forEach(function (item) {
this.translatedOptions[item] = this.translate(item, 'fields', entityType);
}, this);
if (!~this.attributeList.indexOf('today')) {
this.attributeList.unshift('today');
}
attributeList.unshift('');
var links = this.getMetadata().get('entityDefs.' + entityType + '.links') || {};
@@ -135,6 +138,12 @@ Espo.define('views/template/fields/variables', 'views/fields/base', function (De
var entityType = this.model.get('entityType');
this.attributeList.forEach(function (item) {
if (~['today', 'now'].indexOf(item)) {
if (!this.getMetadata().get(['entityDefs', entityType, 'fields', item])) {
this.translatedOptions[item] = this.getLanguage().translateOption(item, 'placeholders', 'Template');
return;
}
}
var field = item;
var scope = entityType;
var isForeign = false;