PageSourceSearch

https://flecs.tech/wp-content/plugins/dokan-pro/modules/request-for-quotation/assets/js/index.js?ver=5.3.0

js flecs.tech collected 2026-10-09 22:39:52 UTC 8,587 bytes, 229 lines download raw bytes

1/* global dokan  */
2;(function($){
3    const dokan_quote_form = '.dokan-quote-form';
4    let Dokan_Request_Quote = {
5        init() {
6            $( '.product' ).on( 'click', '.dokan_request_button', this.addToQuote );
7            $( dokan_quote_form ).on( 'click', '.remove-dokan-quote-item', this.removeQuote );
8            $( '#dokan-quote-form, #quote-action-container' ).on( 'click', '.status-updater', this.quoteStatusHandler );
9            $( '.dokan-dashboard-wrap table.cart.quote_details' ).on( 'input', '.my-offer, .qty, #shipping-cost', this.calculateQuotePrice );
10            $( '.quote-datepicker' ).datepicker( { dateFormat : 'yy-mm-dd', minDate : new Date( new Date() ) } );
11        },
12
13        addToQuote() {
14            if( $(this).hasClass('disabled') ){
15                return;
16            }
17            let variationId = $(this).closest('form').find('.variation_id').val(),
18                productId   = parseInt(variationId) ? variationId : $(this).data('product_id'),
19                qty         = $('.qty').val();
20
21            if ( !qty ){
22                qty = 1;
23            }
24            let self = $(this);
25            self.addClass('loading');
26            $.ajax( {
27                url: dokan.ajaxurl,
28                method: 'post',
29                data: {
30                    action: 'dokan_add_to_quote',
31                    product_id: productId,
32                    quantity: qty,
33                    nonce: dokan.dokan_request_quote_nonce,
34                }
35            } ).done( function ( response ) {
36                if ( 'error' === response['type']) {
37                    dokan_sweetalert(response['message'], {
38                        icon: 'error',
39                    });
40                }
41                self.removeClass('loading');
42                if (response['view_button']) {
43                    self.after(response['view_button']);
44                    self.remove();
45                }else if(response['redirect_to']) {
46                    window.location.href = response['redirect_to'];
47                }else {
48                    window.location.reload();
49                }
50            } ).fail( function ( jqXHR ) {
51                if ( jqXHR.responseJSON.data.message ) {
52                    dokan_sweetalert( jqXHR.responseJSON.data.message, {
53                        icon: 'error',
54                    } );
55                }
56            } );
57        },
58
59        removeQuote( e ) {
60            "use strict";
61            e.preventDefault();
62
63            $(this).closest('tr').css('opacity', '0.5');
64
65            $.ajax({
66                url: dokan.ajaxurl,
67                type: 'POST',
68                data: {
69                    action: 'remove_dokan_quote_item',
70                    quote_key: $(this).data('cart_item_key'),
71                    hide_price: $(this).data('hide_price'),
72                    nonce: dokan.dokan_request_quote_nonce
73                },
74                success: function (response) {
75                    if ( 'error' === response['type']) {
76                        dokan_sweetalert(response['message'], {
77                            icon: 'error',
78                        });
79                    }
80                    if( response['quote_empty'] ){
81                        location.reload();
82                    }
83
84                    let notice_wrapper = $('div.woocommerce-notices-wrapper');
85                    notice_wrapper.html(response['message'] );
86                    $('table.dokan_quote_table_contents').replaceWith( response['quote-table'] );
87                    $('table.table_quote_totals').replaceWith( response['quote-totals'] );
88                    $('body').animate({
89                            scrollTop: notice_wrapper.offset().top,
90                        }, 500
91                    );
92                },
93                error: function ( err ) {
94                    console.log( err );
95                }
96            });
97        },
98
99        updateTotals() {
100            let totalSum = 0,
101                currencySymbol = dokan.currency_format_symbol;
102
103            const shippingCostElement = $( '#shipping-cost' ),
104                shippingCost = parseFloat( shippingCostElement.val() ) || 0,
105                shippingPrevCost = parseFloat( shippingCostElement.data( 'shipping_cost' ) );
106            if ( isNaN( shippingCost ) ) {
107                $( '#shipping-cost' ).val( 0 );
108            }
109
110            const approveBtnElement = $( '#quote-action-container .dokan_convert_to_order_button button.quote-approve-button' ),
111                updateLabel = approveBtnElement.data( 'update_label' ),
112                approveLabel = approveBtnElement.data( 'approve_label' );
113
114            if ( shippingPrevCost !== shippingCost ) {
115                approveBtnElement.html( updateLabel );
116            } else {
117                approveBtnElement.html( approveLabel );
118            }
119
120            $( '.dokan-dashboard-wrap table.cart.quote_details .product-row' ).each( function() {
121                let offerElement = $( this ).find( '.my-offer' ),
122                    offerValue = offerElement.val(),
123                    myOffer = parseFloat( offerValue ) || 0,
124                    qtyValue = $( this ).find( '.qty' ).val(),
125                    qty = parseFloat( qtyValue ) || 1,
126                    total = myOffer * qty,
127                    offerPrevPrice = parseFloat( offerElement.data( 'offer_price' ) );
128
129                if ( isNaN( myOffer ) ) {
130                    $( this ).find( '.my-offer' ).val( 0 );
131                }
132
133                if ( isNaN( qty ) ) {
134                    $( this ).find( '.qty' ).val( 0 );
135                }
136
137                if ( offerPrevPrice !== myOffer ) {
138                    approveBtnElement.html( updateLabel );
139                }
140
141                $( this ).find( '.total' ).text( total.toFixed( 2 ) + currencySymbol );
142                totalSum += total;
143            });
144
145            totalSum += shippingCost;
146
147            $( '#total' ).text( totalSum.toFixed( 2 ) + currencySymbol );
148        },
149
150        calculateQuotePrice() {
151            const value = $( this ).val();
152            if ( isNaN( value ) || value === '' ) { // Handle non numeric value.
153                $( this ).val( 0 );
154            }
155            Dokan_Request_Quote.updateTotals();
156        },
157
158        updateQuoteStatus( action, QuoteId, successMsg, onSuccess ) {
159            Dokan_Request_Quote.sendAjaxRequest(
160                'dokan_update_quote_status',
161                { status: action, quote_id: QuoteId, success_msg: successMsg },
162                function ( response ) {
163                    if ( response.success ) {
164                        if ( response.data.redirect_to) {
165                            window.location = response.data.redirect_to;
166                        }
167                        onSuccess && onSuccess( response );
168                    }
169                }
170            );
171        },
172
173        sendAjaxRequest( action, data, successCallback ) {
174            $.ajax({
175                url: dokan.ajaxurl,
176                type: 'POST',
177                dataType: 'JSON',
178                data: {
179                    action: action,
180                    nonce: dokan.dokan_request_quote_nonce,
181                    ...data
182                },
183                success: successCallback,
184                error: function ( err ) {
185                    console.log( err );
186                }
187            });
188        },
189
190        async quoteStatusHandler( e ) {
191            e.preventDefault();
192
193            const self = $( this ),
194                { action, message } = self.data(),
195                confirmation =
196                await Dokan_Request_Quote.showConfirmationAlert(
197                    dokan[`${action}_confirmation_msg`],
198                    'warning'
199                );
200
201            let onSuccess;
202            if ( confirmation ) {
203                const { quote_id } = self.data();
204                if ( action === 'trash' ) {
205                    onSuccess = ( response ) => response.success && self.closest( 'tr' ).remove();
206                }
207
208                Dokan_Request_Quote.updateQuoteStatus( action, quote_id, message, onSuccess );
209            }
210        },
211
212        async showConfirmationAlert( message, icon ) {
213            const result = await dokan_sweetalert(
214                message,
215                {
216                    action: 'confirm',
217                    icon: icon,
218                }
219            );
220
221            return result?.isConfirmed;
222        },
223
224    };
225
226    $(document).ready(function(){
227        Dokan_Request_Quote.init();
228    });
229})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.