Subversion Repositories SmartDukaan

Rev

Rev 36703 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 36703 Rev 37794
Line 84... Line 84...
84
        </td>
84
        </td>
85
    </table>
85
    </table>
86
    <div id="offer-listings-table">
86
    <div id="offer-listings-table">
87
        <div class="row">
87
        <div class="row">
88
            <div class="col-lg-12">
88
            <div class="col-lg-12">
-
 
89
                <!-- Offer & Scheme Radar: bulk-select offers to send a WhatsApp
-
 
90
                     digest to HO users (RBMs / sales). Backed by
-
 
91
                     OfferRadarNotificationController#sendRadarNotification. -->
-
 
92
                <div class="offer-radar-bar" style="display:flex; align-items:center; gap:12px; margin-bottom:10px;">
-
 
93
                    <button type="button"
-
 
94
                            id="offerRadarSendBtn"
-
 
95
                            class="btn btn-primary"
-
 
96
                            data-radar-kind="offer"
-
 
97
                            disabled>
-
 
98
                        Send WhatsApp Radar (<span id="offerRadarSelectedCount">0</span>)
-
 
99
                    </button>
-
 
100
                    <span class="text-muted" style="font-size:12px;">
-
 
101
                        Tick any offers below, then send. Recipients: all HO users with a mobile number.
-
 
102
                    </span>
-
 
103
                </div>
89
                <table class="table table-striped table-advance table-hover">
104
                <table class="table table-striped table-advance table-hover">
90
                    <tbody>
105
                    <tbody>
91
                    <tr>
106
                    <tr>
-
 
107
                        <th style="width:28px;">
-
 
108
                            <input type="checkbox" id="offerRadarSelectAll" title="Select all">
-
 
109
                        </th>
92
                        <th>Id</th>
110
                        <th>Id</th>
93
                        <th>Name</th>
111
                        <th>Name</th>
94
                        <th>Reference</th>
112
                        <th>Reference</th>
95
                        <th>Payout Type</th>
113
                        <th>Payout Type</th>
96
                        <th>Scheme Type</th>
114
                        <th>Scheme Type</th>
Line 104... Line 122...
104
                        <th>Actions</th>
122
                        <th>Actions</th>
105
                    </tr>
123
                    </tr>
106
                        #if(!$offers.isEmpty())
124
                        #if(!$offers.isEmpty())
107
                            #foreach( $offer in $offers )
125
                            #foreach( $offer in $offers )
108
                            <tr class="offer-details" data-offerid="$offer.getId()" data-offer-title="">
126
                            <tr class="offer-details" data-offerid="$offer.getId()" data-offer-title="">
-
 
127
                                <td>
-
 
128
                                    <input type="checkbox"
-
 
129
                                           class="offer-radar-check"
-
 
130
                                           value="$offer.getId()">
-
 
131
                                </td>
109
                                <td><a class="mk_offer_detail" href="javascript:void(0)">$offer.getId()</a></td>
132
                                <td><a class="mk_offer_detail" href="javascript:void(0)">$offer.getId()</a></td>
110
                                <td><a class="mk_partner_view" href="javascript:void(0)">$offer.getName()</a></td>
133
                                <td><a class="mk_partner_view" href="javascript:void(0)">$offer.getName()</a></td>
111
                                <td>#if($offer.getReference())$offer.getReference()#else-#end</td>
134
                                <td>#if($offer.getReference())$offer.getReference()#else-#end</td>
112
                                <td>$offer.getPayoutType()</td>
135
                                <td>$offer.getPayoutType()</td>
113
                                <td>$offer.getSchemeType()</td>
136
                                <td>$offer.getSchemeType()</td>
Line 151... Line 174...
151
                                </td>
174
                                </td>
152
                            </tr>
175
                            </tr>
153
                            #end
176
                            #end
154
                        #else
177
                        #else
155
                        <tr>
178
                        <tr>
156
                            <td colspan="13" style="text-align:center;">NO MATCHING DATA FOUND FOR CRITERIA</td>
179
                            <td colspan="14" style="text-align:center;">NO MATCHING DATA FOUND FOR CRITERIA</td>
157
                        </tr>
180
                        </tr>
158
                        #end
181
                        #end
159
                    </tbody>
182
                    </tbody>
160
                </table>
183
                </table>
161
            </div>
184
            </div>
Line 191... Line 214...
191
                }
214
                }
192
            } else {
215
            } else {
193
                alert("Please upload file");
216
                alert("Please upload file");
194
            }
217
            }
195
        });
218
        });
-
 
219
 
-
 
220
        // ── Offer Radar bulk-send wiring ──────────────────────────────
-
 
221
        // Wrapped in Velocity's #[[ … ]]# unparsed block because the jQuery
-
 
222
        // convention here uses $-prefixed vars (e.g. $count, $btn) which
-
 
223
        // Velocity would otherwise try to parse as template variables and
-
 
224
        // choke on the following .method(…) call. Inside #[[ ]]# the whole
-
 
225
        // block is emitted verbatim, so jQuery's $ still works at runtime.
-
 
226
    #
-
 
227
        [[
-
 
228
        var $selectAll = $("#offerRadarSelectAll");
-
 
229
        var $btn = $("#offerRadarSendBtn");
-
 
230
        var $count = $("#offerRadarSelectedCount");
-
 
231
 
-
 
232
        function selectedOfferIds() {
-
 
233
            var ids = [];
-
 
234
            $(".offer-radar-check:checked").each(function () {
-
 
235
                var v = parseInt(this.value, 10);
-
 
236
                if (!isNaN(v)) ids.push(v);
-
 
237
            });
-
 
238
            return ids;
-
 
239
        }
-
 
240
 
-
 
241
        function refreshRadarUi() {
-
 
242
            var ids = selectedOfferIds();
-
 
243
            $count.text(ids.length);
-
 
244
            $btn.prop("disabled", ids.length === 0);
-
 
245
            var total = $(".offer-radar-check").length;
-
 
246
            var picked = ids.length;
-
 
247
            $selectAll.prop("indeterminate", picked > 0 && picked < total);
-
 
248
            $selectAll.prop("checked", picked > 0 && picked === total);
-
 
249
        }
-
 
250
 
-
 
251
        $selectAll.on("change", function () {
-
 
252
            $(".offer-radar-check").prop("checked", this.checked);
-
 
253
            refreshRadarUi();
-
 
254
        });
-
 
255
        $(document).on("change", ".offer-radar-check", refreshRadarUi);
-
 
256
 
-
 
257
        $btn.on("click", function () {
-
 
258
            var ids = selectedOfferIds();
-
 
259
            if (ids.length === 0) return;
-
 
260
            if (!confirm("Send WhatsApp Radar digest for " + ids.length + " offer(s) to all HO users?")) return;
-
 
261
 
-
 
262
            var $self = $(this);
-
 
263
            $self.prop("disabled", true).text("Sending…");
-
 
264
            $.ajax({
-
 
265
                url: "/offerRadar/sendNotification",
-
 
266
                method: "POST",
-
 
267
                contentType: "application/json",
-
 
268
                data: JSON.stringify({offerIds: ids, schemeIds: []})
-
 
269
            }).done(function (resp) {
-
 
270
                var r = (resp && resp.response) || resp || {};
-
 
271
                alert("Sent to " + (r.sent || 0) + " user(s). Skipped: " + (r.skipped || 0)
-
 
272
                        + ", Failed: " + (r.failed || 0)
-
 
273
                        + "\nRegion: " + (r.regionSummary || "-")
-
 
274
                        + " | Offers added: " + (r.offersAdded || 0)
-
 
275
                        + " | Schemes added: " + (r.schemesAdded || 0)
-
 
276
                        + " | Revisions: " + (r.revisions || 0)
-
 
277
                        + " | Ending soon: " + (r.endingSoon || 0));
-
 
278
            }).fail(function (xhr) {
-
 
279
                var msg = (xhr.responseJSON && (xhr.responseJSON.response || xhr.responseJSON.message)) || xhr.statusText;
-
 
280
                alert("Radar send failed: " + msg);
-
 
281
            }).always(function () {
-
 
282
                $self.html('Send WhatsApp Radar (<span id="offerRadarSelectedCount">' + ids.length + '</span>)');
-
 
283
                refreshRadarUi();
-
 
284
            });
-
 
285
        });
-
 
286
 
-
 
287
        refreshRadarUi();
-
 
288
    ]]#
196
    });
289
    });
197
</script>
290
</script>
198
 
291
 
199
    
292
    
200
    
293
    
201
294