mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Merge pull request #490 from ricardclau/store_api_key
Add support for LocalStorage
This commit is contained in:
commit
5950acd73c
@ -43,6 +43,8 @@
|
|||||||
{% if authentication.custom_endpoint %}
|
{% if authentication.custom_endpoint %}
|
||||||
api endpoint: <input type="text" id="api_endpoint" value=""/>
|
api endpoint: <input type="text" id="api_endpoint" value=""/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<button id="save_api_auth" type="button">Save</button>
|
||||||
|
<button id="clear_api_auth" type="button">Clear</button>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -97,6 +99,9 @@
|
|||||||
section.find('.section-list').slideDown('fast');
|
section.find('.section-list').slideDown('fast');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{% if enableSandbox %}
|
||||||
|
loadStoredAuthParams();
|
||||||
|
{% endif %}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.toggler').click(function(event) {
|
$('.toggler').click(function(event) {
|
||||||
@ -143,6 +148,38 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
{% if enableSandbox %}
|
{% 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) {
|
var setParameterType = function ($context,setType) {
|
||||||
// no 2nd argument, use default from parameters
|
// no 2nd argument, use default from parameters
|
||||||
if (typeof setType == "undefined") {
|
if (typeof setType == "undefined") {
|
||||||
@ -240,6 +277,25 @@
|
|||||||
return body;
|
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() {
|
$('.tabs li').click(function() {
|
||||||
var contentGroup = $(this).parents('.content');
|
var contentGroup = $(this).parents('.content');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user