From 8194d6fbf8fa37cfed1503ff860fd14e4b4d87f4 Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Thu, 12 Jan 2017 17:03:26 +0300 Subject: [PATCH] [SSE mobile] process locked/disconnected state --- .../mobile/app/controller/Statusbar.js | 108 +++++++++--------- .../mobile/app/view/Statusbar.js | 60 +++------- .../mobile/resources/less/statusbar.less | 6 + 3 files changed, 79 insertions(+), 95 deletions(-) diff --git a/apps/spreadsheeteditor/mobile/app/controller/Statusbar.js b/apps/spreadsheeteditor/mobile/app/controller/Statusbar.js index 88feee787..1903dbd2d 100644 --- a/apps/spreadsheeteditor/mobile/app/controller/Statusbar.js +++ b/apps/spreadsheeteditor/mobile/app/controller/Statusbar.js @@ -75,17 +75,19 @@ define([ this.sheets = this.getApplication().getCollection('Sheets'); this.sheets.bind({ add: function (model, collection, opts) { - console.log('add in collection'); + var $item = me.statusbar.addSheet(model); + model.set('el', $item, {silent:true}); }, change: function (model) { - console.log('change in collection'); + if ( model.changed ) { + if ( model.changed.locked != undefined ) { + model.get('el').toggleClass('locked', model.changed.locked); + } + } }, reset: function (collection, opts) { me.statusbar.clearTabs(); - collection.each(function(model) { - var $item = me.statusbar.addSheet(model); - model.set('el', $item); - }); + me.statusbar.addSheets(collection); } }); @@ -97,21 +99,22 @@ define([ setApi: function(api) { this.api = api; - // this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onApiDisconnect, this)); + this.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(this.onApiDisconnect, this)); // Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiDisconnect, this)); // this.api.asc_registerCallback('asc_onUpdateTabColor', _.bind(this.onApiUpdateTabColor, this)); // this.api.asc_registerCallback('asc_onEditCell', _.bind(this.onApiEditCell, this)); - /** coauthoring begin **/ - // this.api.asc_registerCallback('asc_onWorkbookLocked', _.bind(this.onWorkbookLocked, this)); - // this.api.asc_registerCallback('asc_onWorksheetLocked', _.bind(this.onWorksheetLocked, this)); - /** coauthoring end **/ + this.api.asc_registerCallback('asc_onWorkbookLocked', _.bind(this.onWorkbookLocked, this)); + this.api.asc_registerCallback('asc_onWorksheetLocked', _.bind(this.onWorksheetLocked, this)); // this.api.asc_registerCallback('asc_onError', _.bind(this.onError, this)); - // this.statusbar.setApi(api); - this.api.asc_registerCallback('asc_onSheetsChanged', this.onApiSheetsChanged.bind(this)); }, + setMode: function(mode) { + this.statusbar.setMode(mode); + this.isEdit = mode == 'edit'; + }, + /* * api events * */ @@ -129,8 +132,9 @@ define([ index : i, active : active_index == i, name : me.api.asc_getWorksheetName(i), - cls : locked ? 'coauth-locked':'', - draglocked : locked + // cls : locked ? 'coauth-locked':'', + locked : locked, + color : me.api.asc_getWorksheetTabColor(i) }; (this.api.asc_isWorksheetHidden(i) ? hiddentems : items).push(new SSE.Models.Sheet(tab)); @@ -151,12 +155,14 @@ define([ }, onApiDisconnect: function() { - this.statusbar.setMode({isDisconnected: true}); - this.statusbar.update(); + this.statusbar.setMode('disconnect'); + this.isDisconnected = true; }, - /** coauthoring begin **/ onWorkbookLocked: function(locked) { + this.statusbar.$btnAddTab.toggleClass('disabled', locked); + return; + this.statusbar.tabbar[locked?'addClass':'removeClass']('coauth-locked'); this.statusbar.btnAddWorksheet.setDisabled(locked || this.statusbar.rangeSelectionMode==Asc.c_oAscSelectionDialogType.Chart || this.statusbar.rangeSelectionMode==Asc.c_oAscSelectionDialogType.FormatTable); @@ -172,18 +178,11 @@ define([ } }, - onWorksheetLocked: function(index,locked) { - var count = this.statusbar.tabbar.getCount(), tab; - for (var i = count; i-- > 0; ) { - tab = this.statusbar.tabbar.getAt(i); - if (index == tab.sheetindex) { - tab[locked?'addClass':'removeClass']('coauth-locked'); - tab.isLockTheDrag = locked || (this.statusbar.rangeSelectionMode==Asc.c_oAscSelectionDialogType.FormatTable); - break; - } - } + onWorksheetLocked: function(index, locked) { + var model = this.sheets.findWhere({index: index}); + if ( model && model.get('locked') != locked ) + model.set('locked', locked); }, - /** coauthoring end **/ onApiEditCell: function(state) { var disableAdd = (state == Asc.c_oAscCellEditorState.editFormula), @@ -410,13 +409,6 @@ define([ } }, - onZoomShow: function(e){ - if (e.target.classList.contains('disabled')) { - return false; - } - }, - - onError: function(id, level, errData) { if (id == Asc.c_oAscError.ID.LockedWorksheetRename) this.statusbar.update(); @@ -428,8 +420,13 @@ define([ var sdkindex = model.get('index'); if ( sdkindex == this.api.asc_getActiveWorksheetIndex () ) { - if ( !opened ) - this.statusbar.showTabContextMenu(this._getTabMenuItems(), model); + if ( !opened ) { + if ( this.isEdit && !this.isDisconnected ) { + this.api.asc_closeCellEditor(); + + this.statusbar.showTabContextMenu(this._getTabMenuItems(model), model); + } + } } else { this.api.asc_showWorksheet( sdkindex ); this.statusbar.setActiveTab(index); @@ -475,23 +472,26 @@ define([ }, - _getTabMenuItems: function() { - var items = [ - { - caption: this.menuDuplicate, - event: 'copy' - }, - { - caption: this.menuDelete, - event: 'del' - }, - { - caption: this.menuHide, - event: 'hide' - } - ]; + _getTabMenuItems: function(model) { + var wbLocked = this.api.asc_isWorkbookLocked(); + var shLocked = this.api.asc_isWorksheetLockedOrDeleted(model.get('index')); - if ( this.hiddensheets.length ) { + var items = [{ + caption: this.menuDuplicate, + event: 'copy', + locked: wbLocked || shLocked + },{ + caption: this.menuDelete, + event: 'del', + locked: wbLocked || shLocked + },{ + caption: this.menuHide, + event: 'hide', + locked: wbLocked || shLocked + }]; + + + if ( !wbLocked && !shLocked && this.hiddensheets.length ) { items.push({ caption: this.menuUnhide, event: 'unhide' diff --git a/apps/spreadsheeteditor/mobile/app/view/Statusbar.js b/apps/spreadsheeteditor/mobile/app/view/Statusbar.js index 621afb698..25b9b75b5 100644 --- a/apps/spreadsheeteditor/mobile/app/view/Statusbar.js +++ b/apps/spreadsheeteditor/mobile/app/view/Statusbar.js @@ -49,16 +49,18 @@ define([ el: '.pages > .page', template: '
' + '
' + - '' + + '' + '
' + '
' + '
    ' + '
    ' + '
    ', - tabtemplate: _.template('
  • <%= label %>
  • '), + tabtemplate: _.template('
  • "><%= label %>
  • '), menutemplate: _.template( '<% _.each(menuItems, function(item) { %>' + - '
  • <%= item.caption %>
  • ' + + '
  • ">' + + '<%= item.caption %>' + + '
  • ' + '<% }); %>'), events: {}, @@ -79,30 +81,16 @@ define([ }); // this.editMode = false; - - // this.btnAddWorksheet = new Common.UI.Button({ - // el: $('#status-btn-addtab',this.el), - // hint: this.tipAddTab, - // disabled: true, - // hintAnchor: 'top' - // }); - return this; }, - // setApi: function(api) { - // this.api = api; - // this.api.asc_registerCallback('asc_onSheetsChanged', _.bind(this.update, this)); - // return this; - // }, - setMode: function(mode) { - this.mode = _.extend({}, this.mode, mode); -// this.$el.find('.el-edit')[mode.isEdit?'show':'hide'](); - this.btnAddWorksheet.setVisible(this.mode.isEdit); - this.btnAddWorksheet.setDisabled(this.mode.isDisconnected); - this.lblChangeRights[(!this.mode.isOffline && this.mode.sharingSettingsUrl&&this.mode.sharingSettingsUrl.length)?'show':'hide'](); - // this.updateTabbarBorders(); + if ('edit' == mode) { + this.$btnAddTab.show(); + } else + if ('disconnect' == mode) { + this.$btnAddTab.toggleClass('disabled', true); + } }, setVisible: function(visible) { @@ -112,7 +100,8 @@ define([ addSheet: function(model) { var index = this.$boxTabs.children().length; var $item = $(this.tabtemplate({ - 'label': model.get('name') + label: model.get('name'), + locked: model.get('locked') })).appendTo(this.$boxTabs); $item.on('click', this.onSheetClick.bind(this, index, model)); @@ -120,7 +109,12 @@ define([ return $item; }, - addSheets: function () { + addSheets: function (collection) { + var me = this; + collection.each(function(model) { + var $item = me.addSheet(model); + model.set('el', $item, {silent:true}); + }); }, clearTabs: function () { @@ -213,22 +207,6 @@ define([ ); }, - updateTabbarBorders: function() { - var right = parseInt(this.boxZoom.css('width')), visible = false; - if (this.boxMath.is(':visible')) { - right += parseInt(this.boxMath.css('width')); - visible = true; - } - - if (this.panelUsers.is(':visible')) { - right += parseInt(this.panelUsers.css('width')); - visible = true; - } - - this.boxZoom.find('.separator').css('border-left-color',visible?'':'transparent'); - this.tabBarBox.css('right', right + 'px'); - }, - changeViewMode: function (edit) { if (edit) { this.tabBarBox.css('left', '152px'); diff --git a/apps/spreadsheeteditor/mobile/resources/less/statusbar.less b/apps/spreadsheeteditor/mobile/resources/less/statusbar.less index 9e1d8cd6b..d8ad56e0d 100644 --- a/apps/spreadsheeteditor/mobile/resources/less/statusbar.less +++ b/apps/spreadsheeteditor/mobile/resources/less/statusbar.less @@ -70,4 +70,10 @@ } } } + + .locked { + a { + box-shadow: inset 0 2px #f00; + } + } } \ No newline at end of file