blob: 4d362a9cfe4d4edb731d893d6c77cc94ae218228 [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
26 var data = [ 'Yo, radio button set...', 'Time to shine' ],
27 btnSet = [
28 { id: 'b1', text: 'First Button' },
29 { id: 'b2', text: 'Second Button' },
30 { id: 'b3', text: 'Third Button' }
31 ],
32 btnLookup = {};
33
34 btnSet.forEach(function (b) {
35 btnLookup[b.id] = b;
36 });
37
38 // invoked when the view is loaded
39 function load(view, ctx) {
40 view.setRadio(btnSet, doRadio);
41
42 view.$div.selectAll('p')
43 .data(data)
44 .enter()
45 .append('p')
46 .text(function (d) { return d; })
47 .style('padding', '2px 8px');
48 }
49
50 function doRadio(view, id) {
51 view.$div.append('p')
52 .text('You pressed the ' + btnLookup[id].text)
53 .style({
54 'font-size': '10pt',
55 color: 'green',
56 padding: '0 20px',
57 margin: '2px'
58 });
59 }
60
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));