Subversion Repositories SmartDukaan

Rev

Rev 37794 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 37794 Rev 37795
Line 216... Line 216...
216
                alert("Please upload file");
216
                alert("Please upload file");
217
            }
217
            }
218
        });
218
        });
219
 
219
 
220
        // ── Offer Radar bulk-send wiring ──────────────────────────────
220
        // ── Offer Radar bulk-send wiring ──────────────────────────────
221
        // Wrapped in Velocity's #[[ … ]]# unparsed block because the jQuery
221
        // jQuery locals are renamed off the conventional $-prefix so Velocity
222
        // convention here uses $-prefixed vars (e.g. $count, $btn) which
222
        // never sees a $ident.method() shape and tries to parse it as a
223
        // Velocity would otherwise try to parse as template variables and
223
        // template reference. Keeps this block readable to any Velocity version
224
        // choke on the following .method(…) call. Inside #[[ ]]# the whole
224
        // without needing the whitespace-sensitive #[[ ... ]]# literal block.
225
        // block is emitted verbatim, so jQuery's $ still works at runtime.
-
 
226
    #
-
 
227
        [[
-
 
228
        var $selectAll = $("#offerRadarSelectAll");
225
        var radarSelectAll = $("#offerRadarSelectAll");
229
        var $btn = $("#offerRadarSendBtn");
226
        var radarBtn = $("#offerRadarSendBtn");
230
        var $count = $("#offerRadarSelectedCount");
227
        var radarCount = $("#offerRadarSelectedCount");
231
 
228
 
232
        function selectedOfferIds() {
229
        function selectedOfferIds() {
233
            var ids = [];
230
            var ids = [];
234
            $(".offer-radar-check:checked").each(function () {
231
            $(".offer-radar-check:checked").each(function () {
235
                var v = parseInt(this.value, 10);
232
                var v = parseInt(this.value, 10);
Line 238... Line 235...
238
            return ids;
235
            return ids;
239
        }
236
        }
240
 
237
 
241
        function refreshRadarUi() {
238
        function refreshRadarUi() {
242
            var ids = selectedOfferIds();
239
            var ids = selectedOfferIds();
243
            $count.text(ids.length);
240
            radarCount.text(ids.length);
244
            $btn.prop("disabled", ids.length === 0);
241
            radarBtn.prop("disabled", ids.length === 0);
245
            var total = $(".offer-radar-check").length;
242
            var total = $(".offer-radar-check").length;
246
            var picked = ids.length;
243
            var picked = ids.length;
247
            $selectAll.prop("indeterminate", picked > 0 && picked < total);
244
            radarSelectAll.prop("indeterminate", picked > 0 && picked < total);
248
            $selectAll.prop("checked", picked > 0 && picked === total);
245
            radarSelectAll.prop("checked", picked > 0 && picked === total);
249
        }
246
        }
250
 
247
 
251
        $selectAll.on("change", function () {
248
        radarSelectAll.on("change", function () {
252
            $(".offer-radar-check").prop("checked", this.checked);
249
            $(".offer-radar-check").prop("checked", this.checked);
253
            refreshRadarUi();
250
            refreshRadarUi();
254
        });
251
        });
255
        $(document).on("change", ".offer-radar-check", refreshRadarUi);
252
        $(document).on("change", ".offer-radar-check", refreshRadarUi);
256
 
253
 
257
        $btn.on("click", function () {
254
        radarBtn.on("click", function () {
258
            var ids = selectedOfferIds();
255
            var ids = selectedOfferIds();
259
            if (ids.length === 0) return;
256
            if (ids.length === 0) return;
260
            if (!confirm("Send WhatsApp Radar digest for " + ids.length + " offer(s) to all HO users?")) return;
257
            if (!confirm("Send WhatsApp Radar digest for " + ids.length + " offer(s) to all HO users?")) return;
261
 
258
 
262
            var $self = $(this);
259
            var radarSelf = $(this);
263
            $self.prop("disabled", true).text("Sending…");
260
            radarSelf.prop("disabled", true).text("Sending…");
264
            $.ajax({
261
            $.ajax({
265
                url: "/offerRadar/sendNotification",
262
                url: "/offerRadar/sendNotification",
266
                method: "POST",
263
                method: "POST",
267
                contentType: "application/json",
264
                contentType: "application/json",
268
                data: JSON.stringify({offerIds: ids, schemeIds: []})
265
                data: JSON.stringify({offerIds: ids, schemeIds: []})
Line 277... Line 274...
277
                        + " | Ending soon: " + (r.endingSoon || 0));
274
                        + " | Ending soon: " + (r.endingSoon || 0));
278
            }).fail(function (xhr) {
275
            }).fail(function (xhr) {
279
                var msg = (xhr.responseJSON && (xhr.responseJSON.response || xhr.responseJSON.message)) || xhr.statusText;
276
                var msg = (xhr.responseJSON && (xhr.responseJSON.response || xhr.responseJSON.message)) || xhr.statusText;
280
                alert("Radar send failed: " + msg);
277
                alert("Radar send failed: " + msg);
281
            }).always(function () {
278
            }).always(function () {
282
                $self.html('Send WhatsApp Radar (<span id="offerRadarSelectedCount">' + ids.length + '</span>)');
279
                radarSelf.html('Send WhatsApp Radar (<span id="offerRadarSelectedCount">' + ids.length + '</span>)');
283
                refreshRadarUi();
280
                refreshRadarUi();
284
            });
281
            });
285
        });
282
        });
286
 
283
 
287
        refreshRadarUi();
284
        refreshRadarUi();
288
    ]]#
-
 
289
    });
285
    });
290
</script>
286
</script>
291
 
287
 
292
    
288
    
293
    
289
    
294
290