blob: 4421ee784828f4f9f3f67e8168c6bb38000697f5 [file] [log] [blame]
Matteo Scandoloe6393f02016-05-23 14:27:52 -07001/**
2 * © OpenCORD
3 *
4 * Visit http://guide.xosproject.org/devguide/addview/ for more information
5 *
6 * Created by teone on 7/18/16.
7 */
8
9(function () {
10 'use strict';
11
12 angular.module('xos.uiComponents')
13 .directive('xosSidePanel', function(){
14 return {
15 restrict: 'E',
16 scope: {
17 config: '=',
18 show: '='
19 },
20 template: `
21 <div class="xos-side-panel-content {{vm.classes.join(' ')}}">
22 <div class="row">
23 <div class="col-xs-12">
24 <button type="button" class="close" ng-click="vm.dismiss()">
25 <span aria-hidden="true">&times;</span>
26 </button>
27 </div>
28 </div>
29 <div class="row">
30 <div class="col-xs-12" ng-transclude></div>
31 </div>
32 </div>
33 `,
34 transclude: true,
35 bindToController: true,
36 controllerAs: 'vm',
37 controller: function($scope, $timeout, _){
38 console.log(this.show);
39
40 this.classes = [];
41
42 this.classes.push(this.config.position);
43
44 this.dismiss = () => {
45 this.show = false;
46 this.classes = this.toggleClass(this.classes);
47 $timeout(() => {
48 return _.remove(this.classes, c => c === 'out');
49 }, 500);
50 };
51
52 this.toggleClass = (classes) => {
53 if(classes.indexOf('in') > -1){
54 _.remove(this.classes, c => c === 'in');
55 this.classes.push('out');
56 return classes;
57 }
58 _.remove(this.classes, c => c === 'out');
59 this.classes.push('in');
60 return classes;
61 };
62
63 $scope.$watch(() => this.show, val => {
64 if (angular.isDefined(val)){
65 if (val && val === true){
66 this.classes = this.toggleClass(this.classes);
67 }
68 }
69 })
70 }
71 }
72 });
73})();
74