Merge pull request #490 from ricardclau/store_api_key

Add support for LocalStorage
This commit is contained in:
William Durand 2014-10-08 11:32:56 +02:00
commit 5950acd73c

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 %}
@ -97,6 +99,9 @@
section.find('.section-list').slideDown('fast');
}
}
{% if enableSandbox %}
loadStoredAuthParams();
{% endif %}
});
$('.toggler').click(function(event) {
@ -143,6 +148,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") {
@ -240,6 +277,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');