User Tools

Site Tools


Plugin installed incorrectly. Rename plugin directory 'swiftmail.backup' to 'swiftmail'.
This translation is older than the original page and might be outdated. See what has changed.
en:software:tim:javascript:filter

Table of Contents

Preset Filter

It is possible to preset filter with values from the user profile via Javascript. To achieve this the following code has to be copied into the used custom.js

(function($){
 
	var GADGET_NAME = 'pmprocesses';
	var TAB_NAME = 'instances'; //Specifies on which tab the preset filter lies (e.g.: definitions,myStartedProcessInstances,...)
	var FILTER = 'name'; //Specifies which filter is to be preset (e.g.: smartFormIndex1,smartFormIndex2,...) 
	var SOURCE = gadget.getEntity('currentUserProfile'); //Or gadget.getEntity('currentUser')  to recieve value like First Name, Last Name, ...
	var FIELD = 'department'; //Gibt an welches Feld verwendet werden soll (z.B.: namefirst, namelast,...)
        var USER_PROFILE = gadget.getEntity('currentUserProfile');
	var SYSTEM_PROPS = USER_PROFILE.systemConfigurationProperties;
	var FILTER_NAME = 'filter.' + GADGET_NAME + '.' + TAB_NAME + '.' + FILTER;
	var FIELD_NAME = 'fields.' + GADGET_NAME + '.' + TAB_NAME;
	var APPLY = true;
 
	function applyFilter(gui, value){
		var callback = gui.requestMethodCallback;
		gui.requestMethod.filter = " ( " + FILTER + " like '%" + value + "%' ) ";
		gui.requestMethod(callback);
		gui.filters[FILTER] = {visible: false, active: true, value: value};
	}
 
	function overrideUpdateMe(gui){
		var old = gui.updateMe;
		gui.updateMe = function(){
			if(this.gadget.name==GADGET_NAME && this.tabName==TAB_NAME){
				var filter = this.filters[FILTER] || '';
				webService.SystemManager.saveGui(FILTER_NAME, filter.value || filter);
			}
			old.bind(this)();
		}
	}
 
	if(Gadget.CLIENTNAME=='Processmanager Client'){
		$(SYSTEM_PROPS).each(function(i, e){
			if(e.name==FIELD_NAME && e.value.indexOf(FILTER)===-1)
    			APPLY = false;
   		});
		var checkExist = setInterval(function(){
			var g = gadget.getGadget(GADGET_NAME);
			if(typeof(g)!='undefined'){
				var t = g.tabView.getTab(TAB_NAME);
				if(typeof(t)!='undefined'){
					overrideUpdateMe(t.gui);
					var field = SOURCE.getValue(FIELD);
					if(typeof(field)!='undefined' && $.trim(field)!='' && APPLY)
						applyFilter(t.gui, field);
					$(SYSTEM_PROPS).each(function(i, e){
						if(e.name==FILTER_NAME && $.trim(e.value)!='' && APPLY)
    						applyFilter(t.gui, e.value);
   					});
					clearInterval(checkExist);
				}
			}
		}, 300);
	}
 
}(jQuery));
en/software/tim/javascript/filter.txt · Last modified: 2021/07/01 09:52 (external edit)