Commit 581361b7 authored by Alexander Trofimov's avatar Alexander Trofimov Committed by GitHub

Merge pull request #51 from ONLYOFFICE/feature/format-cells

Feature/format cells
parents 3d549e1b 678ac9da
...@@ -112,6 +112,7 @@ define([ ...@@ -112,6 +112,7 @@ define([
this.menuCls = me.options.menuCls; this.menuCls = me.options.menuCls;
this.menuStyle = me.options.menuStyle; this.menuStyle = me.options.menuStyle;
this.template = me.options.template || me.template; this.template = me.options.template || me.template;
this.itemsTemplate = me.options.itemsTemplate;
this.hint = me.options.hint; this.hint = me.options.hint;
this.editable = me.options.editable; this.editable = me.options.editable;
this.disabled = me.options.disabled; this.disabled = me.options.disabled;
...@@ -134,15 +135,22 @@ define([ ...@@ -134,15 +135,22 @@ define([
var me = this; var me = this;
if (!me.rendered) { if (!me.rendered) {
var items = this.store.toJSON();
this.cmpEl = $(this.template({ this.cmpEl = $(this.template({
id : this.id, id : this.id,
cls : this.cls, cls : this.cls,
style : this.style, style : this.style,
menuCls : this.menuCls, menuCls : this.menuCls,
menuStyle : this.menuStyle, menuStyle : this.menuStyle,
items : this.store.toJSON(), items : items,
scope : me scope : me
})); }));
if (this.itemsTemplate)
this.cmpEl.find('ul').append(
$(this.itemsTemplate({
items : items,
scope : me
})));
if (parentEl) { if (parentEl) {
this.setElement(parentEl, false); this.setElement(parentEl, false);
...@@ -274,7 +282,7 @@ define([ ...@@ -274,7 +282,7 @@ define([
} }
if (this.scroller) if (this.scroller)
this.scroller.update(); this.scroller.update({alwaysVisibleY: this.scrollAlwaysVisible});
this.trigger('show:after', this, e); this.trigger('show:after', this, e);
}, },
...@@ -441,7 +449,7 @@ define([ ...@@ -441,7 +449,7 @@ define([
return this.rendered ? this._input.val() : null; return this.rendered ? this._input.val() : null;
}, },
setValue: function(value) { setValue: function(value, defValue) {
if (!this.rendered) if (!this.rendered)
return; return;
...@@ -454,7 +462,7 @@ define([ ...@@ -454,7 +462,7 @@ define([
this.setRawValue(this._selectedItem.get(this.displayField)); this.setRawValue(this._selectedItem.get(this.displayField));
$('#' + this._selectedItem.get('id'), $(this.el)).addClass('selected'); $('#' + this._selectedItem.get('id'), $(this.el)).addClass('selected');
} else { } else {
this.setRawValue(value); this.setRawValue((defValue!==undefined) ? defValue : value);
} }
}, },
...@@ -529,6 +537,12 @@ define([ ...@@ -529,6 +537,12 @@ define([
}, },
onResetItems: function() { onResetItems: function() {
if (this.itemsTemplate) {
$(this.el).find('ul').html( $(this.itemsTemplate({
items: this.store.toJSON(),
scope: this
})));
} else {
$(this.el).find('ul').html(_.template([ $(this.el).find('ul').html(_.template([
'<% _.each(items, function(item) { %>', '<% _.each(items, function(item) { %>',
'<li id="<%= item.id %>" data-value="<%= item.value %>"><a tabindex="-1" type="menuitem"><%= scope.getDisplayValue(item) %></a></li>', '<li id="<%= item.id %>" data-value="<%= item.value %>"><a tabindex="-1" type="menuitem"><%= scope.getDisplayValue(item) %></a></li>',
...@@ -537,6 +551,7 @@ define([ ...@@ -537,6 +551,7 @@ define([
items: this.store.toJSON(), items: this.store.toJSON(),
scope: this scope: this
})); }));
}
if (!_.isUndefined(this.scroller)) { if (!_.isUndefined(this.scroller)) {
this.scroller.destroy(); this.scroller.destroy();
......
...@@ -50,7 +50,8 @@ define([ ...@@ -50,7 +50,8 @@ define([
'spreadsheeteditor/main/app/view/TableOptionsDialog', 'spreadsheeteditor/main/app/view/TableOptionsDialog',
'spreadsheeteditor/main/app/view/NamedRangeEditDlg', 'spreadsheeteditor/main/app/view/NamedRangeEditDlg',
'spreadsheeteditor/main/app/view/NamedRangePasteDlg', 'spreadsheeteditor/main/app/view/NamedRangePasteDlg',
'spreadsheeteditor/main/app/view/NameManagerDlg' 'spreadsheeteditor/main/app/view/NameManagerDlg',
'spreadsheeteditor/main/app/view/FormatSettingsDialog'
], function () { 'use strict'; ], function () { 'use strict';
SSE.Controllers.Toolbar = Backbone.Controller.extend(_.extend({ SSE.Controllers.Toolbar = Backbone.Controller.extend(_.extend({
...@@ -101,7 +102,9 @@ define([ ...@@ -101,7 +102,9 @@ define([
namedrange_locked: false, namedrange_locked: false,
fontsize: undefined, fontsize: undefined,
multiselect: false, multiselect: false,
sparklines_disabled: false sparklines_disabled: false,
numformattype: undefined,
langId: undefined
}; };
var checkInsertAutoshape = function(e, action) { var checkInsertAutoshape = function(e, action) {
...@@ -252,19 +255,16 @@ define([ ...@@ -252,19 +255,16 @@ define([
if (toolbar.mnuZoomOut) toolbar.mnuZoomOut.on('click', _.bind(this.onZoomOutClick, this)); if (toolbar.mnuZoomOut) toolbar.mnuZoomOut.on('click', _.bind(this.onZoomOutClick, this));
if (toolbar.btnShowMode.rendered) toolbar.btnShowMode.menu.on('item:click', _.bind(this.onHideMenu, this)); if (toolbar.btnShowMode.rendered) toolbar.btnShowMode.menu.on('item:click', _.bind(this.onHideMenu, this));
toolbar.listStyles.on('click', _.bind(this.onListStyleSelect, this)); toolbar.listStyles.on('click', _.bind(this.onListStyleSelect, this));
if (toolbar.btnNumberFormat.rendered) toolbar.btnNumberFormat.menu.on('item:click', _.bind(this.onNumberFormatMenu, this)); toolbar.cmbNumberFormat.on('selected', _.bind(this.onNumberFormatSelect, this));
toolbar.cmbNumberFormat.on('show:before', _.bind(this.onNumberFormatOpenBefore, this, true));
if (toolbar.cmbNumberFormat.cmpEl)
toolbar.cmbNumberFormat.cmpEl.on('click', '#id-toolbar-mnu-item-more-formats a', _.bind(this.onNumberFormatSelect, this));
toolbar.btnCurrencyStyle.menu.on('item:click', _.bind(this.onNumberFormatMenu, this)); toolbar.btnCurrencyStyle.menu.on('item:click', _.bind(this.onNumberFormatMenu, this));
if (toolbar.mnuitemCompactToolbar) toolbar.mnuitemCompactToolbar.on('toggle', _.bind(this.onChangeViewMode, this)); if (toolbar.mnuitemCompactToolbar) toolbar.mnuitemCompactToolbar.on('toggle', _.bind(this.onChangeViewMode, this));
$('#id-toolbar-menu-new-fontcolor').on('click', _.bind(this.onNewTextColor, this)); $('#id-toolbar-menu-new-fontcolor').on('click', _.bind(this.onNewTextColor, this));
$('#id-toolbar-menu-new-paracolor').on('click', _.bind(this.onNewBackColor, this)); $('#id-toolbar-menu-new-paracolor').on('click', _.bind(this.onNewBackColor, this));
$('#id-toolbar-menu-new-bordercolor').on('click', _.bind(this.onNewBorderColor, this)); $('#id-toolbar-menu-new-bordercolor').on('click', _.bind(this.onNewBorderColor, this));
_.each(toolbar.btnNumberFormat.menu.items, function(item) {
if (item.menu) {
item.menu.on('item:click', _.bind(me.onNumberFormatMenu, me));
}
});
this.onSetupCopyStyleButton(); this.onSetupCopyStyleButton();
}, },
...@@ -885,6 +885,63 @@ define([ ...@@ -885,6 +885,63 @@ define([
Common.component.Analytics.trackEvent('ToolBar', 'Number Format'); Common.component.Analytics.trackEvent('ToolBar', 'Number Format');
}, },
onNumberFormatSelect: function(combo, record) {
if (record) {
if (this.api)
this.api.asc_setCellFormat(record.format);
} else {
this.onCustomNumberFormat();
}
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
Common.component.Analytics.trackEvent('ToolBar', 'Number Format');
},
onCustomNumberFormat: function() {
var me = this,
value = Common.localStorage.getItem("sse-settings-reg-settings");
value = (value!==null) ? parseInt(value) : ((me.toolbar.mode.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(me.toolbar.mode.lang)) : 0x0409);
(new SSE.Views.FormatSettingsDialog({
api: me.api,
handler: function(result, settings) {
if (settings) {
me.api.asc_setCellFormat(settings.format);
}
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
},
props : {formatType: me._state.numformattype, langId: value}
})).show();
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
Common.component.Analytics.trackEvent('ToolBar', 'Number Format');
},
onNumberFormatOpenBefore: function(combo) {
if (this.api) {
var me = this;
var value = Common.localStorage.getItem("sse-settings-reg-settings");
value = (value!==null) ? parseInt(value) : ((this.toolbar.mode.lang) ? parseInt(Common.util.LanguageInfo.getLocalLanguageCode(this.toolbar.mode.lang)) : 0x0409);
if (this._state.langId !== value) {
this._state.langId = value;
var info = new Asc.asc_CFormatCellsInfo();
info.asc_setType(Asc.c_oAscNumFormatType.None);
info.asc_setSymbol(this._state.langId);
var arr = this.api.asc_getFormatCells(info); // all formats
me.toolbar.numFormatData.forEach( function(item, index) {
me.toolbar.numFormatData[index].format = arr[index];
});
}
me.toolbar.numFormatData.forEach( function(item, index) {
item.exampleval = me.api.asc_getLocaleExample(item.format);
});
me.toolbar.cmbNumberFormat.setData(me.toolbar.numFormatData);
me.toolbar.cmbNumberFormat.setValue(me._state.numformattype, me.toolbar.txtCustom);
}
},
onDecrement: function(btn) { onDecrement: function(btn) {
if (this.api) if (this.api)
this.api.asc_decreaseCellDigitNumbers(); this.api.asc_decreaseCellDigitNumbers();
...@@ -1238,6 +1295,13 @@ define([ ...@@ -1238,6 +1295,13 @@ define([
if (me.editMode && !me.toolbar.mode.isEditMailMerge && !me.toolbar.mode.isEditDiagram && !me.api.isCellEdited && !me._state.multiselect) if (me.editMode && !me.toolbar.mode.isEditMailMerge && !me.toolbar.mode.isEditDiagram && !me.api.isCellEdited && !me._state.multiselect)
me.onHyperlink(); me.onHyperlink();
e.preventDefault(); e.preventDefault();
},
'command+1,ctrl+1': function(e) {
if (me.editMode && !me.toolbar.mode.isEditMailMerge && !me.api.isCellEdited && !me.toolbar.cmbNumberFormat.isDisabled()) {
me.onCustomNumberFormat();
}
return false;
} }
} }
}); });
...@@ -1459,7 +1523,7 @@ define([ ...@@ -1459,7 +1523,7 @@ define([
var toolbar = this.toolbar; var toolbar = this.toolbar;
if (toolbar.mode.isEditDiagram || toolbar.mode.isEditMailMerge) { if (toolbar.mode.isEditDiagram || toolbar.mode.isEditMailMerge) {
is_cell_edited = (state == Asc.c_oAscCellEditorState.editStart); is_cell_edited = (state == Asc.c_oAscCellEditorState.editStart);
toolbar.lockToolbar(SSE.enumLock.editCell, state == Asc.c_oAscCellEditorState.editStart, {array: [toolbar.btnDecDecimal,toolbar.btnIncDecimal,toolbar.btnNumberFormat]}); toolbar.lockToolbar(SSE.enumLock.editCell, state == Asc.c_oAscCellEditorState.editStart, {array: [toolbar.btnDecDecimal,toolbar.btnIncDecimal,toolbar.cmbNumberFormat]});
} else } else
if (state == Asc.c_oAscCellEditorState.editStart || state == Asc.c_oAscCellEditorState.editEnd) { if (state == Asc.c_oAscCellEditorState.editStart || state == Asc.c_oAscCellEditorState.editEnd) {
toolbar.lockToolbar(SSE.enumLock.editCell, state == Asc.c_oAscCellEditorState.editStart, { toolbar.lockToolbar(SSE.enumLock.editCell, state == Asc.c_oAscCellEditorState.editStart, {
...@@ -1477,8 +1541,8 @@ define([ ...@@ -1477,8 +1541,8 @@ define([
}); });
var is_cell_edited = (state == Asc.c_oAscCellEditorState.editStart); var is_cell_edited = (state == Asc.c_oAscCellEditorState.editStart);
(is_cell_edited) ? Common.util.Shortcuts.suspendEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, alt+h') : (is_cell_edited) ? Common.util.Shortcuts.suspendEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, alt+h, command+1, ctrl+1') :
Common.util.Shortcuts.resumeEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, alt+h'); Common.util.Shortcuts.resumeEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, alt+h, command+1, ctrl+1');
if (is_cell_edited) { if (is_cell_edited) {
toolbar.listStyles.suspendEvents(); toolbar.listStyles.suspendEvents();
...@@ -1871,12 +1935,11 @@ define([ ...@@ -1871,12 +1935,11 @@ define([
toolbar.lockToolbar(SSE.enumLock.multiselect, this._state.multiselect, { array: [toolbar.btnTableTemplate, toolbar.btnInsertHyperlink]}); toolbar.lockToolbar(SSE.enumLock.multiselect, this._state.multiselect, { array: [toolbar.btnTableTemplate, toolbar.btnInsertHyperlink]});
} }
fontparam = toolbar.numFormatTypes[info.asc_getNumFormatType()]; val = info.asc_getNumFormatType();
if (this._state.numformattype !== val) {
if (!fontparam) toolbar.cmbNumberFormat.setValue(val, toolbar.txtCustom);
fontparam = toolbar.numFormatTypes[1]; this._state.numformattype = val;
}
toolbar.btnNumberFormat.setCaption(fontparam);
val = info.asc_getAngle(); val = info.asc_getAngle();
if (this._state.angle !== val) { if (this._state.angle !== val) {
...@@ -2532,10 +2595,10 @@ define([ ...@@ -2532,10 +2595,10 @@ define([
var left = toolbar.isCompactView ? 75 : (toolbar.mode.nativeApp ? 80 : 48 ); var left = toolbar.isCompactView ? 75 : (toolbar.mode.nativeApp ? 80 : 48 );
mask.css('left', left + 'px'); mask.css('left', left + 'px');
mask.css('right', (toolbar.isCompactView ? 0 : 45) + 'px'); mask.css('right', (toolbar.isCompactView ? 0 : 45) + 'px');
Common.util.Shortcuts.suspendEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, command+alt+h, ctrl+alt+h'); Common.util.Shortcuts.suspendEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, command+alt+h, ctrl+alt+h, command+1, ctrl+1');
} else { } else {
mask.remove(); mask.remove();
Common.util.Shortcuts.resumeEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, command+alt+h, ctrl+alt+h'); Common.util.Shortcuts.resumeEvents('command+l, ctrl+l, command+shift+l, ctrl+shift+l, command+k, ctrl+k, command+alt+h, ctrl+alt+h, command+1, ctrl+1');
} }
}, },
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
<div class="toolbar-row"> <div class="toolbar-row">
<span class="btn-placeholder split" id="id-toolbar-diagram-placeholder-btn-digit-dec"></span> <span class="btn-placeholder split" id="id-toolbar-diagram-placeholder-btn-digit-dec"></span>
<span class="btn-placeholder split" id="id-toolbar-diagram-placeholder-btn-digit-inc"></span> <span class="btn-placeholder split" id="id-toolbar-diagram-placeholder-btn-digit-inc"></span>
<span class="btn-placeholder border" id="id-toolbar-diagram-placeholder-btn-format" style="width: 84px; margin-left: 10px;"></span> <span class="btn-placeholder" id="id-toolbar-diagram-placeholder-btn-format" style="width: 84px; margin-left: 10px; vertical-align: middle;"></span>
</div> </div>
</div> </div>
<div class="separator short"></div> <div class="separator short"></div>
...@@ -124,7 +124,7 @@ ...@@ -124,7 +124,7 @@
<div class="toolbar-group"> <div class="toolbar-group">
<div class="toolbar-row"> <div class="toolbar-row">
<span class="btn-placeholder split" id="id-toolbar-short-placeholder-btn-filter"></span> <span class="btn-placeholder split" id="id-toolbar-short-placeholder-btn-filter"></span>
<span class="btn-placeholder border" id="id-toolbar-short-placeholder-btn-format" style="width: 84px; margin-left: 7px;"></span> <span class="btn-placeholder" id="id-toolbar-short-placeholder-btn-format" style="width: 84px; margin-left: 7px; vertical-align: middle;"></span>
</div> </div>
</div> </div>
<div class="separator short"></div> <div class="separator short"></div>
...@@ -249,7 +249,7 @@ ...@@ -249,7 +249,7 @@
<div class="separator long"></div> <div class="separator long"></div>
<div class="toolbar-group"> <div class="toolbar-group">
<div class="toolbar-row"> <div class="toolbar-row">
<span class="btn-placeholder border" id="id-toolbar-full-placeholder-btn-format" style="width: 100%;"></span> <span class="btn-placeholder" id="id-toolbar-full-placeholder-btn-format" style="width: 100%"></span>
</div> </div>
<div class="toolbar-row"> <div class="toolbar-row">
<span class="btn-placeholder split" id="id-toolbar-full-placeholder-btn-percents"></span> <span class="btn-placeholder split" id="id-toolbar-full-placeholder-btn-percents"></span>
......
...@@ -754,7 +754,16 @@ define([ ...@@ -754,7 +754,16 @@ define([
updateRegionalExample: function(landId) { updateRegionalExample: function(landId) {
if (this.api) { if (this.api) {
var text = (landId) ? this.api.asc_getLocaleExample(landId, 1000.01, new Date()) : ''; var text = '';
if (landId) {
var info = new Asc.asc_CFormatCellsInfo();
info.asc_setType(Asc.c_oAscNumFormatType.None);
info.asc_setSymbol(landId);
var arr = this.api.asc_getFormatCells(info); // all formats
text = this.api.asc_getLocaleExample(arr[4], 1000.01, landId);
text = text + ' ' + this.api.asc_getLocaleExample(arr[5], (new Date()).getExcelDateWithTime(), landId);
text = text + ' ' + this.api.asc_getLocaleExample(arr[6], (new Date()).getExcelDateWithTime(), landId);
}
$('#fms-lbl-reg-settings').text(_.isEmpty(text) ? '' : this.strRegSettingsEx + text); $('#fms-lbl-reg-settings').text(_.isEmpty(text) ? '' : this.strRegSettingsEx + text);
} }
}, },
......
This diff is collapsed.
...@@ -1045,6 +1045,35 @@ ...@@ -1045,6 +1045,35 @@
"SSE.Views.FileMenuPanels.MainSettingsGeneral.txtWin": "as Windows", "SSE.Views.FileMenuPanels.MainSettingsGeneral.txtWin": "as Windows",
"SSE.Views.FileMenuPanels.Settings.txtGeneral": "General", "SSE.Views.FileMenuPanels.Settings.txtGeneral": "General",
"SSE.Views.FileMenuPanels.Settings.txtPageSettings": "Page Settings", "SSE.Views.FileMenuPanels.Settings.txtPageSettings": "Page Settings",
"SSE.Views.FormatSettingsDialog.textTitle": "Number Format",
"SSE.Views.FormatSettingsDialog.textCategory": "Category",
"SSE.Views.FormatSettingsDialog.textDecimal": "Decimal",
"SSE.Views.FormatSettingsDialog.textSeparator": "Use 1000 separator",
"SSE.Views.FormatSettingsDialog.textFormat": "Format",
"SSE.Views.FormatSettingsDialog.textSymbols": "Symbols",
"SSE.Views.FormatSettingsDialog.textCancel": "Cancel",
"SSE.Views.FormatSettingsDialog.textOk": "OK",
"SSE.Views.FormatSettingsDialog.txtGeneral": "General",
"SSE.Views.FormatSettingsDialog.txtNumber": "Number",
"SSE.Views.FormatSettingsDialog.txtCustom": "Custom",
"SSE.Views.FormatSettingsDialog.txtCurrency": "Currency",
"SSE.Views.FormatSettingsDialog.txtAccounting": "Accounting",
"SSE.Views.FormatSettingsDialog.txtDate": "Date",
"SSE.Views.FormatSettingsDialog.txtTime": "Time",
"SSE.Views.FormatSettingsDialog.txtPercentage": "Percentage",
"SSE.Views.FormatSettingsDialog.txtFraction": "Fraction",
"SSE.Views.FormatSettingsDialog.txtScientific": "Scientific",
"SSE.Views.FormatSettingsDialog.txtText": "Text",
"SSE.Views.FormatSettingsDialog.txtUpto1": "Up to one digit",
"SSE.Views.FormatSettingsDialog.txtUpto2": "Up to two digits",
"SSE.Views.FormatSettingsDialog.txtUpto3": "Up to three digits",
"SSE.Views.FormatSettingsDialog.txtAs2": "As halfs",
"SSE.Views.FormatSettingsDialog.txtAs8": "As eighths",
"SSE.Views.FormatSettingsDialog.txtAs4": "As fourths",
"SSE.Views.FormatSettingsDialog.txtAs16": "As sixteenths",
"SSE.Views.FormatSettingsDialog.txtAs10": "As tenths",
"SSE.Views.FormatSettingsDialog.txtAs100": "As hundredths",
"SSE.Views.FormatSettingsDialog.txtSample": "Sample:",
"SSE.Views.FormulaDialog.cancelButtonText": "Cancel", "SSE.Views.FormulaDialog.cancelButtonText": "Cancel",
"SSE.Views.FormulaDialog.okButtonText": "OK", "SSE.Views.FormulaDialog.okButtonText": "OK",
"SSE.Views.FormulaDialog.sCategoryAll": "All", "SSE.Views.FormulaDialog.sCategoryAll": "All",
...@@ -1625,6 +1654,7 @@ ...@@ -1625,6 +1654,7 @@
"SSE.Views.Toolbar.textLineSpark": "Line", "SSE.Views.Toolbar.textLineSpark": "Line",
"SSE.Views.Toolbar.textColumnSpark": "Column", "SSE.Views.Toolbar.textColumnSpark": "Column",
"SSE.Views.Toolbar.textWinLossSpark": "Win/Loss", "SSE.Views.Toolbar.textWinLossSpark": "Win/Loss",
"SSE.Views.Toolbar.textMoreFormats": "More formats",
"SSE.Views.Top10FilterDialog.cancelButtonText": "Cancel", "SSE.Views.Top10FilterDialog.cancelButtonText": "Cancel",
"SSE.Views.Top10FilterDialog.okButtonText": "OK", "SSE.Views.Top10FilterDialog.okButtonText": "OK",
"SSE.Views.Top10FilterDialog.textType": "Show", "SSE.Views.Top10FilterDialog.textType": "Show",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment