[DE] Fix forms tab

This commit is contained in:
Julia Radzhabova 2020-10-07 14:20:14 +03:00
parent c35bf4bdcd
commit 833f4058e7
5 changed files with 148 additions and 131 deletions

View file

@ -55,22 +55,10 @@ define([
sdkViewName : '#id_main', sdkViewName : '#id_main',
initialize: function () { initialize: function () {
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
}
});
}, },
onLaunch: function () { onLaunch: function () {
this._state = { this._state = {
prcontrolsdisable:undefined, prcontrolsdisable:undefined
in_object: false
}; };
}, },
@ -80,6 +68,9 @@ define([
this.api.asc_registerCallback('asc_onFocusObject', this.onApiFocusObject.bind(this)); this.api.asc_registerCallback('asc_onFocusObject', this.onApiFocusObject.bind(this));
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
this.api.asc_registerCallback('asc_onChangeSdtGlobalSettings', _.bind(this.onChangeSdtGlobalSettings, this));
this.api.asc_registerCallback('asc_onSendThemeColors', _.bind(this.onSendThemeColors, this));
// this.api.asc_registerCallback('asc_onShowContentControlsActions',_.bind(this.onShowContentControlsActions, this)); // this.api.asc_registerCallback('asc_onShowContentControlsActions',_.bind(this.onShowContentControlsActions, this));
// this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideContentControlsActions, this)); // this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideContentControlsActions, this));
} }
@ -91,6 +82,17 @@ define([
this.view = this.createView('FormsTab', { this.view = this.createView('FormsTab', {
toolbar: this.toolbar.toolbar toolbar: this.toolbar.toolbar
}); });
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:open-color': this.onColorsShow,
'forms:mode': this.onModeClick
}
});
}, },
SetDisabled: function(state) { SetDisabled: function(state) {
@ -111,12 +113,7 @@ define([
var pr, i = -1, type, var pr, i = -1, type,
paragraph_locked = false, paragraph_locked = false,
header_locked = false, header_locked = false;
in_header = false,
in_equation = false,
in_image = false,
in_table = false,
frame_pr = null;
while (++i < selectedObjects.length) { while (++i < selectedObjects.length) {
type = selectedObjects[i].get_ObjectType(); type = selectedObjects[i].get_ObjectType();
@ -124,93 +121,97 @@ define([
if (type === Asc.c_oAscTypeSelectElement.Paragraph) { if (type === Asc.c_oAscTypeSelectElement.Paragraph) {
paragraph_locked = pr.get_Locked(); paragraph_locked = pr.get_Locked();
frame_pr = pr;
} else if (type === Asc.c_oAscTypeSelectElement.Header) { } else if (type === Asc.c_oAscTypeSelectElement.Header) {
header_locked = pr.get_Locked(); header_locked = pr.get_Locked();
in_header = true;
} else if (type === Asc.c_oAscTypeSelectElement.Image) {
in_image = true;
} else if (type === Asc.c_oAscTypeSelectElement.Math) {
in_equation = true;
} else if (type === Asc.c_oAscTypeSelectElement.Table) {
in_table = true;
} }
} }
this._state.prcontrolsdisable = paragraph_locked || header_locked; var in_control = this.api.asc_IsContentControl();
this._state.in_object = in_image || in_table || in_equation; 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;
}
},
var control_props = this.api.asc_IsContentControl() ? this.api.asc_GetContentControlProperties() : null, onSendThemeColors: function() {
control_plain = (control_props) ? (control_props.get_ContentControlType()==Asc.c_oAscSdtLevelType.Inline) : false, this._needUpdateColors = true;
lock_type = control_props ? control_props.get_Lock() : Asc.c_oAscSdtLockType.Unlocked, },
content_locked = lock_type==Asc.c_oAscSdtLockType.SdtContentLocked || lock_type==Asc.c_oAscSdtLockType.ContentLocked;
var rich_del_lock = (frame_pr) ? !frame_pr.can_DeleteBlockContentControl() : false,
rich_edit_lock = (frame_pr) ? !frame_pr.can_EditBlockContentControl() : false,
plain_del_lock = (frame_pr) ? !frame_pr.can_DeleteInlineContentControl() : false,
plain_edit_lock = (frame_pr) ? !frame_pr.can_EditInlineContentControl() : false;
updateThemeColors: function() {
var updateColors = function(picker, defaultColorIndex) {
if (picker) {
var clr;
var need_disable = paragraph_locked || in_equation || in_image || in_header || control_plain || rich_edit_lock || plain_edit_lock; var effectcolors = Common.Utils.ThemeColor.getEffectColors();
for (var i = 0; i < effectcolors.length; i++) {
if (typeof(picker.currentColor) == 'object' &&
clr === undefined &&
picker.currentColor.effectId == effectcolors[i].effectId)
clr = effectcolors[i];
}
picker.updateColors(effectcolors, Common.Utils.ThemeColor.getStandartColors());
if (picker.currentColor === undefined) {
picker.currentColor = effectcolors[defaultColorIndex];
} else if ( clr!==undefined ) {
picker.currentColor = clr;
}
}
};
this.view && this.view.mnuFormsColorPicker && updateColors(this.view.mnuFormsColorPicker, 1);
this.onChangeSdtGlobalSettings();
},
onChangeSdtGlobalSettings: function() {
var show = this.api.asc_GetGlobalContentControlShowHighlight();
if (this.view && this.view.mnuFormsColorPicker) {
this.view.mnuNoFormsColor.setChecked(!show, true);
this.view.mnuFormsColorPicker.clearSelection();
if (show){
var clr = this.api.asc_GetGlobalContentControlHighlightColor();
if (clr) {
clr = Common.Utils.ThemeColor.getHexColor(clr.get_r(), clr.get_g(), clr.get_b());
this.view.mnuFormsColorPicker.selectByRGB(clr, true);
}
}
}
},
onColorsShow: function(menu) {
this._needUpdateColors && this.updateThemeColors();
this._needUpdateColors = false;
}, },
onControlsSelect: function(type) { onControlsSelect: function(type) {
if (!(this.mode && this.mode.canFeatureContentControl)) return; if (!(this.toolbar.mode && this.toolbar.mode.canFeatureContentControl)) return;
if (item.value == 'settings' || item.value == 'remove') { var oPr,
if (this.api.asc_IsContentControl()) { oFormPr = new AscCommon.CSdtFormPr();
var props = this.api.asc_GetContentControlProperties(); this.toolbar.toolbar.fireEvent('insertcontrol', this.toolbar.toolbar);
if (props) { if (type == 'picture')
var id = props.get_InternalId(); this.api.asc_AddContentControlPicture(oFormPr);
if (item.value == 'settings') { else if (type == 'checkbox' || type == 'radiobox') {
var me = this; oPr = new AscCommon.CSdtCheckBoxPr();
(new DE.Views.ControlSettingsDialog({ (type == 'radiobox') && oPr.put_GroupKey('Group 1');
props: props, this.api.asc_AddContentControlCheckBox(oPr, oFormPr);
api: me.api, } else if (type == 'combobox' || type == 'dropdown')
controlLang: me._state.lang, this.api.asc_AddContentControlList(type == 'combobox', oPr, oFormPr);
interfaceLang: me.mode.lang, else if (type == 'text') {
handler: function(result, value) { oPr = new AscCommon.CSdtTextFormPr();
if (result == 'ok') { this.api.asc_AddContentControlTextForm(oPr, oFormPr);
me.api.asc_SetContentControlProperties(value, id);
}
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
}
})).show();
} else {
this.api.asc_RemoveContentControlWrapper(id);
Common.component.Analytics.trackEvent('ToolBar', 'Remove Content Control');
}
}
}
} else {
var isnew = (item.value.indexOf('new-')==0),
oPr, oFormPr;
if (isnew) {
oFormPr = new AscCommon.CSdtFormPr();
this.toolbar.fireEvent('insertcontrol', this.toolbar);
}
if (item.value == 'plain' || item.value == 'rich')
this.api.asc_AddContentControl((item.value=='plain') ? Asc.c_oAscSdtLevelType.Inline : Asc.c_oAscSdtLevelType.Block);
else if (item.value.indexOf('picture')>=0)
this.api.asc_AddContentControlPicture(oFormPr);
else if (item.value.indexOf('checkbox')>=0 || item.value.indexOf('radiobox')>=0) {
if (isnew) {
oPr = new AscCommon.CSdtCheckBoxPr();
(item.value.indexOf('radiobox')>=0) && oPr.put_GroupKey('Group 1');
}
this.api.asc_AddContentControlCheckBox(oPr, oFormPr);
} else if (item.value == 'date')
this.api.asc_AddContentControlDatePicker();
else if (item.value.indexOf('combobox')>=0 || item.value.indexOf('dropdown')>=0)
this.api.asc_AddContentControlList(item.value.indexOf('combobox')>=0, oPr, oFormPr);
else if (item.value == 'new-field') {
oPr = new AscCommon.CSdtTextFormPr();
this.api.asc_AddContentControlTextForm(oPr, oFormPr);
}
Common.component.Analytics.trackEvent('ToolBar', 'Add Content Control');
} }
Common.NotificationCenter.trigger('edit:complete', this.toolbar); Common.NotificationCenter.trigger('edit:complete', this.toolbar);
}, },
@ -229,7 +230,7 @@ define([
}, },
onNewControlsColor: function() { onNewControlsColor: function() {
this.view.mnuControlsColorPicker.addNewColor(); this.view.mnuFormsColorPicker.addNewColor();
}, },
onNoControlsColor: function(item) { onNoControlsColor: function(item) {

View file

@ -3013,9 +3013,14 @@ define([
links.setApi(me.api).setConfig({toolbar: me}); links.setApi(me.api).setConfig({toolbar: me});
Array.prototype.push.apply(me.toolbar.toolbarControls, links.getView('Links').getButtons()); Array.prototype.push.apply(me.toolbar.toolbarControls, links.getView('Links').getButtons());
var forms = me.getApplication().getController('FormsTab'); if (config.canFeatureContentControl) {
forms.setApi(me.api).setConfig({toolbar: me}); tab = {caption: me.textTabForms, action: 'forms'};
Array.prototype.push.apply(me.toolbar.toolbarControls, forms.getView('FormsTab').getButtons()); var forms = me.getApplication().getController('FormsTab');
forms.setApi(me.api).setConfig({toolbar: me});
me.toolbar.addTab(tab, $panel, 4);
me.toolbar.setVisible('forms', true);
Array.prototype.push.apply(me.toolbar.toolbarControls, forms.getView('FormsTab').getButtons());
}
} }
}, },
@ -3437,7 +3442,8 @@ define([
notcriticalErrorTitle: 'Warning', notcriticalErrorTitle: 'Warning',
txtMarginsW: 'Left and right margins are too high for a given page wight', txtMarginsW: 'Left and right margins are too high for a given page wight',
txtMarginsH: 'Top and bottom margins are too high for a given page height', txtMarginsH: 'Top and bottom margins are too high for a given page height',
textInsert: 'Insert' textInsert: 'Insert',
textTabForms: 'Forms'
}, DE.Controllers.Toolbar || {})); }, DE.Controllers.Toolbar || {}));
}); });

View file

@ -659,6 +659,8 @@ define([
}, },
disableControls: function(disable) { disableControls: function(disable) {
if (this._initSettings) return;
var me = this; var me = this;
if (this._state.DisabledControls!==(this._state.LockDelete || disable)) { if (this._state.DisabledControls!==(this._state.LockDelete || disable)) {
this._state.DisabledControls = this._state.LockDelete || disable; this._state.DisabledControls = this._state.LockDelete || disable;

View file

@ -65,23 +65,28 @@ define([
me.fireEvent('forms:insert', ['radiobox']); me.fireEvent('forms:insert', ['radiobox']);
}); });
this.btnImageField.on('click', function (b, e) { this.btnImageField.on('click', function (b, e) {
me.fireEvent('forms:insert', ['image']); me.fireEvent('forms:insert', ['picture']);
}); });
this.btnViewForm.on('click', function (b, e) { this.btnViewForm.on('click', function (b, e) {
me.fireEvent('forms:mode', [b.pressed]); me.fireEvent('forms:mode', [b.pressed]);
}); });
this.btnClearFields.on('click', function (b, e) { if (this.mnuFormsColorPicker) {
me.fireEvent('forms:clear'); this.btnClearFields.on('click', function (b, e) {
}); me.fireEvent('forms:clear');
$('#id-toolbar-menu-new-form-color').on('click', function (b, e) { });
me.fireEvent('forms:new-color'); $('#id-toolbar-menu-new-form-color').on('click', function (b, e) {
}); me.fireEvent('forms:new-color');
this.mnuNoControlsColor.on('click', function (item) { });
me.fireEvent('forms:no-color', [item]); this.mnuNoFormsColor.on('click', function (item) {
}); me.fireEvent('forms:no-color', [item]);
this.mnuControlsColorPicker.on('select', function(picker, color) { });
me.fireEvent('forms:select-color', [color]); this.mnuFormsColorPicker.on('select', function(picker, color) {
}); me.fireEvent('forms:select-color', [color]);
});
this.btnHighlight.menu.on('show:after', function(picker, color) {
me.fireEvent('forms:open-color', [color]);
});
}
} }
return { return {
@ -175,6 +180,7 @@ define([
cls : 'btn-toolbar', cls : 'btn-toolbar',
iconCls : 'toolbar__icon btn-highlight', iconCls : 'toolbar__icon btn-highlight',
caption : this.textHighlight, caption : this.textHighlight,
menu : true,
disabled: true disabled: true
}); });
this.paragraphControls.push(this.btnHighlight); this.paragraphControls.push(this.btnHighlight);
@ -192,21 +198,25 @@ define([
(new Promise(function (accept, reject) { (new Promise(function (accept, reject) {
accept(); accept();
})).then(function(){ })).then(function(){
me.btnHighlight.setMenu(new Common.UI.Menu({ if (config.canEditContentControl) {
items: [ me.btnHighlight.setMenu(new Common.UI.Menu({
me.mnuNoControlsColor = new Common.UI.MenuItem({ items: [
id: 'id-toolbar-menu-no-highlight-form', me.mnuNoFormsColor = new Common.UI.MenuItem({
caption: me.textNoHighlight, id: 'id-toolbar-menu-no-highlight-form',
checkable: true caption: me.textNoHighlight,
}), checkable: true
{caption: '--'}, }),
{template: _.template('<div id="id-toolbar-menu-form-color" style="width: 169px; height: 220px; margin: 10px;"></div>')}, {caption: '--'},
{template: _.template('<a id="id-toolbar-menu-new-form-color" style="padding-left:12px;">' + me.textNewColor + '</a>')} {template: _.template('<div id="id-toolbar-menu-form-color" style="width: 169px; height: 220px; margin: 10px;"></div>')},
] {template: _.template('<a id="id-toolbar-menu-new-form-color" style="padding-left:12px;">' + me.textNewColor + '</a>')}
})); ]
me.mnuControlsColorPicker = new Common.UI.ThemeColorPalette({ }));
el: $('#id-toolbar-menu-form-color') me.mnuFormsColorPicker = new Common.UI.ThemeColorPalette({
}); el: $('#id-toolbar-menu-form-color')
});
} else {
me.btnHighlight.cmpEl.parents('.group').hide().prev('.separator').hide();
}
me.btnTextField.updateHint(me.tipTextField); me.btnTextField.updateHint(me.tipTextField);
me.btnComboBox.updateHint(me.tipComboBox); me.btnComboBox.updateHint(me.tipComboBox);

View file

@ -113,8 +113,7 @@ define([
{caption: me.textTabHome, action: 'home', extcls: 'canedit'}, {caption: me.textTabHome, action: 'home', extcls: 'canedit'},
{caption: me.textTabInsert, action: 'ins', extcls: 'canedit'}, {caption: me.textTabInsert, action: 'ins', extcls: 'canedit'},
{caption: me.textTabLayout, action: 'layout', extcls: 'canedit'}, {caption: me.textTabLayout, action: 'layout', extcls: 'canedit'},
{caption: me.textTabLinks, action: 'links', extcls: 'canedit'}, {caption: me.textTabLinks, action: 'links', extcls: 'canedit'}
{caption: me.textTabForms, action: 'forms', extcls: 'canedit'}
] ]
} }
); );
@ -2363,8 +2362,7 @@ define([
textNewComboboxControl: 'New combo box', textNewComboboxControl: 'New combo box',
textNewCheckboxControl: 'New check box', textNewCheckboxControl: 'New check box',
textNewRadioboxControl: 'New radio box', textNewRadioboxControl: 'New radio box',
textNewDropdownControl: 'New drop-down list', textNewDropdownControl: 'New drop-down list'
textTabForms: 'Forms'
} }
})(), DE.Views.Toolbar || {})); })(), DE.Views.Toolbar || {}));
}); });