Webadmin - searchable formcollection

Make Application/FormCollection selection searchable

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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);
	}
}