Difference between revisions of "MediaWiki:CreatureList.js"

From Virtuverse Wiki
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
function drawTable(mobs) {
 
function drawTable(mobs) {
   var output = $("#sandbox-output");
+
   var output = $("#creatures-list");
   var html = "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th></tr>";
+
   var html = "<div><a href='/index.php/Data:CreatureForm'><button>Add</button></a></div>";
   mobs.forEach(function(mob) {
+
  html += "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th><th>Maturity</th><th>Planets</th><th></th></tr>";
 +
   mobs.creatures.forEach(function(mob) {
 
       var url = "/index.php/Creatures:"+mob["name"];
 
       var url = "/index.php/Creatures:"+mob["name"];
 +
      var planets = mob["planets"];
 +
      var planetURLs = "";
 +
      planets.forEach(function(planet) {
 +
        planetURLs += "<a href='index.php/Story:"+planet+"'>"+planet+"</a>&nbsp;&nbsp;";
 +
      });
 +
      var editURL = "/index.php/Data:CreatureForm?id="+mob["_id"];
 +
     
 
       html += "<tr>";
 
       html += "<tr>";
 
       html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>";
 
       html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>";
 
       html += "<td>"+mob["hp"]+"</td>";
 
       html += "<td>"+mob["hp"]+"</td>";
       html += "<td>"+mob["damage"]+"</td>";
+
       html += "<td>"+mob["min_damage"]+" - "+mob["max_damage"]+"</td>";
 +
      html += "<td>"+mob["maturity"]+"</td>";
 +
      html += "<td>"+planetURLs+"</td>";
 +
      html += "<td><a href='"+editURL+"'>Edit</a></td>";
 
       html += "</tr>"
 
       html += "</tr>"
 
   });
 
   });
 +
 +
  var paging = "<tr><td colspan='10'>";
 +
  mobs.pages.forEach(function(section) {
 +
      var link = "";
 +
      if (section.is_current) {
 +
        link = "&nbsp;&nbsp;[" + section.page + "]&nbsp;&nbsp;";
 +
      } else {
 +
        var path = "/index.php/Creatures?page="+section.start+"&count="+section.count;
 +
        link = "&nbsp;<a href='"+path+"'>"+section.page+"</a>&nbsp;";
 +
      }
 +
      paging += link;
 +
  })
 +
  paging += "</td></tr>";
 +
  html += paging;
 +
 
   html += "</table>";
 
   html += "</table>";
 
   output.html(html);
 
   output.html(html);
 +
}
 +
 +
function query(page, count) {
 +
  $("#loader-creatures-list").show();
 +
  $.ajax({
 +
        type: "GET",
 +
        dataType: "json",
 +
        url: "/vv-api/get-creatures.php?page="+page+"&count="+count,
 +
        success: function(data) {
 +
          $("#loader-creatures-list").hide();
 +
          drawTable(data.result);
 +
        },
 +
        error: function(status, exec) {
 +
          $("#loader-creatures-list").hide();
 +
          $("#creatures-list").html("<i>Error retrieving mob data!</i>");
 +
        }
 +
    });
 
}
 
}
  
 
$(document).ready(function() {
 
$(document).ready(function() {
   $.ajax({
+
   if ($("#creatures-list") != null) {
     type: "GET",
+
     var url = new URL(window.location.href);
     dataType: "json",
+
     var page = url.searchParams.get("page");
     url: "/vv-api/get-creatures.php",
+
     var count = url.searchParams.get("count");
     success: function(data) {
+
     if (page == null) page = 0;
        drawTable(data.result);
+
    if (count == null) count = 10;
     },
+
     query(page, count);
    error: function(status, exec) {
+
   }
        $("#sandbox-output").html("Error retrieving mob data!");
 
    }
 
   });
 
 
});
 
});

Latest revision as of 06:10, 7 August 2019

function drawTable(mobs) {
   var output = $("#creatures-list");
   var html = "<div><a href='/index.php/Data:CreatureForm'><button>Add</button></a></div>";
   html += "<table class='vvwiki-table'><tr><th>Name</th><th>HP</th><th>Damage</th><th>Maturity</th><th>Planets</th><th></th></tr>";
   mobs.creatures.forEach(function(mob) {
      var url = "/index.php/Creatures:"+mob["name"];
      var planets = mob["planets"];
      var planetURLs = "";
      planets.forEach(function(planet) {
         planetURLs += "<a href='index.php/Story:"+planet+"'>"+planet+"</a>&nbsp;&nbsp;";
      });
      var editURL = "/index.php/Data:CreatureForm?id="+mob["_id"];
      
      html += "<tr>";
      html += "<td><b><a href='"+url+"'>"+mob["name"]+"</a></b></td>";
      html += "<td>"+mob["hp"]+"</td>";
      html += "<td>"+mob["min_damage"]+" - "+mob["max_damage"]+"</td>";
      html += "<td>"+mob["maturity"]+"</td>";
      html += "<td>"+planetURLs+"</td>";
      html += "<td><a href='"+editURL+"'>Edit</a></td>";
      html += "</tr>"
   });

   var paging = "<tr><td colspan='10'>";
   mobs.pages.forEach(function(section) {
      var link = "";
      if (section.is_current) {
         link = "&nbsp;&nbsp;[" + section.page + "]&nbsp;&nbsp;";
      } else {
         var path = "/index.php/Creatures?page="+section.start+"&count="+section.count;
         link = "&nbsp;<a href='"+path+"'>"+section.page+"</a>&nbsp;";
      }
      paging += link;
   })
   paging += "</td></tr>";
   html += paging;

   html += "</table>";
   output.html(html);
}

function query(page, count) {
   $("#loader-creatures-list").show();
   $.ajax({
        type: "GET",
        dataType: "json",
        url: "/vv-api/get-creatures.php?page="+page+"&count="+count,
        success: function(data) {
           $("#loader-creatures-list").hide();
           drawTable(data.result);
        },
        error: function(status, exec) {
           $("#loader-creatures-list").hide();
           $("#creatures-list").html("<i>Error retrieving mob data!</i>");
        }
     });
}

$(document).ready(function() {
  if ($("#creatures-list") != null) {
     var url = new URL(window.location.href);
     var page = url.searchParams.get("page");
     var count = url.searchParams.get("count");
     if (page == null) page = 0;
     if (count == null) count = 10;
     query(page, count);
  }
});