rama-huawei | c78f309 | 2016-05-19 18:09:29 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | sfc web gui overlay implementation. |
| 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
| 23 | |
| 24 | // injected refs |
| 25 | var $log, fs, flash, wss, tds, ds, handlerMap = {}; |
| 26 | |
| 27 | // constants |
| 28 | var displayStart = 'sfcwebTopovDisplayStart', |
| 29 | showSfcInf = 'showSfcInfo', |
| 30 | clearMessage = 'sfcTopovClear', |
| 31 | configSfpMessage = 'configSfpMessage' ; |
| 32 | |
| 33 | // internal state |
| 34 | var currentMode = null; |
| 35 | |
| 36 | // === Main API functions |
| 37 | |
| 38 | function start() { |
| 39 | handlerMap[showSfcInf] = showSfcInformation; |
| 40 | wss.bindHandlers(handlerMap); |
| 41 | wss.sendEvent(displayStart); |
| 42 | } |
| 43 | |
| 44 | function dOk() { |
| 45 | var sfcId = null; |
| 46 | sfcId = d3.select('#sfp-value').property("value"); |
| 47 | |
| 48 | if (sfcId) { |
| 49 | console.log(sfcId); |
| 50 | } |
| 51 | |
| 52 | $log.debug('Dialog OK button clicked'); |
| 53 | |
| 54 | wss.sendEvent(configSfpMessage, { |
| 55 | id: sfcId |
| 56 | }); |
| 57 | |
| 58 | flash.flash('SFP ID query:'); |
| 59 | } |
| 60 | |
| 61 | function dClose() { |
| 62 | $log.debug('Dialog Close button clicked (or Esc pressed)'); |
| 63 | } |
| 64 | |
| 65 | function createUserText() { |
| 66 | var content = ds.createDiv(); |
| 67 | var form = content.append('form'); |
| 68 | var p = form.append('p'); |
| 69 | |
| 70 | p.append('input').attr({ |
| 71 | id: 'sfp-value', |
| 72 | type: 'string', |
| 73 | name: 'sfp-value-name' |
| 74 | }); |
| 75 | p.append('span').text('ID'); |
| 76 | p.append('br'); |
| 77 | |
| 78 | return content; |
| 79 | } |
| 80 | |
| 81 | function configSfp() { |
| 82 | tds.openDialog() |
| 83 | .setTitle('SFP ID User Input') |
| 84 | .addContent(createUserText()) |
| 85 | .addOk(dOk, 'OK') |
| 86 | .addCancel(dClose, 'Close') |
| 87 | .bindKeys(); |
| 88 | } |
| 89 | |
| 90 | function showSfcInformation(data) { |
| 91 | console.log(data); |
| 92 | wss.unbindHandlers(handlerMap); |
| 93 | |
| 94 | // Get the modal |
| 95 | var modal = document.getElementById('myModal'); |
| 96 | |
| 97 | // Get the button that opens the modal |
| 98 | var btn = document.getElementById("myBtn"); |
| 99 | |
| 100 | // Get the <span> element that closes the modal |
| 101 | var span = document.getElementsByClassName("close")[0]; |
| 102 | |
| 103 | modal.style.display = "block"; |
| 104 | |
| 105 | var tBody = document.getElementById('sfc-info-body'); |
| 106 | |
| 107 | var tdString = '' ; |
| 108 | |
| 109 | for (var i = 0; i < data.a.length; i++) { |
| 110 | tdString += '<tr> <td>'+ data.a[i] +'</td></tr>'; |
| 111 | } |
| 112 | |
| 113 | tBody.innerHTML = tdString; |
| 114 | |
| 115 | // When the user clicks on <span> (x), close the modal |
| 116 | span.onclick = function() { |
| 117 | modal.style.display = "none"; |
| 118 | } |
| 119 | |
| 120 | // When the user clicks anywhere outside of the modal, close it |
| 121 | window.onclick = function(event) { |
| 122 | if (event.target == modal) { |
| 123 | modal.style.display = "none"; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | } |
| 128 | |
| 129 | function clear() { |
| 130 | wss.sendEvent(clearMessage); |
| 131 | flash.flash('Cleared SFC overlay'); |
| 132 | } |
| 133 | |
| 134 | // === --------------------------- |
| 135 | // === Module Factory Definition |
| 136 | angular.module('ovSfcwebTopov', []) |
| 137 | .factory('SfcwebTopovDemoService', |
| 138 | ['$log', 'FnService', 'FlashService', 'WebSocketService', 'TopoDialogService', 'DialogService', |
| 139 | function (_$log_, _fs_, _flash_, _wss_, _tds_, _ds_) { |
| 140 | $log = _$log_; |
| 141 | fs = _fs_; |
| 142 | flash = _flash_; |
| 143 | wss = _wss_; |
| 144 | tds = _tds_; |
| 145 | ds = _ds_; |
| 146 | return { |
| 147 | start: start, |
| 148 | showSfcInformation: showSfcInformation, |
| 149 | clear: clear, |
| 150 | configSfp: configSfp |
| 151 | }; |
| 152 | }]); |
| 153 | |
| 154 | }()); |