Merge pull request #3119 from ONLYOFFICE/feature/de-ins-field

Feature/de ins field
This commit is contained in:
Julia Radzhabova
2024-08-09 18:35:29 +03:00
committed by GitHub
9 changed files with 204 additions and 11 deletions

View File

@ -448,6 +448,8 @@ define([
view.menuTableDirection.menu.on('item:click', _.bind(me.tableDirection, me));
view.menuTableRefreshField.on('click', _.bind(me.onRefreshField, me));
view.menuParaRefreshField.on('click', _.bind(me.onRefreshField, me));
view.menuTableEditField.on('click', _.bind(me.onEditField, me));
view.menuParaEditField.on('click', _.bind(me.onEditField, me));
view.menuParagraphBreakBefore.on('click', _.bind(me.onParagraphBreakBefore, me));
view.menuParagraphKeepLines.on('click', _.bind(me.onParagraphKeepLines, me));
view.menuParagraphVAlign.menu.on('item:click', _.bind(me.paragraphVAlign, me));
@ -2499,6 +2501,10 @@ define([
this.editComplete();
},
onEditField: function(item, e){
this.documentHolder.fireEvent('field:edit', ['edit']);
},
onParagraphBreakBefore: function(item, e){
this.api && this.api.put_PageBreak(item.checked);
},

View File

@ -169,7 +169,8 @@ define([
'toolbar:setcompact': this.onChangeCompactView.bind(this)
},
'DocumentHolder': {
'list:settings': this.onMarkerSettingsClick.bind(this)
'list:settings': this.onMarkerSettingsClick.bind(this),
'field:edit': this.onInsFieldClick.bind(this, 'edit')
},
'Common.Views.ReviewChanges': {
'collaboration:mailmerge': _.bind(this.onSelectRecepientsClick, this)
@ -385,6 +386,7 @@ define([
toolbar.mnuPageNumberPosPicker.on('item:click', _.bind(this.onInsertPageNumberClick, this));
toolbar.btnEditHeader.menu.on('item:click', _.bind(this.onEditHeaderFooterClick, this));
toolbar.btnInsDateTime.on('click', _.bind(this.onInsDateTimeClick, this));
toolbar.btnInsField.on('click', _.bind(this.onInsFieldClick, this, 'add'));
toolbar.mnuPageNumCurrentPos.on('click', _.bind(this.onPageNumCurrentPosClick, this));
toolbar.mnuInsertPageCount.on('click', _.bind(this.onInsertPageCountClick, this));
toolbar.btnBlankPage.on('click', _.bind(this.onBtnBlankPageClick, this));
@ -821,9 +823,9 @@ define([
this.toolbar.lockToolbar(Common.enumLock.plainEditLock, plain_edit_lock, {array: this.toolbar.paragraphControls.concat([toolbar.btnClearStyle])});
this.toolbar.lockToolbar(Common.enumLock.richDelLock, rich_del_lock, {array: toolbar.btnsPageBreak.concat(this.btnsComment).concat([toolbar.btnInsertTable, toolbar.btnInsertImage, toolbar.btnInsertChart, toolbar.btnInsertTextArt,
toolbar.btnInsDateTime, toolbar.btnBlankPage, toolbar.btnInsertEquation, toolbar.btnInsertSymbol ])});
toolbar.btnInsDateTime, toolbar.btnBlankPage, toolbar.btnInsertEquation, toolbar.btnInsertSymbol, toolbar.btnInsField ])});
this.toolbar.lockToolbar(Common.enumLock.plainDelLock, plain_del_lock, {array: toolbar.btnsPageBreak.concat(this.btnsComment).concat([toolbar.btnInsertTable, toolbar.btnInsertImage, toolbar.btnInsertChart, toolbar.btnInsertTextArt,
toolbar.btnInsDateTime, toolbar.btnBlankPage, toolbar.btnInsertEquation, toolbar.btnInsertSymbol ])});
toolbar.btnInsDateTime, toolbar.btnBlankPage, toolbar.btnInsertEquation, toolbar.btnInsertSymbol, toolbar.btnInsField ])});
this.toolbar.lockToolbar(Common.enumLock.inChart, in_chart, {array: toolbar.textOnlyControls.concat([toolbar.btnClearStyle, toolbar.btnInsertEquation])});
this.toolbar.lockToolbar(Common.enumLock.inSmartart, in_smart_art, {array: toolbar.textOnlyControls.concat([toolbar.btnClearStyle, toolbar.btnContentControls])});
@ -893,7 +895,7 @@ define([
this.toolbar.lockToolbar(Common.enumLock.chartLock, in_chart && image_locked, {array: [toolbar.btnInsertChart]});
this.toolbar.lockToolbar(Common.enumLock.cantAddEquation, !can_add_image&&!in_equation, {array: [toolbar.btnInsertEquation]});
this.toolbar.lockToolbar(Common.enumLock.noParagraphSelected, !in_para, {array: [toolbar.btnInsertSymbol, toolbar.btnInsDateTime, toolbar.btnLineSpace]});
this.toolbar.lockToolbar(Common.enumLock.noParagraphSelected, !in_para, {array: [toolbar.btnInsertSymbol, toolbar.btnInsDateTime, toolbar.btnLineSpace, toolbar.btnInsField]});
this.toolbar.lockToolbar(Common.enumLock.inImage, in_image, {array: [toolbar.btnColumns]});
this.toolbar.lockToolbar(Common.enumLock.inImagePara, in_image && in_para, {array: [toolbar.btnLineNumbers]});
@ -3783,6 +3785,21 @@ define([
})).show();
},
onInsFieldClick: function(type) {
var me = this;
(new DE.Views.FieldDialog({
code: type==='edit' ? me.api.asc_GetComplexFieldInstruction() : '',
handler: function(result, value) {
if (result == 'ok') {
if (me.api) {
type==='edit' ? me.api.asc_EditComplexFieldInstruction(value) : me.api.asc_AddComplexFieldWithInstruction(value);
}
}
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
}
})).show();
},
mouseenterSmartArt: function (groupName) {
if (this.smartArtGenerating === undefined) {
this.generateSmartArt(groupName);

View File

@ -118,6 +118,7 @@
<span class="btn-slot text x-huge" id="slot-btn-instextart"></span>
<span class="btn-slot text x-huge" id="slot-btn-dropcap"></span>
<span class="btn-slot text x-huge" id="slot-btn-datetime"></span>
<span class="btn-slot text x-huge" id="slot-btn-insfield"></span>
</div>
<div class="separator long"></div>
<div class="group">

View File

@ -1234,6 +1234,9 @@ define([
me.menuTableRefreshField = new Common.UI.MenuItem({
caption: me.textRefreshField
});
me.menuTableEditField = new Common.UI.MenuItem({
caption: me.textEditField
});
var menuTableFieldSeparator = new Common.UI.MenuItem({
caption : '--'
@ -1342,7 +1345,7 @@ define([
var isEquation= (value.mathProps && value.mathProps.value);
for (var i = 11; i < 30; i++) {
for (var i = 11; i < 31; i++) { // from menuEquationSeparatorInTable to menuAddCommentTable (except menuAddCommentTable)
me.tableMenu.items[i].setVisible(!isEquation);
}
@ -1385,8 +1388,8 @@ define([
var block_control_lock = (value.paraProps) ? !value.paraProps.value.can_EditBlockContentControl() : false,
disabled = value.tableProps.locked || (value.headerProps!==undefined && value.headerProps.locked);
me.tableMenu.items[14].setDisabled(disabled);
me.tableMenu.items[15].setDisabled(disabled);
me.menuTableInsertText.setDisabled(disabled);
me.menuTableDeleteText.setDisabled(disabled);
if (me.api) {
me.mnuTableMerge.setDisabled(disabled || !me.api.CheckBeforeMergeCells());
@ -1544,6 +1547,8 @@ define([
var in_field = me.api.asc_HaveFields(true);
me.menuTableRefreshField.setVisible(!!in_field);
me.menuTableRefreshField.setDisabled(disabled);
me.menuTableEditField.setVisible(!!in_field);
me.menuTableEditField.setDisabled(disabled);
menuTableFieldSeparator.setVisible(!!in_field);
},
items: [
@ -1559,6 +1564,7 @@ define([
menuTableReviewSeparator,
menuEquationSeparatorInTable,
me.menuTableRefreshField,
me.menuTableEditField,
menuTableFieldSeparator,
me.menuTableSelectText,
me.menuTableInsertText,
@ -1905,6 +1911,9 @@ define([
me.menuParaRefreshField = new Common.UI.MenuItem({
caption: me.textRefreshField
});
me.menuParaEditField = new Common.UI.MenuItem({
caption: me.textEditField
});
var menuParaFieldSeparator = new Common.UI.MenuItem({
caption : '--'
@ -2146,6 +2155,8 @@ define([
var in_field = me.api.asc_HaveFields(true);
me.menuParaRefreshField.setVisible(!!in_field);
me.menuParaRefreshField.setDisabled(disabled);
me.menuParaEditField.setVisible(!!in_field);
me.menuParaEditField.setDisabled(disabled);
menuParaFieldSeparator.setVisible(!!in_field);
var listId = me.api.asc_GetCurrentNumberingId(),
@ -2193,6 +2204,7 @@ define([
me.menuParaControlSettings,
menuParaControlSeparator,
me.menuParaRefreshField,
me.menuParaEditField,
menuParaFieldSeparator,
me.menuParaTOCSettings,
me.menuParaTOCRefresh,
@ -3438,7 +3450,8 @@ define([
txtInsImage: 'Insert image from File',
txtInsImageUrl: 'Insert image from URL',
textClearField: 'Clear field',
textRedo: 'Redo'
textRedo: 'Redo',
textEditField: 'Edit field'
}, DE.Views.DocumentHolder || {}));
});

View File

@ -0,0 +1,131 @@
/*
* (c) Copyright Ascensio System SIA 2010-2024
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-6 Ernesta Birznieka-Upish
* street, Riga, Latvia, EU, LV-1050.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* FieldDialog.js
*
* Created on 08/08/24
*
*/
define([], function () { 'use strict';
DE.Views.FieldDialog = Common.UI.Window.extend(_.extend({
options: {
width: 450,
cls: 'modal-dlg',
buttons: ['ok', 'cancel']
},
initialize : function(options) {
_.extend(this.options, options || {});
_.extend(this.options, {
title: this.textTitle
}, options || {});
this.template = [
'<div class="box">',
'<div class="input-row">',
'<label>' + this.textLabel + '</label>',
'</div>',
'<div id="id-dlg-label-fieldname" class="input-row"></div>',
'<div class="input-row">',
'<label class="light">' + this.textExample + '</label>',
'</div>',
'</div>'
].join('');
this.options.tpl = _.template(this.template)(this.options);
Common.UI.Window.prototype.initialize.call(this, this.options);
},
render: function() {
Common.UI.Window.prototype.render.call(this);
var me = this;
me.inputLabel = new Common.UI.InputField({
el : $('#id-dlg-label-fieldname'),
allowBlank : true,
style : 'width: 100%;',
validateOnBlur: false
});
me.inputLabel.setValue(me.options.code || '');
var $window = this.getChild();
$window.find('.dlg-btn').on('click', _.bind(this.onBtnClick, this));
},
getFocusedComponents: function() {
return [this.inputLabel].concat(this.getFooterButtons());
},
getDefaultFocusableComponent: function () {
return this.inputLabel;
},
show: function() {
Common.UI.Window.prototype.show.apply(this, arguments);
var me = this;
_.delay(function(){
me.getChild('input').focus();
},50);
},
onPrimary: function(event) {
this._handleInput('ok');
return false;
},
onBtnClick: function(event) {
this._handleInput(event.currentTarget.attributes['result'].value);
},
_handleInput: function(state) {
if (this.options.handler) {
if (state == 'ok') {
if (this.inputLabel.checkValidate() !== true) {
this.inputLabel.cmpEl.find('input').focus();
return;
}
}
this.options.handler.call(this, state, this.inputLabel.getValue());
}
this.close();
},
textTitle: 'Field',
textLabel: 'Field codes',
textExample: 'Example of writing code: TIME \\@ "dddd, MMMM d, yyyy"'
}, DE.Views.FieldDialog || {}));
});

View File

@ -865,6 +865,19 @@ define([
});
this.paragraphControls.push(this.btnInsDateTime);
this.btnInsField = new Common.UI.Button({
id: 'id-toolbar-btn-insfield',
cls: 'btn-toolbar x-huge icon-top',
iconCls: 'toolbar__icon btn-quick-field',
lock: [_set.paragraphLock, _set.headerLock, _set.richEditLock, _set.plainEditLock, _set.richDelLock, _set.plainDelLock, _set.noParagraphSelected, _set.previewReviewMode,
_set.viewFormMode, _set.lostConnect, _set.disableOnStart, _set.docLockView, _set.docLockForms, _set.docLockComments, _set.viewMode],
caption: me.capBtnInsField,
dataHint: '1',
dataHintDirection: 'bottom',
dataHintOffset: 'small'
});
this.paragraphControls.push(this.btnInsField);
this.btnBlankPage = new Common.UI.Button({
id: 'id-toolbar-btn-blankpage',
cls: 'btn-toolbar x-huge icon-top',
@ -2040,6 +2053,7 @@ define([
_injectComponent('#slot-btn-line-numbers', this.btnLineNumbers);
_injectComponent('#slot-btn-editheader', this.btnEditHeader);
_injectComponent('#slot-btn-datetime', this.btnInsDateTime);
_injectComponent('#slot-btn-insfield', this.btnInsField);
_injectComponent('#slot-btn-blankpage', this.btnBlankPage);
_injectComponent('#slot-btn-insshape', this.btnInsertShape);
_injectComponent('#slot-btn-inssmartart', this.btnInsertSmartArt);
@ -2455,6 +2469,7 @@ define([
this.btnInsertTextArt.updateHint(this.tipInsertTextArt);
this.btnEditHeader.updateHint(this.tipEditHeader);
this.btnInsDateTime.updateHint(this.tipDateTime);
this.btnInsField.updateHint(this.tipInsField);
this.btnBlankPage.updateHint(this.tipBlankPage);
this.btnInsertShape.updateHint(this.tipInsertShape);
this.btnInsertSmartArt.updateHint(this.tipInsertSmartArt);
@ -3714,7 +3729,9 @@ define([
textEditMode: 'Edit PDF',
tipEditMode: 'Edit current file.<br>The page will be reloaded.',
capBtnPageColor: 'Page Color',
tipPageColor: 'Change page color'
tipPageColor: 'Change page color',
capBtnInsField: 'Field',
tipInsField: 'Insert field'
}
})(), DE.Views.Toolbar || {}));
});

View File

@ -256,7 +256,8 @@ require([
'documenteditor/main/app/view/NumberingValueDialog',
'documenteditor/main/app/view/ListIndentsDialog',
'documenteditor/main/app/view/ProtectDialog',
'documenteditor/main/app/view/MailMergeEmailDlg'
'documenteditor/main/app/view/MailMergeEmailDlg',
'documenteditor/main/app/view/FieldDialog'
];
window.compareVersions = true;

View File

@ -61,7 +61,8 @@ require([
'documenteditor/main/app/view/NumberingValueDialog',
'documenteditor/main/app/view/ListIndentsDialog',
'documenteditor/main/app/view/ProtectDialog',
'documenteditor/main/app/view/MailMergeEmailDlg'
'documenteditor/main/app/view/MailMergeEmailDlg',
'documenteditor/main/app/view/FieldDialog'
], function () {
Common.NotificationCenter.trigger('script:loaded');
});

View File

@ -1938,6 +1938,7 @@
"DE.Views.DocumentHolder.textPrevPage": "Previous Page",
"DE.Views.DocumentHolder.textRedo": "Redo",
"DE.Views.DocumentHolder.textRefreshField": "Update field",
"DE.Views.DocumentHolder.textEditField": "Edit field",
"DE.Views.DocumentHolder.textReject": "Reject change",
"DE.Views.DocumentHolder.textRemCheckBox": "Remove Checkbox",
"DE.Views.DocumentHolder.textRemComboBox": "Remove Combo Box",
@ -2113,6 +2114,9 @@
"DE.Views.EditListItemDialog.textNameError": "Display name must not be empty.",
"DE.Views.EditListItemDialog.textValue": "Value",
"DE.Views.EditListItemDialog.textValueError": "An item with the same value already exists.",
"DE.Views.FieldDialog.textTitle": "Field",
"DE.Views.FieldDialog.textLabel": "Field codes",
"DE.Views.FieldDialog.textExample": "Example of writing code: TIME \\@ \"dddd, MMMM d, yyyy\"",
"DE.Views.FileMenu.btnBackCaption": "Open File Location",
"DE.Views.FileMenu.btnCloseEditor": "Close File",
"DE.Views.FileMenu.btnCloseMenuCaption": "Close Menu",
@ -3570,6 +3574,8 @@
"DE.Views.Toolbar.txtMarginAlign": "Align to margin",
"DE.Views.Toolbar.txtObjectsAlign": "Align selected objects",
"DE.Views.Toolbar.txtPageAlign": "Align to page",
"DE.Views.Toolbar.capBtnInsField": "Field",
"DE.Views.Toolbar.tipInsField": "Insert field",
"DE.Views.ViewTab.textAlwaysShowToolbar": "Always Show Toolbar",
"DE.Views.ViewTab.textDarkDocument": "Dark Document",
"DE.Views.ViewTab.textFitToPage": "Fit To Page",