Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

helper.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* Poweradmin, a friendly web-based admin tool for PowerDNS.
  2. * See <https://www.poweradmin.org> for more details.
  3. *
  4. * Copyright 2007-2010 Rejo Zenger <rejo@zenger.nl>
  5. * Copyright 2010-2014 Poweradmin Development Team
  6. * <http://www.poweradmin.org/credits.html>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. function changePort(db_type) {
  22. var dbport = document.getElementById("dbport");
  23. var host = document.getElementById("host");
  24. var db_name_title = document.getElementById("db_name_title");
  25. var db_path_title = document.getElementById("db_path_title");
  26. var username_row = document.getElementById("username_row");
  27. var password_row = document.getElementById("password_row");
  28. var hostname_row = document.getElementById("hostname_row");
  29. var dbport_row = document.getElementById("dbport_row");
  30. if (db_type == "mysql") {
  31. dbport.value = "3306";
  32. host.value = "localhost";
  33. db_name_title.style.display = '';
  34. db_path_title.style.display = "none";
  35. username_row.style.display = '';
  36. password_row.style.display = '';
  37. hostname_row.style.display = '';
  38. dbport_row.style.display = '';
  39. } else if (db_type == "pgsql") {
  40. dbport.value = "5432";
  41. host.value = "localhost";
  42. db_name_title.style.display = '';
  43. db_path_title.style.display = "none";
  44. username_row.style.display = '';
  45. password_row.style.display = '';
  46. hostname_row.style.display = '';
  47. dbport_row.style.display = '';
  48. } else {
  49. dbport.value = "";
  50. host.value = "";
  51. db_name_title.style.display = "none";
  52. db_path_title.style.display = '';
  53. username_row.style.display = "none";
  54. password_row.style.display = "none";
  55. hostname_row.style.display = "none";
  56. dbport_row.style.display = "none";
  57. }
  58. }
  59. //Add more fields dynamically.
  60. function addField(area, field, limit) {
  61. if (!document.getElementById)
  62. return; //Prevent older browsers from getting any further.
  63. var field_area = document.getElementById(area);
  64. var all_inputs = field_area.getElementsByTagName("input"); //Get all the input fields in the given area.
  65. //Find the count of the last element of the list. It will be in the format '<field><number>'. If the
  66. // field given in the argument is 'friend_' the last id will be 'friend_4'.
  67. var last_item = all_inputs.length - 1;
  68. var last = all_inputs[last_item].id;
  69. var count = Number(last.split("_")[1]) + 1;
  70. //If the maximum number of elements have been reached, exit the function.
  71. // If the given limit is lower than 0, infinite number of fields can be created.
  72. if (count > limit && limit > 0)
  73. return;
  74. if (document.createElement) { //W3C Dom method.
  75. var li = document.createElement("li");
  76. var input = document.createElement("input");
  77. input.id = field + count;
  78. input.name = "domain[]";
  79. input.type = "text"; //Type of field - can be any valid input type like text,file,checkbox etc.
  80. input.className = "input";
  81. li.appendChild(input);
  82. var editLink = document.createElement("input");
  83. editLink.id = 'remove_button';
  84. editLink.type = 'button';
  85. editLink.value = 'Remove field';
  86. editLink.setAttribute('class', 'button');
  87. editLink.onclick = function() {
  88. this.parentNode.parentNode.removeChild(this.parentNode);
  89. }
  90. li.appendChild(editLink);
  91. field_area.appendChild(li);
  92. } else { //Older Method
  93. field_area.innerHTML += "<li><input name='domain[]' id='" + (field + count) + "' type='text' class='input' /> <a onclick=\"this.parentNode.parentNode.removeChild(this.parentNode);\">Remove Field</a></li>";
  94. }
  95. }
  96. function getDomainsElements() {
  97. var
  98. coll = document.getElementsByTagName('input'),
  99. re = /^domain\[\]$/,
  100. t,
  101. elm,
  102. i = 0,
  103. key = 0,
  104. records = new Array();
  105. while (elm = coll.item(i++))
  106. {
  107. t = re.exec(elm.name);
  108. if (t != null)
  109. {
  110. records[key] = elm;
  111. key++;
  112. }
  113. }
  114. return records;
  115. }
  116. function checkDomainFilled() {
  117. var
  118. domains = new Array(),
  119. allEmpty = true,
  120. domains = getDomainsElements();
  121. if (domains.length == 1) {
  122. if ((domains[0].value.length == 0 || domains[0].value == null || domains[0].value == "")) {
  123. alert('Zone name cannot be empty');
  124. return false;
  125. }
  126. } else {
  127. for (key in domains) {
  128. if ((domains[key].value.length != 0)) {
  129. allEmpty = false;
  130. }
  131. }
  132. if (true === allEmpty) {
  133. alert('Please fill in at least one Zone name');
  134. return false;
  135. }
  136. }
  137. add_zone_master.submit();
  138. }