refactoring

This commit is contained in:
OVSharova
2023-01-22 19:43:16 +03:00
parent ff233c9043
commit 04e8fe3c26
7 changed files with 50 additions and 62 deletions

View File

@ -638,6 +638,11 @@ define([
$('#' + this._selectedItem.get('id'), $(this.el)).addClass('selected');
},
clearSelection: function (){
$('.selected', $(this.el)).removeClass('selected');
this._selectedItem = null;
},
itemClicked: function (e) {
var el = $(e.target).closest('li');

View File

@ -4164,21 +4164,15 @@ define([
info.asc_setType(Asc.c_oAscNumFormatType.None);
info.asc_setSymbol(this._state.langId);
var arr = this.api.asc_getFormatCells(info); // all formats
var disp=0
for (var i=0; i<menu.items.length-2; i++) {
menu.items[i].options.format = arr[i+disp];
if(i== Asc.c_oAscNumFormatType.Date)
disp = 1;
menu.items[i].options.format = arr[i];
}
}
var val = menu.options.numformatinfo;
val = (val) ? val.asc_getType() : -1;
for (var i=0; i<menu.items.length-2; i++) {
var mnu = menu.items[i];
mnu.options.exampleval = me.api.asc_getLocaleExample(mnu.options.format);
$(mnu.el).find('label').text(mnu.options.exampleval);
mnu.setChecked(val == mnu.value);
}
}
},

View File

@ -1482,10 +1482,8 @@ define([
onNumberFormatSelect: function(combo, record) {
if (record) {
if (this.api) {
if (this.api)
this.api.asc_setCellFormat(record.format);
this.cmbNumberFormatSetValue(record.value);
}
} else {
this.onCustomNumberFormat();
}
@ -1534,18 +1532,10 @@ define([
item.exampleval = me.api.asc_getLocaleExample(item.format);
});
me.toolbar.cmbNumberFormat.setData(me.toolbar.numFormatData);
this.cmbNumberFormatSetValue();
me.toolbar.cmbNumberFormat.setValue(me._state.numformattype, me.toolbar.txtCustom);
}
},
cmbNumberFormatSetValue: function (numformattype){
numformattype = !numformattype ? this._state.numformattype :numformattype
var indexNFD = numformattype + (numformattype > Asc.c_oAscNumFormatType.Date)|0;
this.toolbar.cmbNumberFormat.setRawValue(
(numformattype === Asc.c_oAscNumFormatType.Date) ? this.toolbar.txtDate : this.toolbar.numFormatData[indexNFD].displayValue
);
},
onDecrement: function(btn) {
if (this.api)
this.api.asc_decreaseCellDigitNumbers();
@ -3200,8 +3190,8 @@ define([
this._state.numformatinfo = val;
val = val.asc_getType();
if (this._state.numformattype !== val) {
this._state.numformattype = val;
this.cmbNumberFormatSetValue();
toolbar.cmbNumberFormat.setValue(val, toolbar.txtCustom);
this._state.numformattype = val;
}
}
@ -3358,8 +3348,8 @@ define([
this._state.numformatinfo = val;
val = val.asc_getType();
if (this._state.numformattype !== val) {
me.toolbar.cmbNumberFormat.setValue(val, me.toolbar.txtCustom);
this._state.numformattype = val;
this.cmbNumberFormatSetValue();
}
}
},
@ -3729,8 +3719,8 @@ define([
this._state.numformatinfo = val;
val = val.asc_getType();
if (this._state.numformattype !== val) {
me.toolbar.cmbNumberFormat.setValue(val, me.toolbar.txtCustom);
this._state.numformattype = val;
this.cmbNumberFormatSetValue();
}
}
},

View File

@ -472,7 +472,6 @@ define([
{
caption: this.txtGeneral,
template: numFormatTemplate,
checkable: true,
format: 'General',
exampleval: '100',
value: Asc.c_oAscNumFormatType.General
@ -480,7 +479,6 @@ define([
{
caption: this.txtNumber,
template: numFormatTemplate,
checkable: true,
format: '0.00',
exampleval: '100,00',
value: Asc.c_oAscNumFormatType.Number
@ -488,7 +486,6 @@ define([
{
caption: this.txtScientific,
template: numFormatTemplate,
checkable: true,
format: '0.00E+00',
exampleval: '1,00E+02',
value: Asc.c_oAscNumFormatType.Scientific
@ -496,7 +493,6 @@ define([
{
caption: this.txtAccounting,
template: numFormatTemplate,
checkable: true,
format: '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)',
exampleval: '100,00 $',
value: Asc.c_oAscNumFormatType.Accounting
@ -504,23 +500,27 @@ define([
{
caption: this.txtCurrency,
template: numFormatTemplate,
checkable: true,
format: '$#,##0.00',
exampleval: '100,00 $',
value: Asc.c_oAscNumFormatType.Currency
},
{
caption: this.txtDate,
caption: this.txtDateShort,
template: numFormatTemplate,
checkable: true,
format: 'MM-dd-yyyy',
exampleval: '04-09-1900',
value: Asc.c_oAscNumFormatType.Date
},
{
caption: this.txtDateLong,
template: numFormatTemplate,
format: 'MMMM d yyyy',
exampleval: 'April 9 1900',
value: Asc.c_oAscNumFormatType.Date
},
{
caption: this.txtTime,
template: numFormatTemplate,
checkable: true,
format: 'HH:MM:ss',
exampleval: '00:00:00',
value: Asc.c_oAscNumFormatType.Time
@ -528,7 +528,6 @@ define([
{
caption: this.txtPercentage,
template: numFormatTemplate,
checkable: true,
format: '0.00%',
exampleval: '100,00%',
value: Asc.c_oAscNumFormatType.Percent
@ -536,7 +535,6 @@ define([
{
caption: this.txtFraction,
template: numFormatTemplate,
checkable: true,
format: '# ?/?',
exampleval: '100',
value: Asc.c_oAscNumFormatType.Fraction
@ -544,7 +542,6 @@ define([
{
caption: this.txtText,
template: numFormatTemplate,
checkable: true,
format: '@',
exampleval: '100',
value: Asc.c_oAscNumFormatType.Text
@ -1329,7 +1326,8 @@ define([
txtScientific: 'Scientific',
txtAccounting: 'Accounting',
txtCurrency: 'Currency',
txtDate: 'Date',
txtDateShort: 'Short Date',
txtDateLong: 'Long Date',
txtTime: 'Time',
txtPercentage: 'Percentage',
txtFraction: 'Fraction',

View File

@ -579,8 +579,8 @@ define([ 'text!spreadsheeteditor/main/app/template/FormatRulesEditDlg.template',
{ value: Asc.c_oAscNumFormatType.Scientific,format: this.ascFormatOptions.Scientific, displayValue: this.txtScientific, exampleval: '1,00E+02' },
{ value: Asc.c_oAscNumFormatType.Accounting,format: this.ascFormatOptions.Accounting, displayValue: this.txtAccounting, exampleval: '100,00 $' },
{ value: Asc.c_oAscNumFormatType.Currency, format: this.ascFormatOptions.Currency, displayValue: this.txtCurrency, exampleval: '100,00 $' },
{ value: Asc.c_oAscNumFormatType.Date, format: 'MM-dd-yyyy', displayValue: this.txtDateShort, exampleval: '04-09-1900' },
{ value: Asc.c_oAscNumFormatType.Date, format: 'MMMM d yyyy', displayValue: this.txtDateLong, exampleval: 'April-09-1900' },
{ value: Asc.c_oAscNumFormatType.Date, format: 'MM-dd-yyyy', displayValue: this.txtDateShort, exampleval: '04-09-1900', customDisplayValue: this.txtDate},
{ value: Asc.c_oAscNumFormatType.Date, format: 'MMMM d yyyy', displayValue: this.txtDateLong, exampleval: 'April-09-1900', customDisplayValue: this.txtDate},
{ value: Asc.c_oAscNumFormatType.Time, format: 'HH:MM:ss', displayValue: this.txtTime, exampleval: '00:00:00' },
{ value: Asc.c_oAscNumFormatType.Percent, format: this.ascFormatOptions.Percentage, displayValue: this.txtPercentage, exampleval: '100,00%' },
{ value: Asc.c_oAscNumFormatType.Fraction, format: this.ascFormatOptions.Fraction, displayValue: this.txtFraction, exampleval: '100' },
@ -610,7 +610,7 @@ define([ 'text!spreadsheeteditor/main/app/template/FormatRulesEditDlg.template',
// '<li id="id-toolbar-mnu-item-more-formats" data-value="-1"><a tabindex="-1" type="menuitem">' + me.textMoreFormats + '</a></li>'
].join(''));
this.cmbNumberFormat = new Common.UI.ComboBox({
this.cmbNumberFormat = new Common.UI.ComboBoxCustom({
el : $('#format-rules-edit-combo-num-format'),
cls : 'input-group-nr',
style : 'width: 113px;',
@ -619,11 +619,14 @@ define([ 'text!spreadsheeteditor/main/app/template/FormatRulesEditDlg.template',
itemsTemplate: formatTemplate,
editable : false,
data : this.numFormatData,
takeFocusOnClose: true
takeFocusOnClose: true,
updateFormControl: function (record){
this.clearSelection();
record && this.setRawValue(record.get('customDisplayValue')||record.get('displayValue'));
}
});
this.cmbNumberFormat.setRawValue(this.numFormatData[Asc.c_oAscNumFormatType.General].displayValue);
this.cmbNumberFormat.on('selected', _.bind(this.onNumberFormatSelect, this));
this.cmbNumberFormat.on('show:before', _.bind(this.onNumberFormatShowBefore, this));
Common.UI.FocusManager.add(this, this.cmbNumberFormat);
this.btnClear = new Common.UI.Button({
@ -1315,13 +1318,7 @@ define([ 'text!spreadsheeteditor/main/app/template/FormatRulesEditDlg.template',
color = this.setColor(xfs.asc_getFillColor(), this.btnFillColor, this.mnuFillColorPicker);
var val = xfs.asc_getNumFormatInfo();
if (val) {
val = val.asc_getType();
var indexNFD = val + (val > Asc.c_oAscNumFormatType.Date)|0;
this.cmbNumberFormat.setRawValue(
(val === Asc.c_oAscNumFormatType.Date) ? this.txtDate : this.numFormatData[indexNFD].displayValue
);
}
val && this.cmbNumberFormat.setValue(val.asc_getType(), this.textCustom);
}
},
@ -1746,13 +1743,6 @@ define([ 'text!spreadsheeteditor/main/app/template/FormatRulesEditDlg.template',
!this.xfsFormat && (this.xfsFormat = new Asc.asc_CellXfs());
this.xfsFormat.asc_setNumFormatInfo(record.format);
this.previewFormat();
this.cmbNumberFormat.setRawValue(
(record.value === Asc.c_oAscNumFormatType.Date) ? this.txtDate : record.displayValue);
},
onNumberFormatShowBefore: function (){
var rec = $('.selected', $(this.cmbNumberFormat.el));
rec && rec.removeClass('selected');;
},
previewFormat: function() {

View File

@ -167,8 +167,8 @@ define([
{ value: Asc.c_oAscNumFormatType.Scientific,format: this.ascFormatOptions.Scientific, displayValue: this.txtScientific, exampleval: '1,00E+02' },
{ value: Asc.c_oAscNumFormatType.Accounting,format: this.ascFormatOptions.Accounting, displayValue: this.txtAccounting, exampleval: '100,00 $' },
{ value: Asc.c_oAscNumFormatType.Currency, format: this.ascFormatOptions.Currency, displayValue: this.txtCurrency, exampleval: '100,00 $' },
{ value: Asc.c_oAscNumFormatType.Date, format: 'MM-dd-yyyy', displayValue: this.txtDateShort, exampleval: '04-09-1900' },
{ value: Asc.c_oAscNumFormatType.Date, format: 'MMMM d yyyy', displayValue: this.txtDateLong, exampleval: 'April 9 1900' },
{ value: Asc.c_oAscNumFormatType.Date, format: 'MM-dd-yyyy', displayValue: this.txtDateShort, exampleval: '04-09-1900', customDisplayValue: this.txtDate},
{ value: Asc.c_oAscNumFormatType.Date, format: 'MMMM d yyyy', displayValue: this.txtDateLong, exampleval: 'April 9 1900', customDisplayValue: this.txtDate },
{ value: Asc.c_oAscNumFormatType.Time, format: 'HH:MM:ss', displayValue: this.txtTime, exampleval: '00:00:00' },
{ value: Asc.c_oAscNumFormatType.Percent, format: this.ascFormatOptions.Percentage, displayValue: this.txtPercentage, exampleval: '100,00%' },
{ value: Asc.c_oAscNumFormatType.Fraction, format: this.ascFormatOptions.Fraction, displayValue: this.txtFraction, exampleval: '100' },
@ -278,7 +278,7 @@ define([
'<li id="id-toolbar-mnu-item-more-formats" data-value="-1"><a tabindex="-1" type="menuitem">' + me.textMoreFormats + '</a></li>'
].join(''));
me.cmbNumberFormat = new Common.UI.ComboBox({
me.cmbNumberFormat = new Common.UI.ComboBoxCustom({
cls : 'input-group-nr',
menuStyle : 'min-width: 180px;',
hint : me.tipNumFormat,
@ -287,7 +287,11 @@ define([
editable : false,
data : me.numFormatData,
dataHint : '1',
dataHintDirection: 'bottom'
dataHintDirection: 'bottom',
updateFormControl: function (record){
this.clearSelection();
record && this.setRawValue(record.get('customDisplayValue')||record.get('displayValue'));
}
});
}
if ( config.isEditMailMerge || config.isEditOle ) {
@ -1393,7 +1397,7 @@ define([
'<li id="id-toolbar-mnu-item-more-formats" data-value="-1"><a tabindex="-1" type="menuitem">' + me.textMoreFormats + '</a></li>'
].join(''));
me.cmbNumberFormat = new Common.UI.ComboBox({
me.cmbNumberFormat = new Common.UI.ComboBoxCustom({
cls : 'input-group-nr',
style : 'width: 113px;',
menuStyle : 'min-width: 180px;',
@ -1403,7 +1407,12 @@ define([
editable : false,
data : me.numFormatData,
dataHint : '1',
dataHintDirection: 'top'
dataHintDirection: 'top',
updateFormControl: function (record){
this.clearSelection();
record && this.setRawValue(record.get('customDisplayValue')||record.get('displayValue'));
}
});
me.btnPercentStyle = new Common.UI.Button({

View File

@ -2249,7 +2249,9 @@
"SSE.Views.DocumentHolder.txtCustomRowHeight": "Custom row height",
"SSE.Views.DocumentHolder.txtCustomSort": "Custom sort",
"SSE.Views.DocumentHolder.txtCut": "Cut",
"SSE.Views.DocumentHolder.txtDate": "Date",
"del_SSE.Views.DocumentHolder.txtDate": "Date",
"SSE.Views.DocumentHolder.txtDateShort": "Short Date",
"SSE.Views.DocumentHolder.txtDateLong": "Long Date",
"SSE.Views.DocumentHolder.txtDelete": "Delete",
"SSE.Views.DocumentHolder.txtDescending": "Descending",
"SSE.Views.DocumentHolder.txtDistribHor": "Distribute horizontally",
@ -3849,7 +3851,7 @@
"SSE.Views.Toolbar.txtCustom": "Custom",
"SSE.Views.Toolbar.txtDate": "Date",
"SSE.Views.Toolbar.txtDateLong": "Long Date",
"SSE.Views.Toolbar.txtDateShort": "Date Short",
"SSE.Views.Toolbar.txtDateShort": "Short Date",
"SSE.Views.Toolbar.txtDateTime": "Date & Time",
"SSE.Views.Toolbar.txtDescending": "Descending",
"SSE.Views.Toolbar.txtDollar": "$ Dollar",