From 8cefc20a94b2b0dbe9eda8febc5ca40df80cfc45 Mon Sep 17 00:00:00 2001 From: Julia Svinareva Date: Fri, 24 Jan 2020 14:26:16 +0300 Subject: [PATCH] [SSE] Move sheet: drag and drop --- apps/common/main/lib/component/TabBar.js | 14 +++++++++++++ .../main/app/controller/Main.js | 2 ++ .../main/app/view/Statusbar.js | 21 ++++++++++++++----- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/apps/common/main/lib/component/TabBar.js b/apps/common/main/lib/component/TabBar.js index a7a93d000..b9563e70f 100644 --- a/apps/common/main/lib/component/TabBar.js +++ b/apps/common/main/lib/component/TabBar.js @@ -233,6 +233,8 @@ define([ this.trigger('tab:contextmenu', this, this.tabs.indexOf(tab), tab, this.selectTabs); }, this.bar), mousedown: $.proxy(function (e) { + if ((3 !== e.which) && !e.ctrlKey && !e.metaKey && !e.shiftKey) + tab.changeState(); /*if (this.bar.options.draggable && !_.isUndefined(dragHelper) && (3 !== e.which)) { if (!tab.isLockTheDrag) { if (!e.ctrlKey && !e.metaKey && !e.shiftKey) @@ -261,8 +263,12 @@ define([ event.preventDefault(); // Necessary. Allows us to drop. } event.dataTransfer.dropEffect = 'move'; + $(e.currentTarget).parent().addClass('mousemove'); return false; }, this), + dragleave: $.proxy(function (e) { + $(e.currentTarget).parent().removeClass('mousemove right'); + }, this), dragend: $.proxy(function (e) { this.bar.$el.find('.mousemove').removeClass('mousemove right'); }, this), @@ -318,6 +324,14 @@ define([ this.tabs[this.tabs.length - 1].$el.addClass('mousemove right'); return false; }, this)); + addEvent(this.$bar[0], 'dragleave', _.bind(function (event) { + this.tabs[this.tabs.length - 1].$el.removeClass('mousemove right'); + }, this)); + addEvent(this.$bar[0], 'drop', _.bind(function (event) { + var index = this.tabs.length; + this.$el.find('.mousemove').removeClass('mousemove right'); + this.trigger('tab:drop', event.dataTransfer, index); + }, this)); this.manager = new StateManager({bar: this}); diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 079a93b65..2a99a4dac 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -410,6 +410,8 @@ define([ docInfo.put_Permissions(_permissions); this.headerView && this.headerView.setDocumentCaption(data.doc.title); + + Common.Utils.InternalSettings.set("sse-doc-info-key", data.doc.key); } this.api.asc_registerCallback('asc_onGetEditorPermissions', _.bind(this.onEditorPermissions, this)); diff --git a/apps/spreadsheeteditor/main/app/view/Statusbar.js b/apps/spreadsheeteditor/main/app/view/Statusbar.js index 0e6896414..5eeef398d 100644 --- a/apps/spreadsheeteditor/main/app/view/Statusbar.js +++ b/apps/spreadsheeteditor/main/app/view/Statusbar.js @@ -210,18 +210,29 @@ define([ arrTabs.push(item.sheetindex); arrName.push(me.api.asc_getWorksheetName(item.sheetindex)); }); - var stringSheet = this.api.asc_StartMoveSheet(arrTabs), + var stringSheet, stringSheetJson, - stringNameJson; + stringNameJson, + stringIndexJson; + stringIndexJson = JSON.stringify(arrTabs); + stringSheet = this.api.asc_StartMoveSheet(arrTabs); stringSheetJson = JSON.stringify(stringSheet); stringNameJson = JSON.stringify(arrName); dataTransfer.setData("onlyoffice", stringSheetJson); dataTransfer.setData("name", stringNameJson); + dataTransfer.setData("arrindex", stringIndexJson); + dataTransfer.setData("key", Common.Utils.InternalSettings.get("sse-doc-info-key")); }, this), 'tab:drop' : _.bind(function (dataTransfer, index) { - var arrSheets = dataTransfer.getData("onlyoffice"), - arrNames = dataTransfer.getData("name"); - this.api.asc_EndMoveSheet(index, JSON.parse(arrNames), JSON.parse(arrSheets)); + var arrSheets = JSON.parse(dataTransfer.getData("onlyoffice")), + arrNames = JSON.parse(dataTransfer.getData("name")), + arrIndex = JSON.parse(dataTransfer.getData("arrindex")), + key = dataTransfer.getData("key"); + if (Common.Utils.InternalSettings.get("sse-doc-info-key") === key) { + this.api.asc_moveWorksheet(index, arrIndex); + } else { + this.api.asc_EndMoveSheet(index, arrNames, arrSheets); + } }, this) });