From 3a74ce23353af0e8a178596e83a6f98e39db9354 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 20 Nov 2019 14:56:32 +0300 Subject: [PATCH] [DE] Show menu for table of contents and date content control --- .../main/app/controller/Links.js | 68 +++++++++++++++---- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Links.js b/apps/documenteditor/main/app/controller/Links.js index fdd1a2a24..28193dd4b 100644 --- a/apps/documenteditor/main/app/controller/Links.js +++ b/apps/documenteditor/main/app/controller/Links.js @@ -94,10 +94,8 @@ define([ this.api.asc_registerCallback('asc_onCanAddHyperlink', _.bind(this.onApiCanAddHyperlink, this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); - this.api.asc_registerCallback('asc_onShowContentControlsActions',_.bind(this.onShowControlsActions, this)); - this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideControlsActions, 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_onShowContentControlsActions',_.bind(this.onShowContentControlsActions, this)); + this.api.asc_registerCallback('asc_onHideContentControlsActions',_.bind(this.onHideContentControlsActions, this)); } return this; @@ -354,8 +352,9 @@ define([ })).show(); }, - onShowContentControlsActions: function(action, x, y) { - var menu = (action==1) ? this.view.contentsUpdateMenu : this.view.contentsMenu, + onShowTOCActions: function(obj, x, y) { + var action = obj.button, + menu = (action==AscCommon.CCButtonType.Toc) ? this.view.contentsUpdateMenu : this.view.contentsMenu, documentHolderView = this.getApplication().getController('DocumentHolder').documentHolder, menuContainer = documentHolderView.cmpEl.find(Common.Utils.String.format('#menu-container-{0}', menu.id)), me = this; @@ -394,15 +393,22 @@ define([ onHideContentControlsActions: function() { this.view.contentsMenu && this.view.contentsMenu.hide(); this.view.contentsUpdateMenu && this.view.contentsUpdateMenu.hide(); + var controlsContainer = this.getApplication().getController('DocumentHolder').documentHolder.cmpEl.find('#calendar-control-container'); + if (controlsContainer.is(':visible')) + controlsContainer.hide(); }, - onShowControlsActions: function(action, x, y) { - var documentHolderView = this.getApplication().getController('DocumentHolder').documentHolder, + onShowDateActions: function(obj, x, y) { + var action = obj.button, + props = obj.pr, + specProps = props.get_DateTimePr(), + id = props.get_InternalId(), + documentHolderView = this.getApplication().getController('DocumentHolder').documentHolder, controlsContainer = documentHolderView.cmpEl.find('#calendar-control-container'), me = this; if (controlsContainer.length < 1) { - controlsContainer = $('
'); + controlsContainer = $('
'); documentHolderView.cmpEl.append(controlsContainer); } @@ -418,7 +424,10 @@ define([ firstday: 1 }); this.cmpCalendar.on('date:click', function (cmp, date) { - me.selectDate = new Date(date); + specProps.put_FullDate(new Date(date)); + me.api.asc_SetContentControlProperties(props, id); + controlsContainer.hide(); + me.api.asc_UncheckContentControlButtons(); }); this.cmpCalendar.on('calendar:keydown', function (cmp, e) { if (e.keyCode==Common.UI.Keys.ESC) { @@ -427,16 +436,45 @@ define([ } }); } - this.cmpCalendar.setDate(this.selectDate ? this.selectDate : new Date()); + this.cmpCalendar.setDate(new Date(specProps ? specProps.get_FullDate() : undefined)); + // align + var offset = controlsContainer.offset(), + docW = Common.Utils.innerWidth(), + docH = Common.Utils.innerHeight() - 10, // Yep, it's magic number + menuW = this.cmpCalendar.cmpEl.outerWidth(), + menuH = this.cmpCalendar.cmpEl.outerHeight(), + buttonOffset = 22, + left = offset.left - menuW + buttonOffset, + top = offset.top; + if (top + menuH > docH) { + top = docH - menuH; + left -= buttonOffset; + } + if (top < 0) + top = 0; + if (left + menuW > docW) + left = docW - menuW; + this.cmpCalendar.cmpEl.css({left: left, top : top}); documentHolderView._preventClick = true; }, - onHideControlsActions: function() { - var controlsContainer = this.getApplication().getController('DocumentHolder').documentHolder.cmpEl.find('#calendar-control-container'); - if (controlsContainer.is(':visible')) - controlsContainer.hide(); + onShowContentControlsActions: function(obj, x, y) { + var type = obj.type; + switch (type) { + case Asc.c_oAscContentControlSpecificType.TOC: + this.onShowTOCActions(obj, x, y); + break; + case Asc.c_oAscContentControlSpecificType.DateTime: + this.onShowDateActions(obj, x, y); + break; + case Asc.c_oAscContentControlSpecificType.Picture: + break; + case Asc.c_oAscContentControlSpecificType.DropDownList: + case Asc.c_oAscContentControlSpecificType.ComboBox: + break; + } } }, DE.Controllers.Links || {}));