[SSE mobile] added context menu for cell

This commit is contained in:
Maxim Kadushkin 2016-12-26 10:48:53 +03:00
parent 6b12e7e012
commit 878144e5e2
3 changed files with 147 additions and 121 deletions

View file

@ -76,7 +76,7 @@ define([
// this.api.isCEditorFocused = false; // this.api.isCEditorFocused = false;
this.api.asc_registerCallback('asc_onSelectionNameChanged', _.bind(this.onApiCellSelection, this)); this.api.asc_registerCallback('asc_onSelectionNameChanged', _.bind(this.onApiCellSelection, this));
// this.api.asc_registerCallback('asc_onEditCell', _.bind(this.onApiEditCell, this)); this.api.asc_registerCallback('asc_onEditCell', _.bind(this.onApiEditCell, this));
// 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)); // Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiDisconnect, this));
// Common.NotificationCenter.on('cells:range', _.bind(this.onCellsRange, this)); // Common.NotificationCenter.on('cells:range', _.bind(this.onCellsRange, this));

View file

@ -48,8 +48,15 @@ define([
SSE.Controllers.DocumentHolder = Backbone.Controller.extend((function() { SSE.Controllers.DocumentHolder = Backbone.Controller.extend((function() {
// private // private
var _stack, var _isEdit = false;
_isEdit = false;
function openLink(url) {
var newDocumentPage = window.open(url, '_blank');
if (newDocumentPage) {
newDocumentPage.focus();
}
}
return { return {
models: [], models: [],
@ -69,8 +76,8 @@ define([
setApi: function(api) { setApi: function(api) {
this.api = api; this.api = api;
// this.api.asc_registerCallback('asc_onShowPopMenu', _.bind(this.onApiShowPopMenu, this)); this.api.asc_registerCallback('asc_onShowPopMenu', _.bind(this.onApiShowPopMenu, this));
// this.api.asc_registerCallback('asc_onHidePopMenu', _.bind(this.onApiHidePopMenu, this)); this.api.asc_registerCallback('asc_onHidePopMenu', _.bind(this.onApiHidePopMenu, this));
}, },
setMode: function (mode) { setMode: function (mode) {
@ -88,33 +95,48 @@ define([
// Handlers // Handlers
onContextMenuClick: function (view, eventName) { onContextMenuClick: function (view, event) {
var me = this; var me = this;
var info = me.api.asc_getCellInfo();
if ('cut' == eventName) { switch (event) {
me.api.asc_Cut(); case 'cut': me.api.asc_Cut(); break;
} else if ('copy' == eventName) { case 'copy': me.api.asc_Copy(); break;
me.api.asc_Copy(); case 'paste': me.api.asc_Paste(); break;
} else if ('paste' == eventName) { case 'del': me.api.asc_emptyCells(Asc.c_oAscCleanOptions.All); break;
me.api.asc_Paste(); case 'wrap': me.api.asc_setCellTextWrap(true); break;
} else if ('delete' == eventName) { case 'unwrap': me.api.asc_setCellTextWrap(false); break;
console.debug('IMPLEMENT: Delete fragment'); case 'edit':
} else if ('edit' == eventName) {
me.view.hideMenu(); me.view.hideMenu();
SSE.getController('EditContainer').showModal();
} else if ('addlink' == eventName) {
me.view.hideMenu();
SSE.getController('AddContainer').showModal(); SSE.getController('AddContainer').showModal();
SSE.getController('AddOther').getView('AddOther').showLink(); // SSE.getController('EditCell').getView('EditCell');
} else if ('openlink' == eventName) { break;
_.some(_stack, function (item) { case 'merge':
if (item.get_ObjectType() == Asc.c_oAscTypeSelectElement.Hyperlink) { if (me.api.asc_mergeCellsDataLost(Asc.c_oAscMergeOptions.Merge)) {
me._openLink(item.get_ObjectValue().get_Value()); uiApp.confirm(me.warnMergeLostData, undefined, function(){
return true; me.api.asc_mergeCells(Asc.c_oAscMergeOptions.Merge);
} });
}); } else {
me.api.asc_mergeCells(Asc.c_oAscMergeOptions.Merge);
}
break;
case 'unmerge':
me.api.asc_mergeCells(Asc.c_oAscMergeOptions.Unmerge);
break;
case 'addlink':
me.view.hideMenu();
SSE.getController('AddContainer').showModal();
SSE.getController('AddOther').getView('AddOther').showInsertLink();
break;
case 'openlink':
var linkinfo = info.asc_getHyperlink();
if ( linkinfo.asc_getType() == Asc.c_oAscHyperlinkType.RangeLink ) {
/* not implemented in sdk */
} else {
var url = linkinfo.asc_getHyperlinkUrl().replace(/\s/g, "%20");
me.api.asc_getUrlType(url) > 0 && openLink(url);
}
break;
} }
me.view.hideMenu(); me.view.hideMenu();
@ -127,6 +149,8 @@ define([
}, },
onApiShowPopMenu: function(posX, posY) { onApiShowPopMenu: function(posX, posY) {
// if ( !this.permitions.isEdit ) return;
if ($('.popover.settings, .popup.settings, .picker-modal.settings').length > 0) { if ($('.popover.settings, .popup.settings, .picker-modal.settings').length > 0) {
return; return;
} }
@ -134,10 +158,9 @@ define([
var me = this, var me = this,
items; items;
_stack = me.api.getSelectedElements(); items = me._initMenu(me.api.asc_getCellInfo());
items = me._initMenu(_stack);
me.view.showMenu(items, posX, posY); me.view.showMenu(items, posX + 200, posY + 100);
}, },
onApiHidePopMenu: function() { onApiHidePopMenu: function() {
@ -146,104 +169,108 @@ define([
// Internal // Internal
_openLink: function(url) { _initMenu: function (cellinfo) {
if (this.api.asc_getUrlType(url) > 0) { var me = this;
var newDocumentPage = window.open(url, '_blank');
if (newDocumentPage) { if ( this.api.isCellEdited ) {
newDocumentPage.focus(); menuItems = [{
} caption: 'Copy',
} event: 'copy'
}, }];
_initMenu: function (stack) { } else {
var me = this, var menuItems = [
menuItems = [], {
canCopy = me.api.can_CopyCut();
if (canCopy) {
menuItems.push({
caption: 'Copy',
event: 'copy'
});
}
var isText = false,
isTable = false,
isImage = false,
isChart = false,
isShape = false,
isLink = false;
_.each(stack, function (item) {
var objectType = item.get_ObjectType(),
objectValue = item.get_ObjectValue();
if (objectType == Asc.c_oAscTypeSelectElement.Text) {
isText = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Image) {
if (objectValue && objectValue.get_ChartProperties()) {
isChart = true;
} else if (objectType && objectValue.get_ShapeProperties()) {
isShape = true;
} else {
isImage = true;
}
} else if (objectType == Asc.c_oAscTypeSelectElement.Table) {
isTable = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Hyperlink) {
isLink = true;
}
});
if (stack.length > 0) {
var topObject = stack[stack.length - 1],
topObjectType = topObject.get_ObjectType(),
topObjectValue = topObject.get_ObjectValue(),
objectLocked = _.isFunction(topObjectValue.get_Locked) ? topObjectValue.get_Locked() : false;
var swapItems = function(items, indexBefore, indexAfter) {
items[indexAfter] = items.splice(indexBefore, 1, items[indexAfter])[0];
};
if (!objectLocked && _isEdit) {
menuItems.push({
caption: 'Cut', caption: 'Cut',
event: 'cut' event: 'cut'
}); },
menuItems.push({ {
caption: 'Copy',
event: 'copy'
},
{
caption: 'Paste', caption: 'Paste',
event: 'paste' event: 'paste'
}); }
];
// Swap 'Copy' and 'Cut' var iscellmenu, isrowmenu, iscolmenu, isallmenu, ischartmenu, isimagemenu, istextshapemenu, isshapemenu, istextchartmenu,
swapItems(menuItems, 0, 1); seltype = cellinfo.asc_getFlags().asc_getSelectionType(),
iscelllocked = cellinfo.asc_getLocked(),
isTableLocked = cellinfo.asc_getLockedTable()===true;
menuItems.push({ switch (seltype) {
caption: 'Delete', case Asc.c_oAscSelectionType.RangeCells: iscellmenu = true; break;
event: 'delete' case Asc.c_oAscSelectionType.RangeRow: isrowmenu = true; break;
}); case Asc.c_oAscSelectionType.RangeCol: iscolmenu = true; break;
case Asc.c_oAscSelectionType.RangeMax: isallmenu = true; break;
case Asc.c_oAscSelectionType.RangeImage: isimagemenu = true; break;
case Asc.c_oAscSelectionType.RangeShape: isshapemenu = true; break;
case Asc.c_oAscSelectionType.RangeChart: ischartmenu = true; break;
case Asc.c_oAscSelectionType.RangeChartText: istextchartmenu = true; break;
case Asc.c_oAscSelectionType.RangeShapeText: istextshapemenu = true; break;
}
if (isimagemenu || isshapemenu || ischartmenu) {
menuItems.push({ menuItems.push({
caption: 'Edit', caption: 'Edit',
event: 'edit' event: 'edit'
}); });
} } else
if (istextshapemenu || istextchartmenu) {
} else {
if ( iscellmenu ) {
!iscelledited &&
menuItems.push({
caption: 'Delete',
event: 'del'
});
var text = me.api.can_AddHyperlink(); !iscelllocked &&
menuItems.push({
caption: 'Cell',
event: 'edit'
});
if (!_.isEmpty(text)) { menuItems.push({
menuItems.push({ caption: 'Merge',
caption: 'Add Link', event: 'merge'
event: 'addlink' });
});
}
if (isLink) { cellinfo.asc_getFlags().asc_getMerge() &&
menuItems.push({ menuItems.push({
caption: 'Open Link', caption: 'Unmerge',
event: 'openlink' event: 'unmerge'
}); });
menuItems.push(
cellinfo.asc_getFlags().asc_getWrapText() ?
{
caption: 'Unwrap',
event: 'unwrap'
} :
{
caption: 'Wrap',
event: 'wrap'
});
if ( cellinfo.asc_getHyperlink() && !iscelledited && !cellinfo.asc_getFlags().asc_getMultiselect() &&
cellinfo.asc_getHyperlink().asc_getType() == Asc.c_oAscHyperlinkType.WebLink )
{
menuItems.push({
caption: 'Open Link',
event: 'openlink'
});
} else
if ( !cellinfo.asc_getHyperlink() && !iscelledited && !cellinfo.asc_getFlags().asc_getMultiselect() &&
!cellinfo.asc_getFlags().asc_getLockText() && !!cellinfo.asc_getText() )
{
menuItems.push({
caption: 'Add Link',
event: 'addlink'
});
}
}
} }
} }
@ -252,7 +279,9 @@ define([
} }
return menuItems; return menuItems;
} },
warnMergeLostData: 'Operation can destroy data in the selected cells.<br>Continue?'
} }
})()); })());
}); });

View file

@ -60,17 +60,15 @@ define([
// Set innerHTML and get the references to the DOM elements // Set innerHTML and get the references to the DOM elements
initialize: function() { initialize: function() {
// Common.NotificationCenter.on('document:ready', function () {
this.$el.append(this.template());
}.bind(this));
}, },
// Render layout // Render layout
render: function() { render: function() {
var el = $(this.el); var el = $(this.el);
el.append(this.template({
//
}));
// this.f7View = uiApp.addView('.view-main', { // this.f7View = uiApp.addView('.view-main', {
// // params // // params
// }); // });
@ -121,8 +119,7 @@ define([
hideMenu: function () { hideMenu: function () {
$('#' + _anchorId) $('#' + _anchorId)
.css('left', -1000) .css({'left': -1000, 'top': -1000});
.css('top', -1000);
uiApp.closeModal('.document-menu.modal-in'); uiApp.closeModal('.document-menu.modal-in');
} }