Hide api key fields when generate a new keys

This commit is contained in:
Claudio Sanches 2015-06-08 20:22:49 -03:00
parent 151499db49
commit 4698111dd2
5 changed files with 12 additions and 14 deletions

View File

@ -70,13 +70,9 @@
$( 'h3', self.el ).first().append( '<div class="wc-api-message updated"><p>' + data.message + '</p></div>' );
$( '#key_id', self.el ).val( data.key_id );
$( '#key_description', self.el ).val( data.description );
$( '#key_user', self.el ).val( data.user_id );
$( '#key_permissions', self.el ).val( data.permissions );
if ( 0 < data.consumer_key.length && 0 < data.consumer_secret.length ) {
$( '#update_api_key', self.el ).val( woocommerce_admin_api_keys.i18n_save_changes ).after( data.revoke_url );
$( '#api-keys-options', self.el ).remove();
$( 'p.submit', self.el ).empty().append( data.revoke_url );
var keysTemplate = _.template( $( '#api-keys-template' ).html(), {
consumer_key: data.consumer_key,
@ -86,6 +82,10 @@
$( 'p.submit', self.el ).before( keysTemplate );
self.createQRCode( data.consumer_key, data.consumer_secret );
self.initTipTip();
} else {
$( '#key_description', self.el ).val( data.description );
$( '#key_user', self.el ).val( data.user_id );
$( '#key_permissions', self.el ).val( data.permissions );
}
} else {
$( 'h3', self.el ).first().append( '<div class="wc-api-message error"><p>' + response.data.message + '</p></div>' );

View File

@ -1 +1 @@
!function(a){var b=Backbone.View.extend({el:a("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},initTipTip:function(){a(".copy-key",this.el).tipTip({attribute:"data-tip",activation:"click",fadeIn:50,fadeOut:50,delay:0}),a(document.body).on("copy",".copy-key",function(b){b.clipboardData.clearData(),b.clipboardData.setData("text/plain",a.trim(a(this).prev("code").html())),b.preventDefault()})},createQRCode:function(b,c){a("#keys-qrcode").qrcode({text:b+"|"+c,width:120,height:120})},saveKey:function(b){b.preventDefault();var c=this;c.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:a("#key_id",c.el).val(),description:a("#key_description",c.el).val(),user:a("#key_user",c.el).val(),permissions:a("#key_permissions",c.el).val()},success:function(b){if(a(".wc-api-message",c.el).remove(),b.success){var d=b.data;if(a("h3",c.el).first().append('<div class="wc-api-message updated"><p>'+d.message+"</p></div>"),a("#key_id",c.el).val(d.key_id),a("#key_description",c.el).val(d.description),a("#key_user",c.el).val(d.user_id),a("#key_permissions",c.el).val(d.permissions),0<d.consumer_key.length&&0<d.consumer_secret.length){a("#update_api_key",c.el).val(woocommerce_admin_api_keys.i18n_save_changes).after(d.revoke_url);var e=_.template(a("#api-keys-template").html(),{consumer_key:d.consumer_key,consumer_secret:d.consumer_secret});a("p.submit",c.el).before(e),c.createQRCode(d.consumer_key,d.consumer_secret),c.initTipTip()}}else a("h3",c.el).first().append('<div class="wc-api-message error"><p>'+b.data.message+"</p></div>");c.unblock()}})}});new b}(jQuery);
!function(a){var b=Backbone.View.extend({el:a("#key-fields"),events:{"click input#update_api_key":"saveKey"},initialize:function(){_.bindAll(this,"saveKey")},block:function(){a(this.el).block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},unblock:function(){a(this.el).unblock()},initTipTip:function(){a(".copy-key",this.el).tipTip({attribute:"data-tip",activation:"click",fadeIn:50,fadeOut:50,delay:0}),a(document.body).on("copy",".copy-key",function(b){b.clipboardData.clearData(),b.clipboardData.setData("text/plain",a.trim(a(this).prev("code").html())),b.preventDefault()})},createQRCode:function(b,c){a("#keys-qrcode").qrcode({text:b+"|"+c,width:120,height:120})},saveKey:function(b){b.preventDefault();var c=this;c.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:a("#key_id",c.el).val(),description:a("#key_description",c.el).val(),user:a("#key_user",c.el).val(),permissions:a("#key_permissions",c.el).val()},success:function(b){if(a(".wc-api-message",c.el).remove(),b.success){var d=b.data;if(a("h3",c.el).first().append('<div class="wc-api-message updated"><p>'+d.message+"</p></div>"),0<d.consumer_key.length&&0<d.consumer_secret.length){a("#api-keys-options",c.el).remove(),a("p.submit",c.el).empty().append(d.revoke_url);var e=_.template(a("#api-keys-template").html(),{consumer_key:d.consumer_key,consumer_secret:d.consumer_secret});a("p.submit",c.el).before(e),c.createQRCode(d.consumer_key,d.consumer_secret),c.initTipTip()}else a("#key_description",c.el).val(d.description),a("#key_user",c.el).val(d.user_id),a("#key_permissions",c.el).val(d.permissions)}else a("h3",c.el).first().append('<div class="wc-api-message error"><p>'+b.data.message+"</p></div>");c.unblock()}})}});new b}(jQuery);

View File

@ -298,9 +298,8 @@ class WC_Admin_Assets {
'wc-api-keys',
'woocommerce_admin_api_keys',
array(
'ajax_url' => admin_url( 'admin-ajax.php' ),
'update_api_nonce' => wp_create_nonce( 'update-api-key' ),
'i18n_save_changes' => __( 'Save Changes', 'woocommerce' )
'ajax_url' => admin_url( 'admin-ajax.php' ),
'update_api_nonce' => wp_create_nonce( 'update-api-key' )
)
);
}

View File

@ -9,7 +9,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<input type="hidden" id="key_id" value="<?php echo esc_attr( $key_id ); ?>" />
<table class="form-table">
<table id="api-keys-options" class="form-table">
<tbody>
<tr valign="top">
<th scope="row" class="titledesc">

View File

@ -2236,7 +2236,6 @@ class WC_AJAX {
array( '%d' )
);
$data['key_id'] = $key_id;
$data['consumer_key'] = '';
$data['consumer_secret'] = '';
$data['message'] = __( 'API Key updated successfully.', 'woocommerce' );
@ -2265,11 +2264,11 @@ class WC_AJAX {
)
);
$data['key_id'] = $wpdb->insert_id;
$key_id = $wpdb->insert_id;
$data['consumer_key'] = $consumer_key;
$data['consumer_secret'] = $consumer_secret;
$data['message'] = __( 'API Key generated successfully. Make sure to copy your new API keys now. You won\'t be able to see it again!', 'woocommerce' );
$data['revoke_url'] = '<a style="color: #a00; text-decoration: none; margin-left: 10px;" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $data['key_id'] ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ). '">' . __( 'Revoke Key', 'woocommerce' ) . '</a>';
$data['revoke_url'] = '<a style="color: #a00; text-decoration: none;" href="' . esc_url( wp_nonce_url( add_query_arg( array( 'revoke-key' => $key_id ), admin_url( 'admin.php?page=wc-settings&tab=api&section=keys' ) ), 'revoke' ) ). '">' . __( 'Revoke Key', 'woocommerce' ) . '</a>';
}
wp_send_json_success( $data );