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
|
|
|
|
2016-12-07 12:07:22 -05: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);
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
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
|
2016-10-13 11:43:39 +02:00
|
|
|
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
|
2016-10-13 11:43:39 +02:00
|
|
|
flagCommit.on('click', function () {
|
2016-12-07 12:07:22 -05:00
|
|
|
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');
|
2020-07-10 14:39:59 -04:00
|
|
|
$(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);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2016-12-07 12:07:22 -05:00
|
|
|
function createFlag(type, id, reason) {
|
|
|
|
|
if (!type || !id || !reason) {
|
2015-10-13 16:36:43 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2020-09-02 14:06:04 -04:00
|
|
|
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');
|
2016-12-07 12:07:22 -05:00
|
|
|
app.alertSuccess('[[flags:modal-submit-success]]');
|
2020-09-02 14:06:04 -04:00
|
|
|
$(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;
|
|
|
|
|
});
|