blob: 11dd1efdcc6427f9b33b77144411ddb86fa0eb52 [file] [log] [blame]
Simon Huntdb9eb072014-11-04 19:12:46 -08001/*
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 Huntdb9eb072014-11-04 19:12:46 -080019 */
20
21(function (onos) {
22 'use strict';
23
Simon Hunt934c3ce2014-11-05 11:45:07 -080024 var intro = [ 'Yo, radio button set...', 'Time to shine' ],
Simon Huntdb9eb072014-11-04 19:12:46 -080025 btnSet = [
Simon Hunt934c3ce2014-11-05 11:45:07 -080026 { text: 'First Button', cb: cbRadio },
27 { text: 'Second Button', cb: cbRadio },
28 { text: 'Third Button', cb: cbRadio }
29 ];
Simon Huntdb9eb072014-11-04 19:12:46 -080030
Simon Hunt934c3ce2014-11-05 11:45:07 -080031 // radio button callback
32 function cbRadio(view, btn) {
33 write(view, 'You pressed the ' + btn.text);
Simon Huntdb9eb072014-11-04 19:12:46 -080034 }
35
Simon Hunt934c3ce2014-11-05 11:45:07 -080036 function write(view, msg) {
Simon Huntdb9eb072014-11-04 19:12:46 -080037 view.$div.append('p')
Simon Hunt934c3ce2014-11-05 11:45:07 -080038 .text(msg)
Simon Huntdb9eb072014-11-04 19:12:46 -080039 .style({
40 'font-size': '10pt',
41 color: 'green',
42 padding: '0 20px',
43 margin: '2px'
44 });
45 }
46
Simon Hunt934c3ce2014-11-05 11:45:07 -080047 // 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 Huntdb9eb072014-11-04 19:12:46 -080059 // == 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));