Commit 6f9f60a0 authored by Pieter-Jan's avatar Pieter-Jan
Browse files

Merge pull request #105 from PidgeyL/development

initial commit moving funtions to ajax
parents 13b0a072 9fe8f850
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -723,12 +723,13 @@ def blacklistEdit():
    return render_template('list.html', rules=blacklist, status=status, listType="Blacklist")


@app.route('/admin/listmanagement/add', methods=['POST'])
@app.route('/admin/listmanagement/add')
@login_required
def listManagementAdd():
    # retrieve the separate item parts
    item = request.form.get('item')
    listType = request.form.get('list')
    item = request.args.get('item', type=str)
    listType = request.args.get('list', type=str)

    vendor = None
    product = None
    version = None
@@ -776,7 +777,8 @@ def listManagementAdd():
        browseList = getBrowseList(None)
        vendor = browseList['vendor']
        status = ["invalid_cpe_format", "error"]
    return render_template('listmanagement.html', status=status, listType=listType, vendor=vendor, product=product, version=version)
    j={"status":status, "listType":listType}
    return jsonify(j)


@app.route('/admin/listmanagement/<vendor>/<product>')
+17 −0
Original line number Diff line number Diff line
@@ -105,3 +105,20 @@ ul.nav li.dropdown:hover > ul.dropdown-menu {
   width:100%;
   text-align:center;
}


#status {
   position:fixed;
   top: 50%;
   left: 50%;
   width:50em;
   height:6em;
   margin-top: -3em;
   margin-left: -25em;
   border: 1px solid #ccc;
   text-align:center;
}

.hidden {
   visibility:hide;
}
+15 −0
Original line number Diff line number Diff line
@@ -25,3 +25,18 @@ jQuery(document).ready(function() {
    return false;
  })
});

//Temporary undo class
(function($){
  $.fn.extend({ 
    removeTemporaryClass: function(className, duration) {
      var elements = this;
      setTimeout(function() {
        elements.addClass(className);
      }, duration);
      return this.each(function() {
        $(this).removeClass(className);
      });
    }
  });
})(jQuery);
+31 −46
Original line number Diff line number Diff line
@@ -7,23 +7,34 @@
  <!-- javascript -->
  <script type="text/javascript">
    function addCPE(list, item){
      var url = "/admin/listmanagement/add";
      var form = document.createElement("FORM");
      form.method = "POST";
      form.style.display = "none";
      document.body.appendChild(form);
      form.action = url
      inputList = document.createElement("INPUT");
      inputList.type = "hidden";
      inputList.name = "list"
      inputList.value = list
      form.appendChild(inputList);
      inputItem = document.createElement("INPUT");
      inputItem.type = "hidden";
      inputItem.name = "item"
      inputItem.value = item
      form.appendChild(inputItem);
      form.submit();
      $.getJSON('/admin/listmanagement/add', {
        list:list, item:item
      }, function(data) {
        $("#status").removeClass();
        $("#status_icon").removeClass();
        if(data['status'][1] =='success'){
          $("#status").addClass("alert alert-success");
          $("#status_icon").addClass("glyphicon glyphicon-ok-sign");
        }else if (data['status'][1] =='info'){
          $("#status").addClass("alert alert-info");
          $("#status_icon").addClass("glyphicon glyphicon-info-sign");
        }else if (data['status'][1] =='warning'){
          $("#status").addClass("alert alert-warning");
          $("#status_icon").addClass("glyphicon glyphicon-warning-sign");
        }else if (data['status'][1] =='error'){
          $("#status").addClass("alert alert-danger");
          $("#status_icon").addClass("glyphicon glyphicon-remove-sign");
        }
        $("#status_message").empty();
        if(data['status'][0] =='cpe_added'){
			$("#status_message").append("Product added to the "+data["listType"]);
		}else if(data['status'][0] == 'cpe_not_added'){
			$("#status_message").append("Failed to add the product to the "+data["listType"]);
		}else if(data['status'][0] == 'invalid_cpe_format'){
			$("#status_message").append("The entered CPE format is invalid");
		}
		$("#status").removeTemporaryClass("hidden", 3000);
      });
    }
  </script>
</head>
@@ -52,35 +63,9 @@
            {% endif %}
          </ol>
          <!-- Status -->
          <div>
            <!-- type -->
            {% if status[1] == 'success' %}
              <div class="alert alert-success">
                <span class="glyphicon glyphicon-ok-sign"></span>
            {% elif status[1] == 'info' %}
              <div class="alert alert-info">
                <span class="glyphicon glyphicon-info-sign"></span>
            {% elif status[1] == 'warning' %}
              <div class="alert alert-warning">
                <span class="glyphicon glyphicon-warning-sign"></span>
            {% elif status[1] == 'error' %}
              <div class="alert alert-danger">
                <span class="glyphicon glyphicon-remove-sign"></span>
            {% else %}
              <div>
            {% endif %}
              <!-- content -->
              {% if (status[0] == 'cpe_added') %}
                Product added to the {{ listType }}
              {% elif status[0] == 'cpe_not_added' %}
                Failed to add the product to the {{ listType }}
              {% elif (status[0] == 'invalid_cpe_format') %}
                The entered CPE format is invalid
              {% endif %}
              {% if (status[0] != 'default') %}
                <br /><br /><a href="/admin/listmanagement"><span class="glyphicon glyphicon-arrow-left"></span> Back to vendors</a>
              {% endif %}
              </div>
          <div id="status" class="hidden">
            <span id="status_icon"></span>
            <div id="status_message"></div>
          </div>
          <!-- vendor/product/version -->
          <table class="table table-hover table-striped">