1 line
2.2 KiB
JavaScript
1 line
2.2 KiB
JavaScript
!function(e){new(Backbone.View.extend({el:e("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){e(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){e(this.el).unblock()},initTipTip:function(i){e(document.body).on("aftercopy",i,function(t){!0===t.success["text/plain"]?(e("#copy-error").text(""),e(i).tipTip({attribute:"data-tip",activation:"focus",fadeIn:50,fadeOut:50,delay:0}).focus()):(e(i).parent().find("input").focus().select(),e("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("click",i,function(){document.queryCommandSupported("copy")||(e(i).parent().find("input").focus().select(),e("#copy-error").text(woocommerce_admin_api_keys.clipboard_failed))}).on("copy",i,function(i){e("#copy-error").text(""),i.clipboardData.clearData(),i.clipboardData.setData("text/plain",e.trim(e(this).prev("input").val())),i.preventDefault()})},createQRCode:function(i,t){e("#keys-qrcode").qrcode({text:i+"|"+t,width:120,height:120})},saveKey:function(i){i.preventDefault();var t=this;t.block(),Backbone.ajax({method:"POST",dataType:"json",url:woocommerce_admin_api_keys.ajax_url,data:{action:"woocommerce_update_api_key",security:woocommerce_admin_api_keys.update_api_nonce,key_id:e("#key_id",t.el).val(),description:e("#key_description",t.el).val(),user:e("#key_user",t.el).val(),permissions:e("#key_permissions",t.el).val()},success:function(i){if(e(".wc-api-message",t.el).remove(),i.success){var a=i.data;if(e("h3",t.el).first().append('<div class="wc-api-message updated"><p>'+a.message+"</p></div>"),0<a.consumer_key.length&&0<a.consumer_secret.length){e("#api-keys-options",t.el).remove(),e("p.submit",t.el).empty().append(a.revoke_url);var o=wp.template("api-keys-template");e("p.submit",t.el).before(o({consumer_key:a.consumer_key,consumer_secret:a.consumer_secret})),t.createQRCode(a.consumer_key,a.consumer_secret),t.initTipTip(".copy-key"),t.initTipTip(".copy-secret")}else e("#key_description",t.el).val(a.description),e("#key_user",t.el).val(a.user_id),e("#key_permissions",t.el).val(a.permissions)}else e("h3",t.el).first().append('<div class="wc-api-message error"><p>'+i.data.message+"</p></div>");t.unblock()}})}}))}(jQuery); |