Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | Sample view to illustrate radio buttons. |
Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | (function (onos) { |
| 22 | 'use strict'; |
| 23 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 24 | var intro = [ 'Yo, radio button set...', 'Time to shine' ], |
Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 25 | btnSet = [ |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 26 | { text: 'First Button', cb: cbRadio }, |
| 27 | { text: 'Second Button', cb: cbRadio }, |
| 28 | { text: 'Third Button', cb: cbRadio } |
| 29 | ]; |
Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 30 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 31 | // radio button callback |
| 32 | function cbRadio(view, btn) { |
| 33 | write(view, 'You pressed the ' + btn.text); |
Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 34 | } |
| 35 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 36 | function write(view, msg) { |
Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 37 | view.$div.append('p') |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 38 | .text(msg) |
Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 39 | .style({ |
| 40 | 'font-size': '10pt', |
| 41 | color: 'green', |
| 42 | padding: '0 20px', |
| 43 | margin: '2px' |
| 44 | }); |
| 45 | } |
| 46 | |
Simon Hunt | 934c3ce | 2014-11-05 11:45:07 -0800 | [diff] [blame] | 47 | // invoked when the view is loaded |
| 48 | function load(view, ctx) { |
| 49 | view.setRadio(btnSet); |
| 50 | |
| 51 | view.$div.selectAll('p') |
| 52 | .data(intro) |
| 53 | .enter() |
| 54 | .append('p') |
| 55 | .text(function (d) { return d; }) |
| 56 | .style('padding', '2px 8px'); |
| 57 | } |
| 58 | |
Simon Hunt | db9eb07 | 2014-11-04 19:12:46 -0800 | [diff] [blame] | 59 | // == register the view here, with links to lifecycle callbacks |
| 60 | |
| 61 | onos.ui.addView('sampleRadio', { |
| 62 | reset: true, // empty the div on reset |
| 63 | load: load |
| 64 | }); |
| 65 | |
| 66 | }(ONOS)); |