Blame view

app/scripts/controllers/tshirtdesign.js 19.8 KB
6f105dbd5   Truong LD   add source code i...
1
  define(['app'], function (app) {
faf1542f8   TRUONG   fix lazy border w...
2
  	app.controller('TshirtdesignCtrl', function ($scope, $rootScope, $window, $timeout, $illustration, $favorite) {
2681003ca   TRUONG   update #1808, #1809
3
  		$scope.Math = window.Math;
faf1542f8   TRUONG   fix lazy border w...
4
  		$scope.savedFrameView = 'views/design_part/tshirt-saved.html?ver='+VERSION;
6f105dbd5   Truong LD   add source code i...
5
  		var canvas = new fabric.Canvas('main-design-container');
53828b4e7   TRUONG   process save/rest...
6
7
8
  		var diffX = 40, diffY = 40;
  		var _coorTrash_x = 567;
  		var _coorTrash_y = 545;
057ad34c6   TRUONG   fix clear color SVG
9
  		var ObjectOrd=0;
2f4c31749   DANG   Fix text design a...
10
  		//Set width and height canvas
360081503   DANG   Fix reponsive
11
  		function setSizeCanvas() {
4ae9cc634   DANG   fix reponsive
12
13
  			if(typeof $rootScope.placeTshirt.place == 'undefined')
  				return;
360081503   DANG   Fix reponsive
14
15
  			var _modalWidth = $('.modal-dialog').width();
  			var _windowWidth = window.innerWidth;
4ae9cc634   DANG   fix reponsive
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  			var place = $rootScope.placeTshirt.place;
  
  			switch (place) {
  				case 't_shirt_p_1' :
  					$scope.designCanvasClass = 'design-content-t_shirt_p_1';
  					if(_windowWidth > 762) {
  						var _contentCanvasWidth = (_modalWidth*8/12)/1.2;
  						var _contentCanvasHeight = _contentCanvasWidth;
  					} else {
  						var _contentCanvasWidth = _windowWidth-70;
  						var _contentCanvasHeight = _contentCanvasWidth;
  					}
  					break;
  				case 't_shirt_p_2' :
  					$scope.designCanvasClass = 'design-content-t_shirt_p_2';
  					if(_windowWidth > 762) {
  						var _contentCanvasWidth = (_modalWidth*8/12)/1.2;
  						var _contentCanvasHeight = (_modalWidth*8/12)/2.2;
  
  					} else {
  						var _contentCanvasWidth = _windowWidth-70;
  						var _contentCanvasHeight = (_windowWidth)/2.5;
  					}
  					break;
  				default:
  					break;
360081503   DANG   Fix reponsive
42
  			}
53828b4e7   TRUONG   process save/rest...
43
  			
360081503   DANG   Fix reponsive
44
  			canvas.setWidth(_contentCanvasWidth);
4ae9cc634   DANG   fix reponsive
45
  			canvas.setHeight(_contentCanvasHeight);
53828b4e7   TRUONG   process save/rest...
46
47
48
49
50
51
52
53
54
  			
  			var mainDsWidth = (_modalWidth*8/12)-30;
  			var mainDsHeight = (place == 't_shirt_p_1' ? 80 : 400) + _contentCanvasHeight;
  			// console.log(mainDsWidth, mainDsHeight);
  			diffX = 40;
  			diffY = (mainDsHeight - _contentCanvasHeight)/2;
  			_coorTrash_x = _contentCanvasWidth + 20;
  			_coorTrash_y = _contentCanvasHeight + diffY - 90;
  			console.log(_coorTrash_x, _coorTrash_y);
2f4c31749   DANG   Fix text design a...
55
  		}
360081503   DANG   Fix reponsive
56
57
58
59
60
  		setSizeCanvas();
  		//Window resize event
  		$(window).resize(function () {
  			setSizeCanvas();
  		});
2f4c31749   DANG   Fix text design a...
61
  		//Custom control
21a01f6ac   Dang YoungWorld   fix bug action "O...
62
  		fabric.Object.prototype.transparentCorners = true;
cc65fa102   DANG   Custom control
63
  		fabric.Object.prototype.hasRotatingPoint = false;
dd18c1038   Dang YoungWorld   fix delete
64
  		canvas.selection = false;
e6cd2bf54   DANG   update version
65

cc65fa102   DANG   Custom control
66
67
68
69
  		var ctrVisible = {tl: false, ml:false, bl:false, mb: false, br: true, mr: false, tr: true, mt: true, mtr: false};
  		for(key in ctrVisible) {
  			fabric.Object.prototype.setControlVisible(key,ctrVisible[key]);
  		}
e6cd2bf54   DANG   update version
70

cc65fa102   DANG   Custom control
71
72
73
74
75
76
77
78
79
  		fabric.Object.prototype.customiseCornerIcons({
  			settings: {
  				borderColor: '#0000ff',
  				cornerSize: 25,
  				cornerShape: 'circle',
  				cornerBackgroundColor: '#0171b4',
  				cornerPadding: 6
  			},
  			mt: {
39a1e279b   DANG   update
80
  				icon: 'images/control-icon/ok.png'
cc65fa102   DANG   Custom control
81
82
83
84
85
86
87
88
89
90
91
92
  			},
  			br: {
  				icon: 'images/control-icon/resize.png'
  			},
  			tr: {
  				icon: 'images/control-icon/rotate.png'
  			}
  		});
  
  		fabric.Canvas.prototype.customiseControls({
  			mt: {
  				cursor: 'pointer',
2f4c31749   DANG   Fix text design a...
93
  				action: function(e, target) {
21a01f6ac   Dang YoungWorld   fix bug action "O...
94
  					fabric.Object.prototype.selectable = false;
dd18c1038   Dang YoungWorld   fix delete
95
  					canvas.deactivateAll().renderAll();
360081503   DANG   Fix reponsive
96
97
  					delete currentObj;
  					$scope.designTextValue = '';
21a01f6ac   Dang YoungWorld   fix bug action "O...
98
99
100
  					$timeout(function(){
  						fabric.Object.prototype.selectable = true;
  					},20);
cc65fa102   DANG   Custom control
101
102
103
104
105
106
107
108
109
110
  				}
  			},
  			br: {
  
  			},
  			tr: {
  				action: 'rotate',
  				cursor: 'crosshair'
  			}
  		});
6f105dbd5   Truong LD   add source code i...
111

6f105dbd5   Truong LD   add source code i...
112
  		canvas.on({
92271fd7c   DANG   add event
113
  			'object:added'      : onIllustrationAdded,
c3bee6bb3   TRUONG   fix trash icon ef...
114
  			'object:moving'     : onIllustrationMoving,
92271fd7c   DANG   add event
115
116
117
118
119
  			'object:scaling'    : onIllustrationChange,
  			'object:rotating'   : onIllustrationChange,
  			'object:selected'   : onObjectSelected,
  			'object:modified'   : onIllustrationModifield,
  			'selection:cleared' : onObjectOut,
6f105dbd5   Truong LD   add source code i...
120
  		});
aff3eb043   TRUONG   update illustrati...
121
122
123
124
125
126
127
128
  		
  		var currentObj;
  		var listObj = [];
  		var stateObj = [];
  		var indexCurr = 0;
  		var indexCurr2 = 0;
  		var actionObj = false;
  		var refreshObj = true;
92271fd7c   DANG   add event
129
  		var spacingNum = 0;
2f4c31749   DANG   Fix text design a...
130
  		$scope.itemFont = 0;
cc65fa102   DANG   Custom control
131

2f4c31749   DANG   Fix text design a...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
  		$scope.showDesignTab = function(tab){
  			canvas.deactivateAll().renderAll();
  			$rootScope.isShowLeftPanel = tab;
  			switch (tab) {
  				case 'illustration': {
  					$scope.IllustrationList = $illustration.getAll();
  					$rootScope.outputImage = false;
  					$scope.illustrationSelectConfig = {
  						allowClear:true
  					};
  					$timeout(function(){
  						$('.illstration-item').tooltip({
  							animated: 'fade',
  							placement: 'bottom',
  							html: true
  						});
2f4c31749   DANG   Fix text design a...
148
149
150
151
152
153
154
155
156
  					},1000);
  					break;
  				}
  				case 'text': {
  					break;
  				}
  			}
  		};
  		$scope.showDesignTab('default');
cc65fa102   DANG   Custom control
157

aff3eb043   TRUONG   update illustrati...
158
159
160
  		
  		function onIllustrationAdded(options){
  			var object = options.target;
aff3eb043   TRUONG   update illustrati...
161
162
163
164
165
166
167
168
169
170
171
  		
  		    if (actionObj === true) {
  		        stateObj = [stateObj[indexCurr2]];
  		        listObj = [listObj[indexCurr2]];
  		
  		        actionObj = false;
  		        console.log(stateObj);
  		        indexCurr = 1;
  		    }
  		    object.saveState();
  		
057ad34c6   TRUONG   fix clear color SVG
172
  		    // console.log(object.originalState);
aff3eb043   TRUONG   update illustrati...
173
174
175
176
177
178
179
  		    stateObj[indexCurr] = JSON.stringify(object.originalState);
  		    listObj[indexCurr] = object;
  		    indexCurr++;
  		    indexCurr2 = indexCurr - 1;
  		    refreshObj = true;
  		}
  		
1d6ddfa62   TRUONG   merge
180
  		function onIllustrationModifield(options){
d7aae10e2   TRUONG   update fix delete...
181
  			$('.object-border').hide();
c3bee6bb3   TRUONG   fix trash icon ef...
182
183
  			//
  		    var pointer = canvas.getPointer(options.e);
53828b4e7   TRUONG   process save/rest...
184
  			if (pointer.x >= _coorTrash_x && pointer.y >= _coorTrash_y && pointer.x <= _coorTrash_x+50 && pointer.y <= _coorTrash_y+70){
c3bee6bb3   TRUONG   fix trash icon ef...
185
  				canvas.getActiveObject().remove();
3ab3e50f8   TRUONG   update, fix trash...
186
  				$('.design-content .trash-design img').attr({'src':'images/trash.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
187
188
189
190
  				return;
  			}
  			
  			//
057ad34c6   TRUONG   fix clear color SVG
191
192
193
194
195
196
197
198
199
200
201
  			try{
  				var objOffset = canvas.getActiveObject().getBoundingRect();
  				var cH = canvas.height, cW = canvas.width, H0 = 20, W0 = 20;
  				//console.log(objOffset,canvas.height,canvas.width);
  				if (objOffset.left<W0-objOffset.width || objOffset.left>cW-W0 || objOffset.top<H0-objOffset.height || objOffset.top>cH-H0){
  					if (confirm('削除してもよろしいですか')){
  						canvas.getActiveObject().remove();
  					}else{
  						undoCanvas();
  						return;
  					}
aff3eb043   TRUONG   update illustrati...
202
  				}
057ad34c6   TRUONG   fix clear color SVG
203
204
  			}catch (e){
  				//
aff3eb043   TRUONG   update illustrati...
205
206
207
  			}
  			
  			var object = options.target;
aff3eb043   TRUONG   update illustrati...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
  		    if (actionObj === true) {
  		        stateObj = [stateObj[indexCurr2]];
  		        listObj = [listObj[indexCurr2]];
  		
  		        actionObj = false;
  		        console.log(stateObj);
  		        indexCurr = 1;
  		    }
  		
  		    object.saveState();
  		
  		    stateObj[indexCurr] = JSON.stringify(object.originalState);
  		    listObj[indexCurr] = object;
  		    indexCurr++;
  		    indexCurr2 = indexCurr - 1;
aff3eb043   TRUONG   update illustrati...
223
224
225
  		    refreshObj = true;
  		}
  		
6f105dbd5   Truong LD   add source code i...
226
  		function onIllustrationChange(options) {
e872619e5   Dang YoungWorld   delete comment
227

6f105dbd5   Truong LD   add source code i...
228
  		}
c3bee6bb3   TRUONG   fix trash icon ef...
229
230
  		
  		function onIllustrationMoving(options) {
d7aae10e2   TRUONG   update fix delete...
231
  			var object = options.target;
c3bee6bb3   TRUONG   fix trash icon ef...
232
  			var pointer = canvas.getPointer(options.e);
53828b4e7   TRUONG   process save/rest...
233
234
  			// console.log(pointer.x, pointer.y);
  			if (pointer.x >= _coorTrash_x && pointer.y >= _coorTrash_y && pointer.x <= _coorTrash_x+50 && pointer.y <= _coorTrash_y+70){
3ab3e50f8   TRUONG   update, fix trash...
235
  				$('.design-content .trash-design img').attr({'src':'images/trash-hover.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
236
  			}else{
3ab3e50f8   TRUONG   update, fix trash...
237
  				$('.design-content .trash-design img').attr({'src':'images/trash.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
238
  			}
d7aae10e2   TRUONG   update fix delete...
239
  			
f2c8c5649   TRUONG   fix & update
240
  			// console.log(object.oCoords,object.originalState);
d7aae10e2   TRUONG   update fix delete...
241
242
  			object.setCoords();
  			var Coords = object.oCoords;
c674a3608   TRUONG   fix delete effect
243
244
245
246
247
248
  			var xAngle = Math.cos(object.getAngle() * (Math.PI / 180))/2;
  			var yAngle = Math.sin(object.getAngle() * (Math.PI / 180))/2;
  			$('#object-border-left').css({'height':Math.ceil(object.originalState.height*object.scaleY), top: Coords.tl.y+diffY, left: Coords.tl.x+diffX});
  			$('#object-border-right').css({'height':Math.ceil(object.originalState.height*object.scaleY), top: Coords.tr.y+diffY, left: Coords.tr.x+diffX});
  			$('#object-border-top').css({'width':Math.ceil(object.originalState.width*object.scaleX), top: Coords.tl.y+diffY, left: Coords.tl.x+diffX});
  			$('#object-border-bottom').css({'width':Math.ceil(object.originalState.width*object.scaleX), top: Coords.bl.y+diffY, left: Coords.bl.x+diffX});
d7aae10e2   TRUONG   update fix delete...
249
250
251
252
253
254
  			$('.object-border').css({
  				'-ms-transform': 'rotate('+object.getAngle()+'deg)', /* IE 9 */
      			'-webkit-transform': 'rotate('+object.getAngle()+'deg)', /* Safari */
      			'transform': 'rotate('+object.getAngle()+'deg)' /* Standard syntax */
  			});
  			$('.object-border').show();
c3bee6bb3   TRUONG   fix trash icon ef...
255
  		}
6f105dbd5   Truong LD   add source code i...
256

92271fd7c   DANG   add event
257
  		function onObjectOut() {
dd18c1038   Dang YoungWorld   fix delete
258
259
  			console.log('onObjectOut');
  			canvas.deactivateAll().renderAll();
92271fd7c   DANG   add event
260
261
  			delete currentObj;
  			$scope.designTextValue = '';
dd18c1038   Dang YoungWorld   fix delete
262
  			$scope.safeApply();
aff3eb043   TRUONG   update illustrati...
263
  		}
6f105dbd5   Truong LD   add source code i...
264

aff3eb043   TRUONG   update illustrati...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
  		function undoCanvas() {
  		    if (indexCurr <= 0) {
  		        indexCurr = 0;
  		        return;
  		    }
  		
  		    if (refreshObj === true) {
  		        indexCurr--;
  		        refreshObj = false;
  		    }
  		
  		    console.log('undo');
  		
  		    indexCurr2 = indexCurr - 1;
  		    currentObj = listObj[indexCurr2];
  		    if (currentObj){
  		    	currentObj.setOptions(JSON.parse(indexCurr[indexCurr2]));
  		    }
  		
  		    indexCurr--;
  		    currentObj.setCoords();
  		    canvas.renderAll();
  		    actionObj = true;
  		}
  		
  		function redoCanvas() {
  		    actionObj = true;
  		    if (indexCurr >= stateObj.length - 1) {
  		        return;
  		    }
  		
  		    console.log('redo');
  		
  		    indexCurr2 = indexCurr + 1;
  		    currentObj = listObj[indexCurr2];
  		    currentObj.setOptions(JSON.parse(indexCurr[indexCurr2]));
  		
  		    indexCurr++;
  		    currentObj.setCoords();
  		    canvas.renderAll();
6f105dbd5   Truong LD   add source code i...
305
  		}
80ff9bbd4   TRUONG   fix bugs and optimal
306
307
  		
  		$scope.canvasClearAll = function(){
60b61386b   TRUONG   fix text
308
  			if (confirm('配置されたすべての文字や画像を消去します')){
80ff9bbd4   TRUONG   fix bugs and optimal
309
  				canvas.clear();
057ad34c6   TRUONG   fix clear color SVG
310
  				ObjectOrd = 0;
80ff9bbd4   TRUONG   fix bugs and optimal
311
312
  			}
  		}
92271fd7c   DANG   add event
313
314
315
  
  		function onObjectSelected(options) {
  			var currentObj = options.target;
b196bab48   TRUONG   fix clear color SVG.
316
  			if (typeof currentObj.toOrd != 'function'){
057ad34c6   TRUONG   fix clear color SVG
317
318
319
320
321
322
  				var currentObjOrd = ++ObjectOrd;
  				currentObj.toOrd = function(){
  					return currentObjOrd;
  				}
  			}
  			console.log(currentObj.toOrd());
92271fd7c   DANG   add event
323
  			$scope.typeObject = currentObj.type;
c8bfdfd96   DANG   event click object
324
325
  			switch ($scope.typeObject) {
  				case 'i-text' :
c8bfdfd96   DANG   event click object
326
  					$rootScope.isShowLeftPanel = 'text';
92271fd7c   DANG   add event
327
328
329
330
331
  					var text = currentObj.text;
  					if(text != '') {
  						$scope.designText = text;
  						$scope.designTextValue = text;
  					}
c8bfdfd96   DANG   event click object
332
333
334
335
336
  					break;
  
  				case 'path-group' :
  					$rootScope.isShowLeftPanel = 'illustration';
  					break;
e5669639a   TRUONG   merge #1759
337
338
339
340
  					
  				case 'image':
  					$rootScope.isShowLeftPanel = 'image';
  					break;
c8bfdfd96   DANG   event click object
341
342
343
344
345
346
  
  				default :
  					$rootScope.isShowLeftPanel = 'default';
  					break;
  			}
  			$rootScope.safeApply();
6f105dbd5   Truong LD   add source code i...
347
348
349
350
351
  		}
  
  		// Illustration process
  		$scope.changeIllustrationCategory = function(currentIllustration){
  			$scope.currentIllustrationCate = $illustration.getList(currentIllustration);
422e7837d   DANG   Change color t-shirt
352
  		};
6f105dbd5   Truong LD   add source code i...
353

057ad34c6   TRUONG   fix clear color SVG
354
  		var arrSvgOriginal = [];
6f105dbd5   Truong LD   add source code i...
355
356
357
  		$scope.insertSvg = function(item){
  			fabric.loadSVGFromURL(item.path, function(objects, options) {
  				var shape = fabric.util.groupSVGElements(objects, options);
057ad34c6   TRUONG   fix clear color SVG
358
359
360
361
362
  				var currentObjOrd = ++ObjectOrd;
  				arrSvgOriginal[currentObjOrd] = item.path;
  				shape.toOrd = function(){
  					return currentObjOrd;
  				}
6f105dbd5   Truong LD   add source code i...
363
  				canvas.add(shape.scale(0.6));
53828b4e7   TRUONG   process save/rest...
364
  				shape.set({ left: 150, top: 100 }).setCoords();
6f105dbd5   Truong LD   add source code i...
365
366
367
  				canvas.renderAll();
  				canvas.setActiveObject(shape);
  			});
422e7837d   DANG   Change color t-shirt
368
  		};
6f105dbd5   Truong LD   add source code i...
369
370
  
  		// color pattern
6f105dbd5   Truong LD   add source code i...
371
  		$scope.listColorPatterns = [
aff3eb043   TRUONG   update illustrati...
372
373
374
375
  			'#000000','#ffff00','#ff6600','#ff0000','#ff6262','#ffa19c','#ff9933','#c45d01','#5d2b03','#ffffcc',
  			'#ffff99','#ffd500','#c0db50','#21a52a','#00663f','#abfcab','#36ffaa','#89eaea','#00938c','#005450',
  			'#0badff','#006cff','#839aff','#0410a0','#ffb2ff','#f93fff','#6600ca','#ff6699','#999999','#666666',
  			'#333333'
422e7837d   DANG   Change color t-shirt
376
  		];
80ff9bbd4   TRUONG   fix bugs and optimal
377
378
379
380
381
  		
  		$scope.changeColorPattern = function(color){
  			var obj = canvas.getActiveObject();
  			if (!color){
  				color = 'none';
057ad34c6   TRUONG   fix clear color SVG
382
  				// console.log(obj.toOrd(), arrSvgOriginal[obj.toOrd()]);
b196bab48   TRUONG   fix clear color SVG.
383
  				if (typeof obj.toOrd == 'function' && typeof arrSvgOriginal[obj.toOrd()] != 'undefined'){
057ad34c6   TRUONG   fix clear color SVG
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
  					var currentObjOrd = obj.toOrd();
  					fabric.loadSVGFromURL(arrSvgOriginal[obj.toOrd()], function(objects, options) {
  						var shape = fabric.util.groupSVGElements(objects, options);
  						shape.toOrd = function(){
  							return currentObjOrd;
  						}
  						obj.setCoords();
  						shape.setScaleX(obj.getScaleX());
  						shape.setScaleY(obj.getScaleY());
  						shape.set('top',obj.getTop());
  						shape.set('left',obj.getLeft());
  						shape.set('angle',obj.getAngle());
  						// shape.set('height',obj.getHeight());
  						// shape.set('width',obj.getWidth());
  						canvas.add(shape);
  						shape.setCoords();
  						// shape.set({ left: 150, top: 100 }).setCoords();
  						canvas.renderAll();
  						canvas.setActiveObject(shape);
  						obj.remove();
  					});
  				}
  			}else{
  				if (obj instanceof fabric.PathGroup) {
  					obj.getObjects().forEach(function(o) {
  						o.fill = color;
  					});
  				}
  				else {
  					obj.fill = color;
  				}
  				canvas.renderAll();
80ff9bbd4   TRUONG   fix bugs and optimal
416
  			}
80ff9bbd4   TRUONG   fix bugs and optimal
417
418
  		};
  		
04cbb68af   DANG   design text basic
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
  		//Font
  		$scope.listFontFamily = [
  			{
  				name : 'GN Aki iro Sesami Cookies',
  				slug : 'gn_aki_iro_sesami_cookies',
  			},
  			{
  				name : 'GN-Fuyu-iro_Script_Bold',
  				slug : 'gn_fuyu_iro_script_bold'
  			},
  			{
  				name : 'GN Killgothic U Kanana',
  				slug : 'gn_killgothic_u_kanana'
  			},
  			{
  				name : 'GN-Kin-iro_Alphabet_Cookies',
  				slug : 'gn_kin_iro_alphabet_cookies'
  
  			},
  			{
  				name : 'GN-Kin-iro_SansSerif',
  				slug : 'gn_kin_iro_sansserif'
  
  			},
  			{
  				name : 'GN-Koharuiro_Sunray',
  				slug : 'gn_koharuiro_sunray'
  
  			},
  			{
  				name : 'GN-Kyu-pin',
  				slug : 'gn_kyu_pin'
  			},
  			{
  				name : 'gn_natsu_iro_schedule',
  				slug : 'gn_natsu_iro_schedule'
  
  			},
  			{
  				name : 'gnkana_kiniro_sansserif_l',
  				slug : 'gnkana_kiniro_sansserif_l'
  
  			},
  			{
  				name : 'gnkana_kiniro_sansserif_st',
  				slug : 'gnkana_kiniro_sansserif_st'
  			},
  			{
  				name : 'gnkana_kon_iro_nightfall',
  				slug : 'gnkana_kon_iro_nightfall'
  
  			},
  			{
  				name : 'ms_gothic',
  				slug : 'ms_gothic'
  
  			},
  			{
  				name : 'msmincho',
  				slug : 'msmincho'
  			},
  			{
  				name : 'ufonts_com_ms_pgothic',
  				slug : 'ufonts_com_ms_pgothic'
  			}
  		];
682a3b12d   TRUONG   fix illustration ...
485
  		
682a3b12d   TRUONG   fix illustration ...
486
  		// layer process
92271fd7c   DANG   add event
487
488
489
  		$scope.layerProcess = function(mode) {
  			// console.log('layerProcess');
  			var activeObject = canvas.getActiveObject();
682a3b12d   TRUONG   fix illustration ...
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
  			if (activeObject){
  				switch (mode) {
  					case 1:
  						activeObject.bringForward();
  						break;
  					case 2:
  						activeObject.sendBackwards();
  						break;
  					case 3:
  						activeObject.bringToFront();
  						break;
  					case 4:
  						activeObject.sendToBack();
  						break;
  				}
e0ee74c15   TRUONG   update fix layer ...
505
  				canvas.deactivateAll().renderAll();
682a3b12d   TRUONG   fix illustration ...
506
  			}
04cbb68af   DANG   design text basic
507
  		};
422e7837d   DANG   Change color t-shirt
508

dd18c1038   Dang YoungWorld   fix delete
509
510
511
  
  		//Design text
  		$scope.inputText = function(e) {
92271fd7c   DANG   add event
512
  			currentObj = canvas.getActiveObject();
cfbd788dd   DANG   fix del
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
  			var _iText = new fabric.IText('', {
  				left: 150,
  				top: 200,
  				fontFamily: typeof $scope.itemFont != 'undefined' ? $scope.listFontFamily[$scope.itemFont].slug : $scope.listFontFamily[0].slug,
  				fontWeight: 'normal',
  				textAlign:  'center',
  				fontSize: 28,
  				fill: 'black',
  				editable: false
  			});
  			if(typeof currentObj != 'undefined' && currentObj != null) {
  				_iText.set({
  					left: currentObj.left,
  					top: currentObj.top,
  					fontFamily: currentObj.fontFamily,
  					fontSize: currentObj.fontSize,
  					fill: currentObj.fill
  				})
92271fd7c   DANG   add event
531
  			}
422e7837d   DANG   Change color t-shirt
532

cfbd788dd   DANG   fix del
533
534
  
  			if(canvas.getActiveObject())
dd18c1038   Dang YoungWorld   fix delete
535
  				canvas.getActiveObject().remove();
cfbd788dd   DANG   fix del
536
  			_iText.set('text', e);
dd18c1038   Dang YoungWorld   fix delete
537
538
539
  			canvas.add(_iText);
  			canvas.setActiveObject(_iText);
  			canvas.renderAll();
c8bfdfd96   DANG   event click object
540
  		};
2f4c31749   DANG   Fix text design a...
541
542
  		$scope.setFontFamily = function(font,index) {
  			$scope.itemFont = index;
ba689b493   DANG   canvas font text
543
  			if(canvas.getActiveObject()) {
92271fd7c   DANG   add event
544
545
546
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
  					currentObj.set('fontFamily', font);
ba689b493   DANG   canvas font text
547
  					canvas.renderAll();
92271fd7c   DANG   add event
548
  					canvas.setActiveObject(currentObj);
ba689b493   DANG   canvas font text
549
550
551
  				}
  
  			}
04cbb68af   DANG   design text basic
552
553
  		};
  		//Set letter spacing text
04cbb68af   DANG   design text basic
554
555
  		$scope.setLetterSpacingText = function(e) {
  			if(canvas.getActiveObject()) {
92271fd7c   DANG   add event
556
557
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
04cbb68af   DANG   design text basic
558
559
  					if(e == 'plus')
  						spacingNum = spacingNum + 30;
2f4c31749   DANG   Fix text design a...
560
  					else if (spacingNum >= -30){
04cbb68af   DANG   design text basic
561
562
  						spacingNum = spacingNum - 30;
  					}
83f7186e9   DANG   fix bug reponsive
563
564
  					if(e == 'default')
  						spacingNum = 0;
2f4c31749   DANG   Fix text design a...
565

2f4c31749   DANG   Fix text design a...
566
567
568
569
570
571
  					currentObj.set('charSpacing', spacingNum);
  					canvas.renderAll();
  					canvas.setActiveObject(currentObj);
  				}
  			}
  		};
e5669639a   TRUONG   merge #1759
572
573
574
  		
  		
  		/**** process insert image */
bd0414901   TRUONG   update store rece...
575
576
577
578
579
  		if (typeof($window.localStorage.recentImages) != 'undefined'){
  			$scope.recentImages = JSON.parse($window.localStorage.recentImages);
  		}else{
  			$scope.recentImages = {};
  		}
2f4c31749   DANG   Fix text design a...
580

bd0414901   TRUONG   update store rece...
581
582
583
584
585
586
  		var addToRecentImage = function(name, data){
  			if (typeof($window.localStorage.recentImages) != 'undefined'){
  				$scope.recentImages = JSON.parse($window.localStorage.recentImages);
  			}else{
  				$scope.recentImages = {};
  			}
2f4c31749   DANG   Fix text design a...
587

bd0414901   TRUONG   update store rece...
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
  			if (typeof($scope.recentImages[name]) == 'undefined'){
  				var ii=0;
  				var II = 0;
  				for(var item in $scope.recentImages){
  					if (II==0){
  						II = item;
  					}
  					ii++;
  				}
  				if (ii>16 && II!=0){
  					delete $scope.recentImages[II];
  				}
  				$scope.recentImages[name] = data;
  				$window.localStorage.recentImages = JSON.stringify($scope.recentImages);
  			}
  		}
  		$scope.chooseImage = function(e){//console.log(e);
0181c19ff   TRUONG   fix bugs and opti...
605
  			if (e.target.files[0] && e.target.files[0].size > 5*1024*1024){
60b61386b   TRUONG   fix text
606
  				alert('アップロードできませんでした');
0181c19ff   TRUONG   fix bugs and opti...
607
608
  				return;
  			}
e5669639a   TRUONG   merge #1759
609
  			var reader = new FileReader();
0181c19ff   TRUONG   fix bugs and opti...
610
  		    reader.onload = function (event) {
bd0414901   TRUONG   update store rece...
611
612
  		    	addToRecentImage ($('#imgLoader').val(), event.target.result);
  		        var imgObj = new Image();//console.log($('#imgLoader').val());
e5669639a   TRUONG   merge #1759
613
614
615
616
617
618
619
620
621
  		        imgObj.src = event.target.result;
  		        imgObj.onload = function () {
  		            // start fabricJS stuff
  		            
  		            var image = new fabric.Image(imgObj);
  		            image.set({
  		                left: 50,
  		                top: 50
  		            });
2f4c31749   DANG   Fix text design a...
622
  		            //image.scale(getRandomNum(0.1, 0.25)).setCoords();
e5669639a   TRUONG   merge #1759
623
624
625
626
627
628
  		            image.scaleToWidth(200);
  		            canvas.add(image);
  		        }
  		    }
      		reader.readAsDataURL(e.target.files[0]);
  		}
2f4c31749   DANG   Fix text design a...
629

bd0414901   TRUONG   update store rece...
630
631
632
633
634
  		$scope.insertRecentImage = function(data){
  	        var imgObj = new Image();
  	        imgObj.src = data;
  	        imgObj.onload = function () {
  	            // start fabricJS stuff
2f4c31749   DANG   Fix text design a...
635

bd0414901   TRUONG   update store rece...
636
637
638
639
640
641
642
643
644
  	            var image = new fabric.Image(imgObj);
  	            image.set({
  	                left: 50,
  	                top: 50
  	            });
  	            image.scaleToWidth(200);
  	            canvas.add(image);
  	        }
  		}
2f4c31749   DANG   Fix text design a...
645

92271fd7c   DANG   add event
646
647
648
649
650
651
652
653
654
655
656
  		//Traslation text
  		$scope.rotateText =  function(style) {
  			if(canvas.getActiveObject()) {
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
  					currentObj.set('rotate', Math.PI / 4);
  					canvas.renderAll();
  					canvas.setActiveObject(currentObj);
  				}
  			}
  		};
80ff9bbd4   TRUONG   fix bugs and optimal
657
658
659
660
661
662
663
664
  		
  		
  		/* Process output */
  		$scope.outputDesign = function(){
  			$rootScope.outputImage = canvas.toDataURL('png');
  			// console.log();
  			$('#tshirt-design').modal('hide');
  		}
faf1542f8   TRUONG   fix lazy border w...
665
666
  		
  		$scope.showRecommend = function(){
53828b4e7   TRUONG   process save/rest...
667
668
  			$scope.recommendList = $favorite.getAll();
  			$scope.favoriteList = $favorite.getAll();
faf1542f8   TRUONG   fix lazy border w...
669
670
671
672
  			$('#tshirt-design-saved').modal({
  				backdrop: 'static',
  				keyboard: false
  			});
53828b4e7   TRUONG   process save/rest...
673
674
675
676
677
678
679
  			$timeout(function(){
  				$('.saved-item').tooltip({
  					animated: 'fade',
  					placement: 'bottom',
  					html: true
  				});
  			},1000);
faf1542f8   TRUONG   fix lazy border w...
680
681
682
683
684
685
686
  		}
  		
  		$scope.closeSavedModal = function(){
  			$('#tshirt-design-saved').modal('hide');
  		}
  		
  		$scope.openSavedTab = function(tab){
faf1542f8   TRUONG   fix lazy border w...
687
688
689
690
691
692
  			$('#tshirt-design-saved .subframe-design .nav-tabs li').removeClass('active');
  			$('#tab-saved-'+tab).addClass('active');
  			$('#tshirt-design-saved .subframe-design .tab-content .tab-pane').removeClass('active');
  			$('#content-saved-'+tab).addClass('active');
  			
  			$timeout(function(){
2681003ca   TRUONG   update #1808, #1809
693
  				$('.saved-item img').tooltip({
faf1542f8   TRUONG   fix lazy border w...
694
695
696
697
  					animated: 'fade',
  					placement: 'bottom',
  					html: true
  				});
2681003ca   TRUONG   update #1808, #1809
698
  			},500);
faf1542f8   TRUONG   fix lazy border w...
699
700
  		}
  		
53828b4e7   TRUONG   process save/rest...
701
  		$favorite.loadFromRemote();
faf1542f8   TRUONG   fix lazy border w...
702
  		$scope.saveFavorite = function(){
2681003ca   TRUONG   update #1808, #1809
703
704
705
  			if (!confirm('Do you want to put current design to your favorite?')){
  				return;
  			}
faf1542f8   TRUONG   fix lazy border w...
706
707
  			var dataDump = {
  				thumb: canvas.toDataURL('png'),
2681003ca   TRUONG   update #1808, #1809
708
  				data: JSON.stringify(canvas)
faf1542f8   TRUONG   fix lazy border w...
709
710
711
712
  			}
  			$favorite.addToFavorite({
  				data: dataDump
  			})
2681003ca   TRUONG   update #1808, #1809
713
  			// console.log(JSON.stringify(dataDump));
53828b4e7   TRUONG   process save/rest...
714
715
716
717
  			alert('saved');
  		}
  		
  		$scope.restoreSaved = function(item){
2681003ca   TRUONG   update #1808, #1809
718
719
720
  			if (!confirm('this may be clear all current design frame, are you sure ?')){
  				return;
  			}
53828b4e7   TRUONG   process save/rest...
721
722
  			$('#tshirt-design-saved').modal('hide');
  			canvas.loadFromJSON(item.data,canvas.renderAll.bind(canvas));
057ad34c6   TRUONG   fix clear color SVG
723
724
725
726
727
728
729
  			ObjectOrd = 0;
  			canvas.forEachObject(function(obj){
  				var currentObjOrd = ++ObjectOrd;
  			    obj.toOrd = function(){
  			    	return currentObjOrd;
  			    }
  			});
faf1542f8   TRUONG   fix lazy border w...
730
  		}
2681003ca   TRUONG   update #1808, #1809
731
732
733
734
735
736
737
738
739
740
  		
  		$scope.deleteFavorite = function(idx){
  			if (confirm('are you sure?')){
  				$favorite.removeFromFavorite({
  					idx: idx
  				});
  				$scope.recommendList = $favorite.getAll();
  				$scope.favoriteList = $favorite.getAll();
  			}
  		}
6f105dbd5   Truong LD   add source code i...
741
742
  	});
  });