| Line 247... |
Line 247... |
| 247 |
// ── Scheme Radar bulk-send wiring ─────────────────────────────
|
247 |
// ── Scheme Radar bulk-send wiring ─────────────────────────────
|
| 248 |
// Same shape as the offer_history version; POST payload only carries
|
248 |
// Same shape as the offer_history version; POST payload only carries
|
| 249 |
// schemeIds because this table has no offers. Row click is a
|
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
|
250 |
// pre-existing scheme-details drill-down, so the checkbox cell and the
|
| 251 |
// input itself stopPropagation to avoid opening the drill on tick.
|
251 |
// input itself stopPropagation to avoid opening the drill on tick.
|
| 252 |
//
|
- |
|
| 253 |
// Wrapped in #[[ … ]]# so Velocity leaves the $-prefixed jQuery vars
|
252 |
// jQuery locals are renamed off the conventional $-prefix so Velocity
|
| 254 |
// (e.g. $schemeCount.text(…)) alone at template-parse time.
|
253 |
// never sees a $ident.method() shape and tries to parse it.
|
| 255 |
#
|
- |
|
| 256 |
[[
|
- |
|
| 257 |
var $schemeSelectAll = $("#schemeRadarSelectAll");
|
254 |
var schemeSelectAll = $("#schemeRadarSelectAll");
|
| 258 |
var $schemeBtn = $("#schemeRadarSendBtn");
|
255 |
var schemeBtn = $("#schemeRadarSendBtn");
|
| 259 |
var $schemeCount = $("#schemeRadarSelectedCount");
|
256 |
var schemeCount = $("#schemeRadarSelectedCount");
|
| 260 |
|
257 |
|
| 261 |
function selectedSchemeIds() {
|
258 |
function selectedSchemeIds() {
|
| 262 |
var ids = [];
|
259 |
var ids = [];
|
| 263 |
$(".scheme-radar-check:checked").each(function () {
|
260 |
$(".scheme-radar-check:checked").each(function () {
|
| 264 |
var v = parseInt(this.value, 10);
|
261 |
var v = parseInt(this.value, 10);
|
| Line 267... |
Line 264... |
| 267 |
return ids;
|
264 |
return ids;
|
| 268 |
}
|
265 |
}
|
| 269 |
|
266 |
|
| 270 |
function refreshSchemeRadarUi() {
|
267 |
function refreshSchemeRadarUi() {
|
| 271 |
var ids = selectedSchemeIds();
|
268 |
var ids = selectedSchemeIds();
|
| 272 |
$schemeCount.text(ids.length);
|
269 |
schemeCount.text(ids.length);
|
| 273 |
$schemeBtn.prop("disabled", ids.length === 0);
|
270 |
schemeBtn.prop("disabled", ids.length === 0);
|
| 274 |
var total = $(".scheme-radar-check").length;
|
271 |
var total = $(".scheme-radar-check").length;
|
| 275 |
var picked = ids.length;
|
272 |
var picked = ids.length;
|
| 276 |
$schemeSelectAll.prop("indeterminate", picked > 0 && picked < total);
|
273 |
schemeSelectAll.prop("indeterminate", picked > 0 && picked < total);
|
| 277 |
$schemeSelectAll.prop("checked", picked > 0 && picked === total);
|
274 |
schemeSelectAll.prop("checked", picked > 0 && picked === total);
|
| 278 |
}
|
275 |
}
|
| 279 |
|
276 |
|
| 280 |
$schemeSelectAll.on("change", function (e) {
|
277 |
schemeSelectAll.on("change", function (e) {
|
| 281 |
e.stopPropagation();
|
278 |
e.stopPropagation();
|
| 282 |
$(".scheme-radar-check").prop("checked", this.checked);
|
279 |
$(".scheme-radar-check").prop("checked", this.checked);
|
| 283 |
refreshSchemeRadarUi();
|
280 |
refreshSchemeRadarUi();
|
| 284 |
});
|
281 |
});
|
| 285 |
$(document).on("change", ".scheme-radar-check", function (e) {
|
282 |
$(document).on("change", ".scheme-radar-check", function (e) {
|
| 286 |
e.stopPropagation();
|
283 |
e.stopPropagation();
|
| 287 |
refreshSchemeRadarUi();
|
284 |
refreshSchemeRadarUi();
|
| 288 |
});
|
285 |
});
|
| 289 |
|
286 |
|
| 290 |
$schemeBtn.on("click", function () {
|
287 |
schemeBtn.on("click", function () {
|
| 291 |
var ids = selectedSchemeIds();
|
288 |
var ids = selectedSchemeIds();
|
| 292 |
if (ids.length === 0) return;
|
289 |
if (ids.length === 0) return;
|
| 293 |
if (!confirm("Send WhatsApp Radar digest for " + ids.length + " scheme(s) to all HO users?")) return;
|
290 |
if (!confirm("Send WhatsApp Radar digest for " + ids.length + " scheme(s) to all HO users?")) return;
|
| 294 |
|
291 |
|
| 295 |
var $self = $(this);
|
292 |
var schemeSelf = $(this);
|
| 296 |
$self.prop("disabled", true).text("Sending…");
|
293 |
schemeSelf.prop("disabled", true).text("Sending…");
|
| 297 |
$.ajax({
|
294 |
$.ajax({
|
| 298 |
url: "/offerRadar/sendNotification",
|
295 |
url: "/offerRadar/sendNotification",
|
| 299 |
method: "POST",
|
296 |
method: "POST",
|
| 300 |
contentType: "application/json",
|
297 |
contentType: "application/json",
|
| 301 |
data: JSON.stringify({offerIds: [], schemeIds: ids})
|
298 |
data: JSON.stringify({offerIds: [], schemeIds: ids})
|
| Line 310... |
Line 307... |
| 310 |
+ " | Ending soon: " + (r.endingSoon || 0));
|
307 |
+ " | Ending soon: " + (r.endingSoon || 0));
|
| 311 |
}).fail(function (xhr) {
|
308 |
}).fail(function (xhr) {
|
| 312 |
var msg = (xhr.responseJSON && (xhr.responseJSON.response || xhr.responseJSON.message)) || xhr.statusText;
|
309 |
var msg = (xhr.responseJSON && (xhr.responseJSON.response || xhr.responseJSON.message)) || xhr.statusText;
|
| 313 |
alert("Radar send failed: " + msg);
|
310 |
alert("Radar send failed: " + msg);
|
| 314 |
}).always(function () {
|
311 |
}).always(function () {
|
| 315 |
$self.html('Send WhatsApp Radar (<span id="schemeRadarSelectedCount">' + ids.length + '</span>)');
|
312 |
schemeSelf.html('Send WhatsApp Radar (<span id="schemeRadarSelectedCount">' + ids.length + '</span>)');
|
| 316 |
refreshSchemeRadarUi();
|
313 |
refreshSchemeRadarUi();
|
| 317 |
});
|
314 |
});
|
| 318 |
});
|
315 |
});
|
| 319 |
|
316 |
|
| 320 |
refreshSchemeRadarUi();
|
317 |
refreshSchemeRadarUi();
|
| 321 |
]]#
|
- |
|
| 322 |
});
|
318 |
});
|
| 323 |
</script>
|
319 |
</script>
|
| 324 |
|
320 |
|