From b27f0937be8bdca4eb82db5f094bb55826d269d7 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 17 Sep 2024 17:05:35 +0300 Subject: [PATCH] Fix date property in document info --- apps/common/main/lib/component/InputField.js | 17 ++++- .../main/lib/view/DocumentPropertyDialog.js | 58 ++++++++++++---- .../main/app/view/FileMenuPanels.js | 68 +++++++------------ apps/documenteditor/main/locale/en.json | 1 + .../main/app/view/FileMenuPanels.js | 41 +++++------ apps/presentationeditor/main/locale/en.json | 1 + .../main/app/view/FileMenuPanels.js | 41 +++++------ apps/spreadsheeteditor/main/locale/en.json | 1 + 8 files changed, 131 insertions(+), 97 deletions(-) diff --git a/apps/common/main/lib/component/InputField.js b/apps/common/main/lib/component/InputField.js index a46b2345f4..887f910335 100644 --- a/apps/common/main/lib/component/InputField.js +++ b/apps/common/main/lib/component/InputField.js @@ -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' diff --git a/apps/common/main/lib/view/DocumentPropertyDialog.js b/apps/common/main/lib/view/DocumentPropertyDialog.js index 47cd7bc179..5925a19076 100644 --- a/apps/common/main/lib/view/DocumentPropertyDialog.js +++ b/apps/common/main/lib/view/DocumentPropertyDialog.js @@ -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.
If you enter a value manually, it will be stored as Text.' }, Common.Views.DocumentPropertyDialog || {})); }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index c4b69e496d..d31b79372c 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -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 '' + @@ -2005,6 +1970,21 @@ define([], function () { ''; }, + 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); diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 603c42f104..e1acf2ec58 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -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.
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.", diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index 7b04573e8e..680e592c69 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -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 '' + @@ -1472,6 +1456,21 @@ define([], function () { ''; }, + 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); diff --git a/apps/presentationeditor/main/locale/en.json b/apps/presentationeditor/main/locale/en.json index 115ab4cc77..a796d6cf82 100644 --- a/apps/presentationeditor/main/locale/en.json +++ b/apps/presentationeditor/main/locale/en.json @@ -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.
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.
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", diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index 658e497b3a..c5901fb17b 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -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 '' + @@ -1976,6 +1960,21 @@ define([], function () { ''; }, + 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); diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 77710982a2..e5e23ee212 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -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.
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",