Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [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 | |
Steven Burrows | bbe3dda | 2016-09-26 14:41:59 -0700 | [diff] [blame^] | 17 | /* |
| 18 | ONOS GUI -- Topology Map Dialog |
| 19 | Display of the dialog window to select a background map for the current topology view |
| 20 | NOTE: This will be deprecated in the future |
| 21 | */ |
Steven Burrows | d576f64 | 2016-09-26 10:40:51 -0700 | [diff] [blame] | 22 | |
| 23 | (function () { |
| 24 | 'use strict'; |
| 25 | |
| 26 | // Injected |
| 27 | var $log, wss, t2ds; |
| 28 | |
| 29 | // Constants |
| 30 | var mapRequest = 'mapSelectorRequest'; |
| 31 | |
| 32 | // State |
| 33 | var order, maps, map, mapItems; |
| 34 | |
| 35 | var Dialog = function (options) { |
| 36 | |
| 37 | this.okHandlerCallback = options.okHandler; |
| 38 | this.closeHandlerCallback = options.closeHandler; |
| 39 | |
| 40 | wss.bindHandlers({ |
| 41 | mapSelectorResponse: this.handleMapResponse.bind(this) |
| 42 | }); |
| 43 | }; |
| 44 | |
| 45 | Dialog.prototype = { |
| 46 | handleMapResponse: function (data) { |
| 47 | $log.info('Got response', data); |
| 48 | order = data.order; |
| 49 | maps = data.maps; |
| 50 | |
| 51 | t2ds.openDialog() |
| 52 | .setTitle('Select Map') |
| 53 | .addContent(this.render.bind(this)()) |
| 54 | .addOk(this.okHandler.bind(this), 'OK') |
| 55 | .addCancel(this.closeHandler.bind(this), 'Close') |
| 56 | .bindKeys(); |
| 57 | }, |
| 58 | |
| 59 | open: function () { |
| 60 | wss.sendEvent(mapRequest); |
| 61 | }, |
| 62 | close: function () { |
| 63 | wss.unbindHandlers({ |
| 64 | mapSelectorResponse: this.handleMapResponse.bind(this) |
| 65 | }); |
| 66 | }, |
| 67 | |
| 68 | selectedMap: function () { |
| 69 | map = maps[this.options[this.selectedIndex].value]; |
| 70 | $log.info('Selected map', map); |
| 71 | }, |
| 72 | |
| 73 | okHandler: function () { |
| 74 | |
| 75 | var p = { |
| 76 | mapid: map.id, |
| 77 | mapscale: map.scale, |
| 78 | mapfilepath: map.filePath, |
| 79 | tint: 'off' |
| 80 | // tint: tintCheck.property('checked') ? 'on' : 'off' |
| 81 | }; |
| 82 | |
| 83 | if (this.okHandlerCallback) { |
| 84 | this.okHandlerCallback(p); |
| 85 | } |
| 86 | |
| 87 | this.close(); |
| 88 | }, |
| 89 | closeHandler: function () { |
| 90 | |
| 91 | if (this.closeHandlerCallback) { |
| 92 | this.closeHandlerCallback(); |
| 93 | } |
| 94 | |
| 95 | this.close(); |
| 96 | }, |
| 97 | |
| 98 | render: function () { |
| 99 | |
| 100 | var content = t2ds.createDiv('map-list'), |
| 101 | form = content.append('form'), |
| 102 | current = this.currentMap(); |
| 103 | |
| 104 | map = maps[current.mapid]; |
| 105 | mapItems = form.append('select').on('change', this.selectedMap); |
| 106 | |
| 107 | order.forEach(function (id) { |
| 108 | var m = maps[id]; |
| 109 | mapItems.append('option') |
| 110 | .attr('value', m.id) |
| 111 | .attr('selected', m.id === current.mapid ? true : null) |
| 112 | .text(m.description); |
| 113 | }); |
| 114 | |
| 115 | return content; |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | angular.module('ovTopo2') |
| 120 | .factory('Topo2MapDialog', [ |
| 121 | '$log', 'WebSocketService', 'Topo2DialogService', |
| 122 | function (_$log_, _wss_, _t2ds_) { |
| 123 | |
| 124 | $log = _$log_; |
| 125 | wss = _wss_; |
| 126 | t2ds = _t2ds_; |
| 127 | |
| 128 | return Dialog; |
| 129 | } |
| 130 | ]); |
| 131 | })(); |