Add JS function for getting parent tag
This commit is contained in:
parent
5fd21e122a
commit
b49061b863
|
@ -64,7 +64,7 @@ function typePassword(el, disable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loginDriver(driver) {
|
function loginDriver(driver) {
|
||||||
var trs = driver.parentNode.parentNode.parentNode.rows;
|
var trs = parentTag(driver, 'table').rows;
|
||||||
for (var i=1; i < trs.length - 1; i++) {
|
for (var i=1; i < trs.length - 1; i++) {
|
||||||
trs[i].className = (/sqlite/.test(driver.value) ? 'hidden' : '');
|
trs[i].className = (/sqlite/.test(driver.value) ? 'hidden' : '');
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ function editingAddRow(button, allowed, focus) {
|
||||||
}
|
}
|
||||||
var match = /(\d+)(\.\d+)?/.exec(button.name);
|
var match = /(\d+)(\.\d+)?/.exec(button.name);
|
||||||
var x = match[0] + (match[2] ? added.substr(match[2].length) : added) + '1';
|
var x = match[0] + (match[2] ? added.substr(match[2].length) : added) + '1';
|
||||||
var row = button.parentNode.parentNode;
|
var row = parentTag(button, 'tr');
|
||||||
var row2 = row.cloneNode(true);
|
var row2 = row.cloneNode(true);
|
||||||
var tags = row.getElementsByTagName('select');
|
var tags = row.getElementsByTagName('select');
|
||||||
var tags2 = row2.getElementsByTagName('select');
|
var tags2 = row2.getElementsByTagName('select');
|
||||||
|
@ -282,7 +282,7 @@ function editingAddRow(button, allowed, focus) {
|
||||||
function editingRemoveRow(button) {
|
function editingRemoveRow(button) {
|
||||||
var field = formField(button.form, button.name.replace(/drop_col(.+)/, 'fields$1[field]'));
|
var field = formField(button.form, button.name.replace(/drop_col(.+)/, 'fields$1[field]'));
|
||||||
field.parentNode.removeChild(field);
|
field.parentNode.removeChild(field);
|
||||||
button.parentNode.parentNode.style.display = 'none';
|
parentTag(button, 'tr').style.display = 'none';
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,9 +368,9 @@ function partitionByChange(el) {
|
||||||
* @param HTMLInputElement
|
* @param HTMLInputElement
|
||||||
*/
|
*/
|
||||||
function partitionNameChange(el) {
|
function partitionNameChange(el) {
|
||||||
var row = el.parentNode.parentNode.cloneNode(true);
|
var row = parentTag(el, 'tr').cloneNode(true);
|
||||||
row.firstChild.firstChild.value = '';
|
row.firstChild.firstChild.value = '';
|
||||||
el.parentNode.parentNode.parentNode.appendChild(row);
|
parentTag(el, 'table').appendChild(row);
|
||||||
el.onchange = function () {};
|
el.onchange = function () {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,13 +381,13 @@ function partitionNameChange(el) {
|
||||||
*/
|
*/
|
||||||
function foreignAddRow(field) {
|
function foreignAddRow(field) {
|
||||||
field.onchange = function () { };
|
field.onchange = function () { };
|
||||||
var row = field.parentNode.parentNode.cloneNode(true);
|
var row = parentTag(field, 'tr').cloneNode(true);
|
||||||
var selects = row.getElementsByTagName('select');
|
var selects = row.getElementsByTagName('select');
|
||||||
for (var i=0; i < selects.length; i++) {
|
for (var i=0; i < selects.length; i++) {
|
||||||
selects[i].name = selects[i].name.replace(/\]/, '1$&');
|
selects[i].name = selects[i].name.replace(/\]/, '1$&');
|
||||||
selects[i].selectedIndex = 0;
|
selects[i].selectedIndex = 0;
|
||||||
}
|
}
|
||||||
field.parentNode.parentNode.parentNode.appendChild(row);
|
parentTag(field, 'table').appendChild(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -397,8 +397,7 @@ function foreignAddRow(field) {
|
||||||
*/
|
*/
|
||||||
function indexesAddRow(field) {
|
function indexesAddRow(field) {
|
||||||
field.onchange = function () { };
|
field.onchange = function () { };
|
||||||
var parent = field.parentNode.parentNode;
|
var row = parentTag(field, 'tr').cloneNode(true);
|
||||||
var row = parent.cloneNode(true);
|
|
||||||
var selects = row.getElementsByTagName('select');
|
var selects = row.getElementsByTagName('select');
|
||||||
for (var i=0; i < selects.length; i++) {
|
for (var i=0; i < selects.length; i++) {
|
||||||
selects[i].name = selects[i].name.replace(/indexes\[\d+/, '$&1');
|
selects[i].name = selects[i].name.replace(/indexes\[\d+/, '$&1');
|
||||||
|
@ -409,7 +408,7 @@ function indexesAddRow(field) {
|
||||||
inputs[i].name = inputs[i].name.replace(/indexes\[\d+/, '$&1');
|
inputs[i].name = inputs[i].name.replace(/indexes\[\d+/, '$&1');
|
||||||
inputs[i].value = '';
|
inputs[i].value = '';
|
||||||
}
|
}
|
||||||
parent.parentNode.appendChild(row);
|
parentTag(field, 'table').appendChild(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Change column in index
|
/** Change column in index
|
||||||
|
@ -417,7 +416,7 @@ function indexesAddRow(field) {
|
||||||
* @param string name prefix
|
* @param string name prefix
|
||||||
*/
|
*/
|
||||||
function indexesChangeColumn(field, prefix) {
|
function indexesChangeColumn(field, prefix) {
|
||||||
var columns = field.parentNode.parentNode.getElementsByTagName('select');
|
var columns = parentTag(field, 'td').getElementsByTagName('select');
|
||||||
var names = [];
|
var names = [];
|
||||||
for (var i=0; i < columns.length; i++) {
|
for (var i=0; i < columns.length; i++) {
|
||||||
var value = selectValue(columns[i]);
|
var value = selectValue(columns[i]);
|
||||||
|
@ -448,7 +447,7 @@ function indexesAddColumn(field, prefix) {
|
||||||
var input = column.getElementsByTagName('input')[0];
|
var input = column.getElementsByTagName('input')[0];
|
||||||
input.name = input.name.replace(/\]\[\d+/, '$&1');
|
input.name = input.name.replace(/\]\[\d+/, '$&1');
|
||||||
input.value = '';
|
input.value = '';
|
||||||
field.parentNode.parentNode.appendChild(column);
|
parentTag(field, 'td').appendChild(column);
|
||||||
field.onchange();
|
field.onchange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,24 @@ function selectValue(select) {
|
||||||
return ((selected.attributes.value || {}).specified ? selected.value : selected.text);
|
return ((selected.attributes.value || {}).specified ? selected.value : selected.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get parent node with specified tag name.
|
||||||
|
* @param HTMLElement
|
||||||
|
* @param string
|
||||||
|
* @return HTMLElement
|
||||||
|
*/
|
||||||
|
function parentTag(el, tag) {
|
||||||
|
var re = new RegExp('^' + tag + '$', 'i');
|
||||||
|
while (!re.test(el.tagName)) {
|
||||||
|
el = el.parentNode;
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
/** Set checked class
|
/** Set checked class
|
||||||
* @param HTMLInputElement
|
* @param HTMLInputElement
|
||||||
*/
|
*/
|
||||||
function trCheck(el) {
|
function trCheck(el) {
|
||||||
var tr = el.parentNode.parentNode;
|
var tr = parentTag(el, 'tr');
|
||||||
tr.className = tr.className.replace(/(^|\s)checked(\s|$)/, '$2') + (el.checked ? ' checked' : '');
|
tr.className = tr.className.replace(/(^|\s)checked(\s|$)/, '$2') + (el.checked ? ' checked' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +148,7 @@ function checkboxClick(event, el) {
|
||||||
}
|
}
|
||||||
if (event.shiftKey && (!lastChecked || lastChecked.name == el.name)) {
|
if (event.shiftKey && (!lastChecked || lastChecked.name == el.name)) {
|
||||||
var checked = (lastChecked ? lastChecked.checked : true);
|
var checked = (lastChecked ? lastChecked.checked : true);
|
||||||
var inputs = el.parentNode.parentNode.parentNode.getElementsByTagName('input');
|
var inputs = parentTag(el, 'table').getElementsByTagName('input');
|
||||||
var checking = !lastChecked;
|
var checking = !lastChecked;
|
||||||
for (var i=0; i < inputs.length; i++) {
|
for (var i=0; i < inputs.length; i++) {
|
||||||
var input = inputs[i];
|
var input = inputs[i];
|
||||||
|
|
Loading…
Reference in a new issue