Advertisement
bentech4u

main.js

May 18th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*global $, console */
  2.  
  3.  
  4. var Main = (function () {
  5.     'use strict';
  6.     function Main() {
  7.         this.ipList = [];
  8.         this.ipCurrentIndex = 0;
  9.  
  10.         this.loadIpList();
  11.     }
  12.  
  13.  
  14.     Main.prototype.loadIpList = function () {
  15.         $.ajax({
  16.             url: "iplist.php",
  17.             method: "get",
  18.             data: {},
  19.             dataType: "json"
  20.         }).done(function (r) {
  21.             this.ipList = r;
  22.             this.ipCurrentIndex = 0;
  23.             this.processIp();
  24.         }.bind(this)).fail(function (r) {
  25.             console(r.responseText);
  26.         }.bind(this));
  27.     };
  28.  
  29.     Main.prototype.processIp = function () {
  30.         var currentIP = this.ipList[this.ipCurrentIndex];
  31.         console.log(currentIP);
  32.         $.ajax({
  33.             url: "process.php",
  34.             method: "get",
  35.             data: {ip: currentIP},
  36.             dataType: "json"
  37.         }).done(function (r) {
  38.             if (r.data !== null) {
  39.                this.displayData(r);
  40.               console.log(r);
  41.             }
  42.         }.bind(this)).fail(function (r) {
  43.             console.log(r.responseText);
  44.         }.bind(this));
  45.     };
  46.  
  47.     Main.prototype.displayData = function (r) {
  48.         var table = $("#mainTable"), mounts = [];
  49.         r.data.forEach(function (z) {
  50.             var m;
  51.             for (m in z.MOUNTS) {
  52.                 console.log(m);
  53.              /*   if (z.MOUNTS.hasOwnProperty(m)) {*/
  54.                 if(z.MOUNTS[m]) {
  55.                     if (parseInt(z.MOUNTS[m].capacity, 10) > 89) {
  56.                         mounts.push({
  57.                             name: z.NAME,
  58.                             ip:z.IP,
  59.                             mount: m,
  60.                             size: z.MOUNTS[m].capacity
  61.                         });
  62.                     }
  63.                 }
  64.             }
  65.         });
  66.  
  67.         mounts.sort(function (a, b) {
  68.             var sa = parseInt(a.size, 10), sb = parseInt(b.size, 10);
  69.  
  70.             if (sa > sb) {
  71.                 return 1;
  72.             }
  73.             if (sa < sb) {
  74.                 return -1;
  75.             }
  76.             return 0;
  77.         });
  78.  
  79.         mounts.forEach(function (e) {
  80.             var row = $("<tr><td>" + e.name + "</td><td>" + e.ip + "</td><td>" + e.size + "</td><td>" + e.mount + "</td></tr>");
  81.             table.append(row);
  82.         });
  83.  
  84.         this.ipCurrentIndex  += 1;
  85.         this.processIp();
  86.  
  87.     };
  88.  
  89.     return Main;
  90. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement