PluginProbe
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings / 6.3.8
MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings v6.3.8
7.2.1 7.2 7.1.2 7.1.1 7.1 7.0.4 7.0.6 7.0.7 6.3.8 6.3.7 6.3.6 6.3.5 6.3.4 6.3.3 6.3.1 trunk 5.7.3 5.7.5 5.8.1 5.8.2 5.8.3 5.8.4 5.8.6 6.0.4 6.0.5 All 36 releases
mlsimport / admin / js / mlsimport-deactivation-survey.js

mlsimport-deactivation-survey.js in MLSImport: IDX Plugin & MLS Plugin for Real Estate Listings 6.3.8, at admin/js/mlsimport-deactivation-survey.js

96 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * MLS Import — deactivation exit survey.
3 *
4 * Intercepts the "Deactivate" link for the MLS Import plugin on the Plugins
5 * screen, shows a short survey modal, sends the chosen reason to the server,
6 * then proceeds with the original deactivation. Submitting or skipping both
7 * complete the deactivation — the user is never trapped.
8 */
9 ( function ( $ ) {
10 'use strict';
11
12 var cfg = window.mlsimport_deact_survey || {};
13
14 $( function () {
15
16 // The Deactivate link inside the MLS Import plugin's row.
17 var $link = $( 'tr[data-plugin="' + cfg.plugin_basename + '"] span.deactivate a' );
18 if ( ! $link.length ) {
19 return;
20 }
21
22 var deactivateUrl = '';
23
24 // --- build the modal once ------------------------------------------
25 var optionsHtml = '';
26 $.each( cfg.options || {}, function ( value, label ) {
27 optionsHtml +=
28 '<label class="mlsimport-es-option">' +
29 '<input type="radio" name="mlsimport_exit_reason" value="' + value + '"> ' +
30 '<span>' + label + '</span>' +
31 '</label>';
32 } );
33
34 var $modal = $(
35 '<div id="mlsimport-exit-survey-modal" class="mlsimport-es-hidden">' +
36 '<div class="mlsimport-es-backdrop"></div>' +
37 '<div class="mlsimport-es-card" role="dialog" aria-modal="true">' +
38 '<h2 class="mlsimport-es-title">' + ( cfg.i18n.title || '' ) + '</h2>' +
39 '<p class="mlsimport-es-intro">' + ( cfg.i18n.intro || '' ) + '</p>' +
40 '<div class="mlsimport-es-options">' + optionsHtml + '</div>' +
41 '<textarea class="mlsimport-es-other mlsimport-es-hidden" rows="3" ' +
42 'placeholder="' + ( cfg.i18n.other_placeholder || '' ) + '"></textarea>' +
43 '<div class="mlsimport-es-actions">' +
44 '<button type="button" class="button button-primary mlsimport-es-submit" disabled>' +
45 ( cfg.i18n.submit || '' ) +
46 '</button>' +
47 '<a href="#" class="mlsimport-es-skip">' + ( cfg.i18n.skip || '' ) + '</a>' +
48 '</div>' +
49 '</div>' +
50 '</div>'
51 );
52 $( 'body' ).append( $modal );
53
54 var $submit = $modal.find( '.mlsimport-es-submit' );
55 var $other = $modal.find( '.mlsimport-es-other' );
56
57 // --- intercept the Deactivate click --------------------------------
58 $link.on( 'click', function ( e ) {
59 e.preventDefault();
60 deactivateUrl = $( this ).attr( 'href' );
61 $modal.removeClass( 'mlsimport-es-hidden' );
62 } );
63
64 // Selecting a reason enables Submit; "other" reveals the text field.
65 $modal.on( 'change', 'input[name="mlsimport_exit_reason"]', function () {
66 $submit.prop( 'disabled', false );
67 $other.toggleClass( 'mlsimport-es-hidden', this.value !== 'other' );
68 } );
69
70 function goDeactivate() {
71 if ( deactivateUrl ) {
72 window.location.href = deactivateUrl;
73 }
74 }
75
76 // Submit: send the answer, then deactivate regardless of the result.
77 $submit.on( 'click', function () {
78 $submit.prop( 'disabled', true );
79 $.post( cfg.ajax_url, {
80 action: 'mlsimport_exit_survey_submit',
81 security: cfg.nonce,
82 reason: $modal.find( 'input[name="mlsimport_exit_reason"]:checked' ).val() || '',
83 details: $other.val() || ''
84 } ).always( goDeactivate );
85 } );
86
87 // Skip: no data sent, deactivate immediately.
88 $modal.on( 'click', '.mlsimport-es-skip', function ( e ) {
89 e.preventDefault();
90 goDeactivate();
91 } );
92
93 } );
94
95 }( jQuery ) );
96