-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjavascript.js
141 lines (129 loc) · 4.63 KB
/
javascript.js
1
2
3
4
5
6
7
8
9
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function addRow(tableID,Ldelete,Litem,Ltype1,Ltype2,Ltype3,Ltype4,Ltype5,Ltype6)
{
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount); //vlozi prazdny riadok do tabulky + vrati referenciu
var colCount = table.rows[1].cells.length; // zrata pocet buniek (v 2.riadku)
for(var i=0; i<colCount; i++)
{
var newcell = row.insertCell(i); // vlozi do noveho riadka bunku + vrati na nu odkaz
var newmax = parseInt(table.rows[rowCount-1].cells[1].innerHTML) + 1; //+1 vyssie id.
//alert(i);
switch (i)
{
case 0: newcell.innerHTML = '<input type="button" value="'+Ldelete+'" onclick="deleteRow(this)" />';
break;
case 1: newcell.innerHTML = newmax;
break;
case 2: newcell.innerHTML = '<input name="label'+newmax+'" type="text" value="'+Litem+' '+newmax+'" style="width:120px;" />';
break;
case 3: var element = document.createElement('select');
element.options[0] = new Option(Ltype1, 'input');
element.options[1] = new Option(Ltype2, 'checkbox');
element.options[2] = new Option(Ltype3, 'radio');
element.options[3] = new Option(Ltype4, 'select');
element.options[4] = new Option(Ltype5, 'textarea');
element.options[5] = new Option(Ltype6, 'textarea');
element.name = 'type'+newmax;
element.selectedIndex = 0;
newcell.innerHTML = ' '; newcell.appendChild(element);
//newcell.onchange = changeEvent;
if (element.addEventListener) {
element.addEventListener('change',changeEvent,false);
//element.addEventListener('change',function () { checkSelectedType(this); },false);
}
else if (element.attachEvent) {
element.attachEvent('onchange',changeEvent);
}
break;
case 4: newcell.innerHTML = '<input name="valid'+newmax+'" type="text" />';
break;
case 5: var element = document.createElement('input');
element.setAttribute('type', 'text');
element.setAttribute('value', '');
element.setAttribute('name', 'multi_values'+newmax);
element.style.display = 'none';
newcell.appendChild(element);
//newcell.innerHTML = '<input name="multi_values'+newmax+'" type="text" />';
break;
}
document.getElementById('maxval').value = newmax+'';
//alert(document.getElementById('maxval').value);
$(table).tableDnD({
//onDragClass: "myDragClass",
onDrop: function(table, row) {
reindexRows();
}
});
}
}
function changeEvent(e)
{
target = (e.target) ? e.target : e.srcElement;
//alert(target);
checkSelectedType(target); //object HTMLSelectElement
}
function deleteRow(obj)//obj==select
{
var delRow = obj.parentNode.parentNode;
var table = delRow.parentNode.parentNode;
if (table.rows.length<=2)
return;
table.deleteRow(delRow.sectionRowIndex+1);
reindexRows();
}
function checkSelectedType(obj)
{
var objRow = obj.parentNode.parentNode;
//whether display or not the text field for multiple values
if (objRow.cells[5].childNodes[0] && objRow.cells[5].childNodes[0].style)
objRow.cells[5].childNodes[0].style.display = (obj.value=='radio' || obj.value=='select') ? 'block' : 'none';
if (objRow.cells[5].childNodes[1] && objRow.cells[5].childNodes[1].style)
objRow.cells[5].childNodes[1].style.display = (obj.value=='radio' || obj.value=='select') ? 'block' : 'none';
}
function reindexRows() //reindexes (=renames) form elements
{
$('#dataTable tbody').find('tr').each(function(i){
var j=i+1;
this.id = 'row'+j;
var cells=this.getElementsByTagName('td');
//alert(cells.length);
var t;
cells[1].innerHTML=j;
t=cells[2].getElementsByTagName('input');
t[0].name='label'+j;
t=cells[3].getElementsByTagName('select');
t[0].name='type'+j;
t=cells[4].getElementsByTagName('input');
t[0].name='valid'+j;
t=cells[5].getElementsByTagName('input');
t[0].name='multi_values'+j;
});
}
$(document).ready(function(){
$("#dataTable tbody").tableDnD({
//onDragClass: "myDragClass",
onDrop: function(table, row) {
reindexRows();
/*var rows = table.tBodies[0].rows;
var debugStr = "Row dropped was "+row.id+". New order: ";
for (var i=0; i<rows.length; i++) {
debugStr += rows[i].id+" ";
}
$("#debugArea").html(debugStr);*/
},
/*onDragStart: function(table, row) {
var cell=$(row).find('td')[1];
cell.innerHTML='<b>'+cell.innerHTML+'</b>';
$("#debugArea").html("Started dragging row "+row.id);
}*/
});
});
function switch_language(elem)
{
var loc=window.location.href;
var pos=loc.indexOf('?');
if (pos>-1)
loc = window.location.href.substr(0,pos);
location.href = loc + "?iLanguage=" + elem.value;
}