Last active
October 8, 2015 02:32
-
-
Save jittagornp/a46cb09c8a64ef8abf4b to your computer and use it in GitHub Desktop.
angularjs of pamarin.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| var pamarin = angular.module('pamarin', [ | |
| 'ui.router', | |
| 'ui.router.stateHelper', | |
| 'LocalStorageModule', | |
| 'ngDialog', | |
| 'ab-base64', | |
| 'checklist-model', | |
| 'ui-notification', | |
| 'ipCookie', | |
| '720kb.tooltips', | |
| 'angularMoment', | |
| 'nsPopover', | |
| 'ngSanitize', | |
| 'uiGmapgoogle-maps', | |
| 'ngProgress', | |
| 'youtube-embed' | |
| ]); | |
| pamarin.constant('config', window.app.conf); | |
| pamarin.constant('principal', window.app.principal); | |
| pamarin.constant('messages', window.app.messages); | |
| pamarin.constant('data', window.app.data); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.config([ | |
| 'ngDialogProvider', | |
| function (ngDialogProvider) { | |
| ngDialogProvider.setDefaults({ | |
| className: 'ngdialog-theme-default', | |
| showClose: true, | |
| closeByDocument: true, | |
| closeByEscape: true, | |
| closeByNavigation: true, | |
| animationEndSupport : false, | |
| trapFocus : false, | |
| preserveFocus : false, | |
| disableAnimation : true | |
| }); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.config([ | |
| 'uiGmapGoogleMapApiProvider', | |
| function (uiGmapGoogleMapApiProvider) { | |
| uiGmapGoogleMapApiProvider.configure({ | |
| key: 'AIzaSyBhl7CqSB0QxqoA7ou1ow6LBMeeoF5oQSw&v=3.exp&signed_in=true', | |
| //v: '3.17'//, | |
| libraries: 'places' | |
| }); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.config([ | |
| 'localStorageServiceProvider', | |
| function (localStorageServiceProvider) { | |
| localStorageServiceProvider | |
| .setPrefix('pamarin'); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.config([ | |
| 'config', | |
| 'NotificationProvider', | |
| function (config, NotificationProvider) { | |
| NotificationProvider.setOptions({ | |
| delay: 10000, | |
| startTop: 40, | |
| startRight: 30, | |
| templateUrl : config.host + '/notification/info.html', | |
| verticalSpacing: 20, | |
| horizontalSpacing: 20, | |
| positionX: 'left', | |
| positionY: 'bottom' | |
| }); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 11/09/2015 | |
| */ | |
| pamarin.config([ | |
| 'config', | |
| '$stateProvider', | |
| function (config, $stateProvider) { | |
| var ready = { | |
| 'account': false | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var mainResolver = { | |
| initData: [ | |
| '$q', | |
| 'data', | |
| 'UserPageService', | |
| 'model.AccountPageContent', | |
| function ($q, data, service, AccountPageContent) { | |
| if (ready['account']) { | |
| var defer = $q.defer(); | |
| service.load(function (data) { | |
| defer.resolve(data); | |
| }); | |
| return defer.promise; | |
| } | |
| return AccountPageContent.fromProtocol(data.init); | |
| } | |
| ] | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var timeout = setTimeout(function () { | |
| clearTimeout(timeout); | |
| angular.forEach( | |
| ready, | |
| function (value, key) { | |
| ready[key] = true; | |
| } | |
| ); | |
| }, 500); | |
| $stateProvider | |
| .state('account', { | |
| url: '/account', | |
| templateUrl: function () { | |
| if (ready['account']) { | |
| return config.host + '/template/account'; | |
| } | |
| return null; | |
| }, | |
| resolve: mainResolver, | |
| controller: 'AccountCtrl' | |
| }); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 11/09/2015 | |
| */ | |
| pamarin.config([ | |
| 'config', | |
| '$stateProvider', | |
| function (config, $stateProvider) { | |
| var ready = { | |
| 'home': false, | |
| 'home.tripofuserfollowing': false, | |
| 'home.triplastest': false | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var mainResolver = { | |
| initData: [ | |
| '$q', | |
| 'data', | |
| '$state', | |
| 'controller.HomePage', | |
| 'model.HomePageContent', | |
| function ($q, data, $state, HomePage, HomePageContent) { | |
| if (ready['home']) { | |
| var defer = $q.defer(); | |
| (new HomePage()).loadData({ | |
| stateName: $state.next.name | |
| }, function (data) { | |
| defer.resolve(data); | |
| }); | |
| return defer.promise; | |
| } | |
| return HomePageContent.fromProtocol(data.init); | |
| } | |
| ] | |
| }; | |
| var tripLastestResolver = { | |
| initData: [ | |
| '$q', | |
| 'HomePageService', | |
| function ($q, pageService) { | |
| if (ready['home.triplastest']) { | |
| var defer = $q.defer(); | |
| pageService.loadTripLastestTab( | |
| function (data) { | |
| defer.resolve(data); | |
| } | |
| ); | |
| return defer.promise; | |
| } | |
| return null; | |
| } | |
| ] | |
| }; | |
| var tripFollowingResolver = { | |
| initData: [ | |
| '$q', | |
| 'HomePageService', | |
| function ($q, pageService) { | |
| if (ready['home.tripofuserfollowing']) { | |
| var defer = $q.defer(); | |
| pageService.loadTripFollowingTab( | |
| function (data) { | |
| defer.resolve(data); | |
| } | |
| ); | |
| return defer.promise; | |
| } | |
| return null; | |
| } | |
| ] | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var timeout = setTimeout(function () { | |
| clearTimeout(timeout); | |
| angular.forEach( | |
| ready, | |
| function (value, key) { | |
| ready[key] = true; | |
| } | |
| ); | |
| }, 500); | |
| $stateProvider | |
| .state('home', { | |
| url: '/', | |
| templateUrl: function () { | |
| if (ready['home']) { | |
| return config.host + '/template'; | |
| } | |
| return null; | |
| }, | |
| resolve: mainResolver, | |
| controller: 'HomeCtrl' | |
| }) | |
| .state('home.triplastest', { | |
| url: 'trips/lastest', | |
| views: { | |
| tab: { | |
| templateUrl: function () { | |
| if (ready['home.triplastest']) { | |
| return config.host + '/template/trips/lastest'; | |
| } | |
| return null; | |
| }, | |
| resolve: tripLastestResolver, | |
| controller: 'TripLastestCtrl' | |
| } | |
| } | |
| }) | |
| .state('home.tripofuserfollowing', { | |
| url: 'trips/followings', | |
| views: { | |
| tab: { | |
| templateUrl: function () { | |
| if (ready['home.tripofuserfollowing']) { | |
| return config.host + '/template/trips/followings'; | |
| } | |
| return null; | |
| }, | |
| resolve: tripFollowingResolver, | |
| controller: 'TripFollowingCtrl' | |
| } | |
| } | |
| }); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.config([ | |
| '$locationProvider', | |
| '$urlRouterProvider', | |
| function ($locationProvider, $urlRouterProvider) { | |
| $locationProvider.html5Mode(true); | |
| $urlRouterProvider.otherwise("/"); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 11/09/2015 | |
| */ | |
| pamarin.config([ | |
| 'config', | |
| '$stateProvider', | |
| function (config, $stateProvider) { | |
| var ready = { | |
| 'trips': false | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var mainResolver = { | |
| initData: [ | |
| '$q', | |
| 'data', | |
| 'TripService', | |
| '$stateParams', | |
| 'model.TripPageContent', | |
| function ($q, data, service, $stateParams, TripPageContent) { | |
| if (ready['trips']) { | |
| var defer = $q.defer(); | |
| service.loadPageDataByUsernameAndTripname( | |
| $stateParams.username, | |
| $stateParams.tripname, | |
| function (data) { | |
| defer.resolve(data); | |
| } | |
| ); | |
| return defer.promise; | |
| } | |
| return TripPageContent.fromProtocol(data.init); | |
| } | |
| ] | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var timeout = setTimeout(function () { | |
| clearTimeout(timeout); | |
| angular.forEach( | |
| ready, | |
| function (value, key) { | |
| ready[key] = true; | |
| } | |
| ); | |
| }, 500); | |
| $stateProvider | |
| .state('trips', { | |
| url: '/+{username}/~{tripname:.*\\/?$}', | |
| templateUrl: function ($stateParams) { | |
| if (ready['trips']) { | |
| return config.host + '/template/+' + $stateParams.username + '/~' + $stateParams.tripname; | |
| } | |
| return null; | |
| }, | |
| resolve: mainResolver, | |
| controller: 'TripCtrl' | |
| }); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 11/09/2015 | |
| */ | |
| pamarin.config([ | |
| 'config', | |
| '$stateProvider', | |
| function (config, $stateProvider) { | |
| var ready = { | |
| 'users.trips': false, | |
| 'users.tripslike': false, | |
| 'users.followers': false, | |
| 'users.followings': false, | |
| 'users': false | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var mainResolver = { | |
| initData: [ | |
| '$q', | |
| 'data', | |
| '$state', | |
| '$stateParams', | |
| 'controller.UserPage', | |
| 'model.UserPageContent', | |
| function ($q, data, $state, $stateParams, UserPage, UserPageContent) { | |
| if (ready['users']) { | |
| var defer = $q.defer(); | |
| (new UserPage()).loadData({ | |
| username: $stateParams.username, | |
| stateName: $state.next.name | |
| }, function (data) { | |
| defer.resolve(data); | |
| }); | |
| return defer.promise; | |
| } | |
| return UserPageContent.fromProtocol(data.init); | |
| } | |
| ] | |
| }; | |
| var tripResolver = { | |
| initData: [ | |
| '$q', | |
| '$stateParams', | |
| 'UserTripTabService', | |
| function ($q, $stateParams, service) { | |
| if (ready['users.trips']) { | |
| var defer = $q.defer(); | |
| service.loadByUsername( | |
| $stateParams.username, | |
| function (data) { | |
| defer.resolve(data); | |
| } | |
| ); | |
| return defer.promise; | |
| } | |
| return null; | |
| } | |
| ] | |
| }; | |
| var tripLikeResolver = { | |
| initData: [ | |
| '$q', | |
| '$stateParams', | |
| 'UserTripTabService', | |
| function ($q, $stateParams, service) { | |
| if (ready['users.tripslike']) { | |
| var defer = $q.defer(); | |
| service.loadLikeByUsername( | |
| $stateParams.username, | |
| function (data) { | |
| defer.resolve(data); | |
| } | |
| ); | |
| return defer.promise; | |
| } | |
| return null; | |
| } | |
| ] | |
| }; | |
| var followingResolver = { | |
| initData: [ | |
| '$q', | |
| '$stateParams', | |
| 'UserFollowPageService', | |
| function ($q, $stateParams, pageService) { | |
| if (ready['users.followings']) { | |
| var defer = $q.defer(); | |
| pageService.loadFollowingTabByUsername( | |
| $stateParams.username, | |
| function (data) { | |
| defer.resolve(data); | |
| } | |
| ); | |
| return defer.promise; | |
| } | |
| return null; | |
| } | |
| ] | |
| }; | |
| var followerResolver = { | |
| initData: [ | |
| '$q', | |
| '$stateParams', | |
| 'UserFollowPageService', | |
| function ($q, $stateParams, pageService) { | |
| if (ready['users.followers']) { | |
| var defer = $q.defer(); | |
| pageService.loadFollowerTabByUsername( | |
| $stateParams.username, | |
| function (data) { | |
| defer.resolve(data); | |
| } | |
| ); | |
| return defer.promise; | |
| } | |
| return null; | |
| } | |
| ] | |
| }; | |
| /* ------------------------------------------------------------------ */ | |
| var timeout = setTimeout(function () { | |
| clearTimeout(timeout); | |
| angular.forEach( | |
| ready, | |
| function (value, key) { | |
| ready[key] = true; | |
| } | |
| ); | |
| }, 500); | |
| $stateProvider | |
| .state('users', { | |
| url: '/+{username}', | |
| templateUrl: function ($stateParams) { | |
| if (ready['users']) { | |
| return config.host + '/template/+' + $stateParams.username; | |
| } | |
| return null; | |
| }, | |
| resolve: mainResolver, | |
| controller: 'UserCtrl' | |
| }) | |
| .state('users.trips', { | |
| url: '/trips', | |
| views: { | |
| tab: { | |
| templateUrl: function ($stateParams) { | |
| if (ready['users.trips']) { | |
| return config.host + '/template/+' + $stateParams.username + '/trips'; | |
| } | |
| return null; | |
| }, | |
| resolve: tripResolver, | |
| controller: 'UserTripCtrl' | |
| } | |
| } | |
| }) | |
| .state('users.tripslike', { | |
| url: '/trips/like', | |
| views: { | |
| tab: { | |
| templateUrl: function ($stateParams) { | |
| if (ready['users.tripslike']) { | |
| return config.host + '/template/+' + $stateParams.username + '/trips/like'; | |
| } | |
| return null; | |
| }, | |
| resolve: tripLikeResolver, | |
| controller: 'UserTripLikeCtrl' | |
| } | |
| } | |
| }) | |
| .state('users.followings', { | |
| url: '/followings', | |
| views: { | |
| tab: { | |
| templateUrl: function ($stateParams) { | |
| if (ready['users.followings']) { | |
| return config.host + '/template/+' + $stateParams.username + '/followings'; | |
| } | |
| return null; | |
| }, | |
| resolve: followingResolver, | |
| controller: 'UserFollowingCtrl' | |
| } | |
| } | |
| }) | |
| .state('users.followers', { | |
| url: '/followers', | |
| views: { | |
| tab: { | |
| templateUrl: function ($stateParams) { | |
| if (ready['users.followers']) { | |
| return config.host + '/template/+' + $stateParams.username + '/followers'; | |
| } | |
| return null; | |
| }, | |
| resolve: followerResolver, | |
| controller: 'UserFollowerCtrl' | |
| } | |
| } | |
| }); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.config([ | |
| '$httpProvider', | |
| function ($httpProvider) { | |
| function isPage(resp) { | |
| return resp.config.url.match('/pagedata/'); | |
| } | |
| function isTab(resp) { | |
| return resp.config.url.match('/pagedata/tab'); | |
| } | |
| /** | |
| * @interceptor ScrollTopInterceptor | |
| */ | |
| $httpProvider.interceptors.push([ | |
| function () { | |
| var $win = jQuery(window); | |
| return { | |
| response: function (resp) { | |
| if (isTab(resp)) { | |
| return resp; | |
| } | |
| if (isPage(resp)) { | |
| $win.scrollTop(0); | |
| return resp; | |
| } | |
| return resp; | |
| } | |
| }; | |
| } | |
| ]); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 06/09/2015 | |
| */ | |
| pamarin.run([ | |
| '$rootScope', | |
| function ($rootScope) { | |
| var $win = jQuery(window); | |
| var $page = jQuery('.pr-page-wrapper'); | |
| var scroll = $win.scrollTop(); | |
| var fixedScroll = scroll; | |
| $win.on('scroll', function () { | |
| scroll = $win.scrollTop(); | |
| }); | |
| $rootScope.$on( | |
| 'ngDialog.opened', | |
| function (e, $dialog) { | |
| $page.css({ | |
| marginTop: (-1) * scroll + 'px' | |
| }); | |
| fixedScroll = scroll; | |
| } | |
| ); | |
| $rootScope.$on( | |
| 'ngDialog.closed', function (e, $dialog) { | |
| $page.css({ | |
| marginTop: 0 | |
| }); | |
| $win.scrollTop(fixedScroll); | |
| } | |
| ); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 30/09/2015 | |
| */ | |
| pamarin.run([ | |
| '$state', | |
| 'messages', | |
| '$rootScope', | |
| 'state.DirtyState', | |
| 'component.ConfirmDialog', | |
| function ($state, messages, $rootScope, DirtyState, ConfirmDialog) { | |
| var hasDirty = false; | |
| function showDialog(state, params) { | |
| ConfirmDialog.create() | |
| .setHeader(messages['dialog.confirmLeafOutPage.TITLE']) | |
| .setMessage(messages['dialog.confirmLeafOutPage.MESSAGE']) | |
| .setConfirmButtonLabel(messages['dialog.confirmLeafOutPage.button.confirm']) | |
| .setCancelButtonLabel(messages['dialog.confirmLeafOutPage.buttom.cancel']) | |
| .onPreConfirm(function () { | |
| DirtyState.clearDirty(); | |
| $state.go(state.name, params); | |
| hasDirty = false; | |
| }) | |
| .onPreCancel(function () { | |
| hasDirty = false; | |
| }) | |
| .open(); | |
| } | |
| $rootScope.$on( | |
| '$stateChangeStart', | |
| function (event, toState, toParams, fromState, fromParams) { | |
| if (DirtyState.isDirty()) { | |
| if (!hasDirty) { | |
| hasDirty = true; | |
| showDialog(toState, toParams); | |
| } | |
| event.preventDefault(); | |
| } | |
| } | |
| ); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.run([ | |
| 'amMoment', | |
| function (moment) { | |
| moment.changeLocale('th'); | |
| //moment.changeTimezone('Asia/Bangkok'); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 05/09/2015 | |
| */ | |
| pamarin.run([ | |
| '$rootScope', | |
| 'state.DirtyState', | |
| 'ngProgressFactory', | |
| function ($rootScope, DirtyState, ngProgressFactory) { | |
| var progress = ngProgressFactory.createInstance(); | |
| progress.setHeight('1px'); | |
| progress.setColor('#3297fd'); | |
| function isPage(state) { | |
| return state.name.indexOf('.') === -1 && !DirtyState.isDirty(); | |
| } | |
| $rootScope.$on( | |
| '$stateChangeStart', | |
| function (event, toState, toParams, fromState, fromParams) { | |
| if (isPage(toState)) { | |
| progress.start(); | |
| } | |
| } | |
| ); | |
| $rootScope.$on( | |
| '$stateChangeSuccess', | |
| function (event, toState, toParams, fromState, fromParams) { | |
| if (isPage(toState)) { | |
| progress.complete(); | |
| } | |
| } | |
| ); | |
| progress.start(); | |
| progress.complete(); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.run([ | |
| '$state', | |
| '$rootScope', | |
| function ($state, $rootScope) { | |
| $rootScope.$on( | |
| '$stateChangeStart', | |
| function (event, toState, toParams, fromState, fromParams) { | |
| $state.next = toState; | |
| } | |
| ); | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.directive('focusOnScrolled', function () { | |
| var MOUSEWHEEL_STEP = 20; | |
| return function (scope, element, attr) { | |
| element.bind('mousewheel DOMMouseScroll', function (e) { | |
| var scrollTo = null; | |
| var $self = jQuery(this); | |
| if (!$self.hasScrollBar()) { | |
| return; | |
| } | |
| if (e.type === 'mousewheel') { | |
| scrollTo = (e.originalEvent.wheelDelta * -1); | |
| } | |
| else if (e.type === 'DOMMouseScroll') { | |
| scrollTo = MOUSEWHEEL_STEP * e.originalEvent.detail; | |
| } | |
| if (scrollTo) { | |
| e.preventDefault(); | |
| $self.scrollTop(scrollTo + $self.scrollTop()); | |
| } | |
| }); | |
| }; | |
| }); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.directive('ngBack', [ | |
| '$window', | |
| function ($window) { | |
| return function (scope, element, attrs) { | |
| element.bind("click", function (event) { | |
| scope.$apply(function () { | |
| $window.history.back(); | |
| }); | |
| event.preventDefault(); | |
| }); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.directive('ngEnter', function () { | |
| return function (scope, element, attrs) { | |
| element.bind("keydown keypress", function (event) { | |
| if (event.which === 13) { | |
| scope.$apply(function () { | |
| scope.$eval(attrs.ngEnter); | |
| }); | |
| event.preventDefault(); | |
| } | |
| }); | |
| }; | |
| }); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.directive('setClassWhenAtTop', [ | |
| '$window', | |
| function ($window) { | |
| var $win = angular.element($window); // wrap window object as jQuery object | |
| return { | |
| restrict: 'A', | |
| link: function (scope, element, attrs) { | |
| var topClass = attrs.setClassWhenAtTop; // get CSS class from directive's attribute value | |
| var offsetTop = element.offset().top; // get element's offset top relative to document | |
| var error = parseInt(attrs.fixedError, 10) || 0; | |
| $win.on('scroll', function (e) { | |
| if ($win.scrollTop() >= (offsetTop - error)) { | |
| element.addClass(topClass); | |
| } else { | |
| element.removeClass(topClass); | |
| } | |
| }); | |
| } | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.directive('whenScrolled', function () { | |
| return function (scope, elm, attr) { | |
| var raw = elm[0]; | |
| elm.bind('scroll', function () { | |
| if (raw.scrollTop + raw.offsetHeight >= raw.scrollHeight) { | |
| scope.$apply(attr.whenScrolled); | |
| } | |
| }); | |
| }; | |
| }); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.filter('cut', [ | |
| function () { | |
| return function (value, max, tail) { | |
| if (!value) | |
| return ''; | |
| max = parseInt(max, 10); | |
| if (!max) { | |
| return value; | |
| } | |
| if (value.length <= max) { | |
| return value; | |
| } | |
| return value.substr(0, max) + (tail || ' …'); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.filter('timeFromNow', [ | |
| 'util.Time', | |
| function (Time) { | |
| return function (value) { | |
| if (!value) { | |
| return ''; | |
| } | |
| return Time.fromNow(value); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('enum.ArticleStatus', [ | |
| 'messages', | |
| 'enum.Enumerate', | |
| function (messages, Enumerate) { | |
| /** | |
| * @enum ArticleStatus | |
| */ | |
| var ArticleStatus = Enumerate([ | |
| { | |
| name: 'PUBLIC', | |
| description: messages.ARTICLE_PUBLIC | |
| }, | |
| { | |
| name: 'DRAFF', | |
| description: messages.ARTICLE_DRAFF | |
| } | |
| ]); | |
| return ArticleStatus; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('enum.Enumerate', function () { | |
| return (function (list, fnc) { | |
| /** | |
| * @enum Enumerate | |
| */ | |
| var Enumerate = function (ctx) { | |
| if (angular.isObject(ctx)) { | |
| angular.forEach(ctx, function (val, key) { | |
| this[key] = val; | |
| }, this); | |
| } else if (angular.isString(ctx)) { | |
| this.name = ctx; | |
| } else { | |
| throw new Error('incorrect arguments.'); | |
| } | |
| }; | |
| Enumerate.values = []; | |
| /** | |
| * @param {String | Object} ctx | |
| * @returns {Enumerate} | |
| */ | |
| Enumerate.valueOf = function (ctx) { | |
| if (!ctx || ctx == 'null') { | |
| return null; | |
| } | |
| var obj = null; | |
| angular.forEach(Enumerate.values, function (item) { | |
| if (item.name === ctx) { | |
| obj = item; | |
| return false; | |
| } | |
| }); | |
| if (!obj) { | |
| obj = new Enumerate(ctx); | |
| Enumerate.values.push(obj); | |
| } | |
| return obj; | |
| }; | |
| /** | |
| * @param {String} protocol | |
| * @returns {Enumerate} | |
| */ | |
| Enumerate.fromProtocol = function (protocol) { | |
| try { | |
| return Enumerate.valueOf(protocol); | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {String} | |
| */ | |
| Enumerate.prototype.toProtocol = function () { | |
| return this.name; | |
| }; | |
| /** | |
| * @returns {String} | |
| */ | |
| Enumerate.prototype.toString = function () { | |
| return this.name; | |
| }; | |
| /** | |
| * @param {String | Enumerate} name | |
| * @returns {Boolean} | |
| */ | |
| Enumerate.prototype.is = function (name) { | |
| if (angular.isString(name)) { | |
| return this.name === name; | |
| } | |
| return this === name; | |
| }; | |
| fnc && angular.forEach(fnc, function (val, key) { | |
| Enumerate.prototype[key] = val; | |
| }); | |
| angular.forEach(list, function (item) { | |
| Enumerate[ | |
| angular.isObject(item) | |
| ? item.name | |
| : item | |
| ] = Enumerate.valueOf(item); | |
| }); | |
| return Enumerate; | |
| }); | |
| }); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('enum.LikeType', [ | |
| 'enum.Enumerate', | |
| function (Enumerate) { | |
| /** | |
| * @enum LikeType | |
| */ | |
| var LikeType = Enumerate([ | |
| 'POST', | |
| 'COMMENT' | |
| ]); | |
| return LikeType; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('enum.MapMarkerType', [ | |
| 'enum.Enumerate', | |
| function (Enumerate) { | |
| /** | |
| * @enum MapMarkerType | |
| */ | |
| var MapMarkerType = Enumerate([ | |
| 'POST' | |
| ]); | |
| return MapMarkerType; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('enum.MapType', [ | |
| 'enum.Enumerate', | |
| function (Enumerate) { | |
| /** | |
| * @enum MapType | |
| */ | |
| var MapType = Enumerate([ | |
| 'ROADMAP', | |
| 'TERRAIN', | |
| 'SATELLITE', | |
| 'HYBRID' | |
| ]); | |
| return MapType; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('enum.PostType', [ | |
| 'messages', | |
| 'enum.Enumerate', | |
| function (messages, Enumerate) { | |
| /** | |
| * @enum PostType | |
| */ | |
| var PostType = Enumerate([ | |
| { | |
| name: 'CONTENT', | |
| description: messages.CONTENT | |
| }, | |
| { | |
| name: 'GALLERY', | |
| description: messages.PHOTO | |
| }, | |
| { | |
| name: 'MAP', | |
| description: messages.MAP | |
| }, | |
| { | |
| name: 'VIDEO', | |
| description: messages.VIDEO | |
| } | |
| ]); | |
| return PostType; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.AccountPageContent', [ | |
| 'model.User', | |
| function (User) { | |
| /** | |
| * @model AccountPageContent | |
| */ | |
| var AccountPageContent = function () { | |
| this.user = null; /* model.User */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {AccountPageContent} | |
| */ | |
| AccountPageContent.fromProtocol = function (protocol) { | |
| try { | |
| var data = new AccountPageContent(); | |
| data.user = User.fromProtocol(protocol.user); | |
| return data; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return AccountPageContent; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Authority', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @model Authority | |
| */ | |
| var Authority = function (id, desc) { | |
| this.id = id || null; /* String */ | |
| this.description = desc || null; /* String */ | |
| }; | |
| Authority.ADMIN = new Authority('ADMIN', 'administrator'); | |
| /** | |
| * @returns {Object} | |
| */ | |
| Authority.prototype.toProtocol = function () { | |
| return { | |
| auth_id: Values.asValue(this.id), | |
| description: Values.asValue(this.description) | |
| }; | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Authority} | |
| */ | |
| Authority.fromProtocol = function (protocol) { | |
| try { | |
| return new Authority(protocol.auth_id, protocol.description); | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return Authority; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Comment', [ | |
| 'util.Time', | |
| 'model.User', | |
| 'util.Values', | |
| function (Time, User, Values) { | |
| /** | |
| * @model Comment | |
| */ | |
| var Comment = function () { | |
| this.id = null; /* String */ | |
| this.message = null; /* String */ | |
| this.backupMessage = null; /* String */ | |
| this.createDate = null; /* String */ | |
| this.createDateDesc = null; /* String */ | |
| this.updateDate = null; /* String */ | |
| this.updateDateDesc = null; /* String */ | |
| this.referenceId = null; /* String */ | |
| this.userId = null; /* String */ | |
| this.user = null; /* model.User */ | |
| this.isOwner = null; /* Boolean */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Comment} | |
| */ | |
| Comment.fromProtocol = function (protocol) { | |
| try { | |
| var comment = new Comment(); | |
| comment.id = protocol.comment_id; | |
| comment.message = protocol.message; | |
| comment.backupMessage = protocol.message; | |
| comment.createDate = protocol.create_date; | |
| comment.createDateDesc = Time.fromNow(protocol.create_date); | |
| comment.updateDate = protocol.update_date; | |
| comment.updateDateDesc = Time.fromNow(protocol.update_date); | |
| comment.referenceId = protocol.reference_id; | |
| comment.userId = protocol.user_id; | |
| comment.user = User.fromProtocol(protocol.user); | |
| comment.isOwner = protocol.is_owner || false; | |
| return comment; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Comment.prototype.toProtocol = function () { | |
| return { | |
| comment_id: Values.asValue(this.id), | |
| message: Values.asValue(this.message), | |
| create_date: Values.asValue(this.createDate), | |
| update_date: Values.asValue(this.updateDate), | |
| reference_id: Values.asValue(this.referenceId), | |
| user_id: Values.asValue(this.userId) | |
| }; | |
| }; | |
| return Comment; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.CommentPageResource', [ | |
| 'model.PageResource', | |
| 'model.Comment', | |
| 'model.ProtocolMapper', | |
| function (PageResource, Comment, ProtocolMapper) { | |
| /** | |
| * @model {CommentPageResource} | |
| */ | |
| var CommentPageResource = function () { | |
| }; | |
| /* | |
| * @param {Object} protocol | |
| * @returns {model.PageResource} | |
| */ | |
| CommentPageResource.fromProtocol = function (protocol) { | |
| var page = PageResource.fromProtocol(protocol); | |
| page.content = ProtocolMapper.fromArray(page.content, Comment); | |
| return page; | |
| }; | |
| return CommentPageResource; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Follows', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @model Follows | |
| */ | |
| var Follows = function () { | |
| this.total = null; /* Number */ | |
| this.followed = null; /* Boolean */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Follows} | |
| */ | |
| Follows.fromProtocol = function (protocol) { | |
| try { | |
| var follows = new Follows(); | |
| follows.total = protocol.total || 0; | |
| follows.followed = protocol.followed || false; | |
| return follows; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Follows.prototype.toProtocol = function () { | |
| return { | |
| total: Values.asValue(this.total), | |
| followed: Values.asValue(this.followed) | |
| }; | |
| }; | |
| return Follows; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.HomePageContent', [ | |
| 'model.TripCardPageResource', | |
| function (TripCardPageResource) { | |
| /** | |
| * @model HomePageContent | |
| */ | |
| var HomePageContent = function () { | |
| this.phrase = null; /* String */ | |
| this.tripCardPage = null; /* model.TripCardPageResource */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {HomePageContent} | |
| */ | |
| HomePageContent.fromProtocol = function (protocol) { | |
| try { | |
| var content = new HomePageContent(); | |
| if(protocol.phrase){ | |
| content.phrase = protocol.phrase; | |
| } | |
| if (protocol.trip_card_page) { | |
| content.tripCardPage = TripCardPageResource.fromProtocol(protocol.trip_card_page); | |
| } | |
| return content; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /* | |
| * @param {PageResource} page | |
| */ | |
| HomePageContent.prototype.addTripCardPage = function (page) { | |
| this.tripCardPage.number = page.number; | |
| this.tripCardPage.hasNextPage = page.hasNextPage; | |
| angular.forEach(page.content, function (card) { | |
| this.tripCardPage.content.push(card); | |
| }, this); | |
| }; | |
| return HomePageContent; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Like', [ | |
| 'model.User', | |
| 'enum.LikeType', | |
| function (User, LikeType) { | |
| /** | |
| * @model Like | |
| */ | |
| var Like = function () { | |
| this.id = { | |
| referenceId: null, /* String */ | |
| userId: null, /* String */ | |
| referenceType: null /* enum.LikeType */ | |
| }; | |
| this.user = null; /* model.User */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Like} | |
| */ | |
| Like.fromProtocol = function (protocol) { | |
| try { | |
| var like = new Like(); | |
| like.id.referenceId = protocol.id.reference_id; | |
| like.id.userId = protocol.id.user_id; | |
| like.id.referenceType = LikeType.valueOf(protocol.id.reference_type); | |
| like.user = User.fromProtocol(protocol.user); | |
| return like; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return Like; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Likes', [ | |
| 'model.Like', | |
| 'model.ProtocolMapper', | |
| function (Like, ProtocolMapper) { | |
| /** | |
| * @model Likes | |
| */ | |
| var Likes = function () { | |
| this.total = null; /* Number */ | |
| this.liked = null; /* Boolean */ | |
| this.likes = null; /* Array<model.Like> */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Likes} | |
| */ | |
| Likes.fromProtocol = function (protocol) { | |
| try { | |
| var likes = new Likes(); | |
| likes.total = protocol.total || 0; | |
| likes.liked = protocol.liked || false; | |
| likes.likes = ProtocolMapper.fromArray(protocol.likes, Like); | |
| return likes; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return Likes; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Link', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @model Link | |
| */ | |
| var Link = function () { | |
| this.pattern = null; /* String */ | |
| this.mapping = null; /* Object */ | |
| this.href = null; /* String */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Link} | |
| */ | |
| Link.fromProtocol = function (protocol) { | |
| try { | |
| var link = new Link(); | |
| link.pattern = protocol.pattern; | |
| link.mapping = protocol.mapping; | |
| link.href = protocol.href; | |
| return link; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Link.prototype.toProtocol = function () { | |
| return { | |
| pattern: Values.asValue(this.pattern), | |
| mapping: Values.asValue(this.mapping), | |
| href: Values.asValue(this.href) | |
| }; | |
| }; | |
| return Link; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.MapMarker', [ | |
| 'enum.MapMarkerType', | |
| 'util.Values', | |
| function (MapMarkerType, Values) { | |
| /** | |
| * @model MapMarker | |
| */ | |
| var MapMarker = function () { | |
| this.id = null; /* String */ | |
| this.latitude = null; /* Number */ | |
| this.longitude = null; /* Number */ | |
| this.referenceId = null; /* String */ | |
| this.referenceType = null; /* enum.MapMarkerType */ | |
| }; | |
| /** | |
| * @param {Number} lat | |
| * @param {Number} lng | |
| * @returns {MapMarker} | |
| */ | |
| MapMarker.fromLatitudeLongitude = function (lat, lng) { | |
| var marker = new MapMarker(); | |
| marker.latitude = lat; | |
| marker.longitude = lng; | |
| return marker; | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {MapMarker} | |
| */ | |
| MapMarker.fromProtocol = function (protocol) { | |
| try { | |
| var marker = new MapMarker(); | |
| marker.id = protocol.marker_id; | |
| marker.latitude = protocol.latitude; | |
| marker.longitude = protocol.longitude; | |
| marker.referenceId = protocol.reference_id; | |
| marker.referenceType = MapMarkerType.valueOf(protocol.reference_type) || MapMarkerType.POST; | |
| return marker; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| MapMarker.prototype.toProtocol = function () { | |
| return { | |
| marker_id: Values.asValue(this.id), | |
| latitude: Values.asValue(this.latitude), | |
| longitude: Values.asValue(this.longitude), | |
| reference_id: Values.asValue(this.referenceId), | |
| reference_type: Values.asValue(this.referenceType) | |
| }; | |
| }; | |
| return MapMarker; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.PageData', [ | |
| function () { | |
| /** | |
| * @model PageData | |
| */ | |
| var PageData = function () { | |
| this.title = null; /* String */ | |
| this.metadata = null; /* Array<Object> */ | |
| this.content = null; /* ? */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PageData} | |
| */ | |
| PageData.fromProtocol = function (protocol) { | |
| try { | |
| var data = new PageData(); | |
| data.title = protocol.title; | |
| data.metadata = protocol.metadata || []; | |
| data.content = protocol.content; | |
| return data; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return PageData; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.PageRequest', [ | |
| 'enum.Enumerate', | |
| function (Enumerate) { | |
| /** | |
| * @model PageRequest | |
| */ | |
| var PageRequest = function (number, size, sorts) { | |
| this.number = number || 0; | |
| this.size = size || 0; | |
| this.sorts = sorts || []; | |
| }; | |
| /** | |
| * @model PageRequest.Sort | |
| * | |
| * @param {String} property | |
| * @param {PageRequest.Sort.Direction} direction | |
| */ | |
| PageRequest.Sort = function (property, direction) { | |
| this.property = property; | |
| this.direction = direction; | |
| }; | |
| /** | |
| * @enum PageRequest.Sort.Direction | |
| */ | |
| PageRequest.Sort.Direction = Enumerate([ | |
| 'ASC', | |
| 'DESC' | |
| ]); | |
| function buildSorts(sorts) { | |
| var sts = []; | |
| angular.forEach(sorts, function (sort) { | |
| sts.push(sort.property + ':' + sort.direction); | |
| }); | |
| return sts.join(','); | |
| } | |
| /** | |
| * @returns {String} | |
| */ | |
| PageRequest.prototype.toString = function () { | |
| return 'page=' + this.number | |
| + '&size=' + this.size | |
| + (this.sorts.length ? ('&sort=' + buildSorts(this.sorts)) : ''); | |
| }; | |
| return PageRequest; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.PageResource', [ | |
| function () { | |
| /** | |
| * @model PageResource | |
| */ | |
| var PageResource = function () { | |
| this.size = null; | |
| this.number = null; | |
| this.content = null; | |
| this.sorts = null; | |
| this.links = null; | |
| this.totalElements = null; | |
| this.totalPages = null; | |
| this.numberOfElements = null; | |
| this.hasNextPage = null; | |
| this.isSlice = null; | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PageResource} | |
| */ | |
| PageResource.fromProtocol = function (protocol) { | |
| try { | |
| var page = new PageResource(); | |
| page.size = protocol.size || 0; | |
| page.number = protocol.number || 0; | |
| page.content = protocol.content || []; | |
| page.sorts = protocol.sorts || []; | |
| page.links = protocol.links || []; | |
| page.totalElements = protocol.total_elements || 0; | |
| page.totalPages = protocol.total_pages || 0; | |
| page.numberOfElements = protocol.number_of_elements || 0; | |
| page.hasNextPage = protocol.has_next_page || false; | |
| page.isSlice = protocol.is_slice || false; | |
| return page; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return PageResource; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Post', [ | |
| 'util.Values', | |
| 'enum.PostType', | |
| 'model.PostMap', | |
| 'model.PostVideo', | |
| 'SecurityContext', | |
| 'model.PostContent', | |
| 'model.PostGallery', | |
| function (Values, PostType, PostMap, PostVideo, securityContext, PostContent, PostGallery) { | |
| /** | |
| * @model Post | |
| */ | |
| var Post = function () { | |
| this.id = null; /* String */ | |
| this.title = null; /* String */ | |
| this.referenceId = null; /* String */ | |
| this.createDate = null; /* String */ | |
| this.updateDate = null; /* String */ | |
| this.type = null; /* enum.PostType */ | |
| this.sequence = null; /* Number */ | |
| this.userId = null; /* String */ | |
| this.map = null; /* model.PostMap */ | |
| this.content = null; /* model.PostContent */ | |
| this.video = null; /* model.PostVideo */ | |
| this.gallery = null; /* model.PostGallery */ | |
| this._title = null; /* String */ | |
| }; | |
| /** | |
| * factory method for create Post with Content | |
| * | |
| * @returns {Post} | |
| */ | |
| function newContent() { | |
| var post = new Post(); | |
| post.type = PostType.CONTENT; | |
| post.content = new PostContent(); | |
| post._editing = true; | |
| post.userId = securityContext.principal.id; | |
| return post; | |
| } | |
| /** | |
| * factory method for create Post with Map | |
| * | |
| * @returns {Post} | |
| */ | |
| function newMap() { | |
| var post = new Post(); | |
| post.type = PostType.MAP; | |
| post.map = new PostMap(); | |
| post._editing = true; | |
| post.userId = securityContext.principal.id; | |
| return post; | |
| } | |
| /** | |
| * factory method for create Post with Video | |
| * | |
| * @returns {Post} | |
| */ | |
| function newVideo() { | |
| var post = new Post(); | |
| post.type = PostType.VIDEO; | |
| post.video = new PostVideo(); | |
| post._editing = true; | |
| post.userId = securityContext.principal.id; | |
| return post; | |
| } | |
| /** | |
| * factory method for create Post with Gallery | |
| * | |
| * @returns {Post} | |
| */ | |
| function newGallery() { | |
| var post = new Post(); | |
| post.type = PostType.GALLERY; | |
| post.gallery = new PostGallery(); | |
| post._editing = true; | |
| post.userId = securityContext.principal.id; | |
| return post; | |
| } | |
| /** | |
| * factory method for create post from type | |
| * | |
| * @param {String} type | |
| * @returns {Post} | |
| */ | |
| Post.fromType = function (type) { | |
| if (PostType.CONTENT.is(type)) { | |
| return newContent(); | |
| } | |
| if (PostType.MAP.is(type)) { | |
| return newMap(); | |
| } | |
| if (PostType.VIDEO.is(type)) { | |
| return newVideo(); | |
| } | |
| if (PostType.GALLERY.is(type)) { | |
| return newGallery(); | |
| } | |
| throw 'Unsupported post type.'; | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Post} | |
| */ | |
| Post.fromProtocol = function (protocol) { | |
| try { | |
| var post = new Post(); | |
| post.id = protocol.post_id; | |
| post.title = protocol.title; | |
| post.referenceId = protocol.reference_id; | |
| post.createDate = protocol.create_date; | |
| post.updateDate = protocol.update_date; | |
| post.type = PostType.valueOf(protocol.type); | |
| post.sequence = protocol.post_sequence; | |
| post.userId = protocol.user_id; | |
| if (protocol.content) { | |
| post.content = PostContent.fromProtocol(protocol.content); | |
| } | |
| if (protocol.map) { | |
| post.map = PostMap.fromProtocol(protocol.map); | |
| } | |
| if (protocol.video) { | |
| post.video = PostVideo.fromProtocol(protocol.video); | |
| } | |
| if (protocol.gallery) { | |
| post.gallery = PostGallery.fromProtocol(protocol.gallery); | |
| } | |
| return post; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Post.prototype.toProtocol = function () { | |
| return { | |
| post_id: Values.asValue(this.id), | |
| title: Values.asValue(this.title), | |
| reference_id: Values.asValue(this.referenceId), | |
| create_date: Values.asValue(this.createDate), | |
| update_date: Values.asValue(this.updateDate), | |
| type: Values.asValue(this.type), | |
| post_sequence: Values.asValue(this.sequence), | |
| user_id: Values.asValue(this.userId), | |
| content: Values.asValue(this.content), | |
| map: Values.asValue(this.map), | |
| video: Values.asValue(this.video), | |
| gallery: Values.asValue(this.gallery) | |
| }; | |
| }; | |
| Post.prototype.backup = function () { | |
| this._title = this.title; | |
| if (this.content) { | |
| this.content.backup(); | |
| } | |
| if (this.map) { | |
| this.map.backup(); | |
| } | |
| if (this.video) { | |
| this.video.backup(); | |
| } | |
| if (this.gallery) { | |
| this.gallery.backup(); | |
| } | |
| }; | |
| Post.prototype.restore = function () { | |
| this.title = this._title; | |
| if (this.content) { | |
| this.content.restore(); | |
| } | |
| if (this.map) { | |
| this.map.restore(); | |
| } | |
| if (this.video) { | |
| this.video.restore(); | |
| } | |
| if (this.gallery) { | |
| this.gallery.restore(); | |
| } | |
| this._title = null; | |
| }; | |
| return Post; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.PostContent', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @model PostContent | |
| */ | |
| var PostContent = function () { | |
| this.id = null; /* String */ | |
| this.content = null; /* String */ | |
| this._content = null; /* String */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PostContent} | |
| */ | |
| PostContent.fromProtocol = function (protocol) { | |
| try { | |
| var content = new PostContent(); | |
| content.id = protocol.post_id; | |
| content.content = protocol.content; | |
| return content; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /* | |
| * @returns {Object} | |
| */ | |
| PostContent.prototype.toProtocol = function () { | |
| return { | |
| post_id: Values.asValue(this.id), | |
| content: Values.asValue(this.content) | |
| }; | |
| }; | |
| PostContent.prototype.backup = function () { | |
| this._content = this.content; | |
| }; | |
| PostContent.prototype.restore = function () { | |
| this.content = this._content; | |
| this._content = null; | |
| }; | |
| return PostContent; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 08/10/2014 | |
| */ | |
| pamarin.factory('model.PostGallery', [ | |
| 'util.Values', | |
| 'model.PostPhoto', | |
| 'model.ProtocolMapper', | |
| function (Values, PostPhoto, ProtocolMapper) { | |
| /** | |
| * @model PostGallery | |
| */ | |
| var PostGallery = function () { | |
| this.id = null; /* String */ | |
| this.description = null; /* String */ | |
| this.photos = null; /* Array<model.PostPhoto> */ | |
| this._description = null; /* String */ | |
| this._photos = null; /* Array<model.PostPhoto> */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PostGallery} | |
| */ | |
| PostGallery.fromProtocol = function (protocol) { | |
| try { | |
| var post = new PostGallery(); | |
| post.id = protocol.post_id; | |
| post.description = protocol.description; | |
| post.photos = ProtocolMapper.fromArray(protocol.photos, PostPhoto); | |
| return post; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| PostGallery.prototype.toProtocol = function () { | |
| return { | |
| post_id: Values.asValue(this.id), | |
| description: Values.asValue(this.description), | |
| photos: ProtocolMapper.toArray(this.photos) | |
| }; | |
| }; | |
| PostGallery.prototype.backup = function () { | |
| this._description = this.description; | |
| this._photos = angular.copy(this.photos); | |
| }; | |
| PostGallery.prototype.restore = function () { | |
| this.description = this._description; | |
| this.photos = this._photos; | |
| this._description = null; | |
| this._photos = null; | |
| }; | |
| return PostGallery; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.PostMap', [ | |
| 'enum.MapType', | |
| 'model.MapMarker', | |
| 'util.Values', | |
| 'enum.MapMarkerType', | |
| 'model.ProtocolMapper', | |
| function (MapType, MapMarker, Values, MapMarkerType, ProtocolMapper) { | |
| /** | |
| * @model PostMap | |
| */ | |
| var PostMap = function () { | |
| this.id = null; /* String */ | |
| this.description = null; /* String */ | |
| this.latitude = null; /* Number */ | |
| this.longitude = null; /* Number */ | |
| this.zoomLevel = null; /* Number */ | |
| this.mapType = MapType.ROADMAP; /* enum.MapType */ | |
| this.markers = null; /* Array<model.MapMarker> */ | |
| this.staticMapUrl = null; /* String */ | |
| this._description = null; /* String */ | |
| this._latitude = null; /* Number */ | |
| this._longitude = null; /* Number */ | |
| this._zoomLevel = null; /* Number */ | |
| this._mapType = null; /* enum.MapType */ | |
| this._markers = null; /* Array<model.MapMarker> */ | |
| this._staticMapUrl = null; /* String */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PostMap} | |
| */ | |
| PostMap.fromProtocol = function (protocol) { | |
| try { | |
| var post = new PostMap(); | |
| post.id = protocol.post_id; | |
| post.description = protocol.description; | |
| post.latitude = protocol.latitude; | |
| post.longitude = protocol.longitude; | |
| post.zoomLevel = protocol.zoom_level; | |
| post.mapType = MapType.valueOf(protocol.map_type); | |
| post.markers = ProtocolMapper.fromArray(protocol.markers, MapMarker); | |
| post.staticMapUrl = protocol.static_map_url; | |
| return post; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| PostMap.prototype.toProtocol = function () { | |
| return { | |
| post_id: Values.asValue(this.id), | |
| description: Values.asValue(this.description), | |
| latitude: Values.asValue(this.latitude), | |
| longitude: Values.asValue(this.longitude), | |
| zoom_level: Values.asValue(this.zoomLevel), | |
| map_type: Values.asValue(this.mapType), | |
| markers: ProtocolMapper.toArray(this.markers) | |
| }; | |
| }; | |
| PostMap.prototype.backup = function () { | |
| this._description = this.description; | |
| this._latitude = this.latitude; | |
| this._longitude = this.longitude; | |
| this._zoomLevel = this.zoomLevel; | |
| this._mapType = this.mapType; | |
| this._markers = angular.copy(this.markers); | |
| this._staticMapUrl = this.staticMapUrl; | |
| }; | |
| PostMap.prototype.restore = function () { | |
| this.description = this._description; | |
| this.latitude = this._latitude; | |
| this.longitude = this._longitude; | |
| this.zoomLevel = this._zoomLevel; | |
| this.mapType = this._mapType; | |
| this.markers = this._markers; | |
| this.staticMapUrl = this._staticMapUrl; | |
| this._description = null; | |
| this._latitude = null; | |
| this._longitude = null; | |
| this._zoomLevel = null; | |
| this._mapType = null; | |
| this._markers = null; | |
| this._staticMapUrl = null; | |
| }; | |
| /** | |
| * @param {model.MapMarker} marker | |
| */ | |
| PostMap.prototype.addMarker = function (marker) { | |
| if (!this.markers) { | |
| this.markers = []; | |
| } | |
| marker.referenceId = this.id; | |
| marker.referenceType = MapMarkerType.POST; | |
| this.markers.push(marker); | |
| }; | |
| return PostMap; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.PostPageResource', [ | |
| 'model.PageResource', | |
| 'model.Post', | |
| 'model.ProtocolMapper', | |
| function (PageResource, Post, ProtocolMapper) { | |
| /** | |
| * @model PostPageResource | |
| */ | |
| var PostPageResource = function () { | |
| }; | |
| /* | |
| * @param {Object} protocol | |
| * @returns {model.PageResource} | |
| */ | |
| PostPageResource.fromProtocol = function (protocol) { | |
| var page = PageResource.fromProtocol(protocol); | |
| page.content = ProtocolMapper.fromArray(page.content, Post); | |
| return page; | |
| }; | |
| return PostPageResource; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 08/10/2014 | |
| */ | |
| pamarin.factory('model.PostPhoto', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @model PostPhoto | |
| */ | |
| var PostPhoto = function () { | |
| this.id = null; /* String */ | |
| this.postId = null; /* String */ | |
| this.displayName = null; /* String */ | |
| this.mimeType = null; /* String */ | |
| this.description = null; /* String */ | |
| this.createDate = null; /* String */ | |
| this.updateDate = null; | |
| this._description = null; /* String */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PostPhoto} | |
| */ | |
| PostPhoto.fromProtocol = function (protocol) { | |
| try { | |
| var post = new PostPhoto(); | |
| post.id = protocol.photo_id; | |
| post.postId = protocol.post_id; | |
| post.displayName = protocol.display_name; | |
| post.mimeType = protocol.mime_type; | |
| post.description = protocol.description; | |
| post.createDate = protocol.create_date; | |
| post.updateDate = protocol.update_date; | |
| return post; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| PostPhoto.prototype.toProtocol = function () { | |
| return { | |
| photo_id: Values.asValue(this.id), | |
| post_id: Values.asValue(this.postId), | |
| display_name: Values.asValue(this.displayName), | |
| mime_type: Values.asValue(this.mimeType), | |
| description: Values.asValue(this.description), | |
| create_date: Values.asValue(this.createDate), | |
| update_date: Values.asValue(this.updateDate) | |
| }; | |
| }; | |
| PostPhoto.prototype.backup = function () { | |
| this._description = this.description; | |
| }; | |
| PostPhoto.prototype.restore = function () { | |
| this.description = this._description; | |
| this._description = null; | |
| }; | |
| return PostPhoto; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 24/09/2015 | |
| */ | |
| pamarin.factory('model.PostVideo', [ | |
| 'util.Values', | |
| 'util.StringUtils', | |
| 'util.YoutubeUtils', | |
| function (Values, StringUtils, YoutubeUtils) { | |
| /** | |
| * @model PostVideo | |
| */ | |
| var PostVideo = function () { | |
| this.id = null; /* String */ | |
| this.description = null; /* String */ | |
| this.link = null; | |
| this.videoParam = ''; | |
| this._description = null; /* String */ | |
| this._link = null; /* String */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PostVideo} | |
| */ | |
| PostVideo.fromProtocol = function (protocol) { | |
| try { | |
| var post = new PostVideo(); | |
| post.id = protocol.post_id; | |
| post.description = protocol.description; | |
| post.link = protocol.link; | |
| post.findVideoParam(); | |
| return post; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| PostVideo.prototype.toProtocol = function () { | |
| return { | |
| post_id: Values.asValue(this.id), | |
| description: Values.asValue(this.description), | |
| link: Values.asValue(this.link) | |
| }; | |
| }; | |
| PostVideo.prototype.findVideoParam = function () { | |
| this.videoParam = YoutubeUtils.getVideoParamsFromUrl(this.link); | |
| return this; | |
| }; | |
| PostVideo.prototype.isYouTube = function () { | |
| return StringUtils.hasText(this.videoParam); | |
| }; | |
| PostVideo.prototype.backup = function () { | |
| this._description = this.description; | |
| this._link = this.link; | |
| }; | |
| PostVideo.prototype.restore = function () { | |
| this.description = this._description; | |
| this.link = this._link; | |
| this._description = null; | |
| this._link = null; | |
| }; | |
| return PostVideo; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Presenter', [ | |
| 'model.User', | |
| 'model.Follows', | |
| 'util.Values', | |
| function (User, Follows, Values) { | |
| /** | |
| * @model Presenter | |
| */ | |
| var Presenter = function () { | |
| this.user = null; /* model.User */ | |
| this.follows = null; /* model.Follows */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Presenter} | |
| */ | |
| Presenter.fromProtocol = function (protocol) { | |
| try { | |
| var presenter = new Presenter(); | |
| presenter.user = User.fromProtocol(protocol.user); | |
| presenter.follows = Follows.fromProtocol(protocol.follows); | |
| return presenter; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Presenter.prototype.toProtocol = function () { | |
| return { | |
| user: Values.asValue(this.user), | |
| follows: Values.asValue(this.follows) | |
| }; | |
| }; | |
| return Presenter; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.ProtocolMapper', [ | |
| function () { | |
| /** | |
| * @model ProtocolMapper | |
| */ | |
| var ProtocolMapper = function () { | |
| }; | |
| /** | |
| * for convert object to Object protocol | |
| * | |
| * @param {Array} arr | |
| * @returns {Array} | |
| */ | |
| ProtocolMapper.toArray = function (arr) { | |
| var protocols = []; | |
| if (!arr) { | |
| return protocols; | |
| } | |
| angular.forEach(arr, function (obj) { | |
| protocols.push(obj.toProtocol()); | |
| }); | |
| return protocols; | |
| }; | |
| /** | |
| * for convert Object protocol to object | |
| * | |
| * @param {Array} arr | |
| * @param {Function} model which has static method .fromProtocol(protocol) | |
| * @returns {Array} | |
| */ | |
| ProtocolMapper.fromArray = function (arr, clazz) { | |
| var objs = []; | |
| if (!arr) { | |
| return objs; | |
| } | |
| angular.forEach(arr, function (item) { | |
| objs.push(clazz.fromProtocol(item)); | |
| }); | |
| return objs; | |
| }; | |
| return ProtocolMapper; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Tag', [ | |
| 'model.TagLookup', | |
| 'util.Values', | |
| function (TagLookup, Values) { | |
| /** | |
| * @model Tag | |
| */ | |
| var Tag = function () { | |
| this.id = { | |
| tripId: null, /* String */ | |
| lookupId: null /* String */ | |
| }; | |
| this.lookup = null; /* model.TagLookup */ | |
| this.createDate = null; /* String */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {Tag} | |
| */ | |
| Tag.fromProtocol = function (protocol) { | |
| try { | |
| var tag = new Tag(); | |
| tag.id.tripId = protocol.id.trip_id; | |
| tag.id.lookupId = protocol.id.lookup_id; | |
| tag.lookup = TagLookup.fromProtocol(protocol.lookup); | |
| tag.createDate = protocol.create_date; | |
| return tag; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Tag.prototype.toProtocol = function () { | |
| return { | |
| id: { | |
| trip_id: Values.asValue(this.id, function () { | |
| return this.id.tripId; | |
| }, this), | |
| lookup_id: Values.asValue(this.id, function () { | |
| return this.id.lookupId; | |
| }, this) | |
| }, | |
| create_date: Values.asValue(this.createDate) | |
| }; | |
| }; | |
| return Tag; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.TagLookup', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @model TagLookup | |
| */ | |
| var TagLookup = function () { | |
| this.id = null; /* String */ | |
| this.name = null; /* String */ | |
| this.description = null; /* String */ | |
| }; | |
| /* | |
| * @param {Object} protocol | |
| * @returns {TagLookup} | |
| */ | |
| TagLookup.fromProtocol = function (protocol) { | |
| try { | |
| var lookup = new TagLookup(); | |
| lookup.id = protocol.lookup_id; | |
| lookup.name = protocol.name; | |
| lookup.description = protocol.description; | |
| return lookup; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| TagLookup.prototype.toProtocol = function () { | |
| return { | |
| lookup_id: Values.asValue(this.id), | |
| name: Values.asValue(this.name) | |
| }; | |
| }; | |
| return TagLookup; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.TagMapper', [ | |
| 'model.Tag', | |
| function (Tag) { | |
| /** | |
| * @model TagMapper | |
| */ | |
| var TagMapper = function () { | |
| }; | |
| /** | |
| * @param {model.TagLookup} lookup | |
| * @param {String} tripId | |
| * @returns {model.Tag} | |
| */ | |
| TagMapper.lookup2Tag = function (lookup, tripId) { | |
| try { | |
| var tag = new Tag(); | |
| tag.id.tripId = tripId; | |
| tag.id.lookupId = lookup.id; | |
| tag.lookup = lookup; | |
| return tag; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @param {Array<model.TagLookup>} lookups | |
| * @param {type} tripId | |
| * @returns {Array<model.Tag>} | |
| */ | |
| TagMapper.lookups2Tags = function (lookups, tripId) { | |
| var tags = []; | |
| angular.forEach(lookups, function (lookup) { | |
| var tag = TagMapper.lookup2Tag(lookup, tripId); | |
| if (tag) { | |
| tags.push(tag); | |
| } | |
| }); | |
| return tags; | |
| }; | |
| /** | |
| * @param {model.Tag} tag | |
| * @returns {mode.TagLookup} | |
| */ | |
| TagMapper.tag2Lookup = function (tag) { | |
| if (!tag) { | |
| return null; | |
| } | |
| return tag.lookup; | |
| }; | |
| /** | |
| * @param {Array<model.Tag>} tags | |
| * @returns {Array<mode.TagLookup>} | |
| */ | |
| TagMapper.tags2Lookups = function (tags) { | |
| var lookups = []; | |
| angular.forEach(tags, function (tag) { | |
| var lookup = TagMapper.tag2Lookup(tag); | |
| if (lookup) { | |
| lookups.push(lookup); | |
| } | |
| }); | |
| return lookups; | |
| }; | |
| return TagMapper; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Tags', [ | |
| 'model.ProtocolMapper', | |
| function (ProtocolMapper) { | |
| /** | |
| * @model Tags | |
| */ | |
| var Tags = function () { | |
| this.tags = null; /* Array<model.Tag> */ | |
| }; | |
| /** | |
| * @param {Array<model.Tag>} tags | |
| * @returns {Tags} | |
| */ | |
| Tags.fromTags = function (tags) { | |
| var tgs = new Tags(); | |
| tgs.tags = tags; | |
| return tgs; | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Tags.prototype.toProtocol = function () { | |
| return { | |
| tags: ProtocolMapper.toArray(this.tags) | |
| }; | |
| }; | |
| return Tags; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.Trip', [ | |
| 'util.Time', | |
| 'model.Tag', | |
| 'model.Link', | |
| 'model.Presenter', | |
| 'util.Values', | |
| 'enum.ArticleStatus', | |
| 'model.ProtocolMapper', | |
| function (Time, Tag, Link, Presenter, Values, ArticleStatus, ProtocolMapper) { | |
| /** | |
| * @model Trip | |
| */ | |
| var Trip = function () { | |
| this.id = null; /* String */ | |
| this.tripname = null; /* String */ | |
| this.name = null; /* String */ | |
| this.description = null; /* String */ | |
| this.userId = null; /* String */ | |
| this.presenter = null; /* model.Presenter */ | |
| this.tags = null; /* Array<model.Tag> */ | |
| this.createDate = null; /* String */ | |
| this.createDateDesc = null; /* String */ | |
| this.publishedDate = null; /* String */ | |
| this.publishedDateDesc = null; /* String */ | |
| this.updateDate = null; /* String */ | |
| this.updateDateDesc = null; /* String */ | |
| this.status = null; /* enum.ArticleStatus */ | |
| this.link = null; /* model.Link */ | |
| this.isOwner = null; /* Boolean */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {model.Trip} | |
| */ | |
| Trip.fromProtocol = function (protocol) { | |
| try { | |
| var trip = new Trip(); | |
| trip.id = protocol.trip_id; | |
| trip.tripname = protocol.tripname; | |
| trip.name = protocol.name; | |
| trip.description = protocol.description; | |
| trip.userId = protocol.user_id; | |
| trip.presenter = Presenter.fromProtocol(protocol.presenter); | |
| trip.tags = ProtocolMapper.fromArray(protocol.tags, Tag); | |
| trip.createDate = protocol.create_date; | |
| trip.createDateDesc = Time.fromNow(protocol.create_date); | |
| trip.publishedDate = protocol.published_date; | |
| trip.publishedDateDesc = Time.fromNow(protocol.published_date); | |
| trip.updateDate = protocol.update_date; | |
| trip.updateDateDesc = Time.fromNow(protocol.update_date); | |
| trip.status = ArticleStatus.valueOf(protocol.status) || ArticleStatus.DRAFF; | |
| trip.link = Link.fromProtocol(protocol.link); | |
| trip.isOwner = protocol.is_owner || false; | |
| return trip; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| Trip.prototype.toProtocol = function () { | |
| return { | |
| trip_id: Values.asValue(this.id), | |
| tripname: Values.asValue(this.tripname), | |
| name: Values.asValue(this.name), | |
| user_id: Values.asValue(this.userId), | |
| tags: Values.asValue(this.tags, ProtocolMapper.toArray(this.tags)), | |
| create_date: Values.asValue(this.createDate), | |
| published_date: Values.asValue(this.publishedDate), | |
| update_date: Values.asValue(this.updateDate), | |
| status: Values.asValue(this.status), | |
| link: Values.asValue(this.link), | |
| is_owner: Values.asValue(this.isOwner) | |
| }; | |
| }; | |
| return Trip; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.TripCard', [ | |
| 'model.Trip', | |
| 'model.Likes', | |
| function (Trip, Likes) { | |
| /** | |
| * @model TripCard | |
| */ | |
| var TripCard = function () { | |
| this.trip = null; /* model.Trip */ | |
| this.likes = null; /* model.Likes */ | |
| this.numberOfComments = null; /* Number */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {UserCard} | |
| */ | |
| TripCard.fromProtocol = function (protocol) { | |
| try { | |
| var card = new TripCard(); | |
| card.trip = Trip.fromProtocol(protocol.trip); | |
| card.likes = Likes.fromProtocol(protocol.likes); | |
| card.numberOfComments = protocol.number_of_comments || 0; | |
| return card; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return TripCard; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.TripCardPageResource', [ | |
| 'model.PageResource', | |
| 'model.TripCard', | |
| 'model.ProtocolMapper', | |
| function (PageResource, TripCard, ProtocolMapper) { | |
| /** | |
| * @model TripCardPageResource | |
| */ | |
| var TripCardPageResource = function () { | |
| }; | |
| /* | |
| * @param {Object} protocol | |
| * @returns {model.PageResource} | |
| */ | |
| TripCardPageResource.fromProtocol = function (protocol) { | |
| var page = PageResource.fromProtocol(protocol); | |
| page.content = ProtocolMapper.fromArray(page.content, TripCard); | |
| return page; | |
| }; | |
| return TripCardPageResource; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.TripPageContent', [ | |
| 'util.Time', | |
| 'model.Trip', | |
| 'model.Likes', | |
| 'model.Comment', | |
| 'SecurityContext', | |
| 'model.PostPageResource', | |
| 'model.CommentPageResource', | |
| 'algorithm.SequencialDiv2Add', | |
| function (Time, Trip, Likes, Comment, securityContext, PostPageResource, CommentPageResource, SequencialDiv2Add) { | |
| /** | |
| * @model TripPageContent | |
| */ | |
| var TripPageContent = function () { | |
| this.trip = null; /* model.Trip */ | |
| this.numberOfPosts = null; /* Number */ | |
| this.postPage = null; /* model.PostPageResource */ | |
| this.likes = null; /* model.Likes */ | |
| this.numberOfComments = null; /* Number */ | |
| this.commentPage = null; /* model.CommentPageResource */ | |
| this.comment = null; /* model.Comment */ | |
| }; | |
| /** | |
| * @param {object} protocol | |
| * @param {Array<Post>} content | |
| */ | |
| function translate2PostPage(protocol, content) { | |
| content.numberOfPosts = protocol.number_of_posts || 0; | |
| content.postPage = PostPageResource.fromProtocol(protocol.post_page); | |
| content.postPage.number = content.postPage.number || 0; | |
| content.postPage.hasNextPage = content.postPage.hasNextPage || false; | |
| angular.forEach(content.postPage.content, function (post) { | |
| post.reference = content.trip; | |
| }); | |
| } | |
| /** | |
| * @param {object} protocol | |
| * @param {Array<comment>} content | |
| */ | |
| function translate2CommentPage(protocol, content) { | |
| content.numberOfComments = protocol.number_of_comments || 0; | |
| content.commentPage = CommentPageResource.fromProtocol(protocol.comment_page); | |
| content.commentPage.number = content.commentPage.number || 0; | |
| content.commentPage.hasNextPage = content.commentPage.hasNextPage || false; | |
| angular.forEach(content.commentPage.content, function (comment) { | |
| comment.reference = content.trip; | |
| }); | |
| } | |
| /** | |
| * @param {Object} protocol | |
| * @returns {TripPageContent} | |
| */ | |
| TripPageContent.fromProtocol = function (protocol) { | |
| try { | |
| var content = new TripPageContent(); | |
| content.trip = Trip.fromProtocol(protocol.trip); | |
| translate2PostPage(protocol, content); | |
| translate2CommentPage(protocol, content); | |
| content.likes = Likes.fromProtocol(protocol.likes); | |
| return content; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| * @returns {model.Post} | |
| */ | |
| TripPageContent.prototype.setupPost = function (post) { | |
| post.reference = this.trip; | |
| post.referenceId = this.trip.id; | |
| return post; | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| * @param {Number} index | |
| */ | |
| TripPageContent.prototype.replacePost = function (post, index) { | |
| this.trip.updateDateDesc = Time.fromNow(post.updateDate); | |
| this.postPage.content.splice(index, 1, this.setupPost(post)); | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| TripPageContent.prototype.addPost = function (post) { | |
| this.postPage.content.push(this.setupPost(post)); | |
| this.numberOfPosts = this.numberOfPosts + 1; | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| * @param {Number} index | |
| */ | |
| TripPageContent.prototype.insertPost = function (post, index) { | |
| SequencialDiv2Add.fromArray(this.postPage.content) | |
| .byStep(1000) | |
| .toIndex(index) | |
| .add(this.setupPost(post)); | |
| this.numberOfPosts = this.numberOfPosts + 1; | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| * @returns {Number} | |
| */ | |
| TripPageContent.prototype.indexOfPost = function (post) { | |
| return this.postPage.content.indexOf(post); | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| TripPageContent.prototype.removePost = function (post) { | |
| this.numberOfPosts = this.numberOfPosts - 1; | |
| this.postPage.content.splice(this.indexOfPost(post), 1); | |
| }; | |
| /* | |
| * @param {PageResource} page | |
| */ | |
| TripPageContent.prototype.addPostPage = function (page) { | |
| this.postPage.number = this.postPage.number + 1; | |
| this.postPage.hasNextPage = page.hasNextPage; | |
| angular.forEach(page.content, function (post) { | |
| this.addPost(post); | |
| }, this); | |
| }; | |
| /** | |
| * @param {Array<model.Tag>} tags | |
| */ | |
| TripPageContent.prototype.setTags = function (tags) { | |
| if (tags.length) { | |
| this.trip.updateDateDesc = Time.fromNow(tags[0].createDate); | |
| } | |
| this.trip.tags = tags; | |
| }; | |
| /** | |
| * @returns {model.Comment} | |
| */ | |
| TripPageContent.prototype.newComment = function () { | |
| if (this.trip) { | |
| var cmnt = new Comment(); | |
| cmnt.referenceId = this.trip.id; | |
| cmnt.reference = this.trip; | |
| cmnt.user = securityContext.user(); | |
| cmnt.userId = cmnt.user.id; | |
| this.comment = cmnt; | |
| return this.comment; | |
| } | |
| return null; | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| */ | |
| TripPageContent.prototype.addComment = function (comment) { | |
| this.numberOfComments = this.numberOfComments + 1; | |
| this.commentPage.content.splice(0, 0, comment); | |
| this.comment = this.newComment(); | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| * @returns {Number} | |
| */ | |
| TripPageContent.prototype.indexOfComment = function (comment) { | |
| return this.commentPage.content.indexOf(comment); | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| * @param {Number} index | |
| */ | |
| TripPageContent.prototype.replaceComment = function (comment, index) { | |
| this.commentPage.content.splice(index, 1, comment); | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| */ | |
| TripPageContent.prototype.removeComment = function (comment) { | |
| this.numberOfComments = this.numberOfComments - 1; | |
| this.commentPage.content.splice(this.indexOfComment(comment), 1); | |
| }; | |
| /* | |
| * @param {PageResource} page | |
| */ | |
| TripPageContent.prototype.addCommentPage = function (page) { | |
| this.commentPage.number = this.commentPage.number + 1; | |
| this.commentPage.hasNextPage = page.hasNextPage; | |
| angular.forEach(page.content, function (comment) { | |
| this.commentPage.content.push(comment); | |
| }, this); | |
| }; | |
| return TripPageContent; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.TripPageResource', [ | |
| 'model.Trip', | |
| 'model.PageResource', | |
| 'model.ProtocolMapper', | |
| function (Trip, PageResource, ProtocolMapper) { | |
| /** | |
| * @model TripPageResource | |
| */ | |
| var TripPageResource = function () { | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {PageResource} | |
| */ | |
| TripPageResource.fromProtocol = function (protocol) { | |
| try { | |
| var page = PageResource.fromProtocol(protocol); | |
| page.content = ProtocolMapper.fromArray(page.content, Trip); | |
| return page; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return TripPageResource; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.User', [ | |
| 'messages', | |
| 'model.Link', | |
| 'enum.Enumerate', | |
| 'model.Authority', | |
| 'util.Values', | |
| 'model.ProtocolMapper', | |
| function (messages, Link, Enumerate, Authority, Values, ProtocolMapper) { | |
| /** | |
| * @model User | |
| */ | |
| var User = function () { | |
| this.id = null; /* String */ | |
| this.username = null; /* String */ | |
| this.firstName = null; /* String */ | |
| this.lastName = null; /* String */ | |
| this.name = null; /* String */ | |
| this.email = null; /* String */ | |
| this.gender = null; /* User.Gener */ | |
| this.locale = null; /*String */ | |
| this.timezone = null; /* Number */ | |
| this.authorities = null; /* Array<model.Authority> */ | |
| this.picture = null; /* String */ | |
| this.social = null; /* User.Social */ | |
| this.socialId = null; /* String */ | |
| this.createDate = null; /* String */ | |
| this.updateDate = null; /* String */ | |
| this.aboutMe = null; /* String */ | |
| this.link = null; /* model.Link */ | |
| this.isOwner = null; /* Boolean */ | |
| }; | |
| /** | |
| * @enum User.Gender | |
| */ | |
| User.Gender = Enumerate([ | |
| { | |
| name: 'UNKNOWN', | |
| description: messages.UNKNOWN | |
| }, | |
| { | |
| name: 'MALE', | |
| description: messages.MALE | |
| }, | |
| { | |
| name: 'FEMALE', | |
| description: messages.FEMALE | |
| } | |
| ]); | |
| /** | |
| * @enum User.Social | |
| */ | |
| User.Social = Enumerate([ | |
| 'FACEBOOK', | |
| 'GOOGLE_PLUS', | |
| 'TWITTER' | |
| ]); | |
| /** | |
| * @param {Object} protocol | |
| * @returns {User} | |
| */ | |
| User.fromProtocol = function (protocol) { | |
| try { | |
| var user = new User(); | |
| user.id = protocol.user_id; | |
| user.username = protocol.username; | |
| user.firstName = protocol.first_name; | |
| user.lastName = protocol.last_name; | |
| user.name = protocol.name; | |
| user.email = protocol.email; | |
| user.gender = User.Gender.valueOf(protocol.gender); | |
| user.locale = protocol.locale; | |
| user.timezone = protocol.timezone; | |
| user.authorities = ProtocolMapper.fromArray(protocol.authorities, Authority); | |
| user.picture = protocol.picture; | |
| user.social = User.Social.valueOf(protocol.social); | |
| user.socialId = protocol.social_id; | |
| user.createDate = protocol.create_date; | |
| user.updateDate = protocol.update_date; | |
| user.aboutMe = protocol.about_me; | |
| user.link = Link.fromProtocol(protocol.link); | |
| user.isOwner = protocol.is_owner || false; | |
| return user; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| User.prototype.toProtocol = function () { | |
| return { | |
| user_id: Values.asValue(this.id), | |
| username: Values.asValue(this.username), | |
| first_name: Values.asValue(this.firstName), | |
| last_name: Values.asValue(this.lastName), | |
| email: Values.asValue(this.email), | |
| gender: Values.asValue(this.gender), | |
| locale: Values.asValue(this.locale), | |
| timezone: Values.asValue(this.timezone), | |
| authorities: ProtocolMapper.toArray(this.authorities), | |
| picture: Values.asValue(this.picture), | |
| social: Values.asValue(this.social), | |
| social_id: Values.asValue(this.socialId), | |
| create_date: Values.asValue(this.createDate), | |
| update_date: Values.asValue(this.updateDate), | |
| about_me: Values.asValue(this.aboutMe) | |
| }; | |
| }; | |
| return User; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.UserCard', [ | |
| 'model.User', | |
| function (User) { | |
| /** | |
| * @model UserCard | |
| */ | |
| var UserCard = function () { | |
| this.user = null; /* model.User */ | |
| this.numberOfTrips = null; /* Number */ | |
| this.followed = null; /* Boolean */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {UserCard} | |
| */ | |
| UserCard.fromProtocol = function (protocol) { | |
| try { | |
| var card = new UserCard(); | |
| card.user = User.fromProtocol(protocol.user); | |
| card.numberOfTrips = protocol.number_of_trips || 0; | |
| card.followed = protocol.followed || false; | |
| return card; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return UserCard; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.UserCardPageResource', [ | |
| 'model.PageResource', | |
| 'model.UserCard', | |
| 'model.ProtocolMapper', | |
| function (PageResource, UserCard, ProtocolMapper) { | |
| /** | |
| * @model UserCardPageResource | |
| */ | |
| var UserCardPageResource = function () { | |
| }; | |
| /* | |
| * @param {Object} protocol | |
| * @returns {model.PageResource} | |
| */ | |
| UserCardPageResource.fromProtocol = function (protocol) { | |
| var page = PageResource.fromProtocol(protocol); | |
| page.content = ProtocolMapper.fromArray(page.content, UserCard); | |
| return page; | |
| }; | |
| return UserCardPageResource; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('model.UserPageContent', [ | |
| 'model.UserCard', | |
| 'model.TripCardPageResource', | |
| 'model.UserCardPageResource', | |
| function (UserCard, TripCardPageResource, UserCardPageResource) { | |
| /** | |
| * @model UserPageContent | |
| */ | |
| var UserPageContent = function () { | |
| this.userCard = null; /* model.UserCard */ | |
| this.tripCardPage = null; /* model.TripCardPageResource */ | |
| this.userCardPage = null; /* model.UserCardPageResource */ | |
| this.numberOfTrips = null; /* Number */ | |
| this.numberOfTripLikeds = null; /* Number */ | |
| this.numberOfFollowers = null; /* Number */ | |
| this.numberOfFollowings = null; /* Number */ | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {UserPageContent} | |
| */ | |
| UserPageContent.fromProtocol = function (protocol) { | |
| try { | |
| var content = new UserPageContent(); | |
| if (protocol.user_card) { | |
| content.userCard = UserCard.fromProtocol(protocol.user_card); | |
| } | |
| if (protocol.trip_card_page) { | |
| content.tripCardPage = TripCardPageResource.fromProtocol(protocol.trip_card_page); | |
| } | |
| if (protocol.user_card_page) { | |
| content.userCardPage = UserCardPageResource.fromProtocol(protocol.user_card_page); | |
| } | |
| content.numberOfTrips = protocol.number_of_trips || 0; | |
| content.numberOfTripLikeds = protocol.number_of_trip_likeds || 0; | |
| content.numberOfFollowers = protocol.number_of_followers || 0; | |
| content.numberOfFollowings = protocol.number_of_followings || 0; | |
| return content; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| /** | |
| * @param {PageResource} page | |
| */ | |
| UserPageContent.prototype.addTripCardPage = function (page) { | |
| this.tripCardPage.number = page.number; | |
| this.tripCardPage.hasNextPage = page.hasNextPage; | |
| angular.forEach(page.content, function (card) { | |
| this.tripCardPage.content.push(card); | |
| }, this); | |
| }; | |
| /** | |
| * @param {PageResource} page | |
| */ | |
| UserPageContent.prototype.addUserCardPage = function (page) { | |
| this.userCardPage.number = page.number; | |
| this.userCardPage.hasNextPage = page.hasNextPage; | |
| angular.forEach(page.content, function (card) { | |
| this.userCardPage.content.push(card); | |
| }, this); | |
| }; | |
| return UserPageContent; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 06/09/2015 | |
| */ | |
| pamarin.factory('dto.TripSettingsDto', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @dto TripSettingsDto | |
| */ | |
| var TripSettingsDto = function () { | |
| this.tripId = null; /* String */ | |
| this.name = null; /* String */ | |
| this.tripname = null; /* String */ | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| TripSettingsDto.prototype.toProtocol = function () { | |
| return { | |
| trip_id: Values.asValue(this.tripId), | |
| name: Values.asValue(this.name), | |
| tripname: Values.asValue(this.tripname) | |
| }; | |
| }; | |
| /** | |
| * @param {Object} protocol | |
| * @returns {TripSettingsDto} | |
| */ | |
| TripSettingsDto.fromProtocol = function (protocol) { | |
| try { | |
| var dto = new TripSettingsDto(); | |
| dto.tripId = protocol.trip_id; | |
| dto.tripname = protocol.tripname; | |
| dto.name = protocol.name; | |
| return dto; | |
| } catch (ex) { | |
| return null; | |
| } | |
| }; | |
| return TripSettingsDto; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 05/09/2015 | |
| */ | |
| pamarin.factory('dto.WriteTripDto', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @dto WriteTripDto | |
| */ | |
| var WriteTripDto = function () { | |
| this.name = null; /* String */ | |
| }; | |
| /** | |
| * @returns {Object} | |
| */ | |
| WriteTripDto.prototype.toProtocol = function () { | |
| return { | |
| name: Values.asValue(this.name) | |
| }; | |
| }; | |
| return WriteTripDto; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.GMarkerUtils', [ | |
| function () { | |
| /** | |
| * @util GMarkerUtils | |
| */ | |
| var GMarkerUtils = function () { | |
| }; | |
| /** | |
| * @param {google.maps.Marker} gmarker | |
| * @returns {google.maps.LatLng} | |
| */ | |
| GMarkerUtils.toLatLng = function (gmarker) { | |
| return gmarker.getPosition(); | |
| }; | |
| /** | |
| * @param {Array<google.maps.Marker>} gmarkers | |
| * @returns {Array<google.maps.LatLng>} | |
| */ | |
| GMarkerUtils.toLatLngs = function (gmarkers) { | |
| var latLngs = []; | |
| angular.forEach( | |
| gmarkers, | |
| function (gmarker) { | |
| latLngs.push(GMarkerUtils.toLatLng(gmarker)); | |
| } | |
| ); | |
| return latLngs; | |
| }; | |
| return GMarkerUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.GPlaceUtils', [ | |
| function () { | |
| /** | |
| * @util GPlaceUtils | |
| */ | |
| var GPlaceUtils = function () { | |
| }; | |
| /** | |
| * @param {google.maps.Place} place | |
| * @returns {google.maps.LatLng} | |
| */ | |
| GPlaceUtils.toLatLng = function (place) { | |
| return place.geometry.location; | |
| }; | |
| /** | |
| * @param {Array<google.maps.Place>} places | |
| * @returns {Array<google.maps.LatLng>} | |
| */ | |
| GPlaceUtils.toLatLngs = function (places) { | |
| var latLngs = []; | |
| angular.forEach( | |
| places, | |
| function (place) { | |
| latLngs.push(GPlaceUtils.toLatLng(place)); | |
| } | |
| ); | |
| return latLngs; | |
| }; | |
| return GPlaceUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.GoogleMapUtils', [ | |
| 'util.GpsUtils', | |
| 'util.MathUtils', | |
| 'util.GMarkerUtils', | |
| function (GpsUtils, MathUtils, GMarkerUtils) { | |
| /** | |
| * @util GoogleMapUtils | |
| */ | |
| var GoogleMapUtils = function () { | |
| }; | |
| /** | |
| * @param {google.maps.LatLng} position | |
| * @returns {Object} | |
| */ | |
| function toGps(position) { | |
| return { | |
| latitude: position.lat(), | |
| longitude: position.lng() | |
| }; | |
| } | |
| /** | |
| * @param {Number} distance meter | |
| * @returns {Number} | |
| */ | |
| GoogleMapUtils.calculateZoomLevel = function (distance) { | |
| var DISTANCE_ZOOM_LEVEL0 = 73728000; | |
| var MIN_ZOOM_LEVEL = 0; | |
| var MAX_ZOOM_LEVEL = 21; | |
| var result = DISTANCE_ZOOM_LEVEL0; | |
| var level = 0; | |
| while ((result /= 2.0) > distance) { | |
| level = level + 1; | |
| } | |
| if (level < MIN_ZOOM_LEVEL) { | |
| return MIN_ZOOM_LEVEL; | |
| } | |
| if (level > MAX_ZOOM_LEVEL) { | |
| return MAX_ZOOM_LEVEL; | |
| } | |
| return level - 1; | |
| }; | |
| /** | |
| * @param {google.maps.LatLng} center | |
| * @param {Array<google.maps.LatLng>} latLngs | |
| * @returns {Number} | |
| */ | |
| GoogleMapUtils.findMaxDistance = function (center, latLngs) { | |
| var distance = 0; | |
| angular.forEach( | |
| latLngs, | |
| function (latLng) { | |
| var dst = GpsUtils.findDistance(toGps(center), toGps(latLng)); | |
| if (dst > distance) { | |
| distance = dst; | |
| } | |
| } | |
| ); | |
| return distance; | |
| }; | |
| /** | |
| * @param {google.maps.LatLng} center | |
| * @param {Array<google.maps.LatLng>} latLngs | |
| * @returns {Number} | |
| */ | |
| GoogleMapUtils.findLatLngOfMinDistance = function (center, latLngs) { | |
| var distance = Number.MAX_VALUE; | |
| var currentLatLng = null; | |
| angular.forEach( | |
| latLngs, | |
| function (latLng) { | |
| var dst = GpsUtils.findDistance(toGps(center), toGps(latLng)); | |
| if (dst < distance) { | |
| distance = dst; | |
| currentLatLng = latLng; | |
| } | |
| } | |
| ); | |
| return currentLatLng; | |
| }; | |
| /** | |
| * @param {Array<google.maps.Marker>} gmarkers | |
| * @returns {Object} | |
| */ | |
| function findMaxMin(gmarkers) { | |
| var latitudes = []; | |
| var longitudes = []; | |
| angular.forEach( | |
| gmarkers, | |
| function (gmarker) { | |
| var position = gmarker.getPosition(); | |
| latitudes.push(position.lat()); | |
| longitudes.push(position.lng()); | |
| } | |
| ); | |
| return{ | |
| minLat: MathUtils.findMin(latitudes), | |
| maxLat: MathUtils.findMax(latitudes), | |
| minLng: MathUtils.findMin(longitudes), | |
| maxLng: MathUtils.findMax(longitudes) | |
| }; | |
| } | |
| /** | |
| * @param {Array<google.maps.Marker>} gmarkers | |
| * @returns {google.maps.LatLng} | |
| */ | |
| GoogleMapUtils.calculateFocus = function (gmarkers) { | |
| var result = findMaxMin(gmarkers); | |
| var center = new google.maps.LatLng( | |
| (result.minLat + result.maxLat) / 2, | |
| (result.minLng + result.maxLng) / 2 | |
| ); | |
| var latLngs = GMarkerUtils.toLatLngs(gmarkers); | |
| var distance = GoogleMapUtils.findMaxDistance(center, latLngs); | |
| var zoom = GoogleMapUtils.calculateZoomLevel(distance); | |
| return { | |
| center: center, | |
| zoom: zoom | |
| }; | |
| }; | |
| return GoogleMapUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.GpsUtils', [ | |
| function () { | |
| /** | |
| * code for compute distance of GPS 2 points | |
| * | |
| * @author redcorw | |
| * create 01/12/2013 | |
| * link http://na5cent.blogspot.com/2011/07/gps-2-javascript.html | |
| */ | |
| var BETWEEN_DEGREE = 15; | |
| var THOUSAND_METER = 1000; | |
| /** | |
| * define surface distance per 1 degree change | |
| */ | |
| var SURFACE_DISTANCE_PER_ONE_DEGREE = [ | |
| {latitude: 110.574, longitude: 111.320}, //0 degree | |
| {latitude: 110.649, longitude: 107.551}, //15 degree | |
| {latitude: 110.852, longitude: 96.486}, //30 degree | |
| {latitude: 111.132, longitude: 78.847}, //45 degree | |
| {latitude: 111.412, longitude: 55.800}, //60 degree | |
| {latitude: 111.618, longitude: 28.902}, //75 degree | |
| {latitude: 111.694, longitude: 0.000} //90 degree | |
| ]; | |
| function getSurfaceDistance(gps) { | |
| return SURFACE_DISTANCE_PER_ONE_DEGREE[parseInt(gps.latitude / BETWEEN_DEGREE)]; //depend on latitude | |
| } | |
| function getLatitudeDistance(gps) { | |
| return getSurfaceDistance(gps).latitude * THOUSAND_METER; | |
| } | |
| function getLongitudeDistance(gps) { | |
| return getSurfaceDistance(gps).longitude * THOUSAND_METER; | |
| } | |
| /** | |
| * @util GpsUtils | |
| */ | |
| var GpsUtils = function () { | |
| }; | |
| GpsUtils.findDistance = function (gps1, gps2) { | |
| var latitudeDistance1 = getLatitudeDistance(gps1); //a1 | |
| var latitudeDistance2 = getLatitudeDistance(gps2); //a2 | |
| var longitudeDistance1 = getLongitudeDistance(gps1); //b1 | |
| var longitudeDistance2 = getLongitudeDistance(gps2); //b2 | |
| // (X2 * a2 - X1 * a1) ^ 2 | |
| var power1 = Math.pow((gps2.latitude * latitudeDistance2) - (gps1.latitude * latitudeDistance1), 2); | |
| // (Y2 * b2 - Y1 * b1) ^ 2 | |
| var power2 = Math.pow((gps2.longitude * longitudeDistance2) - (gps1.longitude * longitudeDistance1), 2); | |
| return Math.sqrt(power1 + power2); | |
| }; | |
| return GpsUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.Http', [ | |
| '$http', | |
| 'util.RequestUtils', | |
| function ($http, RequestUtils) { | |
| /** | |
| * @util Http | |
| */ | |
| var Http = function () { | |
| }; | |
| var request = function (url, method, data, contentType) { | |
| return { | |
| method: method, | |
| url: url, | |
| headers: { | |
| 'Content-Type': contentType | |
| }, | |
| data: data | |
| }; | |
| }; | |
| /** | |
| * @param {String} url | |
| * @param {Object} data_opt | |
| * @returns {$http} | |
| */ | |
| Http.get = function (url, data_opt) { | |
| return $http(request( | |
| url + (data_opt ? ('?' + RequestUtils.toRequestString(data_opt)) : ''), | |
| 'get', | |
| null, | |
| 'application/json' | |
| )); | |
| }; | |
| /** | |
| * @param {String} url | |
| * @param {Object} data_opt | |
| * @returns {$http} | |
| */ | |
| Http.post = function (url, data_opt) { | |
| return $http(request( | |
| url, | |
| 'post', | |
| JSON.stringify(data_opt), | |
| 'application/json' | |
| )); | |
| }; | |
| /** | |
| * @param {String} url | |
| * @param {Object} data_opt | |
| * @returns {$http} | |
| */ | |
| Http.put = function (url, data_opt) { | |
| return $http(request( | |
| url, | |
| 'put', | |
| JSON.stringify(data_opt), | |
| 'application/json' | |
| )); | |
| }; | |
| /** | |
| * @param {String} url | |
| * @param {Object} data_opt | |
| * @returns {$http} | |
| */ | |
| Http.delete = function (url, data_opt) { | |
| return $http(request( | |
| url, | |
| 'delete', | |
| JSON.stringify(data_opt), | |
| 'application/json' | |
| )); | |
| }; | |
| /** | |
| * @param {String} url | |
| * @param {Object} data_opt | |
| * @returns {$http} | |
| */ | |
| Http.postForm = function (url, data_opt) { | |
| return $http(request( | |
| url, | |
| 'post', | |
| RequestUtils.toRequestString(data_opt), | |
| 'application/x-www-form-urlencoded' | |
| )); | |
| }; | |
| return Http; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.MathUtils', [ | |
| function () { | |
| /** | |
| * @util MathUtils | |
| */ | |
| var MathUtils = function () { | |
| }; | |
| /** | |
| * @param {Number} arr | |
| * @returns {Number} | |
| */ | |
| MathUtils.findMax = function (arr) { | |
| return Math.max.apply(Math, arr); | |
| }; | |
| /** | |
| * @param {Number} arr | |
| * @returns {Number} | |
| */ | |
| MathUtils.findMin = function (arr) { | |
| return Math.min.apply(Math, arr); | |
| }; | |
| return MathUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 29/09/2015 | |
| */ | |
| pamarin.factory('util.MessageDisplay', [ | |
| 'util.StringTokenizer', | |
| function (StringTokenizer) { | |
| /** | |
| * @util MessageDisplay | |
| */ | |
| var MessageDisplay = function () { | |
| }; | |
| /** | |
| * message display size less than or equal | |
| */ | |
| MessageDisplay.SIZE = 120; | |
| /** | |
| * @param {String} str | |
| * @returns {String} | |
| */ | |
| MessageDisplay.substring = function (str) { | |
| return StringTokenizer.substring(str, MessageDisplay.SIZE); | |
| }; | |
| return MessageDisplay; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 29/09/2015 | |
| */ | |
| pamarin.factory('util.Messages', [ | |
| function () { | |
| /** | |
| * @util Messages | |
| */ | |
| var Messages = function () { | |
| }; | |
| /** | |
| * @param {String} msg | |
| * @param {Object} params | |
| * | |
| * @returns {String} | |
| */ | |
| Messages.replace = function (msg, params) { | |
| return msg.replace(/\$\{(.*?)\}/g, function (name) { | |
| return (params || {})[name.replace(/[(\$\{)\}]/g, '')] || name; | |
| }); | |
| }; | |
| return Messages; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.PageUtils', [ | |
| 'model.PageRequest', | |
| function (PageRequest) { | |
| /** | |
| * @util PageUtils | |
| */ | |
| var PageUtils = function () { | |
| }; | |
| /** | |
| * @param {PageResource} page | |
| * @param {Function} callback | |
| */ | |
| PageUtils.nextPage = function (page, callback) { | |
| if (page.hasNextPage) { | |
| callback(new PageRequest(page.number + 1, page.size)); | |
| } | |
| }; | |
| return PageUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.RequestUtils', [ | |
| function () { | |
| /** | |
| * @util RequestUtils | |
| */ | |
| var RequestUtils = function () { | |
| }; | |
| /** | |
| * @param {Object} data | |
| * @returns {String} | |
| */ | |
| RequestUtils.toRequestString = function (data) { | |
| var key, result = []; | |
| for (key in data) { | |
| if (data.hasOwnProperty(key)) { | |
| result.push(encodeURIComponent(key) + "=" + encodeURIComponent(data[key])); | |
| } | |
| } | |
| return result.join("&"); | |
| }; | |
| return RequestUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.ResponseMapper', [ | |
| 'messages', | |
| 'model.PageResource', | |
| 'model.ProtocolMapper', | |
| 'component.AlertDialog', | |
| 'validation.Validations', | |
| function (messages, PageResource, ProtocolMapper, AlertDialog, Validations) { | |
| /** | |
| * @util ResponseMapper | |
| */ | |
| var ResponseMapper = function (Http) { | |
| this.Http = Http; | |
| this.model = null; | |
| this._filter = null; | |
| }; | |
| /** | |
| * @param {util.Http} Http | |
| * @returns {ResponseMapper} | |
| */ | |
| ResponseMapper.fromHttp = function (Http) { | |
| return new ResponseMapper(Http); | |
| }; | |
| /** | |
| * @param {@model} model | |
| * @returns {ResponseMapper} | |
| */ | |
| ResponseMapper.prototype.map2Model = function (model) { | |
| this.model = model; | |
| if (!angular.isFunction(model)) { | |
| throw new Error('invalid model type.'); | |
| } | |
| return this; | |
| }; | |
| /** | |
| * @param {Function} callback | |
| * @returns {ResponseMapper} | |
| */ | |
| ResponseMapper.prototype.filter = function (callback) { | |
| this._filter = callback; | |
| return this; | |
| }; | |
| function operateWhenError(protocol) { | |
| if (protocol.error.fields) { //http 400 | |
| Validations.showError(protocol.error.fields); | |
| return; | |
| } | |
| AlertDialog.create() | |
| .setHeader(messages['dialog.warning.TITLE']) | |
| .setMessage(protocol.error.user_message) | |
| .open(); | |
| } | |
| function translateData(protocol) { | |
| Validations.clearError(); | |
| if (protocol.error) { | |
| operateWhenError(protocol); | |
| return; | |
| } | |
| return protocol.payload; | |
| } | |
| /** | |
| * @param {Function} callback | |
| */ | |
| ResponseMapper.prototype.returnPage = function (callback) { | |
| var self = this; | |
| this.Http.success(function (protocol) { | |
| protocol = translateData(protocol); | |
| if (protocol) { | |
| protocol = PageResource.fromProtocol(protocol); | |
| protocol.content = ProtocolMapper.fromArray(protocol.content, self.model); | |
| if (self._filter) { | |
| callback(self._filter(protocol)); | |
| } else { | |
| callback(protocol); | |
| } | |
| } | |
| }); | |
| }; | |
| /** | |
| * @param {Function} callback | |
| */ | |
| ResponseMapper.prototype.returnOne = function (callback) { | |
| var self = this; | |
| this.Http.success(function (protocol) { | |
| protocol = translateData(protocol); | |
| if (protocol) { | |
| if (self.model && angular.isFunction(self.model.fromProtocol)) { | |
| protocol = self.model.fromProtocol(protocol); | |
| } | |
| if (self._filter) { | |
| callback(self._filter(protocol)); | |
| } else { | |
| callback(protocol); | |
| } | |
| } | |
| }); | |
| }; | |
| /** | |
| * @param {Function} callback | |
| */ | |
| ResponseMapper.prototype.returnList = function (callback) { | |
| var self = this; | |
| this.Http.success(function (protocol) { | |
| protocol = translateData(protocol); | |
| if (protocol) { | |
| protocol = ProtocolMapper.fromArray(protocol, self.model); | |
| if (self._filter) { | |
| callback(self._filter(protocol)); | |
| } else { | |
| callback(protocol); | |
| } | |
| } | |
| }); | |
| }; | |
| return ResponseMapper; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 08/09/2015 | |
| */ | |
| pamarin.factory('util.ResponseUtils', [ | |
| function () { | |
| /** | |
| * @util ResponseUtils | |
| */ | |
| var ResponseUtils = function () { | |
| }; | |
| /** | |
| * @param {Object} reponse | |
| * @returns {Boolean} | |
| */ | |
| ResponseUtils.isBadRequest = function (reponse) { | |
| return reponse.status_code === 400; | |
| }; | |
| return ResponseUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 27/09/2015 | |
| */ | |
| pamarin.factory('util.StringTokenizer', [ | |
| 'util.StringUtils', | |
| function (StringUtils) { | |
| /** | |
| * @util StringTokenizer | |
| */ | |
| var StringTokenizer = function () { | |
| }; | |
| function array2String(arr) { | |
| return arr.map(function (str) { | |
| return StringUtils.hasText(str) ? str : ''; | |
| }).join(' '); | |
| } | |
| /** | |
| * @param {String} str | |
| * @param {Number} size | |
| * @returns {String} | |
| */ | |
| StringTokenizer.substring = function (str, size) { | |
| if (angular.isArray(str)) { | |
| str = array2String(str); | |
| } | |
| if (!StringUtils.hasText(str)) { | |
| return ''; | |
| } | |
| str = str.replace('\n', ' '); | |
| if (str.length <= size) { | |
| return str.trim(); | |
| } | |
| var splited = split(str, size); | |
| if (splited.length < (size / 2)) { | |
| return str.substring(0, size).trim() + '...'; | |
| } | |
| return splited.trim() + '...'; | |
| }; | |
| function split(str, size) { | |
| var split = str.split(' '); | |
| var builder = []; | |
| var length = 0; | |
| angular.forEach(split, function (txt) { | |
| length = length + txt.length + 1; | |
| if (length < size) { | |
| builder.push(txt); | |
| builder.push(' '); | |
| } | |
| }); | |
| return builder.join(''); | |
| } | |
| return StringTokenizer; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 05/09/2015 | |
| */ | |
| pamarin.factory('util.StringUtils', [ | |
| function () { | |
| /** | |
| * @author StringUtils | |
| */ | |
| var StringUtils = function () { | |
| }; | |
| function isNotString(str) { | |
| return str !== null | |
| && typeof str !== 'undefined' | |
| && typeof str !== 'string'; | |
| } | |
| /** | |
| * @param {String} str | |
| * @returns {Boolean} | |
| */ | |
| StringUtils.hasText = function (str) { | |
| if (isNotString(str)) { | |
| throw new Error('require string'); | |
| } | |
| if (!str) { | |
| return false; | |
| } | |
| return str.length > 0; | |
| }; | |
| return StringUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('util.Time', [ | |
| 'config', | |
| 'moment', | |
| function (config, moment) { | |
| var pattern = config.dateTimePattern; | |
| /** | |
| * @util {Time} | |
| */ | |
| var Time = function () { | |
| }; | |
| /** | |
| * @param {String} date | |
| * @returns {String} | |
| */ | |
| Time.fromNow = function (date) { | |
| if (!date) { | |
| return null; | |
| } | |
| var mmnt = moment(date, pattern.parser); | |
| var now = moment(); | |
| //since 1 year up | |
| if (now.diff(mmnt, 'year') > 0) { | |
| return mmnt.format(pattern.fromNowLong); | |
| } | |
| //since 2 day up | |
| if (now.diff(mmnt, 'day') > 1) { | |
| return mmnt.format(pattern.fromNowShort); | |
| } | |
| //since 1 day up | |
| if (now.diff(mmnt, 'day') > 0) { | |
| return mmnt.format(pattern.fromNowYesterday); | |
| } | |
| if (now.diff(mmnt, 'hour') > 6) { | |
| if (now.day() === mmnt.day()) { | |
| return mmnt.format(pattern.fromNowTimeOnly); | |
| } else { | |
| return mmnt.format(pattern.fromNowYesterday); | |
| } | |
| } | |
| return mmnt.fromNow(); | |
| }; | |
| return Time; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 20/08/2015 | |
| */ | |
| pamarin.factory('util.Values', [ | |
| function () { | |
| /** | |
| * @util Values | |
| */ | |
| var Values = function () { | |
| }; | |
| function isBoolean(value) { | |
| return typeof value === 'boolean'; | |
| } | |
| function isNaN(value) { | |
| return toString(value) === toString(Number.NaN); | |
| } | |
| function toString(value) { | |
| return '' + value; | |
| } | |
| function isModel(value) { | |
| return angular.isObject(value) | |
| && typeof value['toProtocol'] !== 'undefined'; | |
| } | |
| /** | |
| * @param {Any} value | |
| * @param {Function} callback | |
| * @param {Object} context_opt | |
| * @returns {Any} | |
| */ | |
| Values.asValue = function (value, callback, context_opt) { | |
| if (Values.isNotDefined(value)) { | |
| return null; | |
| } | |
| if (isModel(value)) { | |
| return value.toProtocol() || null; | |
| } | |
| if (angular.isFunction(callback)) { | |
| var result = callback.call(context_opt); | |
| if (Values.isDefined(result)) { | |
| return result; | |
| } | |
| } else { | |
| if (Values.isDefined(callback)) { | |
| return callback; | |
| } | |
| } | |
| return value; | |
| }; | |
| /** | |
| * @param {Any} variable | |
| * @returns {Boolean} | |
| */ | |
| Values.isDefined = function (variable) { | |
| if (isNaN(variable)) { | |
| return false; | |
| } | |
| if (angular.isNumber(variable)) { | |
| return true; | |
| } | |
| if (isBoolean(variable)) { | |
| return true; | |
| } | |
| if (angular.isArray(variable)) { | |
| return !!variable.length; | |
| } | |
| if (angular.isString(variable)) { | |
| return !!variable.length; | |
| } | |
| if (angular.isObject(variable)) { | |
| for (var prop in variable) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| return !!variable; | |
| }; | |
| /** | |
| * @param {Any} variable | |
| * @returns {Boolean} | |
| */ | |
| Values.isNotDefined = function (variable) { | |
| return !Values.isDefined(variable); | |
| }; | |
| return Values; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 27/09/2015 | |
| */ | |
| pamarin.factory('util.YoutubeUtils', [ | |
| 'youtubeEmbedUtils', | |
| function (youtubeEmbedUtils) { | |
| /** | |
| * @author YoutubeUtils | |
| */ | |
| var YoutubeUtils = function () { | |
| }; | |
| /** | |
| * @param {String} url | |
| * @returns {String} | |
| */ | |
| YoutubeUtils.getVideoParamsFromUrl = function (url) { | |
| var index = url.indexOf('v='); | |
| if (index === -1) { | |
| return ''; | |
| } | |
| return youtubeEmbedUtils.getIdFromURL(url); | |
| }; | |
| return YoutubeUtils; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 29/09/2015 | |
| */ | |
| pamarin.factory('algorithm.SequencialDiv2Add', [ | |
| 'util.Values', | |
| function (Values) { | |
| /** | |
| * @algorithm SequencialDiv2Add | |
| */ | |
| var SequencialDiv2Add = function (arr) { | |
| this.arr = arr || []; | |
| this.step = 1000; | |
| this.index; | |
| }; | |
| /** | |
| * @param {Array} arr | |
| * @returns {SequencialDiv2Add} | |
| */ | |
| SequencialDiv2Add.fromArray = function (arr) { | |
| return new SequencialDiv2Add(arr); | |
| }; | |
| /** | |
| * @param {Number} step | |
| * @returns {SequencialDiv2Add} | |
| */ | |
| SequencialDiv2Add.prototype.byStep = function (step) { | |
| this.step = step; | |
| return this; | |
| }; | |
| /** | |
| * @param {Number} toIndex | |
| * @returns {SequencialDiv2Add} | |
| */ | |
| SequencialDiv2Add.prototype.toIndex = function (index) { | |
| this.index = index; | |
| return this; | |
| }; | |
| function add(obj) { | |
| obj.sequence = this.step; | |
| this.arr.push(obj); | |
| } | |
| function addFirst(obj) { | |
| obj.sequence = this.arr[0].sequence - this.step; | |
| this.arr.splice(0, 0, obj); | |
| } | |
| function addLast(obj, before) { | |
| obj.sequence = before.sequence + this.step; | |
| this.arr.splice(this.index, 0, obj); | |
| } | |
| function addBetween(obj, before, after) { | |
| obj.sequence = (before.sequence + after.sequence) / 2.0; | |
| this.arr.splice(this.index, 0, obj); | |
| } | |
| /** | |
| * @returns {Boolean} | |
| */ | |
| SequencialDiv2Add.prototype.isEmpty = function () { | |
| return !this.arr.length; | |
| }; | |
| /** | |
| * @param {Object} obj | |
| * @returns {Array} | |
| */ | |
| SequencialDiv2Add.prototype.add = function (obj) { | |
| if (Values.isDefined(obj.sequence)) { | |
| throw new Error('don\'t define sequence'); | |
| } | |
| if (Values.isNotDefined(this.index)) { | |
| this.index = this.arr.length; | |
| } | |
| if (this.isEmpty()) { | |
| add.call(this, obj); | |
| return this.arr; | |
| } | |
| if (this.index === 0) { | |
| addFirst.call(this, obj); | |
| return this.arr; | |
| } | |
| var before = this.arr[this.index - 1]; | |
| var after = this.arr[this.index]; | |
| if (after) { | |
| addBetween.call(this, obj, before, after); | |
| return this.arr; | |
| } | |
| addLast.call(this, obj, before); | |
| return this.arr; | |
| }; | |
| return SequencialDiv2Add; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 12/09/2015 | |
| */ | |
| pamarin.service('AccountService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.User', | |
| 'util.ResponseMapper', | |
| function (config, Http, User, ResponseMapper) { | |
| var serviceUrl = { | |
| update: config.apiBase + '/users/account/:userId' | |
| }; | |
| /** | |
| * @param {model.User} user | |
| * @param {Function} callback | |
| */ | |
| this.save = function (user, callback) { | |
| console.log(user.toProtocol()); | |
| ResponseMapper.fromHttp(Http.put( | |
| serviceUrl.update.replace(':userId', user.id), | |
| user.toProtocol() | |
| )) | |
| .map2Model(User) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('LoginService', [ | |
| 'util.Http', | |
| 'config', | |
| 'util.ResponseMapper', | |
| function (Http, config, ResponseMapper) { | |
| var serviceUrl = { | |
| loginFacebook: config.apiBase + '/login/facebook' | |
| }; | |
| /** | |
| * @param {Object} ftoken | |
| * @param {Function} callback | |
| */ | |
| this.loginFacebook = function (ftoken, callback) { | |
| ResponseMapper.fromHttp(Http.post(serviceUrl.loginFacebook, ftoken)) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('PageContext', [ | |
| function () { | |
| this.title = jQuery('title').text(); | |
| /** | |
| * @param {model.PageData} data | |
| */ | |
| this.data = function (data) { | |
| this.title = data.title; | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TagLookupService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.TagLookup', | |
| 'util.ResponseMapper', | |
| function (config, Http, TagLookup, ResponseMapper) { | |
| var serviceUrl = { | |
| findAll: config.apiBase + '/taglookups' | |
| }; | |
| /** | |
| * @param {Function} callback | |
| */ | |
| this.findAll = function (callback) { | |
| ResponseMapper.fromHttp(Http.get(serviceUrl.findAll)) | |
| .map2Model(TagLookup) | |
| .returnList(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TagService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.Tag', | |
| 'model.Tags', | |
| 'util.ResponseMapper', | |
| function (config, Http, Tag, Tags, ResponseMapper) { | |
| var serviceUrl = { | |
| update: config.apiBase + '/trips/:tripId/tags' | |
| }; | |
| /** | |
| * @param {String} tripId | |
| * @param {Array<model.Tag>} tags | |
| * @param {Function} callback | |
| */ | |
| this.save = function (tripId, tags, callback) { | |
| ResponseMapper.fromHttp(Http.put( | |
| serviceUrl.update | |
| .replace(":tripId", tripId), | |
| Tags.fromTags(tags).toProtocol() | |
| )) | |
| .map2Model(Tag) | |
| .returnList(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TripCardService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.TripCard', | |
| 'util.ResponseMapper', | |
| function (config, Http, TripCard, ResponseMapper) { | |
| var serviceUrl = { | |
| findLastest: config.apiBase + '/trips/lastest', | |
| findOfUserFollowing: config.apiBase + '/trips/followings' | |
| }; | |
| /** | |
| * @param {Pageable} pageable | |
| * @param {Function} callback | |
| */ | |
| this.findLastest = function (pageable, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.findLastest | |
| + '?' + pageable | |
| )) | |
| .map2Model(TripCard) | |
| .returnPage(callback); | |
| }; | |
| /** | |
| * @param {Pageable} pageable | |
| * @param {Function} callback | |
| */ | |
| this.findOfUserFollowing = function (pageable, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.findOfUserFollowing | |
| + '?' + pageable | |
| )) | |
| .map2Model(TripCard) | |
| .returnPage(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TripCommentService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.Comment', | |
| 'util.ResponseMapper', | |
| function (config, Http, Comment, ResponseMapper) { | |
| var serviceUrl = { | |
| findAll: config.apiBase + '/trips/:tripId/comments', | |
| insert: config.apiBase + '/trips/:tripId/comments', | |
| update: config.apiBase + '/trips/:tripId/comments/:commentId', | |
| delete: config.apiBase + '/trips/:tripId/comments/:commentId' | |
| }; | |
| /** | |
| * @param {String} tripId | |
| * @param {model.PageRequest} pageable | |
| * @param {Function} callback | |
| */ | |
| this.loadByTripId = function (tripId, pageable, callback) { | |
| var url = serviceUrl.findAll | |
| .replace(':tripId', tripId) | |
| + '?' + pageable; | |
| ResponseMapper.fromHttp(Http.get(url)) | |
| .map2Model(Comment) | |
| .returnPage(callback); | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| * @param {Function} callback | |
| */ | |
| this.delete = function (comment, callback) { | |
| var url = serviceUrl.delete | |
| .replace(':tripId', comment.referenceId) | |
| .replace(':commentId', comment.id); | |
| ResponseMapper.fromHttp(Http.delete(url)) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| * @param {Function} callback | |
| */ | |
| this.save = function (comment, callback) { | |
| var http; | |
| if (comment.id) { | |
| http = Http.put( | |
| serviceUrl.update | |
| .replace(':tripId', comment.referenceId) | |
| .replace(':commentId', comment.id), | |
| comment.toProtocol() | |
| ); | |
| } else { | |
| http = Http.post( | |
| serviceUrl.insert | |
| .replace(':tripId', comment.referenceId), | |
| comment.toProtocol() | |
| ); | |
| } | |
| ResponseMapper.fromHttp(http) | |
| .map2Model(Comment) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TripLikeService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.Likes', | |
| 'util.ResponseMapper', | |
| function (config, Http, Likes, ResponseMapper) { | |
| var serviceUrl = { | |
| toggleLike: config.apiBase + '/trips/:tripId/togglelike' | |
| }; | |
| /** | |
| * @param {String} tripId | |
| * @param {Function} callback | |
| * @param {Boolean} sample_opt [optional] | |
| */ | |
| this.toggleLike = function (tripId, callback, sample_opt) { | |
| ResponseMapper.fromHttp(Http.post( | |
| serviceUrl.toggleLike | |
| .replace(':tripId', tripId) | |
| + '?sample=' + (sample_opt || 'false') | |
| )) | |
| .map2Model(Likes) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TripPostService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.Post', | |
| 'util.ResponseMapper', | |
| function (config, Http, Post, ResponseMapper) { | |
| var serviceUrl = { | |
| findAll: config.apiBase + '/trips/:tripId/posts', | |
| insert: config.apiBase + '/trips/:tripId/posts', | |
| update: config.apiBase + '/trips/:tripId/posts/:postId', | |
| delete: config.apiBase + '/trips/:tripId/posts/:postId' | |
| }; | |
| /** | |
| * @param {model.Trip} trip | |
| * @param {model.PageRequest} pageable | |
| * @param {Function} callback | |
| */ | |
| this.findByTrip = function (trip, pageable, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.findAll | |
| .replace(':tripId', trip.id) | |
| + '?' + pageable | |
| )) | |
| .map2Model(Post) | |
| .returnPage(callback); | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| * @param {Function} callback | |
| */ | |
| this.delete = function (post, callback) { | |
| ResponseMapper.fromHttp(Http.delete( | |
| serviceUrl.delete | |
| .replace(':tripId', post.referenceId) | |
| .replace(':postId', post.id) | |
| )) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| * @param {Function} callback | |
| */ | |
| this.save = function (post, callback) { | |
| if (post.id) { | |
| ResponseMapper.fromHttp(Http.put( | |
| serviceUrl.update | |
| .replace(':tripId', post.referenceId) | |
| .replace(':postId', post.id), | |
| post.toProtocol() | |
| )) | |
| .map2Model(Post) | |
| .returnOne(callback); | |
| } else { | |
| ResponseMapper.fromHttp(Http.post( | |
| serviceUrl.insert | |
| .replace(':tripId', post.referenceId), | |
| post.toProtocol() | |
| )) | |
| .map2Model(Post) | |
| .returnOne(callback); | |
| } | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TripService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.Trip', | |
| 'PageContext', | |
| 'model.PageData', | |
| 'enum.ArticleStatus', | |
| 'util.ResponseMapper', | |
| 'model.TripPageContent', | |
| function (config, Http, Trip, pageContext, PageData, ArticleStatus, ResponseMapper, TripPageContent) { | |
| var serviceUrl = { | |
| insert: config.apiBase + '/trips', | |
| delete: config.apiBase + '/trips/:tripId', | |
| toggleLike: config.apiBase + '/trips/:tripId/togglelike', | |
| toggleStatus: config.apiBase + '/trips/:tripId/togglestatus', | |
| findPageData: config.apiBase + '/pagedata/users/:username/trips/:tripname' | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {String} tripname | |
| * @param {Function} callback | |
| */ | |
| this.loadPageDataByUsernameAndTripname = function (username, tripname, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.findPageData | |
| .replace(':username', username) | |
| .replace(':tripname', tripname) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = TripPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {dto.WriteTrip} writeTrip | |
| * @param {Function} callback | |
| */ | |
| this.save = function (writeTrip, callback) { | |
| ResponseMapper.fromHttp(Http.post(serviceUrl.insert, writeTrip.toProtocol())) | |
| .map2Model(Trip) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {String} tripId | |
| * @param {Function} callback | |
| */ | |
| this.toggleStatus = function (tripId, callback) { | |
| ResponseMapper.fromHttp(Http.post( | |
| serviceUrl.toggleStatus | |
| .replace(':tripId', tripId) | |
| )) | |
| .map2Model(ArticleStatus) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {String} tripId | |
| * @param {Function} callback | |
| */ | |
| this.delete = function (tripId, callback) { | |
| ResponseMapper.fromHttp(Http.delete( | |
| serviceUrl.delete.replace(':tripId', tripId) | |
| )) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('TripSettingsService', [ | |
| 'config', | |
| 'util.Http', | |
| 'util.ResponseMapper', | |
| function (config, Http, ResponseMapper) { | |
| var serviceUrl = { | |
| save: config.apiBase + '/trips/:tripId/settings' | |
| }; | |
| /** | |
| * @param {dto.TripSettingsDto} settings | |
| * @param {Function} callback | |
| */ | |
| this.save = function (settings, callback) { | |
| ResponseMapper.fromHttp(Http.post( | |
| serviceUrl.save | |
| .replace(':tripId', settings.tripId) | |
| , settings.toProtocol())) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('UserFollowService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.Follows', | |
| 'model.UserCard', | |
| 'util.ResponseMapper', | |
| function (config, Http, Follows, UserCard, ResponseMapper) { | |
| var serviceUrl = { | |
| toggleFollowByUserId: config.apiBase + '/users/:userId/togglefollow', | |
| loadFollowersByUsername: config.apiBase + '/users/:username/followers', | |
| loadFollowingsByUsername: config.apiBase + '/users/:username/followings' | |
| }; | |
| /** | |
| * @param {String} userId | |
| * @param {Function} callback | |
| * @param {Boolean} count_opt [optional] | |
| * @param {Boolean} sample_opt [optional] | |
| */ | |
| this.toggleFollow = function (userId, callback, count_opt, sample_opt) { | |
| ResponseMapper.fromHttp(Http.post( | |
| serviceUrl.toggleFollowByUserId | |
| .replace(':userId', userId) | |
| + '?count=' + (count_opt || false) + '&sample=' + (sample_opt || false) | |
| )) | |
| .map2Model(Follows) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {model.PageRequest} pageable | |
| * @param {Function} callback | |
| */ | |
| this.loadFollowersByUsername = function (username, pageable, callback) { | |
| ResponseMapper.fromHttp(Http.post( | |
| serviceUrl.loadFollowersByUsername | |
| .replace(':username', username) | |
| + '?' + pageable | |
| )) | |
| .map2Model(UserCard) | |
| .returnPage(callback); | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {model.PageRequest} pageable | |
| * @param {Function} callback | |
| */ | |
| this.loadFollowingsByUsername = function (username, pageable, callback) { | |
| ResponseMapper.fromHttp(Http.post( | |
| serviceUrl.loadFollowingsByUsername | |
| .replace(':username', username) | |
| + '?' + pageable | |
| )) | |
| .map2Model(UserCard) | |
| .returnPage(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('UserService', [ | |
| 'config', | |
| 'util.Http', | |
| 'util.ResponseMapper', | |
| function (config, Http, ResponseMapper) { | |
| var serviceUrl = { | |
| hasUsername: config.apiBase + '/users/:username/has' | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.hasUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.hasUsername | |
| .replace(':username', username) | |
| )) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('UserTripService', [ | |
| 'config', | |
| 'util.Http', | |
| 'model.TripCard', | |
| 'util.ResponseMapper', | |
| function (config, Http, TripCard, ResponseMapper) { | |
| var serviceUrl = { | |
| loadByUsername: config.apiBase + '/users/:username/tripcards', | |
| loadLikeByUsername: config.apiBase + '/users/:username/tripcards/like' | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {model.PageRequest} pageable | |
| * @param {Function} callback | |
| */ | |
| this.loadByUsername = function (username, pageable, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadByUsername | |
| .replace(':username', username) | |
| + '?' + pageable | |
| )) | |
| .map2Model(TripCard) | |
| .returnPage(callback); | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {model.PageRequest} pageable | |
| * @param {Function} callback | |
| */ | |
| this.loadLikeByUsername = function (username, pageable, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadLikeByUsername | |
| .replace(':username', username) | |
| + '?' + pageable | |
| )) | |
| .map2Model(TripCard) | |
| .returnPage(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('HomePageService', [ | |
| 'config', | |
| 'util.Http', | |
| 'PageContext', | |
| 'model.PageData', | |
| 'util.ResponseMapper', | |
| 'model.HomePageContent', | |
| function (config, Http, pageContext, PageData, ResponseMapper, HomePageContent) { | |
| var serviceUrl = { | |
| load: config.apiBase + '/pagedata/home', | |
| loadTripLastest: config.apiBase + '/pagedata/trips/lastest', | |
| loadTripLastestTab: config.apiBase + '/pagedata/tab/trips/lastest', | |
| loadTripFollowing: config.apiBase + '/pagedata/trips/followings', | |
| loadTripFollowingTab: config.apiBase + '/pagedata/tab/trips/followings' | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {Function} callback | |
| */ | |
| this.load = function (callback) { | |
| ResponseMapper.fromHttp(Http.get(serviceUrl.load)) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = HomePageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {Function} callback | |
| */ | |
| this.loadTripLastest = function (callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadTripLastest | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = HomePageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {Function} callback | |
| */ | |
| this.loadTripLastestTab = function (callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadTripLastestTab | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = HomePageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {Function} callback | |
| */ | |
| this.loadTripFollowing = function (callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadTripFollowing | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = HomePageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {Function} callback | |
| */ | |
| this.loadTripFollowingTab = function (callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadTripFollowingTab | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = HomePageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('UserFollowPageService', [ | |
| 'config', | |
| 'util.Http', | |
| 'PageContext', | |
| 'model.PageData', | |
| 'util.ResponseMapper', | |
| 'model.UserPageContent', | |
| function (config, Http, pageContext, PageData, ResponseMapper, UserPageContent) { | |
| var serviceUrl = { | |
| loadFollowerByUsername: config.apiBase + '/pagedata/users/:username/followers', | |
| loadFollowingUsername: config.apiBase + '/pagedata/users/:username/followings', | |
| loadFollowerTabByUsername: config.apiBase + '/pagedata/tab/users/:username/followers', | |
| loadFollowingTabUsername: config.apiBase + '/pagedata/tab/users/:username/followings' | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadFollowerByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadFollowerByUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadFollowingByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadFollowingUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadFollowerTabByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadFollowerTabByUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| //---------------------------------------------------------------------- | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadFollowingTabByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadFollowingTabUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('UserPageService', [ | |
| 'config', | |
| 'util.Http', | |
| 'PageContext', | |
| 'model.PageData', | |
| 'model.UserPageContent', | |
| 'model.AccountPageContent', | |
| 'util.ResponseMapper', | |
| function (config, Http, pageContext, PageData, UserPageContent, AccountPageContent, ResponseMapper) { | |
| var serviceUrl = { | |
| find: config.apiBase + '/pagedata/users', | |
| findByUsername: config.apiBase + '/pagedata/users/:username' | |
| }; | |
| /** | |
| * @param {Function} callback | |
| */ | |
| this.load = function (callback) { | |
| ResponseMapper.fromHttp(Http.get(serviceUrl.find)) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = AccountPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.findByUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('UserTripPageService', [ | |
| 'config', | |
| 'util.Http', | |
| 'PageContext', | |
| 'model.PageData', | |
| 'util.ResponseMapper', | |
| 'model.UserPageContent', | |
| function (config, Http, pageContext, PageData, ResponseMapper, UserPageContent) { | |
| var serviceUrl = { | |
| loadByUsername: config.apiBase + '/pagedata/users/:username/tripcards', | |
| loadLikeByUsername: config.apiBase + '/pagedata/users/:username/tripcards/like' | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadByUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadLikeByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadLikeByUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('UserTripTabService', [ | |
| 'config', | |
| 'util.Http', | |
| 'PageContext', | |
| 'model.PageData', | |
| 'util.ResponseMapper', | |
| 'model.UserPageContent', | |
| function (config, Http, pageContext, PageData, ResponseMapper, UserPageContent) { | |
| var serviceUrl = { | |
| loadByUsername: config.apiBase + '/pagedata/tab/users/:username/tripcards', | |
| loadLikeByUsername: config.apiBase + '/pagedata/tab/users/:username/tripcards/like' | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadByUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| this.loadLikeByUsername = function (username, callback) { | |
| ResponseMapper.fromHttp(Http.get( | |
| serviceUrl.loadLikeByUsername | |
| .replace(':username', username) | |
| )) | |
| .map2Model(PageData) | |
| .filter(function (data) { | |
| data.content = UserPageContent.fromProtocol(data.content); | |
| pageContext.data(data); | |
| return data.content; | |
| }) | |
| .returnOne(callback); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('AuthenToken', [ | |
| 'ipCookie', | |
| function (cookie) { | |
| /** | |
| * @security AuthenToken | |
| */ | |
| var AuthenToken = function () { | |
| }; | |
| AuthenToken.KEY_NAME = 'auth_token'; | |
| AuthenToken.prototype.get = function () { | |
| return cookie(AuthenToken.KEY_NAME); | |
| }; | |
| AuthenToken.prototype.set = function (token) { | |
| cookie(AuthenToken.KEY_NAME, token, { | |
| path: '/' | |
| }); | |
| }; | |
| AuthenToken.prototype.clear = function () { | |
| cookie.remove(AuthenToken.KEY_NAME, { | |
| path: '/' | |
| }); | |
| }; | |
| return AuthenToken; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.service('SecurityContext', [ | |
| 'principal', | |
| '$state', | |
| 'model.User', | |
| 'AuthenToken', | |
| function (principal, $state, User, AuthenToken) { | |
| var ANONYMOUS = 'anonymous'; | |
| var authenToken = new AuthenToken(); | |
| this.principal = User.fromProtocol(principal); | |
| this.invalidToken = function () { | |
| authenToken.clear(); | |
| location.reload(true); | |
| }; | |
| this.regisToken = function (token) { | |
| authenToken.set(token); | |
| }; | |
| this.user = function (user) { | |
| if (user instanceof User) { | |
| this.principal = user; | |
| } | |
| return this.principal; | |
| }; | |
| this.anonymous = function () { | |
| return this.user().id === ANONYMOUS; | |
| }; | |
| this.toProfile = function () { | |
| $state.go('users', { | |
| username: this.user().username | |
| }, { | |
| reload: true | |
| }); | |
| }; | |
| if (this.anonymous()) { | |
| authenToken.clear(); | |
| } | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('lazy.LazyLoad', [ | |
| 'model.PageRequest', | |
| function (PageRequest) { | |
| /** | |
| * @lazy LazyLoad | |
| */ | |
| var LazyLoad = function () { | |
| this.content = []; | |
| this.totalElements = 0; | |
| this.load(this.pageNumber, this.pageSize); | |
| }; | |
| /** | |
| * @constant | |
| */ | |
| LazyLoad.DEFAULT_PAGE_NUMBER = 1; | |
| LazyLoad.DEFAULT_PAGE_SIZE = 25; | |
| LazyLoad.constructor = LazyLoad; | |
| /** | |
| * @abstract | |
| */ | |
| LazyLoad.prototype.onLoad = function (pageable, callback) { | |
| }; | |
| LazyLoad.prototype.getIdParam = function () { | |
| return "id"; | |
| }; | |
| LazyLoad.prototype.load = function (pageNumber, pageSize) { | |
| var that = this; | |
| pageNumber = pageNumber || LazyLoad.DEFAULT_PAGE_NUMBER; | |
| pageSize = pageSize || LazyLoad.DEFAULT_PAGE_SIZE; | |
| var request = new PageRequest(pageNumber - 1, pageSize, this.sorts); | |
| this.onLoad(request, function (page) { | |
| that.content = page.content || []; | |
| that.totalElements = page.totalElements || 0; | |
| }); | |
| }; | |
| LazyLoad.prototype.remove = function (obj) { | |
| angular.forEach(this.content, function (item, index) { | |
| if (item[this.getIdParam()] === obj[this.getIdParam()]) { | |
| this.content.splice(index, 1); | |
| this.totalElements = this.totalElements - 1; | |
| return false; | |
| } | |
| }, this); | |
| } | |
| LazyLoad.prototype.getData = function (id) { | |
| var obj = null; | |
| angular.forEach(this.content, function (item) { | |
| if (item[this.getIdParam()] === id) { | |
| obj = item; | |
| return false; | |
| } | |
| }, this); | |
| return obj; | |
| }; | |
| return LazyLoad; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 02/10/2015 | |
| */ | |
| pamarin.factory('state.DirtyState', [ | |
| 'util.StringUtils', | |
| function (StringUtils) { | |
| /** | |
| * @state DirtyState | |
| */ | |
| var DirtyState = function () { | |
| }; | |
| function find$Element() { | |
| return jQuery('.ng-dirty'); | |
| } | |
| /** | |
| * @returns {Boolean} | |
| */ | |
| DirtyState.isDirty = function () { | |
| var $el = find$Element(); | |
| if ($el.hasClass('ng-hide')) { | |
| return false; | |
| } | |
| if ($el.parents('.ng-hide').length) { | |
| return false; | |
| } | |
| return StringUtils.hasText($el.val()); | |
| }; | |
| DirtyState.clearDirty = function () { | |
| find$Element().removeClass('ng-dirty'); | |
| }; | |
| return DirtyState; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 03/10/2015 | |
| */ | |
| pamarin.factory('state.State', [ | |
| '$state', | |
| function ($state) { | |
| /** | |
| * @state State | |
| */ | |
| var State = function () { | |
| }; | |
| State.reload = function () { | |
| $state.go($state.current.name, $state.params, { | |
| reload: true | |
| }); | |
| }; | |
| return State; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 27/08/2015 | |
| */ | |
| pamarin.factory('component.AlertDialog', [ | |
| 'component.Dialog', | |
| function (Dialog) { | |
| /** | |
| * @component AlertDialog extends Dialog | |
| */ | |
| var AlertDialog = function () { | |
| this.header = null; | |
| this.message = null; | |
| Dialog.call(this, 'pr_alert_dialog'); | |
| this.className = 'pr-alert-dialog'; | |
| }; | |
| /** | |
| * @returns {AlertDialog} | |
| */ | |
| AlertDialog.create = function () { | |
| return new AlertDialog(); | |
| }; | |
| angular.extend(AlertDialog.prototype, Dialog.prototype); | |
| /** | |
| * @param {String} header | |
| * @returns {AlertDialog} | |
| */ | |
| AlertDialog.prototype.setHeader = function (header) { | |
| this.header = header; | |
| return this; | |
| }; | |
| /** | |
| * @param {String} message | |
| * @returns {AlertDialog} | |
| */ | |
| AlertDialog.prototype.setMessage = function (message) { | |
| this.message = message; | |
| return this; | |
| }; | |
| /** | |
| * @override Dialog | |
| */ | |
| AlertDialog.prototype.open = function () { | |
| this.data = this.data || {}; | |
| this.data.header = this.header; | |
| this.data.message = this.message; | |
| return Dialog.prototype.open.call(this); | |
| }; | |
| return AlertDialog; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 27/08/2015 | |
| */ | |
| pamarin.factory('component.ConfirmDialog', [ | |
| 'messages', | |
| 'component.Dialog', | |
| function (messages, Dialog) { | |
| /** | |
| * @component ConfirmDialog extends Dialog | |
| */ | |
| var ConfirmDialog = function () { | |
| this.header = null; | |
| this.message = null; | |
| this.confirmButtonLabel = messages.YES; | |
| this.cancelButtonLabel = messages.NO; | |
| this.preConfirmCallback = null; | |
| this.preCancelCallback = null; | |
| Dialog.call(this, 'pr_confirm_dialog'); | |
| this.className = 'pr-confirm-dialog'; | |
| }; | |
| /** | |
| * @returns {ConfirmDialog} | |
| */ | |
| ConfirmDialog.create = function () { | |
| return new ConfirmDialog(); | |
| }; | |
| angular.extend(ConfirmDialog.prototype, Dialog.prototype); | |
| /** | |
| * @param {String} header | |
| * @returns {ConfirmDialog} | |
| */ | |
| ConfirmDialog.prototype.setHeader = function (header) { | |
| this.header = header; | |
| return this; | |
| }; | |
| /** | |
| * @param {String} message | |
| * @returns {ConfirmDialog} | |
| */ | |
| ConfirmDialog.prototype.setMessage = function (message) { | |
| this.message = message; | |
| return this; | |
| }; | |
| /** | |
| * @param {String} label | |
| * @returns {ConfirmDialog} | |
| */ | |
| ConfirmDialog.prototype.setConfirmButtonLabel = function (label) { | |
| this.confirmButtonLabel = label; | |
| return this; | |
| }; | |
| /** | |
| * @param {String} label | |
| * @returns {ConfirmDialog} | |
| */ | |
| ConfirmDialog.prototype.setCancelButtonLabel = function (label) { | |
| this.cancelButtonLabel = label; | |
| return this; | |
| }; | |
| /** | |
| * @override Dialog | |
| */ | |
| ConfirmDialog.prototype.open = function () { | |
| this.data = this.data || {}; | |
| this.data.header = this.header; | |
| this.data.message = this.message; | |
| this.data.confirmButtonLabel = this.confirmButtonLabel; | |
| this.data.cancelButtonLabel = this.cancelButtonLabel; | |
| var self = this; | |
| Dialog.prototype.onPreClose.call(this, function (data) { | |
| if (data === 'OK') { | |
| self.preConfirmCallback && self.preConfirmCallback(); | |
| } else { | |
| self.preCancelCallback && self.preCancelCallback(); | |
| } | |
| }); | |
| return Dialog.prototype.open.call(this); | |
| }; | |
| /** | |
| * @param {Function} callback | |
| * @returns {ConfirmDialog} | |
| */ | |
| ConfirmDialog.prototype.onPreConfirm = function (callback) { | |
| this.preConfirmCallback = callback; | |
| return this; | |
| }; | |
| /** | |
| * @param {Function} callback | |
| * @returns {ConfirmDialog} | |
| */ | |
| ConfirmDialog.prototype.onPreCancel = function (callback) { | |
| this.preCancelCallback = callback; | |
| return this; | |
| }; | |
| return ConfirmDialog; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 26/08/2015 | |
| */ | |
| pamarin.factory('component.Dialog', [ | |
| 'ngDialog', | |
| function (dialog) { | |
| /** | |
| * @component Dialog | |
| * @param {String} template | |
| */ | |
| var Dialog = function (template) { | |
| this.template = template; | |
| this.data = null; | |
| this.className = null; | |
| this.preCloseCallback = null; | |
| }; | |
| /** | |
| * @param {String} template | |
| * @returns {Dialog} | |
| */ | |
| Dialog.fromTemplate = function (template) { | |
| return new Dialog(template); | |
| }; | |
| /** | |
| * @param {Object} data | |
| * @returns {Dialog} | |
| */ | |
| Dialog.prototype.setData = function (data) { | |
| this.data = data; | |
| return this; | |
| }; | |
| /** | |
| * @param {String} className | |
| * @returns {Dialog} | |
| */ | |
| Dialog.prototype.setClassName = function (className) { | |
| this.className = className; | |
| return this; | |
| }; | |
| /** | |
| * @param {Function} callback | |
| * @returns {Dialog} | |
| */ | |
| Dialog.prototype.onPreClose = function (callback) { | |
| this.preCloseCallback = callback; | |
| return this; | |
| }; | |
| Dialog.prototype.open = function () { | |
| return dialog.open({ | |
| template: this.template, | |
| className: 'ngdialog-theme-default ' + (this.className ? this.className : ''), | |
| data: this.data, | |
| preCloseCallback: this.preCloseCallback | |
| }); | |
| }; | |
| return Dialog; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 18/09/2015 | |
| */ | |
| pamarin.factory('component.Notification', [ | |
| 'Notification', | |
| function (Noti) { | |
| /** | |
| * @component Notification | |
| */ | |
| var Notification = function () { | |
| this.title = null; | |
| this.message = null; | |
| }; | |
| /** | |
| * @returns {Notification} | |
| */ | |
| Notification.create = function () { | |
| return new Notification(); | |
| }; | |
| /** | |
| * @param {String} title | |
| * @returns {Notification} | |
| */ | |
| Notification.prototype.setTitle = function (title) { | |
| this.title = title; | |
| return this; | |
| }; | |
| /** | |
| * @param {String} message | |
| * @returns {Notification} | |
| */ | |
| Notification.prototype.setMessage = function (message) { | |
| this.message = message; | |
| return this; | |
| }; | |
| Notification.prototype.show = function () { | |
| Noti({ | |
| title: this.title, | |
| message: this.message | |
| }); | |
| }; | |
| return Notification; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 24/08/2015 | |
| */ | |
| pamarin.factory('validation.Validations', [ | |
| function () { | |
| /** | |
| * @util Validations | |
| */ | |
| var Validations = function () { | |
| }; | |
| function clear(selector){ | |
| jQuery(selector).html('') | |
| .parent() | |
| .removeClass('has-error'); | |
| } | |
| Validations.clearError = function () { | |
| clear('[data-validate]'); | |
| clear('[data-validate-type]'); | |
| }; | |
| /** | |
| * @param {Array} errors | |
| */ | |
| Validations.showError = function (errors) { | |
| Validations.clearError(); | |
| angular.forEach(errors, function (err) { | |
| var $small; | |
| if (err.field_name) { | |
| $small = jQuery('[data-validate="' + err.field_name + '"]'); | |
| } else { | |
| $small = jQuery('[data-validate-type="' + err.type_name + '"]'); | |
| } | |
| $small.html(err.user_message) | |
| .addClass('pr-validate-message') | |
| .parents('.pr-input-form') | |
| .addClass('pr-has-error'); | |
| }); | |
| }; | |
| return Validations; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('AboutCtrl', [ | |
| '$scope', | |
| 'component.Dialog', | |
| function ($scope, Dialog) { | |
| $scope.showDialog = function () { | |
| Dialog.fromTemplate('pr_about_dialog') | |
| .setClassName('pr-about-dialog') | |
| .open(); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('AccountCtrl', [ | |
| '$scope', | |
| 'initData', | |
| 'messages', | |
| 'AccountService', | |
| 'SecurityContext', | |
| 'component.Notification', | |
| function ($scope, initData, messages, service, securityContext, Notification) { | |
| if (initData) { | |
| $scope.data = initData; | |
| } | |
| function notify() { | |
| Notification.create() | |
| .setTitle(messages['notification.saveAccount.TITLE']) | |
| .setMessage(messages['notification.saveAccount.MESSAGE']) | |
| .show(); | |
| } | |
| $scope.saveAccount = function () { | |
| service.save( | |
| $scope.data.user, | |
| function (user) { | |
| $scope.data.user = user; | |
| securityContext.user(user); | |
| notify(); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 08/09/2015 | |
| */ | |
| pamarin.controller('AlertDialogCtrl', [ | |
| '$scope', | |
| function ($scope) { | |
| $scope.data = $scope.ngDialogData; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('CommentCtrl', [ | |
| '$scope', | |
| 'messages', | |
| 'util.PageUtils', | |
| 'TripCommentService', | |
| 'util.MessageDisplay', | |
| 'component.ConfirmDialog', | |
| function ($scope, messages, PageUtils, commentService, MessageDisplay, ConfirmDialog) { | |
| /** | |
| * @param {model.Comment} comment | |
| */ | |
| function deleteComment(comment) { | |
| commentService.delete( | |
| comment, | |
| function (status) { | |
| if (status) { | |
| $scope.data.removeComment(comment); | |
| } | |
| } | |
| ); | |
| } | |
| /** | |
| * @param {model.Comment} comment | |
| */ | |
| $scope.openConfirmDeleteCommentDialog = function (comment) { | |
| ConfirmDialog.create() | |
| .setHeader(messages['dialog.confirmDeleteComment.TITLE']) | |
| .setMessage(MessageDisplay.substring(comment.message)) | |
| .onPreConfirm(function () { | |
| deleteComment(comment); | |
| }) | |
| .open(); | |
| }; | |
| $scope.postComment = function () { | |
| if ($scope.data.comment.message) { | |
| commentService.save( | |
| $scope.data.comment, | |
| function (comment) { | |
| $scope.data.addComment(comment); | |
| } | |
| ); | |
| } | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| */ | |
| $scope.editComment = function (comment) { | |
| if (comment.message) { | |
| var index = $scope.data.indexOfComment(comment); | |
| commentService.save( | |
| comment, | |
| function (comment) { | |
| comment._editing = false; | |
| $scope.data.replaceComment(comment, index); | |
| } | |
| ); | |
| } | |
| }; | |
| /** | |
| * @param {model.Comment} comment | |
| */ | |
| $scope.cancelComment = function (comment) { | |
| comment.message = comment.backupMessage; | |
| }; | |
| $scope.cancelNewComment = function () { | |
| if ($scope.data.comment.message) { | |
| $scope.data.comment.message = ''; | |
| } | |
| }; | |
| $scope.loadMoreComments = function () { | |
| PageUtils.nextPage( | |
| $scope.data.commentPage, | |
| function (request) { | |
| commentService.loadByTripId( | |
| $scope.data.trip.id, | |
| request, | |
| function (page) { | |
| $scope.data.addCommentPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| if ($scope.data) { | |
| try { | |
| $scope.data.newComment(); | |
| } catch (ex) { | |
| /* swallow */ | |
| } | |
| } | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('ConfirmDialogCtrl', [ | |
| '$scope', | |
| function ($scope) { | |
| $scope.data = $scope.ngDialogData; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('HomeCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| 'util.PageUtils', | |
| 'TripCardService', | |
| function ($state, $scope, initData, PageUtils, tripCardService) { | |
| if (initData) { | |
| $scope.data = initData; | |
| $scope.data.routerState = $state.current.name; | |
| } | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.tripCardPage, | |
| function (request) { | |
| tripCardService.findLastest( | |
| request, | |
| function (page) { | |
| $scope.data.addTripCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('controller.HomePage', [ | |
| 'HomePageService', | |
| function (homePageService) { | |
| var homeState = { | |
| TRIPS_LASTEST: 'home.triplastest', | |
| TRIPS_FOLLOWINGS: 'home.tripofuserfollowing' | |
| }; | |
| /** | |
| * @controller HomePage | |
| */ | |
| var HomePage = function () { | |
| }; | |
| /** | |
| * @param {Function} callback | |
| */ | |
| function tripsLastest(callback) { | |
| homePageService.loadTripLastest(callback); | |
| } | |
| /** | |
| * @param {Function} callback | |
| */ | |
| function tripsFollowings(callback) { | |
| homePageService.loadTripFollowing(callback); | |
| } | |
| /** | |
| * @param {Function} callback | |
| */ | |
| function defaults(callback) { | |
| homePageService.load(callback); | |
| } | |
| /** | |
| * @param {Object} param { stateName } | |
| * @param {Function} callback | |
| */ | |
| HomePage.prototype.loadData = function (param, callback) { | |
| if (homeState.TRIPS_LASTEST === param.stateName) { | |
| tripsLastest.call(this, callback); | |
| } else if (homeState.TRIPS_FOLLOWINGS === param.stateName) { | |
| tripsFollowings.call(this, callback); | |
| } else { | |
| defaults.call(this, callback); | |
| } | |
| }; | |
| return HomePage; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('LoginCtrl', [ | |
| '$scope', | |
| 'LoginService', | |
| 'SecurityContext', | |
| function ($scope, service, securityContext) { | |
| function connected(response) { | |
| return response.status === 'connected'; | |
| } | |
| $scope.loginFacebook = function () { | |
| Facebook.getLoginStatus(function (response) { | |
| if (connected(response)) { | |
| service.loginFacebook( | |
| response.authResponse.accessToken, | |
| function (token) { | |
| securityContext.regisToken(token); | |
| location.reload(true); | |
| } | |
| ); | |
| } | |
| }); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('PageCtrl', [ | |
| '$scope', | |
| 'PageContext', | |
| 'SecurityContext', | |
| function ($scope, pageContext, securityContext) { | |
| $scope.pageContext = pageContext; | |
| $scope.securityContext = securityContext; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('PostMapCtrl', [ | |
| '$scope', | |
| 'enum.MapType', | |
| 'uiGmapIsReady', | |
| 'model.MapMarker', | |
| 'util.GPlaceUtils', | |
| 'uiGmapGoogleMapApi', | |
| 'util.GoogleMapUtils', | |
| function ($scope, MapType, gmapIsReady, MapMarker, GPlaceUtils, googleMapApi, GoogleMapUtils) { | |
| var GOOGLE_MAP_WIDTH = 300; | |
| var DEFAULT_LATITUDE = 13; | |
| var DEFAULT_LONGITUDE = 100; | |
| var DEFAULT_ZOOM_LEVEL = 5; | |
| var _gmap = null; | |
| var _latLng = null; | |
| init(); | |
| /** | |
| * @param {model.PostMap} postMap | |
| * @returns {Object} | |
| */ | |
| function covert2Map(postMap) { | |
| return { | |
| center: { | |
| latitude: postMap.latitude === null ? DEFAULT_LATITUDE : postMap.latitude, | |
| longitude: postMap.longitude === null ? DEFAULT_LONGITUDE : postMap.longitude | |
| }, | |
| zoom: postMap.zoomLevel === null ? DEFAULT_ZOOM_LEVEL : postMap.zoomLevel, | |
| options: { | |
| mapTypeId: postMap.mapType.name.toLowerCase() | |
| //scrollwheel: false, | |
| } | |
| }; | |
| } | |
| function cleanAllMarkers() { | |
| angular.forEach( | |
| $scope.gmarkers, | |
| function (gmarker) { | |
| gmarker.setMap(null); | |
| } | |
| ); | |
| } | |
| function init() { | |
| $scope.post = $scope.ngDialogData; | |
| $scope.map = covert2Map($scope.post.map); | |
| if ($scope.gmarkers) { | |
| cleanAllMarkers(); | |
| } | |
| $scope.gmarkers = []; | |
| $scope.autoMapFocus = true; | |
| } | |
| function pushMarkers(gmap) { | |
| angular.forEach( | |
| $scope.post.map.markers, | |
| function (marker) { | |
| $scope.gmarkers.push(convert2GMarker(gmap, marker)); | |
| } | |
| ); | |
| } | |
| function findNearbyPlaceLocation(places) { | |
| if (_latLng) { | |
| var latLngs = GPlaceUtils.toLatLngs(places); | |
| return GoogleMapUtils.findLatLngOfMinDistance(_latLng, latLngs); | |
| } else { | |
| return places[0].geometry.location; | |
| } | |
| } | |
| function bindSearchBox() { | |
| var input = document.getElementById('pr_googlemap_search_input'); | |
| var searchBox = new google.maps.places.SearchBox(input); | |
| google.maps.event.addListener( | |
| searchBox, | |
| 'places_changed', | |
| function () { | |
| var places = searchBox.getPlaces(); | |
| if (places.length) { | |
| _gmap.panTo(findNearbyPlaceLocation(places)); | |
| } | |
| } | |
| ); | |
| } | |
| gmapIsReady.promise(1).then(function (instances) { | |
| instances.forEach(function (inst) { | |
| pushMarkers(_gmap = inst.map); | |
| bindSearchBox(); | |
| }); | |
| }); | |
| function bindGMarkerDragend(gmap, gmarker) { | |
| google.maps.event.addListener( | |
| gmarker, | |
| 'dragend', | |
| function (event) { | |
| gmarker.marker.latitude = event.latLng.lat(); | |
| gmarker.marker.longitude = event.latLng.lng(); | |
| focusCenter(gmap); | |
| } | |
| ); | |
| } | |
| function focusCenter(gmap) { | |
| if ($scope.autoMapFocus && $scope.gmarkers.length) { | |
| var focus = GoogleMapUtils.calculateFocus($scope.gmarkers, GOOGLE_MAP_WIDTH); | |
| gmap.panTo(focus.center); | |
| if ($scope.gmarkers.length > 1) { | |
| gmap.setZoom(focus.zoom); | |
| } | |
| } | |
| } | |
| function convert2GMarker(gmap, marker) { | |
| var gmarker = new google.maps.Marker({ | |
| map: gmap, | |
| draggable: true, | |
| position: new google.maps.LatLng(marker.latitude, marker.longitude) | |
| }); | |
| marker.gmarker = gmarker; | |
| gmarker.marker = marker; | |
| (bindGMarkerDragend)(gmap, gmarker); | |
| return gmarker; | |
| } | |
| $scope.mapEvents = { | |
| /**/ | |
| maptypeid_changed: function (gmap) { | |
| var mapTypeId = gmap.getMapTypeId().toUpperCase(); | |
| $scope.post.map.mapType = MapType.valueOf(mapTypeId); | |
| }, | |
| /**/ | |
| zoom_changed: function (gmap) { | |
| $scope.post.map.zoomLevel = gmap.getZoom(); | |
| }, | |
| /**/ | |
| center_changed: function (gmap) { | |
| var center = gmap.getCenter(); | |
| $scope.post.map.latitude = center.lat(); | |
| $scope.post.map.longitude = center.lng(); | |
| }, | |
| /**/ | |
| click: function (gmap, etype, args) { | |
| var position = args[0].latLng; | |
| var marker = MapMarker.fromLatitudeLongitude(position.lat(), position.lng()); | |
| $scope.post.map.addMarker(marker); | |
| $scope.gmarkers.push(convert2GMarker(gmap, marker)); | |
| focusCenter(gmap); | |
| } | |
| }; | |
| /** | |
| * @param {google.maps.Marker} gmarker | |
| */ | |
| $scope.onMouseenterMarker = function (gmarker) { | |
| gmarker.setAnimation(google.maps.Animation.BOUNCE); | |
| }; | |
| /** | |
| * @param {google.maps.Marker} gmarker | |
| */ | |
| $scope.onMouseleaveMarker = function (gmarker) { | |
| gmarker.setAnimation(null); | |
| }; | |
| /** | |
| * @param {google.maps.Marker} gmarker | |
| */ | |
| $scope.removeMarker = function (gmarker) { | |
| var gmap = gmarker.getMap(); | |
| gmarker.setMap(null); | |
| var marker = gmarker.marker; | |
| var gindex = $scope.gmarkers.indexOf(gmarker); | |
| $scope.gmarkers.splice(gindex, 1); | |
| var index = $scope.post.map.markers.indexOf(marker); | |
| $scope.post.map.markers.splice(index, 1); | |
| focusCenter(gmap); | |
| }; | |
| /** | |
| * @param {google.maps.Marker} gmarker | |
| */ | |
| $scope.editMarker = function (gmarker) { | |
| gmarker.marker._editing = true; | |
| }; | |
| /** | |
| * @param {google.maps.Marker} gmarker | |
| */ | |
| $scope.cancelMarker = function (gmarker) { | |
| gmarker.marker._editing = false; | |
| }; | |
| /** | |
| * @param {google.maps.Marker} gmarker | |
| */ | |
| $scope.saveMarker = function (gmarker) { | |
| gmarker.marker._editing = false; | |
| }; | |
| $scope.reset = function () { | |
| $scope.post.restore(); | |
| $scope.post.backup(); | |
| init(); | |
| pushMarkers(_gmap); | |
| }; | |
| $scope.detectUserLocation = function () { | |
| if (!navigator.geolocation) { | |
| alert('Browser doesn\'t support Geolocation.'); | |
| } | |
| var success = function (position) { | |
| _latLng = new google.maps.LatLng( | |
| position.coords.latitude, | |
| position.coords.longitude | |
| ); | |
| _gmap.setCenter(_latLng); | |
| }; | |
| var error = function () { | |
| alert('Get Geolocation Fail.'); | |
| }; | |
| navigator.geolocation.getCurrentPosition(success, error); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('SearchCtrl', [ | |
| '$scope', | |
| '$state', | |
| function ($scope, $state) { | |
| $scope.keyword = ''; | |
| $scope.search = function () { | |
| $state.go('search', { | |
| keyword: encodeURIComponent($scope.keyword) | |
| }); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TagCtrl', [ | |
| 'data', | |
| '$scope', | |
| 'TagService', | |
| 'model.TagMapper', | |
| 'TagLookupService', | |
| function (data, $scope, service, TagMapper, lookupService) { | |
| $scope.selected = { | |
| lookups: [] | |
| }; | |
| var initData = $scope.ngDialogData; | |
| if (data.taglookups) { | |
| $scope.lookups = data.taglookups; | |
| translate(initData.selecteds, data.taglookups); | |
| } else { | |
| lookupService.findAll(function (lookups) { | |
| data.taglookups = $scope.lookups = lookups; | |
| translate(initData.selecteds, data.taglookups); | |
| }); | |
| } | |
| $scope.unselectAll = function () { | |
| $scope.selected.lookups = []; | |
| }; | |
| function translate(selecteds, lookups) { | |
| angular.forEach(lookups, function (lookup) { | |
| angular.forEach(selecteds, function (std) { | |
| if (lookup.id === std.id) { | |
| $scope.selected.lookups.push(lookup); | |
| } | |
| }); | |
| }); | |
| } | |
| $scope.saveTag = function () { | |
| var tags = TagMapper.lookups2Tags($scope.selected.lookups, initData.tripId); | |
| service.save( | |
| initData.tripId, | |
| tags, | |
| function (tags) { | |
| $scope.closeThisDialog(tags); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('ToolbarCtrl', [ | |
| '$scope', | |
| 'component.Dialog', | |
| function ($scope, Dialog) { | |
| $scope.writeTrip = function () { | |
| Dialog.fromTemplate('pr_writetrip_dialog') | |
| .setClassName('pr-writetrip-dialog') | |
| .open(); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripCardCtrl', [ | |
| '$scope', | |
| 'TripLikeService', | |
| function ($scope, likeService) { | |
| $scope.toggleLike = function (card) { | |
| likeService.toggleLike( | |
| card.trip.id, | |
| function (likes) { | |
| card.likes = likes; | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripCoverCtrl', [ | |
| '$scope', | |
| 'config', | |
| 'ngDialog', | |
| function ($scope, config, dialog) { | |
| $scope.openTripCoverDialog = function () { | |
| dialog.open({ | |
| template: config.host + '/dialog/tripcover.html', | |
| className: 'ngdialog-theme-default pr-tripsettings-dialog' | |
| }); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'messages', | |
| 'initData', | |
| 'TripService', | |
| 'TripLikeService', | |
| 'model.TagMapper', | |
| 'component.Dialog', | |
| 'UserFollowService', | |
| 'component.Notification', | |
| function ($state, $scope, messages, initData, service, likeService, TagMapper, Dialog, followService, Notification) { | |
| if (initData) { | |
| $scope.data = initData; | |
| } | |
| function notify() { | |
| Notification.create() | |
| .setTitle(messages['notification.selectTag.TITLE']) | |
| .setMessage(messages['notification.selectTag.MESSAGE']) | |
| .show(); | |
| } | |
| $scope.openTagLookupsDialog = function () { | |
| var selecteds = TagMapper.tags2Lookups($scope.data.trip.tags); | |
| Dialog.fromTemplate('pr_tag_lookup_dialog') | |
| .setClassName('pr-taglookup-dialog') | |
| .setData({ | |
| tripId: $scope.data.trip.id, | |
| selecteds: selecteds | |
| }) | |
| .onPreClose(function (tags) { | |
| if (angular.isArray(tags)) { | |
| $scope.data.setTags(tags); | |
| notify(); | |
| } | |
| }) | |
| .open(); | |
| }; | |
| /** | |
| * @param {model.Trip} trip | |
| */ | |
| function replaceState(trip) { | |
| $state.go('trips', { | |
| username: trip.presenter.user.username, | |
| tripname: trip.tripname | |
| }, { | |
| location: 'replace', | |
| reload: true | |
| }); | |
| } | |
| function validateState(data) { | |
| var trip = $scope.data.trip; | |
| var oldTripname = trip.tripname; | |
| trip.tripname = data.tripname; | |
| trip.name = data.name; | |
| if (oldTripname !== data.tripname) { | |
| replaceState(trip); | |
| } | |
| } | |
| $scope.openTripSettingsDailog = function () { | |
| Dialog.fromTemplate('pr_tripsettings_dialog') | |
| .setClassName('pr-tripsettings-dialog') | |
| .setData({ | |
| tripId: $scope.data.trip.id, | |
| name: $scope.data.trip.name, | |
| tripname: $scope.data.trip.tripname | |
| }) | |
| .onPreClose(function (data) { | |
| if (angular.isObject(data)) { | |
| validateState(data); | |
| } | |
| }) | |
| .open(); | |
| }; | |
| $scope.toggleStatus = function () { | |
| service.toggleStatus( | |
| $scope.data.trip.id, | |
| function (status) { | |
| $scope.data.trip.status = status; | |
| } | |
| ); | |
| }; | |
| $scope.toggleLike = function () { | |
| likeService.toggleLike( | |
| $scope.data.trip.id, | |
| function (likes) { | |
| $scope.data.likes = likes; | |
| }, true); | |
| }; | |
| $scope.toggleFollow = function () { | |
| followService.toggleFollow( | |
| $scope.data.trip.presenter.user.id, | |
| function (follows) { | |
| $scope.data.trip.presenter.follows = follows; | |
| }, true); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripFollowingCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| 'util.PageUtils', | |
| 'TripCardService', | |
| function ($state, $scope, initData, PageUtils, service) { | |
| if (initData) { | |
| $scope.data.routerState = $state.current.name; | |
| $scope.data.tripCardPage = initData.tripCardPage; | |
| } | |
| /** | |
| * @override | |
| */ | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.tripCardPage, | |
| function (request) { | |
| service.findOfUserFollowing( | |
| request, | |
| function (page) { | |
| $scope.data.addTripCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripLastestCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| 'util.PageUtils', | |
| 'TripCardService', | |
| function ($state, $scope, initData, PageUtils, service) { | |
| if (initData) { | |
| $scope.data.routerState = $state.current.name; | |
| $scope.data.tripCardPage = initData.tripCardPage; | |
| } | |
| /** | |
| * @override | |
| */ | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.tripCardPage, | |
| function (request) { | |
| service.findLastest( | |
| request, | |
| function (page) { | |
| $scope.data.addTripCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripPostCtrl', [ | |
| '$scope', | |
| 'config', | |
| 'messages', | |
| 'model.Post', | |
| 'enum.PostType', | |
| 'util.Messages', | |
| 'util.PageUtils', | |
| 'TripPostService', | |
| 'component.Dialog', | |
| 'util.MessageDisplay', | |
| 'component.ConfirmDialog', | |
| function ($scope, config, messages, Post, PostType, Messages, PageUtils, tripPostService, Dialog, MessageDisplay, ConfirmDialog) { | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| $scope.editPost = function (post) { | |
| post._editing = true; | |
| post.backup(); | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| $scope.cancelPost = function (post) { | |
| if (post.id) { | |
| post._editing = false; | |
| post.restore(); | |
| } else { | |
| $scope.data.removePost(post); | |
| } | |
| }; | |
| /** | |
| * @param {String} type | |
| */ | |
| $scope.addPost = function (type) { | |
| $scope.data.insertPost(Post.fromType(type), 0); | |
| }; | |
| /** | |
| * @param {Number} index | |
| * @param {String} type | |
| */ | |
| $scope.insertPost = function (index, type) { | |
| $scope.data.insertPost(Post.fromType(type), index); | |
| }; | |
| function canSave(post) { | |
| if (PostType.VIDEO.is(post.type)) { | |
| return post.video.isYouTube(); | |
| } | |
| return true; | |
| } | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| $scope.savePost = function (post) { | |
| if (!canSave(post)) { | |
| return; | |
| } | |
| var index = $scope.data.indexOfPost(post); | |
| tripPostService.save( | |
| post, | |
| function (post) { | |
| $scope.data.replacePost(post, index); | |
| } | |
| ); | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| function deletePost(post) { | |
| tripPostService.delete( | |
| post, | |
| function (status) { | |
| if (status) { | |
| $scope.data.removePost(post); | |
| } | |
| } | |
| ); | |
| } | |
| function deleteMessage(post) { | |
| if (PostType.CONTENT.is(post.type)) { | |
| return MessageDisplay.substring([ | |
| post.title, | |
| post.content.content | |
| ]); | |
| } | |
| if (PostType.MAP.is(post.type)) { | |
| return Messages.replace(messages['dialog.confirmDeletePost.map.MESSAGE'], { | |
| lat: post.map.latitude, | |
| lng: post.map.longitude | |
| }); | |
| } | |
| if (PostType.VIDEO.is(post.type)) { | |
| return Messages.replace(messages['dialog.confirmDeletePost.video.MESSAGE'], { | |
| link: post.video.link | |
| }); | |
| } | |
| return null; | |
| } | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| $scope.openConfirmDeleteDialog = function (post) { | |
| ConfirmDialog.create() | |
| .setHeader(messages['dialog.comfirmDeletePost.TITLE']) | |
| .setMessage(deleteMessage(post)) | |
| .onPreConfirm(function () { | |
| deletePost(post); | |
| }) | |
| .open(); | |
| }; | |
| $scope.loadMorePosts = function () { | |
| PageUtils.nextPage( | |
| $scope.data.postPage, | |
| function (request) { | |
| tripPostService.findByTrip( | |
| $scope.data.trip, | |
| request, | |
| function (page) { | |
| $scope.data.addPostPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| $scope.openPostMapDialog = function (post) { | |
| Dialog.fromTemplate(config.host + '/dialog/postmap.html') | |
| .setClassName('pr-postmap-dialog') | |
| .setData(post) | |
| .open(); | |
| }; | |
| $scope.postTypes = PostType.values; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripPostMapCtrl', [ | |
| '$scope', | |
| 'model.MapMarker', | |
| function ($scope, MapMarker) { | |
| /** | |
| * @param {model.Post} post | |
| */ | |
| $scope.addMapMarker = function (post) { | |
| if (!post.map.markers) { | |
| post.map.markers = []; | |
| } | |
| post.map.markers.push(new MapMarker()); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('TripSettingsCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'messages', | |
| 'TripService', | |
| '$stateParams', | |
| 'util.Messages', | |
| 'dto.TripSettingsDto', | |
| 'TripSettingsService', | |
| 'component.Notification', | |
| 'component.ConfirmDialog', | |
| function ($state, $scope, messages, tripService, $stateParams, Messages, TripSettingsDto, settingsService, Notification, ConfirmDialog) { | |
| $scope.settings = toSettings($scope.ngDialogData); | |
| /** | |
| * @param {Object} data | |
| * @returns {dto.TripSettingsDto} | |
| */ | |
| function toSettings(data) { | |
| var settings = new TripSettingsDto(); | |
| settings.tripId = data.tripId; | |
| settings.name = data.name; | |
| settings.tripname = data.tripname; | |
| return settings; | |
| } | |
| function notifySave() { | |
| Notification.create() | |
| .setTitle(messages['notification.tripSettings.TITLE']) | |
| .setMessage(messages['notification.tripSettings.MESSAGE']) | |
| .show(); | |
| } | |
| $scope.saveSettings = function () { | |
| settingsService.save( | |
| $scope.settings, | |
| function (settings) { | |
| $scope.closeThisDialog(settings); | |
| notifySave(); | |
| } | |
| ); | |
| }; | |
| function notifyDelete(tripName) { | |
| Notification.create() | |
| .setTitle(messages['notification.deleteTrip.TITLE']) | |
| .setMessage(Messages.replace(messages['notification.deleteTrip.MESSAGE'], { | |
| tripName: tripName | |
| })) | |
| .show(); | |
| } | |
| function deleteTrip(tripName) { | |
| tripService.delete( | |
| $scope.settings.tripId, | |
| function (status) { | |
| if (status) { | |
| $state.go('users', { | |
| username: $stateParams.username | |
| }, | |
| { | |
| location: 'replace', | |
| reload: true | |
| }); | |
| notifyDelete(tripName); | |
| } | |
| } | |
| ); | |
| } | |
| $scope.openConfirmDeleteTripDialog = function () { | |
| $scope.closeThisDialog(); | |
| ConfirmDialog.create() | |
| .setHeader(messages['dialog.confirmDeleteTrip.TITLE']) | |
| .setMessage($scope.ngDialogData.name) | |
| .onPreConfirm(function () { | |
| deleteTrip($scope.ngDialogData.name); | |
| }) | |
| .open(); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('UserCardCtrl', [ | |
| '$scope', | |
| 'UserFollowService', | |
| function ($scope, userFollowService) { | |
| /** | |
| * @param {model.UserCard} card | |
| */ | |
| $scope.toggleFollow = function (card) { | |
| userFollowService.toggleFollow( | |
| card.user.id, | |
| function (follows) { | |
| card.followed = follows.followed; | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('UserCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| '$stateParams', | |
| 'util.PageUtils', | |
| 'UserTripService', | |
| 'UserFollowService', | |
| function ($state, $scope, initData, $stateParams, PageUtils, userTripService, userFollowService) { | |
| if (initData) { | |
| $scope.data = initData; | |
| $scope.data.routerState = $state.current.name; | |
| } | |
| $scope.toggleFollow = function () { | |
| userFollowService.toggleFollow( | |
| $scope.data.userCard.user.id, | |
| function (follows) { | |
| $scope.data.userCard.followed = follows.followed; | |
| $scope.data.numberOfFollowers = follows.total; | |
| } | |
| ); | |
| }; | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.tripCardPage, | |
| function (request) { | |
| userTripService.loadByUsername( | |
| $stateParams.username, | |
| request, | |
| function (page) { | |
| $scope.data.addTripCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('UserFollowerCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| '$stateParams', | |
| 'util.PageUtils', | |
| 'UserFollowService', | |
| function ($state, $scope, initData, $stateParams, PageUtils, service) { | |
| if (initData) { | |
| $scope.data.routerState = $state.current.name; | |
| $scope.data.userCardPage = initData.userCardPage; | |
| } | |
| /** | |
| * @override from UserCtrl | |
| */ | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.userCardPage, | |
| function (request) { | |
| service.loadFollowersByUsername( | |
| $stateParams.username, | |
| request, | |
| function (page) { | |
| $scope.data.addUserCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('UserFollowingCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| '$stateParams', | |
| 'util.PageUtils', | |
| 'UserFollowService', | |
| function ($state, $scope, initData, $stateParams, PageUtils, service) { | |
| if (initData) { | |
| $scope.data.routerState = $state.current.name; | |
| $scope.data.userCardPage = initData.userCardPage; | |
| } | |
| /** | |
| * @override from UserCtrl | |
| */ | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.userCardPage, | |
| function (request) { | |
| service.loadFollowingsByUsername( | |
| $stateParams.username, | |
| request, | |
| function (page) { | |
| $scope.data.addUserCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.factory('controller.UserPage', [ | |
| 'UserPageService', | |
| 'UserTripPageService', | |
| 'UserFollowPageService', | |
| function (userPageService, userTripPageService, userFollowPageService) { | |
| var userState = { | |
| TRIPS: 'users.trips', | |
| TRIPS_LIKE: 'users.tripslike', | |
| FOLLOWERS: 'users.followers', | |
| FOLLOWINGS: 'users.followings' | |
| }; | |
| /** | |
| * @controller UserPage | |
| */ | |
| var UserPage = function () { | |
| }; | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| function trips(username, callback) { | |
| userTripPageService.loadByUsername( | |
| username, | |
| callback | |
| ); | |
| } | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| function tripsLike(username, callback) { | |
| userTripPageService.loadLikeByUsername( | |
| username, | |
| callback | |
| ); | |
| } | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| function followers(username, callback) { | |
| userFollowPageService.loadFollowerByUsername( | |
| username, | |
| callback | |
| ); | |
| } | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| function followings(username, callback) { | |
| userFollowPageService.loadFollowingByUsername( | |
| username, | |
| callback | |
| ); | |
| } | |
| /** | |
| * @param {String} username | |
| * @param {Function} callback | |
| */ | |
| function defaults(username, callback) { | |
| userPageService.loadByUsername( | |
| username, | |
| callback | |
| ); | |
| } | |
| /** | |
| * @param {Object} param { username, stateName }, | |
| * @param {Function} callback | |
| */ | |
| UserPage.prototype.loadData = function (param, callback) { | |
| if (userState.TRIPS === param.stateName) { | |
| trips.call(this, param.username, callback); | |
| } else if (userState.TRIPS_LIKE === param.stateName) { | |
| tripsLike.call(this, param.username, callback); | |
| } else if (userState.FOLLOWERS === param.stateName) { | |
| followers.call(this, param.username, callback); | |
| } else if (userState.FOLLOWINGS === param.stateName) { | |
| followings.call(this, param.username, callback); | |
| } else { | |
| defaults.call(this, param.username, callback); | |
| } | |
| }; | |
| return UserPage; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('UserTripCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| '$stateParams', | |
| 'util.PageUtils', | |
| 'UserTripService', | |
| function ($state, $scope, initData, $stateParams, PageUtils, service) { | |
| if (initData) { | |
| $scope.data.routerState = $state.current.name; | |
| $scope.data.tripCardPage = initData.tripCardPage; | |
| } | |
| /** | |
| * @override from UserCtrl | |
| */ | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.tripCardPage, | |
| function (request) { | |
| service.loadByUsername( | |
| $stateParams.username, | |
| request, | |
| function (page) { | |
| $scope.data.addTripCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('UserTripLikeCtrl', [ | |
| '$state', | |
| '$scope', | |
| 'initData', | |
| '$stateParams', | |
| 'util.PageUtils', | |
| 'UserTripService', | |
| function ($state, $scope, initData, $stateParams, PageUtils, service) { | |
| if (initData) { | |
| $scope.data.routerState = $state.current.name; | |
| $scope.data.tripCardPage = initData.tripCardPage; | |
| } | |
| /** | |
| * @override from UserCtrl | |
| */ | |
| $scope.loadMore = function () { | |
| PageUtils.nextPage( | |
| $scope.data.tripCardPage, | |
| function (request) { | |
| service.loadLikeByUsername( | |
| $stateParams.username, | |
| request, | |
| function (page) { | |
| $scope.data.addTripCardPage(page); | |
| } | |
| ); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /** | |
| * @author jittagornp | |
| * create 22/08/2015 | |
| */ | |
| pamarin.controller('WriteTripCtrl', [ | |
| '$scope', | |
| '$state', | |
| 'messages', | |
| 'TripService', | |
| 'dto.WriteTripDto', | |
| 'component.Notification', | |
| function ($scope, $state, messages, service, WriteTripDto, Notification) { | |
| function go2NewTripState(trip) { | |
| $state.go('trips', { | |
| username: trip.presenter.user.username, | |
| tripname: trip.tripname | |
| }); | |
| } | |
| function createDto() { | |
| $scope.writeTrip = new WriteTripDto(); | |
| } | |
| function notify() { | |
| Notification.create() | |
| .setTitle(messages['notification.writeTrip.TITLE']) | |
| .setMessage(messages['notification.writeTrip.MESSAGE']) | |
| .show(); | |
| } | |
| createDto(); | |
| $scope.startWrite = function () { | |
| service.save( | |
| $scope.writeTrip, | |
| function (trip) { | |
| $scope.closeThisDialog(); | |
| go2NewTripState(trip); | |
| notify(); | |
| } | |
| ); | |
| }; | |
| } | |
| ]); | |
| /* | |
| * Pamarin © 2015 | |
| */ | |
| (function ($) { | |
| $(function () { | |
| $('.pr-prerender').remove(); | |
| }); | |
| })(jQuery); | |
| (function ($) { | |
| function getPadding(pos) { | |
| var padding = this.css('padding-' + pos); | |
| if (!padding) { | |
| return 0; | |
| } | |
| return parseInt(padding.replace('px', ''), 10); | |
| } | |
| $.fn.hasScrollBar = function () { | |
| var h = this.height() | |
| + getPadding.call(this, 'top') | |
| + getPadding.call(this, 'bottom'); | |
| return this.get(0).scrollHeight > h; | |
| }; | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment