Fix date property in document info

This commit is contained in:
Julia Radzhabova
2024-09-17 17:05:35 +03:00
parent 175c6e6fdc
commit b27f0937be
8 changed files with 131 additions and 97 deletions

View File

@ -701,6 +701,8 @@ define([
options.btnHint = options.btnHint || this.textDate;
Common.UI.InputFieldBtn.prototype.initialize.call(this, options);
this.dateValue = undefined;
},
render: function (parentEl) {
@ -725,18 +727,29 @@ define([
firstday: 1
});
me.cmpCalendar.on('date:click', function (cmp, date) {
me.dateValue = date;
me.trigger('date:click', me, date);
menu.hide();
});
me.dateValue && me.cmpCalendar.setDate(me.dateValue);
menu.alignPosition();
}
me.cmpCalendar.focus();
})
});
this._input.on('input', function() {
me.dateValue = undefined;
});
},
setDate: function(date) {
if (this.cmpCalendar && date && date instanceof Date && !isNaN(date))
if (date && date instanceof Date && !isNaN(date)) {
this.cmpCalendar && this.cmpCalendar.setDate(date);
this.dateValue = date;
}
},
getDate: function() {
return this.dateValue;
},
textDate: 'Select date'

View File

@ -164,23 +164,21 @@ define([], function () { 'use strict';
this.datepicker = new Common.UI.InputFieldBtnCalendar({
el: $('#id-dlg-value-date'),
allowBlank : true,
validateOnChange: false,
allowBlank : false,
blankError : this.txtPropertyValueBlankError,
validateOnBlur: false,
value : '',
dataHint : '1',
dataHintDirection: 'left',
dataHintOffset: 'small',
validation: function(value) {
return value.length === 0 || isNaN(new Date(value).getTime()) ? this.txtPropertyValueBlankError : true;
}
dataHintOffset: 'small'
});
if (this.options.defaultValue.value && currentType === 'date') {
this.datepicker.setValue(this.options.defaultValue.value);
this.datepicker.setDate(this.options.defaultValue.value);
this.datepicker.setValue(this.dateToString(this.options.defaultValue.value));
}
this.datepicker.setVisible(this.options.defaultValue.type ? this.options.defaultValue.type === AscCommon.c_oVariantTypes.vtFiletime : currentType === 'date');
this.datepicker.on('date:click', function (_, date) {
this.datepicker.setValue(date);
this.datepicker.on('date:click', function (cmp, date) {
cmp.setValue(this.dateToString(date));
}.bind(this));
var $window = this.getChild();
@ -230,8 +228,27 @@ define([], function () { 'use strict';
this.datepicker.focus();
return;
}
ascValue = new Date(this.datepicker.getValue());
ascValue = this.datepicker.getDate();
if (!ascValue) {
ascValue = new Date(this.datepicker.getValue());
if (!ascValue || !(ascValue instanceof Date) || isNaN(ascValue))
ascValue = undefined;
}
if (!ascValue) {
var me = this;
Common.UI.warning({
msg: me.errorDate,
buttons: ['ok', 'cancel'],
callback: function(btn) {
if (btn==='ok') {
me.options.handler.call(this, state, title, AscCommon.c_oVariantTypes.vtLpwstr, me.datepicker.getValue());
me.close();
} else
me.datepicker.focus();
}
});
return;
}
ascType = AscCommon.c_oVariantTypes.vtFiletime;
} else {
if (this.inputTextOrNumber.checkValidate() !== true) {
@ -266,6 +283,22 @@ define([], function () { 'use strict';
this.close();
},
dateToString: function (value) {
var text = '';
if (value) {
value = new Date(value)
var lang = (this.options.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'});
} catch (e) {
lang = 'en';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'});
}
}
return text;
},
txtTitle: "New Document Property",
txtPropertyTitleLabel: "Title",
txtPropertyTitleBlankError: 'Property should have a title',
@ -278,6 +311,7 @@ define([], function () { 'use strict';
txtPropertyTypeDate: "Date",
txtPropertyTypeBoolean: '"Yes" or "no"',
txtPropertyBooleanTrue: 'Yes',
txtPropertyBooleanFalse: 'No'
txtPropertyBooleanFalse: 'No',
errorDate: 'You can choose a value from the calendar to store the value as Date.<br>If you enter a value manually, it will be stored as Text.'
}, Common.Views.DocumentPropertyDialog || {}));
});

View File

@ -1726,16 +1726,7 @@ define([], function () {
this.coreProps = (this.api) ? this.api.asc_getCoreProps() : null;
if (this.coreProps) {
var value = this.coreProps.asc_getCreated();
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
this.lblDate.text(this.dateToString(value));
this._ShowHideInfoItem(this.lblDate, !!value);
} else if (pdfProps)
this.updatePdfInfo(pdfProps);
@ -1759,17 +1750,7 @@ define([], function () {
if (props) {
var visible = false;
value = props.asc_getModified();
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
this.lblModifyDate.text(this.dateToString(value));
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy();
if (value)
@ -1810,32 +1791,14 @@ define([], function () {
if (props) {
value = props.CreationDate;
if (value) {
value = new Date(value);
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
value && (value = new Date(value));
this.lblDate.text(this.dateToString(value));
this._ShowHideInfoItem(this.lblDate, !!value);
var visible = false;
value = props.ModDate;
if (value) {
value = new Date(value);
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
value && (value = new Date(value));
this.lblModifyDate.text(this.dateToString(value));
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
visible = this._ShowHideInfoItem(this.lblModifyBy, false) || visible;
$('tr.divider.modify', this.el)[visible?'show':'hide']();
@ -1995,6 +1958,8 @@ define([], function () {
tplCustomProperty: function(name, type, value) {
if (type === AscCommon.c_oVariantTypes.vtBool) {
value = value ? this.txtYes : this.txtNo;
} else if (type === AscCommon.c_oVariantTypes.vtFiletime) {
value = this.dateToString(new Date(value), true);
}
return '<tr data-name="' + name +'">' +
@ -2005,6 +1970,21 @@ define([], function () {
'</div></td></tr>';
},
dateToString: function (value, hideTime) {
var text = '';
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + (!hideTime ? ' ' + value.toLocaleString(lang, {timeStyle: 'short'}) : '');
} catch (e) {
lang = 'en';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + (!hideTime ? ' ' + value.toLocaleString(lang, {timeStyle: 'short'}) : '');
}
}
return text;
},
renderCustomProperty: function(name, type, value, idx) {
var me = this;
@ -2029,6 +2009,7 @@ define([], function () {
} else if (btn.hasClass('form-control')) {
(new Common.Views.DocumentPropertyDialog({
title: me.txtDocumentPropertyUpdateTitle,
lang: me.mode.lang,
defaultValue: {
name: name,
type: type,
@ -2097,6 +2078,7 @@ define([], function () {
onAddPropertyClick: function() {
var me = this;
(new Common.Views.DocumentPropertyDialog({
lang: me.mode.lang,
handler: function(result, title, type, value) {
if (result === 'ok') {
me.api.asc_addCustomProperty(title, type, value);

View File

@ -840,6 +840,7 @@
"Common.Views.DocumentPropertyDialog.txtPropertyTypeBoolean": "\"Yes\" or \"no\"",
"Common.Views.DocumentPropertyDialog.txtPropertyBooleanTrue": "Yes",
"Common.Views.DocumentPropertyDialog.txtPropertyBooleanFalse": "No",
"Common.Views.DocumentPropertyDialog.errorDate": "You can choose a value from the calendar to store the value as Date.<br>If you enter a value manually, it will be stored as Text.",
"DE.Controllers.DocProtection.txtIsProtectedComment": "Document is protected. You may only insert comments to this document.",
"DE.Controllers.DocProtection.txtIsProtectedForms": "Document is protected. You may only fill in forms in this document.",
"DE.Controllers.DocProtection.txtIsProtectedTrack": "Document is protected. You may edit this document, but all changes will be tracked.",

View File

@ -1378,16 +1378,7 @@ define([], function () {
this.coreProps = (this.api) ? this.api.asc_getCoreProps() : null;
if (this.coreProps) {
var value = this.coreProps.asc_getCreated();
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
this.lblDate.text(this.dateToString(value));
this._ShowHideInfoItem(this.lblDate, !!value);
}
@ -1418,16 +1409,7 @@ define([], function () {
if (props) {
var visible = false;
value = props.asc_getModified();
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
this.lblModifyDate.text(this.dateToString(value));
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy();
if (value)
@ -1462,6 +1444,8 @@ define([], function () {
tplCustomProperty: function(name, type, value) {
if (type === AscCommon.c_oVariantTypes.vtBool) {
value = value ? this.txtYes : this.txtNo;
} else if (type === AscCommon.c_oVariantTypes.vtFiletime) {
value = this.dateToString(new Date(value), true);
}
return '<tr data-name="' + name +'">' +
@ -1472,6 +1456,21 @@ define([], function () {
'</div></td></tr>';
},
dateToString: function (value, hideTime) {
var text = '';
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + (!hideTime ? ' ' + value.toLocaleString(lang, {timeStyle: 'short'}) : '');
} catch (e) {
lang = 'en';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + (!hideTime ? ' ' + value.toLocaleString(lang, {timeStyle: 'short'}) : '');
}
}
return text;
},
renderCustomProperty: function(name, type, value, idx) {
var me = this;
@ -1496,6 +1495,7 @@ define([], function () {
} else if (btn.hasClass('form-control')) {
(new Common.Views.DocumentPropertyDialog({
title: me.txtDocumentPropertyUpdateTitle,
lang: me.mode.lang,
defaultValue: {
name: name,
type: type,
@ -1522,6 +1522,7 @@ define([], function () {
onAddPropertyClick: function() {
var me = this;
(new Common.Views.DocumentPropertyDialog({
lang: me.mode.lang,
handler: function(result, name, type, value) {
if (result === 'ok') {
me.api.asc_addCustomProperty(name, type, value);

View File

@ -903,6 +903,7 @@
"Common.Views.DocumentPropertyDialog.txtPropertyTypeBoolean": "\"Yes\" or \"no\"",
"Common.Views.DocumentPropertyDialog.txtPropertyBooleanTrue": "Yes",
"Common.Views.DocumentPropertyDialog.txtPropertyBooleanFalse": "No",
"Common.Views.DocumentPropertyDialog.errorDate": "You can choose a value from the calendar to store the value as Date.<br>If you enter a value manually, it will be stored as Text.",
"PE.Controllers.LeftMenu.leavePageText": "All unsaved changes in this document will be lost.<br> Click \"Cancel\" then \"Save\" to save them. Click \"OK\" to discard all the unsaved changes.",
"PE.Controllers.LeftMenu.newDocumentTitle": "Unnamed presentation",
"PE.Controllers.LeftMenu.notcriticalErrorTitle": "Warning",

View File

@ -1849,16 +1849,7 @@ define([], function () {
this.coreProps = (this.api) ? this.api.asc_getCoreProps() : null;
if (this.coreProps) {
var value = this.coreProps.asc_getCreated();
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
this.lblDate.text(this.dateToString(value));
this._ShowHideInfoItem(this.lblDate, !!value);
}
},
@ -1883,16 +1874,7 @@ define([], function () {
if (props) {
var visible = false;
value = props.asc_getModified();
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
} catch (e) {
lang = 'en';
this.lblModifyDate.text(value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + ' ' + value.toLocaleString(lang, {timeStyle: 'short'}));
}
}
this.lblModifyDate.text(this.dateToString(value));
visible = this._ShowHideInfoItem(this.lblModifyDate, !!value) || visible;
value = props.asc_getLastModifiedBy();
if (value)
@ -1966,6 +1948,8 @@ define([], function () {
tplCustomProperty: function(name, type, value) {
if (type === AscCommon.c_oVariantTypes.vtBool) {
value = value ? this.txtYes : this.txtNo;
} else if (type === AscCommon.c_oVariantTypes.vtFiletime) {
value = this.dateToString(new Date(value), true);
}
return '<tr data-name="' + name +'">' +
@ -1976,6 +1960,21 @@ define([], function () {
'</div></td></tr>';
},
dateToString: function (value, hideTime) {
var text = '';
if (value) {
var lang = (this.mode.lang || 'en').replace('_', '-').toLowerCase();
try {
if ( lang == 'ar-SA'.toLowerCase() ) lang = lang + '-u-nu-latn-ca-gregory';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + (!hideTime ? ' ' + value.toLocaleString(lang, {timeStyle: 'short'}) : '');
} catch (e) {
lang = 'en';
text = value.toLocaleString(lang, {year: 'numeric', month: '2-digit', day: '2-digit'}) + (!hideTime ? ' ' + value.toLocaleString(lang, {timeStyle: 'short'}) : '');
}
}
return text;
},
renderCustomProperty: function(name, type, value, idx) {
var me = this;
@ -2000,6 +1999,7 @@ define([], function () {
} else if (btn.hasClass('form-control')) {
(new Common.Views.DocumentPropertyDialog({
title: me.txtDocumentPropertyUpdateTitle,
lang: me.mode.lang,
defaultValue: {
name: name,
type: type,
@ -2026,6 +2026,7 @@ define([], function () {
onAddPropertyClick: function() {
var me = this;
(new Common.Views.DocumentPropertyDialog({
lang: me.mode.lang,
handler: function(result, name, type, value) {
if (result === 'ok') {
me.api.asc_addCustomProperty(name, type, value);

View File

@ -762,6 +762,7 @@
"Common.Views.DocumentPropertyDialog.txtPropertyTypeBoolean": "\"Yes\" or \"no\"",
"Common.Views.DocumentPropertyDialog.txtPropertyBooleanTrue": "Yes",
"Common.Views.DocumentPropertyDialog.txtPropertyBooleanFalse": "No",
"Common.Views.DocumentPropertyDialog.errorDate": "You can choose a value from the calendar to store the value as Date.<br>If you enter a value manually, it will be stored as Text.",
"SSE.Controllers.DataTab.strSheet": "Sheet",
"SSE.Controllers.DataTab.textAddExternalData": "The link to an external source has been added. You can update such links in the Data tab.",
"SSE.Controllers.DataTab.textColumns": "Columns",