Webadmin - searchable formcollection

Make Application/FormCollection selection searchable

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Webadmin - searchable formcollection
// @namespace   com.aforms2web.ds.ujs
// @description Make Application/FormCollection selection searchable
// @author      [email protected]
// @include     *webadmin*
// @version     0.8
// @grant       none
// ==/UserScript==

init(); 

function init(){
    var select = $("#afs_application");
    if(select.size() > 0){
	select.attr("size", 10);
	select.attr("style", "min-height: 3em");
	
	var tr = document.createElement("tr");
	var td = document.createElement("td");
	td.innerHTML = "Filter";
	tr.appendChild(td);
	td = document.createElement("td");

	var input = document.createElement("input");
	input.addEventListener ('keydown', stopMovingCarretONUpDown, true);
	input.addEventListener ('keyup', filter, true);
	input.setAttribute("id", "afs_application_filter"); 	
	input.setAttribute("type", "text"); 	
	input.setAttribute("autocomplete", "off"); 	
	input.setAttribute("class", "input_field_size300"); 	
	input.setAttribute("style", "border-top-right-radius: 5em 2em;"); 	
	td.appendChild(input);

	tr.appendChild(td);
	select.closest("tbody").prepend(tr);

	input.focus();

    }
}

var appSelect_currentSelected = null;

function stopMovingCarretONUpDown(event){
	if(event.keyCode == 38 || event.keyCode == 40){ 
	    event.preventDefault();
	}
}

function filter(event){
    var filter = $("#afs_application_filter").val();
    var appSelect = $("#afs_application");
    var selected = null;
    var first = null;
    if(appSelect_currentSelected != null){		
	if(event.keyCode == 38){ // up
	    appSelect_currentSelected.prevAll(':not(:disabled)').first().attr("selected", true);
	    appSelect_currentSelected = appSelect.find("option:selected");
	    return;
	}else if(event.keyCode == 40){ // down
	    appSelect_currentSelected.nextAll(':not(:disabled)').first().attr("selected", true);
	    appSelect_currentSelected = appSelect.find("option:selected");
	    return;
	}
    }
	appSelect_currentSelected = null;
	$("#afs_application > option").each(function() {
	    if(this.text.indexOf(filter) >= 0 || this.text.match(new RegExp(filter, 'gi'))){
		$(this).attr("style", "");
		$(this).attr("disabled", false);
		if(first == null){
		    first = $(this);
		}
		if($(this).attr("selected") && selected == null){
		    appSelect_currentSelected = $(this);
		}
	    }else{
		$(this).attr("style", "display: none; visibility: hidden;");
		$(this).attr("disabled", true);
		$(this).attr("selected", false);
	    }
	});
	if(appSelect_currentSelected == null){
	    first.attr("selected", true);
	    appSelect_currentSelected = appSelect.find("option:selected");
	}
	if(appSelect_currentSelected != null){
	    appSelect.scrollTop(appSelect_currentSelected.position().top);
	}
}