blob: a5b59d09d4f08c279533c96dcf975d476848ee19 [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) {
49 $scope.available = bundle;
50 }
51 });
52 },
53 // error
54 function () {
55 $log.error('Problem with resource', resource);
56 });
57 };
58
59 getData();
60
61 $scope.changeBundle = function (id) {
62 getData(id);
63 };
64
65 $scope.showBundles = function () {
66 $scope.show = !$scope.show;
67 };
68
69 $log.debug('Cord Bundle Ctrl has been created.');
70 }])
71
72 .directive('bundleAvailable', [function () {
73 return {
74 templateUrl: 'app/view/bundle/available.html'
75 };
76 }]);
77}());