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 | d189e28 | 2015-06-05 10:00:22 -0700 | [diff] [blame] | 20 | var urlSuffix = '/rs/bundle'; |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 21 | |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 22 | var basic = 'basic', |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 23 | family = 'family'; |
Bri Prebilic Cole | d050a4b | 2015-05-27 15:53:30 -0700 | [diff] [blame] | 24 | |
Bri Prebilic Cole | 8db1640 | 2015-05-18 13:50:31 -0700 | [diff] [blame] | 25 | angular.module('cordBundle', []) |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 26 | .controller('CordBundleCtrl', ['$log', '$scope', '$resource', |
| 27 | function ($log, $scope, $resource) { |
| 28 | var BundleData, resource, |
| 29 | getData; |
Bri Prebilic Cole | 60553c8 | 2015-06-05 08:50:17 -0700 | [diff] [blame] | 30 | $scope.page.curr = 'bundle'; |
Bri Prebilic Cole | 0e371dc | 2015-06-05 16:47:21 -0700 | [diff] [blame] | 31 | $scope.show = false; |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 32 | |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 33 | getData = function (id) { |
| 34 | if (!id) { id = ''; } |
| 35 | |
Bri Prebilic Cole | d189e28 | 2015-06-05 10:00:22 -0700 | [diff] [blame] | 36 | BundleData = $resource($scope.shared.url + urlSuffix + '/' + id); |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 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 | }); |
Bri Prebilic Cole | f3eba31 | 2015-05-21 16:35:06 -0700 | [diff] [blame] | 57 | }; |
Bri Prebilic Cole | 10570eb | 2015-05-20 16:23:52 -0700 | [diff] [blame] | 58 | |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 59 | getData(); |
Bri Prebilic Cole | d050a4b | 2015-05-27 15:53:30 -0700 | [diff] [blame] | 60 | |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 61 | $scope.changeBundle = function (id) { |
| 62 | getData(id); |
| 63 | }; |
Bri Prebilic Cole | d050a4b | 2015-05-27 15:53:30 -0700 | [diff] [blame] | 64 | |
Bri Prebilic Cole | 0e371dc | 2015-06-05 16:47:21 -0700 | [diff] [blame] | 65 | $scope.showBundles = function () { |
| 66 | $scope.show = !$scope.show; |
| 67 | }; |
| 68 | |
Bri Prebilic Cole | d050a4b | 2015-05-27 15:53:30 -0700 | [diff] [blame] | 69 | $log.debug('Cord Bundle Ctrl has been created.'); |
| 70 | }]) |
| 71 | |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 72 | .directive('bundleAvailable', [function () { |
Bri Prebilic Cole | d050a4b | 2015-05-27 15:53:30 -0700 | [diff] [blame] | 73 | return { |
Bri Prebilic Cole | d3d7a32 | 2015-05-28 14:15:14 -0700 | [diff] [blame] | 74 | templateUrl: 'app/view/bundle/available.html' |
Bri Prebilic Cole | d050a4b | 2015-05-27 15:53:30 -0700 | [diff] [blame] | 75 | }; |
Bri Prebilic Cole | bdd6b3b | 2015-05-22 15:44:18 -0700 | [diff] [blame] | 76 | }]); |
Bri Prebilic Cole | e031189 | 2015-05-15 11:27:15 -0700 | [diff] [blame] | 77 | }()); |