From 10d1ea2e1ca42206f7cc19a4fec3d077047b2f2c Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 15 Jul 2020 19:12:17 +0300 Subject: [PATCH] [SSE] Add sheet view locking --- .../main/app/controller/ViewTab.js | 29 +++++++- .../main/app/view/ViewManagerDlg.js | 68 +++++++++++++++---- 2 files changed, 82 insertions(+), 15 deletions(-) diff --git a/apps/spreadsheeteditor/main/app/controller/ViewTab.js b/apps/spreadsheeteditor/main/app/controller/ViewTab.js index 168bec832..89976d893 100644 --- a/apps/spreadsheeteditor/main/app/controller/ViewTab.js +++ b/apps/spreadsheeteditor/main/app/controller/ViewTab.js @@ -58,6 +58,7 @@ define([ initialize: function () { }, onLaunch: function () { + this._state = {}; }, setApi: function (api) { @@ -68,6 +69,7 @@ define([ this.api.asc_registerCallback('asc_onWorksheetLocked', _.bind(this.onWorksheetLocked, this)); this.api.asc_registerCallback('asc_onSheetsChanged', this.onApiSheetChanged.bind(this)); this.api.asc_registerCallback('asc_onUpdateSheetViewSettings', this.onApiSheetChanged.bind(this)); + this.api.asc_registerCallback('asc_onLockNamedSheetViewManager', this.onLockNamedSheetViewManager.bind(this)); this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); } @@ -97,6 +99,7 @@ define([ } }); Common.NotificationCenter.on('layout:changed', _.bind(this.onLayoutChanged, this)); + Common.NotificationCenter.on('sheetview:locked', _.bind(this.onSheetViewLocked, this)); }, SetDisabled: function(state) { @@ -165,6 +168,10 @@ define([ }, onCreateView: function(item) { + if (this._state.viewlocked) { + Common.NotificationCenter.trigger('sheetview:locked'); + return; + } this.api && this.api.asc_addNamedSheetView(null, true); }, @@ -172,6 +179,7 @@ define([ var me = this; (new SSE.Views.ViewManagerDlg({ api: this.api, + locked: this._state.viewlocked, handler: function(result, value) { if (result == 'ok' && value) { if (me.api) { @@ -212,7 +220,26 @@ define([ onApiZoomChange: function(zf, type){ var value = Math.floor((zf + .005) * 100); this.view.cmbZoom.setValue(value, value + '%'); - } + }, + + onSheetViewLocked: function() { + var me = this; + if ($('.asc-window.modal.alert:visible').length < 1) { + Common.UI.warning({ + msg: this.errorEditView, + maxwidth: 500, + callback: _.bind(function(btn){ + Common.NotificationCenter.trigger('edit:complete', me.view); + }, this) + }); + } + }, + + onLockNamedSheetViewManager: function(state) { + this._state.viewlocked = state; + }, + + errorEditView: 'The existing sheet view cannot be edited and the new ones cannot be created at the moment as some of them are being edited.' }, SSE.Controllers.ViewTab || {})); }); \ No newline at end of file diff --git a/apps/spreadsheeteditor/main/app/view/ViewManagerDlg.js b/apps/spreadsheeteditor/main/app/view/ViewManagerDlg.js index af713d68a..f1120cbbd 100644 --- a/apps/spreadsheeteditor/main/app/view/ViewManagerDlg.js +++ b/apps/spreadsheeteditor/main/app/view/ViewManagerDlg.js @@ -95,13 +95,15 @@ define([ ].join('') }, options); - this.api = options.api; + this.api = options.api; this.views = options.views || []; + this.locked = options.locked || false; this.userTooltip = true; this.currentView = undefined; this.wrapEvents = { - onRefreshNamedSheetViewList: _.bind(this.onRefreshNamedSheetViewList, this) + onRefreshNamedSheetViewList: _.bind(this.onRefreshNamedSheetViewList, this), + onLockNamedSheetViewManager: _.bind(this.onLockNamedSheetViewManager, this) }; Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options); @@ -117,7 +119,7 @@ define([ emptyText: this.textEmpty, template: _.template(['
'].join('')), itemTemplate: _.template([ - '
', + '
', '
<%= name %>
', '<% if (lock) { %>', '
<%=lockuser%>
', @@ -160,24 +162,30 @@ define([ _setDefaults: function (props) { this.refreshList(this.views, 0); this.api.asc_registerCallback('asc_onRefreshNamedSheetViewList', this.wrapEvents.onRefreshNamedSheetViewList); + this.api.asc_registerCallback('asc_onLockNamedSheetViewManager', this.wrapEvents.onLockNamedSheetViewManager); }, onRefreshNamedSheetViewList: function() { this.refreshList(this.api.asc_getNamedSheetViews(), this.currentView); }, + onLockNamedSheetViewManager: function(state) { + this.locked = state; + }, + refreshList: function(views, selectedItem) { if (views) { this.views = views; var arr = []; for (var i=0; i0) - // this.viewList.cmpEl.on('mouseover', _.bind(me.onMouseOverLock, me)).on('mouseout', _.bind(me.onMouseOutLock, me)); + if (this.userTooltip===true && this.viewList.cmpEl.find('.lock-user').length>0) + this.viewList.cmpEl.on('mouseover', _.bind(this.onMouseOverLock, this)).on('mouseout', _.bind(this.onMouseOutLock, this)); } var me = this; @@ -234,19 +242,48 @@ define([ }, onNew: function (duplicate) { + if (this.locked) { + Common.NotificationCenter.trigger('sheetview:locked'); + return; + } var rec = duplicate ? this.viewList.getSelectedRec().get('view') : undefined; this.currentView = this.viewList.store.length; this.api.asc_addNamedSheetView(rec); }, onDelete: function () { - var rec = this.viewList.getSelectedRec(); + var me = this, + rec = this.viewList.getSelectedRec(), + res; if (rec) { - this.api.asc_deleteNamedSheetViews([rec.get('view')]); + if (rec.get('active')) { + Common.UI.warning({ + msg: this.warnDeleteView.replace('%1', rec.get('name')), + buttons: ['yes', 'no'], + primary: 'yes', + callback: function(btn) { + if (btn == 'yes') { + res = me.api.asc_deleteNamedSheetViews([rec.get('view')]); + if (res) {// error when deleting + Common.UI.warning({msg: me.errorDeleteView.replace('%1', rec.get('name')), maxwidth: 500}); + } + } + } + }); + } else { + res = this.api.asc_deleteNamedSheetViews([rec.get('view')]); + if (res) {// error when deleting + Common.UI.warning({msg: this.errorDeleteView.replace('%1', rec.get('name')), maxwidth: 500}); + } + } } }, onRename: function () { + if (this.locked) { + Common.NotificationCenter.trigger('sheetview:locked'); + return; + } var rec = this.viewList.getSelectedRec(); if (rec) { var me = this; @@ -290,14 +327,15 @@ define([ return; } this.currentView = _.indexOf(this.viewList.store.models, record); - // this.btnRename.setDisabled(rawData.lock); - // this.btnDelete.setDisabled(rawData.lock); + this.btnRename.setDisabled(rawData.lock); + this.btnDelete.setDisabled(rawData.lock); } }, close: function () { this.userTipHide(); this.api.asc_unregisterCallback('asc_onRefreshNamedSheetViewList', this.wrapEvents.onRefreshNamedSheetViewList); + this.api.asc_unregisterCallback('asc_onLockNamedSheetViewManager', this.wrapEvents.onLockNamedSheetViewManager); Common.Views.AdvancedSettingsWindow.prototype.close.call(this); }, @@ -323,7 +361,9 @@ define([ guestText: 'Guest', tipIsLocked: 'This element is being edited by another user.', textRenameLabel: 'Rename view', - textRenameError: 'View name must not be empty.' + textRenameError: 'View name must not be empty.', + warnDeleteView: "You are trying to delete the currently enabled view '%1'.
Close this view and delete it?", + errorDeleteView: "You cannot delete view '%1' because it is currently being used by other users." }, SSE.Views.ViewManagerDlg || {})); }); \ No newline at end of file