mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
support for localstorage
This commit is contained in:
parent
6952c4b32c
commit
08153a3071
@ -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 %}
|
||||||
@ -92,6 +94,9 @@
|
|||||||
});
|
});
|
||||||
elem.find('.toggler').click();
|
elem.find('.toggler').click();
|
||||||
}
|
}
|
||||||
|
{% if enableSandbox %}
|
||||||
|
loadStoredAuthParams();
|
||||||
|
{% endif %}
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.toggler').click(function(event) {
|
$('.toggler').click(function(event) {
|
||||||
@ -108,38 +113,70 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
{% if enableSandbox %}
|
{% if enableSandbox %}
|
||||||
var setParameterType = function ($context,setType) {
|
var getStoredValue, storeValue, deleteStoredValue;
|
||||||
// no 2nd argument, use default from parameters
|
var apiAuthKeys = ['api_key', 'api_login', 'api_pass', 'api_endpoint'];
|
||||||
if (typeof setType == "undefined") {
|
|
||||||
setType = $context.parent().attr("data-dataType");
|
|
||||||
$context.val(setType);
|
|
||||||
}
|
|
||||||
|
|
||||||
$context.parent().find('.value').remove();
|
if ('localStorage' in window) {
|
||||||
var placeholder = "";
|
var buildKey = function (key) {
|
||||||
if ($context.parent().attr("data-dataType") != "" && typeof $context.parent().attr("data-dataType") != "undefined") {
|
return 'nelmio_' + key;
|
||||||
placeholder += "[" + $context.parent().attr("data-dataType") + "] ";
|
}
|
||||||
}
|
|
||||||
if ($context.parent().attr("data-format") != "" && typeof $context.parent().attr("data-format") != "undefined") {
|
getStoredValue = function (key) {
|
||||||
placeholder += $context.parent().attr("data-dataType");
|
return localStorage.getItem(buildKey(key));
|
||||||
}
|
}
|
||||||
if ($context.parent().attr("data-description") != "" && typeof $context.parent().attr("data-description") != "undefined") {
|
|
||||||
placeholder += $context.parent().attr("data-description");
|
storeValue = function (key, value) {
|
||||||
|
localStorage.setItem(buildKey(key), value);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteStoredValue = function (key) {
|
||||||
|
localStorage.removeItem(buildKey(key));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
placeholder += "Value";
|
getStoredValue = storeValue = deleteStoredValue = function (){};
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(setType) {
|
var loadStoredAuthParams = function() {
|
||||||
case "boolean":
|
$.each(apiAuthKeys, function(_, value) {
|
||||||
$('<select class="value"><option value=""></option><option value="1">True</option><option value="0">False</option></select>').insertAfter($context);
|
var elm = $('#' + value);
|
||||||
break;
|
if (elm.length) {
|
||||||
case "file":
|
elm.val(getStoredValue(value));
|
||||||
$('<input type="file" class="value" placeholder="'+ placeholder +'">').insertAfter($context);
|
}
|
||||||
break;
|
});
|
||||||
default:
|
|
||||||
$('<input type="text" class="value" placeholder="'+ placeholder +'">').insertAfter($context);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
var setParameterType = function ($context,setType) {
|
||||||
|
// no 2nd argument, use default from parameters
|
||||||
|
if (typeof setType == "undefined") {
|
||||||
|
setType = $context.parent().attr("data-dataType");
|
||||||
|
$context.val(setType);
|
||||||
|
}
|
||||||
|
|
||||||
|
$context.parent().find('.value').remove();
|
||||||
|
var placeholder = "";
|
||||||
|
if ($context.parent().attr("data-dataType") != "" && typeof $context.parent().attr("data-dataType") != "undefined") {
|
||||||
|
placeholder += "[" + $context.parent().attr("data-dataType") + "] ";
|
||||||
|
}
|
||||||
|
if ($context.parent().attr("data-format") != "" && typeof $context.parent().attr("data-format") != "undefined") {
|
||||||
|
placeholder += $context.parent().attr("data-dataType");
|
||||||
|
}
|
||||||
|
if ($context.parent().attr("data-description") != "" && typeof $context.parent().attr("data-description") != "undefined") {
|
||||||
|
placeholder += $context.parent().attr("data-description");
|
||||||
|
} else {
|
||||||
|
placeholder += "Value";
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(setType) {
|
||||||
|
case "boolean":
|
||||||
|
$('<select class="value"><option value=""></option><option value="1">True</option><option value="0">False</option></select>').insertAfter($context);
|
||||||
|
break;
|
||||||
|
case "file":
|
||||||
|
$('<input type="file" class="value" placeholder="'+ placeholder +'">').insertAfter($context);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$('<input type="text" class="value" placeholder="'+ placeholder +'">').insertAfter($context);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var toggleButtonText = function ($btn) {
|
var toggleButtonText = function ($btn) {
|
||||||
if ($btn.text() === 'Default') {
|
if ($btn.text() === 'Default') {
|
||||||
@ -205,6 +242,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