Simon Hunt | 0b05d4a | 2014-10-21 21:50:15 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 781d18b | 2014-10-27 10:31:25 -0700 | [diff] [blame^] | 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | /* |
Simon Hunt | 0b05d4a | 2014-10-21 21:50:15 -0700 | [diff] [blame] | 21 | ONOS UI Framework. |
| 22 | |
| 23 | @author Simon Hunt |
| 24 | */ |
| 25 | |
| 26 | (function ($) { |
| 27 | 'use strict'; |
| 28 | var tsI = new Date().getTime(), // initialize time stamp |
| 29 | tsB; // build time stamp |
| 30 | |
| 31 | // attach our main function to the jQuery object |
| 32 | $.onos = function (options) { |
| 33 | // private namespaces |
| 34 | var publicApi; // public api |
| 35 | |
| 36 | // internal state |
| 37 | var views = {}, |
| 38 | currentView = null, |
| 39 | built = false; |
| 40 | |
| 41 | // DOM elements etc. |
| 42 | var $mast; |
| 43 | |
| 44 | |
| 45 | // various functions.................. |
| 46 | |
| 47 | // throw an error |
| 48 | function throwError(msg) { |
| 49 | // todo: maybe add tracing later |
| 50 | throw new Error(msg); |
| 51 | } |
| 52 | |
| 53 | // define all the public api functions... |
| 54 | publicApi = { |
| 55 | printTime: function () { |
| 56 | console.log("the time is " + new Date()); |
| 57 | }, |
| 58 | |
| 59 | addView: function (vid, cb) { |
| 60 | views[vid] = { |
| 61 | vid: vid, |
| 62 | cb: cb |
| 63 | }; |
| 64 | // TODO: proper registration of views |
| 65 | // for now, make the one (and only) view current.. |
| 66 | currentView = views[vid]; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | // function to be called from index.html to build the ONOS UI |
| 71 | function buildOnosUi() { |
| 72 | tsB = new Date().getTime(); |
| 73 | tsI = tsB - tsI; // initialization duration |
| 74 | |
| 75 | console.log('ONOS UI initialized in ' + tsI + 'ms'); |
| 76 | |
| 77 | if (built) { |
| 78 | throwError("ONOS UI already built!"); |
| 79 | } |
| 80 | built = true; |
| 81 | |
| 82 | // TODO: invoke hash navigation |
| 83 | // --- report build errors --- |
| 84 | |
| 85 | // for now, invoke the one and only load function: |
| 86 | |
| 87 | currentView.cb.load(); |
| 88 | } |
| 89 | |
| 90 | |
| 91 | // export the api and build-UI function |
| 92 | return { |
| 93 | api: publicApi, |
| 94 | buildUi: buildOnosUi |
| 95 | }; |
| 96 | }; |
| 97 | |
| 98 | }(jQuery)); |