From 937fb92e2c4a2c40824ae25ed4801428787b1b3f Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 17 Jun 2022 00:17:00 +0300 Subject: [PATCH 1/4] [DE] Forms: add width rule option --- .../main/lib/component/MetricSpinner.js | 4 + .../main/app/template/FormSettings.template | 19 ++++- .../main/app/view/FormSettings.js | 79 ++++++++++++++++--- 3 files changed, 86 insertions(+), 16 deletions(-) diff --git a/apps/common/main/lib/component/MetricSpinner.js b/apps/common/main/lib/component/MetricSpinner.js index e44b19381..519cf91e4 100644 --- a/apps/common/main/lib/component/MetricSpinner.js +++ b/apps/common/main/lib/component/MetricSpinner.js @@ -567,6 +567,10 @@ define([ this.options.defaultValue = value; }, + getDefaultValue: function() { + return this.options.defaultValue; + }, + checkAutoText: function(value) { if (this.options.allowAuto && typeof value == 'string') { var val = value.toLowerCase(); diff --git a/apps/documenteditor/main/app/template/FormSettings.template b/apps/documenteditor/main/app/template/FormSettings.template index 50dd09c3e..575cca8b3 100644 --- a/apps/documenteditor/main/app/template/FormSettings.template +++ b/apps/documenteditor/main/app/template/FormSettings.template @@ -94,17 +94,28 @@
+ + - - + + + + +
- -
+
+
+ +
+
+
+
+
diff --git a/apps/documenteditor/main/app/view/FormSettings.js b/apps/documenteditor/main/app/view/FormSettings.js index 672f156e9..cb48715a1 100644 --- a/apps/documenteditor/main/app/view/FormSettings.js +++ b/apps/documenteditor/main/app/view/FormSettings.js @@ -80,6 +80,12 @@ define([ this._originalFormProps = null; this._originalProps = null; + this._arrWidthRule = [ + {displayValue: this.textAuto, value: Asc.CombFormWidthRule.Auto}, + {displayValue: this.textAtLeast, value: Asc.CombFormWidthRule.AtLeast}, + {displayValue: this.textExact, value: Asc.CombFormWidthRule.Exact} + ]; + this.render(); }, @@ -214,13 +220,26 @@ define([ this.chComb.on('change', this.onChCombChanged.bind(this)); this.lockedControls.push(this.chComb); + this.cmbWidthRule = new Common.UI.ComboBox({ + el: $markup.findById('#form-combo-width-rule'), + cls: 'input-group-nr', + menuStyle: 'min-width: 85px;', + editable: false, + data: this._arrWidthRule, + dataHint: '1', + dataHintDirection: 'bottom', + dataHintOffset: 'big' + }); + this.cmbWidthRule.setValue(''); + this.cmbWidthRule.on('selected', this.onWidthRuleSelect.bind(this)); + this.spnWidth = new Common.UI.MetricSpinner({ el: $markup.findById('#form-spin-width'), step: .1, - width: 64, + width: 85, defaultUnit : "cm", - value: 'Auto', - allowAuto: true, + value: '', + allowAuto: false, maxValue: 55.88, minValue: 0.1, dataHint: '1', @@ -547,6 +566,7 @@ define([ if (!checked) { this.chComb.setValue(false, true); this.spnWidth.setDisabled(true); + this.cmbWidthRule.setDisabled(true); } if (this.api && !this._noApply) { var props = this._originalProps || new AscCommon.CContentControlPr(); @@ -576,7 +596,8 @@ define([ this.chMaxChars.setValue(true, true); this.spnMaxChars.setDisabled(false || this._state.DisabledControls); } - this.spnWidth.setDisabled(!checked || this._state.DisabledControls); + this.cmbWidthRule.setDisabled(!checked || this._state.Fixed || this._state.DisabledControls); + this.spnWidth.setDisabled(!checked || this._state.WidthRule===Asc.CombFormWidthRule.Auto || this._state.DisabledControls); if (this.api && !this._noApply) { var props = this._originalProps || new AscCommon.CContentControlPr(); var formTextPr = this._originalTextFormProps || new AscCommon.CSdtTextFormPr(); @@ -610,6 +631,19 @@ define([ } }, + onWidthRuleSelect: function(combo, record) { + if (this.api && !this._noApply) { + var props = this._originalProps || new AscCommon.CContentControlPr(); + var formTextPr = this._originalTextFormProps || new AscCommon.CSdtTextFormPr(); + formTextPr.put_WidthRule(record.value); + // if (record.value === Asc.CombFormWidthRule.Auto) + // formTextPr.put_Width(this._state.WidthPlaceholder); + props.put_TextFormPr(formTextPr); + this.api.asc_SetContentControlProperties(props, this.internalId); + this.fireEvent('editcomplete', this); + } + }, + onChRequired: function(field, newValue, oldValue, eOpts){ var checked = (field.getValue()=='checked'); if (this.api && !this._noApply) { @@ -648,6 +682,16 @@ define([ onChFixed: function(field, newValue, oldValue, eOpts){ if (this.api && !this._noApply) { + var props = this._originalProps || new AscCommon.CContentControlPr(); + + if (field.getValue()=='checked') { + var formTextPr = this._originalTextFormProps || new AscCommon.CSdtTextFormPr(); + formTextPr.put_WidthRule(Asc.CombFormWidthRule.Exact); + props.put_TextFormPr(formTextPr); + this.api.asc_SetContentControlProperties(props, this.internalId); + } + + this.cmbWidthRule.setDisabled(!this._state.Comb || field.getValue()=='checked' || this._state.DisabledControls); this.api.asc_SetFixedForm(this.internalId, field.getValue()=='checked'); this.fireEvent('editcomplete', this); } @@ -1118,11 +1162,11 @@ define([ } this.chAutofit.setDisabled(!this._state.Fixed || this._state.Comb || this._state.DisabledControls); - this.spnWidth.setDisabled(!this._state.Comb || this._state.DisabledControls); - val = formTextPr.get_Width(); - if ( (val===undefined || this._state.Width===undefined)&&(this._state.Width!==val) || Math.abs(this._state.Width-val)>0.1) { - this.spnWidth.setValue(val!==0 && val!==undefined ? Common.Utils.Metric.fnRecalcFromMM(val * 25.4 / 20 / 72.0) : -1, true); - this._state.Width=val; + this.cmbWidthRule.setDisabled(!this._state.Comb || this._state.Fixed || this._state.DisabledControls); + val = formTextPr.get_WidthRule(); + if ( this._state.WidthRule!==val ) { + this.cmbWidthRule.setValue((val !== null && val !== undefined) ? val : ''); + this._state.WidthRule=val; } val = this.api.asc_GetTextFormAutoWidth(); @@ -1131,6 +1175,13 @@ define([ this._state.WidthPlaceholder=val; } + this.spnWidth.setDisabled(!this._state.Comb || this._state.WidthRule===Asc.CombFormWidthRule.Auto || this._state.DisabledControls); + val = (this._state.WidthRule===Asc.CombFormWidthRule.Auto) ? this._state.WidthPlaceholder : formTextPr.get_Width(); + if ( (val===undefined || this._state.Width===undefined)&&(this._state.Width!==val) || Math.abs(this._state.Width-val)>0.1) { + this.spnWidth.setValue(val!==0 && val!==undefined ? Common.Utils.Metric.fnRecalcFromMM(val * 25.4 / 20 / 72.0) : this.spnWidth.getDefaultValue(), true); + this._state.Width=val; + } + val = formTextPr.get_MaxCharacters(); this.chMaxChars.setValue(val && val>=0); this.spnMaxChars.setDisabled(!val || val<0 || this._state.DisabledControls); @@ -1161,7 +1212,7 @@ define([ } var val = this._state.Width; this.spnWidth && this.spnWidth.setMinValue(Common.Utils.Metric.fnRecalcFromMM(1)); - this.spnWidth && this.spnWidth.setValue(val!==0 && val!==undefined ? Common.Utils.Metric.fnRecalcFromMM(val * 25.4 / 20 / 72.0) : -1, true); + this.spnWidth && this.spnWidth.setValue(val!==0 && val!==undefined ? Common.Utils.Metric.fnRecalcFromMM(val * 25.4 / 20 / 72.0) : '', true); } }, @@ -1230,7 +1281,8 @@ define([ }); } this.spnMaxChars.setDisabled(this.chMaxChars.getValue()!=='checked' || this._state.DisabledControls); - this.spnWidth.setDisabled(!this._state.Comb || this._state.DisabledControls); + this.cmbWidthRule.setDisabled(!this._state.Comb || this._state.Fixed || this._state.DisabledControls); + this.spnWidth.setDisabled(!this._state.Comb || this._state.WidthRule===Asc.CombFormWidthRule.Auto || this._state.DisabledControls); this.chMulti.setDisabled(!this._state.Fixed || this._state.Comb || this._state.DisabledControls); this.chAutofit.setDisabled(!this._state.Fixed || this._state.Comb || this._state.DisabledControls); this.chAspect.setDisabled(this._state.scaleFlag === Asc.c_oAscPictureFormScaleFlag.Never || this._state.DisabledControls); @@ -1376,7 +1428,10 @@ define([ textTooSmall: 'Image is Too Small', textScale: 'When to scale', textBackgroundColor: 'Background Color', - textTag: 'Tag' + textTag: 'Tag', + textAuto: 'Auto', + textAtLeast: 'At least', + textExact: 'Exactly' }, DE.Views.FormSettings || {})); }); \ No newline at end of file From a8cf3113f09b71b7e20021d0ef778f6cf0438edd Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 17 Jun 2022 17:08:45 +0300 Subject: [PATCH 2/4] [DE] Forms: fix width rule --- .../main/app/view/FormSettings.js | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/apps/documenteditor/main/app/view/FormSettings.js b/apps/documenteditor/main/app/view/FormSettings.js index cb48715a1..22dd24c61 100644 --- a/apps/documenteditor/main/app/view/FormSettings.js +++ b/apps/documenteditor/main/app/view/FormSettings.js @@ -623,6 +623,7 @@ define([ if (this.spnWidth.getValue()) { var value = this.spnWidth.getNumberValue(); formTextPr.put_Width(value<=0 ? 0 : parseInt(Common.Utils.Metric.fnRecalcToMM(value) * 72 * 20 / 25.4 + 0.5)); + formTextPr.put_WidthRule(this.cmbWidthRule.getValue()); } else formTextPr.put_Width(0); @@ -636,8 +637,8 @@ define([ var props = this._originalProps || new AscCommon.CContentControlPr(); var formTextPr = this._originalTextFormProps || new AscCommon.CSdtTextFormPr(); formTextPr.put_WidthRule(record.value); - // if (record.value === Asc.CombFormWidthRule.Auto) - // formTextPr.put_Width(this._state.WidthPlaceholder); + if (record.value === Asc.CombFormWidthRule.Auto) + formTextPr.put_Width(this._state.WidthPlaceholder); props.put_TextFormPr(formTextPr); this.api.asc_SetContentControlProperties(props, this.internalId); this.fireEvent('editcomplete', this); @@ -683,14 +684,6 @@ define([ onChFixed: function(field, newValue, oldValue, eOpts){ if (this.api && !this._noApply) { var props = this._originalProps || new AscCommon.CContentControlPr(); - - if (field.getValue()=='checked') { - var formTextPr = this._originalTextFormProps || new AscCommon.CSdtTextFormPr(); - formTextPr.put_WidthRule(Asc.CombFormWidthRule.Exact); - props.put_TextFormPr(formTextPr); - this.api.asc_SetContentControlProperties(props, this.internalId); - } - this.cmbWidthRule.setDisabled(!this._state.Comb || field.getValue()=='checked' || this._state.DisabledControls); this.api.asc_SetFixedForm(this.internalId, field.getValue()=='checked'); this.fireEvent('editcomplete', this); @@ -1163,7 +1156,7 @@ define([ this.chAutofit.setDisabled(!this._state.Fixed || this._state.Comb || this._state.DisabledControls); this.cmbWidthRule.setDisabled(!this._state.Comb || this._state.Fixed || this._state.DisabledControls); - val = formTextPr.get_WidthRule(); + val = this._state.Fixed ? Asc.CombFormWidthRule.Exact : formTextPr.get_WidthRule(); if ( this._state.WidthRule!==val ) { this.cmbWidthRule.setValue((val !== null && val !== undefined) ? val : ''); this._state.WidthRule=val; @@ -1176,9 +1169,10 @@ define([ } this.spnWidth.setDisabled(!this._state.Comb || this._state.WidthRule===Asc.CombFormWidthRule.Auto || this._state.DisabledControls); - val = (this._state.WidthRule===Asc.CombFormWidthRule.Auto) ? this._state.WidthPlaceholder : formTextPr.get_Width(); - if ( (val===undefined || this._state.Width===undefined)&&(this._state.Width!==val) || Math.abs(this._state.Width-val)>0.1) { - this.spnWidth.setValue(val!==0 && val!==undefined ? Common.Utils.Metric.fnRecalcFromMM(val * 25.4 / 20 / 72.0) : this.spnWidth.getDefaultValue(), true); + val = formTextPr.get_Width(); + val = (this._state.WidthRule===Asc.CombFormWidthRule.Auto || val===undefined || val===0) ? this._state.WidthPlaceholder : val; + if ((val===undefined || this._state.Width===undefined)&&(this._state.Width!==val) || Math.abs(this._state.Width-val)>0.1) { + this.spnWidth.setValue(val!==0 && val!==undefined ? Common.Utils.Metric.fnRecalcFromMM(val * 25.4 / 20 / 72.0) : '', true); this._state.Width=val; } From 208eebcd14844529c0d31a48d31e3c27a296d736 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 20 Jun 2022 22:47:52 +0300 Subject: [PATCH 3/4] Refactoring --- apps/common/main/lib/component/MetricSpinner.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/common/main/lib/component/MetricSpinner.js b/apps/common/main/lib/component/MetricSpinner.js index 519cf91e4..e44b19381 100644 --- a/apps/common/main/lib/component/MetricSpinner.js +++ b/apps/common/main/lib/component/MetricSpinner.js @@ -567,10 +567,6 @@ define([ this.options.defaultValue = value; }, - getDefaultValue: function() { - return this.options.defaultValue; - }, - checkAutoText: function(value) { if (this.options.allowAuto && typeof value == 'string') { var val = value.toLowerCase(); From 9e9e35b2fc041fb5a16fb471b44a7773587decfa Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 20 Jun 2022 23:13:54 +0300 Subject: [PATCH 4/4] [DE] Add translation --- apps/documenteditor/main/locale/en.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index a35f3135d..fdedef637 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -1865,6 +1865,9 @@ "DE.Views.FormSettings.textUnlock": "Unlock", "DE.Views.FormSettings.textValue": "Value Options", "DE.Views.FormSettings.textWidth": "Cell width", + "DE.Views.FormSettings.textAuto": "Auto", + "DE.Views.FormSettings.textAtLeast": "At least", + "DE.Views.FormSettings.textExact": "Exactly", "DE.Views.FormsTab.capBtnCheckBox": "Checkbox", "DE.Views.FormsTab.capBtnComboBox": "Combo Box", "DE.Views.FormsTab.capBtnDownloadForm": "Download as oform",