Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*global $, console */
- var Main = (function () {
- 'use strict';
- function Main() {
- this.ipList = [];
- this.ipCurrentIndex = 0;
- this.loadIpList();
- }
- Main.prototype.loadIpList = function () {
- $.ajax({
- url: "iplist.php",
- method: "get",
- data: {},
- dataType: "json"
- }).done(function (r) {
- this.ipList = r;
- this.ipCurrentIndex = 0;
- this.processIp();
- }.bind(this)).fail(function (r) {
- console(r.responseText);
- }.bind(this));
- };
- Main.prototype.processIp = function () {
- var currentIP = this.ipList[this.ipCurrentIndex];
- console.log(currentIP);
- $.ajax({
- url: "process.php",
- method: "get",
- data: {ip: currentIP},
- dataType: "json"
- }).done(function (r) {
- if (r.data !== null) {
- this.displayData(r);
- console.log(r);
- }
- }.bind(this)).fail(function (r) {
- console.log(r.responseText);
- }.bind(this));
- };
- Main.prototype.displayData = function (r) {
- var table = $("#mainTable"), mounts = [];
- r.data.forEach(function (z) {
- var m;
- for (m in z.MOUNTS) {
- console.log(m);
- /* if (z.MOUNTS.hasOwnProperty(m)) {*/
- if(z.MOUNTS[m]) {
- if (parseInt(z.MOUNTS[m].capacity, 10) > 89) {
- mounts.push({
- name: z.NAME,
- ip:z.IP,
- mount: m,
- size: z.MOUNTS[m].capacity
- });
- }
- }
- }
- });
- mounts.sort(function (a, b) {
- var sa = parseInt(a.size, 10), sb = parseInt(b.size, 10);
- if (sa > sb) {
- return 1;
- }
- if (sa < sb) {
- return -1;
- }
- return 0;
- });
- mounts.forEach(function (e) {
- var row = $("<tr><td>" + e.name + "</td><td>" + e.ip + "</td><td>" + e.size + "</td><td>" + e.mount + "</td></tr>");
- table.append(row);
- });
- this.ipCurrentIndex += 1;
- this.processIp();
- };
- return Main;
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement