Skip to content
Snippets Groups Projects
Commit 0d589d4f authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '316-admin-panel-confirm-remove-messages' into 'master'

Resolve "Admin panel: "Confirm remove" messages"

Closes #316

See merge request piotr.gawron/minerva!233
parents cc9b1cc3 84b59583
No related branches found
No related tags found
1 merge request!233Resolve "Admin panel: "Confirm remove" messages"
Pipeline #
......@@ -5,6 +5,7 @@
var Panel = require('../Panel');
// noinspection JSUnusedLocalSymbols
var logger = require('../../logger');
var Functions = require('../../Functions');
var Promise = require("bluebird");
......@@ -18,15 +19,48 @@ function AbstractAdminPanel(params) {
AbstractAdminPanel.prototype = Object.create(Panel.prototype);
AbstractAdminPanel.prototype.constructor = AbstractAdminPanel;
AbstractAdminPanel.prototype._createHeader = function(name) {
AbstractAdminPanel.prototype._createHeader = function (name) {
this.getElement().appendChild(Functions.createElement({
type : "h1",
content : name
type: "h1",
content: name
}));
};
AbstractAdminPanel.prototype.init = function() {
AbstractAdminPanel.prototype.init = function () {
};
AbstractAdminPanel.prototype.askConfirmRemoval = function (params) {
return new Promise(function (resolve) {
var html;
var content = '';
if (params.content) {
content = params.content;
}
if (params.input) {
html = '<form><input type="text" style="z-index:10000" name="name"><br></form>';
} else {
html = '<form><span>' + content + '</span><input type="text" style="z-index:10000;visibility: hidden"><br></form>';
}
$(html).dialog({
modal: true,
title: params.title,
close: function () {
$(this).dialog('destroy').remove();
resolve({status: false});
},
buttons: {
'OK': function () {
$(this).dialog('destroy').remove();
resolve({reason: $('input[name="name"]').val(), status: true});
},
'Cancel': function () {
$(this).dialog('destroy').remove();
resolve({status: false});
}
}
});
})
};
module.exports = AbstractAdminPanel;
......@@ -139,7 +139,10 @@ CommentsAdminPanel.prototype.onProjectChange = function () {
dataTable.clear().rows.add(data).draw();
$("[name='commentsTable']", self.getElement()).on("click", "[name='removeComment']", function () {
var button = this;
return self.askConfirmRemoval().then(function (param) {
return self.askConfirmRemoval({
title: "Why do you want to remove this comment?",
input: true
}).then(function (param) {
if (param.status) {
return ServerConnector.removeComment({
commentId: $(button).attr("data"),
......@@ -211,23 +214,5 @@ CommentsAdminPanel.prototype.destroy = function () {
}
};
CommentsAdminPanel.prototype.askConfirmRemoval = function () {
return new Promise(function (resolve) {
$('<form><input type="text" style="z-index:10000" name="name"><br></form>').dialog({
modal: true,
title: "Why do you want to remove this comment?",
buttons: {
'OK': function () {
$(this).dialog('close');
resolve({reason: $('input[name="name"]').val(), status: true});
},
'Cancel': function () {
$(this).dialog('close');
resolve({status: false});
}
}
});
})
};
module.exports = CommentsAdminPanel;
......@@ -114,7 +114,15 @@ MapsAdminPanel.prototype._createProjectTableRow = function () {
});
$(projectsTable).on("click", "[name='removeProject']", function () {
var button = this;
return self.removeProject($(button).attr("data")).then(null, GuiConnector.alert);
return self.askConfirmRemoval({
title: "INFO",
content: "Do you really want to remove this map?",
input: false
}).then(function (param) {
if (param.status) {
return self.removeProject($(button).attr("data"))
}
}).catch(GuiConnector.alert);
});
$(projectsTable).on("click", "[name='showEditDialog']", function () {
......
......@@ -109,7 +109,15 @@ UsersAdminPanel.prototype._createUsersTableRow = function () {
});
$(usersTable).on("click", "[name='removeUser']", function () {
var button = this;
return self.removeUser($(button).attr("data")).then(null, GuiConnector.alert);
return self.askConfirmRemoval({
title: "INFO",
content: "Do you really want to remove this user?",
input: false
}).then(function (param) {
if (param.status) {
return self.removeUser($(button).attr("data"))
}
}).catch(GuiConnector.alert);
});
$(usersTable).on("click", "[name='showEditDialog']", function () {
......
"use strict";
require("../../mocha-config");
var CommentsAdminPanel = require('../../../../main/js/gui/admin/CommentsAdminPanel');
var ServerConnector = require('../../ServerConnector-mock');
var logger = require('../../logger');
var fs = require("fs");
var chai = require('chai');
var assert = chai.assert;
describe('CommentsAdminPanel', function () {
function createDialog() {
return ServerConnector.getConfiguration().then(function (configuration) {
return new CommentsAdminPanel({
element: testDiv,
configuration: configuration,
customMap: null
});
});
}
describe('askConfirmRemoval', function () {
it('check question', function () {
helper.loginAsAdmin();
return createDialog().then(function (dialog) {
var title = "Question?";
dialog.askConfirmRemoval({title: title});
assert.ok($(".ui-dialog-title").html().indexOf(title) >= 0);
$("button:contains(Cancel)").click();
return dialog.destroy();
});
});
it('check ok status', function () {
helper.loginAsAdmin();
var dialog;
return createDialog().then(function (result) {
dialog = result;
var promise = dialog.askConfirmRemoval({title: "Question?"});
$("button:contains(OK)").click();
return promise;
}).then(function (result) {
assert.ok(result.status);
return dialog.destroy();
});
});
it('check cancel status', function () {
helper.loginAsAdmin();
var dialog;
return createDialog().then(function (result) {
dialog = result;
var promise = dialog.askConfirmRemoval({title: "Question?"});
$("button:contains(Cancel)").click();
return promise;
}).then(function (result) {
assert.notOk(result.status);
return dialog.destroy();
});
});
it('check close confirmation status', function () {
helper.loginAsAdmin();
var dialog;
return createDialog().then(function (result) {
dialog = result;
var promise = dialog.askConfirmRemoval({title: "Question?"});
$(".ui-dialog-titlebar-close").click();
return promise;
}).then(function (result) {
assert.notOk(result.status);
return dialog.destroy();
});
});
});
});
......@@ -356,7 +356,6 @@ describe('AbstractCustomMap', function () {
var reaction = helper.createReaction(map);
var center = map.getGoogleMap().getCenter();
return map.fitBounds([reaction]).then(function () {
var center2 = map.getGoogleMap().getCenter();
assert.ok(center.lat() !== center2.lat() || center.lng() !== center2.lng());
})
......
......@@ -159,5 +159,15 @@ afterEach(function () {
$(window).off("resize");
this.test.error(new Error("Test didn't left clean resize events handlers."));
}
} else {
//when failed don't forget to clean events
if ($._data(window, "events").resize) {
logger.warn("Clearing events: " + $._data(window, "events").resize);
$(window).off("resize");
}
if (document.body.hasChildNodes()) {
logger.warn("Clearing html");
document.body.innerHTML = "";
}
}
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment