blob: 92df3698a7f4d281f04c3dd03d85c47d1f779f30 [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.
19
20 @author Simon Hunt
21 */
22
23(function (onos) {
24 'use strict';
25
Simon Hunt934c3ce2014-11-05 11:45:07 -080026 var intro = [ 'Yo, radio button set...', 'Time to shine' ],
Simon Huntdb9eb072014-11-04 19:12:46 -080027 btnSet = [
Simon Hunt934c3ce2014-11-05 11:45:07 -080028 { text: 'First Button', cb: cbRadio },
29 { text: 'Second Button', cb: cbRadio },
30 { text: 'Third Button', cb: cbRadio }
31 ];
Simon Huntdb9eb072014-11-04 19:12:46 -080032
Simon Hunt934c3ce2014-11-05 11:45:07 -080033 // radio button callback
34 function cbRadio(view, btn) {
35 write(view, 'You pressed the ' + btn.text);
Simon Huntdb9eb072014-11-04 19:12:46 -080036 }
37
Simon Hunt934c3ce2014-11-05 11:45:07 -080038 function write(view, msg) {
Simon Huntdb9eb072014-11-04 19:12:46 -080039 view.$div.append('p')
Simon Hunt934c3ce2014-11-05 11:45:07 -080040 .text(msg)
Simon Huntdb9eb072014-11-04 19:12:46 -080041 .style({
42 'font-size': '10pt',
43 color: 'green',
44 padding: '0 20px',
45 margin: '2px'
46 });
47 }
48
Simon Hunt934c3ce2014-11-05 11:45:07 -080049 // 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 Huntdb9eb072014-11-04 19:12:46 -080061 // == 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));