Simon Hunt | 8914d8b | 2014-11-04 17:06:00 -0800 | [diff] [blame] | 1 | /* |
| 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 | Module template file for DIV based view. |
| 19 | |
| 20 | @author Simon Hunt |
| 21 | */ |
| 22 | |
| 23 | (function (onos) { |
| 24 | 'use strict'; |
| 25 | |
| 26 | var list, |
| 27 | data = [ 'foo', 'bar', 'baz' ]; |
| 28 | |
| 29 | // invoked only the first time the view is loaded |
| 30 | function preload(view, ctx) { |
| 31 | // NOTE: view.$div is a D3 selection of the view's div |
| 32 | list = view.$div.append('ul'); |
| 33 | } |
| 34 | |
| 35 | // invoked just prior to loading the view |
| 36 | function reset(view) { |
| 37 | |
| 38 | } |
| 39 | |
| 40 | // invoked when the view is loaded |
| 41 | function load(view, ctx) { |
| 42 | list.selectAll('li') |
| 43 | .data(data) |
| 44 | .enter() |
| 45 | .append('li') |
| 46 | .text(function (d) { return d; }) |
| 47 | } |
| 48 | |
| 49 | // invoked when the view is resized |
| 50 | function resize(view, ctx) { |
| 51 | |
| 52 | } |
| 53 | |
| 54 | // == register the view here, with links to lifecycle callbacks |
| 55 | |
| 56 | onos.ui.addView('myViewId', { |
| 57 | preload: preload, |
| 58 | reset: reset, |
| 59 | load: load, |
| 60 | // unload: unload, |
| 61 | // error: error |
| 62 | resize: resize |
| 63 | }); |
| 64 | |
| 65 | }(ONOS)); |