web-apps/apps/presentationeditor/mobile/app/controller/DocumentHolder.js

447 lines
18 KiB
JavaScript
Raw Normal View History

2016-12-20 09:51:21 +00:00
/*
*
* (c) Copyright Ascensio System SIA 2010-2019
2016-12-20 09:51:21 +00:00
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
2016-12-20 09:51:21 +00:00
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
/**
* DocumentHolder.js
* Presentation Editor
*
* Created by Julia Radzhabova on 12/19/16
2018-03-01 12:16:38 +00:00
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
2016-12-20 09:51:21 +00:00
*
*/
define([
'core',
2016-12-22 11:06:59 +00:00
'jquery',
'underscore',
'backbone',
2016-12-20 09:51:21 +00:00
'presentationeditor/mobile/app/view/DocumentHolder'
2016-12-22 14:28:19 +00:00
], function (core, $, _, Backbone) {
2016-12-20 09:51:21 +00:00
'use strict';
PE.Controllers.DocumentHolder = Backbone.Controller.extend(_.extend((function() {
// private
var _stack,
2016-12-22 11:06:59 +00:00
_view,
_actionSheets = [],
2016-12-22 11:06:59 +00:00
_isEdit = false,
_isPopMenuHidden = false,
_isComments = false,
_canViewComments = true;
2016-12-20 09:51:21 +00:00
return {
models: [],
collections: [],
views: [
'DocumentHolder'
],
initialize: function() {
this.addListeners({
'DocumentHolder': {
'contextmenu:click' : this.onContextMenuClick
}
});
},
setApi: function(api) {
2016-12-22 11:06:59 +00:00
var me = this;
me.api = api;
2016-12-20 09:51:21 +00:00
me.api.asc_registerCallback('asc_onShowPopMenu', _.bind(me.onApiShowPopMenu, me));
me.api.asc_registerCallback('asc_onHidePopMenu', _.bind(me.onApiHidePopMenu, me));
me.api.asc_registerCallback('asc_onDocumentContentReady', _.bind(me.onApiDocumentContentReady, me));
Common.NotificationCenter.on('api:disconnect', _.bind(me.onCoAuthoringDisconnect, me));
2018-05-23 11:43:30 +00:00
me.api.asc_registerCallback('asc_onCoAuthoringDisconnect', _.bind(me.onCoAuthoringDisconnect,me));
me.api.asc_registerCallback('asc_onShowComment', _.bind(me.onApiShowComment, me));
me.api.asc_registerCallback('asc_onHideComment', _.bind(me.onApiHideComment, me));
},
onApiShowComment: function(comments) {
_isComments = comments && comments.length>0;
},
onApiHideComment: function() {
_isComments = false;
2016-12-20 09:51:21 +00:00
},
setMode: function (mode) {
_isEdit = mode.isEdit;
_canViewComments = mode.canViewComments;
2016-12-20 09:51:21 +00:00
},
// When our application is ready, lets get started
onLaunch: function() {
var me = this;
2016-12-22 11:06:59 +00:00
_view = me.createView('DocumentHolder').render();
2016-12-20 09:51:21 +00:00
$$(window).on('resize', _.bind(me.onEditorResize, me));
},
// Handlers
onContextMenuClick: function (view, eventName) {
var me = this;
if ('cut' == eventName) {
2020-02-19 08:15:17 +00:00
var res = me.api.Cut();
if (!res) {
_view.hideMenu();
2020-03-19 11:52:52 +00:00
if (!Common.localStorage.getBool("pe-hide-copy-cut-paste-warning")) {
uiApp.modal({
title: me.textCopyCutPasteActions,
text: me.errorCopyCutPaste,
afterText: '<label class="label-checkbox item-content no-ripple">' +
'<input type="checkbox" name="checkbox-show-cut">' +
'<div class="item-media" style="margin-top: 10px; display: flex; align-items: center;">' +
'<i class="icon icon-form-checkbox"></i><span style="margin-left: 10px;">' + me.textDoNotShowAgain + '</span>' +
'</div>' +
'</label>',
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);
}
}]
});
}
2020-02-19 08:15:17 +00:00
}
2016-12-20 09:51:21 +00:00
} else if ('copy' == eventName) {
2020-02-19 08:15:17 +00:00
var res = me.api.Copy();
if (!res) {
_view.hideMenu();
2020-03-19 11:52:52 +00:00
if (!Common.localStorage.getBool("pe-hide-copy-cut-paste-warning")) {
uiApp.modal({
title: me.textCopyCutPasteActions,
text: me.errorCopyCutPaste,
afterText: '<label class="label-checkbox item-content no-ripple">' +
'<input type="checkbox" name="checkbox-show-copy">' +
'<div class="item-media" style="margin-top: 10px; display: flex; align-items: center;">' +
'<i class="icon icon-form-checkbox"></i><span style="margin-left: 10px;">' + me.textDoNotShowAgain + '</span>' +
'</div>' +
'</label>',
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);
}
}]
});
}
2020-02-19 08:15:17 +00:00
}
2016-12-20 09:51:21 +00:00
} else if ('paste' == eventName) {
2020-02-19 08:15:17 +00:00
var res = me.api.Paste();
if (!res) {
_view.hideMenu();
2020-03-19 11:52:52 +00:00
if (!Common.localStorage.getBool("pe-hide-copy-cut-paste-warning")) {
uiApp.modal({
title: me.textCopyCutPasteActions,
text: me.errorCopyCutPaste,
afterText: '<label class="label-checkbox item-content no-ripple">' +
'<input type="checkbox" name="checkbox-show-paste">' +
'<div class="item-media" style="margin-top: 10px; display: flex; align-items: center;">' +
'<i class="icon icon-form-checkbox"></i><span style="margin-left: 10px;">' + me.textDoNotShowAgain + '</span>' +
'</div>' +
'</label>',
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);
}
}]
});
}
2020-02-19 08:15:17 +00:00
}
2016-12-20 09:51:21 +00:00
} else if ('delete' == eventName) {
me.api.asc_Remove();
} else if ('edit' == eventName) {
2016-12-22 11:06:59 +00:00
_view.hideMenu();
2016-12-20 09:51:21 +00:00
PE.getController('EditContainer').showModal();
} else if ('addlink' == eventName) {
2016-12-22 11:06:59 +00:00
_view.hideMenu();
2016-12-20 09:51:21 +00:00
PE.getController('AddContainer').showModal();
uiApp.showTab('#add-other');
PE.getController('AddOther').getView('AddOther').showPageLink();
2016-12-20 09:51:21 +00:00
} 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);
2016-12-20 09:51:21 +00:00
}
2016-12-22 11:06:59 +00:00
_view.hideMenu();
},
stopApiPopMenu: function() {
_isPopMenuHidden = true;
this.onApiHidePopMenu();
},
startApiPopMenu: function() {
_isPopMenuHidden = false;
2016-12-20 09:51:21 +00:00
},
// 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;
2016-12-22 11:06:59 +00:00
2016-12-20 09:51:21 +00:00
var me = this,
items;
_stack = me.api.getSelectedElements();
items = me._initMenu(_stack);
2016-12-22 11:06:59 +00:00
_view.showMenu(items, posX, posY);
2016-12-20 09:51:21 +00:00
},
onApiHidePopMenu: function() {
2016-12-22 11:06:59 +00:00
_view && _view.hideMenu();
2016-12-20 09:51:21 +00:00
},
onApiDocumentContentReady: function () {
_view = this.createView('DocumentHolder').render();
},
2016-12-20 09:51:21 +00:00
// 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);
2016-12-20 09:51:21 +00:00
},
_initMenu: function (stack) {
var me = this,
arrItems = [],
arrItemsIcon = [],
2017-02-07 09:06:05 +00:00
canCopy = me.api.can_CopyCut();
2016-12-20 09:51:21 +00:00
_actionSheets = [];
2016-12-20 09:51:21 +00:00
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({
2016-12-20 09:51:21 +00:00
caption: me.menuCopy,
event: 'copy',
icon: 'icon-copy'
2016-12-20 09:51:21 +00:00
});
}
if (_canViewComments && _isComments && !_isEdit) {
arrItems.push({
caption: me.menuViewComment,
event: 'viewcomment'
});
}
2016-12-20 09:51:21 +00:00
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) {
2016-12-20 09:51:21 +00:00
if (canCopy && isObject) {
arrItemsIcon.push({
2016-12-20 09:51:21 +00:00
caption: me.menuCut,
event: 'cut',
icon: 'icon-cut'
2016-12-20 09:51:21 +00:00
});
// Swap 'Copy' and 'Cut'
swapItems(arrItemsIcon, 0, 1);
2016-12-20 09:51:21 +00:00
}
arrItemsIcon.push({
2016-12-20 09:51:21 +00:00
caption: me.menuPaste,
event: 'paste',
icon: 'icon-paste'
2016-12-20 09:51:21 +00:00
});
if (isObject)
arrItems.push({
2016-12-20 09:51:21 +00:00
caption: me.menuDelete,
event: 'delete'
});
arrItems.push({
2016-12-20 09:51:21 +00:00
caption: me.menuEdit,
event: 'edit'
});
if (!isLink && me.api.can_AddHyperlink()!==false) {
arrItems.push({
2016-12-20 09:51:21 +00:00
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'
});
}
2016-12-20 09:51:21 +00:00
}
}
if (isLink) {
arrItems.push({
2016-12-20 09:51:21 +00:00
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};
2016-12-20 09:51:21 +00:00
return menuItems;
},
onCoAuthoringDisconnect: function() {
this.isDisconnected = true;
},
2016-12-20 09:51:21 +00:00
menuCut: 'Cut',
menuCopy: 'Copy',
menuPaste: 'Paste',
menuEdit: 'Edit',
menuDelete: 'Delete',
menuAddLink: 'Add Link',
menuOpenLink: 'Open Link',
menuMore: 'More',
menuViewComment: 'View Comment',
menuAddComment: 'Add Comment',
2020-02-19 08:15:17 +00:00
sheetCancel: 'Cancel',
textCopyCutPasteActions: 'Copy, Cut and Paste Actions',
2020-03-19 11:52:52 +00:00
errorCopyCutPaste: 'Copy, cut and paste actions using the context menu will be performed within the current file only.',
2020-03-19 13:04:14 +00:00
textDoNotShowAgain: 'Don\'t show again'
2016-12-20 09:51:21 +00:00
}
})(), PE.Controllers.DocumentHolder || {}))
});