2020-01-24 12:14:08 +01:00
/ * *
* EGroupware eTemplate2 - JS Nextmatch object
*
* @license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
2021-08-17 21:56:52 +02:00
* @link https : //www.egroupware.org
2020-01-24 12:14:08 +01:00
* @author Andreas Stöckel
2021-08-17 21:56:52 +02:00
* @copyright EGroupware GmbH 2011 - 2021
* /
2020-01-24 12:14:08 +01:00
/ * e g w : u s e s
// Include the action system
egw_action . egw_action ;
egw_action . egw_action_popup ;
egw_action . egw_action_dragdrop ;
egw_action . egw_menu_dhtmlx ;
// Include some core classes
et2_core_widget ;
et2_core_interfaces ;
et2_core_DOMWidget ;
// Include all widgets the nextmatch extension will create
et2_widget_template ;
et2_widget_grid ;
et2_widget_selectbox ;
et2_widget_selectAccount ;
et2_widget_taglist ;
et2_extension_customfields ;
// Include all nextmatch subclasses
et2_extension_nextmatch_rowProvider ;
2020-01-31 21:07:27 +01:00
et2_extension_nextmatch_controller ;
2020-02-12 22:49:22 +01:00
et2_widget_dynheight ;
2020-01-24 12:14:08 +01:00
// Include the grid classes
et2_dataview ;
* /
2021-08-17 21:56:52 +02:00
import { et2_csvSplit , et2_no_init } from "./et2_core_common" ;
import { et2_IInput , et2_IPrint , et2_IResizeable , implements_methods , et2_implements_registry } from "./et2_core_interfaces" ;
2020-02-05 00:07:50 +01:00
import { ClassWithAttributes } from "./et2_core_inheritance" ;
2020-08-05 19:21:18 +02:00
import { et2_createWidget , et2_register_widget , et2_widget , WidgetConfig } from "./et2_core_widget" ;
2020-01-24 12:14:08 +01:00
import { et2_DOMWidget } from "./et2_core_DOMWidget" ;
import { et2_baseWidget } from "./et2_core_baseWidget" ;
import { et2_inputWidget } from "./et2_core_inputWidget" ;
import { et2_selectbox } from "./et2_widget_selectbox" ;
2020-01-31 21:07:27 +01:00
import { et2_nextmatch_rowProvider } from "./et2_extension_nextmatch_rowProvider" ;
import { et2_nextmatch_controller } from "./et2_extension_nextmatch_controller" ;
import { et2_dataview } from "./et2_dataview" ;
import { et2_dataview_column } from "./et2_dataview_model_columns" ;
2020-02-12 19:16:34 +01:00
import { et2_customfields_list } from "./et2_extension_customfields" ;
2020-08-05 19:21:18 +02:00
import { et2_link_entry , et2_link_to } from "./et2_widget_link" ;
import { et2_dialog } from "./et2_widget_dialog" ;
import { et2_grid } from "./et2_widget_grid" ;
import { et2_dataview_grid } from "./et2_dataview_view_grid" ;
import { et2_taglist } from "./et2_widget_taglist" ;
import { et2_selectAccount } from "./et2_widget_selectAccount" ;
import { et2_dynheight } from "./et2_widget_dynheight" ;
import { et2_arrayMgr } from "./et2_core_arrayMgr" ;
import { et2_button } from "./et2_widget_button" ;
import { et2_searchbox } from "./et2_widget_textbox" ;
import { et2_template } from "./et2_widget_template" ;
2021-08-17 21:56:52 +02:00
import { egw } from "../jsapi/egw_global" ;
import { et2_compileLegacyJS } from "./et2_core_legacyJSFunctions" ;
import { egwIsMobile } from "../egw_action/egw_action_common.js" ;
import Sortable from 'sortablejs/modular/sortable.complete.esm.js' ;
2020-02-12 19:16:34 +01:00
//import {et2_selectAccount} from "./et2_widget_SelectAccount";
2020-01-31 21:07:27 +01:00
2020-01-24 12:14:08 +01:00
/ * *
* Interface all special nextmatch header elements have to implement .
* /
2021-08-17 21:56:52 +02:00
export interface et2_INextmatchHeader
{
2020-01-24 12:14:08 +01:00
/ * *
* The 'setNextmatch' function is called by the parent nextmatch widget
* and tells the nextmatch header widgets which widget they should direct
* their 'sort' , 'search' or 'filter' calls to .
*
* @param { et2_nextmatch } _nextmatch
* /
2020-02-11 19:32:50 +01:00
setNextmatch ( nextmatch : et2_nextmatch ) : void
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
export const et2_INextmatchHeader = "et2_INextmatchHeader" ;
et2_implements_registry . et2_INextmatchHeader = function ( obj : et2_widget )
2020-01-29 22:29:06 +01:00
{
return implements_methods ( obj , [ "setNextmatch" ] ) ;
}
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
export interface et2_INextmatchSortable
{
2021-08-17 21:56:52 +02:00
setSortmode ( _sort_mode ) : void
2020-01-24 12:14:08 +01:00
}
2020-03-18 17:36:14 +01:00
2021-08-17 21:56:52 +02:00
export const et2_INextmatchSortable = "et2_INextmatchSortable" ;
et2_implements_registry . et2_INextmatchSortable = function ( obj : et2_widget )
2020-01-29 22:29:06 +01:00
{
return implements_methods ( obj , [ "setSortmode" ] ) ;
}
2020-01-24 12:14:08 +01:00
2020-03-18 17:36:14 +01:00
// For holding settings while whe print
interface PrintSettings
{
2021-08-17 21:56:52 +02:00
old_height : number ,
row_selector : string ,
orientation_style : HTMLStyleElement
2021-03-01 22:08:13 +01:00
}
interface ActiveFilters
{
search? : string ,
filter? : any ,
filter2? : any ,
2021-08-17 21:56:52 +02:00
col_filter : { [ key : string ] : any } ,
selectcols? : string [ ] ,
searchletter? : string ,
2021-03-01 22:08:13 +01:00
selected? : string [ ]
}
2020-03-18 17:36:14 +01:00
2020-01-24 12:14:08 +01:00
/ * *
* Class which implements the "nextmatch" XET - Tag
*
* NM header is build like this in DOM
*
* + - nextmatch_header -- -- - + -- -- -- -- -- -- + -- -- -- -- -- + -- -- -- -- + -- -- -- -- - + -- -- -- -- -- -- -- + -- -- -- -- -- - + -- -- -- - +
* + header_left | search . . | header_row | category | filter | filter2 | header_right | favorites | count |
* + -- -- -- -- -- -- - + -- -- -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- + -- -- -- -- + -- -- -- -- - + -- -- -- -- -- -- -- + -- -- -- -- -- - + -- -- -- - +
*
* everything left incl . standard filters is floated left :
* + - nextmatch_header -- -- - + -- -- -- -- -- -- + -- -- -- -- -- + -- -- -- -- + -- -- -- -- - +
* + header_left | search . . | header_row | category | filter | filter2 |
* + -- -- -- -- -- -- - + -- -- -- -- -- + -- -- -- -- -- -- + -- -- -- -- -- + -- -- -- -- + -- -- -- -- - +
* everything from header_right on is floated right :
* + -- -- -- -- -- -- -- + -- -- -- -- -- - + -- -- -- - +
* | header_right | favorites | count |
* + -- -- -- -- -- -- -- + -- -- -- -- -- - + -- -- -- - +
* @augments et2_DOMWidget
* /
export class et2_nextmatch extends et2_DOMWidget implements et2_IResizeable , et2_IInput , et2_IPrint
{
static readonly _attributes = {
// These normally set in settings, but broken out into attributes to allow run-time changes
"template" : {
"name" : "Template" ,
"type" : "string" ,
"description" : "The id of the template which contains the grid layout."
} ,
"hide_header" : {
"name" : "Hide header" ,
"type" : "boolean" ,
"description" : "Hide the header" ,
"default" : false
} ,
"header_left" : {
"name" : "Left custom template" ,
"type" : "string" ,
"description" : "Customise the nextmatch - left side. Provided template becomes a child of nextmatch, and any input widgets are automatically bound to refresh the nextmatch on change. Any inputs with an onChange attribute can trigger the nextmatch to refresh by returning true." ,
"default" : ""
} ,
"header_right" : {
"name" : "Right custom template" ,
"type" : "string" ,
"description" : "Customise the nextmatch - right side. Provided template becomes a child of nextmatch, and any input widgets are automatically bound to refresh the nextmatch on change. Any inputs with an onChange attribute can trigger the nextmatch to refresh by returning true." ,
"default" : ""
} ,
"header_row" : {
"name" : "Inline custom template" ,
"type" : "string" ,
"description" : "Customise the nextmatch - inline, after row count. Provided template becomes a child of nextmatch, and any input widgets are automatically bound to refresh the nextmatch on change. Any inputs with an onChange attribute can trigger the nextmatch to refresh by returning true." ,
"default" : ""
} ,
"no_filter" : {
"name" : "No filter" ,
"type" : "boolean" ,
"description" : "Hide the first filter" ,
"default" : et2_no_init
} ,
"no_filter2" : {
"name" : "No filter2" ,
"type" : "boolean" ,
"description" : "Hide the second filter" ,
"default" : et2_no_init
} ,
2020-08-05 19:21:18 +02:00
"disable_autorefresh" : {
"name" : "Disable autorefresh" ,
"type" : "boolean" ,
"description" : "Disable the ability to autorefresh the nextmatch on a regular interval. " ,
"default" : false
} ,
2021-03-16 17:39:07 +01:00
"disable_selection_advance" : {
"name" : "Disable selection advance" ,
"type" : "boolean" ,
"description" : "If a refresh deletes the currently selected row, we normally advance the selection to the next row. Set to true to stop this." ,
"default" : false
} ,
2020-01-24 12:14:08 +01:00
"view" : {
"name" : "View" ,
"type" : "string" ,
"description" : "Display entries as either 'row' or 'tile'. A matching template must also be set after changing this." ,
"default" : et2_no_init
} ,
"onselect" : {
"name" : "onselect" ,
"type" : "js" ,
"default" : et2_no_init ,
"description" : "JS code which gets executed when rows are selected. Can also be a app.appname.func(selected) style method"
} ,
"onfiledrop" : {
"name" : "onFileDrop" ,
"type" : "js" ,
"default" : et2_no_init ,
"description" : "JS code that gets executed when a _file_ is dropped on a row. Other drop interactions are handled by the action system. Return false to prevent the default link action."
} ,
2020-07-20 21:43:26 +02:00
"onadd" : {
"name" : "onAdd" ,
"type" : "js" ,
"default" : et2_no_init ,
"description" : "JS code that gets executed when a new entry is added via refresh(). Allows apps to override the default handling. Return false to cancel the add."
} ,
2020-01-24 12:14:08 +01:00
"settings" : {
"name" : "Settings" ,
"type" : "any" ,
"description" : "The nextmatch settings" ,
"default" : { }
}
} ;
// Currently active filters
2021-03-01 22:08:13 +01:00
activeFilters : ActiveFilters ;
2020-01-24 12:14:08 +01:00
2020-08-07 17:19:06 +02:00
/ * *
* Update types
* @see et2_nextmatch . refresh ( ) for more information
2021-08-17 21:56:52 +02:00
* /
2020-08-07 17:19:06 +02:00
public static readonly ADD = 'add' ;
public static readonly UPDATE_IN_PLACE = 'update-in-place' ;
public static readonly UPDATE = 'update' ;
public static readonly EDIT = 'edit' ;
public static readonly DELETE = 'delete' ;
2020-01-24 12:14:08 +01:00
// DOM / jQuery stuff
2021-08-17 21:56:52 +02:00
private div : JQuery ;
private innerDiv : JQuery ;
private dynheight : any ;
private blank : JQuery ;
2020-01-24 12:14:08 +01:00
// Popup to select columns
2021-08-17 21:56:52 +02:00
private selectPopup : any ;
2020-01-24 12:14:08 +01:00
2020-08-07 17:19:06 +02:00
public static readonly legacyOptions = [ "template" , "hide_header" , "header_left" , "header_right" ] ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
private template : any ;
columns : { visible : boolean , widget : et2_widget } [ ] ;
private sortedColumnsList : string [ ] ;
2020-01-24 12:14:08 +01:00
// If we need the nextmatch to have a value, keep it here.
// Normally this is used in actions, and is the action and selected rows.
2021-08-17 21:56:52 +02:00
private value : any ;
2020-01-24 12:14:08 +01:00
// Big old bag of settings
2021-08-17 21:56:52 +02:00
private settings : any ;
2020-01-24 12:14:08 +01:00
// Current view, either row or tile. We store it here as controllers are
// recreated when the template changes.
2021-08-17 21:56:52 +02:00
view : string ;
2020-01-24 12:14:08 +01:00
// Sub-objects used for actual work
2021-08-17 21:56:52 +02:00
private readonly header : et2_nextmatch_header_bar ;
dataview : any ;
controller : any ;
private rowProvider : any ;
2020-01-24 12:14:08 +01:00
// Flag for an update is currently being done, to avoid a loop
2021-08-17 21:56:52 +02:00
private update_in_progress : boolean ;
2020-01-24 12:14:08 +01:00
// Window timer for automatically refreshing
2021-08-17 21:56:52 +02:00
private _autorefresh_timer : number ;
2020-01-24 12:14:08 +01:00
2020-10-22 23:53:59 +02:00
// Nextmatch can't render while hidden, we store refresh requests for later
2021-08-17 21:56:52 +02:00
private _queued_refreshes : null | { type : string , ids : string [ ] } [ ] = [ ] ;
2020-10-22 23:53:59 +02:00
2020-01-24 12:14:08 +01:00
// When printing, we change the layout around. Keep some values so it can be restored after
2021-08-17 21:56:52 +02:00
private print : PrintSettings = {
2020-03-18 17:36:14 +01:00
old_height : 0 ,
row_selector : '' ,
orientation_style : null
2020-01-24 12:14:08 +01:00
} ;
/ * *
* Constructor
*
* @memberOf et2_nextmatch
* /
2021-08-17 21:56:52 +02:00
constructor ( _parent ? , _attrs? : WidgetConfig , _child? : object )
2020-03-18 17:36:14 +01:00
{
2020-01-24 12:14:08 +01:00
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2_nextmatch . _attributes , _child || { } ) ) ;
2021-08-17 21:56:52 +02:00
this . activeFilters = { col_filter : { } } ;
2020-01-24 13:57:05 +01:00
this . columns = [ ] ;
// keeps sorted columns
this . sortedColumnsList = [ ] ;
2020-01-24 12:14:08 +01:00
// Directly set current col_filters from settings
jQuery . extend ( this . activeFilters . col_filter , this . options . settings . col_filter ) ;
/ *
Process selected custom fields here , so that the settings are correctly
set before the row template is parsed
* /
2020-02-11 19:32:50 +01:00
const prefs = this . _getPreferences ( ) ;
const cfs = { } ;
for ( let i = 0 ; i < prefs . visible . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-12 19:32:29 +01:00
if ( prefs . visible [ i ] . indexOf ( et2_nextmatch_customfields . PREFIX ) == 0 )
2020-01-24 12:14:08 +01:00
{
cfs [ prefs . visible [ i ] . substr ( 1 ) ] = ! prefs . negated ;
}
}
2020-02-11 19:32:50 +01:00
const global_data = this . getArrayMgr ( "modifications" ) . getRoot ( ) . getEntry ( '~custom_fields~' ) ;
2020-01-24 12:14:08 +01:00
if ( typeof global_data == 'object' && global_data != null )
{
global_data . fields = cfs ;
}
this . div = jQuery ( document . createElement ( "div" ) )
. addClass ( "et2_nextmatch" ) ;
2021-08-17 21:56:52 +02:00
this . header = < et2_nextmatch_header_bar > et2_createWidget ( "nextmatch_header_bar" , { } , this ) ;
2020-01-24 12:14:08 +01:00
this . innerDiv = jQuery ( document . createElement ( "div" ) )
. appendTo ( this . div ) ;
// Create the dynheight component which dynamically scales the inner
// container.
this . dynheight = this . _getDynheight ( ) ;
// Create the outer grid container
this . dataview = new et2_dataview ( this . innerDiv , this . egw ( ) ) ;
// Blank placeholder
this . blank = jQuery ( document . createElement ( "div" ) )
. appendTo ( this . dataview . table ) ;
// We cannot create the grid controller now, as this depends on the grid
// instance, which can first be created once we have the columns
this . controller = null ;
this . rowProvider = null ;
}
/ * *
* Destroys all
* /
destroy ( )
{
2020-02-11 19:32:50 +01:00
// Stop auto-refresh
2020-01-24 12:14:08 +01:00
if ( this . _autorefresh_timer )
{
window . clearInterval ( this . _autorefresh_timer ) ;
this . _autorefresh_timer = null ;
}
// Unbind handler used for toggling autorefresh
jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode ) . off ( 'show.et2_nextmatch' ) ;
jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode ) . off ( 'hide.et2_nextmatch' ) ;
// Free the grid components
2020-01-31 21:07:27 +01:00
this . dataview . destroy ( ) ;
2020-01-24 12:14:08 +01:00
if ( this . rowProvider )
{
2020-01-31 21:07:27 +01:00
this . rowProvider . destroy ( ) ;
2020-01-24 12:14:08 +01:00
}
if ( this . controller )
{
2020-01-31 21:07:27 +01:00
this . controller . destroy ( ) ;
2020-01-24 12:14:08 +01:00
}
2020-01-31 21:07:27 +01:00
this . dynheight . destroy ( ) ;
2020-01-24 12:14:08 +01:00
super . destroy ( ) ;
}
2020-02-28 14:45:58 +01:00
getController ( )
{
return this . controller ;
}
2020-01-24 12:14:08 +01:00
/ * *
* Loads the nextmatch settings
*
* @param { object } _attrs
* /
transformAttributes ( _attrs )
{
super . transformAttributes ( _attrs ) ;
2021-08-17 21:56:52 +02:00
if ( this . id )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const entry = this . getArrayMgr ( "content" ) . data ;
2020-01-24 12:14:08 +01:00
_attrs [ "settings" ] = { } ;
2021-08-17 21:56:52 +02:00
if ( entry )
2020-01-24 12:14:08 +01:00
{
_attrs [ "settings" ] = entry ;
// Make sure there's an action var parameter
if ( _attrs [ "settings" ] [ "actions" ] && ! _attrs . settings [ "action_var" ] )
{
_attrs . settings . action_var = "action" ;
}
// Merge settings mess into attributes
2020-02-11 19:32:50 +01:00
for ( let attr in this . attributes )
2020-01-24 12:14:08 +01:00
{
if ( _attrs . settings [ attr ] )
{
_attrs [ attr ] = _attrs . settings [ attr ] ;
delete _attrs . settings [ attr ] ;
}
}
}
}
}
doLoadingFinished ( )
{
super . doLoadingFinished ( ) ;
if ( ! this . dynheight )
{
this . dynheight = this . _getDynheight ( ) ;
}
// Register handler for dropped files, if possible
if ( this . options . settings . row_id )
{
// Appname should be first part of the template name
2020-02-11 19:32:50 +01:00
const split = this . options . template . split ( '.' ) ;
const appname = split [ 0 ] ;
2020-01-24 12:14:08 +01:00
// Check link registry
if ( this . egw ( ) . link_get_registry ( appname ) )
{
2020-02-11 19:32:50 +01:00
const self = this ;
2020-01-24 12:14:08 +01:00
// Register a handler
// @ts-ignore
jQuery ( this . div )
2021-08-17 21:56:52 +02:00
. on ( 'dragenter' , '.egwGridView_grid tr' , function ( e )
{
2020-01-24 12:14:08 +01:00
// Figure out _which_ row
2020-02-11 19:32:50 +01:00
const row = self . controller . getRowByNode ( this ) ;
2020-01-24 12:14:08 +01:00
if ( ! row || ! row . uid )
{
return false ;
}
2021-08-17 21:56:52 +02:00
e . stopPropagation ( ) ;
e . preventDefault ( ) ;
2020-01-24 12:14:08 +01:00
// Indicate acceptance
if ( row . controller && row . controller . _selectionMgr )
{
2021-08-17 21:56:52 +02:00
row . controller . _selectionMgr . setFocused ( row . uid , true ) ;
2020-01-24 12:14:08 +01:00
}
return false ;
} )
2021-08-17 21:56:52 +02:00
. on ( 'dragexit' , '.egwGridView_grid tr' , function ( )
{
2020-01-24 12:14:08 +01:00
self . controller . _selectionMgr . setFocused ( ) ;
} )
2021-08-17 21:56:52 +02:00
. on ( 'dragover' , '.egwGridView_grid tr' , false ) . attr ( "dropzone" , "copy" )
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
. on ( 'drop' , '.egwGridView_grid tr' , function ( e )
{
self . handle_drop ( e , this ) ;
2020-01-24 12:14:08 +01:00
return false ;
} ) ;
}
}
// stop invalidation in no visible tabs
2021-08-17 21:56:52 +02:00
jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'hide.et2_nextmatch' , jQuery . proxy ( function ( )
{
2020-01-24 12:14:08 +01:00
if ( this . controller && this . controller . _grid )
{
this . controller . _grid . doInvalidate = false ;
}
2021-08-17 21:56:52 +02:00
} , this ) ) ;
jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'show.et2_nextmatch' , jQuery . proxy ( function ( )
{
2020-01-24 12:14:08 +01:00
if ( this . controller && this . controller . _grid )
{
this . controller . _grid . doInvalidate = true ;
}
2021-08-17 21:56:52 +02:00
} , this ) ) ;
2020-01-24 12:14:08 +01:00
return true ;
}
/ * *
* Implements the et2_IResizeable interface - lets the dynheight manager
* update the width and height and then update the dataview container .
* /
resize ( )
{
2021-08-17 21:56:52 +02:00
if ( this . dynheight )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . dynheight . update ( function ( _w , _h )
{
2020-01-24 12:14:08 +01:00
this . dataview . resize ( _w , _h ) ;
} , this ) ;
}
}
/ * *
* Sorts the nextmatch widget by the given ID .
*
* @param { string } _id is the id of the data entry which should be sorted .
* @param { boolean } _asc if true , the elements are sorted ascending , otherwise
* descending . If not set , the sort direction will be determined
* automatically .
* @param { boolean } _update true / undefined : call applyFilters , false : only set sort
* /
2021-08-17 21:56:52 +02:00
sortBy ( _id , _asc , _update? : boolean )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( typeof _update == "undefined" )
2020-01-24 12:14:08 +01:00
{
_update = true ;
}
// Create the "sort" entry in the active filters if it did not exist
// yet.
2021-08-17 21:56:52 +02:00
if ( typeof this . activeFilters [ "sort" ] == "undefined" )
2020-01-24 12:14:08 +01:00
{
this . activeFilters [ "sort" ] = {
"id" : null ,
"asc" : true
} ;
}
// Determine the sort direction automatically if it is not set
2021-08-17 21:56:52 +02:00
if ( typeof _asc == "undefined" )
2020-01-24 12:14:08 +01:00
{
_asc = true ;
2021-08-17 21:56:52 +02:00
if ( this . activeFilters [ "sort" ] . id == _id )
2020-01-24 12:14:08 +01:00
{
_asc = ! this . activeFilters [ "sort" ] . asc ;
}
}
// Set the sortmode display
2021-08-17 21:56:52 +02:00
this . iterateOver ( function ( _widget )
{
_widget . setSortmode ( ( _widget . id == _id ) ? ( _asc ? "asc" : "desc" ) : "none" ) ;
2020-01-24 12:14:08 +01:00
} , this , et2_INextmatchSortable ) ;
2021-08-17 21:56:52 +02:00
if ( _update )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . applyFilters ( { sort : { id : _id , asc : _asc } } ) ;
2020-01-24 12:14:08 +01:00
}
else
{
// Update the entry in the activeFilters object
this . activeFilters [ "sort" ] = {
"id" : _id ,
"asc" : _asc
} ;
}
}
/ * *
* Removes the sort entry from the active filters object and thus returns to
* the natural sort order .
* /
resetSort ( )
{
// Check whether the nextmatch widget is currently sorted
2021-08-17 21:56:52 +02:00
if ( typeof this . activeFilters [ "sort" ] != "undefined" )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
// Reset the sort mode
2021-08-17 21:56:52 +02:00
this . iterateOver ( function ( _widget )
{
2020-01-24 12:14:08 +01:00
_widget . setSortmode ( "none" ) ;
} , this , et2_INextmatchSortable ) ;
// Delete the "sort" filter entry
this . applyFilters ( { sort : undefined } ) ;
}
}
/ * *
* Apply current or modified filters on NM widget ( updating rows accordingly )
*
* @param _set filter ( s ) to set eg . { filter : '' } to reset filter in NM header
* /
2021-08-17 21:56:52 +02:00
applyFilters ( _set? : object | any )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
let changed = false ;
let keep_selection = false ;
2020-01-24 12:14:08 +01:00
// Avoid loops cause by change events
if ( this . update_in_progress ) return ;
this . update_in_progress = true ;
// Cleared explicitly
if ( typeof _set != 'undefined' && jQuery . isEmptyObject ( _set ) )
{
changed = true ;
this . activeFilters = { col_filter : { } } ;
}
if ( typeof this . activeFilters == "undefined" )
{
this . activeFilters = { col_filter : { } } ;
}
if ( typeof this . activeFilters . col_filter == "undefined" )
{
this . activeFilters . col_filter = { } ;
}
2021-08-17 21:56:52 +02:00
if ( typeof _set == 'object' )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
for ( let s in _set )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( s == 'col_filter' )
2020-01-24 12:14:08 +01:00
{
// allow apps setState() to reset all col_filter by using undefined or null for it
// they can not pass {} for _set / state.state, if they need to set something
2021-08-17 21:56:52 +02:00
if ( _set . col_filter === undefined || _set . col_filter === null )
2020-01-24 12:14:08 +01:00
{
this . activeFilters . col_filter = { } ;
changed = true ;
}
else
{
2020-02-11 19:32:50 +01:00
for ( let c in _set . col_filter )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( this . activeFilters . col_filter [ c ] !== _set . col_filter [ c ] )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( _set . col_filter [ c ] )
2020-01-24 12:14:08 +01:00
{
this . activeFilters . col_filter [ c ] = _set . col_filter [ c ] ;
}
else
{
delete this . activeFilters . col_filter [ c ] ;
}
changed = true ;
}
}
}
}
2021-08-17 21:56:52 +02:00
else if ( s === 'selected' )
2020-01-24 12:14:08 +01:00
{
changed = true ;
keep_selection = true ;
this . controller . _selectionMgr . resetSelection ( ) ;
this . controller . _objectManager . clear ( ) ;
2020-02-11 19:32:50 +01:00
for ( let i in _set . selected )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . controller . _selectionMgr . setSelected ( _set . selected [ i ] . indexOf ( '::' ) > 0 ? _set . selected [ i ] : this . controller . dataStorePrefix + '::' + _set . selected [ i ] , true ) ;
2020-01-24 12:14:08 +01:00
}
delete _set . selected ;
}
2021-08-17 21:56:52 +02:00
else if ( this . activeFilters [ s ] !== _set [ s ] )
2020-01-24 12:14:08 +01:00
{
this . activeFilters [ s ] = _set [ s ] ;
changed = true ;
}
}
}
this . egw ( ) . debug ( "info" , "Changing nextmatch filters to " , this . activeFilters ) ;
// Keep the selection after applying filters, but only if unchanged
if ( ! changed || keep_selection )
{
this . controller . keepSelection ( ) ;
}
else
{
// Do not keep selection
2021-08-17 21:56:52 +02:00
this . controller . _selectionMgr . resetSelection ( ) ;
2020-01-24 12:14:08 +01:00
this . controller . _objectManager . clear ( ) ;
this . controller . keepSelection ( ) ;
}
// Update the filters in the grid controller
this . controller . setFilters ( this . activeFilters ) ;
// Update the header
this . header . setFilters ( this . activeFilters ) ;
// Update any column filters
2021-08-17 21:56:52 +02:00
this . iterateOver ( function ( column )
{
2020-01-24 12:14:08 +01:00
// Skip favorites - it implements et2_INextmatchHeader, but we don't want it in the filter
if ( typeof column . id != "undefined" && column . id . indexOf ( 'favorite' ) == 0 ) return ;
if ( typeof column . set_value != "undefined" && column . id )
{
column . set_value ( typeof this [ column . id ] == "undefined" || this [ column . id ] == null ? "" : this [ column . id ] ) ;
}
2021-08-17 21:56:52 +02:00
if ( column . id && typeof column . get_value == "function" )
2020-01-24 12:14:08 +01:00
{
this [ column . id ] = column . get_value ( ) ;
}
} , this . activeFilters . col_filter , et2_INextmatchHeader ) ;
// Trigger an update
this . controller . update ( true ) ;
if ( changed )
{
// Highlight matching favorite in sidebox
if ( this . getInstanceManager ( ) . app )
{
2020-02-11 19:32:50 +01:00
const appname = this . getInstanceManager ( ) . app ;
2020-01-24 12:14:08 +01:00
if ( app [ appname ] && app [ appname ] . highlight_favorite )
{
app [ appname ] . highlight_favorite ( ) ;
}
}
}
this . update_in_progress = false ;
}
/ * *
* Refresh given rows for specified change
*
* Change type parameters allows for quicker refresh then complete server side reload :
2020-08-07 17:19:06 +02:00
* - update : request modified data from given rows . May be moved .
2020-07-29 13:58:02 +02:00
* - update - in - place : update row , but do NOT move it , or refresh if uid does not exist
2020-08-07 17:19:06 +02:00
* - edit : rows changed , but sorting may be affected . Full reload .
2020-01-24 12:14:08 +01:00
* - delete : just delete the given rows clientside ( no server interaction neccessary )
2020-07-27 22:07:15 +02:00
* - add : put the new row in at the top , unless app says otherwise
*
2020-08-07 17:19:06 +02:00
* What actually happens also depends on a general preference "lazy-update" :
* default / l a z y :
* - add always on top
* - updates on top , if sorted by last modified , otherwise update - in - place
* - update - in - place is always in place !
*
* exact :
* - add and update on top if sorted by last modified , otherwise full refresh
* - update - in - place is always in place !
*
2020-07-27 22:07:15 +02:00
* Nextmatch checks the application callback nm_refresh_index , which has a default implementation
* in egw_app . nm_refresh_index ( ) .
2020-01-24 12:14:08 +01:00
*
* @param { string [ ] | string } _row_ids rows to refresh
2020-08-07 17:19:06 +02:00
* @param { ? string } _type "update-in-place" , "update" , "edit" , "delete" or "add"
2020-01-24 12:14:08 +01:00
*
* @see jsapi . egw_refresh ( )
2020-07-27 22:07:15 +02:00
* @see egw_app . nm_refresh_index ( )
2020-01-24 12:14:08 +01:00
* @fires refresh from the widget itself
* /
2021-08-17 21:56:52 +02:00
refresh ( _row_ids , _type )
2020-01-24 12:14:08 +01:00
{
// Framework trying to refresh, but nextmatch not fully initialized
if ( this . controller === null || ! this . div )
{
return ;
}
2020-10-22 23:53:59 +02:00
// Make sure we're dealing with arrays
2021-08-17 21:56:52 +02:00
if ( typeof _row_ids == 'string' || typeof _row_ids == 'number' ) _row_ids = [ _row_ids ] ;
2020-10-22 23:53:59 +02:00
2020-08-07 17:19:06 +02:00
// Make some changes in what we're doing based on preference
2020-09-28 16:51:46 +02:00
let update_pref = egw . preference ( "lazy-update" ) || 'lazy' ;
2020-08-07 17:19:06 +02:00
if ( _type == et2_nextmatch . UPDATE && ! this . is_sorted_by_modified ( ) )
{
_type = update_pref == "lazy" ? et2_nextmatch.UPDATE_IN_PLACE : et2_nextmatch.EDIT ;
}
2021-08-17 21:56:52 +02:00
else if ( update_pref == "exact" && _type == et2_nextmatch . ADD && ! this . is_sorted_by_modified ( ) )
2020-08-07 17:19:06 +02:00
{
_type = et2_nextmatch . EDIT ;
}
2021-08-17 21:56:52 +02:00
if ( _type == et2_nextmatch . ADD && ! ( update_pref == "lazy" || update_pref == "exact" && this . is_sorted_by_modified ( ) ) )
2020-09-15 17:05:25 +02:00
{
_type = et2_nextmatch . EDIT ;
}
2020-08-07 17:19:06 +02:00
2021-08-17 21:56:52 +02:00
if ( typeof _type == 'undefined' ) _type = et2_nextmatch . EDIT ;
2021-01-13 17:08:53 +01:00
2021-08-17 21:56:52 +02:00
if ( ! this . div . is ( ':visible' ) ) // run refresh, once we become visible again
2021-01-13 17:08:53 +01:00
{
return this . _queue_refresh ( _row_ids , _type ) ;
}
2021-08-17 21:56:52 +02:00
if ( typeof _row_ids == "undefined" || _row_ids === null )
2020-01-24 12:14:08 +01:00
{
this . applyFilters ( ) ;
// Trigger an event so app code can act on it
2021-08-17 21:56:52 +02:00
jQuery ( this ) . triggerHandler ( "refresh" , [ this ] ) ;
2020-01-24 12:14:08 +01:00
return ;
}
2020-10-14 18:37:47 +02:00
// Clean IDs in case they're UIDs with app prefixed
2021-08-17 21:56:52 +02:00
_row_ids = _row_ids . map ( function ( id )
{
if ( id . toString ( ) . indexOf ( this . controller . dataStorePrefix ) == - 1 )
2020-10-14 18:37:47 +02:00
{
return id ;
}
let parts = id . split ( "::" ) ;
parts . shift ( ) ;
return parts . join ( "::" ) ;
} . bind ( this ) ) ;
2020-08-07 17:19:06 +02:00
if ( _type == et2_nextmatch . DELETE )
2020-01-24 12:14:08 +01:00
{
// Record current & next index
var uid = _row_ids [ 0 ] . toString ( ) . indexOf ( this . controller . dataStorePrefix ) == 0 ? _row_ids [ 0 ] : this . controller . dataStorePrefix + "::" + _row_ids [ 0 ] ;
2020-02-11 19:32:50 +01:00
const entry = this . controller . _selectionMgr . _getRegisteredRowsEntry ( uid ) ;
2020-08-26 19:24:15 +02:00
if ( entry && entry . idx !== null )
2020-01-24 12:14:08 +01:00
{
2020-08-26 19:24:15 +02:00
let next = ( entry . ao ? entry . ao . getNext ( _row_ids . length ) : null ) ;
if ( next == null || ! next . id || next . id == uid )
{
// No next, select previous
next = ( entry . ao ? entry . ao . getPrevious ( 1 ) : null ) ;
}
2020-01-24 12:14:08 +01:00
2020-08-26 19:24:15 +02:00
// Stop automatic updating
this . dataview . grid . doInvalidate = false ;
2021-08-17 21:56:52 +02:00
for ( var i = 0 ; i < _row_ids . length ; i ++ )
2020-08-26 19:24:15 +02:00
{
uid = _row_ids [ i ] . toString ( ) . indexOf ( this . controller . dataStorePrefix ) == 0 ? _row_ids [ i ] : this . controller . dataStorePrefix + "::" + _row_ids [ i ] ;
2020-01-24 12:14:08 +01:00
2020-08-26 19:24:15 +02:00
// Delete from internal references
this . controller . deleteRow ( uid ) ;
}
2020-01-24 12:14:08 +01:00
2020-08-26 19:24:15 +02:00
// Select & focus next row
2021-03-16 17:39:07 +01:00
if ( next && next . id && ! this . options . disable_selection_advance )
2020-08-26 19:24:15 +02:00
{
this . controller . _selectionMgr . setSelected ( next . id , true ) ;
this . controller . _selectionMgr . setFocused ( next . id , true ) ;
}
2020-01-24 12:14:08 +01:00
2020-08-26 19:24:15 +02:00
// Update the count
const total = this . dataview . grid . _total - _row_ids . length ;
// This will remove the last row!
// That's OK, because grid adds one in this.controller.deleteRow()
this . dataview . grid . setTotalCount ( total ) ;
2020-10-09 18:15:17 +02:00
this . controller . _selectionMgr . setTotalCount ( total ) ;
2020-08-26 19:24:15 +02:00
// Re-enable automatic updating
this . dataview . grid . doInvalidate = true ;
this . dataview . grid . invalidate ( ) ;
}
2020-01-24 12:14:08 +01:00
}
id_loop :
2021-08-17 21:56:52 +02:00
for ( var i = 0 ; i < _row_ids . length ; i ++ )
2020-09-03 17:58:12 +02:00
{
2021-08-17 21:56:52 +02:00
let uid = _row_ids [ i ] . toString ( ) . indexOf ( this . controller . dataStorePrefix ) == 0 ? _row_ids [ i ] : this . controller . dataStorePrefix + "::" + _row_ids [ i ] ;
// Check for update on a row we don't have
let known = Object . values ( this . controller . _indexMap ) . filter ( function ( row )
2020-09-03 17:58:12 +02:00
{
2021-08-17 21:56:52 +02:00
return row . uid == uid ;
} ) ;
if ( ( _type == et2_nextmatch . UPDATE || _type == et2_nextmatch . UPDATE_IN_PLACE ) && ( ! known || known . length == 0 ) )
{
_type = et2_nextmatch . ADD ;
if ( update_pref == "exact" && ! this . is_sorted_by_modified ( ) )
2020-09-15 17:05:25 +02:00
{
2021-08-17 21:56:52 +02:00
_type = et2_nextmatch . EDIT ;
}
}
if ( [ et2_nextmatch . ADD , et2_nextmatch . UPDATE ] . indexOf ( _type ) !== - 1 )
{
// Pre-ask for the row data, and only proceed if we actually get it
// need to send nextmatch filters too, as server-side will merge old version from request otherwise
this . egw ( ) . dataFetch (
this . getInstanceManager ( ) . etemplate_exec_id ,
{ refresh : _row_ids } ,
this . controller . _filters ,
this . id , function ( data )
2020-10-02 18:38:49 +02:00
{
2021-08-17 21:56:52 +02:00
// In the event that the etemplate got removed before the data came back (Usually an action caused
// a full submit) just stop here.
if ( ! this . nm . getParent ( ) ) return ;
2020-10-02 18:38:49 +02:00
2021-08-17 21:56:52 +02:00
if ( data . total >= 1 )
{
this . type == et2_nextmatch . ADD ? this . nm . refresh_add ( this . uid , this . type )
: this . nm . refresh_update ( this . uid ) ;
}
else if ( this . type == et2_nextmatch . UPDATE )
{
// Remove row from controller
this . nm . controller . deleteRow ( this . uid ) ;
2020-09-15 17:05:25 +02:00
2021-08-17 21:56:52 +02:00
// Adjust total rows, clean grid
this . nm . controller . _grid . setTotalCount ( this . nm . controller . _grid . _total - _row_ids . length ) ;
this . nm . controller . _selectionMgr . setTotalCount ( this . nm . controller . _grid . _total ) ;
}
} , { type : _type , nm : this , uid : uid , prefix : this.controller.dataStorePrefix } , [ _row_ids ]
) ;
return ;
}
switch ( _type )
{
// update-in-place = update, but always only in place
case et2_nextmatch . UPDATE_IN_PLACE :
this . egw ( ) . dataRefreshUID ( uid ) ;
break ;
// These ones handled above in dataFetch() callback
case et2_nextmatch . UPDATE :
// update [existing] row, maybe we'll put it on top
break ;
case et2_nextmatch . DELETE :
// Handled above, more code to execute after loop so don't exit early
break ;
case et2_nextmatch . ADD :
break ;
// No more smart things we can do, refresh the whole thing
case et2_nextmatch . EDIT :
default :
// Trigger refresh
this . applyFilters ( ) ;
break id_loop ;
}
2020-01-24 12:14:08 +01:00
}
// Trigger an event so app code can act on it
2021-08-17 21:56:52 +02:00
jQuery ( this ) . triggerHandler ( "refresh" , [ this , _row_ids , _type ] ) ;
2020-01-24 12:14:08 +01:00
}
2020-07-22 19:59:42 +02:00
/ * *
* An entry has been updated . Request new data , and ask app about where the row
* goes now .
*
* @param uid
* /
2021-08-17 21:56:52 +02:00
protected refresh_update ( uid : string )
2020-07-22 19:59:42 +02:00
{
// Row data update has been sent, let's move it where app wants it
let entry = this . controller . _selectionMgr . _getRegisteredRowsEntry ( uid ) ;
// Need to delete first as there's a good chance indexes will change in an unknown way
// and we can't always find it by UID after due to duplication
2020-08-07 22:12:30 +02:00
this . controller . deleteRow ( uid ) ;
2020-07-22 19:59:42 +02:00
// Pretend it's a new row, let app tell us where it goes and we'll mark it as new
2020-08-07 17:19:06 +02:00
if ( ! this . refresh_add ( uid , et2_nextmatch . UPDATE ) )
2020-07-22 19:59:42 +02:00
{
// App did not want the row, or doesn't know where it goes but we've already removed it...
// Put it back before anyone notices. New data coming from server anyway.
2021-08-17 21:56:52 +02:00
let callback = function ( data )
{
2020-07-22 21:27:40 +02:00
data . class += " new_entry" ;
2020-07-22 19:59:42 +02:00
this . egw ( ) . dataUnregisterUID ( uid , callback , this ) ;
} ;
this . egw ( ) . dataRegisterUID ( uid , callback , this , this . getInstanceManager ( ) . etemplate_exec_id , this . id ) ;
2021-08-17 21:56:52 +02:00
this . controller . _insertDataRow ( entry , true ) ;
2020-07-22 19:59:42 +02:00
}
2020-09-01 22:48:50 +02:00
// Update does not need to increase row count, but refresh_add() adds it in
2021-08-17 21:56:52 +02:00
this . controller . _grid . setTotalCount ( this . controller . _grid . getTotalCount ( ) - 1 ) ;
2020-10-09 18:15:17 +02:00
this . controller . _selectionMgr . setTotalCount ( this . controller . _grid . getTotalCount ( ) ) ;
2020-07-22 19:59:42 +02:00
return true ;
}
2020-07-20 21:43:26 +02:00
/ * *
* An entry has been added . Put it in the list .
*
* @param uid
2020-07-22 16:58:21 +02:00
* @return boolean false : not added , true : added
2020-07-20 21:43:26 +02:00
* /
2021-08-17 21:56:52 +02:00
protected refresh_add ( uid : string , type = et2_nextmatch . ADD )
2020-07-20 21:43:26 +02:00
{
2020-09-28 16:51:46 +02:00
let index : boolean | number = egw . preference ( "lazy-update" ) !== "exact" ? 0 :
2021-08-17 21:56:52 +02:00
( this . is_sorted_by_modified ( ) ? 0 : false ) ;
2020-07-20 21:43:26 +02:00
2020-08-07 17:19:06 +02:00
// No add, do a full refresh
2020-07-21 23:32:13 +02:00
if ( index === false )
2020-07-20 21:43:26 +02:00
{
2020-07-22 16:58:21 +02:00
return false ;
2020-07-20 21:43:26 +02:00
}
2020-07-21 23:32:13 +02:00
2020-09-10 21:42:32 +02:00
let time = new Date ( ) . valueOf ( ) ;
2020-09-03 17:58:12 +02:00
2021-08-17 21:56:52 +02:00
this . egw ( ) . dataRegisterUID ( uid , this . _push_add_callback , {
nm : this ,
uid : uid ,
index : index
} , this . getInstanceManager ( ) . etemplate_exec_id , this . id ) ;
2020-10-08 19:53:17 +02:00
return true ;
}
2020-10-02 18:38:49 +02:00
2020-10-08 19:53:17 +02:00
/ * *
* Callback for adding a new row via push
*
* Expected context : { nm : this , uid : string , index : number }
* /
2021-08-17 21:56:52 +02:00
protected _push_add_callback ( this : { nm : et2_nextmatch , uid : string , index : number } , data : any )
2020-10-08 19:53:17 +02:00
{
if ( data && this . nm && this . nm . getParent ( ) )
{
if ( data . class )
2020-09-01 22:48:50 +02:00
{
2020-10-08 19:53:17 +02:00
data . class += " new_entry" ;
2020-09-01 22:48:50 +02:00
}
2020-10-08 19:53:17 +02:00
// Don't remove if new data has not arrived
let stored = egw . dataGetUIDdata ( this . uid ) ;
//if(stored?.timestamp >= time) return;
// Increase displayed row count or we lose the last row when we add and the total is wrong
2021-08-17 21:56:52 +02:00
this . nm . controller . _grid . setTotalCount ( this . nm . controller . _grid . getTotalCount ( ) + 1 ) ;
2020-10-09 18:15:17 +02:00
this . nm . controller . _selectionMgr . setTotalCount ( this . nm . controller . _grid . getTotalCount ( ) ) ;
2020-10-08 19:53:17 +02:00
// Insert at the top of the list, or where app said
var entry = this . nm . controller . _selectionMgr . _getRegisteredRowsEntry ( this . uid ) ;
entry . idx = typeof this . index == "number" ? this . index : 0 ;
2021-08-17 21:56:52 +02:00
this . nm . controller . _insertDataRow ( entry , true ) ;
2020-10-08 19:53:17 +02:00
}
2021-08-17 21:56:52 +02:00
else if ( this . nm && this . nm . getParent ( ) )
2020-10-08 19:53:17 +02:00
{
// Server didn't give us our row data
// Delete from internal references
this . nm . controller . deleteRow ( this . uid ) ;
2021-08-17 21:56:52 +02:00
this . nm . controller . _grid . setTotalCount ( this . nm . controller . _grid . getTotalCount ( ) - 1 ) ;
2020-10-09 18:15:17 +02:00
this . nm . controller . _selectionMgr . setTotalCount ( this . nm . controller . _grid . getTotalCount ( ) ) ;
2020-10-08 19:53:17 +02:00
}
this . nm . egw ( ) . dataUnregisterUID ( this . uid , this . nm . _push_add_callback , this ) ;
2020-07-20 21:43:26 +02:00
}
2020-10-22 23:53:59 +02:00
/ * *
* Queue a refresh request until later , when nextmatch is visible
*
* Nextmatch can 't re-draw anything while it' s hidden ( it messes up the sizing when it renders ) so we can ' t actually
* do a refresh right now . Queue it up and when visible again we ' ll update then . If we get too many changes
* queued , we ' ll throw them all away and do a full refresh .
*
* @param _row_ids
* @param _type
* @private
* /
protected _queue_refresh ( _row_ids : string [ ] , _type : string )
{
// Maximum number of requests to queue. 50 chosen arbitrarily just to limit things
const max_queued = 50 ;
if ( this . _queued_refreshes === null )
{
2021-01-13 17:08:53 +01:00
// Already too many or an EDIT came, we'll refresh everything later
2020-10-22 23:53:59 +02:00
return ;
}
2021-08-17 21:56:52 +02:00
// Bind so we can get the queued data when tab is re-activated
2020-10-22 23:53:59 +02:00
let tab = jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode )
. one ( 'show.et2_nextmatch' , this . _queue_refresh_callback . bind ( this ) ) ;
2021-01-13 17:08:53 +01:00
// Edit means refresh everything, so no need to keep queueing
2020-10-22 23:53:59 +02:00
// Too many? Forget it, we'll refresh everything.
2021-01-13 17:08:53 +01:00
if ( this . _queued_refreshes . length >= max_queued || _type == et2_nextmatch . EDIT || ! _type )
2020-10-22 23:53:59 +02:00
{
this . _queued_refreshes = null ;
return ;
}
// Skip if already in array
2021-08-17 21:56:52 +02:00
if ( this . _queued_refreshes . some ( queue = > queue . ids . length === _row_ids . length && queue . ids . every ( ( value , index ) = > value === _row_ids [ index ] ) ) )
2020-10-22 23:53:59 +02:00
{
return ;
}
this . _queued_refreshes . push ( { ids : _row_ids , type : _type } ) ;
}
protected _queue_refresh_callback ( )
{
if ( this . _queued_refreshes === null )
{
// Still bound, but length is 0 - full refresh time
this . _queued_refreshes = [ ] ;
return this . applyFilters ( ) ;
}
let types = { } ;
types [ et2_nextmatch . ADD ] = [ ] ;
types [ et2_nextmatch . UPDATE ] = [ ] ;
types [ et2_nextmatch . UPDATE_IN_PLACE ] = [ ] ;
types [ et2_nextmatch . DELETE ] = [ ] ;
for ( let refresh of this . _queued_refreshes )
{
types [ refresh . type ] = types [ refresh . type ] . concat ( refresh . ids ) ;
}
this . _queued_refreshes = [ ] ;
for ( let type in types )
{
if ( types [ type ] . length > 0 )
{
// Fire each change type once will all changed IDs
this . refresh ( types [ type ] . filter ( ( v , i , a ) = > a . indexOf ( v ) === i ) , type ) ;
}
}
}
2020-08-07 17:19:06 +02:00
/ * *
* Is this nextmatch currently sorted by "modified" date
*
* This is decided by the row_modified options passed from the server and the current sort order
* /
public is_sorted_by_modified ( )
{
let sort = this . getValue ( ) ? . sort || { } ;
return sort && sort . id && sort . id == this . settings . add_on_top_sort_field && sort . asc == false ;
}
2020-07-21 23:32:13 +02:00
private _get_appname ( )
{
let app = '' ;
let list = [ ] ;
list = et2_csvSplit ( this . options . settings . columnselection_pref , 2 , "." ) ;
if ( this . options . settings . columnselection_pref . indexOf ( 'nextmatch' ) == 0 )
{
app = list [ 0 ] . substring ( 'nextmatch' . length + 1 ) ;
}
else
{
app = list [ 0 ] ;
}
return app ;
}
2020-01-24 12:14:08 +01:00
/ * *
* Gets the selection
*
* @return Object { ids : [ UIDs ] , inverted : boolean }
* /
2021-08-17 21:56:52 +02:00
getSelection ( ) : { ids : string [ ] , all : boolean }
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const selected = this . controller && this . controller . _selectionMgr ? this . controller . _selectionMgr . getSelected ( ) : null ;
2020-01-24 12:14:08 +01:00
if ( typeof selected == "object" && selected != null )
{
return selected ;
}
2021-08-17 21:56:52 +02:00
return { ids : [ ] , all : false } ;
2020-01-24 12:14:08 +01:00
}
2020-08-25 22:01:31 +02:00
/ * *
* Log some debug information about internal values
* /
spillYourGuts ( )
{
let guts = function ( controller )
{
2021-08-17 21:56:52 +02:00
console . log ( "Controller:" , controller ) ;
2020-08-25 22:01:31 +02:00
console . log ( "Controller indexMap:" , controller . _indexMap ) ;
console . log ( "Grid:" , controller . _grid ) ;
console . log ( "Selection Manager:" , controller . _selectionMgr ) ;
console . log ( "Selection registered rows:" , controller . _selectionMgr . _registeredRows ) ;
if ( controller && controller . _children . length > 0 )
{
console . groupCollapsed ( "Sub-grids" ) ;
let child_index = 0 ;
for ( let child of controller . _children )
{
console . groupCollapsed ( "Child " + ( ++ child_index ) ) ;
guts ( child ) ;
console . groupEnd ( ) ;
}
console . groupEnd ( )
}
}
console . group ( "Nextmatch internals" ) ;
guts ( this . controller ) ;
console . groupEnd ( ) ;
}
2020-01-24 12:14:08 +01:00
/ * *
* Event handler for when the selection changes
*
* If the onselect attribute was set to a string with javascript code , it will
* be executed "legacy style" . You can get the selected values with getSelection ( ) .
* If the onselect attribute is in app . appname . function style , it will be called
* with the nextmatch and an array of selected row IDs .
*
* The array can be empty , if user cleared the selection .
*
* @param action ActionObject From action system . Ignored .
* @param senders ActionObjectImplemetation From action system . Ignored .
* /
2021-08-17 21:56:52 +02:00
onselect ( action , senders )
2020-01-24 12:14:08 +01:00
{
// Execute the JS code connected to the event handler
2021-08-17 21:56:52 +02:00
if ( typeof this . options . onselect == 'function' )
2020-01-24 12:14:08 +01:00
{
return this . options . onselect . call ( this , this . getSelection ( ) . ids , this ) ;
}
}
2020-01-29 22:29:06 +01:00
/ * *
* Nextmatch needs a namespace
* /
2021-08-17 21:56:52 +02:00
protected _createNamespace ( ) : boolean
2020-01-29 22:29:06 +01:00
{
return true ;
}
2020-01-24 12:14:08 +01:00
/ * *
* Create the dynamic height so nm fills all available space
*
* @returns { undefined }
* /
_getDynheight ( )
{
// Find the parent container, either a tab or the main container
2020-02-11 19:32:50 +01:00
const tab = this . get_tab_info ( ) ;
2020-01-24 12:14:08 +01:00
if ( ! tab )
{
return new et2_dynheight ( this . getInstanceManager ( ) . DOMContainer , this . innerDiv , 100 ) ;
}
2021-08-17 21:56:52 +02:00
else if ( tab && tab . contentDiv )
2020-01-24 12:14:08 +01:00
{
return new et2_dynheight ( tab . contentDiv , this . innerDiv , 100 ) ;
}
return false ;
}
/ * *
* Generates the column caption for the given column widget
*
* @param { et2_widget } _widget
* /
2021-08-17 21:56:52 +02:00
_genColumnCaption ( _widget )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
let result = null ;
2020-01-24 12:14:08 +01:00
if ( typeof _widget . _genColumnCaption == "function" ) return _widget . _genColumnCaption ( ) ;
2020-02-11 19:32:50 +01:00
const self = this ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
_widget . iterateOver ( function ( _widget )
{
2020-02-11 19:32:50 +01:00
const label = self . egw ( ) . lang ( _widget . options . label || _widget . options . empty_label || '' ) ;
2021-08-17 21:56:52 +02:00
if ( ! label ) return ; // skip empty, undefined or null labels
if ( ! result )
2020-01-24 12:14:08 +01:00
{
result = label ;
}
else
{
result += ", " + label ;
}
} , this , et2_INextmatchHeader ) ;
return result ;
}
/ * *
* Generates the column name ( internal ) for the given column widget
* Used in preferences to refer to the columns by name instead of position
*
* See _getColumnCaption ( ) for human fiendly captions
*
* @param { et2_widget } _widget
* /
2021-08-17 21:56:52 +02:00
_getColumnName ( _widget )
2020-01-24 12:14:08 +01:00
{
if ( typeof _widget . _getColumnName == 'function' ) return _widget . _getColumnName ( ) ;
2020-02-11 19:32:50 +01:00
const name = _widget . id ;
const child_names = [ ] ;
const children = _widget . getChildren ( ) ;
2021-08-17 21:56:52 +02:00
for ( let i = 0 ; i < children . length ; i ++ )
{
2020-01-24 12:14:08 +01:00
if ( children [ i ] . id ) child_names . push ( children [ i ] . id ) ;
}
2020-02-11 19:32:50 +01:00
const colName = name + ( name != "" && child_names . length > 0 ? "_" : "" ) + child_names . join ( "_" ) ;
2021-08-17 21:56:52 +02:00
if ( colName == "" )
{
2020-01-24 12:14:08 +01:00
this . egw ( ) . debug ( "info" , "Unable to generate nm column name for " , _widget ) ;
}
return colName ;
}
/ * *
* Retrieve the user ' s preferences for this nextmatch merged with defaults
* Column display , column size , etc .
* /
_getPreferences ( )
{
// Read preference or default for column visibility
2020-02-11 19:32:50 +01:00
let negated = false ;
let columnPreference = "" ;
2020-01-24 12:14:08 +01:00
if ( this . options . settings . default_cols )
{
negated = this . options . settings . default_cols [ 0 ] == "!" ;
columnPreference = negated ? this . options . settings . default_cols . substring ( 1 ) : this . options . settings . default_cols ;
}
if ( this . options . settings . selectcols && this . options . settings . selectcols . length )
{
columnPreference = this . options . settings . selectcols ;
negated = false ;
}
if ( ! this . options . settings . columnselection_pref )
{
// Set preference name so changes are saved
this . options . settings . columnselection_pref = this . options . template ;
}
2020-02-11 19:32:50 +01:00
let app = '' ;
let list = [ ] ;
2021-08-17 21:56:52 +02:00
if ( this . options . settings . columnselection_pref )
{
2020-02-11 19:32:50 +01:00
let pref = { } ;
2020-01-24 12:14:08 +01:00
list = et2_csvSplit ( this . options . settings . columnselection_pref , 2 , "." ) ;
if ( this . options . settings . columnselection_pref . indexOf ( 'nextmatch' ) == 0 )
{
2021-08-17 21:56:52 +02:00
app = list [ 0 ] . substring ( 'nextmatch' . length + 1 ) ;
2020-01-24 12:14:08 +01:00
pref = egw . preference ( this . options . settings . columnselection_pref , app ) ;
}
else
{
app = list [ 0 ] ;
// 'nextmatch-' prefix is there in preference name, but not in setting, so add it in
2021-08-17 21:56:52 +02:00
pref = egw . preference ( "nextmatch-" + this . options . settings . columnselection_pref , app ) ;
2020-01-24 12:14:08 +01:00
}
if ( pref )
{
negated = ( pref [ 0 ] == "!" ) ;
columnPreference = negated ? ( < string > pref ) . substring ( 1 ) : < string > pref ;
}
}
let columnDisplay = [ ] ;
// If no column preference or default set, use all columns
2021-08-17 21:56:52 +02:00
if ( typeof columnPreference == "string" && columnPreference . length == 0 )
2020-01-24 12:14:08 +01:00
{
columnDisplay = [ ] ;
negated = true ;
}
columnDisplay = typeof columnPreference === "string"
2021-08-17 21:56:52 +02:00
? et2_csvSplit ( columnPreference , null , "," ) : columnPreference ;
2020-01-24 12:14:08 +01:00
// Adjusted column sizes
2020-02-11 19:32:50 +01:00
let size = { } ;
2020-01-24 12:14:08 +01:00
if ( this . options . settings . columnselection_pref && app )
{
2020-02-11 19:32:50 +01:00
let size_pref = this . options . settings . columnselection_pref + "-size" ;
2020-01-24 12:14:08 +01:00
// If columnselection pref is missing prefix, add it in
if ( size_pref . indexOf ( 'nextmatch' ) == - 1 )
{
2021-08-17 21:56:52 +02:00
size_pref = 'nextmatch-' + size_pref ;
2020-01-24 12:14:08 +01:00
}
size = this . egw ( ) . preference ( size_pref , app ) ;
}
if ( ! size ) size = { } ;
// Column order
2020-02-11 19:32:50 +01:00
const order = { } ;
for ( let i = 0 ; i < columnDisplay . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
order [ columnDisplay [ i ] ] = i ;
}
return {
visible : columnDisplay ,
visible_negated : negated ,
negated : negated ,
size : size ,
order : order
} ;
}
/ * *
* Apply stored user preferences to discovered columns
*
* @param { array } _row
* @param { array } _colData
* /
2021-08-17 21:56:52 +02:00
_applyUserPreferences ( _row , _colData )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const prefs = this . _getPreferences ( ) ;
const columnDisplay = prefs . visible ;
const size = prefs . size ;
const negated = prefs . visible_negated ;
const order = prefs . order ;
let colName = '' ;
2020-01-24 12:14:08 +01:00
// Add in display preferences
if ( columnDisplay && columnDisplay . length > 0 )
{
RowLoop :
2021-08-17 21:56:52 +02:00
for ( let i = 0 ; i < _row . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
colName = '' ;
if ( _row [ i ] . disabled === true )
{
_colData [ i ] . visible = false ;
continue ;
}
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
// Customfields needs special processing
if ( _row [ i ] . widget . instanceOf ( et2_nextmatch_customfields ) )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
// Find cf field
for ( var j = 0 ; j < columnDisplay . length ; j ++ )
{
if ( columnDisplay [ j ] . indexOf ( _row [ i ] . widget . id ) == 0 )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
_row [ i ] . widget . options . fields = { } ;
for ( let k = j ; k < columnDisplay . length ; k ++ )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( columnDisplay [ k ] . indexOf ( _row [ i ] . widget . prefix ) == 0 )
{
_row [ i ] . widget . options . fields [ columnDisplay [ k ] . substr ( 1 ) ] = true ;
}
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
// Resets field visibility too
_row [ i ] . widget . _getColumnName ( ) ;
_colData [ i ] . visible = ! ( negated || jQuery . isEmptyObject ( _row [ i ] . widget . options . fields ) ) ;
break ;
2020-01-24 12:14:08 +01:00
}
}
2021-08-17 21:56:52 +02:00
// Disable if there are no custom fields
if ( jQuery . isEmptyObject ( _row [ i ] . widget . customfields ) )
{
_colData [ i ] . visible = false ;
continue ;
}
colName = _row [ i ] . widget . id ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
else
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
colName = this . _getColumnName ( _row [ i ] . widget ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
if ( ! negated )
2020-03-23 17:05:46 +01:00
{
2021-08-17 21:56:52 +02:00
_colData [ i ] . order = typeof order [ colName ] === 'undefined' ? i : order [ colName ] ;
2020-03-23 17:05:46 +01:00
}
2021-08-17 21:56:52 +02:00
if ( ! colName ) continue ;
_colData [ i ] . visible = negated ;
let stop = false ;
for ( var j = 0 ; j < columnDisplay . length && ! stop ; j ++ )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( columnDisplay [ j ] == colName )
{
_colData [ i ] . visible = ! negated ;
stop = true ;
}
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
if ( size [ colName ] )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
// Make sure percentages stay percentages, and forget any preference otherwise
if ( _colData [ i ] . width . charAt ( _colData [ i ] . width . length - 1 ) == "%" )
{
_colData [ i ] . width = typeof size [ colName ] == 'string' && size [ colName ] . charAt ( size [ colName ] . length - 1 ) == "%" ? size [ colName ] : _colData [ i ] . width ;
}
else
{
_colData [ i ] . width = parseInt ( size [ colName ] ) + 'px' ;
}
2020-01-24 12:14:08 +01:00
}
}
}
2021-08-17 21:56:52 +02:00
_colData . sort ( function ( a , b )
{
2020-01-24 12:14:08 +01:00
return a . order - b . order ;
} ) ;
2021-08-17 21:56:52 +02:00
_row . sort ( function ( a , b )
{
2020-01-24 12:14:08 +01:00
if ( typeof a . colData !== 'undefined' && typeof b . colData !== 'undefined' )
{
return a . colData . order - b . colData . order ;
}
2021-08-17 21:56:52 +02:00
else if ( typeof a . order !== 'undefined' && typeof b . order !== 'undefined' )
2020-01-24 12:14:08 +01:00
{
return a . order - b . order ;
}
} ) ;
}
/ * *
* Take current column display settings and store them in this . egw ( ) . preferences
* for next time
* /
_updateUserPreferences ( )
{
2020-02-11 19:32:50 +01:00
const colMgr = this . dataview . getColumnMgr ( ) ;
let app = "" ;
2021-08-17 21:56:52 +02:00
if ( ! this . options . settings . columnselection_pref )
{
2020-01-24 12:14:08 +01:00
this . options . settings . columnselection_pref = this . options . template ;
}
2020-02-11 19:32:50 +01:00
const visibility = colMgr . getColumnVisibilitySet ( ) ;
const colDisplay = [ ] ;
const colSize = { } ;
const custom_fields = [ ] ;
2020-01-24 12:14:08 +01:00
// visibility is indexed by internal ID, widget is referenced by position, preference needs name
for ( var i = 0 ; i < colMgr . columns . length ; i ++ )
{
// @ts-ignore
2020-02-11 19:32:50 +01:00
const widget = this . columns [ i ] . widget ;
let colName = this . _getColumnName ( widget ) ;
2021-08-17 21:56:52 +02:00
if ( colName )
{
2020-01-24 12:14:08 +01:00
// Server side wants each cf listed as a seperate column
if ( widget . instanceOf ( et2_nextmatch_customfields ) )
{
// Just the ID for server side, not the whole nm name - some apps use it to skip custom fields
colName = widget . id ;
2021-08-17 21:56:52 +02:00
for ( let name in widget . options . fields )
{
if ( widget . options . fields [ name ] ) custom_fields . push ( et2_nextmatch_customfields . PREFIX + name ) ;
2020-01-24 12:14:08 +01:00
}
}
if ( visibility [ colMgr . columns [ i ] . id ] . visible ) colDisplay . push ( colName ) ;
// When saving sizes, only save columns with explicit values, preserving relative vs fixed
// Others will be left to flex if width changes or more columns are added
if ( colMgr . columns [ i ] . relativeWidth )
{
colSize [ colName ] = ( colMgr . columns [ i ] . relativeWidth * 100 ) + "%" ;
}
2021-08-17 21:56:52 +02:00
else if ( colMgr . columns [ i ] . fixedWidth )
2020-01-24 12:14:08 +01:00
{
colSize [ colName ] = colMgr . columns [ i ] . fixedWidth ;
}
2021-08-17 21:56:52 +02:00
}
else if ( colMgr . columns [ i ] . fixedWidth || colMgr . columns [ i ] . relativeWidth )
{
2020-01-24 12:14:08 +01:00
this . egw ( ) . debug ( "info" , "Could not save column width - no name" , colMgr . columns [ i ] . id ) ;
}
}
2020-02-11 19:32:50 +01:00
const list = et2_csvSplit ( this . options . settings . columnselection_pref , 2 , "." ) ;
let pref = this . options . settings . columnselection_pref ;
2020-01-24 12:14:08 +01:00
if ( pref . indexOf ( 'nextmatch' ) == 0 )
{
2021-08-17 21:56:52 +02:00
app = list [ 0 ] . substring ( 'nextmatch' . length + 1 ) ;
2020-01-24 12:14:08 +01:00
}
else
{
app = list [ 0 ] ;
// 'nextmatch-' prefix is there in preference name, but not in setting, so add it in
2021-08-17 21:56:52 +02:00
pref = "nextmatch-" + this . options . settings . columnselection_pref ;
2020-01-24 12:14:08 +01:00
}
// Server side wants each cf listed as a seperate column
jQuery . merge ( colDisplay , custom_fields ) ;
// Update query value, so data source can use visible columns to exclude expensive sub-queries
2020-02-11 19:32:50 +01:00
const oldCols = this . activeFilters . selectcols ? this . activeFilters . selectcols : [ ] ;
2020-01-24 12:14:08 +01:00
2021-03-22 18:09:41 +01:00
this . activeFilters . selectcols = this . sortedColumnsList . length > 0 ? this . sortedColumnsList : colDisplay ;
2020-01-24 12:14:08 +01:00
// We don't need to re-query if they've removed a column
2020-02-11 19:32:50 +01:00
const changed = [ ] ;
2020-01-24 12:14:08 +01:00
ColLoop :
2021-08-17 21:56:52 +02:00
for ( var i = 0 ; i < colDisplay . length ; i ++ )
{
for ( let j = 0 ; j < oldCols . length ; j ++ )
{
if ( colDisplay [ i ] == oldCols [ j ] ) continue ColLoop ;
}
changed . push ( colDisplay [ i ] ) ;
2020-01-24 12:14:08 +01:00
}
// If a custom field column was added, throw away cache to deal with
// efficient apps that didn't send all custom fields in the first request
2020-02-11 19:32:50 +01:00
const cf_added = jQuery ( changed ) . filter ( jQuery ( custom_fields ) ) . length > 0 ;
2020-01-24 12:14:08 +01:00
2020-04-09 20:39:16 +02:00
// Save visible columns and sizes if selectcols is not emtpy (an empty selectcols actually deletes the prefrence)
if ( ! jQuery . isEmptyObject ( this . activeFilters . selectcols ) )
{
// 'nextmatch-' prefix is there in preference name, but not in setting, so add it in
this . egw ( ) . set_preference ( app , pref , this . activeFilters . selectcols . join ( "," ) ,
// Use callback after the preference gets set to trigger refresh, in case app
// isn't looking at selectcols and just uses preference
2021-08-17 21:56:52 +02:00
cf_added ? jQuery . proxy ( function ( )
{
if ( this . controller ) this . controller . update ( true ) ;
} , this ) : null
2020-04-09 20:39:16 +02:00
) ;
// Save adjusted column sizes and inform user about it
2021-08-17 21:56:52 +02:00
this . egw ( ) . set_preference ( app , pref + "-size" , colSize ) ;
2020-04-09 20:39:16 +02:00
this . egw ( ) . message ( this . egw ( ) . lang ( "Saved column sizes to preferences." ) ) ;
}
2021-08-17 21:56:52 +02:00
this . egw ( ) . set_preference ( app , pref + "-size" , colSize ) ;
2020-01-24 12:14:08 +01:00
// No significant change (just normal columns shown) and no need to wait,
// but the grid still needs to be redrawn if a custom field was removed because
// the cell content changed. This is a cheaper refresh than the callback,
// this.controller.update(true)
if ( ( changed . length || custom_fields . length ) && ! cf_added ) this . applyFilters ( ) ;
}
2021-08-17 21:56:52 +02:00
_parseHeaderRow ( _row , _colData )
2020-01-24 12:14:08 +01:00
{
// Make sure there's a widget - cols disabled in template can be missing them, and the header really likes to have a widget
2021-08-17 21:56:52 +02:00
for ( var x = 0 ; x < _row . length ; x ++ )
2020-01-24 12:14:08 +01:00
{
if ( ! _row [ x ] . widget )
{
_row [ x ] . widget = et2_createWidget ( "label" , { } ) ;
}
}
// Get column display preference
this . _applyUserPreferences ( _row , _colData ) ;
// Go over the header row and create the column entries
this . columns = new Array ( _row . length ) ;
2020-02-11 19:32:50 +01:00
const columnData = new Array ( _row . length ) ;
2020-01-24 12:14:08 +01:00
// No action columns in et2
2020-02-11 19:32:50 +01:00
let remove_action_index = null ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
for ( var x = 0 ; x < _row . length ; x ++ )
2020-01-24 12:14:08 +01:00
{
this . columns [ x ] = jQuery . extend ( {
"order" : _colData [ x ] && typeof _colData [ x ] . order !== 'undefined' ? _colData [ x ] . order : x ,
"widget" : _row [ x ] . widget
2021-08-17 21:56:52 +02:00
} , _colData [ x ] ) ;
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
let visibility = ( ! _colData [ x ] || _colData [ x ] . visible ) ?
2021-08-17 21:56:52 +02:00
et2_dataview_column . ET2_COL_VISIBILITY_VISIBLE :
et2_dataview_column . ET2_COL_VISIBILITY_INVISIBLE ;
if ( _colData [ x ] . disabled && _colData [ x ] . disabled !== '' &&
2020-01-24 12:14:08 +01:00
this . getArrayMgr ( "content" ) . parseBoolExpression ( _colData [ x ] . disabled ) )
{
2020-01-31 21:07:27 +01:00
visibility = et2_dataview_column . ET2_COL_VISIBILITY_DISABLED ;
2020-06-09 21:56:52 +02:00
this . columns [ x ] . visible = false ;
2020-01-24 12:14:08 +01:00
}
columnData [ x ] = {
"id" : "col_" + x ,
// @ts-ignore
"order" : this . columns [ x ] . order ,
"caption" : this . _genColumnCaption ( _row [ x ] . widget ) ,
"visibility" : visibility ,
"width" : _colData [ x ] ? _colData [ x ] . width : 0
} ;
if ( _colData [ x ] . width === 'auto' )
{
// Column manager does not understand 'auto', which grid widget
// uses if width is not set
columnData [ x ] . width = '100%' ;
}
if ( _colData [ x ] . minWidth )
{
columnData [ x ] . minWidth = _colData [ x ] . minWidth ;
}
if ( _colData [ x ] . maxWidth )
{
columnData [ x ] . maxWidth = _colData [ x ] . maxWidth ;
}
// No action columns in et2
2020-02-11 19:32:50 +01:00
const colName = this . _getColumnName ( _row [ x ] . widget ) ;
2020-01-24 12:14:08 +01:00
if ( colName == 'actions' || colName == 'legacy_actions' || colName == 'legacy_actions_check_all' )
{
remove_action_index = x ;
}
2021-08-17 21:56:52 +02:00
else if ( ! colName )
2020-01-24 12:14:08 +01:00
{
// Unnamed column cannot be toggled or saved
2020-04-01 19:46:05 +02:00
columnData [ x ] . visibility = et2_dataview_column . ET2_COL_VISIBILITY_ALWAYS_NOSELECT ;
this . columns [ x ] . visible = true ;
2020-01-24 12:14:08 +01:00
}
}
// Remove action column
if ( remove_action_index != null )
{
2021-08-17 21:56:52 +02:00
this . columns . splice ( remove_action_index , remove_action_index ) ;
columnData . splice ( remove_action_index , remove_action_index ) ;
_colData . splice ( remove_action_index , remove_action_index ) ;
2020-01-24 12:14:08 +01:00
}
// Create the column manager and update the grid container
2020-01-30 00:05:01 +01:00
this . dataview . setColumns ( columnData ) ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
for ( var x = 0 ; x < _row . length ; x ++ )
2020-01-24 12:14:08 +01:00
{
// Append the widget to this container
this . addChild ( _row [ x ] . widget ) ;
}
// Create the nextmatch row provider
this . rowProvider = new et2_nextmatch_rowProvider (
this . dataview . rowProvider , this . _getSubgrid , this ) ;
// Register handler to update preferences when column properties are changed
2020-02-11 19:32:50 +01:00
const self = this ;
2021-08-17 21:56:52 +02:00
this . dataview . onUpdateColumns = function ( )
{
2020-01-24 12:14:08 +01:00
// Use apply to make sure context is there
self . _updateUserPreferences . apply ( self ) ;
// Allow column widgets a chance to resize
2021-08-17 21:56:52 +02:00
self . iterateOver ( function ( widget )
{
widget . resize ( ) ;
} , self , et2_IResizeable ) ;
2020-01-24 12:14:08 +01:00
} ;
// Register handler for column selection popup, or disable
if ( this . selectPopup )
{
this . selectPopup . remove ( ) ;
this . selectPopup = null ;
}
if ( this . options . settings . no_columnselection )
{
2021-08-17 21:56:52 +02:00
this . dataview . selectColumnsClick = function ( )
{
return false ;
} ;
jQuery ( 'span.selectcols' , this . dataview . headTr ) . hide ( ) ;
2020-01-24 12:14:08 +01:00
}
else
{
2021-08-17 21:56:52 +02:00
jQuery ( 'span.selectcols' , this . dataview . headTr ) . show ( ) ;
this . dataview . selectColumnsClick = function ( event )
{
2020-01-24 12:14:08 +01:00
self . _selectColumnsClick ( event ) ;
} ;
}
}
2021-08-17 21:56:52 +02:00
_parseDataRow ( _row , _rowData , _colData )
2020-01-24 12:14:08 +01:00
{
2020-03-11 17:56:51 +01:00
const columnWidgets = [ ] ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
_row . sort ( function ( a , b )
{
return a . colData . order - b . colData . order ;
} ) ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
for ( let x = 0 ; x < this . columns . length ; x ++ )
2020-01-24 12:14:08 +01:00
{
2020-03-11 17:56:51 +01:00
if ( ! this . columns [ x ] . visible )
{
continue ;
}
if ( typeof _row [ x ] != "undefined" && _row [ x ] . widget )
2020-01-24 12:14:08 +01:00
{
columnWidgets [ x ] = _row [ x ] . widget ;
// Append the widget to this container
this . addChild ( _row [ x ] . widget ) ;
}
else
{
columnWidgets [ x ] = _row [ x ] . widget ;
}
// Pass along column alignment
if ( _row [ x ] . align && columnWidgets [ x ] )
{
columnWidgets [ x ] . align = _row [ x ] . align ;
}
}
this . rowProvider . setDataRowTemplate ( columnWidgets , _rowData , this ) ;
// Create the grid controller
this . controller = new et2_nextmatch_controller (
null ,
this . egw ( ) ,
this . getInstanceManager ( ) . etemplate_exec_id ,
this ,
null ,
this . dataview . grid ,
this . rowProvider ,
this . options . settings . action_links ,
null ,
this . options . actions
) ;
2020-10-15 22:56:23 +02:00
this . controller . setFilters ( this . activeFilters )
2020-01-24 12:14:08 +01:00
// Need to trigger empty row the first time
if ( total == 0 ) this . controller . _emptyRow ( ) ;
// Set data cache prefix to either provided custom or auto
if ( ! this . options . settings . dataStorePrefix && this . options . settings . get_rows )
{
// Use jsapi data module to update
2020-02-11 19:32:50 +01:00
let list = this . options . settings . get_rows . split ( '.' , 2 ) ;
2021-08-17 21:56:52 +02:00
if ( list . length < 2 ) list = this . options . settings . get_rows . split ( '_' ) ; // support "app_something::method"
2020-01-24 12:14:08 +01:00
this . options . settings . dataStorePrefix = list [ 0 ] ;
}
this . controller . setPrefix ( this . options . settings . dataStorePrefix ) ;
// Set the view
this . controller . _view = this . view ;
// Load the initial order
/ * t h i s . c o n t r o l l e r . l o a d I n i t i a l O r d e r ( t h i s . _ g e t I n i t i a l O r d e r (
this . options . settings . rows , this . options . settings . row_id
) ) ; * /
// Set the initial row count
var total = typeof this . options . settings . total != "undefined" ?
2021-08-17 21:56:52 +02:00
this . options.settings.total : 0 ;
2020-01-24 12:14:08 +01:00
// This triggers an invalidate, which updates the grid
this . dataview . grid . setTotalCount ( total ) ;
// Insert any data sent from server, so invalidate finds data already
if ( this . options . settings . rows && this . options . settings . num_rows )
{
this . controller . loadInitialData (
this . options . settings . dataStorePrefix ,
this . options . settings . row_id ,
this . options . settings . rows
) ;
// Remove, to prevent duplication
delete this . options . settings . rows ;
}
}
2021-08-17 21:56:52 +02:00
_parseGrid ( _grid )
2020-01-24 12:14:08 +01:00
{
// Search the rows for a header-row - if one is found, parse it
2021-08-17 21:56:52 +02:00
for ( let y = 0 ; y < _grid . rowData . length ; y ++ )
2020-01-24 12:14:08 +01:00
{
// Parse the first row as a header, need header to parse the data rows
2021-08-17 21:56:52 +02:00
if ( _grid . rowData [ y ] [ "class" ] == "th" || y == 0 )
2020-01-24 12:14:08 +01:00
{
this . _parseHeaderRow ( _grid . cells [ y ] , _grid . colData ) ;
}
else
{
this . _parseDataRow ( _grid . cells [ y ] , _grid . rowData [ y ] ,
2021-08-17 21:56:52 +02:00
_grid . colData ) ;
2020-01-24 12:14:08 +01:00
}
}
this . dataview . table . resize ( ) ;
}
2021-08-17 21:56:52 +02:00
_getSubgrid ( _row , _data , _controller )
2020-01-24 12:14:08 +01:00
{
// Fetch the id of the element described by _data, this will be the
// parent_id of the elements in the subgrid
2020-02-11 19:32:50 +01:00
const rowId = _data . content [ this . options . settings . row_id ] ;
2020-01-24 12:14:08 +01:00
// Create a new grid with the row as parent and the dataview grid as
// parent grid
2020-02-11 19:32:50 +01:00
const grid = new et2_dataview_grid ( _row , this . dataview . grid ) ;
2020-01-24 12:14:08 +01:00
// Create a new controller for the grid
2020-02-11 19:32:50 +01:00
const controller = new et2_nextmatch_controller (
_controller ,
this . egw ( ) ,
this . getInstanceManager ( ) . etemplate_exec_id ,
this ,
rowId ,
grid ,
this . rowProvider ,
this . options . settings . action_links ,
_controller . getObjectManager ( )
2020-01-24 12:14:08 +01:00
) ;
controller . update ( ) ;
// Register inside the destruction callback of the grid
2021-08-17 21:56:52 +02:00
grid . setDestroyCallback ( function ( )
{
2020-01-31 21:07:27 +01:00
controller . destroy ( ) ;
2020-01-24 12:14:08 +01:00
} ) ;
return grid ;
}
2021-08-17 21:56:52 +02:00
_getInitialOrder ( _rows , _rowId )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const _order = [ ] ;
2020-01-24 12:14:08 +01:00
// Get the length of the non-numerical rows arra
2020-02-11 19:32:50 +01:00
let len = 0 ;
2021-08-17 21:56:52 +02:00
for ( let key in _rows )
{
if ( ! isNaN ( parseInt ( key ) ) && parseInt ( key ) > len )
2020-01-24 12:14:08 +01:00
len = parseInt ( key ) ;
}
// Iterate over the rows
2021-08-17 21:56:52 +02:00
for ( let i = 0 ; i < len ; i ++ )
2020-01-24 12:14:08 +01:00
{
// Get the uid from the data
2020-02-11 19:32:50 +01:00
const uid = this . egw ( ) . app_name ( ) + '::' + _rows [ i ] [ _rowId ] ;
2020-01-24 12:14:08 +01:00
// Store the data for that uid
this . egw ( ) . dataStoreUID ( uid , _rows [ i ] ) ;
// Push the uid onto the order array
_order . push ( uid ) ;
}
return _order ;
}
2021-08-17 21:56:52 +02:00
_selectColumnsClick ( e )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const self = this ;
const columnMgr = this . dataview . getColumnMgr ( ) ;
2020-01-24 12:14:08 +01:00
// ID for faking letter selection in column selection
2020-02-11 19:32:50 +01:00
const LETTERS = '~search_letter~' ;
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
const columns = { } ;
const columns_selected = [ ] ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
for ( var i = 0 ; i < columnMgr . columns . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
var col = columnMgr . columns [ i ] ;
2020-02-11 19:32:50 +01:00
const widget = this . columns [ i ] . widget ;
2020-01-24 12:14:08 +01:00
2020-02-12 19:16:34 +01:00
if ( col . visibility == et2_dataview_column . ET2_COL_VISIBILITY_DISABLED ||
col . visibility == et2_dataview_column . ET2_COL_VISIBILITY_ALWAYS_NOSELECT )
{
continue ;
}
if ( col . caption )
2020-01-24 12:14:08 +01:00
{
columns [ col . id ] = col . caption ;
2020-02-11 00:00:14 +01:00
if ( col . visibility == et2_dataview_column . ET2_COL_VISIBILITY_VISIBLE ) columns_selected . push ( col . id ) ;
2020-01-24 12:14:08 +01:00
}
// Custom fields get listed separately
if ( widget . instanceOf ( et2_nextmatch_customfields ) )
{
if ( jQuery . isEmptyObject ( ( < et2_nextmatch_customfields > < unknown > widget ) . customfields ) )
{
// No customfields defined, don't show column
2021-08-17 21:56:52 +02:00
delete ( columns [ col . id ] ) ;
2020-01-24 12:14:08 +01:00
continue ;
}
for ( var field_name in ( < et2_nextmatch_customfields > < unknown > widget ) . customfields )
{
2021-08-17 21:56:52 +02:00
columns [ et2_nextmatch_customfields . PREFIX + field_name ] = " - " +
2020-01-24 12:14:08 +01:00
( < et2_nextmatch_customfields > < unknown > widget ) . customfields [ field_name ] . label ;
2021-08-17 21:56:52 +02:00
if ( widget . options . fields [ field_name ] ) columns_selected . push ( et2_customfields_list . PREFIX + field_name ) ;
2020-01-24 12:14:08 +01:00
}
}
}
// Letter search
if ( this . options . settings . lettersearch )
{
columns [ LETTERS ] = egw . lang ( 'Search letter' ) ;
if ( this . header . lettersearch . is ( ':visible' ) ) columns_selected . push ( LETTERS ) ;
}
// Build the popup
if ( ! this . selectPopup )
{
2021-08-17 21:56:52 +02:00
const select = < et2_selectbox > et2_createWidget ( "select" , {
2020-01-24 12:14:08 +01:00
multiple : true ,
rows : 8 ,
2020-02-11 19:32:50 +01:00
empty_label : this.egw ( ) . lang ( "select columns" ) ,
2020-01-24 12:14:08 +01:00
selected_first : false ,
2020-02-11 19:32:50 +01:00
value_class : "selcolumn_sortable_"
2020-01-24 12:14:08 +01:00
} , this ) ;
select . set_select_options ( columns ) ;
select . set_value ( columns_selected ) ;
2020-08-05 19:21:18 +02:00
let autoRefresh ;
if ( ! this . options . disable_autorefresh )
{
2021-08-17 21:56:52 +02:00
autoRefresh = < et2_selectbox > et2_createWidget ( "select" , {
2020-08-05 19:21:18 +02:00
"empty_label" : "Refresh"
} , this ) ;
autoRefresh . set_id ( "nm_autorefresh" ) ;
autoRefresh . set_select_options ( {
2021-08-17 21:56:52 +02:00
// Cause [unknown] problems with mail
30 : "30 seconds" ,
//60: "1 Minute",
180 : "3 Minutes" ,
300 : "5 Minutes" ,
900 : "15 Minutes" ,
1800 : "30 Minutes"
} ) ;
2020-08-05 19:21:18 +02:00
autoRefresh . set_value ( this . _get_autorefresh ( ) ) ;
autoRefresh . set_statustext ( egw . lang ( "Automatically refresh list" ) ) ;
}
2021-08-17 21:56:52 +02:00
const defaultCheck = < et2_selectbox > et2_createWidget ( "select" , { "empty_label" : "Preference" } , this ) ;
2020-01-24 12:14:08 +01:00
defaultCheck . set_id ( 'nm_col_preference' ) ;
defaultCheck . set_select_options ( {
2021-08-17 21:56:52 +02:00
'default' : { label : 'Default' , title : 'Set these columns as the default' } ,
'reset' : { label : 'Reset' , title : "Reset all user's column preferences" } ,
'force' : { label : 'Force' , title : 'Force column preference so users cannot change it' }
2020-01-24 12:14:08 +01:00
} ) ;
2021-08-17 21:56:52 +02:00
defaultCheck . set_value ( this . options . settings . columns_forced ? 'force' : '' ) ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
const okButton = < et2_button > et2_createWidget ( "buttononly" , {
"background_image" : true ,
image : "check"
} , this ) ;
2020-01-24 12:14:08 +01:00
okButton . set_label ( this . egw ( ) . lang ( "ok" ) ) ;
2021-08-17 21:56:52 +02:00
okButton . onclick = function ( )
{
2020-01-24 12:14:08 +01:00
// Update visibility
2020-02-11 19:32:50 +01:00
const visibility = { } ;
2021-08-17 21:56:52 +02:00
for ( var i = 0 ; i < columnMgr . columns . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const col = columnMgr . columns [ i ] ;
2020-02-11 00:00:14 +01:00
if ( col . caption && col . visibility !== et2_dataview_column . ET2_COL_VISIBILITY_ALWAYS_NOSELECT &&
2021-08-17 21:56:52 +02:00
col . visibility !== et2_dataview_column . ET2_COL_VISIBILITY_DISABLED )
2020-01-24 12:14:08 +01:00
{
visibility [ col . id ] = { visible : false } ;
}
}
2020-02-11 19:32:50 +01:00
const value = select . getValue ( ) ;
2020-01-24 12:14:08 +01:00
// Update & remove letter filter
if ( self . header . lettersearch )
{
var show_letters = true ;
if ( value . indexOf ( LETTERS ) >= 0 )
{
2021-08-17 21:56:52 +02:00
value . splice ( value . indexOf ( LETTERS ) , 1 ) ;
2020-01-24 12:14:08 +01:00
}
else
{
show_letters = false ;
}
self . _set_lettersearch ( show_letters ) ;
}
2020-02-11 19:32:50 +01:00
let column = 0 ;
2020-01-24 12:14:08 +01:00
for ( var i = 0 ; i < value . length ; i ++ )
{
// Handle skipped columns
2021-08-17 21:56:52 +02:00
while ( value [ i ] != "col_" + column && column < columnMgr . columns . length )
2020-01-24 12:14:08 +01:00
{
column ++ ;
}
if ( visibility [ value [ i ] ] )
{
visibility [ value [ i ] ] . visible = true ;
}
// Custom fields are listed seperately in column list, but are only 1 column
2021-08-17 21:56:52 +02:00
if ( self . columns [ column ] && self . columns [ column ] . widget . instanceOf ( et2_nextmatch_customfields ) )
{
2020-02-11 19:32:50 +01:00
const cf = self . columns [ column ] . widget . options . customfields ;
const visible = self . columns [ column ] . widget . options . fields ;
2020-01-24 12:14:08 +01:00
// Turn off all custom fields
for ( var field_name in cf )
{
visible [ field_name ] = false ;
}
// Turn on selected custom fields - start from 0 in case they're not in order
2020-02-11 19:32:50 +01:00
for ( let j = 0 ; j < value . length ; j ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-12 19:32:29 +01:00
if ( value [ j ] . indexOf ( et2_customfields_list . PREFIX ) != 0 ) continue ;
2020-01-24 12:14:08 +01:00
visible [ value [ j ] . substring ( 1 ) ] = true ;
i ++ ;
}
( < et2_customfields_list > < unknown > self . columns [ column ] . widget ) . set_visible ( visible ) ;
}
}
columnMgr . setColumnVisibilitySet ( visibility ) ;
this . sortedColumnsList = [ ] ;
2021-08-17 21:56:52 +02:00
jQuery ( select . getDOMNode ( ) ) . find ( 'li[class^="selcolumn_sortable_"]' ) . each ( function ( i , v )
{
2020-02-11 19:32:50 +01:00
const data_id = v . getAttribute ( 'data-value' ) ;
const value = select . getValue ( ) ;
2021-08-17 21:56:52 +02:00
if ( data_id . match ( /^col_/ ) && value . indexOf ( data_id ) != - 1 )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const col_id = data_id . replace ( 'col_' , '' ) ;
const col_widget = self . columns [ col_id ] . widget ;
2021-08-17 21:56:52 +02:00
if ( col_widget . customfields )
2020-01-24 12:14:08 +01:00
{
self . sortedColumnsList . push ( col_widget . id ) ;
2020-02-11 19:32:50 +01:00
for ( let field_name in col_widget . customfields )
2020-01-24 12:14:08 +01:00
{
if ( jQuery . isEmptyObject ( col_widget . options . fields ) || col_widget . options . fields [ field_name ] == true )
{
2020-02-12 19:32:29 +01:00
self . sortedColumnsList . push ( et2_customfields_list . PREFIX + field_name ) ;
2020-01-24 12:14:08 +01:00
}
}
}
else
{
self . sortedColumnsList . push ( self . _getColumnName ( col_widget ) ) ;
}
}
} ) ;
// Hide popup
self . selectPopup . toggle ( ) ;
self . dataview . updateColumns ( ) ;
// Auto refresh
2020-08-05 19:21:18 +02:00
self . _set_autorefresh ( autoRefresh ? autoRefresh . get_value ( ) : 0 ) ;
2020-01-24 12:14:08 +01:00
// Set default or clear forced
if ( show_letters )
{
self . activeFilters . selectcols . push ( 'lettersearch' ) ;
}
self . getInstanceManager ( ) . submit ( ) ;
self . selectPopup = null ;
} ;
2021-08-17 21:56:52 +02:00
const cancelButton = < et2_button > et2_createWidget ( "buttononly" , {
"background_image" : true ,
image : "cancel"
} , this ) ;
2020-01-24 12:14:08 +01:00
cancelButton . set_label ( this . egw ( ) . lang ( "cancel" ) ) ;
2021-08-17 21:56:52 +02:00
cancelButton . onclick = function ( )
{
2020-01-24 12:14:08 +01:00
self . selectPopup . toggle ( ) ;
self . selectPopup = null ;
} ;
2020-02-11 19:32:50 +01:00
const $select = jQuery ( select . getDOMNode ( ) ) ;
2021-08-17 21:56:52 +02:00
let sortablejs = Sortable . create ( select . getDOMNode ( ) . getElementsByClassName ( 'ui-multiselect-checkboxes' ) [ 0 ] , {
ghostClass : 'ui-fav-sortable-placeholder' ,
draggable : 'li[class^="selcolumn_sortable_col"]' ,
filter : 'li[class^="selcolumn_sortable_#"]' ,
direction : 'vertical' ,
delay : 25 ,
2020-01-24 12:14:08 +01:00
} ) ;
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
$select . disableSelection ( ) ;
2021-08-17 21:56:52 +02:00
$select . find ( 'li[class^="selcolumn_sortable_"]' ) . each ( function ( i , v )
{
2020-01-24 12:14:08 +01:00
// @ts-ignore
2021-08-17 21:56:52 +02:00
jQuery ( v ) . attr ( 'data-value' , ( jQuery ( v ) . find ( 'input' ) [ 0 ] . value ) )
2020-01-24 12:14:08 +01:00
} ) ;
2020-02-11 19:32:50 +01:00
const $footerWrap = jQuery ( document . createElement ( "div" ) )
. addClass ( 'dialogFooterToolbar' )
. append ( okButton . getDOMNode ( ) )
. append ( cancelButton . getDOMNode ( ) ) ;
2020-01-24 12:14:08 +01:00
this . selectPopup = jQuery ( document . createElement ( "div" ) )
. addClass ( "colselection ui-dialog ui-widget-content" )
. append ( select . getDOMNode ( ) )
. append ( $footerWrap )
. appendTo ( this . innerDiv ) ;
// Add autorefresh
2020-08-05 19:21:18 +02:00
if ( autoRefresh )
{
$footerWrap . append ( autoRefresh . getSurroundings ( ) . getDOMNode ( autoRefresh . getDOMNode ( ) ) ) ;
}
2020-01-24 12:14:08 +01:00
// Add default checkbox for admins
2020-02-11 19:32:50 +01:00
const apps = this . egw ( ) . user ( 'apps' ) ;
2020-01-24 12:14:08 +01:00
if ( apps [ 'admin' ] )
{
$footerWrap . append ( defaultCheck . getSurroundings ( ) . getDOMNode ( defaultCheck . getDOMNode ( ) ) ) ;
}
}
else
{
this . selectPopup . toggle ( ) ;
}
2020-02-11 19:32:50 +01:00
const t_position = jQuery ( e . target ) . position ( ) ;
const s_position = this . div . position ( ) ;
const max_height = this . getDOMNode ( ) . getElementsByClassName ( 'egwGridView_outer' ) [ 0 ] [ 'tBodies' ] [ 0 ] . clientHeight -
( 2 * this . selectPopup . find ( '.dialogFooterToolbar' ) . height ( ) ) ;
2021-08-17 21:56:52 +02:00
this . selectPopup . find ( '.ui-multiselect-checkboxes' ) . css ( 'max-height' , max_height ) ;
2020-01-24 12:14:08 +01:00
this . selectPopup . css ( "top" , t_position . top )
. css ( "left" , s_position . left + this . div . width ( ) - this . selectPopup . width ( ) ) ;
}
2021-03-24 17:21:02 +01:00
/ * *
* Get the currently displayed columns
* Each customfield is listed separately
* /
get_columns ( )
{
const colMgr = this . dataview . getColumnMgr ( ) ;
const visibility = colMgr . getColumnVisibilitySet ( ) ;
const colDisplay = [ ] ;
const custom_fields = [ ] ;
// visibility is indexed by internal ID, widget is referenced by position, preference needs name
for ( var i = 0 ; i < colMgr . columns . length ; i ++ )
{
// @ts-ignore
const widget = this . columns [ i ] . widget ;
let colName = this . _getColumnName ( widget ) ;
if ( colName )
{
// Server side wants each cf listed as a seperate column
if ( widget . instanceOf ( et2_nextmatch_customfields ) )
{
// Just the ID for server side, not the whole nm name - some apps use it to skip custom fields
colName = widget . id ;
2021-08-17 21:56:52 +02:00
for ( let name in widget . options . fields )
{
if ( widget . options . fields [ name ] ) custom_fields . push ( et2_nextmatch_customfields . PREFIX + name ) ;
2021-03-24 17:21:02 +01:00
}
}
if ( visibility [ colMgr . columns [ i ] . id ] . visible )
{
colDisplay . push ( colName ) ;
}
}
}
// List each customfield as a seperate column
jQuery . merge ( colDisplay , custom_fields ) ;
return this . sortedColumnsList . length > 0 ? this . sortedColumnsList : colDisplay ;
}
2020-01-24 12:14:08 +01:00
/ * *
* Set the currently displayed columns , without updating user ' s preference
*
* @param { string [ ] } column_list List of column names
* @param { boolean } trigger_update = false - explicitly trigger an update
* /
set_columns ( column_list : string [ ] , trigger_update = false )
{
2020-02-11 19:32:50 +01:00
const columnMgr = this . dataview . getColumnMgr ( ) ;
const visibility = { } ;
2020-01-24 12:14:08 +01:00
// Initialize to false
2021-08-17 21:56:52 +02:00
for ( var i = 0 ; i < columnMgr . columns . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const col = columnMgr . columns [ i ] ;
2021-08-17 21:56:52 +02:00
if ( col . caption && col . visibility != et2_dataview_column . ET2_COL_VISIBILITY_ALWAYS_NOSELECT )
2020-01-24 12:14:08 +01:00
{
visibility [ col . id ] = { visible : false } ;
}
}
for ( var i = 0 ; i < this . columns . length ; i ++ )
{
2020-02-11 19:32:50 +01:00
let widget = this . columns [ i ] . widget ;
let colName = this . _getColumnName ( widget ) ;
2020-01-24 12:14:08 +01:00
if ( column_list . indexOf ( colName ) !== - 1 &&
typeof visibility [ columnMgr . columns [ i ] . id ] !== 'undefined'
)
{
visibility [ columnMgr . columns [ i ] . id ] . visible = true ;
}
// Custom fields are listed seperately in column list, but are only 1 column
2021-08-17 21:56:52 +02:00
if ( widget && widget . instanceOf ( et2_nextmatch_customfields ) )
{
2020-01-24 12:14:08 +01:00
// Just the ID for server side, not the whole nm name - some apps use it to skip custom fields
colName = widget . id ;
if ( column_list . indexOf ( colName ) !== - 1 )
{
visibility [ columnMgr . columns [ i ] . id ] . visible = true ;
}
2020-02-11 19:32:50 +01:00
const cf = this . columns [ i ] . widget . options . customfields ;
const visible = this . columns [ i ] . widget . options . fields ;
2020-01-24 12:14:08 +01:00
// Turn off all custom fields
2020-02-11 19:32:50 +01:00
for ( let field_name in cf )
2020-01-24 12:14:08 +01:00
{
visible [ field_name ] = false ;
}
// Turn on selected custom fields - start from 0 in case they're not in order
2020-02-11 19:32:50 +01:00
for ( let j = 0 ; j < column_list . length ; j ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-12 19:32:29 +01:00
if ( column_list [ j ] . indexOf ( et2_customfields_list . PREFIX ) != 0 ) continue ;
2020-01-24 12:14:08 +01:00
visible [ column_list [ j ] . substring ( 1 ) ] = true ;
}
( < et2_nextmatch_customfields > < unknown > widget ) . set_visible ( visible ) ;
}
}
columnMgr . setColumnVisibilitySet ( visibility ) ;
// We don't want to update user's preference, so directly update
this . dataview . _updateColumns ( ) ;
// Allow column widgets a chance to resize
2021-08-17 21:56:52 +02:00
this . iterateOver ( function ( widget )
{
widget . resize ( ) ;
} , this , et2_IResizeable ) ;
2020-01-24 12:14:08 +01:00
}
/ * *
* Set the letter search preference , and update the UI
*
* @param { boolean } letters_on
* /
2021-08-17 21:56:52 +02:00
_set_lettersearch ( letters_on )
2020-01-24 12:14:08 +01:00
{
if ( letters_on )
{
this . header . lettersearch . show ( ) ;
}
else
{
this . header . lettersearch . hide ( ) ;
}
2020-02-11 19:32:50 +01:00
const lettersearch_preference = "nextmatch-" + this . options . settings . columnselection_pref + "-lettersearch" ;
2021-08-17 21:56:52 +02:00
this . egw ( ) . set_preference ( this . egw ( ) . app_name ( ) , lettersearch_preference , letters_on ) ;
2020-01-24 12:14:08 +01:00
}
/ * *
* Set the auto - refresh time period , and starts the timer if not started
*
* @param time int Refresh period , in seconds
* /
2021-08-17 21:56:52 +02:00
_set_autorefresh ( time )
2020-01-24 12:14:08 +01:00
{
2020-08-06 16:40:41 +02:00
// Start / update timer
2021-08-17 21:56:52 +02:00
if ( this . _autorefresh_timer )
2020-08-06 16:40:41 +02:00
{
window . clearInterval ( this . _autorefresh_timer ) ;
delete this . _autorefresh_timer ;
}
2020-01-24 12:14:08 +01:00
// Store preference
2020-02-11 19:32:50 +01:00
const refresh_preference = "nextmatch-" + this . options . settings . columnselection_pref + "-autorefresh" ;
2020-07-21 23:32:13 +02:00
const app = this . _get_appname ( ) ;
2020-01-24 12:14:08 +01:00
if ( this . _get_autorefresh ( ) != time )
{
2021-08-17 21:56:52 +02:00
this . egw ( ) . set_preference ( app , refresh_preference , time ) ;
2020-01-24 12:14:08 +01:00
}
if ( time > 0 )
{
this . _autorefresh_timer = setInterval ( jQuery . proxy ( this . controller . update , this . controller ) , time * 1000 ) ;
// Bind to tab show/hide events, so that we don't bother refreshing in the background
2021-08-17 21:56:52 +02:00
jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'hide.et2_nextmatch' , jQuery . proxy ( function ( e )
{
2020-01-24 12:14:08 +01:00
// Stop
window . clearInterval ( this . _autorefresh_timer ) ;
jQuery ( e . target ) . off ( e ) ;
// If the autorefresh time is up, bind once to trigger a refresh
// (if needed) when tab is activated again
2021-08-17 21:56:52 +02:00
this . _autorefresh_timer = setTimeout ( jQuery . proxy ( function ( )
{
2020-01-24 12:14:08 +01:00
// Check in case it was stopped / destroyed since
if ( ! this . _autorefresh_timer || ! this . getInstanceManager ( ) ) return ;
jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode ) . one ( 'show.et2_nextmatch' ,
// Important to use anonymous function instead of just 'this.refresh' because
// of the parameters passed
2021-08-17 21:56:52 +02:00
jQuery . proxy ( function ( )
{
this . refresh ( null , 'edit' ) ;
} , this )
2020-01-24 12:14:08 +01:00
) ;
2021-08-17 21:56:52 +02:00
} , this ) , time * 1000 ) ;
} , this ) ) ;
jQuery ( this . getInstanceManager ( ) . DOMContainer . parentNode ) . on ( 'show.et2_nextmatch' , jQuery . proxy ( function ( e )
{
2020-01-24 12:14:08 +01:00
// Start normal autorefresh timer again
this . _set_autorefresh ( this . _get_autorefresh ( ) ) ;
jQuery ( e . target ) . off ( e ) ;
2021-08-17 21:56:52 +02:00
} , this ) ) ;
2020-01-24 12:14:08 +01:00
}
}
/ * *
* Get the auto - refresh timer
*
* @return int Refresh period , in secods
* /
2021-08-17 21:56:52 +02:00
_get_autorefresh ( )
2020-01-24 12:14:08 +01:00
{
2020-08-05 19:21:18 +02:00
if ( this . options . disable_autorefresh )
{
return 0 ;
}
2020-02-11 19:32:50 +01:00
const refresh_preference = "nextmatch-" + this . options . settings . columnselection_pref + "-autorefresh" ;
2021-08-17 21:56:52 +02:00
return this . egw ( ) . preference ( refresh_preference , this . _get_appname ( ) ) ;
2020-01-24 12:14:08 +01:00
}
2020-08-06 16:40:41 +02:00
/ * *
* Enable or disable autorefresh
*
* If false , autorefresh will be shown in column selection . If the user already has an autorefresh preference
* for this nextmatch , the timer will be started .
*
* If true , the timer will be stopped and autorefresh will not be shown in column selection
*
* @param disabled
* /
2021-08-17 21:56:52 +02:00
set_disable_autorefresh ( disabled : boolean )
2020-08-06 16:40:41 +02:00
{
this . options . disable_autorefresh = disabled ;
2020-08-26 22:39:39 +02:00
2020-08-06 16:40:41 +02:00
this . _set_autorefresh ( this . _get_autorefresh ( ) ) ;
}
2020-01-24 12:14:08 +01:00
/ * *
* When the template attribute is set , the nextmatch widget tries to load
* that template and to fetch the grid which is inside of it . It then calls
*
2020-02-11 19:32:50 +01:00
* @param { string } template_name Full template name in the form app . template [ . template ]
2020-01-24 12:14:08 +01:00
* /
2021-08-17 21:56:52 +02:00
set_template ( template_name : string )
{
2020-02-11 19:32:50 +01:00
const template = et2_createWidget ( "template" , { "id" : template_name } , this ) ;
2021-08-17 21:56:52 +02:00
if ( this . template )
{
2020-01-24 12:14:08 +01:00
// Stop early to prevent unneeded processing, and prevent infinite
// loops if the server changes the template in get_rows
2021-08-17 21:56:52 +02:00
if ( this . template == template_name )
{
2020-01-24 12:14:08 +01:00
return ;
}
// Free the grid components - they'll be re-created as the template is processed
2020-01-31 21:07:27 +01:00
this . dataview . destroy ( ) ;
this . rowProvider . destroy ( ) ;
this . controller . destroy ( ) ;
2020-08-07 21:18:41 +02:00
this . controller = null ;
2020-01-24 12:14:08 +01:00
// Free any children from previous template
// They may get left behind because of how detached nodes are processed
// We don't use iterateOver because it checks sub-children
2021-08-17 21:56:52 +02:00
for ( let i = this . _children . length - 1 ; i >= 0 ; i -- )
{
2020-02-11 19:32:50 +01:00
const _node = this . _children [ i ] ;
2021-08-17 21:56:52 +02:00
if ( _node != this . header && _node !== template )
{
2020-01-24 12:14:08 +01:00
this . removeChild ( _node ) ;
_node . destroy ( ) ;
}
}
// Clear this setting if it's the same as the template, or
// the columns will not be loaded
2021-08-17 21:56:52 +02:00
if ( this . template == this . options . settings . columnselection_pref )
{
2020-01-24 12:14:08 +01:00
this . options . settings . columnselection_pref = template_name ;
}
this . dataview = new et2_dataview ( this . innerDiv , this . egw ( ) ) ;
}
2021-08-17 21:56:52 +02:00
if ( ! template )
2020-01-24 12:14:08 +01:00
{
this . egw ( ) . debug ( "error" , "Error while loading definition template for " +
2021-08-17 21:56:52 +02:00
"nextmatch widget." , template_name ) ;
2020-01-24 12:14:08 +01:00
return ;
}
if ( this . options . disabled )
{
return ;
}
// Deferred parse function - template might not be fully loaded
2021-08-17 21:56:52 +02:00
const parse = function ( template )
{
2020-01-24 12:14:08 +01:00
// Keep the name of the template, as we'll free up the widget after parsing
this . template = template_name ;
// Fetch the grid element and parse it
2020-02-11 19:32:50 +01:00
const definitionGrid = template . getChildren ( ) [ 0 ] ;
2021-08-17 21:56:52 +02:00
if ( definitionGrid && definitionGrid instanceof et2_grid )
{
2020-01-24 12:14:08 +01:00
this . _parseGrid ( definitionGrid ) ;
2021-08-17 21:56:52 +02:00
}
else
{
2020-01-24 12:14:08 +01:00
this . egw ( ) . debug ( "error" , "Nextmatch widget expects a grid to be the " +
"first child of the defined template." ) ;
return ;
}
// Free the template again, but don't remove it
2021-08-17 21:56:52 +02:00
setTimeout ( function ( )
{
2020-01-29 22:29:06 +01:00
template . destroy ( ) ;
2020-02-11 19:32:50 +01:00
} , 1 ) ;
2020-01-24 12:14:08 +01:00
// Call the "setNextmatch" function of all registered
// INextmatchHeader widgets. This updates this.activeFilters.col_filters according
// to what's in the template.
2021-08-17 21:56:52 +02:00
this . iterateOver ( function ( _node )
{
2020-01-24 12:14:08 +01:00
_node . setNextmatch ( this ) ;
} , this , et2_INextmatchHeader ) ;
// Set filters to current values
2020-01-29 22:29:06 +01:00
// TODO this.controller.setFilters(this.activeFilters);
2020-01-24 12:14:08 +01:00
// If no data was sent from the server, and num_rows is 0, the nm will be empty.
// This triggers a cache check.
2021-08-17 21:56:52 +02:00
if ( ! this . options . settings . num_rows && this . controller )
{
2020-01-24 12:14:08 +01:00
this . controller . update ( ) ;
}
// Load the default sort order
2021-08-17 21:56:52 +02:00
if ( this . options . settings . order && this . options . settings . sort )
{
2020-01-24 12:14:08 +01:00
this . sortBy ( this . options . settings . order ,
this . options . settings . sort == "ASC" , false ) ;
}
// Start auto-refresh
this . _set_autorefresh ( this . _get_autorefresh ( ) ) ;
} ;
// Template might not be loaded yet, defer parsing
2020-02-11 19:32:50 +01:00
const promise = [ ] ;
2020-01-24 12:14:08 +01:00
template . loadingFinished ( promise ) ;
// Wait until template (& children) are done
jQuery . when . apply ( null , promise ) . done (
2021-08-17 21:56:52 +02:00
jQuery . proxy ( function ( )
{
2020-01-24 12:14:08 +01:00
parse . call ( this , template ) ;
if ( ! this . dynheight )
{
this . dynheight = this . _getDynheight ( ) ;
}
this . dynheight . initialized = false ;
this . resize ( ) ;
} , this )
) ;
2020-08-07 21:18:41 +02:00
return promise ;
2020-01-24 12:14:08 +01:00
}
// Some accessors to match conventions
2021-08-17 21:56:52 +02:00
set_hide_header ( hide : boolean )
2020-01-24 12:14:08 +01:00
{
( hide ? this . header . div . hide ( ) : this . header . div . show ( ) ) ;
}
2021-08-17 21:56:52 +02:00
set_header_left ( template : string )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . header . _build_header ( "left" , template ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
set_header_right ( template : string )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . header . _build_header ( "right" , template ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
set_header_row ( template : string )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . header . _build_header ( "row" , template ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
set_no_filter ( bool , filter_name )
2020-01-24 12:14:08 +01:00
{
if ( typeof filter_name == 'undefined' )
{
filter_name = 'filter' ;
}
2021-08-17 21:56:52 +02:00
this . options [ 'no_' + filter_name ] = bool ;
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
let filter = this . header [ filter_name ] ;
2020-01-24 12:14:08 +01:00
if ( filter )
{
filter . set_disabled ( bool ) ;
}
2021-08-17 21:56:52 +02:00
else if ( bool )
2020-01-24 12:14:08 +01:00
{
filter = this . header . _build_select ( filter_name , 'select' ,
2021-08-17 21:56:52 +02:00
this . settings [ filter_name ] , this . settings [ filter_name + '_no_lang' ] ) ;
2020-01-24 12:14:08 +01:00
}
}
2021-08-17 21:56:52 +02:00
set_no_filter2 ( bool )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . set_no_filter ( bool , 'filter2' ) ;
2020-01-24 12:14:08 +01:00
}
/ * *
* Directly change filter value , with no server query .
*
* This allows the server app code to change filter value , and have it
* updated in the client UI .
*
* @param { String | number } value
* /
2021-08-17 21:56:52 +02:00
set_filter ( value )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const update = this . update_in_progress ;
2020-01-24 12:14:08 +01:00
this . update_in_progress = true ;
this . activeFilters . filter = value ;
// Update the header
this . header . setFilters ( this . activeFilters ) ;
this . update_in_progress = update ;
}
/ * *
* Directly change filter2 value , with no server query .
*
* This allows the server app code to change filter2 value , and have it
* updated in the client UI .
*
* @param { String | number } value
* /
2021-08-17 21:56:52 +02:00
set_filter2 ( value )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const update = this . update_in_progress ;
2020-01-24 12:14:08 +01:00
this . update_in_progress = true ;
this . activeFilters . filter2 = value ;
// Update the header
this . header . setFilters ( this . activeFilters ) ;
this . update_in_progress = update ;
}
/ * *
* If nextmatch starts disabled , it will need a resize after being shown
* to get all the sizing correct . Override the parent to add the resize
* when enabling .
*
* @param { boolean } _value
* /
set_disabled ( _value : boolean )
{
2020-02-11 19:32:50 +01:00
const previous = this . disabled ;
2020-01-24 12:14:08 +01:00
super . set_disabled ( _value ) ;
if ( previous && ! _value )
{
this . resize ( ) ;
}
}
/ * *
* Actions are handled by the controller , so ignore these during init .
*
* @param { object } actions
* /
2021-08-17 21:56:52 +02:00
set_actions ( actions : object [ ] )
2020-01-24 12:14:08 +01:00
{
if ( actions != this . options . actions && this . controller != null && this . controller . _actionManager )
{
2020-02-11 19:32:50 +01:00
for ( let i = this . controller . _actionManager . children . length - 1 ; i >= 0 ; i -- )
2020-01-24 12:14:08 +01:00
{
this . controller . _actionManager . children [ i ] . remove ( ) ;
}
this . options . actions = actions ;
this . options . settings . action_links = this . controller . _actionLinks = this . _get_action_links ( actions ) ;
this . controller . _initActions ( actions ) ;
}
}
/ * *
* Switch view between row and tile .
* This should be followed by a call to change the template to match , which
* will cause a reload of the grid using the new settings .
*
* @param { string } view Either 'tile' or 'row'
* /
set_view ( view : "tile" | "row" )
{
// Restrict to the only 2 accepted values
if ( view == 'tile' )
{
this . view = 'tile' ;
}
else
{
this . view = 'row' ;
}
}
/ * *
* Set a different / additional handler for dropped files .
*
* File dropping doesn ' t work with the action system , so we handle it in the
* nextmatch by linking automatically to the target row . This allows an additional handler .
* It should accept a row UID and a File [ ] , and return a boolean Execute the default ( link ) action
*
* @param { String | Function } handler
* /
2021-08-17 21:56:52 +02:00
set_onfiledrop ( handler )
2020-01-24 12:14:08 +01:00
{
this . options . onfiledrop = handler ;
}
/ * *
* Handle drops of files by linking to the row , if possible .
*
* HTML5 / native file drops conflict with jQueryUI draggable , which handles
* all our drop actions . So we side - step the issue by registering an additional
* drop handler on the rows parent . If the row / actions itself doesn ' t handle
* the drop , it should bubble and get handled here .
*
* @param { object } event
* @param { object } target
* /
2021-08-17 21:56:52 +02:00
handle_drop ( event , target )
2020-01-24 12:14:08 +01:00
{
// Check to see if we can handle the link
// First, find the UID
2020-02-11 19:32:50 +01:00
const row = this . controller . getRowByNode ( target ) ;
2020-10-19 11:45:34 +02:00
const uid = row ? . uid || null ;
2020-01-24 12:14:08 +01:00
// Get the file information
2020-02-11 19:32:50 +01:00
let files = [ ] ;
2020-01-24 12:14:08 +01:00
if ( event . originalEvent && event . originalEvent . dataTransfer &&
event . originalEvent . dataTransfer . files && event . originalEvent . dataTransfer . files . length > 0 )
{
files = event . originalEvent . dataTransfer . files ;
}
else
{
return false ;
}
// Exectute the custom handler code
2021-08-17 21:56:52 +02:00
if ( this . options . onfiledrop && ! this . options . onfiledrop . call ( this , uid , files ) )
2020-01-24 12:14:08 +01:00
{
return false ;
}
event . stopPropagation ( ) ;
event . preventDefault ( ) ;
if ( ! row || ! row . uid ) return false ;
// Link the file to the row
// just use a link widget, it's all already done
2020-02-11 19:32:50 +01:00
const split = uid . split ( '::' ) ;
const link_value = {
2020-01-24 12:14:08 +01:00
to_app : split.shift ( ) ,
to_id : split.join ( '::' )
} ;
// Create widget and mangle to our needs
2021-08-17 21:56:52 +02:00
const link = < et2_link_to > et2_createWidget ( "link-to" , { value : link_value } , this ) ;
2020-01-24 12:14:08 +01:00
link . loadingFinished ( ) ;
link . file_upload . set_drop_target ( false ) ;
if ( row . row . tr )
{
// Ignore most of the UI, just use the status indicators
2020-02-11 19:32:50 +01:00
const status = jQuery ( document . createElement ( "div" ) )
2020-01-24 12:14:08 +01:00
. addClass ( 'et2_link_to' )
. width ( row . row . tr . width ( ) )
. position ( { my : "left top" , at : "left top" , of : row . row . tr } )
. append ( link . status_span )
. append ( link . file_upload . progress )
. appendTo ( row . row . tr ) ;
// Bind to link event so we can remove when done
2021-08-17 21:56:52 +02:00
link . div . on ( 'link.et2_link_to' , function ( e , linked )
{
2020-01-24 12:14:08 +01:00
if ( ! linked )
{
jQuery ( "li.success" , link . file_upload . progress )
. removeClass ( 'success' ) . addClass ( 'validation_error' ) ;
}
else
{
// Update row
2021-08-17 21:56:52 +02:00
link . _parent . refresh ( uid , 'edit' ) ;
2020-01-24 12:14:08 +01:00
}
// Fade out nicely
status . delay ( linked ? 1 : 2000 )
2021-08-17 21:56:52 +02:00
. fadeOut ( 500 , function ( )
{
2020-01-31 21:07:27 +01:00
link . destroy ( ) ;
2020-01-24 12:14:08 +01:00
status . remove ( ) ;
} ) ;
} ) ;
}
// Upload and link - this triggers the upload, which triggers the link, which triggers the cleanup and refresh
link . file_upload . set_value ( files ) ;
}
2021-08-17 21:56:52 +02:00
getDOMNode ( _sender ? )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( _sender == this || typeof _sender === 'undefined' )
2020-01-24 12:14:08 +01:00
{
return this . div [ 0 ] ;
}
2021-08-17 21:56:52 +02:00
if ( _sender == this . header )
2020-01-24 12:14:08 +01:00
{
return this . header . div [ 0 ] ;
}
2021-08-17 21:56:52 +02:00
for ( let i = 0 ; i < this . columns . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( this . columns [ i ] && this . columns [ i ] . widget && _sender == this . columns [ i ] . widget )
2020-01-24 12:14:08 +01:00
{
return this . dataview . getHeaderContainerNode ( i ) ;
}
}
// Let header have a chance
if ( _sender && _sender . _parent && _sender . _parent == this )
{
return this . header . getDOMNode ( _sender ) ;
}
return null ;
}
// Input widget
/ * *
* Get the current 'value' for the nextmatch
* /
2021-08-17 21:56:52 +02:00
getValue ( ) : ActiveFilters
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const _ids = this . getSelection ( ) ;
2020-01-24 12:14:08 +01:00
// Translate the internal uids back to server uids
2020-02-11 19:32:50 +01:00
const idsArr = _ids . ids ;
2021-08-17 21:56:52 +02:00
for ( let i = 0 ; i < idsArr . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
idsArr [ i ] = idsArr [ i ] . split ( "::" ) . pop ( ) ;
}
2021-03-01 22:08:13 +01:00
const value : ActiveFilters = {
selected : idsArr ,
2021-02-24 17:18:42 +01:00
col_filter : { }
2020-01-24 12:14:08 +01:00
} ;
jQuery . extend ( value , this . activeFilters , this . value ) ;
2021-03-22 18:09:41 +01:00
if ( typeof value . selectcols == "undefined" || value . selectcols . length === 0 )
{
2021-03-24 17:21:02 +01:00
value . selectcols = this . get_columns ( ) ;
2021-03-22 18:09:41 +01:00
}
2020-01-24 12:14:08 +01:00
return value ;
}
2021-08-17 21:56:52 +02:00
resetDirty ( )
{
}
isDirty ( )
{
return false ;
}
isValid ( )
{
return true ;
}
2020-01-24 12:14:08 +01:00
set_value ( _value )
{
this . value = _value ;
}
// Printing
/ * *
* Prepare for printing
*
* We check for un - loaded rows , and ask the user what they want to do about them .
* If they want to print them all , we ask the server and print when they ' re loaded .
* /
2021-08-17 21:56:52 +02:00
beforePrint ( )
2020-01-24 12:14:08 +01:00
{
// Add the class, if needed
this . div . addClass ( 'print' ) ;
// Trigger resize, so we can fit on a page
2021-08-17 21:56:52 +02:00
this . dynheight . outerNode . css ( 'max-width' , this . div . css ( 'max-width' ) ) ;
2020-01-24 12:14:08 +01:00
this . resize ( ) ;
// Reset height to auto (after width resize) so there's no restrictions
this . dynheight . innerNode . css ( 'height' , 'auto' ) ;
// Check for rows that aren't loaded yet, or lots of rows
2020-02-11 19:32:50 +01:00
const range = this . controller . _grid . getIndexRange ( ) ;
2020-01-24 12:14:08 +01:00
this . print . old_height = this . controller . _grid . _scrollHeight ;
2020-02-11 19:32:50 +01:00
const loaded_count = range . bottom - range . top + 1 ;
const total = this . controller . _grid . getTotalCount ( ) ;
2020-01-24 12:14:08 +01:00
// Defer the printing to ask about columns & rows
2020-02-11 19:32:50 +01:00
const defer = jQuery . Deferred ( ) ;
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
let pref = this . options . settings . columnselection_pref ;
2020-01-24 12:14:08 +01:00
if ( pref . indexOf ( 'nextmatch' ) == 0 )
{
2021-08-17 21:56:52 +02:00
pref = 'nextmatch-' + pref ;
2020-01-24 12:14:08 +01:00
}
2020-02-11 19:32:50 +01:00
const app = this . getInstanceManager ( ) . app ;
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
const columns = { } ;
const columnMgr = this . dataview . getColumnMgr ( ) ;
2020-01-24 12:14:08 +01:00
pref += '_print' ;
2020-02-11 19:32:50 +01:00
const columns_selected = [ ] ;
2020-01-24 12:14:08 +01:00
// Get column names
2021-08-17 21:56:52 +02:00
for ( let i = 0 ; i < columnMgr . columns . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const col = columnMgr . columns [ i ] ;
const widget = this . columns [ i ] . widget ;
let colName = this . _getColumnName ( widget ) ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
if ( col . caption && col . visibility !== et2_dataview_column . ET2_COL_VISIBILITY_ALWAYS_NOSELECT &&
2020-08-20 16:18:39 +02:00
col . visibility !== et2_dataview_column . ET2_COL_VISIBILITY_DISABLED )
2020-01-24 12:14:08 +01:00
{
columns [ colName ] = col . caption ;
2021-08-17 21:56:52 +02:00
if ( col . visibility === et2_dataview_column . ET2_COL_VISIBILITY_VISIBLE ) columns_selected . push ( colName ) ;
2020-01-24 12:14:08 +01:00
}
// Custom fields get listed separately
if ( widget . instanceOf ( et2_nextmatch_customfields ) )
{
2021-08-17 21:56:52 +02:00
delete ( columns [ colName ] ) ;
2020-01-24 12:14:08 +01:00
colName = widget . id ;
2021-08-17 21:56:52 +02:00
if ( col . visibility === et2_dataview_column . ET2_COL_VISIBILITY_VISIBLE && !
2020-01-24 12:14:08 +01:00
jQuery . isEmptyObject ( ( < et2_nextmatch_customfields > < unknown > widget ) . customfields )
)
{
columns [ colName ] = col . caption ;
2020-02-11 19:32:50 +01:00
for ( let field_name in ( < et2_nextmatch_customfields > < unknown > widget ) . customfields )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
columns [ et2_nextmatch_customfields . PREFIX + field_name ] = " - " + ( < et2_nextmatch_customfields > < unknown > widget ) . customfields [ field_name ] . label ;
2020-01-24 12:14:08 +01:00
if ( widget . options . fields [ field_name ] && columns_selected . indexOf ( colName ) >= 0 )
{
2021-08-17 21:56:52 +02:00
columns_selected . push ( et2_nextmatch_customfields . PREFIX + field_name ) ;
2020-01-24 12:14:08 +01:00
}
}
}
}
}
// Preference exists? Set it now
2021-08-17 21:56:52 +02:00
if ( this . egw ( ) . preference ( pref , app ) )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . set_columns ( jQuery . extend ( [ ] , this . egw ( ) . preference ( pref , app ) ) ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
const callback = jQuery . proxy ( function ( button , value )
{
if ( button === et2_dialog . CANCEL_BUTTON )
{
2020-01-24 12:14:08 +01:00
// Give dialog a chance to close, or it will be in the print
2021-08-17 21:56:52 +02:00
window . setTimeout ( function ( )
{
2020-02-11 19:32:50 +01:00
defer . reject ( ) ;
} , 0 ) ;
2020-01-24 12:14:08 +01:00
return ;
}
// Set CSS for orientation
this . div . addClass ( value . orientation ) ;
2020-02-11 19:32:50 +01:00
this . egw ( ) . set_preference ( app , pref + '_orientation' , value . orientation ) ;
2020-01-24 12:14:08 +01:00
// Try to tell browser about orientation
2020-02-11 19:32:50 +01:00
const css = '@page { size: ' + value . orientation + '; }' ,
head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ] ,
style = document . createElement ( 'style' ) ;
2020-01-24 12:14:08 +01:00
style . type = 'text/css' ;
style . media = 'print' ;
// @ts-ignore
2021-08-17 21:56:52 +02:00
if ( style . styleSheet )
{
2020-02-11 19:32:50 +01:00
// @ts-ignore
style . styleSheet . cssText = css ;
2021-08-17 21:56:52 +02:00
}
else
{
2020-02-11 19:32:50 +01:00
style . appendChild ( document . createTextNode ( css ) ) ;
2020-01-24 12:14:08 +01:00
}
head . appendChild ( style ) ;
this . print . orientation_style = style ;
// Trigger resize, so we can fit on a page
2020-02-11 19:32:50 +01:00
this . dynheight . outerNode . css ( 'max-width' , this . div . css ( 'max-width' ) ) ;
2020-01-24 12:14:08 +01:00
// Handle columns
this . set_columns ( value . columns ) ;
2020-02-11 19:32:50 +01:00
this . egw ( ) . set_preference ( app , pref , value . columns ) ;
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
let rows = parseInt ( value . row_count ) ;
2021-08-17 21:56:52 +02:00
if ( rows > total )
{
2020-01-24 12:14:08 +01:00
rows = total ;
}
// If they want the whole thing, style it as all
2021-08-17 21:56:52 +02:00
if ( button === et2_dialog . OK_BUTTON && rows == this . controller . _grid . getTotalCount ( ) )
{
2020-01-24 12:14:08 +01:00
// Add the class, gives more reliable sizing
this . div . addClass ( 'print' ) ;
// Show it all
2020-02-11 19:32:50 +01:00
jQuery ( '.egwGridView_scrollarea' , this . div ) . css ( 'height' , 'auto' ) ;
2020-01-24 12:14:08 +01:00
}
// We need more rows
2021-08-17 21:56:52 +02:00
if ( button === 'dialog[all]' || rows > loaded_count )
{
2020-02-11 19:32:50 +01:00
let count = 0 ;
let fetchedCount = 0 ;
let cancel = false ;
const nm = this ;
const dialog = et2_dialog . show_dialog (
2020-01-24 12:14:08 +01:00
// Abort the long task if they canceled the data load
2021-08-17 21:56:52 +02:00
function ( )
{
2020-02-11 19:32:50 +01:00
count = total ;
cancel = true ;
2021-08-17 21:56:52 +02:00
window . setTimeout ( function ( )
{
2020-02-11 19:32:50 +01:00
defer . reject ( ) ;
} , 0 ) ;
} ,
egw . lang ( 'Loading' ) , egw . lang ( 'please wait...' ) , { } , [
{ "button_id" : et2_dialog . CANCEL_BUTTON , "text" : 'cancel' , id : 'dialog[cancel]' , image : 'cancel' }
2020-01-24 12:14:08 +01:00
]
) ;
2020-02-11 19:32:50 +01:00
// dataFetch() is asynchronous, so all these requests just get fired off...
2020-01-24 12:14:08 +01:00
// 200 rows chosen arbitrarily to reduce requests.
2021-08-17 21:56:52 +02:00
do
{
2020-02-11 19:32:50 +01:00
const ctx = {
2020-01-24 12:14:08 +01:00
"self" : this . controller ,
"start" : count ,
2020-02-11 19:32:50 +01:00
"count" : Math . min ( rows , 200 ) ,
2020-01-24 12:14:08 +01:00
"lastModification" : this . controller . _lastModification
} ;
2021-08-17 21:56:52 +02:00
if ( nm . controller . dataStorePrefix )
{
2020-01-24 12:14:08 +01:00
// @ts-ignore
ctx . prefix = nm . controller . dataStorePrefix ;
}
2021-08-17 21:56:52 +02:00
nm . controller . dataFetch ( { start : count , num_rows : Math.min ( rows , 200 ) } , function ( data )
{
2020-01-24 12:14:08 +01:00
// Keep track
2021-08-17 21:56:52 +02:00
if ( data && data . order )
{
2020-01-24 12:14:08 +01:00
fetchedCount += data . order . length ;
}
nm . controller . _fetchCallback . apply ( this , arguments ) ;
2021-08-17 21:56:52 +02:00
if ( fetchedCount >= rows )
{
if ( cancel )
{
2020-01-24 12:14:08 +01:00
dialog . destroy ( ) ;
defer . reject ( ) ;
return ;
}
// Use CSS to hide all but the requested rows
// Prevents us from showing more than requested, if actual height was less than average
2020-10-14 19:48:57 +02:00
nm . print . row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+" + rows + "))" ;
egw . css ( nm . print . row_selector , 'display: none' ) ;
2020-01-24 12:14:08 +01:00
// No scrollbar in print view
2020-02-11 19:32:50 +01:00
jQuery ( '.egwGridView_scrollarea' , this . div ) . css ( 'overflow-y' , 'hidden' ) ;
2020-01-24 12:14:08 +01:00
// Show it all
2020-02-11 19:32:50 +01:00
jQuery ( '.egwGridView_scrollarea' , this . div ) . css ( 'height' , 'auto' ) ;
2020-01-24 12:14:08 +01:00
// Grid needs to redraw before it can be printed, so wait
2021-08-17 21:56:52 +02:00
window . setTimeout ( jQuery . proxy ( function ( )
{
2020-01-24 12:14:08 +01:00
dialog . destroy ( ) ;
// Should be OK to print now
defer . resolve ( ) ;
2020-02-11 19:32:50 +01:00
} , nm ) , et2_dataview_grid . ET2_GRID_INVALIDATE_TIMEOUT ) ;
2020-01-24 12:14:08 +01:00
}
2020-02-11 19:32:50 +01:00
} , ctx ) ;
2020-01-24 12:14:08 +01:00
count += 200 ;
2021-08-17 21:56:52 +02:00
}
while ( count < rows ) ;
2020-02-11 19:32:50 +01:00
nm . controller . _grid . setScrollHeight ( nm . controller . _grid . getAverageHeight ( ) * ( rows + 1 ) ) ;
2021-08-17 21:56:52 +02:00
}
else
{
2020-01-24 12:14:08 +01:00
// Don't need more rows, limit to requested and finish
// Show it all
2020-02-11 19:32:50 +01:00
jQuery ( '.egwGridView_scrollarea' , this . div ) . css ( 'height' , 'auto' ) ;
2020-01-24 12:14:08 +01:00
// Use CSS to hide all but the requested rows
// Prevents us from showing more than requested, if actual height was less than average
2020-10-14 19:48:57 +02:00
this . print . row_selector = ".egwGridView_grid > tbody > tr:not(:nth-child(-n+" + rows + "))" ;
egw . css ( this . print . row_selector , 'display: none' ) ;
2020-01-24 12:14:08 +01:00
// No scrollbar in print view
2020-02-11 19:32:50 +01:00
jQuery ( '.egwGridView_scrollarea' , this . div ) . css ( 'overflow-y' , 'hidden' ) ;
2020-01-24 12:14:08 +01:00
// Give dialog a chance to close, or it will be in the print
2021-08-17 21:56:52 +02:00
window . setTimeout ( function ( )
{
2020-02-11 19:32:50 +01:00
defer . resolve ( ) ;
} , 0 ) ;
2020-01-24 12:14:08 +01:00
}
2020-02-11 19:32:50 +01:00
} , this ) ;
2020-01-24 12:14:08 +01:00
var value = {
content : {
2021-08-17 21:56:52 +02:00
row_count : Math.min ( 100 , total ) ,
columns : this.egw ( ) . preference ( pref , app ) || columns_selected ,
orientation : this.egw ( ) . preference ( pref + '_orientation' , app )
2020-01-24 12:14:08 +01:00
} ,
sel_options : {
columns : columns
}
} ;
this . _create_print_dialog . call ( this , value , callback ) ;
return defer ;
}
/ * *
* Create and show the print dialog , which calls the provided callback when
* done . Broken out for overriding if needed .
*
* @param { Object } value Current settings and preferences , passed to the dialog for
* the template
* @param { Object } value . content
* @param { Object } value . sel_options
*
* @param { function ( int , Object ) } callback - Process the dialog response ,
* format things according to the specified orientation and fetch any needed
* rows .
*
* /
_create_print_dialog ( value , callback )
{
2020-02-11 19:32:50 +01:00
let base_url = this . getInstanceManager ( ) . template_base_url ;
2021-08-17 21:56:52 +02:00
if ( base_url . substr ( base_url . length - 1 ) == '/' ) base_url = base_url . slice ( 0 , - 1 ) ; // otherwise we generate a url //api/templates, which is wrong
2020-02-11 19:32:50 +01:00
const tab = this . get_tab_info ( ) ;
2020-01-24 12:14:08 +01:00
// Get title for print dialog from settings or tab, if available
2020-02-11 19:32:50 +01:00
const title = this . options . settings . label ? this . options . settings . label : ( tab ? tab . label : '' ) ;
const dialog = et2_createWidget ( "dialog" , {
2020-01-24 12:14:08 +01:00
// If you use a template, the second parameter will be the value of the template, as if it were submitted.
callback : callback , // return false to prevent dialog closing
buttons : et2_dialog.BUTTONS_OK_CANCEL ,
title : this.egw ( ) . lang ( 'Print' ) + ' ' + this . egw ( ) . lang ( title ) ,
2020-02-11 19:32:50 +01:00
template : this.egw ( ) . link ( base_url + '/api/templates/default/nm_print_dialog.xet' ) ,
2020-01-24 12:14:08 +01:00
value : value
} ) ;
}
/ * *
* Try to clean up the mess we made getting ready for printing
* in beforePrint ( )
* /
2021-08-17 21:56:52 +02:00
afterPrint ( )
2020-01-24 12:14:08 +01:00
{
2020-10-15 18:11:24 +02:00
if ( ! this . div . hasClass ( 'print' ) )
{
return ;
}
2020-01-24 12:14:08 +01:00
this . div . removeClass ( 'print landscape portrait' ) ;
jQuery ( this . print . orientation_style ) . remove ( ) ;
delete this . print . orientation_style ;
// Put scrollbar back
2021-08-17 21:56:52 +02:00
jQuery ( '.egwGridView_scrollarea' , this . div ) . css ( 'overflow-y' , '' ) ;
2020-01-24 12:14:08 +01:00
// Correct size of grid, and trigger resize to fix it
this . controller . _grid . setScrollHeight ( this . print . old_height ) ;
delete this . print . old_height ;
// Remove CSS rule hiding extra rows
if ( this . print . row_selector )
{
2020-02-11 19:32:50 +01:00
egw . css ( this . print . row_selector , '' ) ;
2020-01-24 12:14:08 +01:00
delete this . print . row_selector ;
}
// Restore columns
2021-08-17 21:56:52 +02:00
let pref : string | object | boolean = [ ] ;
2020-02-11 19:32:50 +01:00
const app = this . getInstanceManager ( ) . app ;
2020-01-24 12:14:08 +01:00
if ( this . options . settings . columnselection_pref . indexOf ( 'nextmatch' ) == 0 )
{
pref = egw . preference ( this . options . settings . columnselection_pref , app ) ;
}
else
{
// 'nextmatch-' prefix is there in preference name, but not in setting, so add it in
2021-08-17 21:56:52 +02:00
pref = egw . preference ( "nextmatch-" + this . options . settings . columnselection_pref , app ) ;
2020-01-24 12:14:08 +01:00
}
if ( pref )
{
if ( typeof pref === 'string' ) pref = ( < string > pref ) . split ( ',' ) ;
2020-02-11 19:32:50 +01:00
// @ts-ignore
2021-08-17 21:56:52 +02:00
this . set_columns ( pref , app ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
this . dynheight . outerNode . css ( 'max-width' , 'inherit' ) ;
2020-01-24 12:14:08 +01:00
this . resize ( ) ;
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch , [ "nextmatch" ] ) ;
/ * *
* Standard nextmatch header bar , containing filters , search , record count , letter filters , etc .
*
* Unable to use an existing template for this because parent ( nm ) doesn 't, and template widget doesn' t
* actually load templates from the server .
* @augments et2_DOMWidget
* /
2021-08-17 21:56:52 +02:00
export class et2_nextmatch_header_bar extends et2_DOMWidget implements et2_INextmatchHeader
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
static readonly _attributes : any = {
2020-01-24 12:14:08 +01:00
"filter_label" : {
"name" : "Filter label" ,
"type" : "string" ,
"description" : "Label for filter" ,
"default" : "" ,
"translate" : true
} ,
"filter_help" : {
"name" : "Filter help" ,
"type" : "string" ,
"description" : "Help message for filter" ,
"default" : "" ,
"translate" : true
} ,
"filter" : {
"name" : "Filter value" ,
"type" : "any" ,
"description" : "Current value for filter" ,
"default" : ""
} ,
"no_filter" : {
"name" : "No filter" ,
"type" : "boolean" ,
"description" : "Remove filter" ,
"default" : false
}
} ;
2021-08-17 21:56:52 +02:00
headers : { id : string } [ ] | et2_widget [ ] ;
et2_searchbox : et2_inputWidget ;
private favorites : et2_DOMWidget ; // Actually favorite
private nextmatch : et2_nextmatch ;
div : JQuery ;
private update_in_progress : boolean ;
header_div : JQuery ;
private header_row : JQuery ;
private filter_div : JQuery ;
private row_div : JQuery ;
private fav_span : JQuery ;
private toggle_header : JQuery ;
lettersearch : JQuery ;
private delete_action : JQuery ;
private action_header : JQuery ;
private search_box : JQuery ;
private category : any ;
private filter : et2_selectbox ;
private filter2 : et2_selectbox ;
private right_div : JQuery ;
private count : JQuery ;
private count_total : JQuery ;
2020-01-24 12:14:08 +01:00
/ * *
* Constructor
*
2020-02-11 19:32:50 +01:00
* @param _parent
* @param _attrs
* @param _child
2020-01-24 12:14:08 +01:00
* /
2020-02-05 21:48:50 +01:00
constructor ( _parent : et2_nextmatch , _attrs? : WidgetConfig , _child? : object )
{
2021-08-17 21:56:52 +02:00
super ( _parent , [ _parent , _parent . options . settings ] , ClassWithAttributes . extendAttributes ( et2_nextmatch_header_bar . _attributes , _child || { } ) ) ;
2020-01-24 12:14:08 +01:00
this . nextmatch = _parent ;
this . div = jQuery ( document . createElement ( "div" ) )
. addClass ( "nextmatch_header" ) ;
this . _createHeader ( ) ;
// Flag to avoid loops while updating filters
this . update_in_progress = false ;
}
2021-08-17 21:56:52 +02:00
destroy ( )
2020-01-24 12:14:08 +01:00
{
this . nextmatch = null ;
super . destroy ( ) ;
this . div = null ;
}
2021-08-17 21:56:52 +02:00
setNextmatch ( nextmatch )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const create_once = ( this . nextmatch == null ) ;
2020-01-24 12:14:08 +01:00
this . nextmatch = nextmatch ;
if ( create_once )
{
this . _createHeader ( ) ;
}
// Bind row count
2021-08-17 21:56:52 +02:00
this . nextmatch . dataview . grid . setInvalidateCallback ( function ( )
{
2020-01-24 12:14:08 +01:00
this . count_total . text ( this . nextmatch . dataview . grid . getTotalCount ( ) + "" ) ;
} , this ) ;
}
/ * *
* Actions are handled by the controller , so ignore these
*
* @param { object } actions
* /
2021-08-17 21:56:52 +02:00
set_actions ( actions : object [ ] )
{
}
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
_createHeader ( )
2020-01-24 12:14:08 +01:00
{
let button ;
2020-02-11 19:32:50 +01:00
const self = this ;
const nm_div = this . nextmatch . getDOMNode ( ) ;
const settings = this . nextmatch . options . settings ;
2020-01-24 12:14:08 +01:00
this . div . prependTo ( nm_div ) ;
// Left & Right (& row) headers
this . headers = [
2021-08-17 21:56:52 +02:00
{ id : this.nextmatch.options.header_left } ,
{ id : this.nextmatch.options.header_right } ,
{ id : this.nextmatch.options.header_row }
2020-01-24 12:14:08 +01:00
] ;
// The rest of the header
this . header_div = this . row_div = jQuery ( document . createElement ( "div" ) )
. addClass ( "nextmatch_header_row" )
. appendTo ( this . div ) ;
this . filter_div = jQuery ( document . createElement ( "div" ) )
. addClass ( 'filtersContainer' )
. appendTo ( this . row_div ) ;
// Search
this . search_box = jQuery ( document . createElement ( "div" ) )
. addClass ( 'search' )
2021-08-17 21:56:52 +02:00
. prependTo ( egwIsMobile ( ) ? this . nextmatch . getDOMNode ( ) : this . row_div )
2020-01-24 12:14:08 +01:00
// searchbox widget options
2020-02-11 19:32:50 +01:00
const searchbox_options = {
id : "search" ,
overlay : ( typeof settings . searchbox != 'undefined' && typeof settings . searchbox . overlay != 'undefined' ) ? settings.searchbox.overlay : false ,
2021-08-17 21:56:52 +02:00
onchange : function ( )
{
2020-01-24 12:14:08 +01:00
self . nextmatch . applyFilters ( { search : this.get_value ( ) } ) ;
} ,
2020-02-11 19:32:50 +01:00
value : settings.search ,
fix : ! egwIsMobile ( )
2020-01-24 12:14:08 +01:00
} ;
// searchbox widget
2021-08-17 21:56:52 +02:00
this . et2_searchbox = < et2_searchbox > et2_createWidget ( 'searchbox' , searchbox_options , this ) ;
2020-01-24 12:14:08 +01:00
// Set activeFilters to current value
this . nextmatch . activeFilters . search = settings . search ;
this . et2_searchbox . set_value ( settings . search ) ;
2021-08-17 21:56:52 +02:00
jQuery ( this . et2_searchbox . getInputNode ( ) ) . attr ( "aria-label" , egw . lang ( "search" ) ) ;
2020-01-24 12:14:08 +01:00
/ * *
* Mobile theme specific part for nm header
* nm header has very different behaivior for mobile theme and basically
* it has its own markup separately from nm header in normal templates .
* /
2021-08-17 21:56:52 +02:00
if ( egwIsMobile ( ) )
2020-01-24 12:14:08 +01:00
{
this . search_box . addClass ( 'nm-mob-header' ) ;
2021-08-17 21:56:52 +02:00
jQuery ( this . div ) . css ( { display : 'inline-block' } ) . addClass ( 'nm_header_hide' ) ;
2020-01-24 12:14:08 +01:00
//indicates appname in header
jQuery ( document . createElement ( 'div' ) )
2021-08-17 21:56:52 +02:00
. addClass ( 'nm_appname_header' )
. text ( egw . lang ( egw . app_name ( ) ) )
. appendTo ( this . search_box ) ;
2020-01-24 12:14:08 +01:00
this . delete_action = jQuery ( document . createElement ( 'div' ) )
2021-08-17 21:56:52 +02:00
. addClass ( 'nm_delete_action' )
. prependTo ( this . search_box ) ;
2020-01-24 12:14:08 +01:00
// toggle header
// add new button
this . fav_span = jQuery ( document . createElement ( 'div' ) )
2021-08-17 21:56:52 +02:00
. addClass ( 'nm_favorites_div' )
. prependTo ( this . search_box ) ;
2020-01-24 12:14:08 +01:00
// toggle header menu
this . toggle_header = jQuery ( document . createElement ( 'button' ) )
2021-08-17 21:56:52 +02:00
. addClass ( 'nm_toggle_header' )
. click ( function ( )
{
jQuery ( self . div ) . toggleClass ( 'nm_header_hide' ) ;
jQuery ( this ) . toggleClass ( 'nm_toggle_header_on' ) ;
window . setTimeout ( function ( )
{
self . nextmatch . resize ( ) ;
} , 800 ) ;
} )
. prependTo ( this . search_box ) ;
2020-01-24 12:14:08 +01:00
// Context menu
this . action_header = jQuery ( document . createElement ( 'button' ) )
2021-08-17 21:56:52 +02:00
. addClass ( 'nm_action_header' )
. hide ( )
. click ( function ( e )
{
// @ts-ignore
jQuery ( 'tr.selected' , self . nextmatch . getDOMNode ( ) ) . trigger ( {
type : 'contextmenu' ,
which : 3 ,
originalEvent : e
} ) ;
} )
. prependTo ( this . search_box ) ;
2020-01-24 12:14:08 +01:00
}
// Add category
2021-08-17 21:56:52 +02:00
if ( ! settings . no_cat )
{
if ( typeof settings . cat_id_label == 'undefined' ) settings . cat_id_label = '' ;
2020-01-24 12:14:08 +01:00
this . category = this . _build_select ( 'cat_id' , settings . cat_is_select ?
2021-08-17 21:56:52 +02:00
'select' : 'select-cat' , settings . cat_id , settings . cat_is_select !== true , {
2020-01-24 12:14:08 +01:00
multiple : false ,
tags : true ,
class : "select-cat" ,
value_class : settings.cat_id_class
} ) ;
}
// Filter 1
2021-08-17 21:56:52 +02:00
if ( ! settings . no_filter )
{
2020-01-24 12:14:08 +01:00
this . filter = this . _build_select ( 'filter' , 'select' , settings . filter , settings . filter_no_lang ) ;
}
// Filter 2
2021-08-17 21:56:52 +02:00
if ( ! settings . no_filter2 )
{
2020-01-24 12:14:08 +01:00
this . filter2 = this . _build_select ( 'filter2' , 'select' , settings . filter2 ,
2021-08-17 21:56:52 +02:00
settings . filter2_no_lang , {
multiple : false ,
tags : settings.filter2_tags ,
class : "select-cat" ,
value_class : settings.filter2_class
} ) ;
2020-01-24 12:14:08 +01:00
}
// Other stuff
this . right_div = jQuery ( document . createElement ( "div" ) )
. addClass ( 'header_row_right' ) . appendTo ( this . row_div ) ;
// Record count
this . count = jQuery ( document . createElement ( "span" ) )
. addClass ( "header_count ui-corner-all" ) ;
// Need to figure out how to update this as grid scrolls
// this.count.append("? - ? ").append(egw.lang("of")).append(" ");
this . count_total = jQuery ( document . createElement ( "span" ) )
. appendTo ( this . count )
. text ( settings . total + "" ) ;
this . count . prependTo ( this . right_div ) ;
// Favorites
this . _setup_favorites ( settings [ 'favorites' ] ) ;
// Export
if ( typeof settings . csv_fields != "undefined" && settings . csv_fields != false )
{
2020-02-11 19:32:50 +01:00
let definition = settings . csv_fields ;
2020-01-24 12:14:08 +01:00
if ( settings . csv_fields === true )
{
2020-02-11 19:32:50 +01:00
definition = egw . preference ( 'nextmatch-export-definition' , this . nextmatch . egw ( ) . app_name ( ) ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
let button = < et2_button > et2_createWidget ( "buttononly" , {
id : "export" ,
"statustext" : "Export" ,
image : "download" ,
"background_image" : true
} , this ) ;
2020-01-24 12:14:08 +01:00
jQuery ( button . getDOMNode ( ) )
2021-08-17 21:56:52 +02:00
. click ( this . nextmatch , function ( event )
{
2020-01-24 12:14:08 +01:00
// @ts-ignore
2021-08-17 21:56:52 +02:00
egw_openWindowCentered2 ( egw . link ( '/index.php' , {
'menuaction' : 'importexport.importexport_export_ui.export_dialog' ,
'appname' : event . data . egw ( ) . getAppName ( ) ,
'definition' : definition
2020-01-24 12:14:08 +01:00
} ) , '_blank' , 850 , 440 , 'yes' ) ;
} ) ;
}
// Another place to customize nextmatch
this . header_row = jQuery ( document . createElement ( "div" ) )
. addClass ( 'header_row' ) . appendTo ( this . right_div ) ;
// Letter search
2020-02-11 19:32:50 +01:00
const current_letter = this . nextmatch . options . settings . searchletter ?
2021-08-17 21:56:52 +02:00
this . nextmatch . options . settings . searchletter :
( this . nextmatch . activeFilters ? this . nextmatch.activeFilters.searchletter : false ) ;
2020-01-24 12:14:08 +01:00
if ( this . nextmatch . options . settings . lettersearch || current_letter )
{
this . lettersearch = jQuery ( document . createElement ( "table" ) )
. addClass ( 'nextmatch_lettersearch' )
. css ( "width" , "100%" )
. appendTo ( this . div ) ;
2020-02-11 19:32:50 +01:00
const tbody = jQuery ( document . createElement ( "tbody" ) ) . appendTo ( this . lettersearch ) ;
const row = jQuery ( document . createElement ( "tr" ) ) . appendTo ( tbody ) ;
2020-01-24 12:14:08 +01:00
// Capitals, A-Z
2020-02-11 19:32:50 +01:00
const letters = this . egw ( ) . lang ( 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) . split ( '' ) ;
2021-08-17 21:56:52 +02:00
for ( let i in letters )
{
2020-01-24 12:14:08 +01:00
button = jQuery ( document . createElement ( "td" ) )
. addClass ( "lettersearch" )
. appendTo ( row )
. attr ( "id" , letters [ i ] )
. text ( letters [ i ] ) ;
if ( letters [ i ] == current_letter ) button . addClass ( "lettersearch_active" ) ;
}
button = jQuery ( document . createElement ( "td" ) )
. addClass ( "lettersearch" )
. appendTo ( row )
. attr ( "id" , "" )
. text ( egw . lang ( "all" ) ) ;
if ( ! current_letter ) button . addClass ( "lettersearch_active" ) ;
2021-08-17 21:56:52 +02:00
this . lettersearch . click ( this . nextmatch , function ( event )
{
2020-01-24 12:14:08 +01:00
// this is the lettersearch table
2021-08-17 21:56:52 +02:00
jQuery ( "td" , this ) . removeClass ( "lettersearch_active" ) ;
2020-01-24 12:14:08 +01:00
jQuery ( event . target ) . addClass ( "lettersearch_active" ) ;
event . data . applyFilters ( { searchletter : event.target.id || false } ) ;
} ) ;
// Set activeFilters to current value
this . nextmatch . activeFilters . searchletter = current_letter ;
}
// Apply letter search preference
2020-02-11 19:32:50 +01:00
const lettersearch_preference = "nextmatch-" + this . nextmatch . options . settings . columnselection_pref + "-lettersearch" ;
2021-08-17 21:56:52 +02:00
if ( this . lettersearch && ! egw . preference ( lettersearch_preference , this . nextmatch . egw ( ) . app_name ( ) ) )
2020-01-24 12:14:08 +01:00
{
this . lettersearch . hide ( ) ;
}
}
/ * *
* Build & bind to a sub - template into the header
*
* @param { string } location One of left , right , or row
* @param { string } template_name Name of the template to load into the location
* /
2021-08-17 21:56:52 +02:00
_build_header ( location : "left" | "right" | "row" , template_name : string )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const id = location == "left" ? 0 : ( location == "right" ? 1 : 2 ) ;
const existing = this . headers [ id ] ;
2020-01-24 12:14:08 +01:00
// @ts-ignore
if ( existing && existing . _type )
{
if ( existing . id == template_name ) return ;
( < et2_widget > < unknown > existing ) . destroy ( ) ;
this . headers [ id ] = null ;
}
2020-01-24 14:43:08 +01:00
if ( ! template_name ) return ;
2020-01-24 12:14:08 +01:00
// Load the template
2020-02-11 19:32:50 +01:00
const self = this ;
2021-08-17 21:56:52 +02:00
const header = < et2_template > et2_createWidget ( "template" , { "id" : template_name } , this ) ;
2020-01-24 12:14:08 +01:00
this . headers [ id ] = header ;
2020-02-11 19:32:50 +01:00
const deferred = [ ] ;
2020-01-24 12:14:08 +01:00
header . loadingFinished ( deferred ) ;
// Wait until all child widgets are loaded, then bind
2021-08-17 21:56:52 +02:00
jQuery . when . apply ( jQuery , deferred ) . then ( function ( )
{
2020-01-24 12:14:08 +01:00
// fix order in DOM by reattaching templates in correct position
2021-08-17 21:56:52 +02:00
switch ( id )
{
2020-01-24 12:14:08 +01:00
case 0 : // header_left: prepend
jQuery ( header . getDOMNode ( ) ) . prependTo ( self . header_div ) ;
break ;
case 1 : // header_right: before favorites and count
jQuery ( header . getDOMNode ( ) ) . prependTo ( self . header_div . find ( 'div.header_row_right' ) ) ;
break ;
case 2 : // header_row: after search
2021-08-17 21:56:52 +02:00
window . setTimeout ( function ( )
{ // otherwise we might end up after filters
2020-01-24 12:14:08 +01:00
jQuery ( header . getDOMNode ( ) ) . insertAfter ( self . header_div . find ( 'div.search' ) ) ;
} , 1 ) ;
break ;
}
self . _bindHeaderInput ( header ) ;
} ) ;
}
/ * *
* Build the selectbox filters in the header bar
* Sets value , options , labels , and change handlers
*
* @param { string } name
* @param { string } type
* @param { string } value
* @param { string } lang
* @param { object } extra
* /
2021-08-17 21:56:52 +02:00
_build_select ( name : string , type : string , value : string , lang : string | boolean , extra? : object ) : et2_selectbox
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const widget_options = jQuery . extend ( {
2020-01-24 12:14:08 +01:00
"id" : name ,
2020-02-11 19:32:50 +01:00
"label" : this . nextmatch . options . settings [ name + "_label" ] ,
2020-01-24 12:14:08 +01:00
"no_lang" : lang ,
2020-02-11 19:32:50 +01:00
"disabled" : this . nextmatch . options [ 'no_' + name ]
2020-01-24 12:14:08 +01:00
} , extra ) ;
// Set select options
// Check in content for options-<name>
2020-02-11 19:32:50 +01:00
const mgr = this . nextmatch . getArrayMgr ( "content" ) ;
let options = mgr . getEntry ( "options-" + name ) ;
2020-01-24 12:14:08 +01:00
// Look in sel_options
if ( ! options ) options = this . nextmatch . getArrayMgr ( "sel_options" ) . getEntry ( name ) ;
// Check parent sel_options, because those are usually global and don't get passed down
2020-01-24 14:43:08 +01:00
if ( ! options ) options = this . nextmatch . getArrayMgr ( "sel_options" ) . getParentMgr ( ) ? . getEntry ( name ) ;
2020-01-24 12:14:08 +01:00
// Sometimes legacy stuff puts it in here
2021-08-17 21:56:52 +02:00
if ( ! options ) options = mgr . getEntry ( 'rows[sel_options][' + name + ']' ) ;
2020-01-24 12:14:08 +01:00
// Maybe in a row, and options got stuck in ${row} instead of top level
2020-02-11 19:32:50 +01:00
const row_stuck = [ '${row}' , '{$row}' ] ;
for ( let i = 0 ; ! options && i < row_stuck . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
let row_id = '' ;
2020-01-24 12:14:08 +01:00
if ( ( ! options || options . length == 0 ) && (
// perspectiveData.row in nm, data["${row}"] in an auto-repeat grid
this . nextmatch . getArrayMgr ( "sel_options" ) . perspectiveData . row || this . nextmatch . getArrayMgr ( "sel_options" ) . data [ row_stuck [ i ] ] ) )
{
2021-08-17 21:56:52 +02:00
row_id = name . replace ( /[0-9]+/ , row_stuck [ i ] ) ;
2020-01-24 12:14:08 +01:00
options = this . nextmatch . getArrayMgr ( "sel_options" ) . getEntry ( row_id ) ;
if ( ! options )
{
2021-08-17 21:56:52 +02:00
row_id = row_stuck [ i ] + "[" + name + "]" ;
2020-01-24 12:14:08 +01:00
options = this . nextmatch . getArrayMgr ( "sel_options" ) . getEntry ( row_id ) ;
}
}
if ( options )
{
2021-08-17 21:56:52 +02:00
this . egw ( ) . debug ( 'warn' , 'Nextmatch filter options in a weird place - "%s". Should be in sel_options[%s].' , row_id , name ) ;
2020-01-24 12:14:08 +01:00
}
}
// Legacy: Add in 'All' option for cat_id, if not provided.
if ( name == 'cat_id' && options != null && ( typeof options [ '' ] == 'undefined' && typeof options [ 0 ] != 'undefined' && options [ 0 ] . value != '' ) )
{
widget_options . empty_label = this . egw ( ) . lang ( 'All categories' ) ;
}
// Create widget
2020-02-11 19:32:50 +01:00
const select = et2_createWidget ( type , widget_options , this ) ;
2020-01-24 12:14:08 +01:00
if ( options ) select . set_select_options ( options ) ;
// Set value
select . set_value ( value ) ;
// Set activeFilters to current value
this . nextmatch . activeFilters [ select . id ] = select . get_value ( ) ;
// Set onChange
2020-02-11 19:32:50 +01:00
const input = select . input ;
2020-01-24 12:14:08 +01:00
// Tell framework to ignore, or it will reset it to ''/empty when it does loadingFinished()
select . attributes . select_options . ignore = true ;
2021-08-17 21:56:52 +02:00
if ( this . nextmatch . options . settings [ name + "_onchange" ] )
2020-01-24 12:14:08 +01:00
{
// Get the onchange function string
2020-02-11 19:32:50 +01:00
let onchange = this . nextmatch . options . settings [ name + "_onchange" ] ;
2020-01-24 12:14:08 +01:00
// Real submits cause all sorts of problems
if ( onchange . match ( /this\.form\.submit/ ) )
{
2021-08-17 21:56:52 +02:00
this . egw ( ) . debug ( "warn" , "%s tries to submit form, which is not allowed. Filter changes automatically refresh data with no reload." , name ) ;
onchange = onchange . replace ( /this\.form\.submit\([^)]*\);?/ , 'return true;' ) ;
2020-01-24 12:14:08 +01:00
}
// Connect it to the onchange event of the input element - may submit
select . change = et2_compileLegacyJS ( onchange , this . nextmatch , select . getInputNode ( ) ) ;
this . _bindHeaderInput ( select ) ;
}
else // default request changed rows with new filters, previous this.form.submit()
{
2021-08-17 21:56:52 +02:00
input . change ( this . nextmatch , function ( event )
{
2020-02-11 19:32:50 +01:00
const set = { } ;
2020-01-24 12:14:08 +01:00
set [ name ] = select . getValue ( ) ;
event . data . applyFilters ( set ) ;
} ) ;
}
return select ;
}
/ * *
* Set up the favorites UI control
*
* @param filters Array | boolean The nextmatch setting for favorites . Either true , or a list of
* additional fields / settings to add in to the favorite .
* /
2021-08-17 21:56:52 +02:00
_setup_favorites ( filters )
2020-01-24 12:14:08 +01:00
{
if ( typeof filters == "undefined" || filters === false )
{
// No favorites configured
return ;
}
2020-02-11 19:32:50 +01:00
const widget_options = {
2020-01-24 12:14:08 +01:00
default_pref : "nextmatch-" + this . nextmatch . options . settings . columnselection_pref + "-favorite" ,
2020-05-22 18:50:36 +02:00
app : this.getInstanceManager ( ) . app ,
2020-01-24 12:14:08 +01:00
filters : filters ,
2020-05-22 18:50:36 +02:00
sidebox_target : 'favorite_sidebox_' + this . getInstanceManager ( ) . app
2020-01-24 12:14:08 +01:00
} ;
this . favorites = et2_createWidget ( 'favorites' , widget_options , this ) ;
// Add into header
2021-08-17 21:56:52 +02:00
jQuery ( this . favorites . getDOMNode ( this . favorites ) ) . prependTo ( egwIsMobile ( ) ? this . search_box . find ( '.nm_favorites_div' ) . show ( ) : this . right_div ) ;
2020-01-24 12:14:08 +01:00
}
/ * *
* Updates all the filter elements in the header
*
* Does not actually refresh the data , just sets values to match those given .
* Called by et2_nextmatch . applyFilters ( ) .
*
* @param filters Array Key = > Value pairs of current filters
* /
2021-08-17 21:56:52 +02:00
setFilters ( filters )
2020-01-24 12:14:08 +01:00
{
// Avoid loops cause by change events
if ( this . update_in_progress ) return ;
this . update_in_progress = true ;
// Use an array mgr to hande non-simple IDs
2020-02-11 19:32:50 +01:00
const mgr = new et2_arrayMgr ( filters ) ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
this . iterateOver ( function ( child )
{
2020-01-24 12:14:08 +01:00
// Skip favorites, don't want them in the filter
if ( typeof child . id != "undefined" && child . id . indexOf ( "favorite" ) == 0 ) return ;
let value : string | object = '' ;
if ( typeof child . set_value != "undefined" && child . id )
{
value = mgr . getEntry ( child . id ) ;
2021-08-17 21:56:52 +02:00
if ( value == null ) value = '' ;
2020-01-24 12:14:08 +01:00
/ * *
* Sometimes a filter value is not in current options . This can
* happen in a saved favorite , for example , or if server changes
* some filter options , and the order doesn ' t work out . The normal behaviour
* is to warn & not set it , but for nextmatch we ' ll just add it
* in , and let the server either set it properly , or ignore .
* /
if ( value && typeof value != 'object' && child . instanceOf ( et2_selectbox ) )
{
2020-02-11 19:32:50 +01:00
let found = typeof child . options . select_options [ value ] != 'undefined' ;
2020-01-24 12:14:08 +01:00
// options is array of objects with attribute value&label
2021-08-17 21:56:52 +02:00
if ( jQuery . isArray ( child . options . select_options ) )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
for ( let o = 0 ; o < child . options . select_options . length ; ++ o )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( child . options . select_options [ o ] . value == value )
2020-01-24 12:14:08 +01:00
{
found = true ;
break ;
}
}
}
2021-08-17 21:56:52 +02:00
if ( ! found )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const old_options = child . options . select_options ;
2020-01-24 12:14:08 +01:00
// Actual label is not available, obviously, or it would be there
old_options [ value ] = child . egw ( ) . lang ( "Loading" ) ;
child . set_select_options ( old_options ) ;
}
}
child . set_value ( value ) ;
}
if ( typeof child . get_value == "function" && child . id )
{
// Put data in the proper place
2020-02-11 19:32:50 +01:00
let target = this ;
2020-01-24 12:14:08 +01:00
value = child . get_value ( ) ;
// Split up indexes
2020-02-11 19:32:50 +01:00
const indexes = child . id . replace ( /[/g , '[' ) . split ( '[' ) ;
2020-01-24 12:14:08 +01:00
2020-02-11 19:32:50 +01:00
for ( let i = 0 ; i < indexes . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
indexes [ i ] = indexes [ i ] . replace ( /]/g , '' ) . replace ( ']' , '' ) ;
if ( i < indexes . length - 1 )
2020-01-24 12:14:08 +01:00
{
if ( typeof target [ indexes [ i ] ] == "undefined" ) target [ indexes [ i ] ] = { } ;
target = target [ indexes [ i ] ] ;
}
else
{
target [ indexes [ i ] ] = value ;
}
}
}
} , filters ) ;
// Letter search
if ( this . nextmatch . options . settings . lettersearch )
{
2021-08-17 21:56:52 +02:00
jQuery ( "td" , this . lettersearch ) . removeClass ( "lettersearch_active" ) ;
jQuery ( filters . searchletter ? "td#" + filters . searchletter : "td.lettersearch[id='']" , this . lettersearch ) . addClass ( "lettersearch_active" ) ;
2020-01-24 12:14:08 +01:00
// Set activeFilters to current value
2021-08-17 21:56:52 +02:00
filters . searchletter = jQuery ( "td.lettersearch_active" , this . lettersearch ) . attr ( "id" ) || false ;
2020-01-24 12:14:08 +01:00
}
// Reset flag
this . update_in_progress = false ;
}
/ * *
* Help out nextmatch / widget stuff by checking to see if sender is part of header
*
* @param { et2_widget } _sender
* /
2021-08-17 21:56:52 +02:00
getDOMNode ( _sender )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const filters = [ this . category , this . filter , this . filter2 ] ;
for ( let i = 0 ; i < filters . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
if ( _sender == filters [ i ] )
{
// Give them the filter div
return this . filter_div [ 0 ] ;
}
}
if ( _sender == this . et2_searchbox ) return this . search_box [ 0 ] ;
if ( _sender . id == 'export' ) return this . right_div [ 0 ] ;
if ( _sender && _sender . _type == "template" )
{
2020-02-11 19:32:50 +01:00
for ( let i = 0 ; i < this . headers . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
if ( _sender . id == this . headers [ i ] . id && _sender . _parent == this ) return i == 2 ? this . header_row [ 0 ] : this . header_div [ 0 ] ;
}
}
return null ;
}
/ * *
* Bind all the inputs in the header sub - templates to update the filters
* on change , and update current filter with the inputs ' current values
*
* @param { et2_template } sub_header
* /
2021-08-17 21:56:52 +02:00
_bindHeaderInput ( sub_header )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const header = this ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
const bind_change = function ( _widget )
{
2020-01-24 12:14:08 +01:00
// Previously set change function
2020-02-11 19:32:50 +01:00
const widget_change = _widget . change ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
let change = function ( _node )
{
2020-01-24 12:14:08 +01:00
// Call previously set change function
2020-08-11 15:45:40 +02:00
const result = widget_change . call ( _widget , _node , header . nextmatch ) ;
2020-01-24 12:14:08 +01:00
2020-10-19 21:17:09 +02:00
// Find current value in activeFilters
let entry = header . nextmatch . activeFilters ;
const path = _widget . getArrayMgr ( 'content' ) . explodeKey ( _widget . id ) ;
let i = 0 ;
2021-08-17 21:56:52 +02:00
if ( path . length > 0 )
{
for ( ; i < path . length ; i ++ )
{
2020-10-19 21:17:09 +02:00
entry = entry [ path [ i ] ] ;
}
}
2020-01-24 12:14:08 +01:00
2020-10-19 21:17:09 +02:00
// Update filters, if the value is different and we're not already doing so
2021-08-17 21:56:52 +02:00
if ( ( result || typeof result === 'undefined' ) && entry != _widget . getValue ( ) && ! header . update_in_progress )
2020-10-19 21:17:09 +02:00
{
2020-01-24 12:14:08 +01:00
// Widget will not have an entry in getValues() because nulls
// are not returned, we remove it from activeFilters
2021-08-17 21:56:52 +02:00
if ( _widget . _oldValue == null )
{
2020-02-11 19:32:50 +01:00
const path = _widget . getArrayMgr ( 'content' ) . explodeKey ( _widget . id ) ;
2021-08-17 21:56:52 +02:00
if ( path . length > 0 )
{
2020-02-11 19:32:50 +01:00
let entry = header . nextmatch . activeFilters ;
let i = 0 ;
2021-08-17 21:56:52 +02:00
for ( ; i < path . length - 1 ; i ++ )
{
2020-01-24 12:14:08 +01:00
entry = entry [ path [ i ] ] ;
}
delete entry [ path [ i ] ] ;
}
header . nextmatch . applyFilters ( header . nextmatch . activeFilters ) ;
2021-08-17 21:56:52 +02:00
}
else
{
2020-01-24 12:14:08 +01:00
// Not null is easy, just get values
2020-02-11 19:32:50 +01:00
const value = this . getInstanceManager ( ) . getValues ( sub_header ) ;
2020-01-24 12:14:08 +01:00
header . nextmatch . applyFilters ( value [ header . nextmatch . id ] ) ;
}
}
// In case this gets bound twice, it's important to return
return true ;
} ;
_widget . change = change ;
// Set activeFilters to current value
// Use an array mgr to hande non-simple IDs
var value = { } ;
value [ _widget . id ] = _widget . _oldValue = _widget . getValue ( ) ;
2020-02-11 19:32:50 +01:00
const mgr = new et2_arrayMgr ( value ) ;
jQuery . extend ( true , this . nextmatch . activeFilters , mgr . data ) ;
2020-01-24 12:14:08 +01:00
} ;
if ( sub_header . instanceOf ( et2_inputWidget ) )
{
bind_change . call ( this , sub_header ) ;
}
else
{
sub_header . iterateOver ( bind_change , this , et2_inputWidget ) ;
}
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch_header_bar , [ "nextmatch_header_bar" ] ) ;
/ * *
* Classes for the nextmatch sortheaders etc .
*
* @augments et2_baseWidget
* /
export class et2_nextmatch_header extends et2_baseWidget implements et2_INextmatchHeader
{
2021-08-17 21:56:52 +02:00
static readonly _attributes : any = {
2020-01-24 12:14:08 +01:00
"label" : {
"name" : "Caption" ,
"type" : "string" ,
"description" : "Caption for the nextmatch header" ,
"translate" : true
}
} ;
2021-08-17 21:56:52 +02:00
protected labelNode : JQuery ;
protected nextmatch : et2_nextmatch ;
private label : string ;
2020-01-24 12:14:08 +01:00
/ * *
* Constructor
*
* @memberOf et2_nextmatch_header
* /
2021-08-17 21:56:52 +02:00
constructor ( _parent ? , _attrs? : WidgetConfig , _child? : object )
{
2020-01-24 12:14:08 +01:00
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2_nextmatch_header . _attributes , _child || { } ) ) ;
this . labelNode = jQuery ( document . createElement ( "span" ) ) ;
this . nextmatch = null ;
this . setDOMNode ( this . labelNode [ 0 ] ) ;
}
/ * *
* Set nextmatch is the function which has to be implemented for the
* et2_INextmatchHeader interface .
*
* @param { et2_nextmatch } _nextmatch
* /
2021-08-17 21:56:52 +02:00
setNextmatch ( _nextmatch )
2020-01-24 12:14:08 +01:00
{
this . nextmatch = _nextmatch ;
}
2021-08-17 21:56:52 +02:00
set_label ( _value )
2020-01-24 12:14:08 +01:00
{
this . label = _value ;
this . labelNode . text ( _value ) ;
// add class if label is empty
this . labelNode . toggleClass ( 'et2_label_empty' , ! _value ) ;
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch_header , [ 'nextmatch-header' ] ) ;
/ * *
* Extend header to process customfields
*
* @augments et2_customfields_list
2020-01-24 13:57:05 +01:00
*
2020-01-24 14:43:08 +01:00
* TODO This should extend customfield widget when it ' s ready , put the whole column in constructor ( ) back too
2020-01-24 12:14:08 +01:00
* /
2020-02-12 19:16:34 +01:00
export class et2_nextmatch_customfields extends et2_customfields_list implements et2_INextmatchHeader
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
static readonly _attributes : any = {
2020-01-24 12:14:08 +01:00
'customfields' : {
'name' : 'Custom fields' ,
'description' : 'Auto filled'
} ,
'fields' : {
'name' : "Visible fields" ,
"description" : "Auto filled"
}
} ;
2021-08-17 21:56:52 +02:00
private nextmatch : et2_nextmatch ;
2020-01-24 12:14:08 +01:00
/ * *
* Constructor
*
* @memberOf et2_nextmatch_customfields
* /
2021-08-17 21:56:52 +02:00
constructor ( _parent ? , _attrs? : WidgetConfig , _child? : object )
{
2020-01-24 12:14:08 +01:00
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2_nextmatch_customfields . _attributes , _child || { } ) ) ;
// Specifically take the whole column
2020-02-12 19:16:34 +01:00
this . table . css ( "width" , "100%" ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
destroy ( )
2020-01-24 12:14:08 +01:00
{
this . nextmatch = null ;
super . destroy ( ) ;
}
2021-08-17 21:56:52 +02:00
transformAttributes ( _attrs )
2020-01-24 12:14:08 +01:00
{
super . transformAttributes ( _attrs ) ;
// Add in settings that are objects
if ( ! _attrs . customfields )
{
// Check for custom stuff (unlikely)
2020-02-11 19:32:50 +01:00
let data = this . getArrayMgr ( "modifications" ) . getEntry ( this . id ) ;
2020-01-24 12:14:08 +01:00
// Check for global settings
if ( ! data ) data = this . getArrayMgr ( "modifications" ) . getRoot ( ) . getEntry ( '~custom_fields~' , true ) ;
2020-02-11 19:32:50 +01:00
for ( let key in data )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( typeof data [ key ] === 'object' && ! _attrs [ key ] ) _attrs [ key ] = data [ key ] ;
2020-01-24 12:14:08 +01:00
}
}
}
2021-08-17 21:56:52 +02:00
setNextmatch ( _nextmatch )
2020-01-24 12:14:08 +01:00
{
this . nextmatch = _nextmatch ;
this . loadFields ( ) ;
}
/ * *
* Build widgets for header - sortable for numeric , text , etc . , filterables for selectbox , radio
* /
2021-08-17 21:56:52 +02:00
loadFields ( )
2020-01-24 12:14:08 +01:00
{
2020-02-12 19:16:34 +01:00
if ( this . nextmatch == null )
2020-01-24 12:14:08 +01:00
{
// not ready yet
return ;
}
2020-02-11 19:32:50 +01:00
let columnMgr = this . nextmatch . dataview . getColumnMgr ( ) ;
let nm_column = null ;
const set_fields = { } ;
for ( let i = 0 ; i < this . nextmatch . columns . length ; i ++ )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
// @ts-ignore
2020-01-24 12:14:08 +01:00
if ( this . nextmatch . columns [ i ] . widget == this )
{
nm_column = columnMgr . columns [ i ] ;
break ;
}
}
if ( ! nm_column ) return ;
// Check for global setting changes (visibility)
2020-02-11 19:32:50 +01:00
const global_data = this . getArrayMgr ( "modifications" ) . getRoot ( ) . getEntry ( '~custom_fields~' ) ;
2020-01-24 12:14:08 +01:00
if ( global_data != null && global_data . fields ) this . options . fields = global_data . fields ;
2020-02-11 19:32:50 +01:00
const apps = egw . link_app_list ( ) ;
for ( let field_name in this . options . customfields )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const field = this . options . customfields [ field_name ] ;
2020-02-12 19:32:29 +01:00
const cf_id = et2_customfields_list . PREFIX + field_name ;
2020-01-24 12:14:08 +01:00
if ( this . rows [ field_name ] ) continue ;
// Table row
2020-02-11 19:32:50 +01:00
const row = jQuery ( document . createElement ( "tr" ) )
. appendTo ( this . tbody ) ;
const cf = jQuery ( document . createElement ( "td" ) )
. appendTo ( row ) ;
2020-01-24 12:14:08 +01:00
this . rows [ cf_id ] = cf [ 0 ] ;
// Create widget by type
2020-02-11 19:32:50 +01:00
let widget = null ;
2020-01-24 12:14:08 +01:00
if ( field . type == 'select' || field . type == 'select-account' )
{
if ( field . values && typeof field . values [ '' ] !== 'undefined' )
{
2021-08-17 21:56:52 +02:00
delete ( field . values [ '' ] ) ;
2020-01-24 12:14:08 +01:00
}
widget = et2_createWidget (
field . type == 'select-account' ? 'nextmatch-accountfilter' : "nextmatch-filterheader" ,
{
id : cf_id ,
empty_label : field.label ,
select_options : field.values
} ,
this
) ;
}
2021-08-17 21:56:52 +02:00
else if ( apps [ field . type ] )
2020-01-24 12:14:08 +01:00
{
widget = et2_createWidget ( "nextmatch-entryheader" , {
id : cf_id ,
only_app : field.type ,
blur : field.label
} , this ) ;
}
else
{
widget = et2_createWidget ( "nextmatch-sortheader" , {
id : cf_id ,
label : field.label
} , this ) ;
}
// If this is already attached, widget needs to be finished explicitly
if ( this . isAttached ( ) && ! widget . isAttached ( ) )
{
widget . loadingFinished ( ) ;
}
// Check for column filter
if ( ! jQuery . isEmptyObject ( this . options . fields ) && (
this . options . fields [ field_name ] == false || typeof this . options . fields [ field_name ] == 'undefined' ) )
{
cf . hide ( ) ;
}
2021-08-17 21:56:52 +02:00
else if ( jQuery . isEmptyObject ( this . options . fields ) )
2020-01-24 12:14:08 +01:00
{
// If we're showing it make sure it's set, but only after
set_fields [ field_name ] = true ;
}
}
jQuery . extend ( this . options . fields , set_fields ) ;
}
/ * *
* Override parent so we can update the nextmatch row too
*
* @param { array } _fields
* /
2021-08-17 21:56:52 +02:00
set_visible ( _fields )
2020-01-24 12:14:08 +01:00
{
super . set_visible ( _fields ) ;
// Find data row, and do it too
2020-02-11 19:32:50 +01:00
const self = this ;
2020-01-24 12:14:08 +01:00
if ( this . nextmatch )
{
this . nextmatch . iterateOver (
2021-08-17 21:56:52 +02:00
function ( widget )
{
2020-01-24 12:14:08 +01:00
if ( widget == self ) return ;
widget . set_visible ( _fields ) ;
} , this , et2_customfields_list
) ;
}
}
/ * *
* Provide own column caption ( column selection )
*
* If only one custom field , just use that , otherwise use "custom fields"
* /
2021-08-17 21:56:52 +02:00
_genColumnCaption ( )
2020-01-24 12:14:08 +01:00
{
return egw . lang ( "Custom fields" ) ;
}
/ * *
* Provide own column naming , including only selected columns - only useful
* to nextmatch itself , not for sending server - side
* /
2021-08-17 21:56:52 +02:00
_getColumnName ( )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
let name = this . id ;
const visible = [ ] ;
2020-01-24 12:14:08 +01:00
for ( var field_name in this . options . customfields )
{
if ( jQuery . isEmptyObject ( this . options . fields ) || this . options . fields [ field_name ] == true )
{
2020-02-12 19:32:29 +01:00
visible . push ( et2_customfields_list . PREFIX + field_name ) ;
2020-01-24 12:14:08 +01:00
jQuery ( this . rows [ field_name ] ) . show ( ) ;
}
2021-08-17 21:56:52 +02:00
else if ( typeof this . rows [ field_name ] != "undefined" )
2020-01-24 12:14:08 +01:00
{
jQuery ( this . rows [ field_name ] ) . hide ( ) ;
}
}
2021-08-17 21:56:52 +02:00
if ( visible . length )
{
name += "_" + visible . join ( "_" ) ;
2020-01-24 12:14:08 +01:00
}
2021-08-17 21:56:52 +02:00
else if ( this . rows )
2020-01-24 12:14:08 +01:00
{
// None hidden means all visible
jQuery ( this . rows [ field_name ] ) . parent ( ) . parent ( ) . children ( ) . show ( ) ;
}
// Update global custom fields column(s) - widgets will check on their own
// Check for custom stuff (unlikely)
2020-02-11 19:32:50 +01:00
let data = this . getArrayMgr ( "modifications" ) . getEntry ( this . id ) ;
2020-01-24 12:14:08 +01:00
// Check for global settings
if ( ! data ) data = this . getArrayMgr ( "modifications" ) . getRoot ( ) . getEntry ( '~custom_fields~' , true ) || { } ;
if ( ! data . fields ) data . fields = { } ;
2020-02-11 19:32:50 +01:00
for ( let field in this . options . customfields )
2020-01-24 12:14:08 +01:00
{
data . fields [ field ] = ( this . options . fields == null || typeof this . options . fields [ field ] == 'undefined' ? false : this . options . fields [ field ] ) ;
}
return name ;
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch_customfields , [ 'nextmatch-customfields' ] ) ;
/ * *
* @augments et2_nextmatch_header
* /
// @ts-ignore
export class et2_nextmatch_sortheader extends et2_nextmatch_header implements et2_INextmatchSortable
{
2021-08-17 21:56:52 +02:00
static readonly _attributes : any = {
2020-01-24 12:14:08 +01:00
"sortmode" : {
"name" : "Sort order" ,
"type" : "string" ,
"description" : "Default sort order" ,
"translate" : false
}
} ;
2021-08-17 21:56:52 +02:00
public static readonly legacyOptions : [ 'sortmode' ] ;
private sortmode : string ;
2020-01-24 12:14:08 +01:00
/ * *
* Constructor
*
* @memberOf et2_nextmatch_sortheader
* /
2021-08-17 21:56:52 +02:00
constructor ( _parent ? , _attrs? : WidgetConfig , _child? : object )
{
2020-01-24 12:14:08 +01:00
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2_nextmatch_sortheader . _attributes , _child || { } ) ) ;
this . sortmode = "none" ;
this . labelNode . addClass ( "nextmatch_sortheader none" ) ;
}
2021-08-17 21:56:52 +02:00
click ( _event )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
if ( this . nextmatch && super . click ( _event ) )
2020-01-24 12:14:08 +01:00
{
// Send default sort mode if not sorted, otherwise send undefined to calculate
this . nextmatch . sortBy ( this . id , this . sortmode == "none" ? ! ( this . options . sortmode . toUpperCase ( ) == "DESC" ) : undefined ) ;
return true ;
}
return false ;
}
/ * *
* Wrapper to join up interface * framework
*
* @param { string } _mode
* /
set_sortmode ( _mode )
{
// Set via nextmatch after setup
if ( this . nextmatch ) return ;
this . setSortmode ( _mode ) ;
}
/ * *
* Function which implements the et2_INextmatchSortable function .
*
* @param { string } _mode
* /
2021-08-17 21:56:52 +02:00
setSortmode ( _mode )
2020-01-24 12:14:08 +01:00
{
// Remove the last sortmode class and add the new one
this . labelNode . removeClass ( this . sortmode )
. addClass ( _mode ) ;
this . sortmode = _mode ;
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch_sortheader , [ 'nextmatch-sortheader' ] ) ;
/ * *
2020-02-05 00:07:50 +01:00
* Filter from a provided list of options
2020-01-24 12:14:08 +01:00
* /
export class et2_nextmatch_filterheader extends et2_selectbox implements et2_INextmatchHeader , et2_IResizeable
{
2021-08-17 21:56:52 +02:00
private nextmatch : et2_nextmatch ;
2020-01-24 12:14:08 +01:00
/ * *
* Override to add change handler
* /
2021-08-17 21:56:52 +02:00
createInputWidget ( )
2020-01-24 12:14:08 +01:00
{
// Make sure there's an option for all
if ( ! this . options . empty_label && ( ! this . options . select_options || ! this . options . select_options [ "" ] ) )
{
this . options . empty_label = this . options . label ? this . options.label : egw.lang ( "All" ) ;
}
super . createInputWidget ( ) ;
2021-08-17 21:56:52 +02:00
jQuery ( this . getInputNode ( ) ) . change ( this , function ( event )
{
2020-01-24 12:14:08 +01:00
if ( typeof event . data . nextmatch == 'undefined' )
{
// Not fully set up yet
return ;
}
2020-02-11 19:32:50 +01:00
const col_filter = { } ;
2020-01-24 12:14:08 +01:00
col_filter [ event . data . id ] = event . data . input . val ( ) ;
// Set value so it's there for response (otherwise it gets cleared if options are updated)
event . data . set_value ( event . data . input . val ( ) ) ;
event . data . nextmatch . applyFilters ( { col_filter : col_filter } ) ;
} ) ;
}
/ * *
* Set nextmatch is the function which has to be implemented for the
* et2_INextmatchHeader interface .
*
* @param { et2_nextmatch } _nextmatch
* /
2021-08-17 21:56:52 +02:00
setNextmatch ( _nextmatch )
2020-01-24 12:14:08 +01:00
{
this . nextmatch = _nextmatch ;
// Set current filter value from nextmatch settings
if ( this . nextmatch . activeFilters . col_filter && typeof this . nextmatch . activeFilters . col_filter [ this . id ] != "undefined" )
{
this . set_value ( this . nextmatch . activeFilters . col_filter [ this . id ] ) ;
// Make sure it's set in the nextmatch
_nextmatch . activeFilters . col_filter [ this . id ] = this . getValue ( ) ;
}
}
// Make sure selectbox is not longer than the column
2021-08-17 21:56:52 +02:00
resize ( )
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
this . input . css ( "max-width" , jQuery ( this . parentNode ) . innerWidth ( ) + "px" ) ;
2020-01-24 12:14:08 +01:00
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch_filterheader , [ 'nextmatch-filterheader' ] ) ;
/ * *
2020-02-05 00:07:50 +01:00
* Filter by account
2020-01-24 12:14:08 +01:00
* /
2020-02-12 22:49:22 +01:00
export class et2_nextmatch_accountfilterheader extends et2_selectAccount implements et2_INextmatchHeader , et2_IResizeable
{
/ * *
* Override to add change handler
*
* /
2021-08-17 21:56:52 +02:00
createInputWidget ( )
2020-02-12 22:49:22 +01:00
{
// Make sure there's an option for all
if ( ! this . options . empty_label && ! this . options . select_options [ "" ] )
{
this . options . empty_label = this . options . label ? this . options.label : egw.lang ( "All" ) ;
}
2020-08-05 19:21:18 +02:00
super . createInputWidget ( ) ;
2020-02-12 22:49:22 +01:00
2021-08-17 21:56:52 +02:00
this . input . change ( this , function ( event )
{
2020-02-12 22:49:22 +01:00
if ( typeof event . data . nextmatch == 'undefined' )
{
// Not fully set up yet
return ;
}
var col_filter = { } ;
col_filter [ event . data . id ] = event . data . getValue ( ) ;
event . data . nextmatch . applyFilters ( { col_filter : col_filter } ) ;
} ) ;
}
/ * *
* Set nextmatch is the function which has to be implemented for the
* et2_INextmatchHeader interface .
*
* @param { et2_nextmatch } _nextmatch
* /
2021-08-17 21:56:52 +02:00
setNextmatch ( _nextmatch )
2020-02-12 22:49:22 +01:00
{
this . nextmatch = _nextmatch ;
// Set current filter value from nextmatch settings
if ( this . nextmatch . activeFilters . col_filter && this . nextmatch . activeFilters . col_filter [ this . id ] )
{
this . set_value ( this . nextmatch . activeFilters . col_filter [ this . id ] ) ;
}
}
2021-08-17 21:56:52 +02:00
2020-02-12 22:49:22 +01:00
// Make sure selectbox is not longer than the column
2021-08-17 21:56:52 +02:00
resize ( )
2020-02-12 22:49:22 +01:00
{
var max = jQuery ( this . parentNode ) . innerWidth ( ) - 4 ;
var surroundings = this . getSurroundings ( ) . _widgetSurroundings ;
for ( var i = 0 ; i < surroundings . length ; i ++ )
{
max -= jQuery ( surroundings [ i ] ) . outerWidth ( ) ;
}
2021-08-17 21:56:52 +02:00
this . input . css ( "max-width" , max + "px" ) ;
2020-02-12 22:49:22 +01:00
}
}
2021-08-17 21:56:52 +02:00
2020-02-12 22:49:22 +01:00
et2_register_widget ( et2_nextmatch_accountfilterheader , [ 'nextmatch-accountfilter' ] ) ;
2020-01-24 12:14:08 +01:00
/ * *
* Filter allowing multiple values to be selected , base on a taglist instead
* of a regular selectbox
*
* @augments et2_taglist
* /
2021-08-17 21:56:52 +02:00
export class et2_nextmatch_taglistheader extends et2_taglist implements et2_INextmatchHeader , et2_IResizeable
2020-02-12 22:49:22 +01:00
{
static readonly _attributes : any = {
2021-08-17 21:56:52 +02:00
autocomplete_url : { default : '' } ,
multiple : { default : 'toggle' } ,
2020-02-12 22:49:22 +01:00
onchange : {
// @ts-ignore
2021-08-17 21:56:52 +02:00
default : function ( event )
{
2020-02-12 22:49:22 +01:00
if ( typeof this . nextmatch === 'undefined' )
2021-08-17 21:56:52 +02:00
{
// Not fully set up yet
return ;
}
var col_filter = { } ;
2020-02-12 22:49:22 +01:00
col_filter [ this . id ] = this . getValue ( ) ;
// Set value so it's there for response (otherwise it gets cleared if options are updated)
//event.data.set_value(event.data.input.val());
this . nextmatch . applyFilters ( { col_filter : col_filter } ) ;
}
} ,
2021-08-17 21:56:52 +02:00
rows : { default : 2 } ,
2020-02-12 22:49:22 +01:00
class : { default : 'nm_filterheader_taglist' }
} ;
2021-08-17 21:56:52 +02:00
private nextmatch : et2_nextmatch ;
2020-02-12 22:49:22 +01:00
/ * *
* Override to add change handler
*
* @memberOf et2_nextmatch_filterheader
* /
2021-08-17 21:56:52 +02:00
createInputWidget ( )
2020-02-12 22:49:22 +01:00
{
// Make sure there's an option for all
if ( ! this . options . empty_label && ( ! this . options . select_options || ! this . options . select_options [ "" ] ) )
{
this . options . empty_label = this . options . label ? this . options.label : egw.lang ( "All" ) ;
}
super . createInputWidget ( ) ;
}
/ * *
* Disable toggle if there are 2 or less options
* @param { Object [ ] } options
* /
set_select_options ( options )
{
if ( options && options . length <= 2 && this . options . multiple == 'toggle' )
{
this . set_multiple ( false ) ;
}
super . set_select_options ( options )
}
/ * *
* Set nextmatch is the function which has to be implemented for the
* et2_INextmatchHeader interface .
*
* @param { et2_nextmatch } _nextmatch
* /
2021-08-17 21:56:52 +02:00
setNextmatch ( _nextmatch )
2020-02-12 22:49:22 +01:00
{
this . nextmatch = _nextmatch ;
// Set current filter value from nextmatch settings
if ( this . nextmatch . activeFilters . col_filter && typeof this . nextmatch . activeFilters . col_filter [ this . id ] != "undefined" )
{
this . set_value ( this . nextmatch . activeFilters . col_filter [ this . id ] ) ;
// Make sure it's set in the nextmatch
_nextmatch . activeFilters . col_filter [ this . id ] = this . getValue ( ) ;
}
}
// Make sure selectbox is not longer than the column
2021-08-17 21:56:52 +02:00
resize ( )
2020-02-12 22:49:22 +01:00
{
2021-08-17 21:56:52 +02:00
this . div . css ( "height" , '' ) ;
this . div . css ( "max-width" , jQuery ( this . parentNode ) . innerWidth ( ) + "px" ) ;
2020-02-12 22:49:22 +01:00
super . resize ( ) ;
}
}
2021-08-17 21:56:52 +02:00
2020-02-12 22:49:22 +01:00
et2_register_widget ( et2_nextmatch_taglistheader , [ 'nextmatch-taglistheader' ] ) ;
2020-01-24 12:14:08 +01:00
/ * *
2020-02-05 21:48:50 +01:00
* Nextmatch filter that can filter for a selected entry
2020-01-24 12:14:08 +01:00
* /
2021-08-17 21:56:52 +02:00
export class et2_nextmatch_entryheader extends et2_link_entry implements et2_INextmatchHeader
2020-01-24 12:14:08 +01:00
{
/ * *
* Override to add change handler
*
* @memberOf et2_nextmatch_entryheader
* @param { object } event
* @param { object } selected
* /
2021-08-17 21:56:52 +02:00
onchange ( event , selected )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
const col_filter = { } ;
2020-01-24 12:14:08 +01:00
col_filter [ this . id ] = this . get_value ( ) ;
this . nextmatch . applyFilters . call ( this . nextmatch , { col_filter : col_filter } ) ;
}
/ * *
* Override to always return a string appname :id ( or just id ) for simple ( one real selection )
* cases , parent returns an object . If multiple are selected , or anything other than app and
* id , the original parent value is returned .
* /
2021-08-17 21:56:52 +02:00
getValue ( )
2020-01-24 12:14:08 +01:00
{
2020-02-11 19:32:50 +01:00
let value = super . getValue ( ) ;
2020-01-24 12:14:08 +01:00
if ( typeof value == "object" && value != null )
{
if ( ! value . app || ! value . id ) return null ;
// If array with just one value, use a string instead for legacy server handling
if ( typeof value . id == 'object' && value . id . shift && value . id . length == 1 )
{
value . id = value . id . shift ( ) ;
}
// If simple value, format it legacy string style, otherwise
// we return full value
if ( typeof value . id == 'string' )
{
2021-08-17 21:56:52 +02:00
value = value . app + ":" + value . id ;
2020-01-24 12:14:08 +01:00
}
}
return value ;
}
/ * *
* Set nextmatch is the function which has to be implemented for the
* et2_INextmatchHeader interface .
*
* @param { et2_nextmatch } _nextmatch
* /
2021-08-17 21:56:52 +02:00
setNextmatch ( _nextmatch )
2020-01-24 12:14:08 +01:00
{
this . nextmatch = _nextmatch ;
// Set current filter value from nextmatch settings
if ( this . nextmatch . options . settings . col_filter && this . nextmatch . options . settings . col_filter [ this . id ] )
{
this . set_value ( this . nextmatch . options . settings . col_filter [ this . id ] ) ;
if ( this . getValue ( ) != this . nextmatch . activeFilters . col_filter [ this . id ] )
{
this . nextmatch . activeFilters . col_filter [ this . id ] = this . getValue ( ) ;
}
// Tell framework to ignore, or it will reset it to ''/empty when it does loadingFinished()
this . attributes . value . ignore = true ;
//this.attributes.select_options.ignore = true;
}
// Fire on lost focus, clear filter if user emptied box
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch_entryheader , [ 'nextmatch-entryheader' ] ) ;
/ * *
* @augments et2_nextmatch_filterheader
* /
2021-08-17 21:56:52 +02:00
export class et2_nextmatch_customfilter extends et2_nextmatch_filterheader
2020-01-24 12:14:08 +01:00
{
2021-08-17 21:56:52 +02:00
static readonly _attributes : any = {
2020-01-24 12:14:08 +01:00
"widget_type" : {
"name" : "Actual type" ,
"type" : "string" ,
"description" : "The actual type of widget you should use" ,
"no_lang" : 1
} ,
"widget_options" : {
"name" : "Actual options" ,
"type" : "any" ,
"description" : "The options for the actual widget" ,
"no_lang" : 1 ,
"default" : { }
}
} ;
2021-08-17 21:56:52 +02:00
public static readonly legacyOptions : [ "widget_type" , "widget_options" ] ;
2020-01-24 12:14:08 +01:00
2021-08-17 21:56:52 +02:00
real_node : et2_selectbox ;
2020-01-24 12:14:08 +01:00
/ * *
* Constructor
*
* @param _parent
* @param _attrs
2020-02-11 19:32:50 +01:00
* @param _child
2020-01-24 12:14:08 +01:00
* @memberOf et2_nextmatch_customfilter
* /
2020-02-11 19:32:50 +01:00
constructor ( _parent? : et2_widget , _attrs? : WidgetConfig , _child? : object )
2020-01-24 12:14:08 +01:00
{
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2_nextmatch_customfilter . _attributes , _child || { } ) ) ;
switch ( _attrs . widget_type )
{
case "link-entry" :
_attrs . type = 'nextmatch-entryheader' ;
break ;
default :
if ( _attrs . widget_type . indexOf ( 'select' ) === 0 )
{
_attrs . type = 'nextmatch-filterheader' ;
}
else
{
_attrs . type = _attrs . widget_type ;
}
}
2021-08-17 21:56:52 +02:00
jQuery . extend ( _attrs . widget_options , { id : this.id } ) ;
2020-01-24 12:14:08 +01:00
_attrs . id = '' ;
super ( _parent , _attrs , ClassWithAttributes . extendAttributes ( et2_nextmatch_customfilter . _attributes , _child || { } ) ) ;
this . real_node = et2_createWidget ( _attrs . type , _attrs . widget_options , this . getParent ( ) ) ;
const select_options = [ ] ;
const correct_type = _attrs . type ;
this . real_node [ 'type' ] = _attrs . widget_type ;
et2_selectbox . find_select_options ( this . real_node , select_options , _attrs ) ;
this . real_node [ "_type" ] = correct_type ;
if ( typeof this . real_node . set_select_options === 'function' )
{
this . real_node . set_select_options ( select_options ) ;
}
}
// Just pass the real DOM node through, in case anybody asks
2021-08-17 21:56:52 +02:00
getDOMNode ( _sender )
2020-01-24 12:14:08 +01:00
{
return this . real_node ? this . real_node . getDOMNode ( _sender ) : null ;
}
// Also need to pass through real children
2021-08-17 21:56:52 +02:00
getChildren ( )
2020-01-24 12:14:08 +01:00
{
return this . real_node . getChildren ( ) || [ ] ;
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
setNextmatch ( _nextmatch : et2_nextmatch )
{
if ( this . real_node && this . real_node . instanceOf ( et2_INextmatchHeader ) )
{
return ( < et2_INextmatchHeader > < unknown > this . real_node ) . setNextmatch ( _nextmatch ) ;
}
}
}
2021-08-17 21:56:52 +02:00
2020-01-24 12:14:08 +01:00
et2_register_widget ( et2_nextmatch_customfilter , [ 'nextmatch-customfilter' ] ) ;