X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=afm-client%2Fapp%2FFrontend%2Fwidgets%2FActionButtons%2FAppliButton.js;h=f7172253db611cef2641f64ac1a151b24e26e82f;hb=9966df615382815fb6169c9ecd9e3e696f8fa615;hp=f54c5b0a6a5509839eb15e8cecababdd40122a6d;hpb=bf03eef7e8a9d7dcef9f1e739a364be8fb73f7e6;p=src%2Fapp-framework-demo.git diff --git a/afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js b/afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js index f54c5b0..f717225 100644 --- a/afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js +++ b/afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js @@ -31,9 +31,10 @@ '' + 'Application {{label}}' + '' + ''; @@ -49,22 +50,23 @@ ''; angular.module('AppliButton', []) - .directive('appliButton', function (AppConfig, AppCall, ModalFactory, Notification, $timeout) { + .directive('appliButton', function (AppConfig, AppCall, ModalFactory, Notification, $timeout, $window, $location) { function mymethods(scope, elem, attrs) { + scope.runstatus = "stop"; 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() { @@ -78,24 +80,29 @@ switch (action) { case "start": - AppCall.get ("afm-main", "start", {id: scope.appID}, function(response) { + if (scope.runstatus !== "stop") return; + AppCall.get ("afm-main", "start", {id: scope.appID, mode: "remote"}, function(response) { if (response.status !== 200 || response.data.jtype !== "AJB_reply") { notifyError ("start", response); return; } - - notifySuccess ("start", response); + scope.runstatus="start"; + notifySuccess (action, response); + if(response.data.response.uri) + $window.open(response.data.response.uri.replace("%h", $location.host())); }); break; case "stop": - AppCall.get ("afm-main", "stop", {id: scope.runID}, function(response) { + if (scope.runstatus !== "start") return; + + AppCall.get ("afm-main", "terminate", {runid: scope.runID}, function(response) { if (response.status !== 200 || response.data.jtype !== "AJB_reply") { notifyError ("stop", response); return; } - - notifySuccess ("stop", response); + scope.runstatus="stop"; + notifySuccess (action, response); }); break; @@ -108,6 +115,7 @@ // reference http://foundation.zurb.com/apps/docs/#!/angular-modules var config = { + id: 'appliInfoMenu', animationIn: 'slideInFromTop', contentScope: { close : closeModal, @@ -122,8 +130,19 @@ }); break; + + case "uninstall": + if (scope.runstatus !== "stop") return; + AppCall.get ("afm-main", "uninstall", {id: scope.appID}, function(response) { + if (response.status !== 200 || response.data.jtype !== "AJB_reply") { + notifyError ("uninstall", response); + return; + } - + notifySuccess (action, response); + }); + break; + default: console.log ("ActionModal unknown action=[%s]", action); break; @@ -134,13 +153,15 @@ // reference http://foundation.zurb.com/apps/docs/#!/angular-modules var config = { + id: 'appliActionMenu', animationIn: 'slideInFromTop', contentScope: { - action : actionModal, - close : closeModal, - icon : scope.icon, - label : scope.label - }, template : tmplModal + action : actionModal, + runstatus: scope.runstatus, + close : closeModal, + icon : scope.icon, + label : scope.label + }, template : tmplModal }; // Popup Modal to render application data scope.modal = new ModalFactory(config); @@ -149,7 +170,7 @@ // extract application information from AppID+Store if (attrs.handle && scope.store [attrs.handle].name) { - scope.icon = AppConfig.paths.icons + scope.store [attrs.handle].name.toLowerCase() + '-ico.png'; + scope.icon = AppConfig.paths.icons + attrs.handle; //scope.store [attrs.handle].name.toLowerCase() + '-ico.png'; scope.label = scope.store [attrs.handle].name; scope.appID= attrs.handle; } else {