From 0b5edaaee05c570d0de5dd1a60c0529594d9fdbe Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Mon, 9 Jan 2017 11:56:40 +0300 Subject: [PATCH] [SSE mobile] disable 'Add' and 'Edit' options for locked cell --- .../mobile/app/controller/Toolbar.js | 45 +++++++++++++++++++ .../mobile/app/view/Toolbar.js | 11 +++++ 2 files changed, 56 insertions(+) diff --git a/apps/spreadsheeteditor/mobile/app/controller/Toolbar.js b/apps/spreadsheeteditor/mobile/app/controller/Toolbar.js index 77beaeca3..9d05a6b7e 100644 --- a/apps/spreadsheeteditor/mobile/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/mobile/app/controller/Toolbar.js @@ -52,6 +52,10 @@ define([ SSE.Controllers.Toolbar = Backbone.Controller.extend(_.extend((function() { // private var _backUrl; + var locked = { + book: false, + sheet: false + }; return { models: [], @@ -78,6 +82,12 @@ define([ this.api.asc_registerCallback('asc_onCanUndoChanged', _.bind(this.onApiCanRevert, this, 'undo')); this.api.asc_registerCallback('asc_onCanRedoChanged', _.bind(this.onApiCanRevert, this, 'redo')); + this.api.asc_registerCallback('asc_onSelectionChanged', this.onApiSelectionChanged.bind(this)); + this.api.asc_registerCallback('asc_onWorkbookLocked', _.bind(this.onApiWorkbookLocked, this)); + this.api.asc_registerCallback('asc_onWorksheetLocked', _.bind(this.onApiWorksheetLocked, this)); + this.api.asc_registerCallback('asc_onActiveSheetChanged', _.bind(this.onApiActiveSheetChanged, this)); + + Common.NotificationCenter.on('sheet:active', this.onApiActiveSheetChanged.bind(this)); }, setMode: function (mode) { @@ -134,6 +144,18 @@ define([ // API handlers + onApiWorkbookLocked: function (l) { + locked.book = l; + }, + + onApiWorksheetLocked: function (l) { + locked.sheet = l; + }, + + onApiActiveSheetChanged: function (index) { + locked.sheet = this.api.asc_isWorksheetLockedOrDeleted(index); + }, + onApiCanRevert: function(which, can) { if (which == 'undo') { $('#toolbar-undo').toggleClass('disabled', !can); @@ -142,6 +164,29 @@ define([ } }, + onApiSelectionChanged: function(info) { + var islocked = locked.book || locked.sheet; + + if ( !islocked ) { + switch (info.asc_getFlags().asc_getSelectionType()) { + case Asc.c_oAscSelectionType.RangeCells: + islocked = info.asc_getLocked(); + break; + case Asc.c_oAscSelectionType.RangeChart: + var objects = this.api.asc_getGraphicObjectProps(); + for ( var i in objects ) { + if ( objects[i].asc_getObjectType() == Asc.c_oAscTypeSelectElement.Image ) { + if ((islocked = objects[i].asc_getObjectValue().asc_getLocked())) + break; + } + } + break; + } + } + + this.getView('Toolbar').disableControl(['add', 'edit'], islocked); + }, + dlgLeaveTitleText : 'You leave the application', dlgLeaveMsgText : 'You have unsaved changes in this document. Click \'Stay on this Page\' to await the autosave of the document. Click \'Leave this Page\' to discard all the unsaved changes.', leaveButtonText : 'Leave this Page', diff --git a/apps/spreadsheeteditor/mobile/app/view/Toolbar.js b/apps/spreadsheeteditor/mobile/app/view/Toolbar.js index fd4226d22..bcf131140 100644 --- a/apps/spreadsheeteditor/mobile/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/mobile/app/view/Toolbar.js @@ -83,6 +83,9 @@ define([ $('.view-main .navbar').on('addClass removeClass', _.bind(me.onDisplayMainNavbar, me)); + this.$btnEdit = $el.find('#toolbar-edit'); + this.$btnAdd = $el.find('#toolbar-add'); + return me; }, @@ -136,6 +139,14 @@ define([ // Settings showSettings: function () { SSE.getController('Settings').showModal(); + }, + + disableControl: function (opts, val) { + if (!(opts.indexOf('add') < 0)) + this.$btnAdd.toggleClass('disabled', val); + + if (!(opts.indexOf('edit') < 0)) + this.$btnEdit.toggleClass('disabled', val); } } })(), SSE.Views.Toolbar || {}))