Skip to content

Commit

Permalink
Fix date property in document info
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaRadzhabova committed Sep 17, 2024
1 parent 175c6e6 commit b27f093
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 97 deletions.
17 changes: 15 additions & 2 deletions apps/common/main/lib/component/InputField.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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'
Expand Down
58 changes: 46 additions & 12 deletions apps/common/main/lib/view/DocumentPropertyDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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',
Expand All @@ -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 || {}));
});
68 changes: 25 additions & 43 deletions apps/documenteditor/main/app/view/FileMenuPanels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down Expand Up @@ -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']();
Expand Down Expand Up @@ -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 +'">' +
Expand All @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions apps/documenteditor/main/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
41 changes: 21 additions & 20 deletions apps/presentationeditor/main/app/view/FileMenuPanels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 +'">' +
Expand All @@ -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;

Expand All @@ -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,
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions apps/presentationeditor/main/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit b27f093

Please sign in to comment.