2017-12-23 08:33:49 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* (c) Copyright Ascensio System Limited 2010-2017
|
|
|
|
*
|
|
|
|
* 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 Lubanas st. 125a-25, Riga, Latvia,
|
|
|
|
* EU, LV-1021.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Links.js
|
|
|
|
*
|
|
|
|
* Created by Julia Radzhabova on 22.12.2017
|
|
|
|
* Copyright (c) 2017 Ascensio System SIA. All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
|
|
|
'core',
|
2017-12-25 12:55:26 +00:00
|
|
|
'documenteditor/main/app/view/Links',
|
|
|
|
'documenteditor/main/app/view/NoteSettingsDialog'
|
2017-12-23 08:33:49 +00:00
|
|
|
], function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
DE.Controllers.Links = Backbone.Controller.extend(_.extend({
|
|
|
|
models : [],
|
|
|
|
collections : [
|
|
|
|
],
|
|
|
|
views : [
|
|
|
|
'Links'
|
|
|
|
],
|
|
|
|
sdkViewName : '#id_main',
|
|
|
|
|
|
|
|
initialize: function () {
|
|
|
|
|
|
|
|
this.addListeners({
|
|
|
|
'Links': {
|
|
|
|
'links:contents': this.onTableContents,
|
2017-12-25 12:55:26 +00:00
|
|
|
'links:update': this.onTableContentsUpdate,
|
|
|
|
'links:notes': this.onNotesClick
|
2017-12-23 08:33:49 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onLaunch: function () {
|
|
|
|
this._state = {};
|
|
|
|
this.editMode = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
setApi: function (api) {
|
|
|
|
if (api) {
|
|
|
|
this.api = api;
|
|
|
|
this.api.asc_registerCallback('asc_onFocusObject', this.onApiFocusObject.bind(this));
|
|
|
|
this.api.asc_registerCallback('asc_onCoAuthoringDisconnect',_.bind(this.onCoAuthoringDisconnect, this));
|
|
|
|
Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this));
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
setConfig: function(config) {
|
|
|
|
this.toolbar = config.toolbar;
|
|
|
|
this.view = this.createView('Links', {
|
|
|
|
toolbar: this.toolbar
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
SetDisabled: function(state) {
|
|
|
|
this.view && this.view.SetDisabled(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
getView: function(name) {
|
|
|
|
return !name && this.view ?
|
|
|
|
this.view : Backbone.Controller.prototype.getView.call(this, name);
|
|
|
|
},
|
|
|
|
|
|
|
|
onCoAuthoringDisconnect: function() {
|
|
|
|
this.editMode = false;
|
|
|
|
this.SetDisabled(true);
|
|
|
|
},
|
|
|
|
|
|
|
|
onApiFocusObject: function(selectedObjects) {
|
|
|
|
if (!this.editMode) return;
|
|
|
|
|
2017-12-25 12:55:26 +00:00
|
|
|
var pr, i = -1, type,
|
2017-12-23 08:33:49 +00:00
|
|
|
paragraph_locked = false,
|
2017-12-25 12:55:26 +00:00
|
|
|
header_locked = false,
|
|
|
|
in_header = false,
|
|
|
|
in_equation = false,
|
|
|
|
in_image = false;
|
2017-12-23 08:33:49 +00:00
|
|
|
|
|
|
|
while (++i < selectedObjects.length) {
|
|
|
|
type = selectedObjects[i].get_ObjectType();
|
|
|
|
pr = selectedObjects[i].get_ObjectValue();
|
|
|
|
|
|
|
|
if (type === Asc.c_oAscTypeSelectElement.Paragraph) {
|
|
|
|
paragraph_locked = pr.get_Locked();
|
|
|
|
} else if (type === Asc.c_oAscTypeSelectElement.Header) {
|
|
|
|
header_locked = pr.get_Locked();
|
2017-12-25 12:55:26 +00:00
|
|
|
in_header = true;
|
|
|
|
} else if (type === Asc.c_oAscTypeSelectElement.Image) {
|
|
|
|
in_image = true;
|
|
|
|
} else if (type === Asc.c_oAscTypeSelectElement.Math) {
|
|
|
|
in_equation = true;
|
2017-12-23 08:33:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-25 12:55:26 +00:00
|
|
|
var need_disable = paragraph_locked || in_equation || in_image || in_header;
|
|
|
|
_.each (this.view.btnsNotes, function(item){
|
|
|
|
item.setDisabled(need_disable);
|
|
|
|
}, this);
|
|
|
|
|
2017-12-23 08:33:49 +00:00
|
|
|
// var need_disable = paragraph_locked || header_locked;
|
|
|
|
// _.each (this.view.btnsContents, function(item){
|
|
|
|
// item.setDisabled(need_disable);
|
|
|
|
// }, this);
|
|
|
|
},
|
|
|
|
|
|
|
|
onTableContents: function(type){
|
|
|
|
switch (type) {
|
|
|
|
case 0:
|
|
|
|
this.api.asc_addTableOfContents(); break;
|
|
|
|
case 1:
|
|
|
|
this.api.asc_addTableOfContents(); break;
|
|
|
|
case 'settins':
|
|
|
|
break;
|
|
|
|
case 'remove':
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onTableContentsUpdate: function(type){
|
|
|
|
if (type == 'pages')
|
|
|
|
this.api.asc_updateTableOfContents();
|
|
|
|
else
|
|
|
|
this.api.asc_updateaddTableOfContents();
|
2017-12-25 12:55:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onNotesClick: function(type) {
|
|
|
|
var me = this;
|
|
|
|
switch (type) {
|
|
|
|
case 'ins_footnote':
|
|
|
|
this.api.asc_AddFootnote();
|
|
|
|
break;
|
|
|
|
case 'delele':
|
|
|
|
Common.UI.warning({
|
|
|
|
msg: this.view.confirmDeleteFootnotes,
|
|
|
|
buttons: ['yes', 'no'],
|
|
|
|
primary: 'yes',
|
|
|
|
callback: _.bind(function (btn) {
|
|
|
|
if (btn == 'yes') {
|
|
|
|
this.api.asc_RemoveAllFootnotes();
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', this.toolbar);
|
|
|
|
}, this)
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'settings':
|
|
|
|
(new DE.Views.NoteSettingsDialog({
|
|
|
|
api: me.api,
|
|
|
|
handler: function (result, settings) {
|
|
|
|
if (settings) {
|
|
|
|
me.api.asc_SetFootnoteProps(settings.props, settings.applyToAll);
|
|
|
|
if (result == 'insert')
|
|
|
|
me.api.asc_AddFootnote(settings.custom);
|
|
|
|
}
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
|
|
|
|
},
|
|
|
|
props: me.api.asc_GetFootnoteProps()
|
|
|
|
})).show();
|
|
|
|
break;
|
|
|
|
case 'prev':
|
|
|
|
this.api.asc_GotoFootnote(false);
|
|
|
|
setTimeout(function() {
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
|
|
|
|
}, 50);
|
|
|
|
break;
|
|
|
|
case 'next':
|
|
|
|
this.api.asc_GotoFootnote(true);
|
|
|
|
setTimeout(function() {
|
|
|
|
Common.NotificationCenter.trigger('edit:complete', me.toolbar);
|
|
|
|
}, 50);
|
|
|
|
break;
|
|
|
|
}
|
2017-12-23 08:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}, DE.Controllers.Links || {}));
|
|
|
|
});
|