web-apps/apps/documenteditor/main/app/view/BookmarksDialog.js

418 lines
18 KiB
JavaScript
Raw Normal View History

2018-02-19 11:56:44 +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 20A-12 Ernesta Birznieka-Upisha
* street, Riga, Latvia, EU, LV-1050.
2018-02-19 11:56:44 +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
*
*/
/**
* BookmarksDialog.js.js
*
* Created by Julia Radzhabova on 15.02.2018
* Copyright (c) 2017 Ascensio System SIA. All rights reserved.
*
*/
define([
'common/main/lib/util/utils',
'common/main/lib/component/ListView',
'common/main/lib/component/InputField',
'common/main/lib/component/Button',
'common/main/lib/component/RadioBox',
'common/main/lib/view/AdvancedSettingsWindow'
], function () { 'use strict';
DE.Views.BookmarksDialog = Common.Views.AdvancedSettingsWindow.extend(_.extend({
options: {
contentWidth: 310,
2020-04-09 13:29:04 +00:00
height: 366,
2019-09-11 08:38:08 +00:00
buttons: null
2018-02-19 11:56:44 +00:00
},
initialize : function(options) {
var me = this;
_.extend(this.options, {
title: this.textTitle,
template: [
'<div class="box" style="height:' + (me.options.height - 85) + 'px;">',
'<div class="content-panel" style="padding: 0 5px;"><div class="inner-content">',
'<div class="settings-panel active">',
'<table cols="1" style="width: 100%;">',
'<tr>',
'<td class="padding-extra-small">',
'<label class="input-label">', me.textBookmarkName, '</label>',
'</td>',
'</tr>',
'<tr>',
'<td class="padding-large">',
'<div id="bookmarks-txt-name" style="display:inline-block;vertical-align: top;margin-right: 10px;"></div>',
'<button type="button" result="add" class="btn btn-text-default" id="bookmarks-btn-add" style="vertical-align: top;">', me.textAdd,'</button>',
'</td>',
'</tr>',
'<tr>',
'<td class="padding-extra-small">',
'<label class="header" style="margin-right: 10px;">', me.textSort,'</label>',
'<div id="bookmarks-radio-name" style="display: inline-block; margin-right: 10px;"></div>',
'<div id="bookmarks-radio-location" style="display: inline-block;"></div>',
'</td>',
'</tr>',
'<tr>',
'<td class="padding-small">',
2020-04-09 13:29:04 +00:00
'<div id="bookmarks-list" style="width:290px; height: 139px;"></div>',
2018-02-19 11:56:44 +00:00
'</td>',
'</tr>',
'<tr>',
2018-03-28 12:50:41 +00:00
'<td class="padding-large">',
'<button type="button" class="btn btn-text-default" id="bookmarks-btn-goto" style="margin-right: 5px;">', me.textGoto,'</button>',
2019-03-27 14:44:13 +00:00
'<div style="display: inline-block; position: relative;">',
2021-04-14 22:24:55 +00:00
'<button type="button" class="btn btn-text-default auto dropdown-toggle move-focus" id="bookmarks-btn-link" style="min-width: 75px;" data-toggle="dropdown">', me.textGetLink,'</button>',
2019-03-27 14:44:13 +00:00
'<div id="id-clip-copy-box" class="dropdown-menu" style="width: 291px; left: -80px; padding: 10px;">',
'<div id="id-dlg-clip-copy"></div>',
'<button id="id-dlg-copy-btn" class="btn btn-text-default" style="margin-left: 5px; width: 86px;">' + me.textCopy + '</button>',
'</div>',
'</div>',
2019-03-27 14:44:13 +00:00
'<button type="button" class="btn btn-text-default" id="bookmarks-btn-delete" style="float: right;">', me.textDelete,'</button>',
2018-02-19 11:56:44 +00:00
'</td>',
'</tr>',
2018-03-28 12:50:41 +00:00
'<tr>',
'<td>',
'<div id="bookmarks-checkbox-hidden"></div>',
'</td>',
'</tr>',
2018-02-19 11:56:44 +00:00
'</table>',
'</div></div>',
'</div>',
'</div>',
2019-11-06 11:16:09 +00:00
'<div class="footer center">',
2018-02-19 11:56:44 +00:00
'<button class="btn normal dlg-btn" result="cancel" style="width: 86px;">' + me.textClose + '</button>',
'</div>'
].join('')
}, options);
this.api = options.api;
this.handler = options.handler;
this.props = options.props;
2019-03-18 13:03:26 +00:00
this.appOptions = options.appOptions;
2018-02-19 11:56:44 +00:00
Common.Views.AdvancedSettingsWindow.prototype.initialize.call(this, this.options);
},
render: function() {
Common.Views.AdvancedSettingsWindow.prototype.render.call(this);
var me = this;
this.txtName = new Common.UI.InputField({
el : $('#bookmarks-txt-name'),
allowBlank : true,
validateOnChange: true,
2018-08-15 11:54:08 +00:00
validateOnBlur: true,
style : 'width: 205px;',
2018-03-28 12:50:41 +00:00
value : '',
2018-08-15 11:54:08 +00:00
maxLength: 40,
validation : function(value) {
2019-09-18 08:58:40 +00:00
var check = me.props.asc_CheckNewBookmarkName(value),
exist = me.props.asc_HaveBookmark(value);
me.btnAdd.setDisabled(!check && !exist);
return (check || _.isEmpty(value) || exist) ? true : me.txtInvalidName;
2018-08-15 11:54:08 +00:00
}
2019-04-04 09:00:09 +00:00
}).on ('changing', function (input, value) {
var exist = me.props.asc_HaveBookmark(value);
if (exist) {
var rec = me.bookmarksList.store.findWhere({value: value});
me.bookmarksList.selectRecord(rec);
me.bookmarksList.scrollToRecord(rec);
} else
me.bookmarksList.deselectAll();
me.btnGoto.setDisabled(!exist);
me.btnDelete.setDisabled(!exist);
me.btnGetLink.setDisabled(!exist);
2018-08-15 11:54:08 +00:00
});
2018-02-19 11:56:44 +00:00
this.radioName = new Common.UI.RadioBox({
el: $('#bookmarks-radio-name'),
labelText: this.textName,
2018-06-19 10:01:25 +00:00
name: 'asc-radio-bookmark-sort'
2018-02-19 11:56:44 +00:00
});
2018-03-27 12:21:15 +00:00
this.radioName.on('change', _.bind(this.onRadioSort, this));
2018-02-19 11:56:44 +00:00
this.radioLocation = new Common.UI.RadioBox({
el: $('#bookmarks-radio-location'),
labelText: this.textLocation,
name: 'asc-radio-bookmark-sort'
});
2018-03-27 12:21:15 +00:00
this.radioLocation.on('change', _.bind(this.onRadioSort, this));
2018-06-19 10:01:25 +00:00
Common.Utils.InternalSettings.get("de-bookmarks-sort-location") ? this.radioLocation.setValue(true, true) : this.radioName.setValue(true, true);
2018-02-19 11:56:44 +00:00
this.bookmarksList = new Common.UI.ListView({
el: $('#bookmarks-list', this.$window),
2018-03-28 12:50:41 +00:00
store: new Common.UI.DataViewStore(),
tabindex: 1,
2021-04-26 11:54:55 +00:00
itemTemplate: _.template('<div id="<%= id %>" class="list-item" style="pointer-events:none;overflow: hidden; text-overflow: ellipsis;"><%= Common.Utils.String.htmlEncode(value) %></div>')
2018-02-19 11:56:44 +00:00
});
this.bookmarksList.store.comparator = function(rec) {
2018-03-27 12:21:15 +00:00
return (me.radioName.getValue() ? rec.get("value") : rec.get("location"));
2018-02-19 11:56:44 +00:00
};
2018-03-28 12:50:41 +00:00
this.bookmarksList.on('item:dblclick', _.bind(this.onDblClickBookmark, this));
this.bookmarksList.on('entervalue', _.bind(this.onPrimary, this));
this.bookmarksList.on('item:select', _.bind(this.onSelectBookmark, this));
2018-02-19 11:56:44 +00:00
this.btnAdd = new Common.UI.Button({
2018-03-28 14:44:38 +00:00
el: $('#bookmarks-btn-add'),
disabled: true
2018-02-19 11:56:44 +00:00
});
2019-03-27 14:44:13 +00:00
this.btnAdd.on('click', _.bind(this.addBookmark, this));
2018-02-19 11:56:44 +00:00
this.btnGoto = new Common.UI.Button({
2018-03-28 14:44:38 +00:00
el: $('#bookmarks-btn-goto'),
disabled: true
2018-02-19 11:56:44 +00:00
});
2018-03-27 12:21:15 +00:00
this.btnGoto.on('click', _.bind(this.gotoBookmark, this));
2018-02-19 11:56:44 +00:00
this.btnDelete = new Common.UI.Button({
2018-03-28 14:44:38 +00:00
el: $('#bookmarks-btn-delete'),
disabled: true
2018-02-19 11:56:44 +00:00
});
2018-03-27 12:21:15 +00:00
this.btnDelete.on('click', _.bind(this.deleteBookmark, this));
2018-02-19 11:56:44 +00:00
2019-03-18 13:03:26 +00:00
this.btnGetLink = new Common.UI.Button({
el: $('#bookmarks-btn-link'),
disabled: true
});
this.btnGetLink.on('click', _.bind(this.getBookmarkLink, this));
2018-03-28 12:50:41 +00:00
this.chHidden = new Common.UI.CheckBox({
el: $('#bookmarks-checkbox-hidden'),
labelText: this.textHidden,
value: Common.Utils.InternalSettings.get("de-bookmarks-hidden") || false
2018-03-28 12:50:41 +00:00
});
this.chHidden.on('change', _.bind(this.onChangeHidden, this));
if (this.appOptions.canMakeActionLink) {
var inputCopy = new Common.UI.InputField({
el : $('#id-dlg-clip-copy'),
editable : false,
style : 'width: 176px;'
});
var copyBox = this.$window.find('#id-clip-copy-box');
copyBox.on('click', _.bind(function() {
return false;
}, this));
copyBox.parent().on({
'shown.bs.dropdown': function () {
_.delay(function(){
inputCopy._input.select().focus();
},100);
},
'hide.bs.dropdown': function () {
me.txtName._input.select().focus();
}
});
copyBox.find('button').on('click', function() {
inputCopy._input.select();
document.execCommand("copy");
});
Common.Gateway.on('setactionlink', function (url) {
inputCopy.setValue(url);
});
}
2018-02-19 11:56:44 +00:00
this.afterRender();
},
getFocusedComponents: function() {
2021-04-14 22:24:55 +00:00
return [this.txtName, this.radioName, this.radioLocation, this.bookmarksList, this.btnAdd, this.btnGoto, this.btnGetLink, this.btnDelete, this.chHidden];
},
2018-02-19 11:56:44 +00:00
afterRender: function() {
this._setDefaults(this.props);
2019-09-20 13:56:06 +00:00
var me = this;
var onApiBookmarksUpdate = function() {
var rec = me.bookmarksList.getSelectedRec();
me.refreshBookmarks();
if (rec) {
rec = me.bookmarksList.store.findWhere({value: rec.get('value')});
if (rec) {
me.bookmarksList.selectRecord(rec);
me.bookmarksList.scrollToRecord(rec);
} else {
me.txtName.setValue('');
me.btnAdd.setDisabled(true);
me.btnGoto.setDisabled(true);
me.btnDelete.setDisabled(true);
me.btnGetLink.setDisabled(true);
}
}
};
this.api.asc_registerCallback('asc_onBookmarksUpdate', onApiBookmarksUpdate);
this.on('close', function(obj){
me.api.asc_unregisterCallback('asc_onBookmarksUpdate', onApiBookmarksUpdate);
});
2018-02-19 11:56:44 +00:00
},
show: function() {
Common.Views.AdvancedSettingsWindow.prototype.show.apply(this, arguments);
2018-07-23 14:40:40 +00:00
var me = this;
_.delay(function(){
$('input', me.txtName.cmpEl).select().focus();
2018-07-25 07:56:42 +00:00
},100);
2018-02-19 11:56:44 +00:00
},
close: function() {
Common.Views.AdvancedSettingsWindow.prototype.close.apply(this, arguments);
Common.Utils.InternalSettings.set("de-bookmarks-hidden", this.chHidden.getValue()=='checked');
2018-06-19 10:01:25 +00:00
Common.Utils.InternalSettings.set("de-bookmarks-sort-location", this.radioLocation.getValue())
},
2018-02-19 11:56:44 +00:00
_setDefaults: function (props) {
2018-03-28 12:50:41 +00:00
this.refreshBookmarks();
2019-03-18 13:03:26 +00:00
this.btnGetLink.setVisible(this.appOptions.canMakeActionLink);
2018-02-19 11:56:44 +00:00
},
getSettings: function () {
return {};
},
onDlgBtnClick: function(event) {
this.close();
},
onPrimary: function() {
return true;
},
2018-03-28 12:50:41 +00:00
refreshBookmarks: function() {
if (this.props) {
var store = this.bookmarksList.store,
count = this.props.asc_GetCount(),
2018-03-28 14:44:38 +00:00
showHidden = this.chHidden.getValue()=='checked',
2018-03-28 12:50:41 +00:00
arr = [];
for (var i=0; i<count; i++) {
2018-03-28 14:44:38 +00:00
var name = this.props.asc_GetName(i);
if (!this.props.asc_IsInternalUseBookmark(name) && (showHidden || !this.props.asc_IsHiddenBookmark(name))) {
2018-03-28 12:50:41 +00:00
var rec = new Common.UI.DataViewModel();
rec.set({
2018-03-28 14:44:38 +00:00
value: name,
2018-03-28 12:50:41 +00:00
location: i
});
arr.push(rec);
}
2018-03-28 14:44:38 +00:00
}
2018-03-28 12:50:41 +00:00
store.reset(arr, {silent: false});
}
},
onSelectBookmark: function(listView, itemView, record) {
2020-11-16 16:00:40 +00:00
if (!record) return;
2018-03-28 12:50:41 +00:00
var value = record.get('value');
this.txtName.setValue(value);
2018-03-28 14:44:38 +00:00
this.btnAdd.setDisabled(false);
2018-03-28 12:50:41 +00:00
this.btnGoto.setDisabled(false);
this.btnDelete.setDisabled(false);
2019-03-18 13:03:26 +00:00
this.btnGetLink.setDisabled(false);
2018-03-28 12:50:41 +00:00
},
2018-03-27 12:21:15 +00:00
gotoBookmark: function(btn, eOpts){
var rec = this.bookmarksList.getSelectedRec();
2019-09-18 08:58:40 +00:00
if (rec)
this.props.asc_SelectBookmark(rec.get('value'));
else if (this.txtName.getValue()!=='')
this.props.asc_SelectBookmark(this.txtName.getValue());
2018-03-27 12:21:15 +00:00
},
2019-03-27 14:44:13 +00:00
addBookmark: function(btn, eOpts){
this.props.asc_AddBookmark(this.txtName.getValue());
this.refreshBookmarks();
var rec = this.bookmarksList.store.findWhere({value: this.txtName.getValue()});
this.bookmarksList.selectRecord(rec);
this.bookmarksList.scrollToRecord(rec);
this.txtName.focus();
2019-03-27 14:44:13 +00:00
},
2018-03-28 12:50:41 +00:00
onDblClickBookmark: function(listView, itemView, record) {
2018-11-27 10:12:56 +00:00
this.props.asc_SelectBookmark(record.get('value'));
2018-03-28 12:50:41 +00:00
},
2018-03-27 12:21:15 +00:00
deleteBookmark: function(btn, eOpts){
var rec = this.bookmarksList.getSelectedRec();
2019-06-27 11:18:01 +00:00
if (rec) {
this.props.asc_RemoveBookmark(rec.get('value'));
2018-03-27 12:21:15 +00:00
var store = this.bookmarksList.store;
2019-06-27 11:18:01 +00:00
var idx = _.indexOf(store.models, rec);
store.remove(rec);
2018-06-19 10:02:30 +00:00
this.txtName.setValue('');
this.btnAdd.setDisabled(true);
this.btnGoto.setDisabled(true);
this.btnDelete.setDisabled(true);
2019-03-18 13:03:26 +00:00
this.btnGetLink.setDisabled(true);
}
},
getBookmarkLink: function(btn) {
if (btn.cmpEl && btn.cmpEl.parent().hasClass('open')) return;
2019-03-18 13:03:26 +00:00
var rec = this.bookmarksList.getSelectedRec();
2019-06-27 11:18:01 +00:00
rec && Common.Gateway.requestMakeActionLink({
action: {
type: "bookmark", data: rec.get('value')
}
});
2018-03-27 12:21:15 +00:00
},
onRadioSort: function(field, newValue, eOpts) {
if (newValue) {
this.bookmarksList.store.sort();
this.bookmarksList.onResetItems();
}
},
2018-03-28 12:50:41 +00:00
onChangeHidden: function(field, newValue, oldValue, eOpts){
this.refreshBookmarks();
},
2018-02-19 11:56:44 +00:00
textTitle: 'Bookmarks',
textLocation: 'Location',
textBookmarkName: 'Bookmark name',
textSort: 'Sort by',
textName: 'Name',
textAdd: 'Add',
textGoto: 'Go to',
textDelete: 'Delete',
2018-03-28 12:50:41 +00:00
textClose: 'Close',
2018-08-15 11:54:08 +00:00
textHidden: 'Hidden bookmarks',
2019-03-18 13:03:26 +00:00
txtInvalidName: 'Bookmark name can only contain letters, digits and underscores, and should begin with the letter',
2019-03-27 14:44:13 +00:00
textGetLink: 'Get Link',
textCopy: 'Copy'
2018-02-19 11:56:44 +00:00
}, DE.Views.BookmarksDialog || {}))
});