2020-10-07 07:43:34 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System SIA 2010-2020
|
|
|
|
*
|
|
|
|
* 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-12 Ernesta Birznieka-Upisha
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FormsTab.js
|
|
|
|
*
|
|
|
|
* Created by Julia Radzhabova on 06.10.2020
|
|
|
|
* Copyright (c) 2020 Ascensio System SIA. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
|
|
|
'core',
|
|
|
|
'documenteditor/main/app/view/FormsTab'
|
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
DE.Controllers.FormsTab = Backbone.Controller.extend(_.extend({
|
|
|
|
models : [],
|
|
|
|
collections : [
|
|
|
|
],
|
|
|
|
views : [
|
|
|
|
'FormsTab'
|
|
|
|
],
|
|
|
|
sdkViewName : '#id_main',
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
},
|
|
|
|
onLaunch: function () {
|
|
|
|
this._state = {
|
2020-10-07 11:20:14 +00:00
|
|
|
prcontrolsdisable:undefined
|
2020-10-07 07:43:34 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
setApi: function (api) {
|
|
|
|
if (api) {
|
|
|
|
this.api = api;
|
|
|
|
this.api.asc_registerCallback('asc_onFocusObject', this.onApiFocusObject.bind(this));
|
|
|
|
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
|
|
|
|
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
|
2020-10-15 20:42:48 +00:00
|
|
|
this.api.asc_registerCallback('asc_onChangeSpecialFormsGlobalSettings', _.bind(this.onChangeSpecialFormsGlobalSettings, this));
|
|
|
|
Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this));
|
2020-10-07 11:20:14 +00:00
|
|
|
|
2020-10-07 07:43:34 +00:00
|
|
|
// this.api.asc_registerCallback('asc_onShowContentControlsActions',_.bind(this.onShowContentControlsActions, this));
|
|
|
|
// this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideContentControlsActions, this));
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setConfig: function(config) {
|
|
|
|
this.toolbar = config.toolbar;
|
|
|
|
this.view = this.createView('FormsTab', {
|
|
|
|
toolbar: this.toolbar.toolbar
|
|
|
|
});
|
2020-10-07 11:20:14 +00:00
|
|
|
this.addListeners({
|
|
|
|
'FormsTab': {
|
|
|
|
'forms:insert': this.onControlsSelect,
|
|
|
|
'forms:new-color': this.onNewControlsColor,
|
|
|
|
'forms:clear': this.onClearClick,
|
|
|
|
'forms:no-color': this.onNoControlsColor,
|
|
|
|
'forms:select-color': this.onSelectControlsColor,
|
|
|
|
'forms:mode': this.onModeClick
|
|
|
|
}
|
|
|
|
});
|
2020-10-07 07:43:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
SetDisabled: function(state) {
|
|
|
|
this.view && this.view.SetDisabled(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
getView: function(name) {
|
|
|
|
return !name && this.view ?
|
|
|
|
this.view : Backbone.Controller.prototype.getView.call(this, name);
|
|
|
|
},
|
|
|
|
|
|
|
|
onCoAuthoringDisconnect: function() {
|
|
|
|
this.SetDisabled(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
onApiFocusObject: function(selectedObjects) {
|
|
|
|
if (!this.toolbar.editMode) return;
|
|
|
|
|
|
|
|
var pr, i = -1, type,
|
|
|
|
paragraph_locked = false,
|
2020-10-07 11:20:14 +00:00
|
|
|
header_locked = false;
|
2020-10-07 07:43:34 +00:00
|
|
|
|
|
|
|
while (++i < selectedObjects.length) {
|
|
|
|
type = selectedObjects[i].get_ObjectType();
|
|
|
|
pr = selectedObjects[i].get_ObjectValue();
|
|
|
|
|
|
|
|
if (type === Asc.c_oAscTypeSelectElement.Paragraph) {
|
|
|
|
paragraph_locked = pr.get_Locked();
|
|
|
|
} else if (type === Asc.c_oAscTypeSelectElement.Header) {
|
|
|
|
header_locked = pr.get_Locked();
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 11:20:14 +00:00
|
|
|
var in_control = this.api.asc_IsContentControl();
|
|
|
|
var control_props = in_control ? this.api.asc_GetContentControlProperties() : null,
|
|
|
|
lock_type = (in_control&&control_props) ? control_props.get_Lock() : Asc.c_oAscSdtLockType.Unlocked,
|
|
|
|
control_plain = (in_control&&control_props) ? (control_props.get_ContentControlType()==Asc.c_oAscSdtLevelType.Inline) : false;
|
|
|
|
(lock_type===undefined) && (lock_type = Asc.c_oAscSdtLockType.Unlocked);
|
|
|
|
var content_locked = lock_type==Asc.c_oAscSdtLockType.SdtContentLocked || lock_type==Asc.c_oAscSdtLockType.ContentLocked;
|
|
|
|
var need_disable = (paragraph_locked || header_locked || control_plain || content_locked);
|
|
|
|
if (this._state.prcontrolsdisable !== need_disable) {
|
|
|
|
this.view.btnTextField.setDisabled(need_disable);
|
|
|
|
this.view.btnComboBox.setDisabled(need_disable);
|
|
|
|
this.view.btnDropDown.setDisabled(need_disable);
|
|
|
|
this.view.btnCheckBox.setDisabled(need_disable);
|
|
|
|
this.view.btnRadioBox.setDisabled(need_disable);
|
|
|
|
this.view.btnImageField.setDisabled(need_disable);
|
|
|
|
this.view.btnTextField.setDisabled(need_disable);
|
|
|
|
this._state.prcontrolsdisable = need_disable;
|
|
|
|
}
|
|
|
|
},
|
2020-10-07 07:43:34 +00:00
|
|
|
|
2020-10-15 20:42:48 +00:00
|
|
|
onChangeSpecialFormsGlobalSettings: function() {
|
2020-10-07 11:20:14 +00:00
|
|
|
if (this.view && this.view.mnuFormsColorPicker) {
|
2020-10-15 20:42:48 +00:00
|
|
|
var clr = this.api.asc_GetSpecialFormsHighlightColor(),
|
|
|
|
show = !!clr;
|
2020-10-07 11:20:14 +00:00
|
|
|
this.view.mnuNoFormsColor.setChecked(!show, true);
|
|
|
|
this.view.mnuFormsColorPicker.clearSelection();
|
2020-10-15 20:42:48 +00:00
|
|
|
if (clr) {
|
|
|
|
clr = Common.Utils.ThemeColor.getHexColor(clr.get_r(), clr.get_g(), clr.get_b());
|
|
|
|
this.view.mnuFormsColorPicker.selectByRGB(clr, true);
|
2020-10-07 11:20:14 +00:00
|
|
|
}
|
2020-10-07 13:22:59 +00:00
|
|
|
this.view.btnHighlight.currentColor = clr;
|
2021-01-21 19:48:27 +00:00
|
|
|
this.view.btnHighlight.setColor(this.view.btnHighlight.currentColor || 'transparent');
|
2020-10-07 07:43:34 +00:00
|
|
|
}
|
2020-10-07 11:20:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onControlsSelect: function(type) {
|
|
|
|
if (!(this.toolbar.mode && this.toolbar.mode.canFeatureContentControl)) return;
|
|
|
|
|
|
|
|
var oPr,
|
|
|
|
oFormPr = new AscCommon.CSdtFormPr();
|
|
|
|
this.toolbar.toolbar.fireEvent('insertcontrol', this.toolbar.toolbar);
|
|
|
|
if (type == 'picture')
|
|
|
|
this.api.asc_AddContentControlPicture(oFormPr);
|
|
|
|
else if (type == 'checkbox' || type == 'radiobox') {
|
|
|
|
oPr = new AscCommon.CSdtCheckBoxPr();
|
|
|
|
(type == 'radiobox') && oPr.put_GroupKey('Group 1');
|
|
|
|
this.api.asc_AddContentControlCheckBox(oPr, oFormPr);
|
|
|
|
} else if (type == 'combobox' || type == 'dropdown')
|
|
|
|
this.api.asc_AddContentControlList(type == 'combobox', oPr, oFormPr);
|
|
|
|
else if (type == 'text') {
|
|
|
|
oPr = new AscCommon.CSdtTextFormPr();
|
|
|
|
this.api.asc_AddContentControlTextForm(oPr, oFormPr);
|
|
|
|
}
|
2020-10-07 07:43:34 +00:00
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
|
|
|
|
},
|
|
|
|
|
|
|
|
onModeClick: function(state) {
|
|
|
|
if (this.api) {
|
2020-10-08 08:11:34 +00:00
|
|
|
this.disableEditing(state);
|
|
|
|
this.api.asc_setRestriction(state ? Asc.c_oAscRestrictionType.OnlyForms : Asc.c_oAscRestrictionType.None);
|
2020-11-11 14:24:46 +00:00
|
|
|
this.api.asc_SetPerformContentControlActionByClick(state);
|
2020-10-07 07:43:34 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
|
|
|
|
},
|
|
|
|
|
|
|
|
onClearClick: function() {
|
|
|
|
if (this.api) {
|
2020-10-13 12:28:02 +00:00
|
|
|
this.api.asc_ClearAllSpecialForms();
|
2020-10-07 07:43:34 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
|
|
|
|
},
|
|
|
|
|
|
|
|
onNewControlsColor: function() {
|
2020-10-07 11:20:14 +00:00
|
|
|
this.view.mnuFormsColorPicker.addNewColor();
|
2020-10-07 07:43:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onNoControlsColor: function(item) {
|
|
|
|
if (!item.isChecked())
|
2020-10-15 20:42:48 +00:00
|
|
|
this.api.asc_SetSpecialFormsHighlightColor(255, 192, 0);
|
2020-10-07 07:43:34 +00:00
|
|
|
else
|
2020-10-15 20:42:48 +00:00
|
|
|
this.api.asc_SetSpecialFormsHighlightColor();
|
2020-10-07 07:43:34 +00:00
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
|
|
|
|
},
|
|
|
|
|
|
|
|
onSelectControlsColor: function(color) {
|
|
|
|
var clr = Common.Utils.ThemeColor.getRgbColor(color);
|
|
|
|
if (this.api) {
|
2020-10-15 20:42:48 +00:00
|
|
|
this.api.asc_SetSpecialFormsHighlightColor(clr.get_r(), clr.get_g(), clr.get_b());
|
2020-10-07 07:43:34 +00:00
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
|
2020-10-08 08:11:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
disableEditing: function(disable) {
|
|
|
|
if (this._state.DisabledEditing != disable) {
|
|
|
|
this._state.DisabledEditing = disable;
|
|
|
|
|
|
|
|
var app = this.getApplication();
|
|
|
|
var rightMenuController = app.getController('RightMenu');
|
|
|
|
rightMenuController.getView('RightMenu').clearSelection();
|
|
|
|
rightMenuController.SetDisabled(disable);
|
|
|
|
app.getController('Toolbar').DisableToolbar(disable, false, false, true);
|
|
|
|
app.getController('Statusbar').getView('Statusbar').SetDisabled(disable);
|
|
|
|
app.getController('Common.Controllers.ReviewChanges').SetDisabled(disable);
|
|
|
|
app.getController('DocumentHolder').getView().SetDisabled(disable);
|
|
|
|
app.getController('Navigation') && app.getController('Navigation').SetDisabled(disable);
|
|
|
|
app.getController('LeftMenu').setPreviewMode(disable);
|
|
|
|
var comments = app.getController('Common.Controllers.Comments');
|
|
|
|
if (comments)
|
|
|
|
comments.setPreviewMode(disable);
|
|
|
|
if (this.view)
|
|
|
|
this.view.$el.find('.no-group-mask.form-view').css('opacity', 1);
|
|
|
|
}
|
2020-10-15 20:42:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onAppReady: function (config) {
|
|
|
|
var me = this;
|
|
|
|
(new Promise(function (accept, reject) {
|
|
|
|
accept();
|
|
|
|
})).then(function(){
|
|
|
|
if (config.canEditContentControl) {
|
|
|
|
var clr = me.api.asc_GetSpecialFormsHighlightColor();
|
|
|
|
clr && (clr = Common.Utils.ThemeColor.getHexColor(clr.get_r(), clr.get_g(), clr.get_b()));
|
|
|
|
me.view.btnHighlight.currentColor = clr;
|
|
|
|
}
|
|
|
|
});
|
2020-10-07 07:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}, DE.Controllers.FormsTab || {}));
|
|
|
|
});
|