blob: 7153d76d0ae10d6ad47aebec588342035ad0ae65 [file] [log] [blame]
Simon Hunt0b05d4a2014-10-21 21:50:15 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska781d18b2014-10-27 10:31:25 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska781d18b2014-10-27 10:31:25 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska781d18b2014-10-27 10:31:25 -070015 */
16
17/*
Simon Hunt0b05d4a2014-10-21 21:50:15 -070018 ONOS UI Framework.
19
20 @author Simon Hunt
21 */
22
23(function ($) {
24 'use strict';
25 var tsI = new Date().getTime(), // initialize time stamp
26 tsB; // build time stamp
27
28 // attach our main function to the jQuery object
29 $.onos = function (options) {
30 // private namespaces
31 var publicApi; // public api
32
33 // internal state
34 var views = {},
35 currentView = null,
36 built = false;
37
38 // DOM elements etc.
39 var $mast;
40
41
42 // various functions..................
43
44 // throw an error
45 function throwError(msg) {
46 // todo: maybe add tracing later
47 throw new Error(msg);
48 }
49
50 // define all the public api functions...
51 publicApi = {
52 printTime: function () {
53 console.log("the time is " + new Date());
54 },
55
56 addView: function (vid, cb) {
57 views[vid] = {
58 vid: vid,
59 cb: cb
60 };
61 // TODO: proper registration of views
62 // for now, make the one (and only) view current..
63 currentView = views[vid];
64 }
65 };
66
67 // function to be called from index.html to build the ONOS UI
68 function buildOnosUi() {
69 tsB = new Date().getTime();
70 tsI = tsB - tsI; // initialization duration
71
72 console.log('ONOS UI initialized in ' + tsI + 'ms');
73
74 if (built) {
75 throwError("ONOS UI already built!");
76 }
77 built = true;
78
79 // TODO: invoke hash navigation
80 // --- report build errors ---
81
82 // for now, invoke the one and only load function:
83
84 currentView.cb.load();
85 }
86
87
88 // export the api and build-UI function
89 return {
90 api: publicApi,
91 buildUi: buildOnosUi
92 };
93 };
94
95}(jQuery));