2018-06-04 00:06:17 +08:00
|
|
|
(function (global, document) {
|
2018-06-24 10:01:21 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
(document);
|
2018-06-04 00:06:17 +08:00
|
|
|
|
|
|
|
// Opens the moderatiosn settings window.
|
|
|
|
global.moderationOpen = function() {
|
|
|
|
$(".view").hide();
|
|
|
|
$("#moderation-view").show();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Adds a moderator.
|
|
|
|
global.moderatorNewHandler = function() {
|
|
|
|
var data = global.dashboard.$data;
|
|
|
|
var email = $("#new-mod").val();
|
|
|
|
|
|
|
|
var json = {
|
2018-06-20 11:36:49 +08:00
|
|
|
"ownerToken": global.cookieGet("commentoOwnerToken"),
|
2018-06-20 11:29:55 +08:00
|
|
|
"domain": data.domains[data.cd].domain,
|
|
|
|
"email": email,
|
2018-06-04 00:06:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var idx = -1;
|
|
|
|
for (var i = 0; i < data.domains[data.cd].moderators.length; i++) {
|
2018-06-24 10:01:21 +08:00
|
|
|
if (data.domains[data.cd].moderators[i].email === email) {
|
2018-06-04 00:06:17 +08:00
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 10:01:21 +08:00
|
|
|
if (idx === -1) {
|
2018-06-04 00:06:17 +08:00
|
|
|
data.domains[data.cd].moderators.push({"email": email, "timeAgo": "just now"});
|
|
|
|
global.buttonDisable("#new-mod-button");
|
2018-12-20 13:48:43 +08:00
|
|
|
global.post(global.origin + "/api/domain/moderator/new", json, function(resp) {
|
2018-06-04 00:06:17 +08:00
|
|
|
global.buttonEnable("#new-mod-button");
|
|
|
|
|
|
|
|
if (!resp.success) {
|
|
|
|
global.globalErrorShow(resp.message);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
global.globalOKShow("Added a new moderator!");
|
|
|
|
$("#new-mod").val("");
|
|
|
|
$("#new-mod").focus();
|
|
|
|
});
|
2018-06-24 10:01:21 +08:00
|
|
|
} else {
|
2018-06-04 00:06:17 +08:00
|
|
|
global.globalErrorShow("Already a moderator.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Deletes a moderator.
|
|
|
|
global.moderatorDeleteHandler = function(email) {
|
|
|
|
var data = global.dashboard.$data;
|
|
|
|
|
|
|
|
var json = {
|
2018-06-20 11:36:49 +08:00
|
|
|
"ownerToken": global.cookieGet("commentoOwnerToken"),
|
2018-06-20 11:29:55 +08:00
|
|
|
"domain": data.domains[data.cd].domain,
|
|
|
|
"email": email,
|
2018-06-04 00:06:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var idx = -1;
|
|
|
|
for (var i = 0; i < data.domains[data.cd].moderators.length; i++) {
|
2018-06-24 10:01:21 +08:00
|
|
|
if (data.domains[data.cd].moderators[i].email === email) {
|
2018-06-04 00:06:17 +08:00
|
|
|
idx = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 10:01:21 +08:00
|
|
|
if (idx !== -1) {
|
2018-06-04 00:06:17 +08:00
|
|
|
data.domains[data.cd].moderators.splice(idx, 1);
|
2018-12-20 13:48:43 +08:00
|
|
|
global.post(global.origin + "/api/domain/moderator/delete", json, function(resp) {
|
2018-06-04 00:06:17 +08:00
|
|
|
if (!resp.success) {
|
|
|
|
global.globalErrorShow(resp.message);
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-20 13:48:43 +08:00
|
|
|
global.globalOKShow("Removed!");
|
2018-06-04 00:06:17 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 13:48:43 +08:00
|
|
|
} (window.commento, document));
|