collection.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. function loadCollection(selected){
  2. var req = new XMLHttpRequest();
  3. req.onreadystatechange = function() {
  4. if (this.readyState == 4){
  5. if (this.status == 200){
  6. document.getElementById("collection").innerHTML = this.responseText;
  7. }
  8. else{
  9. alert("Error getting monster collection (HTTP status " + this.status + ")");
  10. }
  11. }
  12. };
  13. req.open("POST", "/frame/collection/", true);
  14. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  15. if (selected == null){
  16. req.send();
  17. }
  18. else{
  19. req.send("selected=" + selected);
  20. }
  21. }
  22. function getMonsterId(base, element){
  23. if (["Fire", "Water", "Wind", "Light", "Dark"].indexOf(element) == -1){
  24. return;
  25. }
  26. var bases = [];
  27. for (var i = 1; i < base_list.childNodes.length; i = i +2){
  28. bases.push(base_list.childNodes[i].value);
  29. }
  30. if(bases.indexOf(base) == -1){
  31. return;
  32. }
  33. var req = new XMLHttpRequest();
  34. req.onreadystatechange = function() {
  35. if (this.readyState == 4){
  36. if (this.status == 200){
  37. document.getElementById("new_frame").innerHTML = this.responseText;
  38. }
  39. else{
  40. alert("Error getting monster info (HTTP status " + this.status + ")");
  41. }
  42. }
  43. };
  44. req.open("POST", "/frame/new/", true);
  45. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  46. req.send("base=" + base + "&element=" + element);
  47. }
  48. function showNew(show){
  49. if (show === true){
  50. document.getElementById('cover').style.display = 'block';
  51. document.getElementById('cover').style.opacity = '0.8';
  52. document.getElementById('new').style.display = 'block';
  53. }
  54. else{
  55. document.getElementById('cover').style.display = 'none';
  56. document.getElementById('cover').style.opacity = '0';
  57. document.getElementById('new').style.display = 'none';
  58. }
  59. }
  60. function selectMonster(id) {
  61. if (id == null){
  62. document.getElementById("portrait_container").innerHTML = '';
  63. }
  64. else{
  65. var req = new XMLHttpRequest();
  66. req.onreadystatechange = function() {
  67. if (this.readyState == 4){
  68. if (this.status == 200) {
  69. document.getElementById("portrait_container").innerHTML = this.responseText;
  70. }
  71. else{
  72. alert("Error selecting monster (HTTP status " + this.status + ")");
  73. }
  74. }
  75. };
  76. req.open("POST", "/frame/portrait/", true);
  77. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  78. req.send("id=" + id);
  79. }
  80. }
  81. function selectMaxLevel(stars){
  82. document.getElementById('v_level').max = 10 + (5 * stars);
  83. }
  84. function removeMonster(id){
  85. if (!confirm("Really delete the monster?")){
  86. return;
  87. }
  88. var req = new XMLHttpRequest();
  89. req.onreadystatechange = function() {
  90. if (this.readyState == 4){
  91. if (this.status == 200){
  92. loadCollection(null);
  93. selectMonster(null);
  94. }
  95. else{
  96. alert("Error deleting monster (HTTP status " + this.status + ")");
  97. }
  98. }
  99. };
  100. req.open("POST", "/handler/monster_collection/", true);
  101. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  102. req.send("id=" + id + "&mode=delete");
  103. }
  104. function updateMonster(id, property, value){
  105. var req = new XMLHttpRequest();
  106. req.onreadystatechange = function() {
  107. if (this.readyState == 4){
  108. if (this.status == 200){
  109. loadCollection(id);
  110. selectMonster(id);
  111. }
  112. else{
  113. alert("Error updating monster (HTTP status " + this.status + ")");
  114. }
  115. }
  116. };
  117. req.open("POST", "/handler/monster_collection/", true);
  118. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  119. req.send("id=" + id + "&mode=update&" + property + "=" + value);
  120. }
  121. function addMonster(){
  122. var monster = document.getElementById('new_monster').value;
  123. var stars = document.getElementById('new_stars').value;
  124. var level = document.getElementById('new_level').value;
  125. var awaken = document.getElementById('new_awaken').checked;
  126. var req = new XMLHttpRequest();
  127. req.onreadystatechange = function() {
  128. if (this.readyState == 4){
  129. if (this.status == 200){
  130. showNew(false);
  131. loadCollection(null);
  132. }
  133. else{
  134. alert("Error creating monster (HTTP status " + this.status + ")");
  135. }
  136. }
  137. };
  138. req.open("POST", "/handler/monster_collection/", true);
  139. req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  140. req.send("id=-1&mode=insert&monster=" + monster + "&stars=" + stars + "&level=" + level + "&awaken=" + awaken);
  141. }