notifications.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. jQuery(document).ready(function($) {
  2. $( '#settings-type' ).change( function() {
  3. var val = this.value;
  4. $( '.notification-type' ).hide();
  5. $( '#notification-' + val ).show();
  6. });
  7. $( document ).on( 'click', '.notification-delete', function(e) {
  8. e.preventDefault();
  9. var answer = confirm( commonL10n.warnDelete );
  10. var tr = $( this ).parent().parent().parent().parent();
  11. var n_id = $( this ).data( 'n_id' );
  12. console.log( n_id );
  13. if(answer){
  14. $.post( ajaxurl, { n_id: n_id, action: 'nf_delete_notification', nf_ajax_nonce:ninja_forms_settings.nf_ajax_nonce }, function( response ) {
  15. $( tr ).css( 'background-color', '#FF0000' ).fadeOut( 'slow', function() {
  16. $(this).remove();
  17. } );
  18. });
  19. }
  20. });
  21. $( document ).on( 'click', '.notification-activate', function(e) {
  22. e.preventDefault();
  23. var tr = $( this ).parent().parent().parent().parent();
  24. var activate_action = $( this ).data( 'action' );
  25. var n_id = $( this ).data( 'n_id' );
  26. var that = this;
  27. $.post( ajaxurl, { n_id: n_id, activate_action: activate_action, action: 'nf_' + activate_action + '_notification', nf_ajax_nonce:ninja_forms_settings.nf_ajax_nonce }, function( response ) {
  28. $( tr ).removeClass( 'nf-notification-active' );
  29. $( tr ).removeClass( 'nf-notification-inactive' );
  30. if ( activate_action == 'activate' ) {
  31. $( tr ).addClass( 'nf-notification-active' );
  32. $( that ).html( nf_notifications.deactivate );
  33. $( that ).data( 'action', 'deactivate' );
  34. } else {
  35. $( tr ).addClass( 'nf-notification-inactive' );
  36. $( that ).html( nf_notifications.activate );
  37. $( that ).data( 'action', 'activate' );
  38. }
  39. });
  40. });
  41. $( '.nf-tokenize' ).each( function() {
  42. var limit = $( this ).data( 'token-limit' );
  43. var key = $( this ).data( 'key' );
  44. var type = $( this ).data( 'type' );
  45. $( this ).tokenfield({
  46. autocomplete: {
  47. source: nf_notifications.search_fields[ type ],
  48. delay: 100,
  49. },
  50. tokens: nf_notifications.tokens[ key ],
  51. delimiter: [ '`' ],
  52. showAutocompleteOnFocus: true,
  53. beautify: false,
  54. limit: limit,
  55. createTokensOnBlur: true
  56. });
  57. });
  58. $( document ).on( 'click', '.nf-insert-field', function(e) {
  59. e.preventDefault();
  60. var field_id = $( this ).prev().prev( '.nf-fields-combobox' ).val();
  61. if ( field_id != '' && field_id != null ) {
  62. var shortcode = '[ninja_forms_field id=' + field_id + ']';
  63. window.parent.send_to_editor( shortcode );
  64. }
  65. });
  66. $( document ).on( 'click', '.nf-insert-all-fields', function(e) {
  67. e.preventDefault();
  68. var shortcode = '[ninja_forms_all_fields]';
  69. window.parent.send_to_editor( shortcode );
  70. });
  71. $( '.nf-fields-combobox' ).combobox();
  72. $( '.ui-combobox-input' ).focus( function(e) {
  73. var selected = $( this ).parent().prev( '.nf-fields-combobox' ).val();
  74. if ( selected == '' || selected == null ) {
  75. this.value = '';
  76. } else {
  77. $( this ).select();
  78. }
  79. });
  80. $( '.ui-combobox-input' ).mouseup(function(e){
  81. e.preventDefault();
  82. });
  83. $( '.ui-combobox-input' ).blur( function(e) {
  84. if ( this.value == '' ) {
  85. this.value = $( this ).parent().prev( '.nf-fields-combobox' ).data( 'first-option' );
  86. }
  87. });
  88. $( '#filter-type' ).change( function(e) {
  89. if ( this.value == '' ) {
  90. var url = nf_notifications.filter_type;
  91. } else {
  92. var url = nf_notifications.filter_type + '&type=' + this.value
  93. }
  94. $( '.spinner' ).show();
  95. document.location.href = url;
  96. });
  97. $( '#toggle_email_advanced' ).click( function(e) {
  98. e.preventDefault();
  99. $( '#email_advanced' ).toggle();
  100. });
  101. });