Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 1 | /* |
| 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 Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 20 | var $log, $resource; |
| 21 | |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 22 | var url = 'http://localhost:8080/rs/bundle'; |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 23 | |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 24 | var basic = 'basic', |
| 25 | family = 'family', |
| 26 | current, |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame^] | 27 | bundleScope, |
| 28 | avScope, |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 29 | avCb; |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 30 | |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame^] | 31 | 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 Cole | 8db1640 | 2015-05-18 13:50:31 -0700 | [diff] [blame] | 39 | angular.module('cordBundle', []) |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame^] | 40 | .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 Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 64 | .controller('CordBundleCtrl', ['$log', '$scope', '$resource', |
| 65 | function (_$log_, $scope, _$resource_) { |
| 66 | var BundleData, resource; |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 67 | $scope.page = 'bundle'; |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame^] | 68 | bundleScope = $scope; |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 69 | $log = _$log_; |
| 70 | $resource = _$resource_; |
| 71 | |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 72 | BundleData = $resource(url); |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 73 | resource = BundleData.get({}, |
| 74 | // success |
| 75 | function () { |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame^] | 76 | setInfo(resource, $scope); |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 77 | }, |
| 78 | // error |
| 79 | function () { |
| 80 | $log.error('Problem with resource', resource); |
| 81 | }); |
Bri Prebilic Cole | 3c3361c | 2015-05-19 12:07:29 -0700 | [diff] [blame] | 82 | |
| 83 | $log.debug('Cord Bundle Ctrl has been created.'); |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 84 | }]) |
Bri Prebilic Cole | 8db1640 | 2015-05-18 13:50:31 -0700 | [diff] [blame] | 85 | |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 86 | .controller('CordAvailable', ['$scope', |
| 87 | function ($scope) { |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame^] | 88 | avScope = $scope; |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 89 | 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 Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 99 | |
| 100 | $log.debug('Cord Available Ctrl has been created.'); |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame^] | 101 | }]); |
Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 102 | }()); |