Commit 7525b9a2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

comments moved to project edit tab

parent 0ff71a78
......@@ -9,7 +9,6 @@ var Header = require('./gui/Header');
var GuiUtils = require('./gui/leftPanel/GuiUtils');
var ObjectWithListeners = require('./ObjectWithListeners');
var CommentsAdminPanel = require('./gui/admin/CommentsAdminPanel');
var ConfigurationAdminPanel = require('./gui/admin/ConfigurationAdminPanel');
var MapsAdminPanel = require('./gui/admin/MapsAdminPanel');
var UsersAdminPanel = require('./gui/admin/UsersAdminPanel');
......@@ -58,9 +57,6 @@ Admin.prototype._createGui = function () {
self.getElement().appendChild(headerDiv);
var panels = [{
name: "COMMENTS",
panelClass: CommentsAdminPanel
}, {
name: "PROJECTS",
panelClass: MapsAdminPanel
}, {
......
......@@ -15,6 +15,7 @@ function AbstractGuiElement(params) {
self.setElement(params.element);
self.setProject(params.project);
self.setMap(params.customMap);
self.setConfiguration(params.configuration);
self._controlElements = [];
......@@ -23,33 +24,33 @@ function AbstractGuiElement(params) {
AbstractGuiElement.prototype = Object.create(ObjectWithListeners.prototype);
AbstractGuiElement.prototype.constructor = AbstractGuiElement;
AbstractGuiElement.prototype.setMap = function(map) {
AbstractGuiElement.prototype.setMap = function (map) {
if (map === undefined) {
throw new Error("map must be defined");
}
this._map = map;
};
AbstractGuiElement.prototype.getMap = function() {
AbstractGuiElement.prototype.getMap = function () {
return this._map;
};
AbstractGuiElement.prototype.setElement = function(element) {
AbstractGuiElement.prototype.setElement = function (element) {
if (element === undefined || element === null) {
throw new Error("DOM Element must be defined");
}
this._element = element;
};
AbstractGuiElement.prototype.getElement = function() {
AbstractGuiElement.prototype.getElement = function () {
return this._element;
};
AbstractGuiElement.prototype.setProject = function(project) {
AbstractGuiElement.prototype.setProject = function (project) {
this._project = project;
};
AbstractGuiElement.prototype.getProject = function() {
AbstractGuiElement.prototype.getProject = function () {
if (this._project === undefined || this._project === null) {
return this.getMap().getProject();
} else {
......@@ -57,7 +58,7 @@ AbstractGuiElement.prototype.getProject = function() {
}
};
AbstractGuiElement.prototype.setControlElement = function(type, element) {
AbstractGuiElement.prototype.setControlElement = function (type, element) {
if (type === null || type === undefined) {
throw new Error("Unknown control element type");
}
......@@ -68,7 +69,7 @@ AbstractGuiElement.prototype.setControlElement = function(type, element) {
this._controlElements[type] = element;
};
AbstractGuiElement.prototype.getControlElement = function(type) {
AbstractGuiElement.prototype.getControlElement = function (type) {
if (type === null || type === undefined) {
throw new Error("Unknown control element type");
}
......@@ -79,14 +80,55 @@ AbstractGuiElement.prototype.getControlElement = function(type) {
return this._controlElements[type];
};
AbstractGuiElement.prototype.downloadFile = function(url) {
AbstractGuiElement.prototype.downloadFile = function (url) {
this._downloadFile = url;
window.open(url, '_blank');
};
AbstractGuiElement.prototype.getLastDownloadUrl = function() {
AbstractGuiElement.prototype.getLastDownloadUrl = function () {
return this._downloadFile;
};
AbstractGuiElement.prototype.setConfiguration = function (configuration) {
this._configuration = configuration;
};
AbstractGuiElement.prototype.getConfiguration = function () {
return this._configuration;
};
AbstractGuiElement.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="reason-value"><br></form>';
} else {
html = '<form><span>' + content + '</span><input type="text" style="z-index:10000;visibility: hidden" name="reason-value"><br></form>';
}
$(html).dialog({
modal: true,
title: params.title,
close: function () {
$(this).dialog('destroy').remove();
resolve({status: false});
},
buttons: {
'OK': function () {
var reason = $('input[name="reason-value"]').val();
$(this).dialog('destroy').remove();
resolve({reason: reason, status: true});
},
'Cancel': function () {
$(this).dialog('destroy').remove();
resolve({status: false});
}
}
});
})
};
module.exports = AbstractGuiElement;
......@@ -30,37 +30,4 @@ 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;
"use strict";
var AbstractAdminPanel = require('./AbstractAdminPanel');
var AbstractGuiElement = require('../AbstractGuiElement');
var Functions = require('../../Functions');
// noinspection JSUnusedLocalSymbols
var logger = require('../../logger');
// noinspection JSUnusedLocalSymbols
var Promise = require("bluebird");
var xss = require('xss');
function CommentsAdminPanel(params) {
AbstractAdminPanel.call(this, params);
params.customMap = null;
AbstractGuiElement.call(this, params);
this._createGui();
}
CommentsAdminPanel.prototype = Object.create(AbstractAdminPanel.prototype);
CommentsAdminPanel.prototype = Object.create(AbstractGuiElement.prototype);
CommentsAdminPanel.prototype.constructor = CommentsAdminPanel;
CommentsAdminPanel.prototype._createGui = function () {
var self = this;
var projectsDiv = Functions.createElement({
type: "div"
});
self.getElement().appendChild(projectsDiv);
var dataDiv = Functions.createElement({
type: "div",
style: "display:table"
});
projectsDiv.appendChild(dataDiv);
var commentsCell = Functions.createElement({
type: "div",
style: "display:table-cell;width:100%;vertical-align:top"
});
projectsDiv.appendChild(commentsCell);
var commentsTable = Functions.createElement({
type: "table",
......@@ -43,7 +29,8 @@ CommentsAdminPanel.prototype._createGui = function () {
className: "display",
style: "width:100%"
});
commentsCell.appendChild(commentsTable);
self.getElement().appendChild(commentsTable);
$(commentsTable).DataTable({
columns: [{
......@@ -63,26 +50,6 @@ CommentsAdminPanel.prototype._createGui = function () {
}]
});
var projectsCell = Functions.createElement({
type: "div",
style: "display:table-cell"
});
projectsDiv.appendChild(projectsCell);
var selectProject = Functions.createElement({
type: "select",
name: "projectSelect"
});
selectProject.size = "12";
selectProject.onchange = function () {
return self.onProjectChange();
};
projectsCell.appendChild(Functions.createElement({
type: "h3",
content: "Project"
}));
projectsCell.appendChild(selectProject);
};
CommentsAdminPanel.prototype.init = function () {
......@@ -90,46 +57,11 @@ CommentsAdminPanel.prototype.init = function () {
return self.refreshProjects();
};
CommentsAdminPanel.prototype.refreshProjects = function () {
var self = this;
var projectSelect = $("[name='projectSelect']", self.getElement())[0];
return ServerConnector.getProjects().then(function (projects) {
while (projectSelect.firstChild) {
projectSelect.removeChild(projectSelect.firstChild);
}
projects.sort(function (project1, project2) {
if (project1.getProjectId() < project2.getProjectId()) {
return -1;
} else if (project1.getProjectId() > project2.getProjectId()) {
return 1;
} else {
return 0;
}
});
for (var i = 0; i < projects.length; i++) {
var project = projects[i];
var value = project.getProjectId();
var name = project.getProjectId() + " - " + project.getName();
projectSelect.appendChild(new Option(name, value));
}
return ServerConnector.getProjectId();
}).then(function (projectId) {
projectSelect.value = projectId;
return self.onProjectChange();
});
};
CommentsAdminPanel.prototype.getSelectedProjectId = function () {
var projectSelect = $("[name='projectSelect']", this.getElement())[0];
return projectSelect.value;
};
CommentsAdminPanel.prototype.onProjectChange = function () {
CommentsAdminPanel.prototype.refreshComments = function () {
var self = this;
return ServerConnector.getComments({
projectId: self.getSelectedProjectId()
projectId: self.getProject().getProjectId()
}).then(function (comments) {
var dataTable = $($("[name='commentsTable']", self.getElement())[0]).DataTable();
var data = [];
......@@ -159,7 +91,7 @@ CommentsAdminPanel.prototype.onProjectChange = function () {
CommentsAdminPanel.prototype.commentToTableRow = function (comment) {
var self = this;
var projectId = self.getSelectedProjectId();
var projectId = self.getProject().getProjectId();
var toYesNo = function (val) {
if (val) {
return "YES";
......
......@@ -6,6 +6,7 @@ var Promise = require("bluebird");
var AbstractGuiElement = require('../AbstractGuiElement');
var AddOverlayDialog = require('../AddOverlayDialog');
var Annotation = require('../../map/data/Annotation');
var CommentsTab = require('./CommentsAdminPanel');
var GuiConnector = require('../../GuiConnector');
var Functions = require('../../Functions');
......@@ -18,6 +19,7 @@ var xss = require('xss');
function EditProjectDialog(params) {
AbstractGuiElement.call(this, params);
var self = this;
self.setConfiguration(params.configuration);
self.registerListenerType("onSave");
$(self.getElement()).addClass("minerva-edit-project-dialog");
$(self.getElement()).css({overflow: "hidden"});
......@@ -57,6 +59,7 @@ EditProjectDialog.prototype.createGui = function () {
self.createOverlaysTab(tabMenuDiv, tabContentDiv);
self.createMapsTab(tabMenuDiv, tabContentDiv);
self.createUsersTab(tabMenuDiv, tabContentDiv);
self.createCommentsTab(tabMenuDiv, tabContentDiv);
$("a", tabMenuDiv).bind("click", function () {
//workaround for some css issues...
tabDiv.style.top = "40px";
......@@ -73,7 +76,27 @@ EditProjectDialog.prototype.createGeneralTab = function (tabMenuDiv, tabContentD
id: self.getProject().getProjectId() + "_general_tab",
content: self.createGeneralTabContent()
});
};
EditProjectDialog.prototype.createCommentsTab = function (tabMenuDiv, tabContentDiv) {
var self = this;
var element = Functions.createElement({type: "div", style: "margin-top:10px;"});
self.addTab({
tabMenuDiv: tabMenuDiv,
tabContentDiv: tabContentDiv,
name: "COMMENTS",
id: self.getProject().getProjectId() + "_comment_tab",
content: element
});
var commentsTab = new CommentsTab({
element: element,
project: self.getProject(),
configuration: self.getConfiguration()
});
self.setCommentsTab(commentsTab);
};
EditProjectDialog.prototype.addTab = function (params) {
......@@ -510,6 +533,8 @@ EditProjectDialog.prototype.init = function () {
return self.refreshMaps();
}).then(function () {
return self.refreshOverlays();
}).then(function () {
return self.refreshComments();
}).then(function () {
$(window).trigger('resize');
});
......@@ -705,31 +730,6 @@ EditProjectDialog.prototype.mapToTableRow = function (map, users) {
return row;
};
EditProjectDialog.prototype.destroy = function () {
var self = this;
var div = self.getElement();
var usersTable = $("[name=usersTable]", self.getElement())[0];
var overlaysTable = $("[name=overlaysTable]", self.getElement())[0];
var mapsTable = $("[name=mapsTable]", self.getElement())[0];
if ($.fn.DataTable.isDataTable(usersTable)) {
$(usersTable).DataTable().destroy();
}
if ($.fn.DataTable.isDataTable(overlaysTable)) {
$(overlaysTable).DataTable().destroy();
}
if ($.fn.DataTable.isDataTable(mapsTable)) {
$(mapsTable).DataTable().destroy();
}
if ($(div).hasClass("ui-dialog-content")) {
$(div).dialog("destroy");
}
if (self._addOverlayDialog !== undefined) {
self._addOverlayDialog.destroy();
delete self._addOverlayDialog;
}
};
EditProjectDialog.prototype.open = function () {
var self = this;
var div = self.getElement();
......@@ -838,4 +838,42 @@ EditProjectDialog.prototype.openAddOverlayDialog = function () {
});
};
EditProjectDialog.prototype.setCommentsTab = function (commentsTab) {
this._commentsTab = commentsTab;
};
EditProjectDialog.prototype.refreshComments = function (commentsTab) {
return this._commentsTab.refreshComments();
};
EditProjectDialog.prototype.destroy = function () {
var self = this;
var div = self.getElement();
var usersTable = $("[name=usersTable]", self.getElement())[0];
var overlaysTable = $("[name=overlaysTable]", self.getElement())[0];
var mapsTable = $("[name=mapsTable]", self.getElement())[0];
if ($.fn.DataTable.isDataTable(usersTable)) {
$(usersTable).DataTable().destroy();
}
if ($.fn.DataTable.isDataTable(overlaysTable)) {
$(overlaysTable).DataTable().destroy();
}
if ($.fn.DataTable.isDataTable(mapsTable)) {
$(mapsTable).DataTable().destroy();
}
if ($(div).hasClass("ui-dialog-content")) {
$(div).dialog("destroy");
}
if (self._addOverlayDialog !== undefined) {
self._addOverlayDialog.destroy();
delete self._addOverlayDialog;
}
if (this._commentsTab !== undefined) {
this._commentsTab.destroy();
}
};
module.exports = EditProjectDialog;
......@@ -306,6 +306,7 @@ MapsAdminPanel.prototype.getDialog = function (project) {
type: "div"
}),
project: project,
configuration: self.getConfiguration(),
customMap: null
});
self._dialogs[project.getProjectId()] = dialog;
......
......@@ -10,16 +10,23 @@ var assert = require('assert');
describe('EditProjectDialog', function () {
it('open', function () {
var dialog;
var project;
function createDialog() {
return ServerConnector.getProject().then(function (result) {
project = result;
dialog = new EditProjectDialog({
var project = result;
var dialog = new EditProjectDialog({
element: testDiv,
project: project,
customMap: null
customMap: null,
configuration: helper.getConfiguration()
});
return dialog;
});
}
it('open', function () {
var dialog;
return createDialog().then(function (result) {
dialog = result;
return dialog.open();
}).then(function () {
assert.equal(0, logger.getWarnings().length);
......@@ -30,14 +37,8 @@ describe('EditProjectDialog', function () {
it('init', function () {
helper.loginAsAdmin();
var dialog;
var project;
return ServerConnector.getProject().then(function (result) {
project = result;
dialog = new EditProjectDialog({
element: testDiv,
project: project,
customMap: null
});
return createDialog().then(function (result) {
dialog = result;
return dialog.init();
}).then(function () {
dialog.destroy();
......@@ -46,14 +47,8 @@ describe('EditProjectDialog', function () {
it('saveOverlay', function () {
helper.loginAsAdmin();
var dialog;
var project;
return ServerConnector.getProject().then(function (result) {
project = result;
dialog = new EditProjectDialog({
element: testDiv,
project: project,
customMap: null
});
return createDialog().then(function (result) {
dialog = result;
return dialog.init();
}).then(function () {
return dialog.saveOverlay(14081);
......@@ -65,14 +60,8 @@ describe('EditProjectDialog', function () {
it('saveMap', function () {
helper.loginAsAdmin();
var dialog;
var project;
return ServerConnector.getProject().then(function (result) {
project = result;
dialog = new EditProjectDialog({
element: testDiv,
project: project,
customMap: null
});
return createDialog().then(function (result) {
dialog = result;
return dialog.init();
}).then(function () {
return dialog.saveMap(15781);
......@@ -84,14 +73,8 @@ describe('EditProjectDialog', function () {
it('saveUser', function () {
helper.loginAsAdmin();
var dialog;
var project;
return ServerConnector.getProject().then(function (result) {
project = result;
dialog = new EditProjectDialog({
element: testDiv,
project: project,
customMap: null
});
return createDialog().then(function (result) {
dialog = result;
return dialog.init();
}).then(function () {
return dialog.saveUser("anonymous");
......@@ -110,7 +93,8 @@ describe('EditProjectDialog', function () {
dialog = new EditProjectDialog({
element: testDiv,
project: project,
customMap: null
customMap: null,
configuration: helper.getConfiguration()
});
return dialog.onSaveClicked();
}).then(function (result) {
......@@ -121,12 +105,8 @@ describe('EditProjectDialog', function () {
it('openAddOverlayDialog', function () {
var dialog;
return ServerConnector.getProject().then(function (project) {
dialog = new EditProjectDialog({
element: testDiv,
project: project,
customMap: null
});
return createDialog().then(function (result) {
dialog = result;
return dialog.openAddOverlayDialog();
}).then(function () {
dialog.destroy();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment