var globalApp = angular.module( 'globalApp', [ 'ngCookies', 'ngRoute', 'ngTouch' ] ); var globalConfig = []; globalConfig.push( '$compileProvider' ); globalConfig.push( '$locationProvider' ); globalConfig.push( '$routeProvider' ); function ngGlobalConfig( $compileProvider, $locationProvider, $routeProvider ) { $compileProvider // .aHrefSanitizationWhitelist( /^\s*(https?|mailto|exturls?):/ ); $locationProvider.html5Mode( true ); $routeProvider // .when( '/', { template: '' } ) // .when( '/index.php', { template: '' } ) // .when( '/index-a', { template: '' } ) // .when( '/index-b', { template: '' } ) // .when( '/index-c', { template: '' } ) // .when( '/favorite', { template: '' } ) // .when( '/history', { template: '' } ) // .when( '/settings', { template: '' } ) // .otherwise( { template: '

Page not exists!

' } ); } globalConfig.push( ngGlobalConfig ); globalApp.config( globalConfig ); // --------- // Services // --------- globalApp.service( '$appVersion', [ '$cookies', function( $cookies ) { var this_ = this; this_.isNewVersion = function() { var serverVer = $cookies.get( 'appVersion' ); if ( serverVer ) { var localVer = localStorage.getItem( 'appVersion' ); if ( !localVer ) { localStorage.setItem( 'appVersion', serverVer ); } else if ( localVer !== serverVer ) { localStorage.setItem( 'appVersion', serverVer ); document.location.reload( true ); return true; } } return false; }; } ] ); // ----------- // Components // ----------- globalApp.component( 'pgIndexA', { templateUrl: '/components/index-a.php', controller: [ '$location', function( $location ) { var this_ = this; localStorage.setItem( 'appIsInit', true ); this_.goNext = function() { $location.url( '/index-b' ); }; this_.goPrev = function() { $location.url( '/index-c' ); }; } ] } ); globalApp.component( 'pgIndexB', { templateUrl: '/components/index-b.php', controller: [ '$location', function( $location ) { var this_ = this; this_.goNext = function() { $location.url( '/index-c' ); }; this_.goPrev = function() { $location.url( '/index-a' ); }; } ] } ); globalApp.component( 'pgIndexC', { templateUrl: '/components/index-c.php', controller: [ '$location', function( $location ) { var this_ = this; this_.goNext = function() { $location.url( '/index-a' ); }; this_.goPrev = function() { $location.url( '/index-b' ); }; } ] } ); globalApp.component( 'pgFavorite', { templateUrl: '/components/favorite.php', controller: [ '$appVersion', '$http', '$location', '$window', function( $appVersion, $http, $location, $window ) { var this_ = this; this_.isLoading = null; this_.listDocs = null; this_.pg = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/favorite.php', { params: $location.search() } ) // .then( function( response ) { if ( response.data.isUnknown ) { document.location.href = '/'; } if ( $appVersion.isNewVersion() ) { return true; } this_.isLoading = false; this_.listDocs = response.data.listDocs; this_.pg = response.data.pg; } ); }; this_.setPage = function( page ) { $location.search( 'page', page ); }; this_.toggleFav = function( doc ) { this_.isLoading = true; $http // .post( '/rest/_fav.php', { docId: doc.docId, isFav: +( !doc.isFav ) } ) // .then( function( response ) { this_.isLoading = false; loadData(); } ); }; this_.verifyUrl = function( doc ) { var url = ''; url += 'exturls://certidox.com/backoffice/verification/'; url += doc.isActive; url += '/'; url += doc.qrCode; url += '/'; return url; }; this_.$onInit = function() { loadData(); }; } ] } ); globalApp.component( 'pgHistory', { templateUrl: '/components/history.php', controller: [ '$appVersion', '$http', '$location', function( $appVersion, $http, $location ) { var this_ = this; if ( !localStorage.getItem( 'appIsInit' ) ) { $location.url( '/index-a' ); return; } this_.isLoading = null; this_.listDocs = null; this_.pg = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/history.php', { params: $location.search() } ) // .then( function( response ) { if ( response.data.isUnknown ) { document.location.href = '/'; } if ( $appVersion.isNewVersion() ) { return true; } this_.isLoading = false; this_.listDocs = response.data.listDocs; this_.pg = response.data.pg; } ); }; this_.setPage = function( page ) { $location.search( 'page', page ); }; this_.toggleFav = function( doc ) { this_.isLoading = true; $http // .post( '/rest/_fav.php', { docId: doc.docId, isFav: +( !doc.isFav ) } ) // .then( function( response ) { this_.isLoading = false; loadData(); } ); }; this_.verifyUrl = function( doc ) { var url = ''; url += 'exturls://certidox.com/backoffice/verification/'; url += doc.isActive; url += '/'; url += doc.qrCode; url += '/'; return url; }; this_.$onInit = function() { loadData(); }; } ] } ); globalApp.component( 'pgSettings', { templateUrl: '/components/settings.php', controller: [ '$appVersion', '$http', '$location', '$window', function( $appVersion, $http, $location, $window ) { var this_ = this; this_.isLoading = null; this_.deviceData = null; this_.langs = null; var loadData = function() { this_.isLoading = true; $http // .post( '/rest/settings.php' ) // .then( function( response ) { if ( response.data.isUnknown ) { document.location.href = '/'; } if ( $appVersion.isNewVersion() ) { return true; } this_.isLoading = false; this_.deviceData = response.data.deviceData; this_.langs = response.data.langs; } ); }; this_.setData = function( name, value ) { this_.isLoading = true; $http // .post( '/rest/_settings.php', { name: name, value: value } ) // .then( function( response ) { if ( name === 'lang' ) { $window.location.href += ''; return; } this_.isLoading = false; loadData(); } ); }; this_.$onInit = function() { loadData(); }; } ] } );