cs fix
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/fields/datetime-optional', 'views/fields/datetime', function (Dep) {
|
||||
define('views/fields/datetime-optional', 'views/fields/datetime', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
@@ -39,27 +39,34 @@ Espo.define('views/fields/datetime-optional', 'views/fields/datetime', function
|
||||
|
||||
isDate: function () {
|
||||
var dateValue = this.model.get(this.nameDate);
|
||||
if (dateValue && dateValue != '') {
|
||||
|
||||
if (dateValue && dateValue !== '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
data: function () {
|
||||
var data = Dep.prototype.data.call(this);
|
||||
|
||||
if (this.isDate()) {
|
||||
var dateValue = this.model.get(this.nameDate);
|
||||
|
||||
data.date = this.getDateTime().toDisplayDate(dateValue);
|
||||
data.time = this.noneOption;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
getDateStringValue: function () {
|
||||
if (this.isDate()) {
|
||||
var dateValue = this.model.get(this.nameDate);
|
||||
|
||||
return this.stringifyDateValue(dateValue);
|
||||
}
|
||||
|
||||
return Dep.prototype.getDateStringValue.call(this);
|
||||
},
|
||||
|
||||
@@ -85,6 +92,7 @@ Espo.define('views/fields/datetime-optional', 'views/fields/datetime', function
|
||||
}
|
||||
|
||||
$time.timepicker(o);
|
||||
|
||||
$time.parent().find('button.time-picker-btn').on('click', function () {
|
||||
$time.timepicker('show');
|
||||
});
|
||||
@@ -97,15 +105,18 @@ Espo.define('views/fields/datetime-optional', 'views/fields/datetime', function
|
||||
var time = this.$time.val();
|
||||
|
||||
var value = null;
|
||||
if (time != this.noneOption && time != '') {
|
||||
if (date != '' && time != '') {
|
||||
|
||||
if (time !== this.noneOption && time !== '') {
|
||||
if (date !== '' && time !== '') {
|
||||
value = this.parse(date + ' ' + time);
|
||||
}
|
||||
|
||||
data[this.name] = value;
|
||||
data[this.nameDate] = null;
|
||||
} else {
|
||||
if (date != '') {
|
||||
if (date !== '') {
|
||||
data[this.nameDate] = this.getDateTime().fromDisplayDate(date);
|
||||
|
||||
var dateTimeValue = data[this.nameDate] + ' 00:00:00';
|
||||
|
||||
dateTimeValue = moment.utc(dateTimeValue)
|
||||
@@ -113,7 +124,8 @@ Espo.define('views/fields/datetime-optional', 'views/fields/datetime', function
|
||||
.format(this.getDateTime().internalDateTimeFullFormat);
|
||||
|
||||
data[this.name] = dateTimeValue;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
data[this.nameDate] = null;
|
||||
data[this.name] = null;
|
||||
}
|
||||
@@ -123,22 +135,29 @@ Espo.define('views/fields/datetime-optional', 'views/fields/datetime', function
|
||||
|
||||
validateAfter: function () {
|
||||
var field = this.model.getFieldParam(this.name, 'after');
|
||||
|
||||
if (field) {
|
||||
var fieldDate = field + 'Date';
|
||||
var value = this.model.get(this.name) || this.model.get(this.nameDate);
|
||||
var otherValue = this.model.get(field) || this.model.get(fieldDate);
|
||||
|
||||
if (value && otherValue) {
|
||||
var isNotValid = false;
|
||||
|
||||
if (this.validateAfterAllowSameDay && this.model.get(this.nameDate)) {
|
||||
isNotValid = moment(value).unix() < moment(otherValue).unix();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
isNotValid = moment(value).unix() <= moment(otherValue).unix();
|
||||
}
|
||||
|
||||
if (isNotValid) {
|
||||
var msg = this.translate('fieldShouldAfter', 'messages').replace('{field}', this.getLabelText())
|
||||
.replace('{otherField}', this.translate(field, 'fields', this.model.name));
|
||||
var msg = this.translate('fieldShouldAfter', 'messages')
|
||||
.replace('{field}', this.getLabelText())
|
||||
.replace('{otherField}', this.translate(field, 'fields', this.model.name));
|
||||
|
||||
this.showValidationMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -147,15 +166,21 @@ Espo.define('views/fields/datetime-optional', 'views/fields/datetime', function
|
||||
|
||||
validateBefore: function () {
|
||||
var field = this.model.getFieldParam(this.name, 'before');
|
||||
|
||||
if (field) {
|
||||
var fieldDate = field + 'Date';
|
||||
var value = this.model.get(this.name) || this.model.get(this.nameDate);
|
||||
|
||||
var otherValue = this.model.get(field) || this.model.get(fieldDate);
|
||||
|
||||
if (value && otherValue) {
|
||||
if (moment(value).unix() >= moment(otherValue).unix()) {
|
||||
var msg = this.translate('fieldShouldBefore', 'messages').replace('{field}', this.getLabelText())
|
||||
.replace('{otherField}', this.translate(field, 'fields', this.model.name));
|
||||
var msg = this.translate('fieldShouldBefore', 'messages')
|
||||
.replace('{field}', this.getLabelText())
|
||||
.replace('{otherField}', this.translate(field, 'fields', this.model.name));
|
||||
|
||||
this.showValidationMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -166,11 +191,13 @@ Espo.define('views/fields/datetime-optional', 'views/fields/datetime', 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());
|
||||
|
||||
this.showValidationMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
|
||||
return Dep.extend({
|
||||
|
||||
@@ -36,7 +36,29 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
|
||||
validations: ['required', 'datetime', 'after', 'before'],
|
||||
|
||||
searchTypeList: ['lastSevenDays', 'ever', 'isEmpty', 'currentMonth', 'lastMonth', 'nextMonth', 'currentQuarter', 'lastQuarter', 'currentYear', 'lastYear', 'today', 'past', 'future', 'lastXDays', 'nextXDays', 'olderThanXDays', 'afterXDays', 'on', 'after', 'before', 'between'],
|
||||
searchTypeList: [
|
||||
'lastSevenDays',
|
||||
'ever',
|
||||
'isEmpty',
|
||||
'currentMonth',
|
||||
'lastMonth',
|
||||
'nextMonth',
|
||||
'currentQuarter',
|
||||
'lastQuarter',
|
||||
'currentYear',
|
||||
'lastYear',
|
||||
'today',
|
||||
'past',
|
||||
'future',
|
||||
'lastXDays',
|
||||
'nextXDays',
|
||||
'olderThanXDays',
|
||||
'afterXDays',
|
||||
'on',
|
||||
'after',
|
||||
'before',
|
||||
'between'
|
||||
],
|
||||
|
||||
timeFormatMap: {
|
||||
'HH:mm': 'H:i',
|
||||
@@ -48,11 +70,14 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
var data = Dep.prototype.data.call(this);
|
||||
|
||||
data.date = data.time = '';
|
||||
|
||||
var value = this.getDateTime().toDisplay(this.model.get(this.name));
|
||||
|
||||
if (value) {
|
||||
data.date = value.substr(0, value.indexOf(' '));
|
||||
data.time = value.substr(value.indexOf(' ') + 1);
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
@@ -60,15 +85,23 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
if (this.mode === 'detail' && !this.model.has(this.name)) {
|
||||
return '...';
|
||||
}
|
||||
|
||||
var value = this.model.get(this.name);
|
||||
|
||||
if (!value) {
|
||||
if (this.mode == 'edit' || this.mode == 'search' || this.mode === 'list' || this.mode == 'listLink') {
|
||||
if (
|
||||
this.mode === 'edit' |
|
||||
this.mode === 'search' |
|
||||
this.mode === 'list' ||
|
||||
this.mode === 'listLink'
|
||||
) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return this.translate('None');
|
||||
}
|
||||
|
||||
if (this.mode == 'list' || this.mode == 'detail' || this.mode == 'listLink') {
|
||||
if (this.mode === 'list' || this.mode === 'detail' || this.mode === 'listLink') {
|
||||
if (this.getConfig().get('readableDateFormatDisabled') || this.params.useNumericFormat) {
|
||||
return this.getDateTime().toDisplayDateTime(value);
|
||||
}
|
||||
@@ -91,17 +124,20 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
|
||||
if (d.unix() > ranges['today'][0] && d.unix() < ranges['today'][1]) {
|
||||
return this.translate('Today') + ' ' + d.format(timeFormat);
|
||||
} else if (d.unix() > ranges['tomorrow'][0] && d.unix() < ranges['tomorrow'][1]) {
|
||||
}
|
||||
else if (d.unix() > ranges['tomorrow'][0] && d.unix() < ranges['tomorrow'][1]) {
|
||||
return this.translate('Tomorrow') + ' ' + d.format(timeFormat);
|
||||
} else if (d.unix() > ranges['yesterday'][0] && d.unix() < ranges['yesterday'][1]) {
|
||||
}
|
||||
else if (d.unix() > ranges['yesterday'][0] && d.unix() < ranges['yesterday'][1]) {
|
||||
return this.translate('Yesterday') + ' ' + d.format(timeFormat);
|
||||
}
|
||||
|
||||
var readableFormat = this.getDateTime().getReadableDateFormat();
|
||||
|
||||
if (d.format('YYYY') == now.format('YYYY')) {
|
||||
if (d.format('YYYY') === now.format('YYYY')) {
|
||||
return d.format(readableFormat) + ' ' + d.format(timeFormat);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return d.format(readableFormat + ', YYYY') + ' ' + d.format(timeFormat);
|
||||
}
|
||||
}
|
||||
@@ -111,11 +147,13 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
|
||||
initTimepicker: function () {
|
||||
var $time = this.$time;
|
||||
|
||||
$time.timepicker({
|
||||
step: this.params.minuteStep || 30,
|
||||
scrollDefaultNow: true,
|
||||
timeFormat: this.timeFormatMap[this.getDateTime().timeFormat]
|
||||
});
|
||||
|
||||
$time.parent().find('button.time-picker-btn').on('click', function () {
|
||||
$time.timepicker('show');
|
||||
});
|
||||
@@ -123,7 +161,9 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
|
||||
setDefaultTime: function () {
|
||||
var d = moment('2014-01-01 00:00').format(this.getDateTime().getDateTimeFormat()) || '';
|
||||
|
||||
var index = d.indexOf(' ');
|
||||
|
||||
if (~index) {
|
||||
this.$time.val(d.substr(index + 1));
|
||||
}
|
||||
@@ -132,9 +172,10 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
afterRender: function () {
|
||||
Dep.prototype.afterRender.call(this);
|
||||
|
||||
if (this.mode == 'edit') {
|
||||
if (this.mode === 'edit') {
|
||||
var $date = this.$date = this.$element;
|
||||
var $time = this.$time = this.$el.find('input.time-part');
|
||||
|
||||
this.initTimepicker();
|
||||
|
||||
this.$element.on('change.datetime', function (e) {
|
||||
@@ -145,26 +186,32 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
}.bind(this));
|
||||
|
||||
var timeout = false;
|
||||
|
||||
var changeCallback = function () {
|
||||
if (!timeout) {
|
||||
this.trigger('change');
|
||||
}
|
||||
timeout = true;
|
||||
|
||||
setTimeout(function () {
|
||||
timeout = false;
|
||||
}, 100)
|
||||
}.bind(this);
|
||||
|
||||
$time.on('change', changeCallback);
|
||||
}
|
||||
},
|
||||
|
||||
update: function (value) {
|
||||
if (this.mode == 'edit') {
|
||||
if (this.mode === 'edit') {
|
||||
var formatedValue = this.getDateTime().toDisplay(value);
|
||||
|
||||
var arr = formatedValue.split(' ');
|
||||
|
||||
this.$date.val(arr[0]);
|
||||
this.$time.val(arr[1]);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
this.setup();
|
||||
this.render();
|
||||
}
|
||||
@@ -181,17 +228,22 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
var time = this.$time.val();
|
||||
|
||||
var value = null;
|
||||
if (date != '' && time != '') {
|
||||
|
||||
if (date !== '' && time !== '') {
|
||||
value = this.parse(date + ' ' + time);
|
||||
}
|
||||
|
||||
data[this.name] = value;
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
validateDatetime: function () {
|
||||
if (this.model.get(this.name) === -1) {
|
||||
var msg = this.translate('fieldShouldBeDatetime', 'messages').replace('{field}', this.getLabelText());
|
||||
|
||||
this.showValidationMessage(msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
@@ -202,6 +254,7 @@ Espo.define('views/fields/datetime', 'views/fields/date', function (Dep) {
|
||||
if (data) {
|
||||
data.dateTime = true;
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user