[SSE mobile] process locked/disconnected state

This commit is contained in:
Maxim Kadushkin 2017-01-12 17:03:26 +03:00
parent abd400c9d3
commit 8194d6fbf8
3 changed files with 79 additions and 95 deletions

View file

@ -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'

View file

@ -49,16 +49,18 @@ define([
el: '.pages > .page',
template: '<div class="statusbar">' +
'<div id="box-addtab" class="status-group">' +
'<a href="#" id="btn-addtab" class="button"><i class="icon icon-plus"></i></a>' +
'<a href="#" id="btn-addtab" class="button" style="display:none"><i class="icon icon-plus"></i></a>' +
'</div>' +
'<div class="box-tabs">' +
'<ul class="sheet-tabs bottom"></ul>' +
'</div>' +
'</div>',
tabtemplate: _.template('<li class="tab"><a><%= label %></a></li>'),
tabtemplate: _.template('<li class="tab<% if (locked) print(" locked"); %>"><a><%= label %></a></li>'),
menutemplate: _.template(
'<% _.each(menuItems, function(item) { %>' +
'<li data-event="<%= item.event %>"><a href="#" class="item-link list-button"><%= item.caption %></li>' +
'<li data-event="<%= item.event %>" class="<% if (item.locked===true) print("disabled") %>">' +
'<a href="#" class="item-link list-button"><%= item.caption %>' +
'</li>' +
'<% }); %>'),
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');

View file

@ -70,4 +70,10 @@
}
}
}
.locked {
a {
box-shadow: inset 0 2px #f00;
}
}
}