Merge branch 'fix'

This commit is contained in:
Yuri Kuznetsov
2022-05-12 15:02:00 +03:00
4 changed files with 73 additions and 56 deletions
@@ -36,6 +36,8 @@ define('crm:views/meeting/fields/date-end', 'views/fields/datetime-optional', fu
noneOptionIsHidden: true,
isEnd: true,
setup: function () {
Dep.prototype.setup.call(this);
@@ -34,6 +34,8 @@ Espo.define('crm:views/task/fields/date-end', 'views/fields/datetime-optional',
listTemplate: 'crm:task/fields/date-end/detail',
isEnd: true,
data: function () {
var data = Dep.prototype.data.call(this);
+11 -6
View File
@@ -84,7 +84,7 @@ define('views/fields/datetime-optional', 'views/fields/datetime', function (Dep)
noneOption: [{
label: this.noneOption,
value: this.noneOption,
}]
}],
};
if (this.emptyTimeInInlineEditDisabled && this.isInlineEditMode() || this.noneOptionIsHidden) {
@@ -93,7 +93,7 @@ define('views/fields/datetime-optional', 'views/fields/datetime', function (Dep)
$time.timepicker(o);
$time.parent().find('button.time-picker-btn').on('click', function () {
$time.parent().find('button.time-picker-btn').on('click', () => {
$time.timepicker('show');
});
},
@@ -113,14 +113,17 @@ define('views/fields/datetime-optional', 'views/fields/datetime', function (Dep)
data[this.name] = value;
data[this.nameDate] = null;
} else {
}
else {
if (date !== '') {
data[this.nameDate] = this.getDateTime().fromDisplayDate(date);
var dateTimeValue = data[this.nameDate] + ' 00:00:00';
dateTimeValue = moment.utc(dateTimeValue)
.tz(this.getConfig().get('timeZone') || 'UTC')
dateTimeValue = moment
.tz(dateTimeValue, this.getConfig().get('timeZone') || 'UTC')
.add(this.isEnd ? 1 : 0, 'days')
.utc()
.format(this.getDateTime().internalDateTimeFullFormat);
data[this.name] = dateTimeValue;
@@ -130,6 +133,7 @@ define('views/fields/datetime-optional', 'views/fields/datetime', function (Dep)
data[this.name] = null;
}
}
return data;
},
@@ -190,7 +194,8 @@ define('views/fields/datetime-optional', 'views/fields/datetime', function (Dep)
validateRequired: function () {
if (this.isRequired()) {
if (this.model.get(this.name) === null && this.model.get(this.nameDate) === null) {
var msg = this.translate('fieldIsRequired', 'messages').replace('{field}', this.getLabelText());
var msg = this.translate('fieldIsRequired', 'messages')
.replace('{field}', this.getLabelText());
this.showValidationMessage(msg);
+58 -50
View File
@@ -69,20 +69,21 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
this.seconds = moment(
this.model.get(this.endField)).unix() - moment(this.model.get(this.startField)
).unix();
}
else {
if (start) {
var end = this._getDateEnd();
this.model.set(this.endField, end, {silent: true});
}
return;
}
if (start) {
var end = this._getDateEnd();
this.model.set(this.endField, end, {silent: true});
}
},
init: function () {
Dep.prototype.init.call(this);
this.listenTo(this, 'render', function () {
this.listenTo(this, 'render', () => {
this.calculateSeconds();
var durationOptions = '';
@@ -93,19 +94,20 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
options.push(this.seconds);
}
options.sort(function (a, b) {
options.sort((a, b) => {
return a - b;
});
options.forEach(function (d) {
options.forEach((d) => {
durationOptions += '<option value="' + d + '" ' +
(d === this.seconds ? 'selected' : '') + '>' + this.stringifyDuration(d) + '</option>';
}.bind(this));
(d === this.seconds ? 'selected' : '') + '>' +
this.stringifyDuration(d) + '</option>';
});
this.durationOptions = durationOptions;
this.stringValue = this.stringifyDuration(this.seconds);
}.bind(this));
});
},
setup: function () {
@@ -172,19 +174,19 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
if (this.mode === 'edit') {
this.$duration = this.$el.find('.main-element');
this.$duration.on('change', function () {
this.$duration.on('change', () => {
this.seconds = parseInt(this.$duration.val());
this.updateDateEnd();
this.$duration.find('option.custom').remove();
}.bind(this));
});
}
this.stopListening(this.model, 'change:' + this.endField);
this.stopListening(this.model, 'change:' + this.endField);
this.listenTo(this.model, 'change:' + this.endField, function () {
this.listenTo(this.model, 'change:' + this.endField, () => {
var start = this.model.get(this.startField);
var end = this.model.get(this.endField);
@@ -195,7 +197,7 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
this.seconds = moment(end).unix() - moment(start).unix();
this.updateDuration();
}.bind(this));
});
this.listenTo(this.model, 'change:' + this.startField, this.updateDateEnd);
@@ -211,9 +213,9 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
this.updateDateEnd();
}
else {
this.endFieldView.once('after:render', function () {
this.endFieldView.once('after:render', () => {
this.updateDateEnd();
}.bind(this));
});
}
}
}
@@ -235,7 +237,10 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
if (seconds) {
endUnix = moment.utc(start).unix() + seconds;
end = moment.unix(endUnix).utc().format(this.getDateTime().internalDateFormat);
end = moment.unix(endUnix)
.utc()
.add(-1, 'day')
.format(this.getDateTime().internalDateFormat);
}
else {
end = start;
@@ -272,20 +277,19 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
if (this.model.get('isAllDay')) {
var end = this._getDateEndDate();
setTimeout(function () {
setTimeout(() => {
this.model.set(this.endField + 'Date', end, {updatedByDuration: true});
}.bind(this), 1);
}, 1);
return;
}
var end = this._getDateEnd();
setTimeout(function () {
setTimeout(() => {
this.model.set(this.endField, end, {updatedByDuration: true});
this.model.set(this.endField + 'Date', null);
}.bind(this), 1);
}, 1);
},
updateDuration: function () {
@@ -294,42 +298,46 @@ define('views/fields/duration', 'views/fields/enum', function (Dep) {
if (seconds < 0) {
if (this.mode === 'edit') {
this.$duration.val('');
return;
}
else {
this.setup();
this.render();
}
this.setup();
this.render();
return;
}
else {
if (this.mode === 'edit') {
this.$duration.find('option.custom').remove();
var $o = $('<option>')
.val(seconds)
.text(this.stringifyDuration(seconds))
.addClass('custom');
if (this.mode === 'edit') {
this.$duration.find('option.custom').remove();
var $found = this.$duration.find('option').filter(function (i, el) {
var $o = $('<option>')
.val(seconds)
.text(this.stringifyDuration(seconds))
.addClass('custom');
var $found = this.$duration.find('option')
.filter((i, el) => {
return $(el).val() >= seconds;
}).first();
})
.first();
if ($found.length) {
if (parseInt($found.val()) !== seconds) {
$o.insertBefore($found);
};
}
else {
$o.appendTo(this.$duration);
}
this.$duration.val(seconds);
if ($found.length) {
if (parseInt($found.val()) !== seconds) {
$o.insertBefore($found);
};
}
else {
this.setup();
this.render();
$o.appendTo(this.$duration);
}
this.$duration.val(seconds);
return;
}
this.setup();
this.render();
},
fetch: function () {