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