blob: 9e6133b17e94ffba2264a3a3947a84759fff4ad8 [file] [log] [blame]
Simon Huntef31fb22014-12-19 13:16:44 -08001/*
Simon Hunt8ead3a22015-01-06 11:00:15 -08002 * Copyright 2014,2015 Open Networking Laboratory
Simon Huntef31fb22014-12-19 13:16:44 -08003 *
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 ONOS GUI -- Sample View Module
Simon Huntef31fb22014-12-19 13:16:44 -080019 */
20
21(function () {
22 'use strict';
Simon Hunt69252862015-02-26 11:26:08 -080023
24 // injected refs
25 var $log, tbs, flash;
26
Simon Hunta89f0f92015-02-26 16:47:12 -080027 // configuration
28 var tbid = 'sample-toolbar';
29
Simon Hunt69252862015-02-26 11:26:08 -080030 // internal state
31 var togFnDiv, radFnP;
Bri Prebilic Cole439cd772015-02-25 09:20:31 -080032
33 function btnFn() {
34 flash.flash('Hi there friends!');
35 }
Simon Hunt69252862015-02-26 11:26:08 -080036
Bri Prebilic Cole439cd772015-02-25 09:20:31 -080037 function togFn(display) {
Simon Hunt69252862015-02-26 11:26:08 -080038 togFnDiv.style('display', display ? 'block' : 'none');
Bri Prebilic Cole664d4702015-02-25 12:16:14 -080039 }
Simon Hunt69252862015-02-26 11:26:08 -080040
Bri Prebilic Cole664d4702015-02-25 12:16:14 -080041 function checkFn() {
42 radFnP.text('Checkmark radio button active.')
43 .style('color', 'green');
44 }
Simon Hunt69252862015-02-26 11:26:08 -080045
Bri Prebilic Cole664d4702015-02-25 12:16:14 -080046 function xMarkFn() {
47 radFnP.text('Xmark radio button active.')
48 .style('color', 'red');
49 }
Simon Hunt69252862015-02-26 11:26:08 -080050
Bri Prebilic Cole664d4702015-02-25 12:16:14 -080051 function birdFn() {
52 radFnP.text('Bird radio button active.')
53 .style('color', '#369');
Bri Prebilic Cole439cd772015-02-25 09:20:31 -080054 }
Bri Prebilic Cole5000a752015-02-23 17:20:53 -080055
Simon Hunta89f0f92015-02-26 16:47:12 -080056
57 // define the controller
58
Simon Huntef31fb22014-12-19 13:16:44 -080059 angular.module('ovSample', ['onosUtil'])
Simon Hunta89f0f92015-02-26 16:47:12 -080060 .controller('OvSampleCtrl',
61 ['$scope', '$log', 'ToolbarService', 'FlashService',
Simon Hunt69252862015-02-26 11:26:08 -080062
Simon Hunta89f0f92015-02-26 16:47:12 -080063 function ($scope, _$log_, _tbs_, _flash_) {
64 var self = this,
65 toolbar,
66 rset;
Simon Huntef31fb22014-12-19 13:16:44 -080067
Simon Hunta89f0f92015-02-26 16:47:12 -080068 $log = _$log_;
69 tbs = _tbs_;
70 flash = _flash_;
Simon Huntef31fb22014-12-19 13:16:44 -080071
Simon Hunta89f0f92015-02-26 16:47:12 -080072 self.message = 'Hey there folks!';
Simon Hunt69252862015-02-26 11:26:08 -080073
Simon Hunta89f0f92015-02-26 16:47:12 -080074 togFnDiv = d3.select('#ov-sample')
75 .append('div')
76 .text('Look at me!')
77 .style({
78 display: 'none',
79 color: 'rgb(204, 89, 81)',
80 'font-size': '20pt'
81 });
Bri Prebilic Cole439cd772015-02-25 09:20:31 -080082
Simon Hunta89f0f92015-02-26 16:47:12 -080083 radFnP = d3.select('#ov-sample')
84 .append('p')
85 .style('font-size', '16pt');
Simon Hunt69252862015-02-26 11:26:08 -080086
Simon Hunta89f0f92015-02-26 16:47:12 -080087 toolbar = tbs.createToolbar(tbid);
88 rset = [
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070089 { gid: 'checkMark', cb: checkFn, tooltip: 'rbtn tooltip' },
Simon Hunta89f0f92015-02-26 16:47:12 -080090 { gid: 'xMark', cb: xMarkFn },
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070091 { gid: 'bird', cb: birdFn, tooltip: 'hello' }
Simon Hunta89f0f92015-02-26 16:47:12 -080092 ];
Simon Huntdf510012015-02-26 16:34:37 -080093
Bri Prebilic Cole54d09382015-03-19 18:40:27 -070094 toolbar.addButton('demo-button', 'crown', btnFn, 'yay a tooltip');
95 toolbar.addToggle('demo-toggle', 'chain', false, togFn, 'another tooltip');
Simon Hunta89f0f92015-02-26 16:47:12 -080096 toolbar.addSeparator();
97 toolbar.addRadioSet('demo-radio', rset);
Bri Prebilic Cole5a206bb2015-03-25 16:33:27 -070098 toolbar.hide();
Bri Prebilic Cole5000a752015-02-23 17:20:53 -080099
Simon Hunta89f0f92015-02-26 16:47:12 -0800100 checkFn();
101
102 // Clean up on destroyed scope
103 $scope.$on('$destroy', function () {
104 tbs.destroyToolbar(tbid);
105 });
106
107 $log.log('OvSampleCtrl has been created');
108 }]);
Simon Huntef31fb22014-12-19 13:16:44 -0800109}());