Use populate_form rather than restore_items

pull/83/head
Sheng 2019-08-25 16:35:19 +08:00
parent 18b20de3a4
commit d496b4ff87
1 changed files with 18 additions and 11 deletions

View File

@ -76,16 +76,12 @@ jQuery(function($){
}
function restore_items(names, storage) {
function restore_items(names) {
var i, name, value;
if (storage === undefined) {
storage = window.localStorage;
}
for (i=0; i < names.length; i++) {
name = names[i];
value = storage.getItem(name);
value = window.localStorage.getItem(name);
if (value) {
$('#'+name).val(value);
}
@ -93,6 +89,17 @@ jQuery(function($){
}
function populate_form(data) {
var names = form_keys.concat(['passphrase']),
i, name;
for (i=0; i < names.length; i++) {
name = names[i];
$('#'+name).val(data.get(name));
}
}
function get_object_length(object) {
return Object.keys(object).length;
}
@ -310,12 +317,12 @@ jQuery(function($){
}
function log_status(text, fill_form) {
function log_status(text, to_populate) {
console.log(text);
status.html(text.split('\n').join('<br/>'));
if (fill_form && validated_form_data) {
restore_items(fields.concat(['password']), validated_form_data);
if (to_populate && validated_form_data) {
populate_form(validated_form_data);
validated_form_data = undefined;
}
@ -539,7 +546,7 @@ jQuery(function($){
function wrap_object(opts) {
var obj = {};
obj.getItem = obj.get = function(attr) {
obj.get = function(attr) {
return opts[attr] || '';
};
@ -553,7 +560,7 @@ jQuery(function($){
function clean_data(data) {
var i, attr, val;
var attrs = fields.concat(['password', 'privatekey', 'passphrase', 'totp']);
var attrs = form_keys.concat(['privatekey', 'passphrase']);
for (i = 0; i < attrs.length; i++) {
attr = attrs[i];