Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 1 | /* |
Simon Hunt | 8ead3a2 | 2015-01-06 11:00:15 -0800 | [diff] [blame] | 2 | * Copyright 2014,2015 Open Networking Laboratory |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 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 | ONOS GUI -- Sample View Module |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | (function () { |
| 22 | 'use strict'; |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 23 | |
| 24 | // injected refs |
| 25 | var $log, tbs, flash; |
| 26 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 27 | // configuration |
| 28 | var tbid = 'sample-toolbar'; |
| 29 | |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 30 | // internal state |
| 31 | var togFnDiv, radFnP; |
Bri Prebilic Cole | 439cd77 | 2015-02-25 09:20:31 -0800 | [diff] [blame] | 32 | |
| 33 | function btnFn() { |
| 34 | flash.flash('Hi there friends!'); |
| 35 | } |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 36 | |
Bri Prebilic Cole | 439cd77 | 2015-02-25 09:20:31 -0800 | [diff] [blame] | 37 | function togFn(display) { |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 38 | togFnDiv.style('display', display ? 'block' : 'none'); |
Bri Prebilic Cole | 664d470 | 2015-02-25 12:16:14 -0800 | [diff] [blame] | 39 | } |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 40 | |
Bri Prebilic Cole | 664d470 | 2015-02-25 12:16:14 -0800 | [diff] [blame] | 41 | function checkFn() { |
| 42 | radFnP.text('Checkmark radio button active.') |
| 43 | .style('color', 'green'); |
| 44 | } |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 45 | |
Bri Prebilic Cole | 664d470 | 2015-02-25 12:16:14 -0800 | [diff] [blame] | 46 | function xMarkFn() { |
| 47 | radFnP.text('Xmark radio button active.') |
| 48 | .style('color', 'red'); |
| 49 | } |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 50 | |
Bri Prebilic Cole | 664d470 | 2015-02-25 12:16:14 -0800 | [diff] [blame] | 51 | function birdFn() { |
| 52 | radFnP.text('Bird radio button active.') |
| 53 | .style('color', '#369'); |
Bri Prebilic Cole | 439cd77 | 2015-02-25 09:20:31 -0800 | [diff] [blame] | 54 | } |
Bri Prebilic Cole | 5000a75 | 2015-02-23 17:20:53 -0800 | [diff] [blame] | 55 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 56 | |
| 57 | // define the controller |
| 58 | |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 59 | angular.module('ovSample', ['onosUtil']) |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 60 | .controller('OvSampleCtrl', |
| 61 | ['$scope', '$log', 'ToolbarService', 'FlashService', |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 62 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 63 | function ($scope, _$log_, _tbs_, _flash_) { |
| 64 | var self = this, |
| 65 | toolbar, |
| 66 | rset; |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 67 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 68 | $log = _$log_; |
| 69 | tbs = _tbs_; |
| 70 | flash = _flash_; |
Simon Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 71 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 72 | self.message = 'Hey there folks!'; |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 73 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 74 | 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 Cole | 439cd77 | 2015-02-25 09:20:31 -0800 | [diff] [blame] | 82 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 83 | radFnP = d3.select('#ov-sample') |
| 84 | .append('p') |
| 85 | .style('font-size', '16pt'); |
Simon Hunt | 6925286 | 2015-02-26 11:26:08 -0800 | [diff] [blame] | 86 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 87 | toolbar = tbs.createToolbar(tbid); |
| 88 | rset = [ |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 89 | { gid: 'checkMark', cb: checkFn, tooltip: 'rbtn tooltip' }, |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 90 | { gid: 'xMark', cb: xMarkFn }, |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 91 | { gid: 'bird', cb: birdFn, tooltip: 'hello' } |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 92 | ]; |
Simon Hunt | df51001 | 2015-02-26 16:34:37 -0800 | [diff] [blame] | 93 | |
Bri Prebilic Cole | 54d0938 | 2015-03-19 18:40:27 -0700 | [diff] [blame] | 94 | toolbar.addButton('demo-button', 'crown', btnFn, 'yay a tooltip'); |
| 95 | toolbar.addToggle('demo-toggle', 'chain', false, togFn, 'another tooltip'); |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 96 | toolbar.addSeparator(); |
| 97 | toolbar.addRadioSet('demo-radio', rset); |
Bri Prebilic Cole | 5a206bb | 2015-03-25 16:33:27 -0700 | [diff] [blame] | 98 | toolbar.hide(); |
Bri Prebilic Cole | 5000a75 | 2015-02-23 17:20:53 -0800 | [diff] [blame] | 99 | |
Simon Hunt | a89f0f9 | 2015-02-26 16:47:12 -0800 | [diff] [blame] | 100 | 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 Hunt | ef31fb2 | 2014-12-19 13:16:44 -0800 | [diff] [blame] | 109 | }()); |