· 10 years ago · Jul 07, 2016, 10:45 AM
1(function () {
2 'use strict';
3
4 angular.module ( 'angle' , [
5 'app.core' ,
6 'app.routes' ,
7 'app.sidebar' ,
8 'app.navsearch' ,
9 'app.preloader' ,
10 'app.loadingbar' ,
11 'app.elements' ,
12 'app.extras' ,
13 'app.translate' ,
14 'app.settings' ,
15 'app.utils' ,
16 'app.schedule' ,
17 'satellizer' ,
18 // 'btford.socket-io',
19 // 'angular.filter',
20 ] )
21
22 //Loading Icon Interceptor
23 .config ( function ( $httpProvider ) {
24
25 $httpProvider.interceptors.push ( function ( $q , $rootScope ) {
26 return {
27 'request': function ( config ) {
28 config.timeout = http_timeout;
29 $rootScope.$broadcast ( 'loading-started' );
30 return config || $q.when ( config );
31 } ,
32 'response': function ( response ) {
33 $rootScope.$broadcast ( 'loading-complete' );
34 return response || $q.when ( response );
35 } ,
36 'responseError': function ( rejection ) {
37 if ( rejection.status === - 1 ) {
38 //Request timeput
39 if ( env == 'development' || env == 'beta' ) alert ( 'Request timedout. Please, try again later.' );
40 } else {
41 if ( env == 'development' || env == 'beta' ) alert ( print_r ( rejection.data ) );
42 }
43 $rootScope.$broadcast ( 'loading-complete' );
44 if (response != undefined)
45 return response || $q.when ( response );
46
47 }
48 };
49 } );
50
51 } )
52
53 //Loading Icon Interceptor (Icon Processor)
54 //There is already one loading icon.
55 //This is addition to the Malaeb icon loading. It pops up in between.
56 /*
57 .directive("loadingIndicator", function() {
58 return {
59 restrict : "A",
60 template: "<div class='loading-overlap'><span>Loading...</span></div>",
61 link : function(scope, element, attrs) {
62 scope.$on("loading-started", function(e) {
63 element.css({"display" : "block", "z-index": "9999", "position": "fixed"});
64 });
65
66 scope.$on("loading-complete", function(e) {
67 element.css({"display" : "none", "z-index": "0", "position": "fixed"});
68 });
69
70 }
71 };
72 })
73 */
74
75
76 .directive ( 'restrictInput' , [ function () {
77
78 return {
79
80 restrict: 'A' ,
81 require: '?ngModel' ,
82 link: function ( scope , element , attrs , ngModel ) {
83 var digits;
84 var old_digits = '';
85 if ( ! ngModel ) return;
86 ngModel.$parsers.unshift ( function ( inputValue ) {
87
88 var regex = RegExp ( attrs.restrictInput );
89 var value = inputValue;
90
91 if ( regex.test ( value ) ) {
92 digits = value;
93 old_digits = digits;
94 } else {
95 digits = old_digits; //we need old val
96 }
97
98 ngModel.$setViewValue = digits;
99 ngModel.$render ();
100 return digits;
101
102 } );
103
104 }
105 }
106
107 } ] )
108
109 .directive ( 'validInput' , function () {
110 return {
111 require: '?ngModel' ,
112 scope: {
113 "inputPattern": '@'
114 } ,
115 link: function ( scope , element , attrs , ngModelCtrl ) {
116
117 var regexp = null;
118
119 if ( scope.inputPattern !== undefined ) {
120 regexp = new RegExp ( scope.inputPattern , "g" );
121 }
122
123 if ( ! ngModelCtrl ) {
124 return;
125 }
126
127 ngModelCtrl.$parsers.push ( function ( val ) {
128
129 if ( regexp ) {
130 var clean = val.replace ( regexp , '' );
131
132 if ( val !== clean ) {
133 ngModelCtrl.$setViewValue ( clean );
134 ngModelCtrl.$render ();
135 }
136
137 return clean;
138 } else {
139 return val;
140 }
141
142 } );
143
144 element.bind ( 'keypress' , function ( event ) {
145 if ( event.keyCode === 32 ) {
146 event.preventDefault ();
147 }
148 } );
149
150 }
151 };
152 } )
153
154 .directive ( 'awLimitLength' , function () {
155 return {
156 restrict: "A" ,
157 require: 'ngModel' ,
158 link: function ( scope , element , attrs , ngModel ) {
159 attrs.$set ( "ngTrim" , "false" );
160 var limitLength = parseInt ( attrs.awLimitLength , 10 );// console.log(attrs);
161 scope.$watch ( attrs.ngModel , function ( newValue ) {
162 if (ngModel.$viewValue) {
163 if ( ngModel.$viewValue.length > limitLength ) {
164 ngModel.$setViewValue ( ngModel.$viewValue.substring ( 0 , limitLength ) );
165 ngModel.$render ();
166 }
167 }
168 } );
169 }
170 };
171 } );
172
173}) ();
174
175
176(function () {
177 'use strict';
178
179 angular
180 .module ( 'app.colors' , [] );
181}) ();
182(function () {
183 'use strict';
184
185 angular
186 .module ( 'app.elements' , [] );
187}) ();
188(function () {
189 'use strict';
190
191 angular
192 .module ( 'app.extras' , [] );
193}) ();
194(function () {
195 'use strict';
196
197 angular
198 .module ( 'app.schedule' , [] );
199}) ();
200
201(function () {
202 'use strict';
203
204 angular
205 .module ( 'app.core' , [
206 'ngRoute' ,
207 'ngAnimate' ,
208 'ngStorage' ,
209 'ngCookies' ,
210 'pascalprecht.translate' ,
211 'ui.bootstrap' ,
212 'ui.router' ,
213 'oc.lazyLoad' ,
214 'cfp.loadingBar' ,
215 'ngSanitize' ,
216 'ngResource' ,
217 'ui.utils' ,
218 'satellizer' ,
219
220 // 'btford.socket-io',
221 // 'angular.filter'
222 ] );
223}) ();
224(function () {
225 'use strict';
226
227 angular
228 .module ( 'app.lazyload' , [] );
229}) ();
230(function () {
231 'use strict';
232
233 angular
234 .module ( 'app.loadingbar' , [] );
235}) ();
236(function () {
237 'use strict';
238
239 angular
240 .module ( 'app.navsearch' , [] );
241}) ();
242(function () {
243 'use strict';
244
245 angular
246 .module ( 'app.preloader' , [] );
247}) ();
248
249
250(function () {
251 'use strict';
252
253 angular
254 .module ( 'app.routes' , [
255 'app.lazyload'
256 ] );
257}) ();
258(function () {
259 'use strict';
260
261 angular
262 .module ( 'app.settings' , [] );
263}) ();
264(function () {
265 'use strict';
266
267 angular
268 .module ( 'app.sidebar' , [] );
269}) ();
270(function () {
271 'use strict';
272
273 angular
274 .module ( 'app.translate' , [] );
275}) ();
276(function () {
277 'use strict';
278
279 angular
280 .module ( 'app.utils' , [
281 'app.colors'
282 ] );
283}) ();
284
285(function () {
286 'use strict';
287
288 angular
289 .module ( 'app.colors' )
290 .constant ( 'APP_COLORS' , {
291 'primary': '#5d9cec' ,
292 'success': '#27c24c' ,
293 'info': '#23b7e5' ,
294 'warning': '#ff902b' ,
295 'danger': '#f05050' ,
296 'inverse': '#131e26' ,
297 'green': '#37bc9b' ,
298 'pink': '#f532e5' ,
299 'purple': '#7266ba' ,
300 'dark': '#3a3f51' ,
301 'yellow': '#fad732' ,
302 'gray-darker': '#232735' ,
303 'gray-dark': '#3a3f51' ,
304 'gray': '#dde6e9' ,
305 'gray-light': '#e4eaec' ,
306 'gray-lighter': '#edf1f2'
307 } )
308 ;
309}) ();
310/**=========================================================
311 * Module: colors.js
312 * Services to retrieve global colors
313 =========================================================*/
314
315(function () {
316 'use strict';
317
318 angular
319 .module ( 'app.colors' )
320 .service ( 'Colors' , Colors );
321
322 Colors.$inject = [ 'APP_COLORS' ];
323 function Colors ( APP_COLORS ) {
324 this.byName = byName;
325
326 ////////////////
327
328 function byName ( name ) {
329 return (APP_COLORS[ name ] || '#fff');
330 }
331 }
332
333}) ();
334
335(function () {
336 'use strict';
337
338 angular
339 .module ( 'app.core' )
340 .config ( coreConfig );
341
342 coreConfig.$inject = [ '$controllerProvider' , '$compileProvider' , '$filterProvider' , '$provide' , '$animateProvider' , '$authProvider' ];
343 function coreConfig ( $controllerProvider , $compileProvider , $filterProvider , $provide , $animateProvider , $authProvider ) {
344
345 var core = angular.module ( 'app.core' );
346 // registering components after bootstrap
347 core.controller = $controllerProvider.register;
348 core.directive = $compileProvider.directive;
349 core.filter = $filterProvider.register;
350 core.factory = $provide.factory;
351 core.service = $provide.service;
352 core.constant = $provide.constant;
353 core.value = $provide.value;
354
355 $authProvider.loginUrl = API_URL + 'api/v1/authenticate';
356 // Disables animation on items with class .ng-no-animation
357 $animateProvider.classNameFilter ( /^((?!(ng-no-animation)).)*$/ );
358
359 }
360
361}) ();
362/**=========================================================
363 * Module: constants.js
364 * Define constants to inject across the application
365 =========================================================*/
366
367(function () {
368 'use strict';
369
370 angular
371 .module ( 'app.core' )
372 .constant ( 'APP_MEDIAQUERY' , {
373 'desktopLG': 1200 ,
374 'desktop': 992 ,
375 'tablet': 768 ,
376 'mobile': 480
377 } )
378 ;
379
380}) ();
381(function () {
382 'use strict';
383
384 angular
385 .module ( 'app.core' )
386 .run ( appRun );
387
388 appRun.$inject = [ '$rootScope' , '$state' , '$stateParams' , '$window' , '$templateCache' , 'Colors' , '$auth' , '$http' ];
389
390 function appRun ( $rootScope , $state , $stateParams , $window , $templateCache , Colors , $auth , $http ) {
391
392 // Set reference to access them from any scope
393 $rootScope.$state = $state;
394 $rootScope.$stateParams = $stateParams;
395 $rootScope.$storage = $window.localStorage;
396
397 $rootScope.logout = function () {
398
399 $auth.logout ();
400 $state.go ( 'login' );
401 };
402
403 // Uncomment this to disable template cache
404 if ( cache_templates == false ) {
405 $rootScope.$on ( '$stateChangeStart' , function ( event , toState , toParams , fromState , fromParams ) {
406 if ( typeof(toState) !== 'undefined' ) {
407 $templateCache.remove ( toState.templateUrl );
408 }
409 } );
410 }
411
412 // Allows to use branding color with interpolation
413 // {{ colorByName('primary') }}
414 $rootScope.colorByName = Colors.byName;
415
416 // cancel click event easily
417 $rootScope.cancel = function ( $event ) {
418 $event.stopPropagation ();
419 };
420
421 // Hooks Example
422 // -----------------------------------
423
424 // Hook not found
425 $rootScope.$on ( '$stateNotFound' ,
426 function ( event , unfoundState/*, fromState, fromParams*/ ) {
427 console.log ( unfoundState.to ); // "lazy.state"
428 console.log ( unfoundState.toParams ); // {a:1, b:2}
429 console.log ( unfoundState.options ); // {inherit:false} + default options
430 } );
431 // Hook error
432 $rootScope.$on ( '$stateChangeError' ,
433 function ( event , toState , toParams , fromState , fromParams , error ) {
434 //console.log ( error );
435 } );
436 // Hook success
437 $rootScope.$on ( '$stateChangeSuccess' ,
438 function ( /*event, toState, toParams, fromState, fromParams*/ ) {
439 // display new view from top
440 $window.scrollTo ( 0 , 0 );
441 // Save the route title
442 $rootScope.currTitle = $state.current.title;
443 } );
444
445 // Load a title dynamically
446 $rootScope.currTitle = $state.current.title;
447 $rootScope.pageTitle = function () {
448 /*var title = $rootScope.app.name + ' - ' + ($rootScope.currTitle || $rootScope.app.description);*/
449 var title = 'Malaeb Dashboard';
450 document.title = title;
451 return title;
452 };
453 if ( $auth.isAuthenticated () ) {
454
455
456 $http.get ( API_URL + 'api/v1/authenticate/user' )
457 .success ( function ( response ) {
458 // Stringify the retured data
459 var user = JSON.stringify ( response.user );
460
461 // Set the stringified user data into local storage
462 localStorage.setItem ( 'user' , user );
463
464 // Getting current user data from local storage
465 $rootScope.currentUser = response.user;
466 //console.log($rootScope.currentUser.roles[0].name);
467 // $rootScope.currentUser = localStorage.setItem('user');;
468 if ( typeof( $rootScope.currentUser.stadiums ) === 'undefined' || $rootScope.currentUser.stadiums.length == 0 ) {
469 $rootScope.currentUser.stadiums = [ {} ];
470 $rootScope.currentUser.stadiums[ 0 ].pitches = [ {} ];
471 $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id = 0;
472 }
473 //console.log ( $rootScope.currentUser );
474 $state.go ( 'app.schedule' );
475 } )
476 .error ( function () {
477 console.log ( $rootScope.loginErrorText );
478 } );
479 } else {
480 $state.go ( 'login' );
481 }
482
483 }
484
485}) ();
486
487
488(function () {
489 'use strict';
490
491 angular
492 .module ( 'app.lazyload' )
493 .config ( lazyloadConfig );
494
495 lazyloadConfig.$inject = [ '$ocLazyLoadProvider' , 'APP_REQUIRES' ];
496 function lazyloadConfig ( $ocLazyLoadProvider , APP_REQUIRES ) {
497
498 // Lazy Load modules configuration
499 $ocLazyLoadProvider.config ( {
500 debug: false ,
501 events: true ,
502 modules: APP_REQUIRES.modules
503 } );
504
505 }
506}) ();
507(function () {
508 'use strict';
509
510 angular
511 .module ( 'app.lazyload' )
512 .constant ( 'APP_REQUIRES' , {
513 // jQuery based and standalone scripts
514 scripts: {
515 'modernizr': [
516 'vendor/modernizr/modernizr.custom.js'
517 ] ,
518 'icons': [
519 'vendor/fontawesome/css/font-awesome.min.css' ,
520 'vendor/simple-line-icons/css/simple-line-icons.css'
521 ] ,
522 'moment': [
523 'vendor/moment/min/moment-with-locales.min.js'
524 ] ,
525 'jquery-ui': [
526 'vendor/jquery-ui/ui/core.js' ,
527 'vendor/jquery-ui/ui/widget.js'
528 ] ,
529 // loads only jquery required modules and touch support
530 'jquery-ui-widgets': [ 'vendor/jquery-ui/ui/core.js' ,
531 'vendor/jquery-ui/ui/widget.js' ,
532 'vendor/jquery-ui/ui/mouse.js' ,
533 'vendor/jquery-ui/ui/draggable.js' ,
534 'vendor/jquery-ui/ui/droppable.js' ,
535 'vendor/jquery-ui/ui/sortable.js' ,
536 'vendor/jqueryui-touch-punch/jquery.ui.touch-punch.min.js' ] ,
537 // 'inputmask': ['vendor/jquery.inputmask/dist/jquery.inputmask.bundle.js'],
538 // 'flatdoc': ['vendor/flatdoc/flatdoc.js'],
539 // 'codemirror': ['vendor/codemirror/lib/codemirror.js',
540 // 'vendor/codemirror/lib/codemirror.css'],
541 // // modes for common web files
542 // 'codemirror-modes-web': ['vendor/codemirror/mode/javascript/javascript.js',
543 // 'vendor/codemirror/mode/xml/xml.js',
544 // 'vendor/codemirror/mode/htmlmixed/htmlmixed.js',
545 // 'vendor/codemirror/mode/css/css.js'],
546 // 'taginput' : ['vendor/bootstrap-tagsinput/dist/bootstrap-tagsinput.css',
547 // 'vendor/bootstrap-tagsinput/dist/bootstrap-tagsinput.min.js'],
548 // 'filestyle': ['vendor/bootstrap-filestyle/src/bootstrap-filestyle.js'],
549 // 'parsley': ['vendor/parsleyjs/dist/parsley.min.js'],
550 'fullcalendar': [
551 'vendor/fullcalendar/dist/fullcalendar.min.js' ,
552 'vendor/fullcalendar/dist/fullcalendar.css'
553 ] ,
554 'gcal': [
555 'vendor/fullcalendar/dist/gcal.js'
556 ] ,
557 'ui.calendar': [
558 'vendor/angular-ui-calendar/calendar.js'
559 ] ,
560 'angular.filter': [
561 'vendor/angular-filter/angular-filter.js'
562 ] ,
563 'btford.socket-io': [
564 'vendor/angular-socket-io/socket.js'
565 ] ,
566
567
568 } ,
569 // Angular based script (use the right module name)
570 modules: [
571 // {name: 'toaster', files: ['vendor/angularjs-toaster/toaster.js', 'vendor/angularjs-toaster/toaster.css']}
572 {
573 name: 'ngDialog' ,
574 files: [
575 'vendor/ngDialog/js/ngDialog.min.js' ,
576 'vendor/ngDialog/css/ngDialog.min.css' ,
577 'vendor/ngDialog/css/ngDialog-theme-default.min.css' ,
578 'app/css/ngDialog.custom.css'
579 ]
580 }
581 // {name: 'angular.filter', files: ['vendor/angular-filter/angular-filter.js']},
582 ]
583 } );
584
585}) ();
586
587(function () {
588 'use strict';
589
590 angular
591 .module ( 'app.loadingbar' )
592 .config ( loadingbarConfig )
593 ;
594 loadingbarConfig.$inject = [ 'cfpLoadingBarProvider' ];
595 function loadingbarConfig ( cfpLoadingBarProvider ) {
596 cfpLoadingBarProvider.includeBar = true;
597 cfpLoadingBarProvider.includeSpinner = false;
598 cfpLoadingBarProvider.latencyThreshold = 500;
599 cfpLoadingBarProvider.parentSelector = '.wrapper > section';
600 }
601}) ();
602(function () {
603 'use strict';
604
605 angular
606 .module ( 'app.loadingbar' )
607 .run ( loadingbarRun )
608 ;
609 loadingbarRun.$inject = [ '$rootScope' , '$timeout' , 'cfpLoadingBar' ];
610 function loadingbarRun ( $rootScope , $timeout , cfpLoadingBar ) {
611
612 // Loading bar transition
613 // -----------------------------------
614 var thBar;
615 $rootScope.$on ( '$stateChangeStart' , function () {
616 if ( $ ( '.wrapper > section' ).length ) // check if bar container exists
617 thBar = $timeout ( function () {
618 cfpLoadingBar.start ();
619 } , 0 ); // sets a latency Threshold
620 } );
621 $rootScope.$on ( '$stateChangeSuccess' , function ( event ) {
622 event.targetScope.$watch ( '$viewContentLoaded' , function () {
623 $timeout.cancel ( thBar );
624 cfpLoadingBar.complete ();
625 } );
626 } );
627
628 }
629
630}) ();
631/**=========================================================
632 * Module: navbar-search.js
633 * Navbar search toggler * Auto dismiss on ESC key
634 =========================================================*/
635
636(function () {
637 'use strict';
638
639 angular
640 .module ( 'app.navsearch' )
641 .directive ( 'searchOpen' , searchOpen )
642 .directive ( 'searchDismiss' , searchDismiss );
643
644 //
645 // directives definition
646 //
647
648 function searchOpen () {
649 var directive = {
650 controller: searchOpenController ,
651 restrict: 'A'
652 };
653 return directive;
654
655 }
656
657 function searchDismiss () {
658 var directive = {
659 controller: searchDismissController ,
660 restrict: 'A'
661 };
662 return directive;
663
664 }
665
666 //
667 // Contrller definition
668 //
669
670 searchOpenController.$inject = [ '$scope' , '$element' , 'NavSearch' ];
671 function searchOpenController ( $scope , $element , NavSearch ) {
672 $element
673 .on ( 'click' , function ( e ) {
674 e.stopPropagation ();
675 } )
676 .on ( 'click' , NavSearch.toggle );
677 }
678
679 searchDismissController.$inject = [ '$scope' , '$element' , 'NavSearch' ];
680 function searchDismissController ( $scope , $element , NavSearch ) {
681
682 var inputSelector = '.navbar-form input[type="text"]';
683
684 $ ( inputSelector )
685 .on ( 'click' , function ( e ) {
686 e.stopPropagation ();
687 } )
688 .on ( 'keyup' , function ( e ) {
689 if ( e.keyCode === 27 ) // ESC
690 NavSearch.dismiss ();
691 } );
692
693 // click anywhere closes the search
694 $ ( document ).on ( 'click' , NavSearch.dismiss );
695 // dismissable options
696 $element
697 .on ( 'click' , function ( e ) {
698 e.stopPropagation ();
699 } )
700 .on ( 'click' , NavSearch.dismiss );
701 }
702
703}) ();
704
705
706/**=========================================================
707 * Module: nav-search.js
708 * Services to share navbar search functions
709 =========================================================*/
710
711(function () {
712 'use strict';
713
714 angular
715 .module ( 'app.navsearch' )
716 .service ( 'NavSearch' , NavSearch );
717
718 function NavSearch () {
719 this.toggle = toggle;
720 this.dismiss = dismiss;
721
722 ////////////////
723
724 var navbarFormSelector = 'form.navbar-form';
725
726 function toggle () {
727 var navbarForm = $ ( navbarFormSelector );
728
729 navbarForm.toggleClass ( 'open' );
730
731 var isOpen = navbarForm.hasClass ( 'open' );
732
733 navbarForm.find ( 'input' )[ isOpen ? 'focus' : 'blur' ] ();
734 }
735
736 function dismiss () {
737 $ ( navbarFormSelector )
738 .removeClass ( 'open' ) // Close control
739 .find ( 'input[type="text"]' ).blur () // remove focus
740 .val ( '' ) // Empty input
741 ;
742 }
743 }
744}) ();
745
746(function () {
747 'use strict';
748
749 angular
750 .module ( 'app.preloader' )
751 .directive ( 'preloader' , preloader );
752
753 preloader.$inject = [ '$animate' , '$timeout' , '$q' ];
754 function preloader ( $animate , $timeout , $q ) {
755
756 var directive = {
757 restrict: 'EAC' ,
758 template: '<div class="preloader-progress">' +
759 '<div class="preloader-progress-bar" ' +
760 'ng-style="{width: loadCounter + \'%\'}"></div>' +
761 '</div>'
762 ,
763 link: link
764 };
765 return directive;
766
767 ///////
768
769 function link ( scope , el ) {
770
771 scope.loadCounter = 0;
772
773 var counter = 0 ,
774 timeout;
775
776 // disables scrollbar
777 angular.element ( 'body' ).css ( 'overflow' , 'hidden' );
778 // ensure class is present for styling
779 el.addClass ( 'preloader' );
780
781 appReady ().then ( endCounter );
782
783 timeout = $timeout ( startCounter );
784
785 ///////
786
787 function startCounter () {
788
789 var remaining = 100 - counter;
790 counter = counter + (0.015 * Math.pow ( 1 - Math.sqrt ( remaining ) , 2 ));
791
792 scope.loadCounter = parseInt ( counter , 10 );
793
794 timeout = $timeout ( startCounter , 20 );
795 }
796
797 function endCounter () {
798
799 $timeout.cancel ( timeout );
800
801 scope.loadCounter = 100;
802
803 $timeout ( function () {
804 // animate preloader hiding
805 $animate.addClass ( el , 'preloader-hidden' );
806 // retore scrollbar
807 angular.element ( 'body' ).css ( 'overflow' , '' );
808 } , 300 );
809 }
810
811 function appReady () {
812 var deferred = $q.defer ();
813 var viewsLoaded = 0;
814 // if this doesn't sync with the real app ready
815 // a custom event must be used instead
816 var off = scope.$on ( '$viewContentLoaded' , function () {
817 viewsLoaded ++;
818 // we know there are at least two views to be loaded
819 // before the app is ready (1-index.html 2-app*.html)
820 if ( viewsLoaded === 2 ) {
821 // with resolve this fires only once
822 $timeout ( function () {
823 deferred.resolve ();
824 } , 3000 );
825
826 off ();
827 }
828
829 } );
830
831 return deferred.promise;
832 }
833
834 } //link
835 }
836
837}) ();
838/**=========================================================
839 * Module: helpers.js
840 * Provides helper functions for routes definition
841 =========================================================*/
842
843(function () {
844 'use strict';
845
846 angular
847 .module ( 'app.routes' )
848 .provider ( 'RouteHelpers' , RouteHelpersProvider )
849 ;
850
851 RouteHelpersProvider.$inject = [ 'APP_REQUIRES' ];
852 function RouteHelpersProvider ( APP_REQUIRES ) {
853
854 /* jshint validthis:true */
855 return {
856 // provider access level
857 basepath: basepath ,
858 resolveFor: resolveFor ,
859 // controller access level
860 $get: function () {
861 return {
862 basepath: basepath ,
863 resolveFor: resolveFor
864 };
865 }
866 };
867
868 // Set here the base of the relative path
869 // for all app views
870 function basepath ( uri ) {
871 return 'app/views/' + uri;
872 }
873
874 // Generates a resolve object by passing script names
875 // previously configured in constant.APP_REQUIRES
876 function resolveFor () {
877 var _args = arguments;
878 return {
879 deps: [ '$ocLazyLoad' , '$q' , function ( $ocLL , $q ) {
880 // Creates a promise chain for each argument
881 var promise = $q.when ( 1 ); // empty promise
882 for ( var i = 0 , len = _args.length ; i < len ; i ++ ) {
883 promise = andThen ( _args[ i ] );
884 }
885 return promise;
886
887 // creates promise to chain dynamically
888 function andThen ( _arg ) {
889 // also support a function that returns a promise
890 if ( typeof _arg === 'function' )
891 return promise.then ( _arg );
892 else
893 return promise.then ( function () {
894 // if is a module, pass the name. If not, pass the array
895 var whatToLoad = getRequired ( _arg );
896 // simple error check
897 if ( ! whatToLoad ) return $.error ( 'Route resolve: Bad resource name [' + _arg + ']' );
898 // finally, return a promise
899 return $ocLL.load ( whatToLoad );
900 } );
901 }
902
903 // check and returns required data
904 // analyze module items with the form [name: '', files: []]
905 // and also simple array of script files (for not angular js)
906 function getRequired ( name ) {
907 if ( APP_REQUIRES.modules )
908 for ( var m in APP_REQUIRES.modules )
909 if ( APP_REQUIRES.modules[ m ].name && APP_REQUIRES.modules[ m ].name === name )
910 return APP_REQUIRES.modules[ m ];
911 return APP_REQUIRES.scripts && APP_REQUIRES.scripts[ name ];
912 }
913
914 } ]
915 };
916 } // resolveFor
917
918 }
919
920
921}) ();
922
923
924/**=========================================================
925 * Module: config.js
926 * App routes and resources configuration
927 =========================================================*/
928
929
930(function () {
931 'use strict';
932
933 angular
934 .module ( 'app.routes' )
935 .config ( routesConfig );
936
937 routesConfig.$inject = [ '$stateProvider' , '$locationProvider' , '$urlRouterProvider' , 'RouteHelpersProvider' ];
938 function routesConfig ( $stateProvider , $locationProvider , $urlRouterProvider , helper ) {
939
940 // Set the following to true to enable the HTML5 Mode
941 // You may have to set <base> tag in index and a routing configuration in your server
942 $locationProvider.html5Mode ( false );
943
944 // defaults to dashboard
945 $urlRouterProvider.otherwise ( '/login' );
946
947 //
948 // Application Routes
949 // -----------------------------------
950 $stateProvider
951 .state ( 'app' , {
952 url: '/app' ,
953 abstract: true ,
954 templateUrl: helper.basepath ( 'app.html' ) ,
955 resolve: helper.resolveFor ( 'modernizr' , 'icons' )
956 } )
957 .state ( 'login' , {
958 url: '/' ,
959 title: 'Login' ,
960 templateUrl: helper.basepath ( 'login.html' ) ,
961 controller: 'AuthController'
962 } )
963 .state ( 'app.singleview' , {
964 url: '/singleview' ,
965 title: 'Single View' ,
966 templateUrl: helper.basepath ( 'singleview.html' )
967 } )
968 .state ( 'app.schedule' , {
969 url: '/schedule/:id' ,
970 title: 'Pitch Schedule' ,
971 controller: 'ScheduleController' ,
972 templateUrl: helper.basepath ( 'schedule.html' ) ,
973 resolve: helper.resolveFor ( 'jquery-ui' , 'jquery-ui-widgets' , 'moment' , 'fullcalendar' , 'ngDialog' , 'ui.calendar' , 'angular.filter' , 'btford.socket-io' )
974 } )
975
976 .state ( 'app.profile' , {
977 url: '/profile' ,
978 title: 'User Profile' ,
979 controller: 'ProfileController' ,
980 templateUrl: helper.basepath ( 'profile.html' ) ,
981 resolve: helper.resolveFor ( 'jquery-ui' , 'jquery-ui-widgets' , 'moment' , 'fullcalendar' , 'ngDialog' , 'ui.calendar' )
982 } )
983 .state ( 'app.submenu' , {
984 url: '/submenu' ,
985 title: 'Submenu' ,
986 templateUrl: helper.basepath ( 'submenu.html' ) ,
987
988 } )
989 .state ( 'app.repeatedBooking' , {
990 url: '/repeatedBooking' ,
991 title: 'repeatedBooking' ,
992 controller: 'repeatedBookingCtrl' ,
993 templateUrl: helper.basepath ( 'repeatedBooking.html' ) ,
994 resolve: helper.resolveFor ( 'jquery-ui' , 'jquery-ui-widgets' , 'moment' , 'fullcalendar' , 'ngDialog' , 'ui.calendar' )
995
996 } )
997 //
998 // CUSTOM RESOLVES
999 // Add your own resolves properties
1000 // following this object extend
1001 // method
1002 // -----------------------------------
1003 // .state('app.someroute', {
1004 // url: '/some_url',
1005 // templateUrl: 'path_to_template.html',
1006 // controller: 'someController',
1007 // resolve: angular.extend(
1008 // helper.resolveFor(), {
1009 // // YOUR RESOLVES GO HERE
1010 // }
1011 // )
1012 // })
1013 ;
1014
1015 } // routesConfig
1016
1017}) ();
1018
1019
1020(function () {
1021 'use strict';
1022
1023 angular
1024 .module ( 'app.settings' )
1025 .run ( settingsRun );
1026
1027 settingsRun.$inject = [ '$rootScope' , '$localStorage' ];
1028
1029 function settingsRun ( $rootScope , $localStorage ) {
1030
1031 // Global Settings
1032 // -----------------------------------
1033 $rootScope.app = {
1034 name: 'Malaeb' ,
1035 description: 'Dashboard' ,
1036 year: ((new Date ()).getFullYear ()) ,
1037 layout: {
1038 isFixed: true ,
1039 isCollapsed: false ,
1040 isBoxed: false ,
1041 isRTL: false ,
1042 horizontal: false ,
1043 isFloat: false ,
1044 asideHover: false ,
1045 theme: 'app/css/malaeb.css' ,
1046 asideScrollbar: false
1047 } ,
1048 useFullLayout: false ,
1049 hiddenFooter: false ,
1050 offsidebarOpen: false ,
1051 asideToggled: false ,
1052 viewAnimation: 'ng-fadeInUp' ,
1053 transitionLoading: false
1054 };
1055
1056 // Setup the layout mode
1057 $rootScope.app.layout.horizontal = ( $rootScope.$stateParams.layout === 'app-h');
1058
1059 // Restore layout settings [*** UNCOMMENT TO ENABLE ***]
1060 // if( angular.isDefined($localStorage.layout) )
1061 // $rootScope.app.layout = $localStorage.layout;
1062 // else
1063 // $localStorage.layout = $rootScope.app.layout;
1064 //
1065 // $rootScope.$watch('app.layout', function () {
1066 // $localStorage.layout = $rootScope.app.layout;
1067 // }, true);
1068
1069 // Close submenu when sidebar change from collapsed to normal
1070 $rootScope.$watch ( 'app.layout.isCollapsed' , function ( newValue ) {
1071 if ( newValue === false )
1072 $rootScope.$broadcast ( 'closeSidebarMenu' );
1073 } );
1074
1075 }
1076
1077}) ();
1078
1079/**=========================================================
1080 * Module: sidebar-menu.js
1081 * Handle sidebar collapsible elements
1082 =========================================================*/
1083
1084(function () {
1085 'use strict';
1086
1087 angular
1088 .module ( 'app.sidebar' )
1089 .controller ( 'SidebarController' , SidebarController );
1090
1091 SidebarController.$inject = [ '$rootScope' , '$scope' , '$state' , 'SidebarLoader' , 'Utils' ];
1092 function SidebarController ( $rootScope , $scope , $state , SidebarLoader , Utils ) {
1093
1094 activate ();
1095
1096 ////////////////
1097
1098 function activate () {
1099 var collapseList = [];
1100
1101 // demo: when switch from collapse to hover, close all items
1102 $rootScope.$watch ( 'app.layout.asideHover' , function ( oldVal , newVal ) {
1103 if ( newVal === false && oldVal === true ) {
1104 closeAllBut ( - 1 );
1105 }
1106 } );
1107
1108
1109 // Load menu from json file
1110 // -----------------------------------
1111
1112 SidebarLoader.getMenu ( sidebarReady );
1113
1114 function sidebarReady ( items ) {
1115 $scope.menuItems = items;
1116 }
1117
1118 // Handle sidebar and collapse items
1119 // ----------------------------------
1120
1121 $scope.getMenuItemPropClasses = function ( item ) {
1122 return (item.heading ? 'nav-heading' : '') +
1123 (isActive ( item ) ? ' active' : '');
1124 };
1125
1126 $scope.addCollapse = function ( $index , item ) {
1127 collapseList[ $index ] = $rootScope.app.layout.asideHover ? true : ! isActive ( item );
1128 };
1129
1130 $scope.isCollapse = function ( $index ) {
1131 return (collapseList[ $index ]);
1132 };
1133
1134 $scope.toggleCollapse = function ( $index , isParentItem ) {
1135
1136 // collapsed sidebar doesn't toggle drodopwn
1137 if ( Utils.isSidebarCollapsed () || $rootScope.app.layout.asideHover ) return true;
1138
1139 // make sure the item index exists
1140 if ( angular.isDefined ( collapseList[ $index ] ) ) {
1141 if ( ! $scope.lastEventFromChild ) {
1142 collapseList[ $index ] = ! collapseList[ $index ];
1143 closeAllBut ( $index );
1144 }
1145 }
1146 else if ( isParentItem ) {
1147 closeAllBut ( - 1 );
1148 }
1149
1150 $scope.lastEventFromChild = isChild ( $index );
1151
1152 return true;
1153
1154 };
1155
1156 // Controller helpers
1157 // -----------------------------------
1158
1159 // Check item and children active state
1160 function isActive ( item ) {
1161
1162 if ( ! item ) return;
1163
1164 if ( ! item.sref || item.sref === '#' ) {
1165 var foundActive = false;
1166 angular.forEach ( item.submenu , function ( value ) {
1167 if ( isActive ( value ) ) foundActive = true;
1168 } );
1169 return foundActive;
1170 }
1171 else
1172 return $state.is ( item.sref ) || $state.includes ( item.sref );
1173 }
1174
1175 function closeAllBut ( index ) {
1176 index += '';
1177 for ( var i in collapseList ) {
1178 if ( index < 0 || index.indexOf ( i ) < 0 )
1179 collapseList[ i ] = true;
1180 }
1181 }
1182
1183 function isChild ( $index ) {
1184 /*jshint -W018*/
1185 return (typeof $index === 'string') && ! ($index.indexOf ( '-' ) < 0);
1186 }
1187
1188 } // activate
1189 }
1190
1191}) ();
1192
1193/**=========================================================
1194 * Module: sidebar.js
1195 * Wraps the sidebar and handles collapsed state
1196 =========================================================*/
1197
1198(function () {
1199 'use strict';
1200
1201 angular
1202 .module ( 'app.sidebar' )
1203 .directive ( 'sidebar' , sidebar );
1204
1205 sidebar.$inject = [ '$rootScope' , '$timeout' , '$window' , 'Utils' ];
1206 function sidebar ( $rootScope , $timeout , $window , Utils ) {
1207 var $win = angular.element ( $window );
1208 var directive = {
1209 // bindToController: true,
1210 // controller: Controller,
1211 // controllerAs: 'vm',
1212 link: link ,
1213 restrict: 'EA' ,
1214 template: '<nav class="sidebar" ng-transclude></nav>' ,
1215 transclude: true ,
1216 replace: true
1217 // scope: {}
1218 };
1219 return directive;
1220
1221 function link ( scope , element , attrs ) {
1222
1223 var currentState = $rootScope.$state.current.name;
1224 var $sidebar = element;
1225
1226 var eventName = Utils.isTouch () ? 'click' : 'mouseenter';
1227 var subNav = $ ();
1228
1229 $sidebar.on ( eventName , '.nav > li' , function () {
1230
1231 if ( Utils.isSidebarCollapsed () || $rootScope.app.layout.asideHover ) {
1232
1233 subNav.trigger ( 'mouseleave' );
1234 subNav = toggleMenuItem ( $ ( this ) , $sidebar );
1235
1236 // Used to detect click and touch events outside the sidebar
1237 sidebarAddBackdrop ();
1238
1239 }
1240
1241 } );
1242
1243 scope.$on ( 'closeSidebarMenu' , function () {
1244 removeFloatingNav ();
1245 } );
1246
1247 // Normalize state when resize to mobile
1248 $win.on ( 'resize' , function () {
1249 if ( ! Utils.isMobile () )
1250 asideToggleOff ();
1251 } );
1252
1253 // Adjustment on route changes
1254 $rootScope.$on ( '$stateChangeStart' , function ( event , toState ) {
1255 currentState = toState.name;
1256 // Hide sidebar automatically on mobile
1257 asideToggleOff ();
1258
1259 $rootScope.$broadcast ( 'closeSidebarMenu' );
1260 } );
1261
1262 // Autoclose when click outside the sidebar
1263 if ( angular.isDefined ( attrs.sidebarAnyclickClose ) ) {
1264
1265 var wrapper = $ ( '.wrapper' );
1266 var sbclickEvent = 'click.sidebar';
1267
1268 $rootScope.$watch ( 'app.asideToggled' , watchExternalClicks );
1269
1270 }
1271
1272 //////
1273
1274 function watchExternalClicks ( newVal ) {
1275 // if sidebar becomes visible
1276 if ( newVal === true ) {
1277 $timeout ( function () { // render after current digest cycle
1278 wrapper.on ( sbclickEvent , function ( e ) {
1279 // if not child of sidebar
1280 if ( ! $ ( e.target ).parents ( '.aside' ).length ) {
1281 asideToggleOff ();
1282 }
1283 } );
1284 } );
1285 }
1286 else {
1287 // dettach event
1288 wrapper.off ( sbclickEvent );
1289 }
1290 }
1291
1292 function asideToggleOff () {
1293 $rootScope.app.asideToggled = false;
1294 if ( ! scope.$$phase ) scope.$apply (); // anti-pattern but sometimes necessary
1295 }
1296 }
1297
1298 ///////
1299
1300 function sidebarAddBackdrop () {
1301 var $backdrop = $ ( '<div/>' , {'class': 'dropdown-backdrop'} );
1302 $backdrop.insertAfter ( '.aside-inner' ).on ( 'click mouseenter' , function () {
1303 removeFloatingNav ();
1304 } );
1305 }
1306
1307 // Open the collapse sidebar submenu items when on touch devices
1308 // - desktop only opens on hover
1309 function toggleTouchItem ( $element ) {
1310 $element
1311 .siblings ( 'li' )
1312 .removeClass ( 'open' )
1313 .end ()
1314 .toggleClass ( 'open' );
1315 }
1316
1317 // Handles hover to open items under collapsed menu
1318 // -----------------------------------
1319 function toggleMenuItem ( $listItem , $sidebar ) {
1320
1321 removeFloatingNav ();
1322
1323 var ul = $listItem.children ( 'ul' );
1324
1325 if ( ! ul.length ) return $ ();
1326 if ( $listItem.hasClass ( 'open' ) ) {
1327 toggleTouchItem ( $listItem );
1328 return $ ();
1329 }
1330
1331 var $aside = $ ( '.aside' );
1332 var $asideInner = $ ( '.aside-inner' ); // for top offset calculation
1333 // float aside uses extra padding on aside
1334 var mar = parseInt ( $asideInner.css ( 'padding-top' ) , 0 ) + parseInt ( $aside.css ( 'padding-top' ) , 0 );
1335 var subNav = ul.clone ().appendTo ( $aside );
1336
1337 toggleTouchItem ( $listItem );
1338
1339 var itemTop = ($listItem.position ().top + mar) - $sidebar.scrollTop ();
1340 var vwHeight = $win.height ();
1341
1342 subNav
1343 .addClass ( 'nav-floating' )
1344 .css ( {
1345 position: $rootScope.app.layout.isFixed ? 'fixed' : 'absolute' ,
1346 top: itemTop ,
1347 bottom: (subNav.outerHeight ( true ) + itemTop > vwHeight) ? 0 : 'auto'
1348 } );
1349
1350 subNav.on ( 'mouseleave' , function () {
1351 toggleTouchItem ( $listItem );
1352 subNav.remove ();
1353 } );
1354
1355 return subNav;
1356 }
1357
1358 function removeFloatingNav () {
1359 $ ( '.dropdown-backdrop' ).remove ();
1360 $ ( '.sidebar-subnav.nav-floating' ).remove ();
1361 $ ( '.sidebar li.open' ).removeClass ( 'open' );
1362 }
1363 }
1364
1365
1366}) ();
1367
1368
1369(function () {
1370 'use strict';
1371
1372 angular
1373 .module ( 'app.sidebar' )
1374 .service ( 'SidebarLoader' , SidebarLoader );
1375
1376 SidebarLoader.$inject = [ '$http' ];
1377 function SidebarLoader ( $http ) {
1378 this.getMenu = getMenu;
1379
1380 ////////////////
1381
1382 function getMenu ( onReady , onError ) {
1383 var menuJson = 'server/sidebar-menu.json' ,
1384 menuURL = menuJson + '?v=' + (new Date ().getTime ()); // jumps cache
1385
1386 onError = onError || function () {
1387 alert ( 'Failure loading menu' );
1388 };
1389
1390 $http
1391 .get ( menuURL )
1392 .success ( onReady )
1393 .error ( onError );
1394 }
1395 }
1396}) ();
1397(function () {
1398 'use strict';
1399
1400 angular
1401 .module ( 'app.sidebar' )
1402 .controller ( 'UserBlockController' , UserBlockController );
1403
1404 UserBlockController.$inject = [ '$rootScope' , '$scope' ];
1405 function UserBlockController ( $rootScope , $scope ) {
1406
1407 activate ();
1408
1409 function activate () {
1410 $rootScope.user = {
1411 name: 'John' ,
1412 job: 'ng-developer' ,
1413 picture: 'app/img/user/02.jpg'
1414 };
1415
1416 // Hides/show user avatar on sidebar
1417 $rootScope.toggleUserBlock = function () {
1418 $rootScope.$broadcast ( 'toggleUserBlock' );
1419 };
1420
1421 $rootScope.userBlockVisible = true;
1422
1423 var detach = $rootScope.$on ( 'toggleUserBlock' , function ( /*event, args*/ ) {
1424
1425 $rootScope.userBlockVisible = ! $rootScope.userBlockVisible;
1426
1427 } );
1428
1429 $scope.$on ( '$destroy' , detach );
1430 }
1431 }
1432}) ();
1433
1434(function () {
1435 'use strict';
1436
1437 angular
1438 .module ( 'app.translate' )
1439 .config ( translateConfig )
1440 ;
1441 translateConfig.$inject = [ '$translateProvider' ];
1442 function translateConfig ( $translateProvider ) {
1443
1444 $translateProvider.useStaticFilesLoader ( {
1445 prefix: 'app/i18n/' ,
1446 suffix: '.json'
1447 } );
1448
1449 $translateProvider.preferredLanguage ( 'en' );
1450 $translateProvider.useLocalStorage ();
1451 $translateProvider.usePostCompiling ( true );
1452 $translateProvider.useSanitizeValueStrategy ( 'sanitizeParameters' );
1453
1454 }
1455}) ();
1456(function () {
1457 'use strict';
1458
1459 angular
1460 .module ( 'app.translate' )
1461 .run ( translateRun )
1462 ;
1463 translateRun.$inject = [ '$rootScope' , '$translate' ];
1464
1465 function translateRun ( $rootScope , $translate ) {
1466
1467 // Internationalization
1468 // ----------------------
1469
1470 $rootScope.language = {
1471 // Handles language dropdown
1472 listIsOpen: false ,
1473 // list of available languages
1474 available: {
1475 'en': 'English' ,
1476 'es_AR': 'Español'
1477 } ,
1478 // display always the current ui language
1479 init: function () {
1480 var proposedLanguage = $translate.proposedLanguage () || $translate.use ();
1481 var preferredLanguage = $translate.preferredLanguage (); // we know we have set a preferred one in app.config
1482 $rootScope.language.selected = $rootScope.language.available[ (proposedLanguage || preferredLanguage) ];
1483 } ,
1484 set: function ( localeId ) {
1485 // Set the new idiom
1486 $translate.use ( localeId );
1487 // save a reference for the current language
1488 $rootScope.language.selected = $rootScope.language.available[ localeId ];
1489 // finally toggle dropdown
1490 $rootScope.language.listIsOpen = ! $rootScope.language.listIsOpen;
1491 }
1492 };
1493
1494 $rootScope.language.init ();
1495
1496 }
1497}) ();
1498/**=========================================================
1499 * Module: animate-enabled.js
1500 * Enable or disables ngAnimate for element with directive
1501 =========================================================*/
1502
1503(function () {
1504 'use strict';
1505
1506 angular
1507 .module ( 'app.utils' )
1508 .directive ( 'animateEnabled' , animateEnabled );
1509
1510 animateEnabled.$inject = [ '$animate' ];
1511 function animateEnabled ( $animate ) {
1512 var directive = {
1513 link: link ,
1514 restrict: 'A'
1515 };
1516 return directive;
1517
1518 function link ( scope , element , attrs ) {
1519 scope.$watch ( function () {
1520 return scope.$eval ( attrs.animateEnabled , scope );
1521 } , function ( newValue ) {
1522 $animate.enabled ( ! ! newValue , element );
1523 } );
1524 }
1525 }
1526
1527}) ();
1528
1529/**=========================================================
1530 * Module: browser.js
1531 * Browser detection
1532 =========================================================*/
1533
1534(function () {
1535 'use strict';
1536
1537 angular
1538 .module ( 'app.utils' )
1539 .service ( 'Browser' , Browser );
1540
1541 Browser.$inject = [ '$window' ];
1542 function Browser ( $window ) {
1543 return $window.jQBrowser;
1544 }
1545
1546}) ();
1547
1548/**=========================================================
1549 * Module: clear-storage.js
1550 * Removes a key from the browser storage via element click
1551 =========================================================*/
1552
1553(function () {
1554 'use strict';
1555
1556 angular
1557 .module ( 'app.utils' )
1558 .directive ( 'resetKey' , resetKey );
1559
1560 resetKey.$inject = [ '$state' , '$localStorage' ];
1561 function resetKey ( $state , $localStorage ) {
1562 var directive = {
1563 link: link ,
1564 restrict: 'A' ,
1565 scope: {
1566 resetKey: '@'
1567 }
1568 };
1569 return directive;
1570
1571 function link ( scope , element ) {
1572 element.on ( 'click' , function ( e ) {
1573 e.preventDefault ();
1574
1575 if ( scope.resetKey ) {
1576 delete $localStorage[ scope.resetKey ];
1577 $state.go ( $state.current , {} , {reload: true} );
1578 }
1579 else {
1580 $.error ( 'No storage key specified for reset.' );
1581 }
1582 } );
1583 }
1584 }
1585
1586}) ();
1587
1588/**=========================================================
1589 * Module: fullscreen.js
1590 * Toggle the fullscreen mode on/off
1591 =========================================================*/
1592
1593(function () {
1594 'use strict';
1595
1596 angular
1597 .module ( 'app.utils' )
1598 .directive ( 'toggleFullscreen' , toggleFullscreen );
1599
1600 toggleFullscreen.$inject = [ 'Browser' ];
1601 function toggleFullscreen ( Browser ) {
1602 var directive = {
1603 link: link ,
1604 restrict: 'A'
1605 };
1606 return directive;
1607
1608 function link ( scope , element ) {
1609 // Not supported under IE
1610 if ( Browser.msie ) {
1611 element.addClass ( 'hide' );
1612 }
1613 else {
1614 element.on ( 'click' , function ( e ) {
1615 e.preventDefault ();
1616
1617 if ( screenfull.enabled ) {
1618
1619 screenfull.toggle ();
1620
1621 // Switch icon indicator
1622 if ( screenfull.isFullscreen )
1623 $ ( this ).children ( 'em' ).removeClass ( 'fa-expand' ).addClass ( 'fa-compress' );
1624 else
1625 $ ( this ).children ( 'em' ).removeClass ( 'fa-compress' ).addClass ( 'fa-expand' );
1626
1627 } else {
1628 $.error ( 'Fullscreen not enabled' );
1629 }
1630
1631 } );
1632 }
1633 }
1634 }
1635
1636
1637}) ();
1638
1639/**=========================================================
1640 * Module: load-css.js
1641 * Request and load into the current page a css file
1642 =========================================================*/
1643
1644(function () {
1645 'use strict';
1646
1647 angular
1648 .module ( 'app.utils' )
1649 .directive ( 'loadCss' , loadCss );
1650
1651 function loadCss () {
1652 var directive = {
1653 link: link ,
1654 restrict: 'A'
1655 };
1656 return directive;
1657
1658 function link ( scope , element , attrs ) {
1659 element.on ( 'click' , function ( e ) {
1660 if ( element.is ( 'a' ) ) e.preventDefault ();
1661 var uri = attrs.loadCss ,
1662 link;
1663
1664 if ( uri ) {
1665 link = createLink ( uri );
1666 if ( ! link ) {
1667 $.error ( 'Error creating stylesheet link element.' );
1668 }
1669 }
1670 else {
1671 $.error ( 'No stylesheet location defined.' );
1672 }
1673
1674 } );
1675 }
1676
1677 function createLink ( uri ) {
1678 var linkId = 'autoloaded-stylesheet' ,
1679 oldLink = $ ( '#' + linkId ).attr ( 'id' , linkId + '-old' );
1680
1681 $ ( 'head' ).append ( $ ( '<link/>' ).attr ( {
1682 'id': linkId ,
1683 'rel': 'stylesheet' ,
1684 'href': uri
1685 } ) );
1686
1687 if ( oldLink.length ) {
1688 oldLink.remove ();
1689 }
1690
1691 return $ ( '#' + linkId );
1692 }
1693 }
1694
1695}) ();
1696
1697/**=========================================================
1698 * Module: now.js
1699 * Provides a simple way to display the current time formatted
1700 =========================================================*/
1701
1702(function () {
1703 'use strict';
1704
1705 angular
1706 .module ( 'app.utils' )
1707 .directive ( 'now' , now );
1708
1709 now.$inject = [ 'dateFilter' , '$interval' ];
1710 function now ( dateFilter , $interval ) {
1711 var directive = {
1712 link: link ,
1713 restrict: 'EA'
1714 };
1715 return directive;
1716
1717 function link ( scope , element , attrs ) {
1718 var format = attrs.format;
1719
1720 function updateTime () {
1721 var dt = dateFilter ( new Date () , format );
1722 element.text ( dt );
1723 }
1724
1725 updateTime ();
1726 var intervalPromise = $interval ( updateTime , 1000 );
1727
1728 scope.$on ( '$destroy' , function () {
1729 $interval.cancel ( intervalPromise );
1730 } );
1731
1732 }
1733 }
1734
1735}) ();
1736
1737/**=========================================================
1738 * Module: table-checkall.js
1739 * Tables check all checkbox
1740 =========================================================*/
1741(function () {
1742 'use strict';
1743
1744 angular
1745 .module ( 'app.utils' )
1746 .directive ( 'checkAll' , checkAll );
1747
1748 function checkAll () {
1749 var directive = {
1750 link: link ,
1751 restrict: 'A'
1752 };
1753 return directive;
1754
1755 function link ( scope , element ) {
1756 element.on ( 'change' , function () {
1757 var $this = $ ( this ) ,
1758 index = $this.index () + 1 ,
1759 checkbox = $this.find ( 'input[type="checkbox"]' ) ,
1760 table = $this.parents ( 'table' );
1761 // Make sure to affect only the correct checkbox column
1762 table.find ( 'tbody > tr > td:nth-child(' + index + ') input[type="checkbox"]' )
1763 .prop ( 'checked' , checkbox[ 0 ].checked );
1764
1765 } );
1766 }
1767 }
1768
1769}) ();
1770
1771/**=========================================================
1772 * Module: trigger-resize.js
1773 * Triggers a window resize event from any element
1774 =========================================================*/
1775(function () {
1776 'use strict';
1777
1778 angular
1779 .module ( 'app.utils' )
1780 .directive ( 'triggerResize' , triggerResize );
1781
1782 triggerResize.$inject = [ '$window' , '$timeout' ];
1783 function triggerResize ( $window , $timeout ) {
1784 var directive = {
1785 link: link ,
1786 restrict: 'A'
1787 };
1788 return directive;
1789
1790 function link ( scope , element ) {
1791 element.on ( 'click' , function () {
1792 $timeout ( function () {
1793 // all IE friendly dispatchEvent
1794 var evt = document.createEvent ( 'UIEvents' );
1795 evt.initUIEvent ( 'resize' , true , false , $window , 0 );
1796 $window.dispatchEvent ( evt );
1797 // modern dispatchEvent way
1798 // $window.dispatchEvent(new Event('resize'));
1799 } );
1800 } );
1801 }
1802 }
1803
1804}) ();
1805
1806/**=========================================================
1807 * Module: utils.js
1808 * Utility library to use across the theme
1809 =========================================================*/
1810
1811(function () {
1812 'use strict';
1813
1814 angular
1815 .module ( 'app.utils' )
1816 .service ( 'Utils' , Utils );
1817
1818 Utils.$inject = [ '$window' , 'APP_MEDIAQUERY' ];
1819 function Utils ( $window , APP_MEDIAQUERY ) {
1820
1821 var $html = angular.element ( 'html' ) ,
1822 $win = angular.element ( $window ) ,
1823 $body = angular.element ( 'body' );
1824
1825 return {
1826 // DETECTION
1827 support: {
1828 transition: (function () {
1829 var transitionEnd = (function () {
1830
1831 var element = document.body || document.documentElement ,
1832 transEndEventNames = {
1833 WebkitTransition: 'webkitTransitionEnd' ,
1834 MozTransition: 'transitionend' ,
1835 OTransition: 'oTransitionEnd otransitionend' ,
1836 transition: 'transitionend'
1837 } , name;
1838
1839 for ( name in transEndEventNames ) {
1840 if ( element.style[ name ] !== undefined ) return transEndEventNames[ name ];
1841 }
1842 } ());
1843
1844 return transitionEnd && {end: transitionEnd};
1845 }) () ,
1846 animation: (function () {
1847
1848 var animationEnd = (function () {
1849
1850 var element = document.body || document.documentElement ,
1851 animEndEventNames = {
1852 WebkitAnimation: 'webkitAnimationEnd' ,
1853 MozAnimation: 'animationend' ,
1854 OAnimation: 'oAnimationEnd oanimationend' ,
1855 animation: 'animationend'
1856 } , name;
1857
1858 for ( name in animEndEventNames ) {
1859 if ( element.style[ name ] !== undefined ) return animEndEventNames[ name ];
1860 }
1861 } ());
1862
1863 return animationEnd && {end: animationEnd};
1864 }) () ,
1865 requestAnimationFrame: window.requestAnimationFrame ||
1866 window.webkitRequestAnimationFrame ||
1867 window.mozRequestAnimationFrame ||
1868 window.msRequestAnimationFrame ||
1869 window.oRequestAnimationFrame ||
1870 function ( callback ) {
1871 window.setTimeout ( callback , 1000 / 60 );
1872 } ,
1873 /*jshint -W069*/
1874 touch: (
1875 ('ontouchstart' in window && navigator.userAgent.toLowerCase ().match ( /mobile|tablet/ )) ||
1876 (window.DocumentTouch && document instanceof window.DocumentTouch) ||
1877 (window.navigator[ 'msPointerEnabled' ] && window.navigator[ 'msMaxTouchPoints' ] > 0) || //IE 10
1878 (window.navigator[ 'pointerEnabled' ] && window.navigator[ 'maxTouchPoints' ] > 0) || //IE >=11
1879 false
1880 ) ,
1881 mutationobserver: (window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver || null)
1882 } ,
1883 // UTILITIES
1884 isInView: function ( element , options ) {
1885 /*jshint -W106*/
1886 var $element = $ ( element );
1887
1888 if ( ! $element.is ( ':visible' ) ) {
1889 return false;
1890 }
1891
1892 var window_left = $win.scrollLeft () ,
1893 window_top = $win.scrollTop () ,
1894 offset = $element.offset () ,
1895 left = offset.left ,
1896 top = offset.top;
1897
1898 options = $.extend ( {topoffset: 0 , leftoffset: 0} , options );
1899
1900 if ( top + $element.height () >= window_top && top - options.topoffset <= window_top + $win.height () &&
1901 left + $element.width () >= window_left && left - options.leftoffset <= window_left + $win.width () ) {
1902 return true;
1903 } else {
1904 return false;
1905 }
1906 } ,
1907
1908 langdirection: $html.attr ( 'dir' ) === 'rtl' ? 'right' : 'left' ,
1909
1910 isTouch: function () {
1911 return $html.hasClass ( 'touch' );
1912 } ,
1913
1914 isSidebarCollapsed: function () {
1915 return $body.hasClass ( 'aside-collapsed' );
1916 } ,
1917
1918 isSidebarToggled: function () {
1919 return $body.hasClass ( 'aside-toggled' );
1920 } ,
1921
1922 isMobile: function () {
1923 return $win.width () < APP_MEDIAQUERY.tablet;
1924 }
1925
1926 };
1927 }
1928}) ();
1929
1930(function () {
1931 'use strict';
1932
1933 angular
1934 .module ( 'custom' , [
1935 // request the the entire framework
1936 'angle' ,
1937 // or just modules
1938 'app.core' ,
1939 'app.sidebar'
1940 /*...*/
1941 ] );
1942}) ();
1943
1944// To run this code, edit file index.html or index.jade and change
1945// html data-ng-app attribute from angle to myAppName
1946// ----------------------------------------------------------------------
1947
1948(function () {
1949 'use strict';
1950
1951 angular
1952 .module ( 'custom' )
1953 .controller ( 'Controller' , Controller );
1954
1955 Controller.$inject = [ '$log' ];
1956 function Controller ( $log ) {
1957 // for controllerAs syntax
1958 // var vm = this;
1959
1960 activate ();
1961
1962 ////////////////
1963
1964 function activate () {
1965 $log.log ( 'I\'m a line from custom.js' );
1966 }
1967 }
1968}) ();
1969
1970
1971(function () {
1972 'use strict';
1973
1974 angular
1975 .module ( 'app.schedule', [
1976 'ui.bootstrap'
1977 ]
1978 )
1979 .controller ( 'ScheduleController' , ScheduleController )
1980 .controller ( 'NewBookingCtrl' , NewBookingCtrl )
1981 .controller ( 'repeatedBookingCtrl' , repeatedBookingCtrl )
1982 .controller ( 'editMultipleBooking' , editMultipleBooking )
1983 .controller ( 'editBooking' , editBooking )
1984 .controller ( 'closeConfirm' , closeConfirm)
1985 .service ( 'BookingService' , BookingService )
1986 .service ( 'BookingEditService' , BookingEditService )
1987 .service ( 'PitchService' , PitchService )
1988 .factory ( 'RtSocket' , RtSocket );
1989
1990 RtSocket.$inject = [ 'socketFactory' ];
1991
1992 function RtSocket ( socketFactory ) {
1993 var rtSocket = socketFactory ( {
1994 ioSocket: io.connect ( SOCKET_URL , {'path': '/socket.io'} ) ,
1995 } );
1996 rtSocket.forward ( 'booking' );
1997 return rtSocket;
1998 }
1999
2000 ScheduleController.$inject = [ '$scope' , '$http' , '$timeout' , '$rootScope' , '$stateParams' , '$state' , 'ngDialog' , 'BookingService' , 'BookingEditService' , 'PitchService' , 'uiCalendarConfig' , '$compile' , '$filter' , '$interval' , 'RtSocket' , '$auth' , 'whereFilter' ];
2001 function ScheduleController ( $scope , $http , $timeout , $rootScope , $stateParams , $state , ngDialog , BookingService , BookingEditService , PitchService , uiCalendarConfig , $compile , $filter , $interval , RtSocket , $auth , whereFilter ) {
2002
2003 if ( ! $auth.isAuthenticated () ) {
2004 $state.go ( 'login' );
2005 } //Check if user is not logged-in
2006
2007 $scope.booking = BookingService.booking ();
2008 $scope.pitchService = PitchService.pitchData;
2009 $scope.pitch = {};
2010
2011 if ( ! $stateParams.id ) {
2012 if (
2013 typeof($rootScope.currentUser) !== 'undefined' &&
2014 typeof($rootScope.currentUser.stadiums[ 0 ]) !== 'undefined' &&
2015 typeof($rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ]) !== 'undefined' &&
2016 typeof($rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id) !== 'undefined'
2017 ) {
2018 $scope.pitchId = $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id;
2019 } else {
2020 $scope.pitchId = null;
2021 }
2022 } else {
2023 $scope.pitchId = $stateParams.id;
2024 }
2025 var allowedPitch = whereFilter ( $rootScope.currentUser.stadiums[ 0 ].pitches , {'id': $scope.pitchId} );
2026
2027 if ( allowedPitch.length <= 0 ) {
2028 $state.go ( 'app.schedule' , {id: $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id} );
2029 }
2030
2031 $scope.getMaxTime = function ( time , length ) {
2032 var endTime = moment.utc ( time , 'HH:mm:ss' );
2033 endTime.add ( (parseInt ( length ) + 1) * 90 ,'minutes' );
2034 return endTime.format ( 'HH:mm:ss' );
2035 }
2036
2037 $scope.$on ( 'socket:booking' , function ( ev , data ) {
2038 var jsData = JSON.parse ( data.pitch );
2039 PitchService.pitchData[ $scope.pitchId ] = jsData;
2040 // console.log(PitchService.pitchData[$scope.pitchId]);
2041 if ( $scope.pitchId == jsData.id ) {
2042 $scope.pitch = PitchService.pitchData[ $scope.pitchId ];
2043 $scope.pitchPrice = PitchService.pitchData[ $scope.pitchId ].pitch_price;
2044 }
2045 } );
2046
2047
2048 //edit the data.
2049 $scope.editBooking = function ( event ) {
2050 ngDialog.close ( 'ngdialog1' );
2051 ngDialog.open ( {
2052 template: 'editBookingInfoModal' ,
2053 controller: 'editBooking' ,
2054 className: 'ngdialog-theme-default ngdialog-theme-custom'
2055 } );
2056 };
2057
2058
2059
2060 $scope.editMultipleBooking = function ( event ) {
2061 ngDialog.close ( 'ngdialog1' );
2062 ngDialog.open ( {
2063 template: 'editMultipleBookingInfoModal' ,
2064 controller: 'editMultipleBooking' ,
2065 className: 'ngdialog-theme-default ngdialog-theme-custom'
2066 } );
2067 };
2068
2069 /*
2070 $scope.editRecurringBooking = function (event) {
2071 console.log(event);
2072 $scope.directiveParameters = {};
2073 $scope.directiveParameters.editAll = true;
2074
2075 }
2076 */
2077
2078 //New Admin Wide Stadium Browser
2079 $scope.changeStadiumMessage = null;
2080 $scope.changeStadiumList = [];
2081 $scope.changeStadium = function () {
2082 //Fetch list of stadiums
2083 $scope.changeStadiumMessage = 'Loading...';
2084 $scope.changeStadiumList = [];
2085 $http.get ( API_URL + 'api/v1/stadium_list' )
2086 .success ( function ( response ) {
2087 $scope.changeStadiumMessage = null;
2088 $scope.changeStadiumList = response.data;
2089 } )
2090 .error ( function ( response ) {
2091 $scope.changeStadiumMessage = 'Error occured during loading. Try again later.';
2092 $scope.changeStadiumList = [];
2093 } );
2094 };
2095 $scope.changePitchList = function ( stadium ) {
2096 $rootScope.currentUser.stadiums[ 0 ].pitches = stadium.pitches;
2097 };
2098 //$rootScope.currentUser.stadiums[0].pitches
2099
2100 $scope.getPitchData = function ( range_view ) {
2101
2102 $scope.liveUpdateState = 1;
2103
2104 if ( typeof(uiCalendarConfig.calendars.schedule) !== 'undefined' && typeof(uiCalendarConfig.calendars.schedule.fullCalendar ( 'getView' )) !== 'undefined' ) {
2105 range_view = (uiCalendarConfig.calendars.schedule.fullCalendar ( 'getView' ));
2106 }
2107
2108 if ( typeof(range_view) !== 'undefined' ) {
2109 var time_midpoint = ( new Date ( range_view.start ).getTime () + new Date ( range_view.end ).getTime () ) / 2;
2110 var time_diff = Math.abs ( new Date ( range_view.end ).getTime () - new Date ( range_view.start ).getTime () ) / (60 * 60 * 24 * 1000);
2111 var frame_date = moment ( time_midpoint ).format ( "DD-MM-YYYY" );
2112 var frame_width = time_diff;
2113 } else {
2114 var frame_date = moment ().format ( "DD-MM-YYYY" );
2115 var frame_width = 14;
2116 }
2117
2118 //console.log ( 'Fetch Invoked for ' + $scope.pitchId );
2119
2120 //Action on change PITCH button
2121 $http.get ( API_URL + 'api/v1/pitches/' + $scope.pitchId + '?format=fetchlists' + '&frame_set=' + frame_date + '&frame_width=' + frame_width ).success ( function ( response ) {
2122 //
2123
2124 PitchService.pitchData[ $scope.pitchId ] = response.data;
2125 $scope.pitch = PitchService.pitchData[ $scope.pitchId ];
2126
2127 var events = [];
2128 var bookingsData = $scope.pitch.bookings;
2129 var getBookingInCalendarFormat = function ( element , index , array ) {
2130 var calendarObject = {};
2131 var startTime = moment ( element.match_date + ' ' + element.match_time );
2132 var endTime = moment ( element.match_date + ' ' + element.match_end_time );
2133
2134 if ( element.match_time < element.match_end_time ) {
2135 calendarObject.title = element.booking_name;
2136 } else {
2137 calendarObject.title = '> ' + element.booking_name;
2138 endTime = endTime.add ( 'day' , 1 );
2139 }
2140
2141 var eventTitle = startTime.format ( 'hh:mm A' ) + " - " + endTime.format ( 'hh:mm A' );
2142 calendarObject.start = startTime.format ( "YYYY-MM-DD HH:mm" );
2143 calendarObject.end = endTime.format ( "YYYY-MM-DD HH:mm" );
2144 //calendarObject.title = eventTitle;
2145 calendarObject.id = element.id;
2146 calendarObject.allDay = false;
2147 calendarObject.backgroundColor = $scope.getEventColor ( element ); //Info (aqua)
2148 calendarObject.borderColor = $scope.getEventColor ( element ); //Info (aqua)
2149 events.push ( calendarObject );
2150 }
2151
2152 bookingsData.forEach ( getBookingInCalendarFormat );
2153 $scope.eventSource = events;
2154
2155 if ( uiCalendarConfig.calendars[ 'schedule' ] != undefined ) // had to add this if statement because it was running this code before the calendars array was initialized
2156 {
2157 uiCalendarConfig.calendars.schedule.fullCalendar ( 'removeEvents' );
2158 uiCalendarConfig.calendars.schedule.fullCalendar ( 'addEventSource' , $scope.eventSource );
2159 }
2160
2161 $scope.liveUpdateState = 2;
2162
2163 } )
2164 .error ( function () {
2165 $scope.liveUpdateState = 3;
2166 console.log ( response.error );
2167 } );
2168
2169 $http.get ( API_URL + 'api/v1/pitches/' ).success ( function ( response ) {
2170 $scope.pitchService.pitches = response.data;
2171 $scope.pitches = $scope.pitchService.pitches;
2172 $scope.liveUpdateState = 4;
2173 } )
2174 .error ( function () {
2175 $scope.liveUpdateState = 5;
2176 console.log ( response.error );
2177 } );
2178
2179 $timeout ( function () {
2180 $rootScope.$broadcast ( 'loading-complete' );
2181 } , 10 );//Supress
2182 };
2183
2184
2185 $scope.getPitchData ();
2186
2187 $scope.createNewBooking = function () {
2188 ngDialog.open ( {
2189 template: 'createNewBookingModal' ,
2190 controller: 'NewBookingCtrl' ,
2191 preCloseCallback: function ( value ) {
2192 if ( $scope.booking.data.booking_status == 2 /*|| $scope.booking.data.booking_status == undefined */) {
2193 $scope.booking.data.booking_status = 4;
2194 $http.put ( API_URL + 'api/v1/bookings/' + $scope.booking.data.id , $scope.booking.data )
2195 .success ( function ( response ) {
2196 $scope.bookingError = false;
2197 } )
2198 .error ( function ( response ) {
2199 $scope.bookingError = true;
2200 $scope.bookingErrorText = "Failed to cancel booking. Please contact support.";
2201 } )
2202 }
2203 if ( $scope.booking.data.booking_status == 4 || $scope.booking.data.booking_status == 1 ) {
2204 return true;
2205 }
2206 else {
2207 return false;
2208 }
2209 } ,
2210 className: 'ngdialog-theme-default ngdialog-theme-custom'
2211 } );
2212 }
2213
2214 /*
2215 var cancelAutoUpdate = $timeout(function(){
2216 alert('cancelAutoUpdate Invoked');
2217
2218 var frame_date = moment().format("DD-MM-YYYY");
2219 var frame_width = 14;
2220 $http.get(API_URL+'api/v1/pitches/'+$scope.pitchId+'?format=fetchlists'+'&frame_set='+frame_date+'&frame_width='+frame_width).success(function(response){
2221 //
2222 PitchService.pitchData[$scope.pitchId] = response.data;
2223 $scope.pitch = PitchService.pitchData[$scope.pitchId];
2224
2225
2226 })
2227 .error(function(){
2228 console.log(response.error);
2229 });
2230 }, 2000);
2231 */
2232
2233 var stopLiveFetch = undefined;
2234 $scope.$on ( '$stateChangeStart' , function () {
2235 $interval.cancel ( stopLiveFetch );
2236 } );
2237
2238 $scope.$on ( "$destroy" , function () {
2239 $interval.cancel ( stopLiveFetch );
2240 } );
2241
2242 $scope.getEvents = function () {
2243 var eventSources = $scope.eventSources;
2244 return eventSources;
2245 }
2246 $scope.slotTimeChange = function () {
2247 $rootScope.selectedValue = $scope.singleSelect;
2248 $scope.uiConfig.calendar.views.agenda.slotDuration = $rootScope.selectedValue;
2249
2250 console.log ( '$scope.uiConfig.calendar.views.agenda.slotDuration' , $scope.uiConfig.calendar.views.agenda.slotDuration );
2251
2252
2253 //TODO change code duplication already defined function in $scope.getPitchData
2254
2255 var frame_date = moment ( $scope.booking.date ).format ( "DD-MM-YYYY" );
2256 var frame_width = 7;
2257 $http.get ( API_URL + 'api/v1/pitches/' + $scope.pitchId + '?format=fetchlists' + '&frame_set=' + frame_date + '&frame_width=' + frame_width ).success ( function ( response ) {
2258 //
2259 PitchService.pitchData[ $scope.pitchId ] = response.data;
2260 $scope.pitch = PitchService.pitchData[ $scope.pitchId ];
2261
2262 var events = [];
2263 var bookingsData = $scope.pitch.bookings;
2264 var getBookingInCalendarFormat = function ( element , index , array ) {
2265 var calendarObject = {};
2266 var startTime = moment ( element.match_date + ' ' + element.match_time );
2267 var endTime = moment ( element.match_date + ' ' + element.match_end_time );
2268
2269 if ( element.match_time < element.match_end_time ) {
2270 calendarObject.title = element.booking_name;
2271 } else {
2272 calendarObject.title = '> ' + element.booking_name;
2273 endTime = endTime.add ( 'day' , 1 );
2274 }
2275
2276 var eventTitle = startTime.format ( 'hh:mm A' ) + " - " + endTime.format ( 'hh:mm A' )
2277 calendarObject.start = startTime.format ( "YYYY-MM-DD HH:mm" );
2278 calendarObject.end = endTime.format ( "YYYY-MM-DD HH:mm" );
2279 //calendarObject.title = eventTitle;
2280 calendarObject.id = element.id;
2281 calendarObject.allDay = false;
2282 calendarObject.backgroundColor = $scope.getEventColor ( element ); //Info (aqua)
2283 calendarObject.borderColor = $scope.getEventColor ( element ); //Info (aqua)
2284 events.push ( calendarObject );
2285
2286 }
2287
2288 bookingsData.forEach ( getBookingInCalendarFormat );
2289 $scope.eventSource = events;
2290
2291 if ( uiCalendarConfig.calendars[ 'schedule' ] != undefined ) // had to add this if statement because it was running this code before the calendars array was initialized
2292 {
2293 uiCalendarConfig.calendars.schedule.fullCalendar ( 'removeEvents' );
2294 uiCalendarConfig.calendars.schedule.fullCalendar ( 'addEventSource' , $scope.eventSource );
2295 }
2296
2297 } )
2298 .error ( function () {
2299 console.log ( response.error );
2300 } );
2301
2302
2303 $http.get ( API_URL + 'api/v1/pitches/' ).success ( function ( response ) {
2304 //
2305 $scope.pitchService.pitches = response.data;
2306 $scope.pitches = $scope.pitchService.pitches;
2307 } )
2308 .error ( function () {
2309 console.log ( response.error );
2310 } );
2311
2312
2313 }
2314
2315 $scope.getEventColor = function ( event ) {
2316
2317 /*
2318 if (event.reservation_group != '0') {
2319 return "#581845";
2320 }
2321 */
2322 if ( event.booking_status == 1 || event.booking_status == "1" ) {
2323
2324 if ( event.booking_type == 1 || event.booking_type == "1" ) {
2325 return "#85C140";
2326 } else if ( event.booking_type == 3 || event.booking_type == "3" ) {
2327 return "#666666";
2328 } else {
2329 return "#00c0ef";
2330 }
2331
2332 } else {
2333 return "#E9FA4D";
2334 }
2335
2336 };
2337
2338 $scope.$watch ( function ( scope ) {
2339 return scope.pitch;
2340 } ,
2341 function ( newValue , oldValue ) {
2342
2343 //console.log ( $scope.pitch.stadium.closing_time );
2344 /*alert($scope.singleSelect);*/
2345
2346 //Calendar Config
2347 if ( $scope.pitch.stadium.full24display == 1 ) {
2348 var fullview = false;
2349 var min_time = $scope.pitch.stadium.opening_time;
2350 var max_time = $scope.pitch.stadium.closing_time;
2351 } else {
2352 var fullview = true;
2353 var min_time = '00:00:00';
2354 var max_time = '24:00:00';
2355 }
2356
2357 function setTimeline ( view ) {
2358
2359 if ( view.type == 'agendaWeek' ) {
2360 if ( fullview ) {
2361 var divs = angular.element ( document.querySelectorAll ( ".fc-slats tr td.fc-widget-content" ) );
2362
2363 var min_time_parsed = $scope.pitch.stadium.opening_time.split ( ':' );
2364 var min_time_calc = (parseInt ( min_time_parsed[ 0 ] ) * 2) + (parseInt ( min_time_parsed[ 1 ] ) == 30 ? 1 : 0);
2365
2366 var max_time_parsed = $scope.pitch.stadium.closing_time.split ( ':' );
2367 var max_time_calc = (parseInt ( max_time_parsed[ 0 ] ) * 2) + (parseInt ( max_time_parsed[ 1 ] ) == 30 ? 1 : 0);
2368
2369 if ( $scope.pitch.stadium.closing_time == '23:59:00' ) max_time_calc = 48;
2370
2371 //console.log ( min_time_calc , max_time_calc );
2372
2373 var i = 0;
2374 var j = 0;
2375 [].forEach.call ( divs , function ( div ) {
2376
2377 if ( ( j >= 0 && j < min_time_calc ) || ( j > max_time_calc && j < 48 ) )
2378 div.style.backgroundColor = "rgba(100,100,100,0.25)";
2379
2380 i ++;
2381 if ( i % 2 == 0 ) j ++;
2382 } );
2383 }
2384 }
2385 }
2386
2387 $scope.uiConfig = {
2388 calendar: {
2389 scrollTime: '12:00:00' ,
2390 height: 600 ,
2391 header: {
2392 left: '' ,
2393 center: 'title' ,
2394 right: 'month,agendaWeek,agendaDay prev,next today'
2395 } ,
2396
2397 defaultView: 'agendaWeek' ,
2398 buttonIcons: { // note the space at the beginning
2399 prev: ' fa fa-caret-left' ,
2400 next: ' fa fa-caret-right'
2401 } ,
2402
2403 buttonText: {
2404 today: 'today' ,
2405 month: 'month' ,
2406 week: 'week' ,
2407 day: 'day'
2408 } ,
2409
2410 editable: false ,
2411 selectable: true ,
2412 selectHelper: true ,
2413 displayEventEnd: true ,
2414
2415 slotLabelInterval: 30 ,
2416 slotLabelFormat: 'h(:mm) a' ,
2417
2418 select: function ( start , end ) {
2419 $scope.booking.pitch = $scope.pitch;
2420 $scope.booking.date = start;
2421 $scope.booking.dateEnd = end;
2422 $scope.booking.time = start;
2423 $scope.createNewBooking ();
2424 } ,
2425 selectOverlap: false ,
2426 // aspectRatio: 2,
2427 viewRender: function ( view , element ) {
2428
2429 console.log ( 'Clear Prev Interval' , stopLiveFetch );
2430 $interval.cancel ( stopLiveFetch );
2431
2432 if ( view.name == 'agendaWeek' ) {
2433 //Run Fetcher
2434 $timeout ( function () {
2435
2436 console.log ( 'Running Fetch Interval' );
2437 setTimeline ( view );
2438 $scope.getPitchData ( view );
2439
2440 $scope.liveUpdateState = 0; //0 = pending / 1 - in process / 2 - done / 3 - canceled
2441 if ( angular.isDefined ( stopLiveFetch ) ) {
2442 console.log ( 'Clear Prev Interval' , stopLiveFetch );
2443 $interval.cancel ( stopLiveFetch );
2444 }
2445 stopLiveFetch = $interval ( function () {
2446 $scope.getPitchData ( view );
2447 } , 5000 );
2448
2449 console.log ( 'Interval Created' , stopLiveFetch );
2450
2451 } , 100 );
2452 } else {
2453 //Just Single Fetch
2454 $scope.getPitchData ( view );
2455 }
2456
2457 } ,
2458
2459 views: {
2460 agenda: {
2461 // slotDuration: $scope.singleSelect,
2462 // slotLabelInterval: "00:10:00",
2463 // minTime: "05:00:00",`
2464
2465 minTime: min_time , //OLD DEPENDS on open - closing
2466 maxTime: max_time ,
2467
2468 // maxTime: $scope.getMaxTime($scope.pitch.opening_time, $scope.pitch.number_games),
2469 // maxTime:"15:00:00",
2470
2471 allDaySlot: false ,
2472 slotEventOverlap: false ,
2473 } ,
2474 } ,
2475
2476 eventClick: $scope.infoOnEventClick ,
2477 }
2478 }
2479
2480 $scope.events = [];
2481 var bookingsData = $scope.pitch.bookings;
2482 var getBookingInCalendarFormat = function ( element , index , array ) {
2483
2484 var calendarObject = {};
2485
2486 var startTime = moment ( element.match_date + ' ' + element.match_time );
2487 var endTime = moment ( element.match_date + ' ' + element.match_end_time );
2488
2489 if ( element.match_time < element.match_end_time ) {
2490 calendarObject.title = element.booking_name;
2491 } else {
2492 calendarObject.title = '> ' + element.booking_name;
2493 endTime = endTime.add ( 'day' , 1 );
2494 }
2495
2496 if (element.reservation_group != '0')
2497 calendarObject.title = calendarObject.title + "\n(Fixed)"
2498
2499 var eventTime = startTime.format ( 'hh:mm A' ) + " - " + endTime.format ( 'hh:mm A' );
2500
2501 calendarObject.start = startTime.format ( "YYYY-MM-DD HH:mm" );
2502 calendarObject.end = endTime.format ( "YYYY-MM-DD HH:mm" );
2503
2504 calendarObject.id = element.id;
2505 calendarObject.allDay = false;
2506 calendarObject.eventTime = eventTime;
2507 calendarObject.backgroundColor = $scope.getEventColor ( element ); //Info (aqua)
2508 calendarObject.borderColor = $scope.getEventColor ( element ); //Info (aqua)
2509 $scope.events.push ( calendarObject );
2510
2511 }
2512
2513 // $scope.pitchService[$scope.booking.pitch.id].bookings.length = 0;
2514 bookingsData.forEach ( getBookingInCalendarFormat );
2515 // console.log(events);
2516 $scope.eventSource = $scope.events;
2517
2518 // console.log(uiCalendarConfig.calendars['schedule']);
2519 // uiCalendarConfig.calendars.schedule.fullCalendar('refetchEvents');
2520 if ( uiCalendarConfig.calendars[ 'schedule' ] != undefined ) /* had to add this if statement because it was running this code before the calendars array was initialized */ {
2521 uiCalendarConfig.calendars.schedule.fullCalendar ( 'removeEvents' );
2522 uiCalendarConfig.calendars.schedule.fullCalendar ( 'addEventSource' , $scope.eventSource );
2523 }
2524
2525 $scope.eventSources = $scope.events;
2526 // }
2527
2528 // return eventSources;
2529 } )
2530 $scope.cancelBooking = function ( event ) {
2531 event.booking_status = 3;
2532 $http.put ( API_URL + 'api/v1/bookings/' + event.id , event )
2533 .success ( function ( response ) {
2534 // $ionicHistory.nextViewOptions({
2535 // disableBack: true
2536 // });
2537 // $state.go('app.booking');
2538 $scope.closeThisDialog ( 1 );
2539 } )
2540
2541 .error ( function ( response ) {
2542 $scope.bookingError = true;
2543 $scope.bookingErrorText = "Failed to cancel booking. Please contact support.";
2544 // console.log(response);
2545 } )
2546 }
2547
2548 //feature to cancel multiple bookings (repeated bookings)
2549 $scope.cancelReservationBookings = function (event) {
2550 var eventID = event.id;
2551 $scope.bookings = {};
2552 $scope.bookings.reservation_group = event.reservation_group;
2553
2554 $http.post ( API_URL + 'api/v1/cancel_recurring', $scope.bookings )
2555 .success ( function ( response ) {
2556 $scope.closeThisDialog ( 1 );
2557 } )
2558 .error ( function ( response ) {
2559 $scope.closeThisDialog ( 1 );
2560 $scope.bookingError = true;
2561 $scope.bookingErrorText = "Failed to cancel booking. Please contact support.";
2562 // console.log(response);
2563 } );
2564 }
2565
2566
2567
2568 $scope.closeInfo = function () {
2569 closeThisDialog ( 1 );
2570 }
2571 $scope.infoOnEventClick = function ( date , jsEvent , view ) {
2572 $scope.currentlyViewing = {};
2573 var event = $filter ( 'filter' ) ( $scope.pitch.bookings , {id: date.id} )[ 0 ];
2574 if ( event.booking_type != 3 ) {
2575 $scope.currentlyViewing.event = event;
2576 $scope.currentlyViewing.title = date.eventTime;
2577 BookingService.addEventData ( event.id , event.match_date, date.eventTime, event.reservation_group);
2578 $scope.currentlyViewing.date = event.match_date;
2579 $scope.currentlyViewing.name = event.booking_name;
2580 $scope.currentlyViewing.phone = event.booking_phone_number;
2581
2582 $scope.currentlyViewing.repeatedBooking = ( (event.reservation_group != '0') ? true : false);
2583 //console.log("value of reservation group is")
2584 //console.log(event.reservation_group);
2585
2586 $scope.currentlyViewing.maximumSlotPossible = BookingService.getMaximumSlot();
2587 console.log("maximumSlotPossible");
2588 console.log($scope.currentlyViewing.maximumSlotPossible);
2589
2590 if ( $rootScope.currentUser.roles[ 0 ].slug == 'admin' ) {
2591 $scope.currentlyViewing.allowCancel = true; //if you admin allow cancel any kind of bookingsfad
2592 } else {
2593 $scope.currentlyViewing.allowCancel = ((event.booking_type == 2 || event.booking_type == "2") && event.user_id == $rootScope.currentUser.id) ? true : false;
2594 }
2595
2596 ngDialog.open ( {
2597 template: 'viewBookingInfoModal' ,
2598 controller: 'ScheduleController' ,
2599 scope: $scope ,
2600 className: 'ngdialog-theme-default ngdialog-theme-custom'
2601 } );
2602 }
2603 };
2604 };
2605
2606 closeConfirm.$inject = [
2607 '$scope' ,
2608 '$rootScope',
2609 '$http' ,
2610 '$timeout' ,
2611 '$stateParams' ,
2612 '$state' ,
2613 'ngDialog' ,
2614 'BookingService' ,
2615 'PitchService' ,
2616 'uiCalendarConfig' ,
2617 '$compile' ,
2618 '$filter' ,
2619 '$interval' ,
2620 'RtSocket' ,
2621 '$auth' ,
2622 'whereFilter'
2623 ];
2624 function closeConfirm($scope , $rootScope , $http , $timeout , $stateParams , $state , ngDialog , BookingService , PitchService , uiCalendarConfig , $compile , $filter , $interval , RtSocket , $auth , whereFilter ) {
2625 $scope.closeDialogue = function () {
2626 $scope.closeThisDialog ( 1 );
2627 $state.go ( 'app.schedule' , {id: $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id} );
2628 }
2629 }
2630
2631 editBooking.$inject = [
2632 '$scope' ,
2633 '$http' ,
2634 '$timeout' ,
2635 '$stateParams' ,
2636 '$state' ,
2637 'ngDialog' ,
2638 'BookingService' ,
2639 'PitchService' ,
2640 'uiCalendarConfig' ,
2641 '$compile' ,
2642 '$filter' ,
2643 '$interval' ,
2644 'RtSocket' ,
2645 '$auth' ,
2646 'whereFilter'
2647 ];
2648 function editBooking ( $scope , $http , $timeout , $stateParams , $state , ngDialog , BookingService , PitchService , uiCalendarConfig , $compile , $filter , $interval , RtSocket , $auth , whereFilter ) {
2649 $scope.currentlyViewing = {};
2650 var booking_dataArray = BookingService.getEventData ();
2651 $scope.currentlyViewing.name = booking_dataArray[0];
2652 $scope.currentlyViewing.date = booking_dataArray[1];
2653 $scope.currentlyViewing.timing = booking_dataArray[2];
2654 $scope.currentlyViewing.recurringEvent = ( (booking_dataArray != '0') ? true : false);
2655
2656 $scope.currentlyViewing.confirmMultipleEdit = false;
2657
2658 console.log(booking_dataArray);
2659 console.log($scope.currentlyViewing.recurringEvent);
2660
2661
2662
2663 var beginningTime = $scope.currentlyViewing.timing.split(" - ")[0];
2664 var endingTime = $scope.currentlyViewing.timing.split(" - ")[1];
2665 var displayDate = moment($scope.currentlyViewing.date).format( "YYYY-MM-DD" );
2666
2667 beginningTime = new Date ("1/1/2013 " + beginningTime);
2668 endingTime = new Date ("1/1/2013 " + endingTime);
2669
2670 $scope.newTiming = {};
2671 $scope.newTiming.specificTime = beginningTime;
2672 beginningTime = moment(beginningTime);
2673 endingTime = moment(endingTime);
2674
2675 $scope.newTiming.date = $scope.currentlyViewing.date;
2676
2677 $scope.newTiming.specificDate = moment($scope.newTiming.date + ' ' + beginningTime);
2678
2679 $scope.newTiming.timing = $scope.currentlyViewing.timings;
2680 $scope.newTiming.duration = (endingTime).diff(beginningTime, "minute");
2681
2682 $scope.customDisplayDate = new Date($scope.newTiming.date);
2683
2684 $scope.saveChanges = function ( ) {
2685 if ($scope.currentlyViewing.confirmMultipleEdit) {
2686 console.log("can edit multiple");
2687 }
2688 else {
2689 console.log("can't edit multiple bookings");
2690 }
2691 var duration = parseInt($scope.newTiming.duration);
2692
2693 if ($scope.newTiming.specificDate == undefined) {
2694
2695 $scope.newTiming.specificDate = new Date($scope.newTiming.date) ;
2696 }
2697 $scope.newTiming.specificDate.setHours($scope.newTiming.specificTime.getHours());
2698 $scope.newTiming.specificDate.setMinutes($scope.newTiming.specificTime.getMinutes());
2699
2700 var dataDate = moment ( $scope.newTiming.specificDate ).format ( "YYYY-MM-DD" );
2701
2702 var dataTime = moment ( $scope.newTiming.specificDate ).format ( "HH:mm:ss" );
2703 var endTime = moment(moment ( dataDate + " " + dataTime)).add(duration, 'm');
2704 endTime = moment ( endTime ).format ( "HH:mm:ss" );
2705
2706 $scope.editDataInfo = {
2707 'match_date': dataDate,
2708 'match_time': dataTime,
2709 'match_end_time': endTime,
2710 'payment_order_duration': duration
2711 };
2712
2713 $http.put ( API_URL + 'api/v1/bookings/'+ $scope.currentlyViewing.name , $scope.editDataInfo )
2714 .success( function ( response ) {
2715 console.log(response);
2716 $scope.closeThisDialog ( 1 );
2717 } )
2718 .error( function ( response ) {
2719 $scope.message = function() {
2720 alert( response.message );
2721 }
2722 $scope.message();
2723 })
2724
2725 }
2726
2727 }
2728
2729
2730
2731 editMultipleBooking.$inject = [
2732 '$scope' ,
2733 '$http' ,
2734 '$timeout' ,
2735 '$stateParams' ,
2736 '$state' ,
2737 'ngDialog' ,
2738 'BookingService' ,
2739 'PitchService' ,
2740 'uiCalendarConfig' ,
2741 '$compile' ,
2742 '$filter' ,
2743 '$interval' ,
2744 'RtSocket' ,
2745 '$auth' ,
2746 'whereFilter'
2747 ];
2748 function editMultipleBooking ( $scope , $http , $timeout , $stateParams , $state , ngDialog , BookingService , PitchService , uiCalendarConfig , $compile , $filter , $interval , RtSocket , $auth , whereFilter ) {
2749 $scope.currentlyViewing = {};
2750 var booking_dataArray = BookingService.getEventData ();
2751 $scope.currentlyViewing.name = booking_dataArray[0];
2752 $scope.currentlyViewing.date = booking_dataArray[1];
2753 $scope.currentlyViewing.timing = booking_dataArray[2];
2754 $scope.currentlyViewing.recurringEvent = booking_dataArray[3];
2755
2756
2757 var beginningTime = $scope.currentlyViewing.timing.split(" - ")[0];
2758 var endingTime = $scope.currentlyViewing.timing.split(" - ")[1];
2759
2760 beginningTime = new Date ("1/1/2013 " + beginningTime);
2761 endingTime = new Date ("1/1/2013 " + endingTime);
2762
2763
2764 $scope.newTiming = {};
2765 $scope.newTiming.specificTime = beginningTime;
2766 beginningTime = moment(beginningTime);
2767 endingTime = moment(endingTime);
2768
2769 $scope.newTiming.date = $scope.currentlyViewing.date;
2770
2771 $scope.newTiming.specificDate = moment($scope.newTiming.date + ' ' + beginningTime);
2772
2773 $scope.newTiming.timing = $scope.currentlyViewing.timings;
2774 $scope.newTiming.duration = (endingTime).diff(beginningTime, "minute");
2775
2776 $scope.customDisplayDate = new Date($scope.newTiming.date);
2777
2778
2779
2780 $scope.saveChanges = function ( ) {
2781
2782 $scope.newbookingData = {
2783 'bookingGroup': $scope.currentlyViewing.recurringEvent
2784 };
2785
2786 console.log($scope.newbookingData);
2787
2788 $http.get( API_URL + 'api/v1/bookings/' + '?bookingGroup=' + $scope.currentlyViewing.recurringEvent)
2789 .success( function ( response ) {
2790 console.log(response);
2791 //$scope.closeThisDialog ( 1 );
2792 } )
2793 .error( function ( response ) {
2794 $scope.message = function() {
2795 alert( response.message );
2796 }
2797 $scope.message();
2798 })
2799
2800 }
2801
2802
2803
2804
2805
2806 $scope.saveChangess = function ( ) {
2807
2808 var duration = parseInt($scope.newTiming.duration);
2809 $scope.newTiming.specificDate = new Date("1/1/2016") ;
2810 $scope.newTiming.specificDate.setHours($scope.newTiming.specificTime.getHours());
2811 $scope.newTiming.specificDate.setMinutes($scope.newTiming.specificTime.getMinutes());
2812
2813 var dataDate = moment ( $scope.newTiming.specificDate ).format ( "YYYY-MM-DD" );
2814 var dataTime = moment ( $scope.newTiming.specificDate ).format ( "HH:mm:ss" );
2815 var endTime = moment(moment ( dataDate + " " + dataTime)).add(duration, 'm');
2816 endTime = moment ( endTime ).format ( "HH:mm:ss" );
2817
2818 $scope.editDataInfo = {
2819 'matchDate': dataDate,
2820 'match_time': dataTime,
2821 'match_end_time': endTime,
2822 'payment_order_duration': duration,
2823 'bookingGroup': $scope.currentlyViewing.recurringEvent
2824 };
2825
2826 console.log($scope.editDataInfo);
2827
2828
2829 $http.post ( API_URL + 'api/v1/edit_recurring', $scope.editDataInfo )
2830 .success( function ( response ) {
2831 console.log(response);
2832
2833 $scope.closeThisDialog ( 1 );
2834 } )
2835 .error( function ( response ) {
2836 $scope.message = function() {
2837 alert( response.message );
2838 }
2839 $scope.message();
2840 });
2841
2842 weofweoiuhf
2843
2844 }
2845
2846 }
2847
2848
2849
2850 repeatedBookingCtrl.$inject = [
2851 '$q',
2852 '$scope' , '$http' , '$timeout' , '$rootScope' , '$stateParams' , '$state' , 'ngDialog' , 'BookingService' , 'PitchService' , '$interval' , 'uiCalendarConfig' , '$auth' ];
2853 function repeatedBookingCtrl (
2854 $q,
2855 $scope , $http , $timeout , $rootScope , $stateParams , $state , ngDialog , BookingService , PitchService , $interval , uiCalendarConfig , $auth ) {
2856 $scope.booking = BookingService.booking ();
2857 $scope.pitchService = PitchService.pitchData;
2858
2859 $scope.addError = false;
2860
2861 var pitchData = {};
2862 var arr = Object.keys ( $scope.pitchService );
2863
2864 $scope.closetheDiaogue = function () {
2865 ngDialog.open ( {
2866 template: 'closeConfirm' ,
2867 controller: 'closeConfirm' ,
2868 preCloseCallback: function ( ) {
2869 $state.go('app.schedule', {id: $rootScope.currentUser.stadiums[0].pitches[0].id});
2870 },
2871 className: 'ngdialog-theme-default ngdialog-theme-custom'
2872 } );
2873 }
2874
2875
2876 pitchData = $scope.pitchService[ arr[ 0 ] ];
2877
2878 //New Admin Wide Stadium Browser
2879 $scope.changeStadiumMessage = null;
2880 $scope.changeStadiumList = [];
2881 $scope.changeStadium = function () {
2882 //Fetch list of stadiums
2883 $scope.changeStadiumMessage = 'Loading...';
2884 $scope.changeStadiumList = [];
2885 $http.get ( API_URL + 'api/v1/stadium_list' )
2886 .success ( function ( response ) {
2887 $scope.changeStadiumMessage = null;
2888 $scope.changeStadiumList = response.data;
2889 } )
2890 .error ( function ( response ) {
2891 $scope.changeStadiumMessage = 'Error occured during loading. Try again later.';
2892 $scope.changeStadiumList = [];
2893 } );
2894 };
2895 $scope.changePitchList = function ( stadium ) {
2896 $scope.admPitchList = stadium.pitches;
2897 };
2898
2899 $scope.admPitchList = ($rootScope.currentUser.stadiums[ 0 ].pitches); //Only pitches on controll
2900
2901 $scope.activePitchId = null;
2902 $scope.numnberOfConflicts = 0;
2903 $scope.conflictingDates = 0;
2904
2905
2906 $scope.checkForSlot = function( data ) {
2907
2908 $rootScope.app.transitionLoading = true;
2909
2910 var startDate = moment ( data.startDate ).format ( "YYYY-MM-DD" );
2911 var startTime = moment ( data.startTime ).format ( "HH:mm:ss" );
2912 var endTime = moment(data.startTime).add ( parseInt ( data.singleSelect ) , "m" ).format( "HH:mm:ss" );
2913 var endDate = moment ( data.endDate ).format ( "YYYY-MM-DD" );
2914
2915 var allDates = [];
2916 var nextDate = moment ( data.startDate );
2917 allDates.push(moment ( nextDate ).format ( "YYYY-MM-DD" ));
2918 while ( nextDate.isBefore ( endDate ) ) {
2919 if ( data.optradio == "week" ) {
2920 nextDate.add ( 1 , 'w' );
2921 } else if ( data.optradio == "otherweek" ) {
2922 nextDate.add ( 2 , 'w' );
2923 } else if ( data.optradio == "month" ) {
2924 nextDate.add ( 1 , 'M' );
2925 }
2926 allDates.push(moment ( nextDate ).format ( "YYYY-MM-DD" ));
2927
2928 }
2929
2930
2931 var datesToCheck = {
2932 'pitch_id' : $scope.activePitchId ,
2933 'startTime' : startTime,
2934 'endTime' : endTime,
2935 'dates' : allDates
2936 };
2937
2938
2939 $http.post( API_URL + 'api/v1/checkrepeats' , datesToCheck)
2940 .success(function(response) {
2941 $scope.numnberOfConflicts = parseInt(response.messages);
2942 $scope.conflictingDates = response.datesConflicting;
2943
2944 $rootScope.app.transitionLoading = false;
2945 if ($scope.numnberOfConflicts == 0) {
2946 console.log("It comes here");
2947 $scope.btnRepeatedBooking(data);
2948 }
2949 else
2950 $scope.addError = true;
2951 })
2952 .error(function (response) {
2953 $rootScope.app.transitionLoading = false;
2954 $scope.addErrorText = "There was an error parsing the request. Please try again later and contact support if the problem still exists";
2955 })
2956
2957 return 0;
2958 }
2959
2960 $scope.cancelPlans = function (request) {
2961 if (request == 1) {
2962 $state.go ( 'app.schedule' , {id: $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id} );
2963 }
2964 else
2965 $scope.addError = false;
2966 }
2967
2968 $scope.btnRepeatedBooking = function ( data ) {
2969
2970 $scope.reservationGroup = {}
2971 $scope.reservationGroup.id = Math.random().toString(20).substring(7);
2972
2973 $rootScope.app.transitionLoading = true;
2974
2975 var actionArray = [];
2976
2977 if ( data ) {
2978 if ( ($scope.activePitchId != null) && (data.name != null) && (data.startDate != null) && (data.startTime != null) && (data.endDate != null) && /*(data.endTime != null) &&*/ (data.optradio != null) && (data.singleSelect != null) ) {
2979 $scope.errorMessage = "";
2980 var matchStartTime = moment ( moment ().format ( "YYYY-MM-DD" ) + " " + pitchData.stadium.opening_time );
2981 var matchEndTime = moment ( moment ().format ( "YYYY-MM-DD" ) + " " + pitchData.stadium.closing_time );
2982 var matchBookedEndTime = moment ( moment ( data.endDate ).format ( "YYYY-MM-DD" ) + " " + pitchData.stadium.closing_time );
2983 var matchBookedStartTime = moment ( moment ( data.startDate ).format ( "YYYY-MM-DD" ) + " " + pitchData.stadium.closing_time );
2984 var startDate = moment ( data.startDate ).format ( "YYYY-MM-DD" );
2985 startDate = startDate + " " + moment ( data.startTime ).format ( "HH:mm:ss" );
2986 startDate = moment ( startDate );
2987
2988 var bookedEndTime = matchBookedStartTime.clone ();
2989 bookedEndTime.subtract ( parseInt ( data.singleSelect ) , "m" );
2990
2991 var bookEndDate = startDate.clone ();
2992 bookEndDate.add ( parseInt ( data.singleSelect ) , "m" );
2993
2994 var endDate = moment ( data.endDate ).format ( "YYYY-MM-DD" );
2995 data.endTime = data.startTime; //Fake Fix
2996
2997 endDate = endDate + " " + moment ( data.endTime ).format ( "HH:mm:ss" );
2998 endDate = moment ( endDate ).add ( 1 , 'day' );
2999
3000 if ( (startDate.valueOf () <= endDate.valueOf ()) && (matchBookedEndTime.valueOf () >= matchStartTime.valueOf ()) ) {
3001
3002 $rootScope.app.transitionLoading = true;
3003 $scope.errorMessage = "";
3004 var nextDate = startDate.clone ();
3005
3006 while ( nextDate.isBefore ( endDate ) ) {
3007
3008 var matchEndTime = nextDate.clone ();
3009 matchEndTime.add ( parseInt ( data.singleSelect ) , "m" );
3010 $scope.match_end_timeNew = matchEndTime.format ( "HH:mm:ss" );
3011
3012
3013 $scope.bookingInfo = {
3014 'user_id_t' : ( ($scope.user_id_t == undefined) ? $rootScope.currentUser.id : $scope.user_id_t ) ,
3015 'pitch_id': $scope.activePitchId ,
3016 'match_date': nextDate.format ( 'YYYY-MM-DD' ) ,
3017 'match_time': nextDate.format ( 'HH:mm:ss' ) ,
3018
3019 'booking_name': data.name ,
3020 'booking_phone_number': data.phone_number ,
3021
3022 'booking_type': data.booking_type ,
3023 'match_end_time': $scope.match_end_timeNew ,
3024 'payment_method': 1 ,
3025 'booking_status': 1,
3026 'reservation_group': $scope.reservationGroup.id
3027 };
3028
3029 var promise = $http.post ( API_URL + 'api/v1/bookings' , $scope.bookingInfo )
3030 .success ( function ( response ) {
3031 BookingService.setData ( response );
3032 $scope.booking = BookingService.booking ();
3033
3034 } )
3035 .error ( function ( response ) {
3036 $scope.bookingError = true;
3037 $scope.bookingErrorText = "An error occurred. Please check your input and try again.";
3038 } );
3039
3040 actionArray.push(promise);
3041
3042 if ( data.optradio == "week" ) {
3043 nextDate.add ( 1 , 'w' );
3044 } else if ( data.optradio == "otherweek" ) {
3045 nextDate.add ( 2 , 'w' );
3046 } else if ( data.optradio == "month" ) {
3047 nextDate.add ( 1 , 'M' );
3048 }
3049 //console.log ( "next date " , nextDate.format ( "DD-MM-YYYY HH:mm:ss" ) );
3050 }
3051 $q.all(actionArray).then(function (ret) {
3052 console.log('Popped');
3053
3054 });
3055
3056 $rootScope.app.transitionLoading = false;
3057 $scope.closetheDiaogue();
3058 //$state.go ( 'app.schedule' , {id: $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id} );
3059
3060 } else {
3061 $scope.errorMessage = "Please enter valuable date and time. Stadium available Between(" + matchStartTime.format ( 'HH:mm:ss' ) + " - " + matchEndTime.format ( 'HH:mm:ss' ) + ")";
3062 }
3063
3064
3065 }
3066
3067 } else {
3068 $scope.errorMessage = "All fields are mandatory";
3069 }
3070 $rootScope.app.transitionLoading = false;
3071
3072 }
3073
3074
3075 }
3076
3077 NewBookingCtrl.$inject = [
3078 '$scope' ,
3079 '$http' ,
3080 '$timeout' ,
3081 '$rootScope' ,
3082 '$stateParams' ,
3083 '$state' ,
3084 'ngDialog' ,
3085 'BookingService' ,
3086 'PitchService' ,
3087 '$interval' ,
3088 'uiCalendarConfig' ,
3089 '$auth'
3090 ];
3091 function NewBookingCtrl ( $scope , $http , $timeout , $rootScope , $stateParams , $state , ngDialog , BookingService , PitchService , $interval , uiCalendarConfig , $auth ) {
3092
3093 $scope.booking = BookingService.booking ();
3094 $scope.pitchService = PitchService.pitchData;
3095
3096 $scope.isAdmin = ( ($rootScope.currentUser.roles[ 0 ].slug == 'admin') ? 1 : 0);
3097 $scope.slotTimeChange = function () {
3098
3099 if ( $scope.singleSelect == '' || $scope.singleSelect == undefined || $scope.singleSelect == null )
3100 $scope.singleSelect = '01:30:00';
3101 // var NewAddedTime =moment.utc(moment($scope.singleSelect,"HH:mm:ss").add(moment($scope.booking.data.match_time,"HH:mm:ss"))).format("HH:mm:ss");
3102 // $scope.booking.data.match_end_time = moment(moment.duration($scope.booking.data.match_time).add($scope.singleSelect)._milliseconds).format('hh:mm:ss');
3103 var ms = moment.duration ( $scope.booking.data.match_time ).add ( $scope.singleSelect )._milliseconds;
3104 var temp = moment.utc ( ms );
3105 $scope.end_time = temp.format ( "hh:mm A" );
3106 $scope.booking.data.match_end_time = temp.format ( "HH:mm:ss" );
3107 $scope.booking.data.payment_order_duration = ( ($scope.singleSelect == "02:00:00") ? 120 : ( ($scope.singleSelect == "01:30:00") ? 90 : 60 ) );
3108 // timeHours = moment.duration($scope.booking.data.match_time).add($scope.singleSelect);
3109 // timeMinutes = moment.duration($scope.booking.data.match_time).add($scope.singleSelect);
3110 $scope.booking.data.user_id = $scope.user_id_t;
3111 $http.put ( API_URL + 'api/v1/bookings/' + $scope.booking.data.id , $scope.booking.data )
3112 .success ( function ( response ) {
3113 $scope.end_time = temp.format ( "hh:mm A" );
3114 } )
3115 .error ( function ( response ) {
3116 $scope.bookingError = true;
3117 $scope.bookingErrorText = "An error occurred. Please check your input and try again.";
3118 console.log ( response );
3119 } );
3120
3121 }; //timeSlot Change
3122
3123 if ( ! $auth.isAuthenticated () ) {
3124 $state.go ( 'login' );
3125 }
3126
3127 var end_time = angular.copy ( $scope.booking.date );
3128 $scope.start_time = $scope.booking.date.format ( 'hh:mm A' );
3129 $scope.end_time = $scope.booking.dateEnd.format ( 'hh:mm A' );
3130
3131 $rootScope.match_end_time = $scope.singleSelect;
3132 $scope.date = $scope.booking.date.format ( "dddd - Do of MMMM" );
3133
3134 $rootScope.isTransacting = undefined;
3135 $scope.bookingError = false;
3136 $scope.booking = BookingService.booking ();
3137 $scope.booking.payment_method = 1;
3138 $scope.timeLeft = moment.duration ( 4 , 'minutes' );
3139
3140 $scope.pitch = $scope.pitchService[ $scope.booking.pitch.id ];
3141 // console.log($scope.booking.time);
3142
3143
3144
3145 $scope.payload = {
3146 'pitch_id': $scope.booking.pitch.id ,
3147 'match_date': $scope.booking.date.format ( 'YYYY-MM-DD' ) ,
3148 'match_time': $scope.booking.time.format ( 'HH:mm:ss' )
3149 };
3150
3151
3152 //To add: Async call to this.
3153 $scope.maximumSlotPossible = -1;
3154 $http.post( API_URL + 'api/v1/check_slot_possibility', $scope.payload)
3155 .success ( function ( response ) {
3156 $scope.maximumSlotPossible = parseInt(response.message);
3157 })
3158 .error ( function ( response ) {
3159 console.log("this is a error message");
3160 console.log(response);
3161 } )
3162 ;
3163 BookingService.setMaximumSlot($scope.maximumSlotPossible);
3164
3165 $scope.singleTime = ( ($scope.maximumSlotPossible > 60 || $scope.maximumSlotPossible == -1) ? '01:30:00' : '01:00:00' );
3166 var ms = moment.duration ( $scope.booking.time.format ( 'HH:mm:ss' ) ).add ( $scope.singleTime )._milliseconds;
3167 var temp = moment.utc ( ms );
3168 $scope.end_time = temp.format ( "hh:mm A" );
3169 $scope.match_end_timeNew = temp.format ( "HH:mm:ss" );
3170 $scope.bookingInfo = {
3171 'pitch_id': $scope.booking.pitch.id ,
3172 'match_date': $scope.booking.date.format ( 'YYYY-MM-DD' ) ,
3173 'match_time': $scope.booking.time.format ( 'HH:mm:ss' ) ,
3174 'match_end_time': $scope.match_end_timeNew ,
3175 'payment_method': $scope.booking.payment_method ,
3176 'booking_status': 2,
3177 'reservation_group': '0',
3178 'defaults': 90
3179 };
3180
3181
3182
3183 $http.post ( API_URL + 'api/v1/bookings' , $scope.bookingInfo )
3184 .success ( function ( response ) {
3185 BookingService.setData ( response );
3186 $scope.booking = BookingService.booking ();
3187 $scope.cancelTimer = $interval ( function () {
3188 $scope.timeLeft.subtract ( 1 , 's' );
3189 $scope.timeLeftText ();
3190 } , 1000 , 240 );
3191 } )
3192 .error ( function ( response ) {
3193 $scope.bookingError = true;
3194 // console.log(response);
3195 $scope.bookingErrorText = "An error occurred. Please check your input and try again.";
3196 } );
3197
3198 //Allow Continue
3199 $scope.allowContinue = function () {
3200 if ( $scope.timeLeft.asSeconds () > 0 ) {
3201 return true;
3202 } else {
3203 return false;
3204 }
3205 };
3206
3207 //Time Left Text
3208 $scope.timeLeftText = function () {
3209 var timeLeftAsSeconds = parseInt ( $scope.timeLeft.asSeconds () );
3210 var textToShow = "";
3211 if ( parseInt ( timeLeftAsSeconds / 60 ) > 0 ) {
3212 textToShow = (parseInt ( timeLeftAsSeconds / 60 )) + "m " + (timeLeftAsSeconds % 60) + "s";
3213 } else {
3214 textToShow = (timeLeftAsSeconds % 60) + "s";
3215 }
3216 return textToShow;
3217 };
3218
3219 //Get Color
3220 $scope.getEventColor = function ( event ) { //Copy
3221
3222
3223
3224 /*
3225 if (event.reservation_group != '0') {
3226 return "#581845";
3227 }
3228 */
3229 if ( event.booking_status == 1 || event.booking_status == "1" ) {
3230
3231 if ( event.booking_type == 1 || event.booking_type == "1" ) {
3232 return "#85C140";
3233 } else if ( event.booking_type == 3 || event.booking_type == "3" ) {
3234 return "#666666";
3235 } else {
3236 return "#00c0ef";
3237 }
3238
3239 } else {
3240 return "#E9FA4D";
3241 }
3242 };
3243
3244
3245 if ( ! $stateParams.id ) {
3246 $scope.pitchId = $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id;
3247 } else {
3248 $scope.pitchId = $stateParams.id;
3249 }
3250
3251
3252 //Confirm Bookage
3253 $scope.confirmBooking = function () {
3254
3255 if ( $scope.booking_name.length > 0 ) {
3256 $scope.booking.data.booking_name = $scope.booking_name;
3257 }
3258
3259 if ( $scope.booking_phone_number.length > 0 ) {
3260 $scope.booking.data.booking_phone_number = $scope.booking_phone_number;
3261 }
3262
3263 $scope.booking.data.payment_method = (($scope.booking.payment_method == undefined) ? 1 : $scope.booking.payment_method);
3264 $scope.booking.data.booking_status = 1;
3265
3266
3267 $scope.booking.data.user_id = ( ($scope.user_id_t == undefined) ? $rootScope.currentUser.id : $scope.user_id_t ) ;
3268 //create a new time to update.
3269 if ( $scope.singleSelect == '' || $scope.singleSelect == undefined || $scope.singleSelect == null )
3270 $scope.singleSelect = '01:30:00';
3271 var ms = moment.duration ( $scope.booking.data.match_time ).add ( $scope.singleSelect )._milliseconds;
3272 var temp = moment.utc ( ms );
3273 $scope.end_time = temp.format ( "hh:mm A" );
3274 $scope.booking.data.match_end_time = temp.format ( "HH:mm:ss" );
3275
3276 $http.put ( API_URL + 'api/v1/bookings/' + $scope.booking.data.id , $scope.booking.data )
3277 .success ( function ( response ) {
3278
3279 // var time_midpoint = ( new Date(range_view.start).getTime() + new Date(range_view.end).getTime() )/2;
3280 // var time_diff = Math.abs( new Date(range_view.end).getTime() - new Date(range_view.start).getTime() )/(60*60*24*1000);
3281 // var frame_date = moment(time_midpoint).format("DD-MM-YYYY");
3282 // var frame_width = time_diff;
3283
3284 var frame_date = moment ( $scope.booking.date ).format ( "DD-MM-YYYY" );
3285 var frame_width = 7;
3286
3287 $http.get ( API_URL + 'api/v1/pitches/' + $scope.pitchId + '?format=fetchlists' + '&frame_set=' + frame_date + '&frame_width=' + frame_width ).success ( function ( response ) {
3288 //
3289 PitchService.pitchData[ $scope.pitchId ] = response.data;
3290 $scope.pitch = PitchService.pitchData[ $scope.pitchId ];
3291 var pitchPrice = PitchService.pitchData[ $scope.pitchId ].pitch_price;
3292 var realPrice = 0;
3293 var now = $scope.booking.data.match_end_time;
3294 var then = $scope.booking.data.match_time;
3295
3296 var timeDifference = moment.utc ( moment ( now , "HH:mm:ss" ).diff ( moment ( then , "HH:mm:ss" ) ) ).format ( "HH:mm:ss" );
3297 var i;
3298 for ( i = 0 ; i < pitchPrice.length ; i ++ ) {
3299 if ( pitchPrice[ i ].pitch_duration == timeDifference ) {
3300 $scope.booking.data.amount_paid = pitchPrice[ i ].pitch_price;
3301 $http.put ( API_URL + 'api/v1/bookings/' + $scope.booking.data.id , $scope.booking.data )
3302 .success ( function ( response ) {
3303
3304 } )
3305 .error ( function ( response ) {
3306 $scope.bookingError = true;
3307 $scope.bookingErrorText = "An error occurred. Please check your input and try again.";
3308 // console.log(response);
3309 } )
3310 }
3311
3312 }
3313 var events = [];
3314 var bookingsData = $scope.pitch.bookings;
3315 var getBookingInCalendarFormat = function ( element , index , array ) {
3316 var calendarObject = {};
3317
3318 var startTime = moment ( element.match_date + ' ' + element.match_time );
3319 var endTime = moment ( element.match_date + ' ' + element.match_end_time );
3320
3321 if ( element.match_time < element.match_end_time ) {
3322 calendarObject.title = element.booking_name;
3323 } else {
3324 calendarObject.title = '> ' + element.booking_name;
3325 endTime = endTime.add ( 'day' , 1 );
3326 }
3327
3328 var eventTitle = startTime.format ( 'hh:mm A' ) + " - " + endTime.format ( 'hh:mm A' )
3329 calendarObject.start = startTime.format ( "YYYY-MM-DD HH:mm" );
3330 calendarObject.end = endTime.format ( "YYYY-MM-DD HH:mm" );
3331 //calendarObject.title =element.booking_name;
3332 calendarObject.id = element.id;
3333 calendarObject.allDay = false;
3334 calendarObject.backgroundColor = $scope.getEventColor ( element ); //Info (aqua)
3335 calendarObject.borderColor = $scope.getEventColor ( element ); //Info (aqua)
3336 events.push ( calendarObject );
3337
3338 }
3339
3340 bookingsData.forEach ( getBookingInCalendarFormat );
3341 $scope.eventSource = events;
3342
3343
3344 if ( uiCalendarConfig.calendars[ 'schedule' ] != undefined ) // had to add this if statement because it was running this code before the calendars array was initialized
3345 {
3346 uiCalendarConfig.calendars.schedule.fullCalendar ( 'removeEvents' );
3347 uiCalendarConfig.calendars.schedule.fullCalendar ( 'addEventSource' , $scope.eventSource );
3348 }
3349
3350 $scope.closeThisDialog ( 1 );
3351 } )
3352 .error ( function () {
3353 // console.log(response.error);
3354 } );
3355
3356 } )
3357 .error ( function ( response ) {
3358 $scope.bookingError = true;
3359 $scope.bookingErrorText = "An error occurred. Please check your input and try again.";
3360 // console.log(response);
3361 } );
3362 }; //Confirm Bookage!
3363
3364
3365 $scope.cancelBooking = function (cancelledBySystem) {
3366
3367 if ( cancelledBySystem == 0 || cancelledBySystem == undefined ) {
3368 $scope.closeThisDialog ( 1 );
3369 return null;
3370 }
3371 if ( $scope.booking.payment_method == undefined ) {
3372 console.log("has not been defnied");
3373 }
3374 //$scope.booking.data.payment_method = 1; //becuase it is already cancelled. Payment method should not be valid here.
3375 if ($scope.booking.data == undefined)
3376 $scope.booking.data = {}
3377 $scope.booking.data.booking_status = 4;
3378
3379
3380 $rootScope.app.transitionLoading = true;
3381 var tryBookingTurn = 1;
3382 while(cancelledBySystem && tryBookingTurn < 5) {
3383
3384 tryBookingTurn += 1;
3385 $http.put ( API_URL + 'api/v1/bookings/' + $scope.booking.data.id , $scope.booking.data )
3386 .success ( function ( response ) {
3387 cancelledBySystem = 0;
3388 $scope.closeThisDialog ( 1 );
3389 } )
3390 .error ( function ( response ) {
3391 $scope.bookingError = true;
3392 $scope.closeThisDialog(1);
3393 $scope.bookingErrorText = "Failed to cancel booking. Please contact support.";
3394 } )
3395 }
3396 $rootScope.app.transitionLoading = false;
3397 }
3398 }
3399
3400 BookingService.$inject = [];
3401 function BookingService () {
3402 this.bookingData = {};
3403 this.booking = function () {
3404 return this.bookingData;
3405 };
3406
3407 this.setPitch = function ( pitch ) {
3408 this.bookingData.pitch = pitch;
3409 };
3410
3411 this.getPitch = function () {
3412 return this.bookingData.pitch;
3413 };
3414
3415 this.setDate = function ( date ) {
3416 this.bookingData.date = date;
3417 };
3418
3419 this.getDate = function () {
3420 return this.bookingData.date;
3421 };
3422
3423 this.setTime = function ( time ) {
3424 this.bookingData.time = time;
3425 };
3426
3427 this.setData = function ( data ) {
3428 this.bookingData.data = data;
3429 };
3430
3431 this.getData = function () {
3432 return this.bookingData.data;
3433 };
3434
3435 this.getTime = function () {
3436 return this.bookingData.time;
3437 };
3438
3439 this.setPaymentMethod = function ( paymentMethod ) {
3440 this.bookingData.paymentMethod = paymentMethod;
3441 };
3442
3443 this.getPaymentMethod = function () {
3444 return this.bookingData.paymentMethod;
3445 };
3446
3447 this.setBookingName = function ( bookingName ) {
3448 this.bookingData.bookingName = bookingName;
3449 };
3450
3451 this.getBookingName = function () {
3452 return this.bookingData.bookingName;
3453 };
3454
3455 this.setBookingPhoneNumber = function ( bookingPhoneNumber ) {
3456 this.bookingData.bookingPhoneNumber = bookingPhoneNumber;
3457 };
3458
3459 this.getBookingPhoneNumber = function () {
3460 return this.bookingData.bookingPhoneNumber;
3461 };
3462
3463 this.addEventData = function ( eventID , eventMatchDate, eventTime, recurringEvent ) {
3464 this.bookingData.idToEdit = eventID;
3465 this.bookingData.matchData = eventMatchDate;
3466 this.bookingData.eventTime = eventTime;
3467 this.bookingData.recurringEvent = recurringEvent;
3468 this.bookingData.completeData = [eventID, eventMatchDate, eventTime, recurringEvent];
3469 }
3470
3471 this.getEventData = function () {
3472 return this.bookingData.completeData;
3473 }
3474
3475 this.setMaximumSlot = function (minutes) {
3476 this.bookingData.maximumSlotPossible = minutes;
3477 }
3478
3479 this.getMaximumSlot = function (minutes) {
3480 return this.bookingData.maximumSlotPossible;
3481 }
3482
3483
3484 }
3485
3486 BookingEditService.$inject = [];
3487 function BookingEditService () {
3488
3489 var eventData = undefined
3490
3491 this.addEventData = function ( event ) {
3492 eventData = event
3493 }
3494
3495 var getEventData = function () {
3496 return this.eventData;
3497 }
3498 }
3499
3500
3501 PitchService.$inject = [ '$http' ];
3502 function PitchService ( $http ) {
3503
3504 this.pitchData = {};
3505
3506 this.pitches = function () {
3507 return this.pitchData;
3508 };
3509 }
3510
3511}) ();
3512
3513(function () {
3514 'use strict';
3515
3516 angular
3517 .module ( 'app.core' )
3518 .controller ( 'AuthController' , AuthController )
3519 .controller ( 'ProfileController' , ProfileController )
3520
3521 AuthController.$inject = [ '$scope' , '$location' , '$stateParams' , '$http' , '$state' , '$auth' , '$rootScope' , '$filter' ];
3522 function AuthController ( $scope , $location , $stateParams , $http , $state , $auth , $rootScope , $filter ) {
3523 var vm = this;
3524
3525 activate ();
3526
3527 ////////////////
3528
3529 function activate () {
3530 // bind here all data from the form
3531 vm.account = {};
3532 // place the message if something goes wrong
3533 vm.authMsg = '';
3534
3535 if ( ! $auth.isAuthenticated () ) {
3536
3537 vm.login = function () {
3538 vm.authMsg = '';
3539
3540
3541 $rootScope.app.transitionLoading = true;
3542 if ( vm.loginForm.$valid ) {
3543
3544 $auth.login ( {email: vm.account.email , password: vm.account.password} )
3545 .then ( function () {
3546 // Return an $http request for the authenticated user
3547 $http.get ( API_URL + 'api/v1/authenticate/user' ).success ( function ( response ) {
3548 // Stringify the retured data
3549 var user = JSON.stringify ( response.user );
3550 // Set the stringified user data into local storage
3551 var playerRole = $filter ( 'filter' ) ( response.user.roles , {slug: 'player'} );
3552 if ( playerRole.length > 0 ) {
3553 $auth.logout ();
3554 vm.authMsg = 'This dashboard is meant for Pitch Owners only. Please use the Malaeb App as a Player.';
3555 } else {
3556 localStorage.setItem ( 'user' , user );
3557 // Getting current user data from local storage
3558 $rootScope.currentUser = response.user;
3559 // $rootScope.currentUser = localStorage.setItem('user');;
3560
3561 if ( typeof( $rootScope.currentUser.stadiums ) === 'undefined' || $rootScope.currentUser.stadiums.length == 0 ) {
3562 $rootScope.currentUser.stadiums = [ {} ];
3563 $rootScope.currentUser.stadiums[ 0 ].pitches = [ {} ];
3564 $rootScope.currentUser.stadiums[ 0 ].pitches[ 0 ].id = 0;
3565 }
3566
3567 if ( $rootScope.redirectAfterLogin != undefined ) {
3568 var redirectTo = $rootScope.redirectAfterLogin;
3569 $rootScope.redirectAfterLogin = undefined;
3570 $state.go ( redirectTo );
3571 } else {
3572 $rootScope.app.transitionLoading = false;
3573 $state.go ( 'app.schedule' );
3574 }
3575 }
3576
3577
3578 } )
3579 .error ( function () {
3580 $rootScope.app.transitionLoading = false;
3581 vm.authMsg = 'Server Request Error';
3582
3583 } )
3584 } ).catch ( function ( error ) {
3585 vm.authMsg = 'Incorrect credentials.';
3586 $rootScope.app.transitionLoading = false;
3587 } );
3588 } else {
3589 // set as dirty if the user click directly to login so we show the validation messages
3590 /*jshint -W106*/
3591 vm.loginForm.account_email.$dirty = true;
3592 vm.loginForm.account_password.$dirty = true;
3593 }
3594 };
3595
3596 } else {
3597 $state.go ( 'app.schedule' );
3598 }
3599 }
3600
3601 }
3602
3603 ProfileController.$inject = [ '$scope' , '$location' , '$stateParams' , '$http' , '$state' , '$auth' , '$rootScope' ];
3604 function ProfileController ( $scope , $location , $stateParams , $http , $state , $auth , $rootScope ) {
3605
3606 if ( ! $auth.isAuthenticated () ) {
3607 $state.go ( 'login' );
3608 }
3609
3610 $scope.profile = $rootScope.currentUser;
3611
3612 $scope.errorMessage = "";
3613 $scope.updateProfile = function () {
3614 $scope.errorMessage = "";
3615
3616 var updatedProfile = {
3617 'id': $scope.profile.id ,
3618 'name': $scope.profile.name ,
3619 'email': $scope.profile.email ,
3620 };
3621 if ( $scope.profile.password ) {
3622 if ( $scope.profile.password.length > 0 ) {
3623 updatedProfile.password = $scope.profile.password;
3624 updatedProfile.password_confirmation = $scope.profile.password;
3625 }
3626 }
3627
3628 // if($scope.profileForm.$valid) {
3629 $http.put ( API_URL + 'api/v1/users/' + $scope.profile.id , updatedProfile ).success ( function ( response ) {
3630 $http.get ( API_URL + 'api/v1/authenticate/user' ).success ( function ( response ) {
3631 // Stringify the retured data
3632 var user = JSON.stringify ( response.user );
3633 // Set the stringified user data into local storage
3634 localStorage.setItem ( 'user' , user );
3635
3636 // Getting current user data from local storage
3637 $rootScope.currentUser = response.user;
3638 // $rootScope.currentUser = localStorage.setItem('user');;
3639
3640
3641 if ( $rootScope.redirectAfterLogin != undefined ) {
3642 var redirectTo = $rootScope.redirectAfterLogin;
3643 $rootScope.redirectAfterLogin = undefined;
3644 $state.go ( redirectTo );
3645 } else {
3646 $state.go ( 'app.schedule' );
3647 }
3648 } )
3649 .error ( function ( response ) {
3650 $scope.errorMessage = response.error;
3651
3652 } );
3653 } )
3654 .error ( function ( response ) {
3655 $scope.errorMessage = response.error;
3656
3657 } )
3658 }
3659
3660
3661 }
3662}) ();