Files
NodeBB/public/src/modules/flags.js

88 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-10-13 16:36:43 -04:00
'use strict';
2018-11-17 20:50:07 -05:00
define('flags', function () {
2017-02-17 20:20:42 -07:00
var Flag = {};
var flagModal;
var flagCommit;
2017-10-31 12:19:28 -04:00
var flagReason;
2015-10-13 16:36:43 -04:00
Flag.showFlagModal = function (data) {
2018-11-17 20:50:07 -05:00
app.parseAndTranslate('partials/modals/flag_modal', data, function (html) {
2015-10-13 16:36:43 -04:00
flagModal = $(html);
flagModal.on('hidden.bs.modal', function () {
2015-10-13 16:36:43 -04:00
flagModal.remove();
});
flagCommit = flagModal.find('#flag-post-commit');
2017-10-31 12:19:28 -04:00
flagReason = flagModal.find('#flag-reason-custom');
2015-10-13 16:36:43 -04:00
2017-10-31 12:19:28 -04:00
// Quick-report buttons
flagModal.on('click', '.flag-reason', function () {
2017-10-31 12:19:28 -04:00
var reportText = $(this).text();
2017-11-09 16:56:15 -05:00
if (flagReason.val().length === 0) {
2017-10-31 12:19:28 -04:00
return createFlag(data.type, data.id, reportText);
}
// Custom reason has text, confirm submission
bootbox.confirm({
title: '[[flags:modal-submit-confirm]]',
message: '<p>[[flags:modal-submit-confirm-text]]</p><p class="help-block">[[flags:modal-submit-confirm-text-help]]</p>',
callback: function (result) {
if (result) {
createFlag(data.type, data.id, reportText);
}
},
});
2015-10-13 16:36:43 -04:00
});
2017-10-31 12:19:28 -04:00
// Custom reason report submission
flagCommit.on('click', function () {
createFlag(data.type, data.id, flagModal.find('#flag-reason-custom').val());
2015-10-13 16:36:43 -04:00
});
2017-10-31 12:19:28 -04:00
flagModal.on('click', '.toggle-custom', function () {
flagReason.prop('disabled', false);
flagReason.focus();
});
2015-10-13 16:36:43 -04:00
flagModal.modal('show');
$(window).trigger('action:flag.showModal', {
modalEl: flagModal,
type: data.type,
id: data.id,
});
2015-10-13 16:36:43 -04:00
flagModal.find('#flag-reason-custom').on('keyup blur change', checkFlagButtonEnable);
});
};
function createFlag(type, id, reason) {
if (!type || !id || !reason) {
2015-10-13 16:36:43 -04:00
return;
}
var data = { type: type, id: id, reason: reason };
socket.emit('flags.create', data, function (err, flagId) {
2015-10-13 16:36:43 -04:00
if (err) {
return app.alertError(err.message);
}
flagModal.modal('hide');
app.alertSuccess('[[flags:modal-submit-success]]');
$(window).trigger('action:flag.create', { flagId: flagId, data: data });
2015-10-13 16:36:43 -04:00
});
}
function checkFlagButtonEnable() {
if (flagModal.find('#flag-reason-custom').val()) {
flagCommit.removeAttr('disabled');
} else {
flagCommit.attr('disabled', true);
}
}
return Flag;
});