row_helper_dynamic.js 4.78 KB
Newer Older
Ad Schellevis's avatar
Ad Schellevis committed
1 2 3
// Global Variables
var rowname				= new Array(99);
var rowtype				= new Array(99);
4 5
var newrow				= new Array(99);
var rowsize			= new Array(99);
Ad Schellevis's avatar
Ad Schellevis committed
6 7 8

// Global variables.  Set to javascript code
// that will be eval() after change, add & delete.
9
var rowhelper_onChange	= '';
Ad Schellevis's avatar
Ad Schellevis committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
var rowhelper_onAdd		= '';
var rowhelper_onDelete	= '';

for (i = 0; i < 99; i++) {
	rowname[i] = '';
	rowtype[i] = '';
	newrow[i] = '';
	rowsize[i] = '25';
}

var field_counter_js = 0;
var loaded = 0;
var is_streaming_progress_bar = 0;
var temp_streaming_text = "";

var addRowTo = (function() {
    return (function (tableId, objectSize) {
	var $ = jQuery;
	var d, tbody, tr, td, bgc, i, ii, j, size, className;
	d = document;
	tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
	tr = d.createElement("tr");
	totalrows++;
	size = objectSize;
	for (i = 0; i < field_counter_js; i++) {
		if (!objectSize)
			size = rowsize[i];
		td = d.createElement("td");
		if(typeof(rowtype[i]) == 'function') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' />" + rowtype[i](rowname[i], size, totalrows) + " ";
		} else if(rowtype[i] == 'textbox') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><input " + rowhelper_onChange + " size='" + rowsize[i] + "' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "' /> ";
		} else if(rowtype[i] == 'textbox,ipv4v6') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><input " + rowhelper_onChange + " size='" + rowsize[i] + "' name='" + rowname[i] + totalrows + "' class='ipv4v6' id='" + rowname[i] + totalrows + "' /> ";
		} else if(rowtype[i] == 'select') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><select " + rowhelper_onChange + " name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
		} else if(rowtype[i] == 'select,ipv4v6') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><select " + rowhelper_onChange + " name='" + rowname[i] + totalrows + "' class='ipv4v6' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
		} else if(rowtype[i] == 'interfaces_selection') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><select " + rowhelper_onChange + " name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
		} else if(rowtype[i] == 'select_source') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><select " + rowhelper_onChange + " name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
		} else if(rowtype[i] == 'checkbox') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><input " + rowhelper_onChange + " type='checkbox'name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "' /> ";
		} else if(rowtype[i] == 'input') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><input " + rowhelper_onChange + " class='formfld unknown' size='" + size + "' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "' /> ";
		} else if(rowtype[i] == 'password') {
			td.innerHTML="<input type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "' /><input " + rowhelper_onChange + " class='formfld pwd' type='password' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "' /> ";
		}
		tr.appendChild(td);
	}
	td = d.createElement("td");
	td.rowSpan = "1";
63
	td.innerHTML = '<a onclick="removeRow(this); return false;" href="#"><span class="glyphicon glyphicon-remove"></span></a>';
Ad Schellevis's avatar
Ad Schellevis committed
64 65
	tr.appendChild(td);
	tbody.appendChild(tr);
66
	if(rowhelper_onAdd != '')
Ad Schellevis's avatar
Ad Schellevis committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
		eval(rowhelper_onAdd);
	if($(tr).ipv4v6ify)
		$(tr).ipv4v6ify();
    });
})();

function removeRow(el) {
    var cel;
    while (el && el.nodeName.toLowerCase() != "tr")
	    el = el.parentNode;

    if (el && el.parentNode) {
	cel = el.getElementsByTagName("td").item(0);
	el.parentNode.removeChild(el);
    }
82
	if(rowhelper_onDelete != '')
Ad Schellevis's avatar
Ad Schellevis committed
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
		eval(rowhelper_onDelete);
}

function find_unique_field_name(field_name) {
	// loop through field_name and strip off -NUMBER
	var last_found_dash = 0;
	for (var i = 0; i < field_name.length; i++) {
		// is this a dash, if so, update
		//    last_found_dash
		if (field_name.substr(i,1) == "-" )
			last_found_dash = i;
	}
	if (last_found_dash < 1)
		return field_name;
	return(field_name.substr(0,last_found_dash));
}