',
buttons: [{
text: 'OK',
onClick: function () {
var dontshow = $('input[name="checkbox-show-cut"]').prop('checked');
if (dontshow) Common.localStorage.setItem("pe-hide-copy-cut-paste-warning", 1);
}
}]
});
}
}
} else if ('copy' == eventName) {
var res = me.api.Copy();
if (!res) {
_view.hideMenu();
if (!Common.localStorage.getBool("pe-hide-copy-cut-paste-warning")) {
uiApp.modal({
title: me.textCopyCutPasteActions,
text: me.errorCopyCutPaste,
afterText: '',
buttons: [{
text: 'OK',
onClick: function () {
var dontshow = $('input[name="checkbox-show-copy"]').prop('checked');
if (dontshow) Common.localStorage.setItem("pe-hide-copy-cut-paste-warning", 1);
}
}]
});
}
}
} else if ('paste' == eventName) {
var res = me.api.Paste();
if (!res) {
_view.hideMenu();
if (!Common.localStorage.getBool("pe-hide-copy-cut-paste-warning")) {
uiApp.modal({
title: me.textCopyCutPasteActions,
text: me.errorCopyCutPaste,
afterText: '',
buttons: [{
text: 'OK',
onClick: function () {
var dontshow = $('input[name="checkbox-show-paste"]').prop('checked');
if (dontshow) Common.localStorage.setItem("pe-hide-copy-cut-paste-warning", 1);
}
}]
});
}
}
} else if ('delete' == eventName) {
me.api.asc_Remove();
} else if ('edit' == eventName) {
_view.hideMenu();
PE.getController('EditContainer').showModal();
} else if ('addlink' == eventName) {
_view.hideMenu();
PE.getController('AddContainer').showModal();
uiApp.showTab('#add-other');
PE.getController('AddOther').getView('AddOther').showPageLink();
} else if ('openlink' == eventName) {
_.some(_stack, function (item) {
if (item.get_ObjectType() == Asc.c_oAscTypeSelectElement.Hyperlink) {
me._openLink(item.get_ObjectValue().get_Value());
return true;
}
});
} else if ('viewcomment' == eventName) {
var getCollaboration = PE.getController('Common.Controllers.Collaboration');
getCollaboration.showCommentModal();
} else if ('addcomment' == eventName) {
_view.hideMenu();
PE.getController('AddContainer').showModal();
PE.getController('AddOther').getView('AddOther').showPageComment(false);
} else if ('showActionSheet' == eventName && _actionSheets.length > 0) {
_.delay(function () {
_.each(_actionSheets, function (action) {
action.text = action.caption
action.onClick = function () {
me.onContextMenuClick(null, action.event)
}
});
uiApp.actions([_actionSheets, [
{
text: me.sheetCancel,
bold: true
}
]]);
}, 100);
}
_view.hideMenu();
},
stopApiPopMenu: function() {
_isPopMenuHidden = true;
this.onApiHidePopMenu();
},
startApiPopMenu: function() {
_isPopMenuHidden = false;
},
// API Handlers
onEditorResize: function(cmp) {
// Hide context menu
},
onApiShowPopMenu: function(posX, posY) {
if (_isPopMenuHidden || $('.popover.settings, .popup.settings, .picker-modal.settings, .modal-in, .actions-modal').length > 0)
return;
var me = this,
items;
_stack = me.api.getSelectedElements();
items = me._initMenu(_stack);
_view.showMenu(items, posX, posY);
},
onApiHidePopMenu: function() {
_view && _view.hideMenu();
},
onApiDocumentContentReady: function () {
_view = this.createView('DocumentHolder').render();
},
// Internal
_openLink: function(url) {
if (this.api.asc_getUrlType(url) > 0) {
var newDocumentPage = window.open(url, '_blank');
if (newDocumentPage) {
newDocumentPage.focus();
}
} else
this.api.asc_GoToInternalHyperlink(url);
},
_initMenu: function (stack) {
var me = this,
arrItems = [],
arrItemsIcon = [],
canCopy = me.api.can_CopyCut();
_actionSheets = [];
var isText = false,
isTable = false,
isImage = false,
isChart = false,
isShape = false,
isLink = false,
isSlide = false,
isObject = false;
_.each(stack, function (item) {
var objectType = item.get_ObjectType(),
objectValue = item.get_ObjectValue();
if (objectType == Asc.c_oAscTypeSelectElement.Paragraph) {
isText = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Image) {
isImage = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Chart) {
isChart = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Shape) {
isShape = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Table) {
isTable = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Hyperlink) {
isLink = true;
} else if (objectType == Asc.c_oAscTypeSelectElement.Slide) {
isSlide = true;
}
});
isObject = isText || isImage || isChart || isShape || isTable;
if (canCopy && isObject) {
arrItemsIcon.push({
caption: me.menuCopy,
event: 'copy',
icon: 'icon-copy'
});
}
if (_canViewComments && _isComments && !_isEdit) {
arrItems.push({
caption: me.menuViewComment,
event: 'viewcomment'
});
}
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;
!objectLocked && (objectLocked = _.isFunction(topObjectValue.get_LockDelete) ? topObjectValue.get_LockDelete() : false);
var swapItems = function(items, indexBefore, indexAfter) {
items[indexAfter] = items.splice(indexBefore, 1, items[indexAfter])[0];
};
if (!objectLocked && _isEdit && !me.isDisconnected) {
if (canCopy && isObject) {
arrItemsIcon.push({
caption: me.menuCut,
event: 'cut',
icon: 'icon-cut'
});
// Swap 'Copy' and 'Cut'
swapItems(arrItemsIcon, 0, 1);
}
arrItemsIcon.push({
caption: me.menuPaste,
event: 'paste',
icon: 'icon-paste'
});
if (isObject)
arrItems.push({
caption: me.menuDelete,
event: 'delete'
});
arrItems.push({
caption: me.menuEdit,
event: 'edit'
});
if (!isLink && me.api.can_AddHyperlink()!==false) {
arrItems.push({
caption: me.menuAddLink,
event: 'addlink'
});
}
if (_isComments && _canViewComments) {
arrItems.push({
caption: me.menuViewComment,
event: 'viewcomment'
});
}
var hideAddComment = (isText && isChart) || me.api.can_AddQuotedComment() === false || !_canViewComments;
if (!hideAddComment) {
arrItems.push({
caption: me.menuAddComment,
event: 'addcomment'
});
}
}
}
if (isLink) {
arrItems.push({
caption: me.menuOpenLink,
event: 'openlink'
});
}
if (Common.SharedSettings.get('phone') && arrItems.length > 2) {
_actionSheets = arrItems.slice(2);
arrItems = arrItems.slice(0, 2);
arrItems.push({
caption: me.menuMore,
event: 'showActionSheet'
});
}
var menuItems = {itemsIcon: arrItemsIcon, items: arrItems};
return menuItems;
},
onCoAuthoringDisconnect: function() {
this.isDisconnected = true;
},
menuCut: 'Cut',
menuCopy: 'Copy',
menuPaste: 'Paste',
menuEdit: 'Edit',
menuDelete: 'Delete',
menuAddLink: 'Add Link',
menuOpenLink: 'Open Link',
menuMore: 'More',
menuViewComment: 'View Comment',
menuAddComment: 'Add Comment',
sheetCancel: 'Cancel',
textCopyCutPasteActions: 'Copy, Cut and Paste Actions',
errorCopyCutPaste: 'Copy, cut and paste actions using the context menu will be performed within the current file only.',
textDoNotShowAgain: 'Don\'t show again'
}
})(), PE.Controllers.DocumentHolder || {}))
});