Subversion Repositories SmartDukaan

Rev

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

Rev 36452 Rev 37794
Line 133... Line 133...
133
        </div>
133
        </div>
134
    </div>
134
    </div>
135
    <div id="schemes-table">
135
    <div id="schemes-table">
136
        <div class="row">
136
        <div class="row">
137
            <div class="col-lg-12" style="max-height:400px; overflow-y:auto;">
137
            <div class="col-lg-12" style="max-height:400px; overflow-y:auto;">
-
 
138
                <!-- Offer & Scheme Radar: bulk-select schemes and send a WhatsApp
-
 
139
                     digest to all HO users. Handler:
-
 
140
                     OfferRadarNotificationController#sendRadarNotification. -->
-
 
141
                <div class="scheme-radar-bar" style="display:flex; align-items:center; gap:12px; margin-bottom:10px;">
-
 
142
                    <button type="button"
-
 
143
                            id="schemeRadarSendBtn"
-
 
144
                            class="btn btn-primary"
-
 
145
                            data-radar-kind="scheme"
-
 
146
                            disabled>
-
 
147
                        Send WhatsApp Radar (<span id="schemeRadarSelectedCount">0</span>)
-
 
148
                    </button>
-
 
149
                    <span class="text-muted" style="font-size:12px;">
-
 
150
                        Tick any schemes below, then send. Recipients: all HO users with a mobile number.
-
 
151
                    </span>
-
 
152
                </div>
138
                <table class="table table-striped table-advance table-hover">
153
                <table class="table table-striped table-advance table-hover">
139
                    <tbody>
154
                    <tbody>
140
                    <tr>
155
                    <tr>
-
 
156
                        <th style="width:28px;">
-
 
157
                            <input type="checkbox" id="schemeRadarSelectAll" title="Select all">
-
 
158
                        </th>
141
                        <th>ID</th>
159
                        <th>ID</th>
142
                        <th>Name</th>
160
                        <th>Name</th>
143
                        <th>Reference</th>
161
                        <th>Reference</th>
144
                        <th>Description</th>
162
                        <th>Description</th>
145
                        <th>Type</th>
163
                        <th>Type</th>
Line 153... Line 171...
153
                        <th>Expire</th>
171
                        <th>Expire</th>
154
                    </tr>
172
                    </tr>
155
                        #if($schemes && !$schemes.isEmpty())
173
                        #if($schemes && !$schemes.isEmpty())
156
                            #foreach( $scheme in $schemes )
174
                            #foreach( $scheme in $schemes )
157
                            <tr class="scheme-details" data="$scheme.getId()" style="cursor:pointer;">
175
                            <tr class="scheme-details" data="$scheme.getId()" style="cursor:pointer;">
-
 
176
                                <td onclick="event.stopPropagation();">
-
 
177
                                    <input type="checkbox"
-
 
178
                                           class="scheme-radar-check"
-
 
179
                                           value="$scheme.getId()"
-
 
180
                                           onclick="event.stopPropagation();">
-
 
181
                                </td>
158
                                <td>$scheme.getId()</td>
182
                                <td>$scheme.getId()</td>
159
                                <td>$scheme.getName()</td>
183
                                <td>$scheme.getName()</td>
160
                                <td>#if($scheme.getReference())$scheme.getReference()#else-#end</td>
184
                                <td>#if($scheme.getReference())$scheme.getReference()#else-#end</td>
161
                                <td>$scheme.getDescription()</td>
185
                                <td>$scheme.getDescription()</td>
162
                                <td>$scheme.getType()</td>
186
                                <td>$scheme.getType()</td>
Line 217... Line 241...
217
    });
241
    });
218
 
242
 
219
    $(document).ready(function () {
243
    $(document).ready(function () {
220
        console.log('$partnerType')
244
        console.log('$partnerType')
221
        $('#partner-category').val('$partnerType');
245
        $('#partner-category').val('$partnerType');
-
 
246
 
-
 
247
        // ── Scheme Radar bulk-send wiring ─────────────────────────────
-
 
248
        // Same shape as the offer_history version; POST payload only carries
-
 
249
        // schemeIds because this table has no offers. Row click is a
-
 
250
        // pre-existing scheme-details drill-down, so the checkbox cell and the
-
 
251
        // input itself stopPropagation to avoid opening the drill on tick.
-
 
252
        //
-
 
253
        // Wrapped in #[[ … ]]# so Velocity leaves the $-prefixed jQuery vars
-
 
254
        // (e.g. $schemeCount.text(…)) alone at template-parse time.
-
 
255
    #
-
 
256
        [[
-
 
257
        var $schemeSelectAll = $("#schemeRadarSelectAll");
-
 
258
        var $schemeBtn = $("#schemeRadarSendBtn");
-
 
259
        var $schemeCount = $("#schemeRadarSelectedCount");
-
 
260
 
-
 
261
        function selectedSchemeIds() {
-
 
262
            var ids = [];
-
 
263
            $(".scheme-radar-check:checked").each(function () {
-
 
264
                var v = parseInt(this.value, 10);
-
 
265
                if (!isNaN(v)) ids.push(v);
-
 
266
            });
-
 
267
            return ids;
-
 
268
        }
-
 
269
 
-
 
270
        function refreshSchemeRadarUi() {
-
 
271
            var ids = selectedSchemeIds();
-
 
272
            $schemeCount.text(ids.length);
-
 
273
            $schemeBtn.prop("disabled", ids.length === 0);
-
 
274
            var total = $(".scheme-radar-check").length;
-
 
275
            var picked = ids.length;
-
 
276
            $schemeSelectAll.prop("indeterminate", picked > 0 && picked < total);
-
 
277
            $schemeSelectAll.prop("checked", picked > 0 && picked === total);
-
 
278
        }
-
 
279
 
-
 
280
        $schemeSelectAll.on("change", function (e) {
-
 
281
            e.stopPropagation();
-
 
282
            $(".scheme-radar-check").prop("checked", this.checked);
-
 
283
            refreshSchemeRadarUi();
-
 
284
        });
-
 
285
        $(document).on("change", ".scheme-radar-check", function (e) {
-
 
286
            e.stopPropagation();
-
 
287
            refreshSchemeRadarUi();
-
 
288
        });
-
 
289
 
-
 
290
        $schemeBtn.on("click", function () {
-
 
291
            var ids = selectedSchemeIds();
-
 
292
            if (ids.length === 0) return;
-
 
293
            if (!confirm("Send WhatsApp Radar digest for " + ids.length + " scheme(s) to all HO users?")) return;
-
 
294
 
-
 
295
            var $self = $(this);
-
 
296
            $self.prop("disabled", true).text("Sending…");
-
 
297
            $.ajax({
-
 
298
                url: "/offerRadar/sendNotification",
-
 
299
                method: "POST",
-
 
300
                contentType: "application/json",
-
 
301
                data: JSON.stringify({offerIds: [], schemeIds: ids})
-
 
302
            }).done(function (resp) {
-
 
303
                var r = (resp && resp.response) || resp || {};
-
 
304
                alert("Sent to " + (r.sent || 0) + " user(s). Skipped: " + (r.skipped || 0)
-
 
305
                        + ", Failed: " + (r.failed || 0)
-
 
306
                        + "\nRegion: " + (r.regionSummary || "-")
-
 
307
                        + " | Offers added: " + (r.offersAdded || 0)
-
 
308
                        + " | Schemes added: " + (r.schemesAdded || 0)
-
 
309
                        + " | Revisions: " + (r.revisions || 0)
-
 
310
                        + " | Ending soon: " + (r.endingSoon || 0));
-
 
311
            }).fail(function (xhr) {
-
 
312
                var msg = (xhr.responseJSON && (xhr.responseJSON.response || xhr.responseJSON.message)) || xhr.statusText;
-
 
313
                alert("Radar send failed: " + msg);
-
 
314
            }).always(function () {
-
 
315
                $self.html('Send WhatsApp Radar (<span id="schemeRadarSelectedCount">' + ids.length + '</span>)');
-
 
316
                refreshSchemeRadarUi();
-
 
317
            });
-
 
318
        });
-
 
319
 
-
 
320
        refreshSchemeRadarUi();
-
 
321
    ]]#
222
    });
322
    });
223
</script>
323
</script>
224
324