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

Merge pull request #36 from ONLYOFFICE/feature/refactor

Feature/refactor
parents 1bcc69da f5fb3f94
...@@ -494,9 +494,10 @@ define([ ...@@ -494,9 +494,10 @@ define([
}, },
setMenu: function (m) { setMenu: function (m) {
if (this.rendered && m && _.isObject(m) && _.isFunction(m.render)){ if (m && _.isObject(m) && _.isFunction(m.render)){
this.menu = m; this.menu = m;
this.menu.render(this.cmpEl); if (this.rendered)
this.menu.render(this.cmpEl);
} }
} }
}); });
......
...@@ -653,18 +653,19 @@ define([ ...@@ -653,18 +653,19 @@ define([
if (window.styles_loaded) { if (window.styles_loaded) {
clearInterval(timer_sl); clearInterval(timer_sl);
toolbarController.getView('Toolbar').createDelayedElements(); toolbarController.createDelayedElements();
documentHolderController.getView('DocumentHolder').createDelayedElements(); documentHolderController.getView('DocumentHolder').createDelayedElements();
rightmenuController.createDelayedElements();
me.api.asc_registerCallback('asc_onFocusObject', _.bind(me.onFocusObject, me));
me.api.asc_registerCallback('asc_onUpdateLayout', _.bind(me.fillLayoutsStore, me)); // slide layouts loading me.api.asc_registerCallback('asc_onUpdateLayout', _.bind(me.fillLayoutsStore, me)); // slide layouts loading
me.updateThemeColors(); me.updateThemeColors();
var shapes = me.api.asc_getPropertyEditorShapes(); var shapes = me.api.asc_getPropertyEditorShapes();
if (shapes) if (shapes)
me.fillAutoShapes(shapes[0], shapes[1]); me.fillAutoShapes(shapes[0], shapes[1]);
rightmenuController.createDelayedElements();
me.api.asc_registerCallback('asc_onFocusObject', _.bind(me.onFocusObject, me));
me.fillTextArt(me.api.asc_getTextArtPreviews()); me.fillTextArt(me.api.asc_getTextArtPreviews());
toolbarController.activateControls(); toolbarController.activateControls();
if (me.needToUpdateVersion) if (me.needToUpdateVersion)
......
...@@ -246,6 +246,7 @@ define([ ...@@ -246,6 +246,7 @@ define([
if (this.editMode && this.api) { if (this.editMode && this.api) {
this.api.asc_registerCallback('asc_doubleClickOnObject', _.bind(this.onDoubleClickOnObject, this)); this.api.asc_registerCallback('asc_doubleClickOnObject', _.bind(this.onDoubleClickOnObject, this));
this.rightmenu.shapeSettings.createDelayedElements();
var selectedElements = this.api.getSelectedElements(); var selectedElements = this.api.getSelectedElements();
if (selectedElements.length>0) { if (selectedElements.length>0) {
var open = Common.localStorage.getItem("pe-hide-right-settings"); var open = Common.localStorage.getItem("pe-hide-right-settings");
......
...@@ -171,7 +171,7 @@ define([ ...@@ -171,7 +171,7 @@ define([
// Create toolbar view // Create toolbar view
this.toolbar = this.createView('Toolbar'); 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) { onToolbarAfterRender: function(toolbar) {
...@@ -699,6 +699,7 @@ define([ ...@@ -699,6 +699,7 @@ define([
$('.menu-zoom .zoom', this.toolbar.el).html(percent + '%'); $('.menu-zoom .zoom', this.toolbar.el).html(percent + '%');
this._state.zoom_percent = percent; this._state.zoom_percent = percent;
} }
this.toolbar.mnuZoom.options.value = percent;
}, },
onApiInitEditorStyles: function(themes) { onApiInitEditorStyles: function(themes) {
...@@ -1829,6 +1830,11 @@ define([ ...@@ -1829,6 +1830,11 @@ define([
} }
}, },
createDelayedElements: function() {
this.toolbar.createDelayedElements();
this.onToolbarAfterRender(this.toolbar);
},
textEmptyImgUrl : 'You need to specify image URL.', textEmptyImgUrl : 'You need to specify image URL.',
textWarning : 'Warning', textWarning : 'Warning',
textFontSizeErr : 'The entered value must be more than 0', textFontSizeErr : 'The entered value must be more than 0',
......
...@@ -64,7 +64,6 @@ define([ ...@@ -64,7 +64,6 @@ define([
}, },
initialize: function () { initialize: function () {
var me = this;
this._initSettings = true; this._initSettings = true;
this._state = { this._state = {
...@@ -83,7 +82,29 @@ define([ ...@@ -83,7 +82,29 @@ define([
this.labelWidth = $(this.el).find('#image-label-width'); this.labelWidth = $(this.el).find('#image-label-width');
this.labelHeight = $(this.el).find('#image-label-height'); 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;
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() {
this.btnOriginalSize = new Common.UI.Button({ this.btnOriginalSize = new Common.UI.Button({
el: $('#image-button-original-size') el: $('#image-button-original-size')
}); });
...@@ -103,7 +124,7 @@ define([ ...@@ -103,7 +124,7 @@ define([
el: $('#image-button-edit-object') el: $('#image-button-edit-object')
}); });
this.lockedControls.push(this.btnEditObject); this.lockedControls.push(this.btnEditObject);
this.btnOriginalSize.on('click', _.bind(this.setOriginalSize, this)); this.btnOriginalSize.on('click', _.bind(this.setOriginalSize, this));
this.btnInsertFromFile.on('click', _.bind(function(btn){ this.btnInsertFromFile.on('click', _.bind(function(btn){
if (this.api) this.api.ChangeImageFromFile(); if (this.api) this.api.ChangeImageFromFile();
...@@ -114,41 +135,21 @@ define([ ...@@ -114,41 +135,21 @@ define([
if (this.api) this.api.asc_pluginRun(this._originalProps.asc_getPluginGuid(), 0, this._originalProps.asc_getPluginData()); if (this.api) this.api.asc_pluginRun(this._originalProps.asc_getPluginGuid(), 0, this._originalProps.asc_getPluginData());
this.fireEvent('editcomplete', this); this.fireEvent('editcomplete', this);
}, 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.linkAdvanced = $('#image-advanced-link');
this.lblReplace = $('#image-lbl-replace'); this.lblReplace = $('#image-lbl-replace');
}, $(this.el).on('click', '#image-advanced-link', _.bind(this.openAdvancedSettings, this));
setApi: function(api) {
this.api = api;
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() { createDelayedElements: function() {
this.createDelayedControls();
this.updateMetricUnit(); this.updateMetricUnit();
this._initSettings = false;
}, },
ChangeSettings: function(props) { ChangeSettings: function(props) {
if (this._initSettings) { if (this._initSettings)
this.createDelayedElements(); this.createDelayedElements();
this._initSettings = false;
}
this.disableControls(this._locked); this.disableControls(this._locked);
...@@ -269,6 +270,8 @@ define([ ...@@ -269,6 +270,8 @@ define([
}, },
disableControls: function(disable) { disableControls: function(disable) {
if (this._initSettings) return;
if (this._state.DisabledControls!==disable) { if (this._state.DisabledControls!==disable) {
this._state.DisabledControls = disable; this._state.DisabledControls = disable;
_.each(this.lockedControls, function(item) { _.each(this.lockedControls, function(item) {
......
...@@ -64,7 +64,6 @@ define([ ...@@ -64,7 +64,6 @@ define([
}, },
initialize: function () { initialize: function () {
var me = this;
this._initSettings = true; this._initSettings = true;
this._state = { this._state = {
...@@ -79,68 +78,6 @@ define([ ...@@ -79,68 +78,6 @@ define([
this._locked = false; this._locked = false;
this.render(); this.render();
this._arrLineRule = [
{displayValue: this.textAuto, defaultValue: 1, value: c_paragraphLinerule.LINERULE_AUTO, minValue: 0.5, step: 0.01, defaultUnit: ''},
{displayValue: this.textExact, defaultValue: 5, value: c_paragraphLinerule.LINERULE_EXACT, minValue: 0.03, step: 0.01, defaultUnit: 'cm'}
];
// Short Size
this.cmbLineRule = new Common.UI.ComboBox({
el: $('#paragraph-combo-line-rule'),
cls: 'input-group-nr',
menuStyle: 'min-width: 85px;',
editable: false,
data: this._arrLineRule
});
this.cmbLineRule.setValue(c_paragraphLinerule.LINERULE_AUTO);
this.lockedControls.push(this.cmbLineRule);
this.numLineHeight = new Common.UI.MetricSpinner({
el: $('#paragraph-spin-line-height'),
step: .01,
width: 85,
value: '1.5',
defaultUnit : "",
maxValue: 132,
minValue: 0.5
});
this.lockedControls.push(this.numLineHeight);
this.numSpacingBefore = new Common.UI.MetricSpinner({
el: $('#paragraph-spin-spacing-before'),
step: .1,
width: 85,
value: '0 cm',
defaultUnit : "cm",
maxValue: 55.88,
minValue: 0,
allowAuto : true,
autoText : this.txtAutoText
});
this.spinners.push(this.numSpacingBefore);
this.lockedControls.push(this.numSpacingBefore);
this.numSpacingAfter = new Common.UI.MetricSpinner({
el: $('#paragraph-spin-spacing-after'),
step: .1,
width: 85,
value: '0.35 cm',
defaultUnit : "cm",
maxValue: 55.88,
minValue: 0,
allowAuto : true,
autoText : this.txtAutoText
});
this.spinners.push(this.numSpacingAfter);
this.lockedControls.push(this.numSpacingAfter);
this.numLineHeight.on('change', _.bind(this.onNumLineHeightChange, this));
this.numSpacingBefore.on('change', _.bind(this.onNumSpacingBeforeChange, this));
this.numSpacingAfter.on('change', _.bind(this.onNumSpacingAfterChange, this));
this.cmbLineRule.on('selected', _.bind(this.onLineRuleSelect, this));
this.cmbLineRule.on('hide:after', _.bind(this.onHideMenus, this));
$(this.el).on('click', '#paragraph-advanced-link', _.bind(this.openAdvancedSettings, this));
}, },
render: function () { render: function () {
...@@ -200,6 +137,8 @@ define([ ...@@ -200,6 +137,8 @@ define([
}, },
_onLineSpacing: function(value) { _onLineSpacing: function(value) {
if (this._initSettings) return;
var linerule = value.get_LineRule(); var linerule = value.get_LineRule();
var line = value.get_Line(); var line = value.get_Line();
...@@ -229,10 +168,8 @@ define([ ...@@ -229,10 +168,8 @@ define([
}, },
ChangeSettings: function(prop) { ChangeSettings: function(prop) {
if (this._initSettings) { if (this._initSettings)
this.createDelayedElements(); this.createDelayedElements();
this._initSettings = false;
}
this.disableControls(this._locked); this.disableControls(this._locked);
...@@ -297,22 +234,92 @@ define([ ...@@ -297,22 +234,92 @@ define([
spinner.setStep(Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt ? 1 : 0.01); spinner.setStep(Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt ? 1 : 0.01);
} }
} }
var rec = this.cmbLineRule.store.at(1); if (this.cmbLineRule) {
rec.set({defaultUnit: Common.Utils.Metric.getCurrentMetricName(), var rec = this.cmbLineRule.store.at(1);
minValue: parseFloat(Common.Utils.Metric.fnRecalcFromMM(0.3).toFixed(2)), rec.set({defaultUnit: Common.Utils.Metric.getCurrentMetricName(),
step: (Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt) ? 1 : 0.01}); minValue: parseFloat(Common.Utils.Metric.fnRecalcFromMM(0.3).toFixed(2)),
step: (Common.Utils.Metric.getCurrentMetric()==Common.Utils.Metric.c_MetricUnits.pt) ? 1 : 0.01});
if (this._state.LineRule !== null) {
var obj; if (this._state.LineRule !== null) {
rec = this.cmbLineRule.store.findWhere((obj={}, obj['value']=this._state.LineRule, obj)); var obj;
if (!rec) rec = this.cmbLineRule.store.at(0); rec = this.cmbLineRule.store.findWhere((obj={}, obj['value']=this._state.LineRule, obj));
this.numLineHeight.setDefaultUnit(rec.get('defaultUnit')); if (!rec) rec = this.cmbLineRule.store.at(0);
this.numLineHeight.setStep(rec.get('step')); this.numLineHeight.setDefaultUnit(rec.get('defaultUnit'));
this.numLineHeight.setStep(rec.get('step'));
}
} }
}, },
createDelayedControls: function() {
var me = this;
this._arrLineRule = [
{displayValue: this.textAuto, defaultValue: 1, value: c_paragraphLinerule.LINERULE_AUTO, minValue: 0.5, step: 0.01, defaultUnit: ''},
{displayValue: this.textExact, defaultValue: 5, value: c_paragraphLinerule.LINERULE_EXACT, minValue: 0.03, step: 0.01, defaultUnit: 'cm'}
];
// Short Size
this.cmbLineRule = new Common.UI.ComboBox({
el: $('#paragraph-combo-line-rule'),
cls: 'input-group-nr',
menuStyle: 'min-width: 85px;',
editable: false,
data: this._arrLineRule
});
this.cmbLineRule.setValue(c_paragraphLinerule.LINERULE_AUTO);
this.lockedControls.push(this.cmbLineRule);
this.numLineHeight = new Common.UI.MetricSpinner({
el: $('#paragraph-spin-line-height'),
step: .01,
width: 85,
value: '1.5',
defaultUnit : "",
maxValue: 132,
minValue: 0.5
});
this.lockedControls.push(this.numLineHeight);
this.numSpacingBefore = new Common.UI.MetricSpinner({
el: $('#paragraph-spin-spacing-before'),
step: .1,
width: 85,
value: '0 cm',
defaultUnit : "cm",
maxValue: 55.88,
minValue: 0,
allowAuto : true,
autoText : this.txtAutoText
});
this.spinners.push(this.numSpacingBefore);
this.lockedControls.push(this.numSpacingBefore);
this.numSpacingAfter = new Common.UI.MetricSpinner({
el: $('#paragraph-spin-spacing-after'),
step: .1,
width: 85,
value: '0.35 cm',
defaultUnit : "cm",
maxValue: 55.88,
minValue: 0,
allowAuto : true,
autoText : this.txtAutoText
});
this.spinners.push(this.numSpacingAfter);
this.lockedControls.push(this.numSpacingAfter);
this.numLineHeight.on('change', _.bind(this.onNumLineHeightChange, this));
this.numSpacingBefore.on('change', _.bind(this.onNumSpacingBeforeChange, this));
this.numSpacingAfter.on('change', _.bind(this.onNumSpacingAfterChange, this));
this.cmbLineRule.on('selected', _.bind(this.onLineRuleSelect, this));
this.cmbLineRule.on('hide:after', _.bind(this.onHideMenus, this));
$(this.el).on('click', '#paragraph-advanced-link', _.bind(this.openAdvancedSettings, this));
},
createDelayedElements: function() { createDelayedElements: function() {
this.createDelayedControls();
this.updateMetricUnit(); this.updateMetricUnit();
this._initSettings = false;
}, },
openAdvancedSettings: function(e) { openAdvancedSettings: function(e) {
...@@ -357,6 +364,8 @@ define([ ...@@ -357,6 +364,8 @@ define([
}, },
disableControls: function(disable) { disableControls: function(disable) {
if (this._initSettings) return;
if (this._state.DisabledControls!==disable) { if (this._state.DisabledControls!==disable) {
this._state.DisabledControls = disable; this._state.DisabledControls = disable;
_.each(this.lockedControls, function(item) { _.each(this.lockedControls, function(item) {
......
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