2017-04-22 12:40:46 +00:00
|
|
|
/*
|
|
|
|
*
|
2019-01-17 13:05:03 +00:00
|
|
|
* (c) Copyright Ascensio System SIA 2010-2019
|
2017-04-22 12:40:46 +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
|
|
|
|
*
|
2019-01-17 13:00:34 +00:00
|
|
|
* You can contact Ascensio System SIA at 20A-12 Ernesta Birznieka-Upisha
|
|
|
|
* street, Riga, Latvia, EU, LV-1050.
|
2017-04-22 12:40:46 +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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Mixtbar.js
|
|
|
|
*
|
|
|
|
* Combined component for toolbar's and header's elements
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Created by Maxim.Kadushkin on 4/11/2017.
|
2018-03-01 12:16:38 +00:00
|
|
|
* Copyright (c) 2018 Ascensio System SIA. All rights reserved.
|
2017-04-22 12:40:46 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
define([
|
2019-02-05 09:25:57 +00:00
|
|
|
'backbone',
|
|
|
|
'common/main/lib/component/BaseView'
|
2017-04-22 12:40:46 +00:00
|
|
|
], function (Backbone) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
Common.UI.Mixtbar = Common.UI.BaseView.extend((function () {
|
|
|
|
var $boxTabs;
|
|
|
|
var $scrollL;
|
|
|
|
var optsFold = {timeout: 2000};
|
|
|
|
var config = {};
|
|
|
|
|
|
|
|
var onScrollTabs = function(opts, e) {
|
|
|
|
var sv = $boxTabs.scrollLeft();
|
|
|
|
if ( sv || opts == 'right' ) {
|
|
|
|
$boxTabs.animate({scrollLeft: opts == 'left' ? sv - 100 : sv + 100}, 200);
|
|
|
|
}
|
2017-11-22 08:41:47 +00:00
|
|
|
};
|
2017-04-22 12:40:46 +00:00
|
|
|
|
|
|
|
function onTabDblclick(e) {
|
|
|
|
this.fireEvent('change:compact', [$(e.target).data('tab')]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onShowFullviewPanel(state) {
|
|
|
|
if ( state )
|
|
|
|
optsFold.$bar.addClass('cover'); else
|
|
|
|
optsFold.$bar.removeClass('cover');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClickDocument(e) {
|
|
|
|
if ( this.isFolded ) {
|
2018-05-07 14:17:41 +00:00
|
|
|
if ( $(e.target).parents('.toolbar, #file-menu-panel').length ){
|
2017-04-22 12:40:46 +00:00
|
|
|
} else {
|
2017-07-10 15:32:33 +00:00
|
|
|
this.collapse();
|
2017-04-22 12:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
$tabs: undefined,
|
|
|
|
$panels: undefined,
|
|
|
|
isFolded: false,
|
|
|
|
|
|
|
|
initialize : function(options) {
|
|
|
|
Common.UI.BaseView.prototype.initialize.call(this, options);
|
|
|
|
|
2018-05-16 14:41:47 +00:00
|
|
|
var _template_tabs =
|
|
|
|
'<section class="tabs">' +
|
2018-11-16 14:37:25 +00:00
|
|
|
'<a class="scroll left"></a>' +
|
2018-05-16 14:41:47 +00:00
|
|
|
'<ul>' +
|
|
|
|
'<% for(var i in items) { %>' +
|
|
|
|
'<li class="ribtab' +
|
|
|
|
'<% if (items[i].haspanel===false) print(" x-lone") %>' +
|
|
|
|
'<% if (items[i].extcls) print(\' \' + items[i].extcls) %>">' +
|
|
|
|
'<a data-tab="<%= items[i].action %>" data-title="<%= items[i].caption %>"><%= items[i].caption %></a>' +
|
|
|
|
'</li>' +
|
|
|
|
'<% } %>' +
|
|
|
|
'</ul>' +
|
2018-11-16 14:37:25 +00:00
|
|
|
'<a class="scroll right"></a>' +
|
2018-05-16 14:41:47 +00:00
|
|
|
'</section>';
|
|
|
|
|
2017-04-22 12:40:46 +00:00
|
|
|
this.$layout = $(options.template({
|
2018-05-16 14:41:47 +00:00
|
|
|
tabsmarkup: _.template(_template_tabs)({items: options.tabs})
|
2017-04-22 12:40:46 +00:00
|
|
|
}));
|
|
|
|
|
|
|
|
config.tabs = options.tabs;
|
|
|
|
$(document.body).on('click', onClickDocument.bind(this));
|
2017-10-12 14:25:47 +00:00
|
|
|
|
|
|
|
Common.NotificationCenter.on('tab:visible', _.bind(function(action, visible){
|
2018-05-15 12:37:26 +00:00
|
|
|
this.setVisible(action, visible);
|
2017-10-12 14:25:47 +00:00
|
|
|
}, this));
|
2017-04-22 12:40:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
afterRender: function() {
|
|
|
|
var me = this;
|
|
|
|
|
|
|
|
$boxTabs = me.$('.tabs > ul');
|
|
|
|
me.$tabs = $boxTabs.find('> li');
|
|
|
|
me.$panels = me.$('.box-panels > .panel');
|
2017-05-01 11:30:44 +00:00
|
|
|
optsFold.$bar = me.$('.toolbar');
|
2017-04-22 12:40:46 +00:00
|
|
|
var $scrollR = me.$('.tabs .scroll.right');
|
|
|
|
$scrollL = me.$('.tabs .scroll.left');
|
|
|
|
|
|
|
|
$scrollL.on('click', onScrollTabs.bind(this, 'left'));
|
|
|
|
$scrollR.on('click', onScrollTabs.bind(this, 'right'));
|
|
|
|
|
2017-06-16 09:24:00 +00:00
|
|
|
$boxTabs.on('dblclick', '> .ribtab', onTabDblclick.bind(this));
|
2017-08-30 12:23:22 +00:00
|
|
|
$boxTabs.on('click', '> .ribtab', me.onTabClick.bind(this));
|
2017-04-22 12:40:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isTabActive: function(tag) {
|
|
|
|
var t = this.$tabs.filter('.active').find('> a');
|
|
|
|
return t.length && t.data('tab') == tag;
|
|
|
|
},
|
|
|
|
|
2018-05-17 10:44:46 +00:00
|
|
|
setFolded: function(value) {
|
2017-04-22 12:40:46 +00:00
|
|
|
this.isFolded = value;
|
|
|
|
|
|
|
|
var me = this;
|
|
|
|
if ( this.isFolded ) {
|
|
|
|
if (!optsFold.$box) optsFold.$box = me.$el.find('.box-controls');
|
|
|
|
|
2018-05-03 16:02:09 +00:00
|
|
|
optsFold.$bar.addClass('folded z-clear').toggleClass('expanded', false);
|
2017-08-01 11:39:31 +00:00
|
|
|
optsFold.$bar.find('.tabs .ribtab').removeClass('active');
|
2018-05-03 16:02:09 +00:00
|
|
|
optsFold.$bar.on($.support.transition.end, function (e) {
|
|
|
|
if ( optsFold.$bar.hasClass('folded') && !optsFold.$bar.hasClass('expanded') )
|
|
|
|
optsFold.$bar.toggleClass('z-clear', true);
|
|
|
|
});
|
2017-04-22 12:40:46 +00:00
|
|
|
optsFold.$box.on({
|
|
|
|
mouseleave: function (e) {
|
2017-08-01 10:17:29 +00:00
|
|
|
// optsFold.timer = setTimeout( function(e) {
|
|
|
|
// clearTimeout(optsFold.timer);
|
|
|
|
// me.collapse();
|
|
|
|
// }, optsFold.timeout);
|
2017-04-22 12:40:46 +00:00
|
|
|
},
|
|
|
|
mouseenter: function (e) {
|
2017-08-01 10:17:29 +00:00
|
|
|
// clearTimeout(optsFold.timer);
|
2017-04-22 12:40:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// $(document.body).on('focus', 'input, textarea', function(e) {
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// $(document.body).on('blur', 'input, textarea', function(e) {
|
|
|
|
// });
|
|
|
|
//
|
|
|
|
// Common.NotificationCenter.on({
|
|
|
|
// 'modal:show': function(){
|
|
|
|
// },
|
|
|
|
// 'modal:close': function(dlg) {
|
|
|
|
// },
|
|
|
|
// 'modal:hide': function(dlg) {
|
|
|
|
// },
|
|
|
|
// 'dataview:focus': function(e){
|
|
|
|
// },
|
|
|
|
// 'dataview:blur': function(e){
|
|
|
|
// },
|
|
|
|
// 'menu:show': function(e){
|
|
|
|
// },
|
|
|
|
// 'menu:hide': function(e){
|
|
|
|
// },
|
|
|
|
// 'edit:complete': _.bind(me.onEditComplete, me)
|
|
|
|
// });
|
|
|
|
|
|
|
|
} else {
|
2017-08-01 10:17:29 +00:00
|
|
|
// clearTimeout(optsFold.timer);
|
2018-05-03 16:02:09 +00:00
|
|
|
optsFold.$bar.removeClass('folded z-clear');
|
2017-04-22 12:40:46 +00:00
|
|
|
optsFold.$box.off();
|
2017-08-30 12:23:22 +00:00
|
|
|
|
|
|
|
var active_panel = optsFold.$box.find('.panel.active');
|
|
|
|
if ( active_panel.length ) {
|
|
|
|
var tab = active_panel.data('tab');
|
|
|
|
me.$tabs.find('> a[data-tab=' + tab + ']').parent().toggleClass('active', true);
|
2018-05-16 14:41:47 +00:00
|
|
|
} else {
|
2018-05-17 10:44:46 +00:00
|
|
|
tab = me.$tabs.siblings(':not(.x-lone)').first().find('> a[data-tab]').data('tab');
|
|
|
|
me.setTab(tab);
|
2017-08-30 12:23:22 +00:00
|
|
|
}
|
2017-04-22 12:40:46 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-07-10 15:32:33 +00:00
|
|
|
collapse: function() {
|
2017-08-01 10:17:29 +00:00
|
|
|
Common.UI.Menu.Manager.hideAll();
|
|
|
|
// clearTimeout(optsFold.timer);
|
|
|
|
|
2017-06-28 08:43:50 +00:00
|
|
|
if ( this.isFolded && optsFold.$bar ) {
|
2017-06-16 09:25:36 +00:00
|
|
|
optsFold.$bar.removeClass('expanded');
|
|
|
|
optsFold.$bar.find('.tabs .ribtab').removeClass('active');
|
|
|
|
}
|
2017-04-22 12:40:46 +00:00
|
|
|
},
|
|
|
|
|
2017-07-10 15:32:33 +00:00
|
|
|
expand: function() {
|
2017-08-01 10:17:29 +00:00
|
|
|
// clearTimeout(optsFold.timer);
|
2017-04-22 12:40:46 +00:00
|
|
|
|
2018-05-03 16:02:09 +00:00
|
|
|
optsFold.$bar.removeClass('z-clear');
|
2017-04-22 12:40:46 +00:00
|
|
|
optsFold.$bar.addClass('expanded');
|
2017-08-01 10:17:29 +00:00
|
|
|
// optsFold.timer = setTimeout(this.collapse, optsFold.timeout);
|
2017-04-22 12:40:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
onResize: function(e) {
|
|
|
|
if ( this.hasTabInvisible() ) {
|
|
|
|
if ( !$boxTabs.parent().hasClass('short') )
|
|
|
|
$boxTabs.parent().addClass('short');
|
|
|
|
} else
|
|
|
|
if ( $boxTabs.parent().hasClass('short') ) {
|
|
|
|
$boxTabs.parent().removeClass('short');
|
|
|
|
}
|
2018-12-12 11:56:08 +00:00
|
|
|
|
|
|
|
this.processPanelVisible();
|
2017-04-22 12:40:46 +00:00
|
|
|
},
|
|
|
|
|
2017-08-30 12:23:22 +00:00
|
|
|
onTabClick: function (e) {
|
2018-05-16 14:41:47 +00:00
|
|
|
var me = this;
|
|
|
|
|
|
|
|
var $target = $(e.currentTarget);
|
|
|
|
var tab = $target.find('> a[data-tab]').data('tab');
|
|
|
|
var islone = $target.hasClass('x-lone');
|
|
|
|
if ( me.isFolded ) {
|
|
|
|
if ( $target.hasClass('x-lone') ) {
|
|
|
|
me.collapse();
|
|
|
|
// me.fireEvent('')
|
|
|
|
} else
|
|
|
|
if ( $target.hasClass('active') ) {
|
|
|
|
me.collapse();
|
|
|
|
} else {
|
|
|
|
me.setTab(tab);
|
2018-12-17 13:50:51 +00:00
|
|
|
me.processPanelVisible(null, true);
|
2017-08-30 12:23:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-05-16 14:41:47 +00:00
|
|
|
if ( !$target.hasClass('active') && !islone ) {
|
|
|
|
me.setTab(tab);
|
2018-12-17 13:50:51 +00:00
|
|
|
me.processPanelVisible(null, true);
|
2018-05-16 14:41:47 +00:00
|
|
|
}
|
2017-08-30 12:23:22 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-04-22 12:40:46 +00:00
|
|
|
setTab: function (tab) {
|
2018-05-16 14:41:47 +00:00
|
|
|
var me = this;
|
2017-04-27 15:40:27 +00:00
|
|
|
if ( !tab ) {
|
2018-05-16 14:41:47 +00:00
|
|
|
// onShowFullviewPanel.call(this, false);
|
2017-05-01 11:30:44 +00:00
|
|
|
|
2017-07-10 15:34:10 +00:00
|
|
|
if ( this.isFolded ) { this.collapse(); }
|
2017-04-22 12:40:46 +00:00
|
|
|
else tab = this.lastPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( tab ) {
|
2018-05-16 14:41:47 +00:00
|
|
|
me.$tabs.removeClass('active');
|
|
|
|
me.$panels.removeClass('active');
|
2017-04-22 12:40:46 +00:00
|
|
|
|
|
|
|
var panel = this.$panels.filter('[data-tab=' + tab + ']');
|
|
|
|
if ( panel.length ) {
|
|
|
|
this.lastPanel = tab;
|
|
|
|
panel.addClass('active');
|
|
|
|
}
|
|
|
|
|
2017-05-01 11:30:44 +00:00
|
|
|
if ( panel.length ) {
|
2018-05-16 14:41:47 +00:00
|
|
|
if ( me.isFolded ) me.expand();
|
2017-05-01 11:30:44 +00:00
|
|
|
} else {
|
2018-05-16 14:41:47 +00:00
|
|
|
// onShowFullviewPanel.call(this, true);
|
|
|
|
if ( me.isFolded ) me.collapse();
|
2017-07-10 15:32:33 +00:00
|
|
|
}
|
2017-07-10 15:34:10 +00:00
|
|
|
|
|
|
|
var $tp = this.$tabs.find('> a[data-tab=' + tab + ']').parent();
|
|
|
|
if ( $tp.length ) {
|
|
|
|
$tp.addClass('active');
|
2017-04-22 12:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
addTab: function (tab, panel, after) {
|
|
|
|
function _get_tab_action(index) {
|
|
|
|
if (!config.tabs[index])
|
|
|
|
return _get_tab_action(--index);
|
|
|
|
|
|
|
|
return config.tabs[index].action;
|
|
|
|
}
|
|
|
|
|
2019-02-21 12:41:43 +00:00
|
|
|
var _tabTemplate = _.template('<li class="ribtab" style="display: none;"><a data-tab="<%= action %>" data-title="<%= caption %>"><%= caption %></a></li>');
|
2017-04-22 12:40:46 +00:00
|
|
|
|
|
|
|
config.tabs[after + 1] = tab;
|
|
|
|
var _after_action = _get_tab_action(after);
|
|
|
|
|
|
|
|
var _elements = this.$tabs || this.$layout.find('.tabs');
|
|
|
|
var $target = _elements.find('a[data-tab=' + _after_action + ']');
|
|
|
|
if ( $target.length ) {
|
|
|
|
$target.parent().after( _tabTemplate(tab) );
|
|
|
|
|
|
|
|
if (panel) {
|
|
|
|
_elements = this.$panels || this.$layout.find('.box-panels > .panel');
|
|
|
|
$target = _elements.filter('[data-tab=' + _after_action + ']');
|
|
|
|
|
|
|
|
if ($target.length) {
|
|
|
|
$target.after(panel);
|
2018-05-15 12:37:26 +00:00
|
|
|
} else {
|
|
|
|
panel.appendTo(this.$layout.find('.box-panels'));
|
2017-04-22 12:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// synchronize matched elements
|
|
|
|
this.$tabs && (this.$tabs = $boxTabs.find('> li'));
|
|
|
|
this.$panels && (this.$panels = this.$el.find('.box-panels > .panel'));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
isCompact: function () {
|
|
|
|
return this.isFolded;
|
|
|
|
},
|
|
|
|
|
|
|
|
hasTabInvisible: function() {
|
2017-08-03 14:43:43 +00:00
|
|
|
if ($boxTabs.length<1) return false;
|
|
|
|
|
2017-04-27 08:58:37 +00:00
|
|
|
var _left_bound_ = Math.round($boxTabs.offset().left),
|
|
|
|
_right_bound_ = Math.round(_left_bound_ + $boxTabs.width());
|
2017-04-22 12:40:46 +00:00
|
|
|
|
2017-10-18 14:03:49 +00:00
|
|
|
var tab = this.$tabs.filter(':visible:first').get(0);
|
2017-07-21 14:56:05 +00:00
|
|
|
if ( !tab ) return false;
|
|
|
|
|
2017-04-22 12:40:46 +00:00
|
|
|
var rect = tab.getBoundingClientRect();
|
|
|
|
|
2017-04-27 08:58:37 +00:00
|
|
|
if ( !(Math.round(rect.left) < _left_bound_) ) {
|
2017-10-18 14:03:49 +00:00
|
|
|
tab = this.$tabs.filter(':visible:last').get(0);
|
2017-04-22 12:40:46 +00:00
|
|
|
rect = tab.getBoundingClientRect();
|
|
|
|
|
2017-04-27 08:58:37 +00:00
|
|
|
if (!(Math.round(rect.right) > _right_bound_))
|
2017-04-22 12:40:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2018-12-12 11:56:08 +00:00
|
|
|
/**
|
|
|
|
* in case panel partly visible.
|
|
|
|
* hide button's caption to decrease panel width
|
|
|
|
* ##adopt-panel-width
|
|
|
|
**/
|
2018-12-17 13:50:51 +00:00
|
|
|
processPanelVisible: function(panel, now) {
|
2018-12-12 11:56:08 +00:00
|
|
|
var me = this;
|
|
|
|
if ( me._timer_id ) clearTimeout(me._timer_id);
|
|
|
|
|
|
|
|
function _fc() {
|
2019-01-18 13:43:56 +00:00
|
|
|
var $active = panel || me.$panels.filter('.active');
|
2018-12-17 13:50:51 +00:00
|
|
|
if ( $active && $active.length ) {
|
2018-12-12 11:56:08 +00:00
|
|
|
var _maxright = $active.parents('.box-controls').width();
|
|
|
|
var data = $active.data(),
|
|
|
|
_rightedge = data.rightedge;
|
|
|
|
|
|
|
|
if ( !_rightedge ) {
|
|
|
|
_rightedge = $active.get(0).getBoundingClientRect().right;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( _rightedge > _maxright ) {
|
|
|
|
if ( !$active.hasClass('compactwidth') ) {
|
|
|
|
$active.addClass('compactwidth');
|
|
|
|
data.rightedge = _rightedge;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ($active.hasClass('compactwidth')) {
|
|
|
|
$active.removeClass('compactwidth');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-12-17 13:50:51 +00:00
|
|
|
if ( now === true ) _fc(); else
|
2018-12-12 11:56:08 +00:00
|
|
|
me._timer_id = setTimeout(function() {
|
|
|
|
delete me._timer_id;
|
|
|
|
_fc();
|
|
|
|
}, 100);
|
|
|
|
},
|
|
|
|
/**/
|
|
|
|
|
2017-04-22 12:40:46 +00:00
|
|
|
setExtra: function (place, el) {
|
2017-05-04 12:36:42 +00:00
|
|
|
if ( !!el ) {
|
|
|
|
if (this.$tabs) {
|
|
|
|
} else {
|
|
|
|
if (place == 'right') {
|
|
|
|
this.$layout.find('.extra.right').html(el);
|
|
|
|
} else if (place == 'left') {
|
|
|
|
this.$layout.find('.extra.left').html(el);
|
|
|
|
}
|
2017-04-22 12:40:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-12 14:25:47 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
setVisible: function (tab, visible) {
|
|
|
|
if ( tab && this.$tabs )
|
|
|
|
this.$tabs.find('> a[data-tab=' + tab + ']').parent().css('display', visible ? '' : 'none');
|
2017-04-22 12:40:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}()));
|
|
|
|
});
|