commit 9a49c9e5a3abf396d95ab7517437b58d4139de0d
parent f09ba9ec1a411c6e8775dd956300bc6a8e093e5f
Author: Sheng <webmaster0115@gmail.com>
Date: Tue, 21 Aug 2018 21:46:16 +0800
Use localStorage
Diffstat:
2 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/webssh/static/js/main.js b/webssh/static/js/main.js
@@ -7,9 +7,31 @@ jQuery(function($){
var status = $('#status'),
btn = $('.btn-primary'),
- style = {};
+ style = {},
+ names = ['hostname', 'port', 'username', 'password'];
+ function store_items(names, data) {
+ var i, name;
+
+ for (i = 0; i < names.length; i++) {
+ name = names[i];
+ window.localStorage.setItem(name, data.get(name));
+ }
+ }
+
+ function restore_items(names) {
+ var i, name, value;
+
+ for (i=0; i < names.length; i++) {
+ name = names[i];
+ value = window.localStorage.getItem(name) || '';
+ $('#'+name).val(value);
+ }
+ }
+
+ restore_items(names);
+
function parse_xterm_style() {
var text = $('.xterm-helpers style').text();
var arr = text.split('xterm-normal-char{width:');
@@ -236,6 +258,8 @@ jQuery(function($){
return;
}
+ store_items(names, data);
+
status.text('');
btn.prop('disabled', true);
diff --git a/webssh/templates/index.html b/webssh/templates/index.html
@@ -17,6 +17,9 @@
margin-top: 20px;
}
+ .btn-danger {
+ margin-left: 5px;
+ }
</style>
</head>
<body>
@@ -25,21 +28,21 @@
<div class="row">
<div class="col">
<label for="Hostname">Hostname</label>
- <input class="form-control" type="text" name="hostname" value="" required>
+ <input class="form-control" type="text" id="hostname" name="hostname" value="" required>
</div>
<div class="col">
<label for="Port">Port</label>
- <input class="form-control" type="number" name="port" min=1 max=65535 value="" required>
+ <input class="form-control" type="number" id="port" name="port" min=1 max=65535 value="" required>
</div>
</div>
<div class="row">
<div class="col">
<label for="Username">Username</label>
- <input class="form-control" type="text" name="username" value="" required>
+ <input class="form-control" type="text" id="username" name="username" value="" required>
</div>
<div class="col">
<label for="Username">Private Key</label>
- <input class="form-control" type="file" name="privatekey" value="">
+ <input class="form-control" type="file" id="privatekey" name="privatekey" value="">
</div>
</div>
<div class="row">
@@ -53,6 +56,7 @@
</div>
{% module xsrf_form_html() %}
<button type="submit" class="btn btn-primary">Connect</button>
+ <button type="reset" class="btn btn-danger">Reset</button>
</form>
</div>