Fix 'setWidget' action for the case a widget was closed instead of minimized

Change-Id: I74339e444fcca43aee3c694c2a24fe7e68980d81
diff --git a/dev/js/src/plugin/server.js b/dev/js/src/plugin/server.js
index ce36354..7f9bc85 100644
--- a/dev/js/src/plugin/server.js
+++ b/dev/js/src/plugin/server.js
@@ -157,15 +157,28 @@
             // a intermediate object to toggle the view
             if ('state' in this.button && this.button.state.associates() > 0) {
 
-              // TODO:
-              //   Use roll() when existing
               let s = this.button.state;
-              if (s.get()) {
-                s.set(false);
-              } else {
+
+              // The associated service is existent
+              if (services[this.button['widgetID']]) {
+              
+                // TODO:
+                //   Use roll() when existing
+                if (s.get()) {
+                  s.set(false);
+                } else {
+                  s.set(true);
+                };
+                return;
+              }
+
+              // The service is not existent
+              else {
+
+                // Remove broken state associations
+                s.clear();
                 s.set(true);
-              };
-              return;
+              }
             };
 
             // Add the widget to the panel
@@ -174,6 +187,7 @@
             
             // If a state exists, associate with a mediator object
             if ('state' in this.button) {
+              this.button['widgetID'] = id;
               this.button.state.associate({
                 setState : function (value) {
                   // Minimize the widget
@@ -493,7 +507,7 @@
     // Close the service
     _closeService : function (id) {
       delete limits[id];
-
+      
       // Close the iframe
       if (services[id] && services[id]._closeIframe) {
         services[id]._closeIframe();
diff --git a/dev/js/src/plugin/widget.js b/dev/js/src/plugin/widget.js
index 25bc6cc..a845ebc 100644
--- a/dev/js/src/plugin/widget.js
+++ b/dev/js/src/plugin/widget.js
@@ -65,7 +65,7 @@
     // On closing the widget view
     onClose : function () {
       if (this._mgr) {
-        this._mgr._closeService(this._id);
+        this._mgr._closeService(this.id);
         this._mgr = undefined;
       };
     }