Commit af7f2254 authored by Julia Radzhabova's avatar Julia Radzhabova Committed by GitHub

Merge pull request #15 from ONLYOFFICE/refactor

Refactor
parents de773f86 d38c8714
......@@ -218,7 +218,7 @@ define([
style : me.style
}));
if (me.menu && _.isFunction(me.menu.render))
if (me.menu && _.isObject(me.menu) && _.isFunction(me.menu.render))
me.menu.render(me.cmpEl);
parentEl.html(me.cmpEl);
......@@ -379,7 +379,7 @@ define([
}
if (me.disabled) {
me.setDisabled(me.disabled);
me.setDisabled(!(me.disabled=false));
}
me.trigger('render:after', me);
......@@ -414,7 +414,7 @@ define([
},
setDisabled: function(disabled) {
if (this.rendered) {
if (this.rendered && this.disabled != disabled) {
var el = this.cmpEl,
isGroup = el.hasClass('btn-group');
......@@ -489,6 +489,13 @@ define([
}
}
}
},
setMenu: function (m) {
if (m && _.isObject(m) && _.isFunction(m.render)){
this.menu = m;
this.menu.render(this.cmpEl);
}
}
});
});
......
......@@ -188,13 +188,6 @@ define([
Common.NotificationCenter.on('menumanager:hideall', _.bind(me.closeMenu, me));
this.scroller = new Common.UI.Scroller({
el: $('.dropdown-menu', me.cmpEl),
minScrollbarLength : 40,
scrollYMarginOffset: 30,
includePadding : true
});
// set default selection
this.setDefaultSelection();
......@@ -232,6 +225,15 @@ define([
},
onBeforeShowMenu: function(e) {
if ( !this.scroller ) {
this.scroller = new Common.UI.Scroller(_.extend({
el: $('.dropdown-menu', this.cmpEl),
minScrollbarLength: 40,
scrollYMarginOffset: 30,
includePadding: true
}, this.options.scroller));
}
Common.NotificationCenter.trigger('menu:show');
this.trigger('show:before', this, e);
if (this.options.hint) {
......@@ -525,12 +527,12 @@ define([
this.scroller.destroy();
delete this.scroller;
}
this.scroller = new Common.UI.Scroller({
this.scroller = new Common.UI.Scroller(_.extend({
el: $('.dropdown-menu', this.cmpEl),
minScrollbarLength : 40,
scrollYMarginOffset: 30,
includePadding : true
});
}, this.options.scroller));
}
}
})());
......
......@@ -85,11 +85,14 @@ define([
initialize : function(options) {
Common.UI.ComboBox.prototype.initialize.call(this, _.extend(options, {
displayField: 'name'
displayField: 'name',
scroller: {
alwaysVisibleY: true,
onChange: this.updateVisibleFontsTiles.bind(this)
}
}));
this.recent = _.isNumber(options.recent) ? options.recent : 3;
this.bindUpdateVisibleFontsTiles = _.bind(this.updateVisibleFontsTiles, this);
Common.NotificationCenter.on('fonts:change', _.bind(this.onApiChangeFont, this));
Common.NotificationCenter.on('fonts:load', _.bind(this.fillFonts, this));
......@@ -109,8 +112,6 @@ define([
this._input.on('keyup', _.bind(this.onInputKeyUp, this));
this._input.on('keydown', _.bind(this.onInputKeyDown, this));
this.scroller.update({alwaysVisibleY: true, onChange:this.bindUpdateVisibleFontsTiles});
return this;
},
......
......@@ -851,7 +851,7 @@ define([
if (window.styles_loaded) {
clearInterval(timer_sl);
toolbarController.getView('Toolbar').createDelayedElements();
toolbarController.createDelayedElements();
documentHolderController.getView('DocumentHolder').createDelayedElements();
me.loadLanguages();
......
......@@ -166,7 +166,7 @@ define([
// Create toolbar view
this.toolbar = this.createView('Toolbar');
this.toolbar.on('render:after', _.bind(this.onToolbarAfterRender, this));
// this.toolbar.on('render:after', _.bind(this.onToolbarAfterRender, this));
},
onToolbarAfterRender: function(toolbar) {
......@@ -2627,6 +2627,11 @@ define([
me._mailMergeDlg.show();
},
createDelayedElements: function() {
this.toolbar.createDelayedElements();
this.onToolbarAfterRender(this.toolbar);
},
textEmptyImgUrl : 'You need to specify image URL.',
textWarning : 'Warning',
textFontSizeErr : 'The entered value is incorrect.<br>Please enter a numeric value between 1 and 100',
......
......@@ -64,7 +64,6 @@ define([
},
initialize: function () {
var me = this;
this._initSettings = true;
this._state = {
......@@ -80,67 +79,6 @@ define([
this._locked = false;
this.render();
var _arrPosition = [
[c_pageNumPosition.PAGE_NUM_POSITION_TOP, c_pageNumPosition.PAGE_NUM_POSITION_LEFT, 'icon-right-panel btn-colontitul-tl', 'headerfooter-button-top-left', this.textTopLeft],
[c_pageNumPosition.PAGE_NUM_POSITION_TOP, c_pageNumPosition.PAGE_NUM_POSITION_CENTER, 'icon-right-panel btn-colontitul-tc', 'headerfooter-button-top-center', this.textTopCenter],
[c_pageNumPosition.PAGE_NUM_POSITION_TOP, c_pageNumPosition.PAGE_NUM_POSITION_RIGHT, 'icon-right-panel btn-colontitul-tr', 'headerfooter-button-top-right', this.textTopRight],
[c_pageNumPosition.PAGE_NUM_POSITION_BOTTOM, c_pageNumPosition.PAGE_NUM_POSITION_LEFT, 'icon-right-panel btn-colontitul-bl', 'headerfooter-button-bottom-left', this.textBottomLeft],
[c_pageNumPosition.PAGE_NUM_POSITION_BOTTOM, c_pageNumPosition.PAGE_NUM_POSITION_CENTER, 'icon-right-panel btn-colontitul-bc', 'headerfooter-button-bottom-center', this.textBottomCenter],
[c_pageNumPosition.PAGE_NUM_POSITION_BOTTOM, c_pageNumPosition.PAGE_NUM_POSITION_RIGHT, 'icon-right-panel btn-colontitul-br', 'headerfooter-button-bottom-right', this.textBottomRight]
];
this._btnsPosition = [];
_.each(_arrPosition, function(item, index, list){
var _btn = new Common.UI.Button({
cls: 'btn-options huge',
iconCls: item[2],
posWhere:item[0],
posAlign:item[1],
hint: item[4]
});
_btn.render( $('#'+item[3])) ;
_btn.on('click', _.bind(this.onBtnPositionClick, this));
this._btnsPosition.push( _btn );
this.lockedControls.push(_btn);
}, this);
this.numPosition = new Common.UI.MetricSpinner({
el: $('#headerfooter-spin-position'),
step: .1,
width: 85,
value: '1.25 cm',
defaultUnit : "cm",
maxValue: 55.88,
minValue: 0
});
this.spinners.push(this.numPosition);
this.lockedControls.push(this.numPosition);
this.lblPosition = $(this.el).find('#headerfooter-label-position');
this.chDiffFirst = new Common.UI.CheckBox({
el: $('#headerfooter-check-diff-first'),
labelText: this.textDiffFirst
});
this.lockedControls.push(this.chDiffFirst);
this.chDiffOdd = new Common.UI.CheckBox({
el: $('#headerfooter-check-diff-odd'),
labelText: this.textDiffOdd
});
this.lockedControls.push(this.chDiffOdd);
this.chSameAs = new Common.UI.CheckBox({
el: $('#headerfooter-check-same-as'),
labelText: this.textSameAs
});
this.lockedControls.push(this.chSameAs);
this.numPosition.on('change', _.bind(this.onNumPositionChange, this));
this.chDiffFirst.on('change', _.bind(this.onDiffFirstChange, this));
this.chDiffOdd.on('change', _.bind(this.onDiffOddChange, this));
this.chSameAs.on('change', _.bind(this.onSameAsChange, this));
},
render: function () {
......@@ -240,7 +178,71 @@ define([
}
},
createDelayedControls: function() {
var _arrPosition = [
[c_pageNumPosition.PAGE_NUM_POSITION_TOP, c_pageNumPosition.PAGE_NUM_POSITION_LEFT, 'icon-right-panel btn-colontitul-tl', 'headerfooter-button-top-left', this.textTopLeft],
[c_pageNumPosition.PAGE_NUM_POSITION_TOP, c_pageNumPosition.PAGE_NUM_POSITION_CENTER, 'icon-right-panel btn-colontitul-tc', 'headerfooter-button-top-center', this.textTopCenter],
[c_pageNumPosition.PAGE_NUM_POSITION_TOP, c_pageNumPosition.PAGE_NUM_POSITION_RIGHT, 'icon-right-panel btn-colontitul-tr', 'headerfooter-button-top-right', this.textTopRight],
[c_pageNumPosition.PAGE_NUM_POSITION_BOTTOM, c_pageNumPosition.PAGE_NUM_POSITION_LEFT, 'icon-right-panel btn-colontitul-bl', 'headerfooter-button-bottom-left', this.textBottomLeft],
[c_pageNumPosition.PAGE_NUM_POSITION_BOTTOM, c_pageNumPosition.PAGE_NUM_POSITION_CENTER, 'icon-right-panel btn-colontitul-bc', 'headerfooter-button-bottom-center', this.textBottomCenter],
[c_pageNumPosition.PAGE_NUM_POSITION_BOTTOM, c_pageNumPosition.PAGE_NUM_POSITION_RIGHT, 'icon-right-panel btn-colontitul-br', 'headerfooter-button-bottom-right', this.textBottomRight]
];
this._btnsPosition = [];
_.each(_arrPosition, function(item, index, list){
var _btn = new Common.UI.Button({
cls: 'btn-options huge',
iconCls: item[2],
posWhere:item[0],
posAlign:item[1],
hint: item[4]
});
_btn.render( $('#'+item[3])) ;
_btn.on('click', _.bind(this.onBtnPositionClick, this));
this._btnsPosition.push( _btn );
this.lockedControls.push(_btn);
}, this);
this.numPosition = new Common.UI.MetricSpinner({
el: $('#headerfooter-spin-position'),
step: .1,
width: 85,
value: '1.25 cm',
defaultUnit : "cm",
maxValue: 55.88,
minValue: 0
});
this.spinners.push(this.numPosition);
this.lockedControls.push(this.numPosition);
this.lblPosition = $(this.el).find('#headerfooter-label-position');
this.chDiffFirst = new Common.UI.CheckBox({
el: $('#headerfooter-check-diff-first'),
labelText: this.textDiffFirst
});
this.lockedControls.push(this.chDiffFirst);
this.chDiffOdd = new Common.UI.CheckBox({
el: $('#headerfooter-check-diff-odd'),
labelText: this.textDiffOdd
});
this.lockedControls.push(this.chDiffOdd);
this.chSameAs = new Common.UI.CheckBox({
el: $('#headerfooter-check-same-as'),
labelText: this.textSameAs
});
this.lockedControls.push(this.chSameAs);
this.numPosition.on('change', _.bind(this.onNumPositionChange, this));
this.chDiffFirst.on('change', _.bind(this.onDiffFirstChange, this));
this.chDiffOdd.on('change', _.bind(this.onDiffOddChange, this));
this.chSameAs.on('change', _.bind(this.onSameAsChange, this));
},
createDelayedElements: function() {
this.createDelayedControls();
this.updateMetricUnit();
},
......@@ -249,6 +251,8 @@ define([
},
disableControls: function(disable) {
if (this._initSettings) return;
if (this._state.DisabledControls!==disable) {
this._state.DisabledControls = disable;
_.each(this.lockedControls, function(item) {
......
......@@ -64,7 +64,6 @@ define([
},
initialize: function () {
var me = this;
this._initSettings = true;
this._state = {
......@@ -84,7 +83,35 @@ define([
this.render();
var viewData = [
this.labelWidth = $(this.el).find('#image-label-width');
this.labelHeight = $(this.el).find('#image-label-height');
},
render: function () {
var el = $(this.el);
el.html(this.template({
scope: this
}));
},
setApi: function(api) {
this.api = api;
if (this.api)
this.api.asc_registerCallback('asc_onImgWrapStyleChanged', _.bind(this._ImgWrapStyleChanged, this));
return this;
},
updateMetricUnit: function() {
var value = Common.Utils.Metric.fnRecalcFromMM(this._state.Width);
this.labelWidth[0].innerHTML = this.textWidth + ': ' + value.toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName();
value = Common.Utils.Metric.fnRecalcFromMM(this._state.Height);
this.labelHeight[0].innerHTML = this.textHeight + ': ' + value.toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName();
},
createDelayedControls: function() {
var me = this,
viewData = [
{ offsetx: 0, data: Asc.c_oAscWrapStyle2.Inline, iconcls:'wrap-inline', tip: this.txtInline, selected: true },
{ offsetx: 50, data: Asc.c_oAscWrapStyle2.Square, iconcls:'wrap-square', tip: this.txtSquare },
{ offsetx: 100, data: Asc.c_oAscWrapStyle2.Tight, iconcls:'wrap-tight', tip: this.txtTight },
......@@ -116,9 +143,6 @@ define([
this.mnuWrapPicker.on('item:click', _.bind(this.onSelectWrap, this, this.btnWrapType));
this.lockedControls.push(this.btnWrapType);
this.labelWidth = $(this.el).find('#image-label-width');
this.labelHeight = $(this.el).find('#image-label-height');
this.btnOriginalSize = new Common.UI.Button({
el: $('#image-button-original-size')
});
......@@ -149,35 +173,14 @@ define([
if (this.api) this.api.asc_pluginRun(this._originalProps.asc_getPluginGuid(), 0, this._originalProps.asc_getPluginData());
this.fireEvent('editcomplete', this);
}, this));
$(this.el).on('click', '#image-advanced-link', _.bind(this.openAdvancedSettings, this));
},
render: function () {
var el = $(this.el);
el.html(this.template({
scope: this
}));
this.linkAdvanced = $('#image-advanced-link');
this.lblReplace = $('#image-lbl-replace');
$(this.el).on('click', '#image-advanced-link', _.bind(this.openAdvancedSettings, this));
},
setApi: function(api) {
this.api = api;
if (this.api)
this.api.asc_registerCallback('asc_onImgWrapStyleChanged', _.bind(this._ImgWrapStyleChanged, this));
return this;
},
updateMetricUnit: function() {
var value = Common.Utils.Metric.fnRecalcFromMM(this._state.Width);
this.labelWidth[0].innerHTML = this.textWidth + ': ' + value.toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName();
value = Common.Utils.Metric.fnRecalcFromMM(this._state.Height);
this.labelHeight[0].innerHTML = this.textHeight + ': ' + value.toFixed(1) + ' ' + Common.Utils.Metric.getCurrentMetricName();
},
createDelayedElements: function() {
this.createDelayedControls();
this.updateMetricUnit();
},
......@@ -248,6 +251,7 @@ define([
},
_ImgWrapStyleChanged: function(style) {
if (!this.mnuWrapPicker) return;
if (this._state.WrappingStyle!==style) {
this._noApply = true;
var record = this.mnuWrapPicker.store.findWhere({data: style});
......@@ -387,6 +391,8 @@ define([
},
disableControls: function(disable) {
if (this._initSettings) return;
if (this._state.DisabledControls!==disable) {
this._state.DisabledControls = disable;
_.each(this.lockedControls, function(item) {
......
......@@ -72,7 +72,9 @@ define([
},
initialize: function () {
var me = this;
var me = this,
_set = DE.enumLockMM;
this._initSettings = true;
this._state = {
......@@ -88,18 +90,8 @@ define([
this.emailAddresses = undefined;
this.mergeMailData = undefined;
var _set = DE.enumLockMM;
this.render();
this.btnEditData = new Common.UI.Button({
el: me.$el.find('#mmerge-button-edit-data'),
lock: [_set.preview, _set.lostConnect]
});
this.btnEditData.on('click', _.bind(this.onEditData, this));
this.lblAddRecipients = $('#mmerge-lbl-add-recipients');
this.btnInsField = new Common.UI.Button({
cls: 'btn-text-menu-default',
caption: this.textInsertField,
......@@ -120,19 +112,6 @@ define([
});
this.btnInsField.render( $('#mmerge-btn-ins-field',me.$el)) ;
this.chHighlight = new Common.UI.Switcher({
el: me.$el.find('#mmerge-switcher-highlight'),
lock: [_set.noFields, _set.lostConnect]
});
this.chHighlight.on('change', _.bind(this.onCheckHighlightChange, this));
this.chPreview = new Common.UI.Switcher({
el: me.$el.find('#mmerge-switcher-preview'),
lock: [_set.noRecipients, _set.lostConnect]
});
this.chPreview.on('change', _.bind(this.onCheckPreviewChange, this));
this.emptyDBControls.push(this.chPreview);
this.txtFieldNum = new Common.UI.InputField({
el : $('#mmerge-field-num', me.$el),
allowBlank : true,
......@@ -161,6 +140,52 @@ define([
}
});
this.emptyDBControls.push(this.txtFieldNum);
},
render: function () {
this.$el.html(this.template({
scope: this
}));
},
setApi: function(api) {
this.api = api;
if (this.api) {
this.api.asc_registerCallback('asc_onPreviewMailMergeResult', _.bind(this.onPreviewMailMergeResult, this));
this.api.asc_registerCallback('asc_onEndPreviewMailMergeResult', _.bind(this.onEndPreviewMailMergeResult, this));
this.api.asc_registerCallback('asc_onStartMailMerge', _.bind(this.onStartMailMerge, this));
this.api.asc_registerCallback('asc_onSaveMailMerge', _.bind(this.onSaveMailMerge, this));
this.api.asc_registerCallback('asc_onEndAction', _.bind(this.onLongActionEnd, this));
Common.Gateway.on('setemailaddresses', _.bind(this.onSetEmailAddresses, this));
Common.Gateway.on('processmailmerge', _.bind(this.onProcessMailMerge, this));
}
return this;
},
createDelayedControls: function() {
var me = this,
_set = DE.enumLockMM;
this.btnEditData = new Common.UI.Button({
el: me.$el.find('#mmerge-button-edit-data'),
lock: [_set.preview, _set.lostConnect]
});
this.btnEditData.on('click', _.bind(this.onEditData, this));
this.lblAddRecipients = $('#mmerge-lbl-add-recipients');
this.chHighlight = new Common.UI.Switcher({
el: me.$el.find('#mmerge-switcher-highlight'),
lock: [_set.noFields, _set.lostConnect]
});
this.chHighlight.on('change', _.bind(this.onCheckHighlightChange, this));
this.chPreview = new Common.UI.Switcher({
el: me.$el.find('#mmerge-switcher-preview'),
lock: [_set.noRecipients, _set.lostConnect]
});
this.chPreview.on('change', _.bind(this.onCheckPreviewChange, this));
this.emptyDBControls.push(this.chPreview);
this.btnFirst = new Common.UI.Button({
cls: 'btn-toolbar',
......@@ -343,32 +368,26 @@ define([
}).on('click', _.bind(this.onMergeClick, this, false));
this.emptyDBControls.push(this.btnMerge);
this.$el.on('click', '#mmerge-readmore-link', _.bind(this.openHelp, this));
},
render: function () {
this.$el.html(this.template({
scope: this
}));
this.linkReadMore = $('#mmerge-readmore-link', this.$el);
},
this.$el.on('click', '#mmerge-readmore-link', _.bind(this.openHelp, this));
setApi: function(api) {
this.api = api;
if (this.api) {
this.api.asc_registerCallback('asc_onPreviewMailMergeResult', _.bind(this.onPreviewMailMergeResult, this));
this.api.asc_registerCallback('asc_onEndPreviewMailMergeResult', _.bind(this.onEndPreviewMailMergeResult, this));
this.api.asc_registerCallback('asc_onStartMailMerge', _.bind(this.onStartMailMerge, this));
this.api.asc_registerCallback('asc_onSaveMailMerge', _.bind(this.onSaveMailMerge, this));
this.api.asc_registerCallback('asc_onEndAction', _.bind(this.onLongActionEnd, this));
Common.Gateway.on('setemailaddresses', _.bind(this.onSetEmailAddresses, this));
Common.Gateway.on('processmailmerge', _.bind(this.onProcessMailMerge, this));
if (this.mode) {
if (!this.mode.mergeFolderUrl)
this.btnPortal.setVisible(false);
if (!this.mode.canSendEmailAddresses) {
this._arrMergeSrc.pop();
this.cmbMergeTo.setData(this._arrMergeSrc);
this.cmbMergeTo.setValue(this._arrMergeSrc[0].value);
}
}
return this;
},
ChangeSettings: function(props) {
if (this._initSettings) {
this.createDelayedControls();
this._initSettings = false;
}
this.disableInsertControls(this._locked);
if (props) {
......@@ -763,6 +782,8 @@ define([
},
disableControls: function(disable) {
if (this._initSettings) return;
this.lockControls(DE.enumLockMM.lostConnect, disable, {
array: _.union([this.btnEditData, this.btnInsField, this.chHighlight], (this.mode.mergeFolderUrl) ? [this.btnPortal] : []),
merge: true
......@@ -775,13 +796,6 @@ define([
setMode: function(mode) {
this.mode = mode;
if (!this.mode.mergeFolderUrl)
this.btnPortal.setVisible(false);
if (!this.mode.canSendEmailAddresses) {
this._arrMergeSrc.pop();
this.cmbMergeTo.setData(this._arrMergeSrc);
this.cmbMergeTo.setValue(this._arrMergeSrc[0].value);
}
},
disableEditing: function(disable) {
......@@ -807,7 +821,7 @@ define([
},
disablePreviewMode: function() {
if (this.api && this.chPreview.getValue()) {
if (this.api && this.chPreview && this.chPreview.getValue()) {
this.api.asc_EndPreviewMailMergeResult();
}
},
......
......@@ -67,7 +67,6 @@ define([
},
initialize: function () {
var me = this;
this._initSettings = true;
this._state = {
......@@ -157,22 +156,8 @@ define([
this.btnColor = new Common.UI.ColorButton({
style: "width:45px;",
disabled: this._locked,
menu : new Common.UI.Menu({
items: [
{ template: _.template('<div id="paragraph-color-menu" style="width: 165px; height: 220px; margin: 10px;"></div>') },
{ template: _.template('<a id="paragraph-color-new" style="padding-left:12px;">' + me.textNewColor + '</a>') }
]
})
});
this.btnColor.on('render:after', function(btn) {
me.mnuColorPicker = new Common.UI.ThemeColorPalette({
el: $('#paragraph-color-menu'),
transparent: true
});
me.mnuColorPicker.on('select', _.bind(me.onColorPickerSelect, me));
menu : true
});
this.btnColor.render( $('#paragraph-color-btn'));
this.lockedControls.push(this.btnColor);
......@@ -456,8 +441,20 @@ define([
},
UpdateThemeColors: function() {
if (this.mnuColorPicker)
this.mnuColorPicker.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors());
if (!this.mnuColorPicker) {
this.btnColor.setMenu( new Common.UI.Menu({
items: [
{ template: _.template('<div id="paragraph-color-menu" style="width: 165px; height: 220px; margin: 10px;"></div>') },
{ template: _.template('<a id="paragraph-color-new" style="padding-left:12px;">' + this.textNewColor + '</a>') }
]
}));
this.mnuColorPicker = new Common.UI.ThemeColorPalette({
el: $('#paragraph-color-menu'),
transparent: true
});
this.mnuColorPicker.on('select', _.bind(this.onColorPickerSelect, this));
}
this.mnuColorPicker.updateColors(Common.Utils.ThemeColor.getEffectColors(), Common.Utils.ThemeColor.getStandartColors());
},
onHideMenus: function(e){
......
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