Added runmode=remote|local
[src/app-framework-demo.git] / afm-client / app / Frontend / widgets / ActionButtons / AppliButton.js
index 69e61b6..014fe4d 100644 (file)
             '';
 
     angular.module('AppliButton', [])
-            .directive('appliButton', function (AppConfig, AppCall, ModalFactory, Notification, $timeout) {
+            .directive('appliButton', function (AppConfig, AppCall, ModalFactory, Notification, $timeout, $window, $location, urlquery) {
 
                 function mymethods(scope, elem, attrs) {
-                    scope.runstatus = "stop"
+                    scope.runstatus = "stop";
+                    scope.runmode   = urlquery.runmode || "auto";
                     scope.clicked = function () {
 
-                        var notifyError = function(api, response) {
-                            Notification.error ({message: "Fail /api/afm-main" + api + "=" + scope.label + " RunID="+ scope.appID, delay: 5000});
+                        var notifyError = function(action, response) {
+                            Notification.error ({message: "Fail /api/afm-main" + action + "=" + scope.label + " RunID="+ scope.appID, delay: 5000});
                             elem.addClass ("fail");
                             elem.removeClass ("success");
-                            scope.callback (scope.appID, api, response);
+                            scope.callback (scope.appID, action, response);
                         };
                         
-                        var notifySuccess = function (api, response) {
+                        var notifySuccess = function (action, response) {
                             elem.removeClass ("fail");
                             scope.runID = response.data.response.runid;
-                            scope.callback (scope.appID, "/api/afm-main/start", response);
+                            scope.callback (scope.appID, action, response);
                         };
                         
                         var closeModal = function() {
                                 
                                 case "start":
                                     if (scope.runstatus !== "stop") return;
-                                    AppCall.get ("afm-main", "start", {id: scope.appID}, function(response) {
+                                    AppCall.get ("afm-main", "start", {id: scope.appID, mode: scope.runmode}, function(response) {
                                         if (response.status !== 200 || response.data.jtype !== "AJB_reply") {
                                             notifyError ("start", response);
                                             return;
                                         }
                                         scope.runstatus="start";
-                                        notifySuccess ("start", response);
+                                        notifySuccess (action, response);
+                                       if(response.data.response.uri)
+                                               $window.open(response.data.response.uri.replace("%h", $location.host()));
                                     });
                                     break;
                                     
                                             return;
                                         }
                                         scope.runstatus="stop";
-                                        notifySuccess ("stop", response);
+                                        notifySuccess (action, response);
                                     });
                                     break;
                                         
                                             return;
                                         }
                                         
-                                        notifySuccess ("uninstall", response);
+                                        notifySuccess (action, response);
                                     });
                                     break;