From 14fa2345795587f2f46aa5198b2473c6602e19b5 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Fri, 14 Apr 2017 15:29:33 +0200
Subject: [PATCH] submenu functionality fixed (adding submenu options fixed)

---
 frontend-js/src/main/js/gui/ContextMenu.js    |  2 +-
 frontend-js/src/main/js/gui/MapContextMenu.js | 18 +++++++++++++++++-
 frontend-js/src/main/js/gui/SubMenu.js        |  2 +-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/frontend-js/src/main/js/gui/ContextMenu.js b/frontend-js/src/main/js/gui/ContextMenu.js
index ed0ce3c782..3850ff4af1 100644
--- a/frontend-js/src/main/js/gui/ContextMenu.js
+++ b/frontend-js/src/main/js/gui/ContextMenu.js
@@ -29,7 +29,7 @@ ContextMenu.prototype.constructor = ContextMenu;
 ContextMenu.prototype.addOption = function(name, handler) {
   var self = this;
   if (name instanceof SubMenu) {
-    self.addSubMenu(name);
+    self.getElement().appendChild(name.getElement());
   } else {
     var option = Functions.createElement({
       type : "li",
diff --git a/frontend-js/src/main/js/gui/MapContextMenu.js b/frontend-js/src/main/js/gui/MapContextMenu.js
index 52207e7c18..c43bd96211 100644
--- a/frontend-js/src/main/js/gui/MapContextMenu.js
+++ b/frontend-js/src/main/js/gui/MapContextMenu.js
@@ -3,8 +3,9 @@
 /* exported logger */
 
 var ContextMenu = require('./ContextMenu');
-var Functions = require('../Functions');
+var SubMenu = require('./SubMenu');
 
+var Functions = require('../Functions');
 var logger = require('../logger');
 
 function MapContextMenu(params) {
@@ -17,6 +18,20 @@ function MapContextMenu(params) {
 MapContextMenu.prototype = Object.create(ContextMenu.prototype);
 MapContextMenu.prototype.constructor = MapContextMenu;
 
+MapContextMenu.prototype.init = function() {
+  var li = Functions.createElement({
+    type : "li"
+  });
+  var submenu = new SubMenu({
+    element : li,
+    name : "test",
+    customMap : self.getMap()
+  });
+  submenu.addOption("Option A");
+  submenu.addOption("Option B");
+  self.addOption(submenu);
+};
+
 MapContextMenu.prototype._createMapContextMenuGui = function() {
   var self = this;
   self.addOption("Add comment", function() {
@@ -25,6 +40,7 @@ MapContextMenu.prototype._createMapContextMenuGui = function() {
   self.addOption("Select mode", function() {
     return self.getMap().turnOnOffDrawing();
   });
+
 };
 
 module.exports = MapContextMenu;
diff --git a/frontend-js/src/main/js/gui/SubMenu.js b/frontend-js/src/main/js/gui/SubMenu.js
index bd79c5232a..dc943a491a 100644
--- a/frontend-js/src/main/js/gui/SubMenu.js
+++ b/frontend-js/src/main/js/gui/SubMenu.js
@@ -43,7 +43,7 @@ SubMenu.prototype._createGui = function(params) {
 SubMenu.prototype.addOption = function(name, handler) {
   var self = this;
   if (name instanceof SubMenu) {
-    self.addSubMenu(name);
+    self.getElement().appendChild(name.getElement());
   } else {
     var option = Functions.createElement({
       type : "li",
-- 
GitLab