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

66 lines
1.5 KiB
JavaScript
Raw Normal View History

2015-10-13 16:36:43 -04:00
'use strict';
2016-09-13 22:54:40 -04:00
/* globals define, app, socket, templates */
2015-10-13 16:36:43 -04:00
define('flags', [], function () {
2015-10-13 16:36:43 -04:00
var Flag = {},
flagModal,
flagCommit;
Flag.showFlagModal = function (data) {
parseModal(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');
flagModal.on('click', '.flag-reason', function () {
createFlag(data.type, data.id, $(this).text());
2015-10-13 16:36:43 -04:00
});
flagCommit.on('click', function () {
createFlag(data.type, data.id, flagModal.find('#flag-reason-custom').val());
2015-10-13 16:36:43 -04:00
});
flagModal.modal('show');
flagModal.find('#flag-reason-custom').on('keyup blur change', checkFlagButtonEnable);
});
};
function parseModal(tplData, callback) {
templates.parse('partials/modals/flag_modal', tplData, function (html) {
require(['translator'], function (translator) {
2016-09-13 22:54:40 -04:00
translator.translate(html, callback);
});
2015-10-13 16:36:43 -04:00
});
}
function createFlag(type, id, reason) {
if (!type || !id || !reason) {
2015-10-13 16:36:43 -04:00
return;
}
socket.emit('flags.create', {type: type, id: id, reason: reason}, function (err) {
2015-10-13 16:36:43 -04:00
if (err) {
return app.alertError(err.message);
}
flagModal.modal('hide');
app.alertSuccess('[[flags:modal-submit-success]]');
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;
});