Project

General

Profile

« Previous | Next » 

Revision d5b2cfd4

Added by Scott Ullrich over 14 years ago

Adding support for custom hooks. If the function row_helper_dynamic_custom() exists it will be called and pass a tr object which is the createElement("tr") handle.

View differences:

usr/local/www/javascript/row_helper_dynamic.js
19 19
var addRowTo = (function() {
20 20
    return (function (tableId, objectSize) {
21 21
	var d, tbody, tr, td, bgc, i, ii, j;
22
	var onChange;
22 23
	d = document;
23 24
	tbody = d.getElementById(tableId).getElementsByTagName("tbody").item(0);
24 25
	tr = d.createElement("tr");
25 26
	totalrows++;
27
	if(function_exists('row_helper_dynamic_custom')) 
28
		onChange = " onchange='row_helper_dynamic_custom(" + tr + ")' ";
26 29
	if (!objectSize)
27 30
		objectSize = rowsize[i];
28 31
	for (i = 0; i < field_counter_js; i++) {
......
30 33
		if(typeof(rowtype[i]) == 'function') {
31 34
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input>" + rowtype[i](rowname[i], objectSize, totalrows) + " ";
32 35
		} else if(rowtype[i] == 'textbox') {
33
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input size='" + rowsize[i] + "' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
36
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input " + onChange + " size='" + rowsize[i] + "' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
34 37
		} else if(rowtype[i] == 'select') {
35
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><select name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
38
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><select " + onChange + " name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
36 39
		} else if(rowtype[i] == 'select_source') {
37
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><select name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
40
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><select " + onChange + " name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'>" + newrow[i] + "</select> ";
38 41
		} else if(rowtype[i] == 'checkbox') {
39
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input type='checkbox'name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
42
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input " + onChange + " type='checkbox'name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
40 43
		} else if(rowtype[i] == 'input') {
41
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input class='formfld unknown' size='" + objectSize + "' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
44
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input " + onChange + " class='formfld unknown' size='" + objectSize + "' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
42 45
		} else if(rowtype[i] == 'password') {
43
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input class='formfld pwd' type='password' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
46
			td.innerHTML="<INPUT type='hidden' value='" + totalrows +"' name='" + rowname[i] + "_row-" + totalrows + "'></input><input " + onChange + " class='formfld pwd' type='password' name='" + rowname[i] + totalrows + "' id='" + rowname[i] + totalrows + "'></input> ";
44 47
		}
45 48
		tr.appendChild(td);
46 49
	}
......
76 79
		return field_name;
77 80
	return(field_name.substr(0,last_found_dash));
78 81
}
82

  
83
function function_exists (function_name) {
84
    // http://kevin.vanzonneveld.net
85
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
86
    // +   improved by: Steve Clay
87
    // +   improved by: Legaev Andrey
88
    // *     example 1: function_exists('isFinite');
89
    // *     returns 1: true
90
    if (typeof function_name == 'string'){
91
        return (typeof this.window[function_name] == 'function');
92
    } else{
93
        return (function_name instanceof Function);
94
    }
95
}

Also available in: Unified diff