Skip to content

Commit

Permalink
Merge pull request #27 from CMU-313/mia/refactor-digest
Browse files Browse the repository at this point in the history
Refactored code in public/src/admin/manage/digest.js
  • Loading branch information
mhli1260 authored Sep 25, 2024
2 parents 7d96899 + ab4037b commit 7bed986
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions public/src/admin/manage/digest.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
'use strict';


define('admin/manage/digest', ['bootbox', 'alerts'], function (bootbox, alerts) {
const Digest = {};
console.log('Mia Li');
function interval_resend(action) {
const interval = action.slice(7);
bootbox.confirm('[[admin/manage/digest:resend-all-confirm]]', function (ok) {
if (ok) {
Digest.send(action, undefined, function (err) {
if (err) {
return alerts.error(err);
}
alerts.success('[[admin/manage/digest:resent-' + interval + ']]');
});
}
});
}

function single_resend(action, uid) {
Digest.send(action, uid, function (err) {
if (err) {
return alerts.error(err);
}
alerts.success('[[admin/manage/digest:resent-single]]');
});
}
Digest.init = function () {
$('.digest').on('click', '[data-action]', function () {
const action = this.getAttribute('data-action');
const uid = this.getAttribute('data-uid');

if (action.startsWith('resend-')) {
const interval = action.slice(7);
bootbox.confirm('[[admin/manage/digest:resend-all-confirm]]', function (ok) {
if (ok) {
Digest.send(action, undefined, function (err) {
if (err) {
return alerts.error(err);
}

alerts.success('[[admin/manage/digest:resent-' + interval + ']]');
});
}
});
interval_resend(action);
} else {
Digest.send(action, uid, function (err) {
if (err) {
return alerts.error(err);
}

alerts.success('[[admin/manage/digest:resent-single]]');
});
single_resend(action, uid);
}
});
};
Expand Down

0 comments on commit 7bed986

Please sign in to comment.