Blame view

app/scripts/controllers/main.js 3.94 KB
c87bc1f33   TRUONG   first commit: ini...
1
2
  define(['app'], function (app) {
  	'use strict';
3ca9f7356   Dang YoungWorld   Add t-shirt
3
  	app.controller('MainCtrl', function ($rootScope, $scope, $timeout, $illustration, $t_shirt, $routeParams) {
4d7dab16f   DANG   Clean code
4
  		//Define and init var
6582efe66   DANG   add css
5
  		$('[data-toggle="tooltip"]').tooltip()
682a3b12d   TRUONG   fix illustration ...
6
  		$rootScope.API_URL = 'http://domain.com';
c9d8b2fe3   Truong LD   update version
7
  		$scope.designFrameView = 'views/tshirt-design.html?ver='+VERSION;
1d6ddfa62   TRUONG   merge
8
  		$scope.designPartIllustration = 'views/design_part/illustration.html?ver='+VERSION;
19a541686   TRUONG   restruct + fix style
9
10
11
  		$scope.designPartImage = 'views/design_part/image.html?ver='+VERSION;
  		$scope.designPartText = 'views/design_part/text.html?ver='+VERSION;
  		$scope.designPartDefault = 'views/design_part/default.html?ver='+VERSION;
3ca9f7356   Dang YoungWorld   Add t-shirt
12
  		var currentTShirtKey = 0;
0136530e3   DANG   Commit code
13
  		var placeTShirtKey = '';
4d7dab16f   DANG   Clean code
14
  		var tShirtColorFirstKey = 0;
236cbc7b4   Dang YoungWorld   update theme
15
  		$scope.hideReviewDesign = false;
4d7dab16f   DANG   Clean code
16
17
18
19
20
21
22
23
  		$scope.tShirtChoiceBackFrontKey = 'front';
  		$scope.tShirtColorKey = tShirtColorFirstKey;
  
  		/**
  		 * Get param route
  		 * @type {any}
  		 * @private
  		 */
3ca9f7356   Dang YoungWorld   Add t-shirt
24
25
26
  		var _routeParams = $routeParams;
  		if(typeof _routeParams.tShirt != 'undefined')
  			currentTShirtKey = _routeParams.tShirt - 1;
4d7dab16f   DANG   Clean code
27
  		if(typeof _routeParams.place != 'undefined')
0136530e3   DANG   Commit code
28
  			placeTShirtKey = _routeParams.place;
3ca9f7356   Dang YoungWorld   Add t-shirt
29

4d7dab16f   DANG   Clean code
30
31
32
33
34
  		/**
  		 * Get all info TShirt
  		 * @param: id
  		 * @return: object
  		 */
7e14f1786   Dang YoungWorld   Fix reponsive
35
  		$rootScope.placeTshirt = $t_shirt.getTShirtPlace(currentTShirtKey, placeTShirtKey);
3ca9f7356   Dang YoungWorld   Add t-shirt
36
  		$scope.tShirtColor = $t_shirt.getTShirtColor(currentTShirtKey);
422e7837d   DANG   Change color t-shirt
37
38
39
40
41
  		$rootScope.tShirtColorCode = $scope.tShirtColor[tShirtColorFirstKey].code;
  		$scope.tShirtColorName = $scope.tShirtColor[tShirtColorFirstKey].name;
  		$scope.tShirtImgFront = $scope.tShirtColor[tShirtColorFirstKey].img.front;
  		$scope.tShirtImgBack = $scope.tShirtColor[tShirtColorFirstKey].img.back;
  		$scope.tShirtImg = $scope.tShirtImgFront;
4d7dab16f   DANG   Clean code
42
43
44
  		/**
  		 * Set preview size and position
  		 */
360081503   DANG   Fix reponsive
45
  		function setSizePreViewDesign() {
360081503   DANG   Fix reponsive
46
  			var _widthTShirtImage = $('.tshirt-image').width();
7e14f1786   Dang YoungWorld   Fix reponsive
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  			if(typeof $rootScope.placeTshirt.place == 'undefined')
  				return;
  
  			var place = $rootScope.placeTshirt.place;
  			switch (place) {
  				case 't_shirt_p_1' :
  					var widthPreview = _widthTShirtImage/2.5;
  					var heihtPreview = _widthTShirtImage/2.5;
  					break;
  				case 't_shirt_p_2' :
  					var widthPreview = _widthTShirtImage/2.5;
  					var heihtPreview = _widthTShirtImage/4.5;
  					break;
  				default:
  					break;
  			}
  			$('#preview-design').css({width: widthPreview, height: heihtPreview});
360081503   DANG   Fix reponsive
64
65
  		}
  		setSizePreViewDesign();
360081503   DANG   Fix reponsive
66
67
68
  		$(window).resize(function () {
  			setSizePreViewDesign();
  		});
4d7dab16f   DANG   Clean code
69
70
71
72
  		/**
  		 * Choice color t-shirt
  		 * @param key
  		 */
422e7837d   DANG   Change color t-shirt
73
74
  		$scope.choiceTShirtColor = function(key) {
  			$scope.tShirtColorKey = key;
4d7dab16f   DANG   Clean code
75
76
77
78
79
  			var tShirtColor = $scope.tShirtColor[key];
  			$rootScope.tShirtColorCode = tShirtColor.code;
  			$scope.tShirtColorName = tShirtColor.name;
  			$scope.tShirtImgFront = tShirtColor.img.front;
  			$scope.tShirtImgBack = tShirtColor.img.back;
422e7837d   DANG   Change color t-shirt
80
81
82
83
84
85
  			if($scope.tShirtChoiceBackFrontKey == 'front') {
  				$scope.tShirtImg = $scope.tShirtImgFront;
  			} else {
  				$scope.tShirtImg = $scope.tShirtImgBack;
  			}
  		};
4d7dab16f   DANG   Clean code
86
87
88
89
  		/**
  		 * Choice back or front t-shirt
  		 * @param choice
  		 */
422e7837d   DANG   Change color t-shirt
90
91
92
93
94
95
96
97
  		$scope.choiceTShirtBackFront = function(choice) {
  			if(choice == 'front') {
  				$scope.tShirtImg = $scope.tShirtImgFront;
  			} else {
  				$scope.tShirtImg = $scope.tShirtImgBack;
  			}
  			$scope.tShirtChoiceBackFrontKey = choice;
  		};
c8bfdfd96   DANG   event click object
98
99
100
101
102
103
104
105
106
  		//safeApply
  		$rootScope.safeApply = function(fn) {
  			var phase = this.$root.$$phase;
  			if(phase == '$apply' || phase == '$digest') {
  				if(fn && (typeof(fn) === 'function')) {
  					fn();
  				}
  			} else {
  				this.$apply(fn);
6f105dbd5   Truong LD   add source code i...
107
  			}
422e7837d   DANG   Change color t-shirt
108
  		};
4d7dab16f   DANG   Clean code
109
110
111
  		/**
  		 * Open modal design
  		 */
87c93a029   Dang YoungWorld   add modal
112
  		$scope.modalTShirtDesign = function() {
5fe93ca88   Dang YoungWorld   Theme modal
113
114
115
116
117
118
  			$('#tshirt-design').modal(
  				{
  					backdrop: 'static',
  					keyboard: false
  				}
  			);
2f4c31749   DANG   Fix text design a...
119

5fe93ca88   Dang YoungWorld   Theme modal
120
  		};
4d7dab16f   DANG   Clean code
121
122
123
  		/**
  		 * Close modal design
  		 */
5fe93ca88   Dang YoungWorld   Theme modal
124
125
  		$scope.modalClose = function(){
  			$('#tshirt-design').modal('hide');
422e7837d   DANG   Change color t-shirt
126
  		};
236cbc7b4   Dang YoungWorld   update theme
127
128
129
130
131
132
133
134
135
  		/**
  		 *Show/Hide review design
  		 */
  		$scope.hideShowReviewDesign = function () {
  			if($scope.hideReviewDesign == true)
  				$scope.hideReviewDesign = false;
  			else
  				$scope.hideReviewDesign = true;
  		}
7e14f1786   Dang YoungWorld   Fix reponsive
136

c87bc1f33   TRUONG   first commit: ini...
137
138
  	});
  });