(function( $ ){ $(document).ready(function($){ var options = {}; options.ui = { showPopover: false, showErrors: true, showProgressBar: true, showVerdictsInsideProgressBar: true, }; options.rules = { activated: { wordTwoCharacterClasses: true, wordRepetitions: true } }; $(':password').pwstrength(options); var modal = $('#ModalAddPrivateKey'); modal.modal({show:false}); $('#form-add-private-key .input-daterange').datepicker({ startDate: "today", todayBtn: "linked", clearBtn: true, todayHighlight: true, orientation: "bottom right", autoclose: true }); // private key form var form = $('#form-add-private-key'); var validator = form.validate({ rules: { "kid" : { required: true, free_text : true, maxlength:255, minlength: 5 }, "valid_from": { required: true, dateUS:true }, "valid_to": { required: true , dateUS:true }, "pem_content" : { pem_private_key : function(element){ var autogenerate = $("#autogenerate").is(':checked'); return autogenerate? false: true; }}, password: { private_key_password_required: {pem_content_id: '#pem_content'}, minlength: 5 }, "password-confirmation" : { minlength: 5, equalTo : "#password" }, "alg" : {required: true} } }); modal.on('hidden.bs.modal', function () { form.cleanForm(); validator.resetForm(); }) $("body").on('click',".add-private-key",function(event){ modal.modal('show'); validator.resetForm(); $(":password").pwstrength("forceUpdate"); $('#autogenerate').prop('checked', true); $('#active').prop('checked', true); $("#pem_container").hide(); event.preventDefault(); return false; }); $("body").on('click',"#autogenerate",function(event){ var autogenerate = $(this).is(':checked'); if(autogenerate){ $("#pem_container").hide(); } else{ $("#pem_container").show(); } }); $("body").on('click',".delete-private-key",function(event){ if(window.confirm('are you sure?')){ //delete key var private_key_id = $(this).attr('data-private-key-id'); $.ajax( { type: "DELETE", url: privateKeyUrls.delete.replace('@id', private_key_id), contentType: "application/json; charset=utf-8", dataType: "json", timeout: 60000, success: function (data, textStatus, jqXHR) { $('#tr_'+private_key_id).fadeOut(300, function() { $(this).remove(); if($('#body-private-keys').children('tr').length) $('.private-keys-empty-message').hide(); else $('.private-keys-empty-message').show(); }); }, error: function (jqXHR, textStatus, errorThrown) { ajaxError(jqXHR, textStatus, errorThrown); } } ); } event.preventDefault(); return false; }); $("body").on('click',".save-private-key",function(event){ if(form.valid()) { var private_key_data = form.serializeForm(); private_key_data.type = 'RSA'; if(private_key_data.autogenerate) delete private_key_data.pem_content; $.ajax( { type: "POST", url: privateKeyUrls.add, data: JSON.stringify(private_key_data), contentType: "application/json; charset=utf-8", dataType: "json", timeout: 60000, success: function (data, textStatus, jqXHR) { modal.modal('hide'); form.cleanForm(); $('.private-keys-empty-message').hide(); loadPrivateKeys(); }, error: function (jqXHR, textStatus, errorThrown) { ajaxError(jqXHR, textStatus, errorThrown); } } ); } event.preventDefault(); return false; }); $("body").on('click',".private-key-status",function(event){ var status_badge = $(this); var private_key_id = status_badge.attr('data-private-key-id'); var private_key_data = { id : private_key_id }; private_key_data.active = status_badge.hasClass('private-key-active') ? false : true; $.ajax( { type: "PUT", url: privateKeyUrls.update.replace('@id', private_key_id), contentType: "application/json; charset=utf-8", data: JSON.stringify(private_key_data), dataType: "json", timeout: 60000, success: function (data, textStatus, jqXHR) { loadPrivateKeys(); }, error: function (jqXHR, textStatus, errorThrown) { ajaxError(jqXHR, textStatus, errorThrown); } } ); event.preventDefault(); return false; }); $('#usage').change(function(){ var usage = $(this).val(); var alg_select = $('#alg'); alg_select.empty(); var result = []; if(usage === 'sig') { result = oauth2_supported_algorithms.sig_algorihtms.rsa; } else { result = oauth2_supported_algorithms.key_management_algorihtms; } $.each(result, function(index, item) { var key = item === 'none' ? '' : item; alg_select.append($("").val(key).text(item)); }); }); $('#usage').trigger('change'); }); function loadPrivateKeys(){ $.ajax({ type: "GET", url: privateKeyUrls.get+'?offset=1&limit=4294967296', dataType: "json", timeout:60000, success: function (data,textStatus,jqXHR) { //load data... var private_keys = data.page; if(private_keys.length > 0){ var template = $('
' + '
'+
'