From 3ebdce373e134b70b129154d8033c1c628847a6c Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Mon, 25 Jan 2016 14:37:32 +0100 Subject: First version --- .../widgets/ActionButtons/ActionButtons.scss | 27 +++++ .../Frontend/widgets/ActionButtons/AppliButton.js | 130 +++++++++++++++++++++ .../Frontend/widgets/ActionButtons/SubmitButton.js | 52 +++++++++ 3 files changed, 209 insertions(+) create mode 100644 afm-client/app/Frontend/widgets/ActionButtons/ActionButtons.scss create mode 100644 afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js create mode 100644 afm-client/app/Frontend/widgets/ActionButtons/SubmitButton.js (limited to 'afm-client/app/Frontend/widgets/ActionButtons') diff --git a/afm-client/app/Frontend/widgets/ActionButtons/ActionButtons.scss b/afm-client/app/Frontend/widgets/ActionButtons/ActionButtons.scss new file mode 100644 index 0000000..16f7bb5 --- /dev/null +++ b/afm-client/app/Frontend/widgets/ActionButtons/ActionButtons.scss @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2015 "IoT.bzh" + * Author "Fulup Ar Foll" + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +@import "app/ibz-mixins"; + +// place here your submit buttons customization +appli-button { + @include ibz-button(grey,1rem) + img { + height: 3rem; + } +} diff --git a/afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js b/afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js new file mode 100644 index 0000000..387212e --- /dev/null +++ b/afm-client/app/Frontend/widgets/ActionButtons/AppliButton.js @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2015 "IoT.bzh" + * Author "Fulup Ar Foll" + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Bugs: Input with Callback SHOULD BE get 'required' class + */ + +(function () { + 'use strict'; + + var tmplAppli = '
' + + '' + + '{{label}}' + + '
'; + + var tmplModal = + '×' + + '' + + 'Application {{appname}}' + + '' + + ''; + + angular.module('AppliButton', []) + .directive('appliButton', function (AppConfig, AppCall, ModalFactory, Notification, $timeout) { + + function mymethods(scope, elem, attrs) { + scope.clicked = function () { + + var closeModal = function() { + console.log ("Modal Closing"); + scope.modal.deactivate(); + $timeout (function() {scope.modal.destroy();}, 1000); + }; + + var actionModal = function(action) { + console.log ("Modal Action=%s", action); + switch (action) { + + case "start": + AppCall.get ("afm-main", "start", {id: scope.appliID}, function(response) { + if (response.status !== 200) { + Notification.error ({message: "Fail to start application=" + scope.label +" ID="+ scope.appliID, delay: 5000}); + elem.addClass ("fail"); + elem.removeClass ("success"); + scope.callback (scope.appliID, "/api/afm-main/start", response); + return; + } + + // Check this is a valid response from Binder + if (response.data.request.jtype !== "AJB_reply" && response.data.request.api !== "start") { + Notification.error ({message: "Invalid Respond to /opa/afm-main/start response.data="+response.data, delay: 5000}); + elem.addClass ("fail"); + elem.removeClass ("success"); + scope.callback (scope.appliID, "/api/afm-main/start", response); + return; + } + + // Application was stated + scope.callback (scope.appliID, "/api/afm-main/start", response); + }); + break; + + case "stop": + break; + + default: + console.log ("ActionModal unknown action=[%s]", action); + break; + } + + closeModal(); + }; + + // reference http://foundation.zurb.com/apps/docs/#!/angular-modules + var config = { + animationIn: 'slideInFromTop', + contentScope: { + action : actionModal, + close : closeModal, + appicon : scope.icon, + appname : scope.label, + }, template : tmplModal + }; + // Popup Modal to render application data + scope.modal = new ModalFactory(config); + scope.modal.activate (); + }; + + // 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(); + scope.label = scope.store [attrs.handle].name; + scope.appliID= attrs.handle; + } else { + scope.icon = AppConfig.paths.icons + 'w3c-ico.png'; + scope.label = attrs.handle; + } + + // add label as class + elem.addClass (scope.label.toLowerCase()); + + // note: clicked in imported and when template is clicked + // it will call clicked method passed in param. + } + + return { + restrict: 'E', + template: tmplAppli, + link: mymethods, + scope: {callback: '=', store: '='} + }; + }); +})(); diff --git a/afm-client/app/Frontend/widgets/ActionButtons/SubmitButton.js b/afm-client/app/Frontend/widgets/ActionButtons/SubmitButton.js new file mode 100644 index 0000000..323cd46 --- /dev/null +++ b/afm-client/app/Frontend/widgets/ActionButtons/SubmitButton.js @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2015 "IoT.bzh" + * Author "Fulup Ar Foll" + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Bugs: Input with Callback SHOULD BE get 'required' class + */ + +(function () { + 'use strict'; + + var tmpl = '
' + + '' + + '{{label}}' + + '
'; + + angular.module('SubmitButton', []) + .directive('submitButton', function () { + + function mymethods(scope, elem, attrs) { + + // ajust icon or use default + scope.icon = attrs.icon || 'fi-foot'; + scope.label = attrs.label || 'Next'; + + // add label as class + elem.addClass (scope.label.toLowerCase()); + + // note: clicked in imported and when template is clicked + // it will call clicked method passed in param. + } + + return { + restrict: 'E', + template: tmpl, + link: mymethods, + scope: {clicked : '='} + }; + }); +})(); -- cgit