blob: 60dea84b3fbb9e747e400388db7c24e45bb73352 [file] [log] [blame]
Matteo Scandolo5d568612016-01-26 11:02:16 -08001/*
2 * Copyright 2015 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(function () {
18 'use strict';
19
20 var urlSuffix = '/rs/bundle';
21
22 var basic = 'basic',
23 family = 'family';
24
25 angular.module('cordBundle', [])
26 .controller('CordBundleCtrl', ['$log', '$scope', '$resource',
27 function ($log, $scope, $resource) {
28 var BundleData, resource,
29 getData;
30 $scope.page.curr = 'bundle';
31 $scope.show = false;
32
33 getData = function (id) {
34 if (!id) { id = ''; }
35
36 BundleData = $resource($scope.shared.url + urlSuffix + '/' + id);
37 resource = BundleData.get({},
38 // success
39 function () {
40 var current, availId;
41 current = resource.bundle.id;
42 $scope.name = resource.bundle.name;
43 $scope.desc = resource.bundle.desc;
44 $scope.funcs = resource.bundle.functions;
45
46 availId = (current === basic) ? family : basic;
47 resource.bundles.forEach(function (bundle) {
48 if (bundle.id === availId) {
Matteo Scandolo2b545462016-01-26 15:17:10 -080049 // NOTE available should be an array
Matteo Scandolo5d568612016-01-26 11:02:16 -080050 $scope.available = bundle;
51 }
52 });
53 },
54 // error
55 function () {
56 $log.error('Problem with resource', resource);
57 });
58 };
59
60 getData();
61
62 $scope.changeBundle = function (id) {
63 getData(id);
64 };
65
66 $scope.showBundles = function () {
67 $scope.show = !$scope.show;
68 };
69
70 $log.debug('Cord Bundle Ctrl has been created.');
71 }])
72
73 .directive('bundleAvailable', [function () {
74 return {
75 templateUrl: 'app/view/bundle/available.html'
76 };
77 }]);
78}());