Kenneth Love avatar Kenneth Love committed 2829ea4

js fixes

Comments (0)

Files changed (3)

     elif rtype == 'string':
         r.set(key, value)
 
+    key_changed = 'false'
+    if request.form['key_name'] != request.form['saved_key_name']:
+        r.rename(key, request.form['key_name'])
+        key = request.form['key_name']
+        key_changed = 'true'
+
     return jsonify(
         flash=key + ' was saved successfully',
-        value=value
+        value=value,
+        key=key,
+        key_changed=key_changed
     )
 
 @app.route('/key/new/string', methods=['GET', 'POST'])

static/js/redbeard.js

                     $(list).html('<li>An error occurred. Make sure redis is running and reload the page.</li>');
                 });
         } else {
-            $(list).empty();
-            var jqxhr = $.getJSON('/search/' + filter)
-                .success(function(data) {
-                    var items = [];
-                    $.each(data['keys'], function(key, value) {
-                        items.push('<li><a href="/key/' + value + '/">' + value + '</a></li>');
-                    });
-                    $(list).html(items.join(''));
-                })
-                .error(function() {
-                    $(list).html('<li>An error occurred. Make sure redis is running and reload the page.</li>');
-                });
+            update_keys();
         }
     }).keyup(function() {
         $(this).change();
     });
 }
 
+function update_keys() {
+    list = $("#keylist");
+    $(list).empty();
+    var jqxhr = $.getJSON('/search/')
+        .success(function(data) {
+            var items = [];
+            $.each(data['keys'], function(key, value) {
+                items.push('<li><a href="/key/' + value + '/">' + value + '</a></li>');
+            });
+            $(list).html(items.join(''));
+        })
+        .error(function() {
+            $(list).html('<li>An error occurred. Make sure redis is running and reload the page.</li>');
+        });
+    $(window).hashchange();
+}
+
 $(window).hashchange(function() {
-    var hash = window.location.hash.replace('#', '');
+    var hash = location.hash.replace('#', '');
     if (hash != '') {
         var link = '/key/' + hash;
         $.get(link, function(data) {
             $('#right').html(data);
         });
         $('li', '#keylist').removeClass('current');
-        $('a[href=' + link + ']', '#keylist').parent('li').addClass('current');
+        $('a[href="' + link + '"]', '#keylist').parent('li').addClass('current');
         $('#keylist').scrollTo('.current');
     } else {
         $('#right').empty();
     listFilter($('#keyheader'), $('#keylist'));
     $(".filterform").live('submit', function(e) { e.preventDefault(); });
 
-    if (window.location.hash) {
-        var link = '/key/' + window.location.hash.replace('#', '');
-        $('a[href=' + link + ']', '#keylist').parent('li').addClass('current');
+    if (location.hash) {
+        var link = '/key/' + location.hash.replace('#', '');
+        $('a[href="' + link + '"]', '#keylist').parent('li').addClass('current');
 
         $.get(link, function(data) {
             $('#right').html(data);
         });
     });
 
+    $(window).hashchange();
+
     $('#id_redis_db').live('change', function() {
         $(this).parent().parent('form').submit();
     });
             }
         });
     });
+    var flashes = $("#flashes");
+
+    $("#refresh").live('click', function(e) {
+        e.stopPropagation();
+        e.preventDefault();
+        var link = $(this).attr('href'),
+            hash = link.replace("/key/", "");
+        $.get(link, function(data) {
+            $('#right').html(data);
+            window.location.hash = hash;
+        });
+    });
+
+    $("#delete").live('click', function(e) {
+        e.stopPropagation();
+        e.preventDefault();
+        var link = $(this).attr("href");
+        $.confirm({
+            'title': 'Delete Confirmation',
+            'message': 'Are you sure you want to delete this key?',
+            'buttons': {
+                'Yes': {
+                    'class': 'go',
+                    'action': function() {
+                        $.ajax({
+                            url: link,
+                            dataType: "json",
+                            success: function(data) {
+                                flashes.empty();
+                                $("<li>").text(data['flash']).appendTo(flashes);
+                                $("#refresh_keys").trigger('click');
+                            }
+                        });
+                    }
+                },
+                'No': {
+                    'class': 'stop'
+                }
+            }
+        });
+    });
+
+    $("#key").live('submit', function(e) {
+        e.stopPropagation();
+        e.preventDefault();
+
+        var link = $(this).attr("action"),
+            flashes = $("#flashes"),
+            saved_name = $(this).find("input[name=saved_key_name]").val();
+
+        flashes.empty();
+
+        $.ajax({
+            url: link,
+            type: "POST",
+            data: {
+                "key_name": $(this).find("input[name=key_name]").val(),
+                "saved_key_name": saved_name,
+                "value": $(this).find("textarea").val()
+            },
+            dataType: "json",
+            success: function(data) {
+                $(this).find("textarea").val(data['value']);
+                $(this).find("input[name=key_name], input[name=saved_key_name]").val(data['key']);
+                $("<li>").text(data['flash']).appendTo(flashes);
+                if (data['key_changed'] = 'true') {
+                    location.hash = data['key'];
+                    update_keys();
+                }
+            }
+        });
+    });
 });

templates/key.html

-<article id="key">
-	<header>
-		<h2>{{ rtype }}: <b>{{ key }}</b></h2>
-		{% if ttl %}
-		<h3>Key expires in: {{ ttl }} seconds</h3>
-		{% endif %}
-	</header>
+<article>
 	<form action="{{ url_for('save', key=key) }}" method="post" id="key">
+		<header>
+			<h2>{{ rtype }}</h2>
+			<input type="text" name="key_name" value="{{ key }}">
+			<input type="hidden" name="saved_key_name" value="{{ key }}">
+			{% if ttl %}
+			<h3>Key expires in: {{ ttl }} seconds</h3>
+			{% endif %}
+		</header>
 		<textarea name="value" cols="60" rows="20">{{ output }}</textarea>
 		<div id="controls">
 			<a id="refresh" href="{{ url_for('key', key=key) }}" title="refresh">refresh</a>
 		</div>
 	</form>
 </article>
-
-<script>
-	$(function() {
-		var flashes = $("#flashes");
-
-		$("#refresh").live('click', function(e) {
-        	var link = $(this).attr('href'),
-            	hash = link.replace("/key/", "");
-        	e.preventDefault();
-        	$.get(link, function(data) {
-            	$('#right').html(data);
-            	window.location.hash = hash;
-        	});
-		});
-
-		$("#delete").live('click', function(e) {
-			e.stopPropagation();
-			e.preventDefault();
-			var link = $(this).attr("href");
-			$.confirm({
-				'title': 'Delete Confirmation',
-				'message': 'Are you sure you want to delete this key?',
-				'buttons': {
-					'Yes': {
-						'class': 'go',
-						'action': function() {
-							$.ajax({
-								url: link,
-								dataType: "json",
-								success: function(data) {
-									flashes.empty();
-									$("<li>").text(data['flash']).appendTo(flashes);
-									$("#refresh_keys").trigger('click');
-								}
-							});
-						}
-					},
-					'No': {
-						'class': 'stop'
-					}
-				}
-			});
-		});
-
-    	$("#key").submit(function(e) {
-        	e.preventDefault();
-
-			var link = $(this).attr("action"),
-				flashes = $("#flashes");
-
-			flashes.empty();
-
-			$.ajax({
-				url: link,
-				type: "POST",
-				data: {
-					"value": $(this).find("textarea").val()
-				},
-				dataType: "json",
-				success: function(data) {
-					$(this).find("textarea").val(data['value']);
-					$("<li>").text(data['flash']).appendTo(flashes);
-				}
-			});
-    	});
-	});
-</script>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.