mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
N°2847 - Rework iTopWebPage layout (WIP Part IV)
- iTopWebPage: Clean up some commented sections - iTopWebPage: Marked some new methods as @internal - iTopWebPage: Restore page content to allow // developments - Quick create: Add quick object creation box to the top bar - Global search: Improve cinematic with other widgets - Components / Layouts: Move JS parts to iTopWebPage, will be put in dedicated PHP helpers later
This commit is contained in:
@@ -55,6 +55,7 @@ $(function()
|
||||
_bindEvents: function()
|
||||
{
|
||||
const me = this;
|
||||
const oBodyElem = $('body');
|
||||
|
||||
this.element.find(this.js_selectors.icon).on('click', function(oEvent){
|
||||
me._onIconClick(oEvent);
|
||||
@@ -65,19 +66,30 @@ $(function()
|
||||
this.element.find(this.js_selectors.compartment_element).on('click', function(oEvent){
|
||||
me._onCompartmentElementClick(oEvent, $(this));
|
||||
});
|
||||
$('body').on('click', function(oEvent){
|
||||
// Mostly for outside clicks that should close elements
|
||||
oBodyElem.on('click', function(oEvent){
|
||||
me._onBodyClick(oEvent);
|
||||
});
|
||||
// Mostly for hotkeys
|
||||
oBodyElem.on('keyup', function(oEvent){
|
||||
me._onBodyKeyUp(oEvent);
|
||||
});
|
||||
},
|
||||
_onIconClick: function(oEvent)
|
||||
{
|
||||
// Avoid anchor glitch
|
||||
oEvent.preventDefault();
|
||||
|
||||
// Open drawer
|
||||
this.element.toggleClass(this.css_classes.opened);
|
||||
// Focus in the input for a better UX
|
||||
this.element.find(this.js_selectors.input).trigger('focus');
|
||||
if(this._isDrawerOpened())
|
||||
{
|
||||
this._closeDrawer();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._openDrawer();
|
||||
// Focus in the input for a better UX
|
||||
this._setFocusOnInput();
|
||||
}
|
||||
},
|
||||
_onFormSubmit: function(oEvent)
|
||||
{
|
||||
@@ -103,8 +115,43 @@ $(function()
|
||||
{
|
||||
if($(oEvent.target.closest('.ibo-global-search')).length === 0)
|
||||
{
|
||||
this.element.removeClass(this.css_classes.opened);
|
||||
this._closeDrawer();
|
||||
}
|
||||
},
|
||||
_onBodyKeyUp: function(oEvent)
|
||||
{
|
||||
// Note: We thought about extracting the oEvent.key in a variable to lower case it, but this would be done
|
||||
// on every single key up in the application, which might not be what we want... (time consuming)
|
||||
if((oEvent.altKey === true) && (oEvent.key === 'h' || oEvent.key === 'H'))
|
||||
{
|
||||
if(this._isDrawerOpened())
|
||||
{
|
||||
this._setFocusOnInput();
|
||||
}
|
||||
// If drawer is closed, we trigger the click on the icon in order for the other widget to behave like they should (eg. close themselves)
|
||||
else
|
||||
{
|
||||
this.element.find(this.js_selectors.icon).trigger('click');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Methods
|
||||
_isDrawerOpened: function()
|
||||
{
|
||||
return this.element.hasClass(this.css_classes.opened);
|
||||
},
|
||||
_openDrawer: function()
|
||||
{
|
||||
this.element.addClass(this.css_classes.opened);
|
||||
},
|
||||
_closeDrawer: function()
|
||||
{
|
||||
this.element.removeClass(this.css_classes.opened);
|
||||
},
|
||||
_setFocusOnInput: function()
|
||||
{
|
||||
this.element.find(this.js_selectors.input).trigger('focus');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
166
js/components/quick-create.js
Normal file
166
js/components/quick-create.js
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2013-2020 Combodo SARL
|
||||
*
|
||||
* This file is part of iTop.
|
||||
*
|
||||
* iTop is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* iTop is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
*/
|
||||
|
||||
;
|
||||
$(function()
|
||||
{
|
||||
// the widget definition, where 'itop' is the namespace,
|
||||
// 'breadcrumbs' the widget name
|
||||
$.widget( 'itop.quick_create',
|
||||
{
|
||||
// default options
|
||||
options:
|
||||
{
|
||||
|
||||
},
|
||||
css_classes:
|
||||
{
|
||||
opened: 'ibo-quick-create--is-opened',
|
||||
},
|
||||
js_selectors:
|
||||
{
|
||||
icon: '[data-role="ibo-quick-create--icon"]',
|
||||
form: '[data-role="ibo-quick-create--head"]',
|
||||
input: '[data-role="ibo-quick-create--input"]',
|
||||
compartment_element: '[data-role="ibo-quick-create--compartment-element"]',
|
||||
},
|
||||
|
||||
// the constructor
|
||||
_create: function()
|
||||
{
|
||||
this.element.addClass('ibo-quick-create');
|
||||
this._initializeMarkup();
|
||||
this._bindEvents();
|
||||
},
|
||||
// events bound via _bind are removed automatically
|
||||
// revert other modifications here
|
||||
_destroy: function()
|
||||
{
|
||||
this.element.removeClass('ibo-quick-create');
|
||||
},
|
||||
_initializeMarkup: function()
|
||||
{
|
||||
const me = this;
|
||||
|
||||
// Instantiate selectize.js on input
|
||||
this.element.find(this.js_selectors.input).selectize({
|
||||
openOnFocus: false,
|
||||
maxItems: 1
|
||||
});
|
||||
|
||||
// Remove some inline styling from the widget
|
||||
this.element.find('.selectize-input > input').css('width', '');
|
||||
},
|
||||
_bindEvents: function()
|
||||
{
|
||||
const me = this;
|
||||
const oBodyElem = $('body');
|
||||
|
||||
this.element.find(this.js_selectors.icon).on('click', function(oEvent){
|
||||
me._onIconClick(oEvent);
|
||||
});
|
||||
this.element.find(this.js_selectors.form).on('submit', function(oEvent){
|
||||
me._onFormSubmit(oEvent);
|
||||
});
|
||||
this.element.find(this.js_selectors.input).on('change', function(oEvent){
|
||||
me._onInputOptionSelected(oEvent, $(this));
|
||||
});
|
||||
// Mostly for outside clicks that should close elements
|
||||
oBodyElem.on('click', function(oEvent){
|
||||
me._onBodyClick(oEvent);
|
||||
});
|
||||
// Mostly for hotkeys
|
||||
oBodyElem.on('keyup', function(oEvent){
|
||||
me._onBodyKeyUp(oEvent);
|
||||
});
|
||||
},
|
||||
_onIconClick: function(oEvent)
|
||||
{
|
||||
// Avoid anchor glitch
|
||||
oEvent.preventDefault();
|
||||
|
||||
if(this._isDrawerOpened())
|
||||
{
|
||||
this._closeDrawer();
|
||||
}
|
||||
else
|
||||
{
|
||||
this._openDrawer();
|
||||
// Focus in the input for a better UX
|
||||
this._setFocusOnInput();
|
||||
}
|
||||
},
|
||||
_onFormSubmit: function(oEvent)
|
||||
{
|
||||
const sSearchValue = this.element.find(this.js_selectors.input).val();
|
||||
|
||||
// Submit form only if something in the input
|
||||
if(sSearchValue === '')
|
||||
{
|
||||
oEvent.preventDefault();
|
||||
}
|
||||
},
|
||||
_onInputOptionSelected: function(oEvent, oInputElem)
|
||||
{
|
||||
// Submit form directly on change
|
||||
this.element.find(this.js_selectors.form).trigger('submit');
|
||||
},
|
||||
_onBodyClick: function(oEvent)
|
||||
{
|
||||
if($(oEvent.target.closest('.ibo-quick-create')).length === 0)
|
||||
{
|
||||
this._closeDrawer();
|
||||
}
|
||||
},
|
||||
_onBodyKeyUp: function(oEvent)
|
||||
{
|
||||
// Note: We thought about extracting the oEvent.key in a variable to lower case it, but this would be done
|
||||
// on every single key up in the application, which might not be what we want... (time consuming)
|
||||
if((oEvent.altKey === true) && (oEvent.key === 'n' || oEvent.key === 'N'))
|
||||
{
|
||||
if(this._isDrawerOpened())
|
||||
{
|
||||
this._setFocusOnInput();
|
||||
}
|
||||
// If drawer is closed, we trigger the click on the icon in order for the other widget to behave like they should (eg. close themselves)
|
||||
else
|
||||
{
|
||||
this.element.find(this.js_selectors.icon).trigger('click');
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// Methods
|
||||
_isDrawerOpened: function()
|
||||
{
|
||||
return this.element.hasClass(this.css_classes.opened);
|
||||
},
|
||||
_openDrawer: function()
|
||||
{
|
||||
this.element.addClass(this.css_classes.opened);
|
||||
},
|
||||
_closeDrawer: function()
|
||||
{
|
||||
this.element.removeClass(this.css_classes.opened);
|
||||
},
|
||||
_setFocusOnInput: function()
|
||||
{
|
||||
this.element.find('.selectize-input > input').trigger('focus');
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user