Commit 4d7dab16fa0162f1383f7e8dfa41e5667662a446
1 parent
0ba7cbbc4e
Exists in
master
and in
1 other branch
Clean code
Showing 3 changed files with 62 additions and 18 deletions Side-by-side Diff
app/scripts/controllers/main.js
| 1 | 1 | define(['app'], function (app) { |
| 2 | 2 | 'use strict'; |
| 3 | 3 | app.controller('MainCtrl', function ($rootScope, $scope, $timeout, $illustration, $t_shirt, $routeParams) { |
| 4 | - // console.log($('nav').width()); | |
| 4 | + //Define and init var | |
| 5 | 5 | $rootScope.API_URL = 'http://domain.com'; |
| 6 | 6 | $scope.designFrameView = 'views/tshirt-design.html?ver='+VERSION; |
| 7 | 7 | $scope.designPartIllustration = 'views/design_part/illustration.html?ver='+VERSION; |
| 8 | 8 | $scope.designPartImage = 'views/design_part/image.html?ver='+VERSION; |
| 9 | 9 | $scope.designPartText = 'views/design_part/text.html?ver='+VERSION; |
| 10 | 10 | $scope.designPartDefault = 'views/design_part/default.html?ver='+VERSION; |
| 11 | - | |
| 12 | - //Action T-Shirt choice color and Back or Front | |
| 13 | 11 | var currentTShirtKey = 0; |
| 12 | + var placeTShirt; | |
| 13 | + var tShirtColorFirstKey = 0; | |
| 14 | + $scope.tShirtChoiceBackFrontKey = 'front'; | |
| 15 | + $scope.tShirtColorKey = tShirtColorFirstKey; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Get param route | |
| 19 | + * @type {any} | |
| 20 | + * @private | |
| 21 | + */ | |
| 14 | 22 | var _routeParams = $routeParams; |
| 15 | 23 | if(typeof _routeParams.tShirt != 'undefined') |
| 16 | 24 | currentTShirtKey = _routeParams.tShirt - 1; |
| 25 | + if(typeof _routeParams.place != 'undefined') | |
| 26 | + placeTShirt = _routeParams.place; | |
| 17 | 27 | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * Get all info TShirt | |
| 31 | + * @param: id | |
| 32 | + * @return: object | |
| 33 | + */ | |
| 18 | 34 | $scope.tShirtColor = $t_shirt.getTShirtColor(currentTShirtKey); |
| 19 | - //Set color name default | |
| 20 | - var tShirtColorFirstKey = 0; | |
| 21 | - $scope.tShirtChoiceBackFrontKey = 'front'; | |
| 22 | - $scope.tShirtColorKey = tShirtColorFirstKey; | |
| 23 | 35 | $rootScope.tShirtColorCode = $scope.tShirtColor[tShirtColorFirstKey].code; |
| 24 | 36 | $scope.tShirtColorName = $scope.tShirtColor[tShirtColorFirstKey].name; |
| 25 | 37 | $scope.tShirtImgFront = $scope.tShirtColor[tShirtColorFirstKey].img.front; |
| 26 | 38 | $scope.tShirtImgBack = $scope.tShirtColor[tShirtColorFirstKey].img.back; |
| 27 | 39 | $scope.tShirtImg = $scope.tShirtImgFront; |
| 28 | - | |
| 29 | 40 | |
| 30 | - //review design set position | |
| 41 | + /** | |
| 42 | + * Set preview size and position | |
| 43 | + */ | |
| 31 | 44 | function setSizePreViewDesign() { |
| 32 | 45 | var _widthPreviewDesign = $('#preview-design').width(); |
| 33 | 46 | var _widthTShirtImage = $('.tshirt-image').width(); |
| 34 | 47 | |
| 35 | 48 | |
| 36 | 49 | |
| ... | ... | @@ -35,23 +48,30 @@ |
| 35 | 48 | $('#preview-design').css({left: leftReviewDesign}); |
| 36 | 49 | } |
| 37 | 50 | setSizePreViewDesign(); |
| 38 | - //event resize window | |
| 39 | 51 | $(window).resize(function () { |
| 40 | 52 | setSizePreViewDesign(); |
| 41 | 53 | }); |
| 42 | - | |
| 54 | + /** | |
| 55 | + * Choice color t-shirt | |
| 56 | + * @param key | |
| 57 | + */ | |
| 43 | 58 | $scope.choiceTShirtColor = function(key) { |
| 44 | 59 | $scope.tShirtColorKey = key; |
| 45 | - $rootScope.tShirtColorCode = $scope.tShirtColor[key].code; | |
| 46 | - $scope.tShirtColorName = $scope.tShirtColor[key].name; | |
| 47 | - $scope.tShirtImgFront = $scope.tShirtColor[key].img.front; | |
| 48 | - $scope.tShirtImgBack = $scope.tShirtColor[key].img.back; | |
| 60 | + var tShirtColor = $scope.tShirtColor[key]; | |
| 61 | + $rootScope.tShirtColorCode = tShirtColor.code; | |
| 62 | + $scope.tShirtColorName = tShirtColor.name; | |
| 63 | + $scope.tShirtImgFront = tShirtColor.img.front; | |
| 64 | + $scope.tShirtImgBack = tShirtColor.img.back; | |
| 49 | 65 | if($scope.tShirtChoiceBackFrontKey == 'front') { |
| 50 | 66 | $scope.tShirtImg = $scope.tShirtImgFront; |
| 51 | 67 | } else { |
| 52 | 68 | $scope.tShirtImg = $scope.tShirtImgBack; |
| 53 | 69 | } |
| 54 | 70 | }; |
| 71 | + /** | |
| 72 | + * Choice back or front t-shirt | |
| 73 | + * @param choice | |
| 74 | + */ | |
| 55 | 75 | $scope.choiceTShirtBackFront = function(choice) { |
| 56 | 76 | if(choice == 'front') { |
| 57 | 77 | $scope.tShirtImg = $scope.tShirtImgFront; |
| ... | ... | @@ -72,7 +92,9 @@ |
| 72 | 92 | this.$apply(fn); |
| 73 | 93 | } |
| 74 | 94 | }; |
| 75 | - | |
| 95 | + /** | |
| 96 | + * Open modal design | |
| 97 | + */ | |
| 76 | 98 | $scope.modalTShirtDesign = function() { |
| 77 | 99 | $('#tshirt-design').modal( |
| 78 | 100 | { |
| ... | ... | @@ -82,6 +104,9 @@ |
| 82 | 104 | ); |
| 83 | 105 | |
| 84 | 106 | }; |
| 107 | + /** | |
| 108 | + * Close modal design | |
| 109 | + */ | |
| 85 | 110 | $scope.modalClose = function(){ |
| 86 | 111 | $('#tshirt-design').modal('hide'); |
| 87 | 112 | }; |
app/scripts/routes.js
app/scripts/services/tshirt.js
| ... | ... | @@ -11,7 +11,20 @@ |
| 11 | 11 | gender: '', |
| 12 | 12 | image: '' |
| 13 | 13 | }, |
| 14 | - place_design: {}, | |
| 14 | + place_design: { | |
| 15 | + 'place_1' : { | |
| 16 | + 'face' : 'front', | |
| 17 | + 'place' : 't_shirt_p_1' | |
| 18 | + }, | |
| 19 | + 'place_2' : { | |
| 20 | + 'face' : 'front', | |
| 21 | + 'place' : 't_shirt_p_2' | |
| 22 | + }, | |
| 23 | + 'place_3' : { | |
| 24 | + 'face' : 'front', | |
| 25 | + 'place' : 't_shirt_p_3' | |
| 26 | + } | |
| 27 | + }, | |
| 15 | 28 | color: [ |
| 16 | 29 | { |
| 17 | 30 | name: 'color: 2E GRAY', |
| ... | ... | @@ -131,6 +144,12 @@ |
| 131 | 144 | return []; |
| 132 | 145 | } |
| 133 | 146 | return DATA[key]['color']; |
| 147 | + }, | |
| 148 | + getTShirtPlace : function(key, place) { | |
| 149 | + if(typeof DATA[key].place_design.place == 'undefined' || typeof DATA[key].place_design.place == 'null') | |
| 150 | + return []; | |
| 151 | + | |
| 152 | + return DATA[key].place_design.place; | |
| 134 | 153 | }, |
| 135 | 154 | |
| 136 | 155 | getAll: function(){ |