2 * Copyright (C) 2015 "IoT.bzh"
3 * Author "Fulup Ar Foll"
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * Bugs: Input with Callback SHOULD BE get 'required' class
24 var tmplAppli = '<div ng-click="clicked()">' +
25 '<img ng-src={{icon}}-ico.png>' +
26 '<span>{{label}}</span>' +
30 '<b class="close-button" ng-click="close()">×</b>' +
31 '<img ng-src="{{appicon}}-ico.png">' +
32 '<span class="modal-text">Application <b>{{appname}}</b></span>' +
33 '<ul class="vertical icon-left primary menu-bar">' +
34 '<li><a ng-click=action("start")><i class="fi-check"> Start</i></a></li>' +
35 '<li><a href="#"><i class="fi-x"> Stop</i></a></li>' +
36 '<li><a href="#"><i class="fi-info"> Info</i></a></li>' +
40 angular.module('AppliButton', [])
41 .directive('appliButton', function (AppConfig, AppCall, ModalFactory, Notification, $timeout) {
43 function mymethods(scope, elem, attrs) {
44 scope.clicked = function () {
46 var closeModal = function() {
47 console.log ("Modal Closing");
48 scope.modal.deactivate();
49 $timeout (function() {scope.modal.destroy();}, 1000);
52 var actionModal = function(action) {
53 console.log ("Modal Action=%s", action);
57 AppCall.get ("afm-main", "start", {id: scope.appliID}, function(response) {
58 if (response.status !== 200) {
59 Notification.error ({message: "Fail to start application=" + scope.label +" ID="+ scope.appliID, delay: 5000});
60 elem.addClass ("fail");
61 elem.removeClass ("success");
62 scope.callback (scope.appliID, "/api/afm-main/start", response);
66 // Check this is a valid response from Binder
67 if (response.data.request.jtype !== "AJB_reply" && response.data.request.api !== "start") {
68 Notification.error ({message: "Invalid Respond to /opa/afm-main/start response.data="+response.data, delay: 5000});
69 elem.addClass ("fail");
70 elem.removeClass ("success");
71 scope.callback (scope.appliID, "/api/afm-main/start", response);
75 // Application was stated
76 scope.callback (scope.appliID, "/api/afm-main/start", response);
84 console.log ("ActionModal unknown action=[%s]", action);
91 // reference http://foundation.zurb.com/apps/docs/#!/angular-modules
93 animationIn: 'slideInFromTop',
98 appname : scope.label,
99 }, template : tmplModal
101 // Popup Modal to render application data
102 scope.modal = new ModalFactory(config);
103 scope.modal.activate ();
106 // extract application information from AppID+Store
107 if (attrs.handle && scope.store [attrs.handle].name) {
108 scope.icon = AppConfig.paths.icons + scope.store [attrs.handle].name.toLowerCase();
109 scope.label = scope.store [attrs.handle].name;
110 scope.appliID= attrs.handle;
112 scope.icon = AppConfig.paths.icons + 'w3c-ico.png';
113 scope.label = attrs.handle;
116 // add label as class
117 elem.addClass (scope.label.toLowerCase());
119 // note: clicked in imported and when template is clicked
120 // it will call clicked method passed in param.
127 scope: {callback: '=', store: '='}