11'use strict' ;
22
33angular . module ( 'myApp.controllers' , [ ] )
4+ . controller ( 'SiteCtrl' , [ '$scope' , 'cmsSiteSettings' , function ( $scope , cmsSiteSettings ) {
5+ $scope . site = {
6+ templates : {
7+ mainMenu : '/_partials/mainMenu.html'
8+ }
9+ } ;
10+ var siteSettings = cmsSiteSettings . get ( { } , function ( settings ) {
11+ if ( settings . variables ) {
12+ for ( var key in settings . variables ) {
13+ if ( settings . variables . hasOwnProperty ( key ) && key . substr ( 0 , 5 ) === 'site_' ) {
14+ $scope . site [ key . substr ( 5 ) ] = settings . variables [ key ] ;
15+ }
16+ }
17+ }
18+ } ) ;
19+ } ] )
20+
21+ . controller ( 'MainMenuCtrl' , [ '$scope' , 'cmsMainMenu' , function ( $scope , cmsMainMenu ) {
22+ $scope . mainMenu = [ ] ;
23+ var mainMenu = cmsMainMenu . get ( { } , function ( data ) {
24+ if ( data . links . length ) {
25+ for ( var i = 0 ; i < data . links . length ; i ++ ) {
26+ var link = data . links [ i ] . link ;
27+ if ( link . internal_path === '<front>' ) {
28+ link . path = '/' ;
29+ }
30+ else {
31+ link . path = '/' + link . alias ;
32+ }
33+ $scope . mainMenu . push ( data . links [ i ] . link ) ;
34+ }
35+ }
36+ } ) ;
37+ } ] )
38+
39+ . controller ( 'PageCtrl' , [ '$scope' , 'cmsNode' , 'cmsSiteSettings' , '$location' , 'cmsTemplate' , function ( $scope , cmsNode , cmsSiteSettings , $location , cmsTemplate ) {
40+ $scope . node = { } ;
41+ $scope . front = false ;
42+ var node = cmsNode . get ( { path : 'node/1' } , function ( data ) {
43+ if ( data . nodes && data . nodes [ 0 ] && data . nodes [ 0 ] . node ) {
44+ $scope . node = data . nodes [ 0 ] . node ;
45+ var siteSettings = cmsSiteSettings . get ( { } , function ( settings ) {
46+ if ( settings . variables ) {
47+ if ( settings . variables . site_frontpage ) {
48+ if ( $scope . node . path && $scope . node . path == settings . variables . site_frontpage || 'node/' + $scope . node . id == settings . variables . site_frontpage ) {
49+ $scope . front = true ;
50+ }
51+ }
52+
53+ if ( $scope . node . type && settings . variables . allowed_content_types && settings . variables . allowed_content_types . indexOf ( $scope . node . type ) !== - 1 ) {
54+ if ( $scope . path !== $scope . node . path ) {
55+ $location . path ( $scope . node . path ) . replace ( ) ;
56+ }
57+
58+ cmsTemplate . getPartial ( $scope . node ) . then ( function ( partialUrl ) {
59+ $scope . templateUrl = partialUrl ;
60+ } , function ( ) {
61+ $location . path ( '/404' ) ;
62+ } ) ;
63+ }
64+ else {
65+ $location . path ( '/404' ) ;
66+ }
67+ }
68+ } ) ;
69+ }
70+ } ) ;
71+ } ] ) ;
72+
473;
0 commit comments