Projekt

Allgemein

Profil

GX-Task #43500 » gm_gprint2.js.php

gm_gprint.js ohne Backend-Code - Moritz Bunjes, 23.10.2015 19:17

 
1
/* gm_gprint.js <?php
2
#   --------------------------------------------------------------
3
#   gm_gprint.js 2015-01-08 gm
4
#   Gambio GmbH
5
#   http://www.gambio.de
6
#   Copyright (c) 2015 Gambio GmbH
7
#   Released under the GNU General Public License (Version 2)
8
#   [http://www.gnu.org/licenses/gpl-2.0.html]
9
#   --------------------------------------------------------------
10
?>*/
11

    
12
<?php
13
include_once(get_usermod(DIR_FS_CATALOG . 'gm/javascript/jquery/plugins/ajaxfileupload/ajaxfileupload.js'));
14
?>
15

    
16
var c_mode = encodeURIComponent('<?php echo gm_prepare_string($this->v_data_array['GET']['mode']); ?>');
17

    
18
if(typeof(gm_session_id) == 'undefined')
19
{
20
	var gm_session_id = '<?php echo gm_prepare_string($this->v_data_array['GET']['XTCsid']); ?>';
21
}
22
gm_session_id = encodeURIComponent(gm_session_id);
23

    
24

    
25
var t_current_page = '<?php echo gm_prepare_string($this->v_data_array['GET']['current_page']); ?>';
26

    
27
var coo_surfaces_manager = null;
28
var coo_gprint_configuration = null;
29
var coo_cart_wishlist_manager = null;
30

    
31
<?php
32
include_once(get_usermod(DIR_FS_CATALOG . 'gm/javascript/gm_gprint_functions.js'));
33
include_once(get_usermod(DIR_FS_CATALOG . 'gm/javascript/GMGPrintConfiguration.js'));
34
include_once(get_usermod(DIR_FS_CATALOG . 'gm/javascript/GMGPrintSurfacesManager.js'));
35
include_once(get_usermod(DIR_FS_CATALOG . 'gm/javascript/GMGPrintSurfaces.js'));
36
include_once(get_usermod(DIR_FS_CATALOG . 'gm/javascript/GMGPrintElements.js'));
37
include_once(get_usermod(DIR_FS_CATALOG . 'gm/javascript/GMGPrintCartWishlistManager.js'));
38
?>
39

    
40
$(document).ready(function()
41
{
42
	coo_gprint_configuration = new GMGPrintConfiguration();
43
	coo_gprint_configuration.set_languages_id(<?php echo $_SESSION['languages_id'] ?>);
44
	coo_cart_wishlist_manager = new GMGPrintCartWishlistManager();
45
	window.coo_cart_wishlist_manager = coo_cart_wishlist_manager;
46
	
47
	<?php
48
	if(!empty($this->v_data_array['GET']['id']))
49
	{
50
		echo 'coo_surfaces_manager = new GMGPrintSurfacesManager(' . (int)$this->v_data_array['GET']['id'] . ', coo_gprint_configuration);';
51
		echo 'coo_surfaces_manager.load_surfaces_group(' . (int)$this->v_data_array['GET']['id'] . ', \'' . addslashes($this->v_data_array['GET']['product']) . '\');';
52
		echo '$(\'#details_cart_part\').show();';
53
	}
54
	?>
55
		
56
	if(t_current_page == 'ProductInfo' && $('#gm_gprint').attr('id') == 'gm_gprint')
57
	{
58
		$('#gm_wishlist_link').click(function()
59
		{
60
			$('#gm_gprint input[type="text"], #gm_gprint textarea').each(function()
61
			{
62
				var t_value = $(this).val();
63
				t_value = t_value.replace('€', '&euro;');
64
				$(this).val(t_value);
65
			});
66
			
67
			var t_product = '';
68
			
69
			var t_input_name = '';
70
			
71
			$('.gm_attr_calc_input').each(function()
72
			{
73
				t_input_name = $(this).attr('name');
74
			
75
				if(t_input_name.indexOf('id[') != -1)
76
				{
77
					if($(this).attr('type') == 'radio' && $(this).prop('checked') == true)
78
					{
79
						t_product += '{' + gm_gprint_clear_number(t_input_name) + '}' + $(this).val();
80
					}
81
					else if($(this).attr('type') != 'radio')
82
					{
83
						t_product += '{' + gm_gprint_clear_number(t_input_name) + '}' + $(this).val();
84
					}
85
				}
86
			});
87
			
88
			t_product_copy = t_product;
89
			t_input_name = $('#gm_gprint_random').attr('name');
90
			
91
			var t_product_random = '';
92
			t_product_random = '{' + gm_gprint_clear_number(t_input_name) + '}' + $('#gm_gprint_random').val();
93
			
94
			var t_opened_product = '<?php echo gm_prepare_string($this->v_data_array['GET']['product']); ?>';
95
						
96
			if((t_opened_product != '' && (t_opened_product.indexOf(t_product) == -1 || t_opened_product.indexOf(t_product_random) == -1)) || t_opened_product.substr(0, 4) == 'cart')
97
			{
98
				var t_random_number = Math.random() + '';
99
				t_random_number = t_random_number.substr(2, 6);
100
				
101
				if(t_random_number.substr(0, 1) == '0')
102
				{
103
					t_random_number = '1' + t_random_number.substr(1, 5);
104
				}
105
				$('#gm_gprint_random').attr('name', 'id[' + t_random_number + ']');
106
				
107
				var delete_file_id = '';
108
				var t_old_product = t_opened_product.replace(/wishlist_/g, '');
109
				t_old_product = t_old_product.replace(/cart_/g, '');
110
				
111
				var t_start = t_old_product.indexOf(t_product_random);
112
				var t_end = t_start+t_product_random.length;
113
				
114
				var t_new_product_part_1 = t_old_product.substring(0, t_start);
115
				var t_new_product_part_2 = t_old_product.substring(t_end);
116
				
117
				var t_new_product = t_new_product_part_1 + '{' + t_random_number + '}' + $('#gm_gprint_random').val() + t_new_product_part_2;
118

    
119
				var t_source = 'wishlist';
120
				if(t_opened_product.substr(0, 4) == 'cart')
121
				{
122
					t_source = 'cart';
123
				}
124
				
125
				$('.delete_file').each(function()
126
				{
127
					delete_file_id = $(this).attr('id');
128
					delete_file_id = delete_file_id.replace(/delete_file_/g, '');
129
					coo_cart_wishlist_manager.copy_file(delete_file_id, t_old_product, t_new_product, 'wishlist', t_source);
130
				});
131
			}
132
			
133
			coo_cart_wishlist_manager.get_customers_data(coo_surfaces_manager, 'wishlist');
134
		});
135
		
136
		$('#cart_quantity').submit(function()
137
		{
138
			return false;
139
		});
140

    
141
		$('#cart_button').click(function()
142
		{
143
			$('#gm_gprint input[type="text"], #gm_gprint textarea').each(function()
144
			{
145
				var t_value = $(this).val();
146
				t_value = t_value.replace('€', '&euro;');
147
				$(this).val(t_value);
148
			});
149
			
150
			var t_product = '';
151
			
152
			var t_input_name = '';
153
			
154
			$('.gm_attr_calc_input').each(function()
155
			{
156
				t_input_name = $(this).attr('name');
157
				
158
				if(t_input_name.indexOf('id[') != -1)
159
				{
160
					if($(this).attr('type') == 'radio' && $(this).prop('checked') == true)
161
					{
162
						t_product += '{' + gm_gprint_clear_number(t_input_name) + '}' + $(this).val();
163
					}
164
					else if($(this).attr('type') != 'radio')
165
					{
166
						t_product += '{' + gm_gprint_clear_number(t_input_name) + '}' + $(this).val();
167
					}
168
				}
169
			});
170
			
171
			t_product_copy = t_product;
172
			t_input_name = $('#gm_gprint_random').attr('name');
173

    
174
			var t_product_random = '';
175
			t_product_random = '{' + gm_gprint_clear_number(t_input_name) + '}' + $('#gm_gprint_random').val();
176
			
177
			var t_opened_product = '<?php echo gm_prepare_string($this->v_data_array['GET']['product']); ?>';
178
						
179
			if((t_opened_product != '' && (t_opened_product.indexOf(t_product) == -1 || t_opened_product.indexOf(t_product_random) == -1)) || t_opened_product.substr(0, 8) == 'wishlist')
180
			{
181
				var t_random_number = Math.random() + '';
182
				t_random_number = t_random_number.substr(2, 6);
183
				
184
				if(t_random_number.substr(0, 1) == '0')
185
				{
186
					t_random_number = '1' + t_random_number.substr(1, 5);
187
				}
188

    
189
				$('#gm_gprint_random').attr('name', 'id[' + t_random_number + ']');
190
				
191
				var delete_file_id = '';
192
				var t_old_product = t_opened_product.replace(/cart_/g, '');
193
				t_old_product = t_old_product.replace(/wishlist_/g, '');
194
				
195
				var t_start = t_old_product.indexOf(t_product_random);
196
				var t_end = t_start+t_product_random.length;
197
				
198
				var t_new_product_part_1 = t_old_product.substring(0, t_start);
199
				var t_new_product_part_2 = t_old_product.substring(t_end);
200
				
201
				var t_new_product = t_new_product_part_1 + '{' + t_random_number + '}' + $('#gm_gprint_random').val() + t_new_product_part_2;
202

    
203
				var t_source = 'cart';
204
				if(t_opened_product.substr(0, 8) == 'wishlist')
205
				{
206
					t_source = 'wishlist';
207
				}
208
				
209
				$('.delete_file').each(function()
210
				{
211
					delete_file_id = $(this).attr('id');
212
					delete_file_id = delete_file_id.replace(/delete_file_/g, '');
213
					coo_cart_wishlist_manager.copy_file(delete_file_id, t_old_product, t_new_product, 'cart', t_source);
214
				});
215
			}
216
			
217
			if(typeof(coo_dropdowns_listener) != 'undefined')
218
			{
219
				coo_dropdowns_listener.check_combi_status();
220
			}
221
			
222
			coo_gm_qty_ckeck = new GMOrderQuantityChecker();
223
			var t_gm_qty_check = coo_gm_qty_ckeck.check();
224

    
225
			if(t_gm_qty_check)
226
			{
227
				coo_cart_wishlist_manager.get_customers_data(coo_surfaces_manager, 'cart');
228
			}
229

    
230
			return false;
231
		});
232
	}
233
	else if(t_current_page == 'Cart')
234
	{
235
		$('#cart_quantity').submit(function(){
236
			return coo_cart_wishlist_manager.update_cart();
237
		});
238
	}
239
	else if(t_current_page == 'Wishlist' && $('#gm_update_wishlist').attr('id') == 'gm_update_wishlist' && $('#gm_wishlist_to_cart').attr('id') == 'gm_wishlist_to_cart')
240
	{
241
		var t_wishlist_delete_href = $('#gm_update_wishlist').attr('href');
242
		t_wishlist_delete_href = t_wishlist_delete_href.replace(/:/g, ':coo_cart_wishlist_manager.update_wishlist();');
243
		$('#gm_update_wishlist').attr('href', t_wishlist_delete_href);
244
		
245
		var t_wishlist_add_href = $('#gm_wishlist_to_cart').attr('href');
246
		t_wishlist_add_href = t_wishlist_add_href.replace(/:/g, ':coo_cart_wishlist_manager.wishlist_to_cart();');
247
		$('#gm_wishlist_to_cart').attr('href', t_wishlist_add_href);
248
	}
249

    
250
    if(typeof(coo_qty_input_resizer) == 'object')
251
	{
252
        coo_qty_input_resizer.init_binds();
253
    }
254

    
255
	$('.gm_gprint_surface').on('click', '*', function () {
256
		$(this).parent().find('*').removeClass('selected-customizer-element');
257
		$('#' + $(this).prop('id').replace('copy_', '')).addClass('selected-customizer-element');
258
	});
259
});
260

    
    (1-1/1)