blob: 987c70a72de45e963caf63f1494a03cc158c8040 [file] [log] [blame]
Bri Prebilic Colee0311892015-05-15 11:27:15 -07001/*
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
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070020 var $log, $resource;
21
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070022 var url = 'http://localhost:8080/rs/bundle';
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070023
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070024 var basic = 'basic',
25 family = 'family',
26 current,
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -070027 bundleScope,
28 avScope,
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070029 avCb;
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070030
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -070031 function setInfo(resource, scope) {
32 current = resource.bundle.id;
33 scope.name = resource.bundle.name;
34 scope.desc = resource.bundle.desc;
35 scope.funcs = resource.bundle.functions;
36 avCb(resource);
37 }
38
Bri Prebilic Cole8db16402015-05-18 13:50:31 -070039 angular.module('cordBundle', [])
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -070040 .directive('bundleAvailable', ['$resource', function ($resource) {
41 return {
42 templateUrl: 'app/view/bundle/available.html',
43 link: function (scope, elem) {
44 var button = $(elem).find('button'),
45 ApplyData, resource;
46
47 button.click(function () {
48 ApplyData = $resource(url + '/' + avScope.available.id);
49 resource = ApplyData.get({},
50 // success
51 function () {
52 setInfo(resource, bundleScope);
53 },
54 // error
55 function () {
56 $log.error('Problem with resource', resource);
57 }
58 );
59 });
60 }
61 };
62 }])
63
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070064 .controller('CordBundleCtrl', ['$log', '$scope', '$resource',
65 function (_$log_, $scope, _$resource_) {
66 var BundleData, resource;
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070067 $scope.page = 'bundle';
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -070068 bundleScope = $scope;
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070069 $log = _$log_;
70 $resource = _$resource_;
71
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070072 BundleData = $resource(url);
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070073 resource = BundleData.get({},
74 // success
75 function () {
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -070076 setInfo(resource, $scope);
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070077 },
78 // error
79 function () {
80 $log.error('Problem with resource', resource);
81 });
Bri Prebilic Cole3c3361c2015-05-19 12:07:29 -070082
83 $log.debug('Cord Bundle Ctrl has been created.');
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070084 }])
Bri Prebilic Cole8db16402015-05-18 13:50:31 -070085
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070086 .controller('CordAvailable', ['$scope',
87 function ($scope) {
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -070088 avScope = $scope;
Bri Prebilic Colef3eba312015-05-21 16:35:06 -070089 avCb = function (resource) {
90 $scope.id = (current === basic) ? family : basic;
91 $scope.bundles = resource.bundles;
92
93 $scope.bundles.forEach(function (bundle) {
94 if (bundle.id === $scope.id) {
95 $scope.available = bundle;
96 }
97 });
98 };
Bri Prebilic Cole10570eb2015-05-20 16:23:52 -070099
100 $log.debug('Cord Available Ctrl has been created.');
Bri Prebilic Colebdd6b3b2015-05-22 15:44:18 -0700101 }]);
Bri Prebilic Colee0311892015-05-15 11:27:15 -0700102}());