Webadmin - searchable formcollection

Make Application/FormCollection selection searchable

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);
	}
}