support for localstorage

This commit is contained in:
Ricard Clau 2014-08-23 12:24:50 +01:00
parent 6952c4b32c
commit 08153a3071

View File

@ -43,6 +43,8 @@
{% if authentication.custom_endpoint %}
api endpoint: <input type="text" id="api_endpoint" value=""/>
{% endif %}
<button id="save_api_auth" type="button">Save</button>
<button id="clear_api_auth" type="button">Clear</button>
{% endif %}
</div>
{% endif %}
@ -92,6 +94,9 @@
});
elem.find('.toggler').click();
}
{% if enableSandbox %}
loadStoredAuthParams();
{% endif %}
});
$('.toggler').click(function(event) {
@ -108,6 +113,38 @@
});
{% if enableSandbox %}
var getStoredValue, storeValue, deleteStoredValue;
var apiAuthKeys = ['api_key', 'api_login', 'api_pass', 'api_endpoint'];
if ('localStorage' in window) {
var buildKey = function (key) {
return 'nelmio_' + key;
}
getStoredValue = function (key) {
return localStorage.getItem(buildKey(key));
}
storeValue = function (key, value) {
localStorage.setItem(buildKey(key), value);
}
deleteStoredValue = function (key) {
localStorage.removeItem(buildKey(key));
}
} else {
getStoredValue = storeValue = deleteStoredValue = function (){};
}
var loadStoredAuthParams = function() {
$.each(apiAuthKeys, function(_, value) {
var elm = $('#' + value);
if (elm.length) {
elm.val(getStoredValue(value));
}
});
}
var setParameterType = function ($context,setType) {
// no 2nd argument, use default from parameters
if (typeof setType == "undefined") {
@ -205,6 +242,25 @@
return body;
}
$('#save_api_auth').click(function(event) {
$.each(apiAuthKeys, function(_, value) {
var elm = $('#' + value);
if (elm.length) {
storeValue(value, elm.val());
}
});
});
$('#clear_api_auth').click(function(event) {
$.each(apiAuthKeys, function(_, value) {
deleteStoredValue(value);
var elm = $('#' + value);
if (elm.length) {
elm.val('');
}
});
});
$('.tabs li').click(function() {
var contentGroup = $(this).parents('.content');