blob: fa95025c71bec257fd0a556150078f6a1d59c895 [file] [log] [blame]
Matteo Scandolod2044a42017-08-07 16:08:28 -07001
2/*
3 * Copyright 2017-present Open Networking Foundation
4
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8
9 * http://www.apache.org/licenses/LICENSE-2.0
10
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
Matteo Scandoloe6393f02016-05-23 14:27:52 -070019/**
20 * © OpenCORD
21 *
22 * Visit http://guide.xosproject.org/devguide/addview/ for more information
23 *
24 * Created by teone on 7/18/16.
25 */
26
27(function () {
28 'use strict';
29
30 angular.module('xos.uiComponents')
31 .directive('xosSidePanel', function(){
32 return {
33 restrict: 'E',
34 scope: {
35 config: '=',
36 show: '='
37 },
38 template: `
39 <div class="xos-side-panel-content {{vm.classes.join(' ')}}">
40 <div class="row">
41 <div class="col-xs-12">
42 <button type="button" class="close" ng-click="vm.dismiss()">
43 <span aria-hidden="true">&times;</span>
44 </button>
45 </div>
46 </div>
47 <div class="row">
48 <div class="col-xs-12" ng-transclude></div>
49 </div>
50 </div>
51 `,
52 transclude: true,
53 bindToController: true,
54 controllerAs: 'vm',
55 controller: function($scope, $timeout, _){
56 console.log(this.show);
57
58 this.classes = [];
59
60 this.classes.push(this.config.position);
61
62 this.dismiss = () => {
63 this.show = false;
64 this.classes = this.toggleClass(this.classes);
65 $timeout(() => {
66 return _.remove(this.classes, c => c === 'out');
67 }, 500);
68 };
69
70 this.toggleClass = (classes) => {
71 if(classes.indexOf('in') > -1){
72 _.remove(this.classes, c => c === 'in');
73 this.classes.push('out');
74 return classes;
75 }
76 _.remove(this.classes, c => c === 'out');
77 this.classes.push('in');
78 return classes;
79 };
80
81 $scope.$watch(() => this.show, val => {
82 if (angular.isDefined(val)){
83 if (val && val === true){
84 this.classes = this.toggleClass(this.classes);
85 }
86 }
87 })
88 }
89 }
90 });
91})();
92