diff --git a/apps/common/forms/resources/less/common.less b/apps/common/forms/resources/less/common.less index a1f29bb12..9246cb8ca 100644 --- a/apps/common/forms/resources/less/common.less +++ b/apps/common/forms/resources/less/common.less @@ -687,6 +687,7 @@ font-weight: bold; font-size: 11px; box-shadow: 0 6px 12px rgba(0,0,0,0.175); + max-width: 350px; padding: 5px 12px; white-space: pre-wrap; diff --git a/apps/documenteditor/forms/app/controller/ApplicationController.js b/apps/documenteditor/forms/app/controller/ApplicationController.js index 262c8c9fd..4a0a63a24 100644 --- a/apps/documenteditor/forms/app/controller/ApplicationController.js +++ b/apps/documenteditor/forms/app/controller/ApplicationController.js @@ -16,7 +16,10 @@ define([ labelDocName, btnSubmit, _submitFail, $submitedTooltip, $requiredTooltip, - $ttEl, $tooltip; + $ttEl, $tooltip, + $listControlMenu, listControlItems = [], listObj, + bodyWidth = 0, + ttOffset = [0, -10]; DE.Controllers.ApplicationController = Backbone.Controller.extend(_.assign({ views: [ @@ -173,6 +176,7 @@ define([ onDocumentResize: function() { this.api && this.api.Resize(); + bodyWidth = $('body').width(); }, onBeforeUnload: function() { @@ -324,10 +328,11 @@ define([ $('#toolbar').addClass('bottom'); this.boxSdk.addClass('bottom'); $('#box-tools').removeClass('dropdown').addClass('dropup'); - // ttOffset[1] = -40; + ttOffset[1] = -40; } else { $('#toolbar').addClass('top'); this.boxSdk.addClass('top'); + ttOffset[1] = 40; } this.appOptions.customization = this.editorConfig.customization; @@ -665,34 +670,50 @@ define([ }, onDocMouseMove: function(data) { + var me = this; if (data) { - if (data.get_Type() == 1) { // hyperlink + var type = data.get_Type(); + if (type == Asc.c_oAscMouseMoveDataTypes.Hyperlink || type==Asc.c_oAscMouseMoveDataTypes.Form) { // hyperlink this.isHideBodyTip = false; + var str = (type == Asc.c_oAscMouseMoveDataTypes.Hyperlink) ? me.txtPressLink : data.get_FormHelpText(); + if (str.length>500) + str = str.substr(0, 500) + '...'; + str = Common.Utils.String.htmlEncode(str); + if ( !$ttEl ) { $ttEl = $('.hyperlink-tooltip'); $ttEl.tooltip({'container':'body', 'trigger':'manual'}); - $ttEl.on('shown.bs.tooltip', function(e) { - $tooltip = $ttEl.data('bs.tooltip').tip(); - - $tooltip.css({ - left: $ttEl.ttpos[0] + ttOffset[0], - top: $ttEl.ttpos[1] + ttOffset[1] - }); - - $tooltip.find('.tooltip-arrow').css({left: 10}); - }); } - if ( !$tooltip ) { - $ttEl.ttpos = [data.get_X(), data.get_Y()]; - $ttEl.tooltip('show'); - } else { - $tooltip.css({ - left:data.get_X() + ttOffset[0], - top:data.get_Y() + ttOffset[1] - }); + $ttEl.ttpos = [data.get_X(), data.get_Y()]; + if ( !$tooltip) + $tooltip = $ttEl.data('bs.tooltip').tip(); + + if (!$tooltip.is(':visible')) { + var tip = $ttEl.data('bs.tooltip'); + tip.options.title = str; + tip.show([-1000, -1000]); + } else + $tooltip.find('.tooltip-inner')['text'](str); + + var ttHeight = $tooltip.height(), + ttWidth = $tooltip.width(); + !bodyWidth && (bodyWidth = $('body').width()); + + $ttEl.ttpos[1] -= (ttHeight - ttOffset[1] + 20); + if ($ttEl.ttpos[0] + ttWidth + 10 >bodyWidth) { + $ttEl.ttpos[0] = bodyWidth - ttWidth - 5; + if ($ttEl.ttpos[1] < 0) + $ttEl.ttpos[1] += ttHeight + ttOffset[1] + 20; + } else if ($ttEl.ttpos[1] < 0) { + $ttEl.ttpos[1] = 0; + $ttEl.ttpos[0] += 20; } + $tooltip.css({ + left: $ttEl.ttpos[0], + top: $ttEl.ttpos[1] + }); } } }, @@ -784,6 +805,99 @@ define([ } }, + onShowContentControlsActions: function(obj, x, y) { + var me = this; + switch (obj.type) { + case Asc.c_oAscContentControlSpecificType.Picture: + if (obj.pr && obj.pr.get_Lock) { + var lock = obj.pr.get_Lock(); + if (lock == Asc.c_oAscSdtLockType.SdtContentLocked || lock==Asc.c_oAscSdtLockType.ContentLocked) + return; + } + this.api.asc_addImage(obj); + setTimeout(function(){ + me.api.asc_UncheckContentControlButtons(); + }, 500); + break; + case Asc.c_oAscContentControlSpecificType.DropDownList: + case Asc.c_oAscContentControlSpecificType.ComboBox: + this.onShowListActions(obj, x, y); + break; + } + }, + + onHideContentControlsActions: function() { + $listControlMenu && $listControlMenu.hide(); + this.api.asc_UncheckContentControlButtons(); + }, + + onShowListActions: function(obj, x, y) { + var type = obj.type, + props = obj.pr, + specProps = (type == Asc.c_oAscContentControlSpecificType.ComboBox) ? props.get_ComboBoxPr() : props.get_DropDownListPr(), + isForm = !!props.get_FormPr(), + me = this; + + var menuContainer = this.view.getMenuForm(); + + if (!$listControlMenu) { + $listControlMenu = menuContainer.find('ul'); + $listControlMenu.on('click', 'li', function(e) { + var value = $(e.target).attr('value'); + if (value) { + value = parseInt(value); + setTimeout(function(){ + (value!==-1) && me.api.asc_SelectContentControlListItem(listControlItems[value], listObj.get_InternalId()); + }, 1); + } + }); + $('#editor_sdk').on('click', function(e){ + if (e.target.localName == 'canvas') { + if (me._preventClick) + me._preventClick = false; + else { + $listControlMenu && $listControlMenu.hide(); + me.api.asc_UncheckContentControlButtons(); + } + } + }); + } + $listControlMenu.find('li').remove(); + listControlItems = []; + listObj = props; + + if (specProps) { + var k = 0; + if (isForm){ // for dropdown and combobox form control always add placeholder item + var text = props.get_PlaceholderText(); + $listControlMenu.append('
  • ' + + ((text.trim()!=='') ? text : me.txtEmpty) + + '
  • '); + listControlItems.push(''); + } + var count = specProps.get_ItemsCount(); + k = listControlItems.length; + for (var i=0; i' + + Common.Utils.String.htmlEncode(specProps.get_ItemDisplayText(i)) + + ''); + listControlItems.push(specProps.get_ItemValue(i)); + } + } + if (!isForm && listControlItems.length<1) { + $listControlMenu.append('
  • ' + + me.txtEmpty + + '
  • '); + listControlItems.push(-1); + } + } + + menuContainer.css({left: x, top : y}); + me._preventClick = true; + $listControlMenu.show(); + }, + onDocumentContentReady: function() { var me = this; @@ -859,6 +973,11 @@ define([ this.api.asc_registerCallback('asc_onPrint', _.bind(this.onPrint, this)); this.api.asc_registerCallback('asc_onPrintUrl', _.bind(this.onPrintUrl, this)); this.api.asc_registerCallback('sync_onAllRequiredFormsFilled', _.bind(this.onFillRequiredFields, this)); + if (this.appOptions.canFillForms) { + this.api.asc_registerCallback('asc_onShowContentControlsActions', _.bind(this.onShowContentControlsActions, this)); + this.api.asc_registerCallback('asc_onHideContentControlsActions', _.bind(this.onHideContentControlsActions, this)); + // this.api.asc_SetHighlightRequiredFields(true); + } Common.Gateway.on('processmouse', _.bind(this.onProcessMouse, this)); Common.Gateway.on('downloadas', _.bind(this.onDownloadAs, this)); @@ -1024,6 +1143,8 @@ define([ textRequired: 'Fill all required fields to send form.', textGotIt: 'Got it', errorForceSave: "An error occurred while saving the file. Please use the 'Download as' option to save the file to your computer hard drive or try again later.", - textCloseTip: "Click to close the tip." + textCloseTip: "Click to close the tip.", + txtPressLink: 'Press Ctrl and click link', + txtEmpty: '(Empty)' }, DE.Controllers.ApplicationController)); }); diff --git a/apps/documenteditor/forms/app/view/ApplicationView.js b/apps/documenteditor/forms/app/view/ApplicationView.js index b6efe5e24..cfb2509b4 100644 --- a/apps/documenteditor/forms/app/view/ApplicationView.js +++ b/apps/documenteditor/forms/app/view/ApplicationView.js @@ -10,7 +10,8 @@ define([ 'use strict'; var $btnTools; - + var $menuForm; + DE.Views.ApplicationView = Backbone.View.extend({ // Render layout render: function() { @@ -38,6 +39,17 @@ define([ return $btnTools.parent().find(name); }, + getMenuForm: function() { + if (!$menuForm) { + $menuForm = $(''); + $('#editor_sdk').append($menuForm); + } + return $menuForm; + }, + txtDownload: 'Download', txtPrint: 'Print', txtShare: 'Share', diff --git a/apps/documenteditor/forms/index.html b/apps/documenteditor/forms/index.html index 4ecc26fd5..cae67bd44 100644 --- a/apps/documenteditor/forms/index.html +++ b/apps/documenteditor/forms/index.html @@ -222,7 +222,7 @@ - + diff --git a/apps/documenteditor/forms/locale/en.json b/apps/documenteditor/forms/locale/en.json index de0c0c291..2db8c2ef8 100644 --- a/apps/documenteditor/forms/locale/en.json +++ b/apps/documenteditor/forms/locale/en.json @@ -34,6 +34,8 @@ "DE.ApplicationController.unknownErrorText": "Unknown error.", "DE.ApplicationController.unsupportedBrowserErrorText": "Your browser is not supported.", "DE.ApplicationController.waitText": "Please, wait...", + "DE.ApplicationController.txtEmpty": "(Empty)", + "DE.ApplicationController.txtPressLink": "Press Ctrl and click link", "DE.ApplicationView.txtDownload": "Download", "DE.ApplicationView.txtDownloadDocx": "Download as docx", "DE.ApplicationView.txtDownloadPdf": "Download as pdf",