Commits

Chris Jones committed 82ac34c

Added a delete image. Created new view to handle deletetion of keys. Some CSS goodness for the new delete button. Unfortunately had to write some js, scary. Ajax call works but has a bug and is calling twice. It works for now. Ken, my js god should be able to fix that.

Comments (0)

Files changed (5)

         value=value
     )
 
+@app.route('/key/delete/<key>', methods=['GET'])
+def delete(key):
+    """ Delete key """
+    r = get_redis_connection(session)
+
+    if r.exists(key):
+        r.delete(key)
+        return jsonify(flash="Key '" + key + "' was deleted successfully")
+    else:
+        return jsonify(flash="Key '" + key + "' was not found in Redis")
+
 if __name__ == '__main__':
     app.run()

static/css/style.css

     width:32px;
   }
 
-  #refresh {
+  #refresh, #delete {
     background:url('../img/reload.png') center center no-repeat;
     display:block;
     float:right;
     text-indent:-99999px;
     width:24px;
   }
+
+  #delete {
+    background:url('../img/delete.png') center center no-repeat;
+    height:28px;
+    margin-right:220px;
+    width:28px;
+  }
     
 
 footer {

static/img/delete.png

Added
New image

templates/index.html

 {% endblock %}
 
 {% block content %}
-<p>Hi! I'm some content!</p>
 {% endblock %}
 
 {% block extra_scripts %}

templates/key.html

 		<textarea name="value" cols="60" rows="20">{{ output }}</textarea>
 		<br>
 		<a id="refresh" href="{{ url_for('key', key=key) }}" title="refresh">refresh</a>
+		<a id="delete" href="{{ url_for('delete', key=key) }}" title="delete">delete</a>
 		<input type="submit" value="save" title="save">
 	</form>
 </article>
         	});
 		});
 
+		$("#delete").live('click', function(e) {
+			e.preventDefault();
+			e.stopPropagation();
+
+			var link = $(this).attr("href"),
+				flashes = $("#flashes");
+
+			flashes.empty();
+
+			if (confirm('Are you sure you want to delete this key?')) {
+				$.ajax({
+					url: link,
+					dataType: "json",
+					success: function(data) {
+						$("<li>").text(data['flash']).appendTo(flashes);
+						$("#keylist li.current").remove();
+						window.location.hash = '';
+					}
+				});
+			}
+		});
+
     	$("#key").submit(function(e) {
         	e.preventDefault();