1 | /* |
---|
2 | * This file is part of EC-CUBE |
---|
3 | * |
---|
4 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
5 | * |
---|
6 | * http://www.lockon.co.jp/ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | $(function() { |
---|
24 | // 規格1選択時 |
---|
25 | $('select[name=classcategory_id1]') |
---|
26 | .change(function() { |
---|
27 | var $form = $(this).parents('form'); |
---|
28 | var product_id = $form.find('input[name=product_id]').val(); |
---|
29 | var $sele1 = $(this); |
---|
30 | var $sele2 = $form.find('select[name=classcategory_id2]'); |
---|
31 | |
---|
32 | // 規格1のみの場合 |
---|
33 | if (!$sele2.length) { |
---|
34 | checkStock($form, product_id, $sele1.val(), '0'); |
---|
35 | // 規格2ありの場合 |
---|
36 | } else { |
---|
37 | setClassCategories($form, product_id, $sele1, $sele2); |
---|
38 | } |
---|
39 | }); |
---|
40 | |
---|
41 | // 規格2選択時 |
---|
42 | $('select[name=classcategory_id2]') |
---|
43 | .change(function() { |
---|
44 | var $form = $(this).parents('form'); |
---|
45 | var product_id = $form.find('input[name=product_id]').val(); |
---|
46 | var $sele1 = $form.find('select[name=classcategory_id1]'); |
---|
47 | var $sele2 = $(this); |
---|
48 | checkStock($form, product_id, $sele1.val(), $sele2.val()); |
---|
49 | }); |
---|
50 | }); |
---|
51 | /** |
---|
52 | * 規格2のプルダウンを設定する. |
---|
53 | */ |
---|
54 | function setClassCategories($form, product_id, $sele1, $sele2, selected_id2) { |
---|
55 | if ($sele1 && $sele1.length) { |
---|
56 | var classcat_id1 = $sele1.val() ? $sele1.val() : ''; |
---|
57 | if ($sele2 && $sele2.length) { |
---|
58 | // 規格2の選択肢をクリア |
---|
59 | $sele2.children().remove(); |
---|
60 | |
---|
61 | var classcat2; |
---|
62 | |
---|
63 | // 商品一覧時 |
---|
64 | if (typeof productsClassCategories != 'undefined') { |
---|
65 | classcat2 = productsClassCategories[product_id][classcat_id1]; |
---|
66 | } |
---|
67 | // 詳細表示時 |
---|
68 | else { |
---|
69 | classcat2 = classCategories[classcat_id1]; |
---|
70 | } |
---|
71 | |
---|
72 | // 規格2の要素を設定 |
---|
73 | for (var key in classcat2) { |
---|
74 | var id = classcat2[key]['classcategory_id2']; |
---|
75 | var name = classcat2[key]['name']; |
---|
76 | var option = $('<option />').val(id ? id : '').text(name); |
---|
77 | if (id == selected_id2) { |
---|
78 | option.attr('selected', true); |
---|
79 | } |
---|
80 | $sele2.append(option); |
---|
81 | } |
---|
82 | checkStock($form, product_id, $sele1.val() ? $sele1.val() : '__unselected2', |
---|
83 | $sele2.val() ? $sele2.val() : ''); |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * 規格の選択状態に応じて, フィールドを設定する. |
---|
90 | */ |
---|
91 | function checkStock($form, product_id, classcat_id1, classcat_id2) { |
---|
92 | |
---|
93 | classcat_id2 = classcat_id2 ? classcat_id2 : ''; |
---|
94 | |
---|
95 | var classcat2; |
---|
96 | |
---|
97 | // 商品一覧時 |
---|
98 | if (typeof productsClassCategories != 'undefined') { |
---|
99 | classcat2 = productsClassCategories[product_id][classcat_id1]['#' + classcat_id2]; |
---|
100 | } |
---|
101 | // 詳細表示時 |
---|
102 | else { |
---|
103 | classcat2 = classCategories[classcat_id1]['#' + classcat_id2]; |
---|
104 | } |
---|
105 | |
---|
106 | // 商品コード |
---|
107 | var $product_code_default = $form.find('[id^=product_code_default]'); |
---|
108 | var $product_code_dynamic = $form.find('[id^=product_code_dynamic]'); |
---|
109 | if (classcat2 |
---|
110 | && typeof classcat2['product_code'] != 'undefined') { |
---|
111 | $product_code_default.hide(); |
---|
112 | $product_code_dynamic.show(); |
---|
113 | $product_code_dynamic.text(classcat2['product_code']); |
---|
114 | } else { |
---|
115 | $product_code_default.show(); |
---|
116 | $product_code_dynamic.hide(); |
---|
117 | } |
---|
118 | |
---|
119 | // 在庫(品切れ) |
---|
120 | var $cartbtn_default = $form.find('[id^=cartbtn_default]'); |
---|
121 | var $cartbtn_dynamic = $form.find('[id^=cartbtn_dynamic]'); |
---|
122 | if (classcat2 && classcat2['stock_find'] === false) { |
---|
123 | |
---|
124 | $cartbtn_dynamic.text('申し訳ございませんが、只今品切れ中です。').show(); |
---|
125 | $cartbtn_default.hide(); |
---|
126 | } else { |
---|
127 | $cartbtn_dynamic.hide(); |
---|
128 | $cartbtn_default.show(); |
---|
129 | } |
---|
130 | |
---|
131 | // 通常価格 |
---|
132 | var $price01_default = $form.find('[id^=price01_default]'); |
---|
133 | var $price01_dynamic = $form.find('[id^=price01_dynamic]'); |
---|
134 | if (classcat2 |
---|
135 | && typeof classcat2['price01'] != 'undefined' |
---|
136 | && String(classcat2['price01']).length >= 1) { |
---|
137 | |
---|
138 | $price01_dynamic.text(classcat2['price01']).show(); |
---|
139 | $price01_default.hide(); |
---|
140 | } else { |
---|
141 | $price01_dynamic.hide(); |
---|
142 | $price01_default.show(); |
---|
143 | } |
---|
144 | |
---|
145 | // 販売価格 |
---|
146 | var $price02_default = $form.find('[id^=price02_default]'); |
---|
147 | var $price02_dynamic = $form.find('[id^=price02_dynamic]'); |
---|
148 | if (classcat2 |
---|
149 | && typeof classcat2['price02'] != 'undefined' |
---|
150 | && String(classcat2['price02']).length >= 1) { |
---|
151 | |
---|
152 | $price02_dynamic.text(classcat2['price02']).show(); |
---|
153 | $price02_default.hide(); |
---|
154 | } else { |
---|
155 | $price02_dynamic.hide(); |
---|
156 | $price02_default.show(); |
---|
157 | } |
---|
158 | |
---|
159 | // ポイント |
---|
160 | var $point_default = $form.find('[id^=point_default]'); |
---|
161 | var $point_dynamic = $form.find('[id^=point_dynamic]'); |
---|
162 | if (classcat2 |
---|
163 | && typeof classcat2['point'] != 'undefined' |
---|
164 | && String(classcat2['point']).length >= 1) { |
---|
165 | |
---|
166 | $point_dynamic.text(classcat2['point']).show(); |
---|
167 | $point_default.hide(); |
---|
168 | } else { |
---|
169 | $point_dynamic.hide(); |
---|
170 | $point_default.show(); |
---|
171 | } |
---|
172 | |
---|
173 | // 商品規格 |
---|
174 | var $product_class_id_dynamic = $form.find('[id^=product_class_id]'); |
---|
175 | if (classcat2 |
---|
176 | && typeof classcat2['product_class_id'] != 'undefined' |
---|
177 | && String(classcat2['product_class_id']).length >= 1) { |
---|
178 | |
---|
179 | $product_class_id_dynamic.val(classcat2['product_class_id']); |
---|
180 | } else { |
---|
181 | $product_class_id_dynamic.val(''); |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | (function( window, undefined ){ |
---|
186 | |
---|
187 | var common = {}; |
---|
188 | |
---|
189 | common.win01 = function(URL,Winname,Wwidth,Wheight){ |
---|
190 | var WIN; |
---|
191 | WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=no,resizable=no,toolbar=no,location=no,directories=no,status=no"); |
---|
192 | WIN.focus(); |
---|
193 | }; |
---|
194 | |
---|
195 | common.win02 = function(URL,Winname,Wwidth,Wheight){ |
---|
196 | var WIN; |
---|
197 | WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no"); |
---|
198 | WIN.focus(); |
---|
199 | }; |
---|
200 | |
---|
201 | common.win03 = function(URL,Winname,Wwidth,Wheight){ |
---|
202 | var WIN; |
---|
203 | WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no"); |
---|
204 | WIN.focus(); |
---|
205 | }; |
---|
206 | |
---|
207 | common.winSubmit = function(URL,formName,Winname,Wwidth,Wheight){ |
---|
208 | var WIN = window.open(URL,Winname,"width="+Wwidth+",height="+Wheight+",scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no,menubar=no"); |
---|
209 | document.forms[formName].target = Winname; |
---|
210 | WIN.focus(); |
---|
211 | }; |
---|
212 | |
---|
213 | common.openWindow = function(URL,name,width,height) { |
---|
214 | window.open(URL,name,"width="+width+",height="+height+",scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no"); |
---|
215 | }; |
---|
216 | |
---|
217 | // 親ウィンドウの存在確認. |
---|
218 | common.isOpener = function() { |
---|
219 | var ua = navigator.userAgent; |
---|
220 | if( !!window.opener ) { |
---|
221 | if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1 ) { |
---|
222 | return !window.opener.closed; |
---|
223 | } else { |
---|
224 | return typeof window.opener.document == 'object'; |
---|
225 | } |
---|
226 | } else { |
---|
227 | return false; |
---|
228 | } |
---|
229 | }; |
---|
230 | |
---|
231 | common.chgImg = function(fileName,img){ |
---|
232 | if (typeof(img) == "object") { |
---|
233 | img.src = fileName; |
---|
234 | } else { |
---|
235 | document.images[img].src = fileName; |
---|
236 | } |
---|
237 | }; |
---|
238 | |
---|
239 | common.chgImgImageSubmit = function(fileName,imgObj){ |
---|
240 | imgObj.src = fileName; |
---|
241 | }; |
---|
242 | |
---|
243 | // 郵便番号入力呼び出し. |
---|
244 | common.getAddress = function(php_url, tagname1, tagname2, input1, input2) { |
---|
245 | var zip1 = document.form1[tagname1].value; |
---|
246 | var zip2 = document.form1[tagname2].value; |
---|
247 | |
---|
248 | if(zip1.length == 3 && zip2.length == 4) { |
---|
249 | $.get( |
---|
250 | php_url, |
---|
251 | {zip1: zip1, zip2: zip2, input1: input1, input2: input2}, |
---|
252 | function(data) { |
---|
253 | var arrData = data.split("|"); |
---|
254 | if (arrData.length > 1) { |
---|
255 | eccube.common.putAddress(input1, input2, arrData[0], arrData[1], arrData[2]); |
---|
256 | } else { |
---|
257 | alert(data); |
---|
258 | } |
---|
259 | } |
---|
260 | ); |
---|
261 | } else { |
---|
262 | alert("郵便番号を正しく入力して下さい。"); |
---|
263 | } |
---|
264 | }; |
---|
265 | |
---|
266 | // 郵便番号から検索した住所を渡す. |
---|
267 | common.putAddress = function(input1, input2, state, city, town) { |
---|
268 | if(state != "") { |
---|
269 | // 項目に値を入力する. |
---|
270 | document.form1[input1].selectedIndex = state; |
---|
271 | document.form1[input2].value = city + town; |
---|
272 | } |
---|
273 | }; |
---|
274 | |
---|
275 | common.setFocus = function(name) { |
---|
276 | if(document.form1[name]) { |
---|
277 | document.form1[name].focus(); |
---|
278 | } |
---|
279 | }; |
---|
280 | |
---|
281 | // モードとキーを指定してSUBMITを行う。 |
---|
282 | common.setModeAndSubmit = function(mode, keyname, keyid) { |
---|
283 | switch(mode) { |
---|
284 | case 'delete_category': |
---|
285 | if(!window.confirm('選択したカテゴリとカテゴリ内の全てのカテゴリを削除します')){ |
---|
286 | return; |
---|
287 | } |
---|
288 | break; |
---|
289 | case 'delete': |
---|
290 | if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか?')){ |
---|
291 | return; |
---|
292 | } |
---|
293 | break; |
---|
294 | case 'confirm': |
---|
295 | if(!window.confirm('登録しても宜しいですか')){ |
---|
296 | return; |
---|
297 | } |
---|
298 | break; |
---|
299 | case 'delete_all': |
---|
300 | if(!window.confirm('検索結果を全て削除しても宜しいですか')){ |
---|
301 | return; |
---|
302 | } |
---|
303 | break; |
---|
304 | default: |
---|
305 | break; |
---|
306 | } |
---|
307 | document.form1['mode'].value = mode; |
---|
308 | if(keyname != "" && keyid != "") { |
---|
309 | document.form1[keyname].value = keyid; |
---|
310 | } |
---|
311 | document.form1.submit(); |
---|
312 | }; |
---|
313 | |
---|
314 | common.fnFormModeSubmit = function(form, mode, keyname, keyid) { |
---|
315 | switch(mode) { |
---|
316 | case 'delete': |
---|
317 | if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか?')){ |
---|
318 | return; |
---|
319 | } |
---|
320 | break; |
---|
321 | case 'confirm': |
---|
322 | if(!window.confirm('登録しても宜しいですか')){ |
---|
323 | return; |
---|
324 | } |
---|
325 | break; |
---|
326 | case 'regist': |
---|
327 | if(!window.confirm('登録しても宜しいですか')){ |
---|
328 | return; |
---|
329 | } |
---|
330 | break; |
---|
331 | default: |
---|
332 | break; |
---|
333 | } |
---|
334 | document.forms[form]['mode'].value = mode; |
---|
335 | if(keyname != "" && keyid != "") { |
---|
336 | document.forms[form][keyname].value = keyid; |
---|
337 | } |
---|
338 | document.forms[form].submit(); |
---|
339 | }; |
---|
340 | |
---|
341 | common.setValueAndSubmit = function(form, key, val) { |
---|
342 | document.forms[form][key].value = val; |
---|
343 | document.forms[form].submit(); |
---|
344 | return false; |
---|
345 | }; |
---|
346 | |
---|
347 | common.setValue = function(key, val, form) { |
---|
348 | if (typeof form === 'undefined') { |
---|
349 | form = 'form1'; |
---|
350 | } |
---|
351 | document.forms[form][key].value = val; |
---|
352 | }; |
---|
353 | |
---|
354 | common.changeAction = function(url) { |
---|
355 | document.form1.action = url; |
---|
356 | }; |
---|
357 | |
---|
358 | // ページナビで使用する。 |
---|
359 | common.movePage = function(pageno, mode, form) { |
---|
360 | if (typeof form !== 'undefined') { |
---|
361 | form = 'form1'; |
---|
362 | } |
---|
363 | document.forms[form]['pageno'].value = pageno; |
---|
364 | if (typeof mode !== 'undefined') { |
---|
365 | document.forms[form]['mode'].value = 'search'; |
---|
366 | } |
---|
367 | document.forms[form].submit(); |
---|
368 | }; |
---|
369 | |
---|
370 | common.submitForm = function(form){ |
---|
371 | if (typeof form !== 'undefined') { |
---|
372 | form = 'form1'; |
---|
373 | } |
---|
374 | document.forms[form].submit(); |
---|
375 | } |
---|
376 | |
---|
377 | // ポイント入力制限。 |
---|
378 | common.togglePointForm = function() { |
---|
379 | if(document.form1['point_check']) { |
---|
380 | var list = ['use_point']; |
---|
381 | var color; |
---|
382 | var flag; |
---|
383 | |
---|
384 | if(!document.form1['point_check'][0].checked) { |
---|
385 | color = "#dddddd"; |
---|
386 | flag = true; |
---|
387 | } else { |
---|
388 | color = ""; |
---|
389 | flag = false; |
---|
390 | } |
---|
391 | |
---|
392 | var len = list.length; |
---|
393 | for(i = 0; i < len; i++) { |
---|
394 | if(document.form1[list[i]]) { |
---|
395 | var current_color = document.form1[list[i]].style.backgroundColor; |
---|
396 | if (color != "#dddddd" && (current_color == "#ffe8e8" || current_color == "rgb(255, 232, 232)")) |
---|
397 | { |
---|
398 | continue; |
---|
399 | } |
---|
400 | document.form1[list[i]].disabled = flag; |
---|
401 | document.form1[list[i]].style.backgroundColor = color; |
---|
402 | } |
---|
403 | } |
---|
404 | } |
---|
405 | } |
---|
406 | |
---|
407 | // 別のお届け先入力制限。 |
---|
408 | common.toggleDeliveryForm = function() { |
---|
409 | if(!document.form1) { |
---|
410 | return; |
---|
411 | } |
---|
412 | if(document.form1['deliv_check']) { |
---|
413 | var list = [ |
---|
414 | 'shipping_name01', |
---|
415 | 'shipping_name02', |
---|
416 | 'shipping_kana01', |
---|
417 | 'shipping_kana02', |
---|
418 | 'shipping_pref', |
---|
419 | 'shipping_zip01', |
---|
420 | 'shipping_zip02', |
---|
421 | 'shipping_addr01', |
---|
422 | 'shipping_addr02', |
---|
423 | 'shipping_tel01', |
---|
424 | 'shipping_tel02', |
---|
425 | 'shipping_tel03' |
---|
426 | ]; |
---|
427 | |
---|
428 | if(!document.form1['deliv_check'].checked) { |
---|
429 | eccube.common.changeDisabled(list, '#dddddd'); |
---|
430 | } else { |
---|
431 | eccube.common.changeDisabled(list, ''); |
---|
432 | } |
---|
433 | } |
---|
434 | }; |
---|
435 | |
---|
436 | // 最初に設定されていた色を保存しておく。 |
---|
437 | common.savedColor = []; |
---|
438 | |
---|
439 | common.changeDisabled = function(list, color) { |
---|
440 | var len = list.length; |
---|
441 | |
---|
442 | for(i = 0; i < len; i++) { |
---|
443 | if(document.form1[list[i]]) { |
---|
444 | if(color == "") { |
---|
445 | // 有効にする。 |
---|
446 | document.form1[list[i]].disabled = false; |
---|
447 | document.form1[list[i]].style.backgroundColor = eccube.common.savedColor[list[i]]; |
---|
448 | } else { |
---|
449 | // 無効にする。 |
---|
450 | document.form1[list[i]].disabled = true; |
---|
451 | eccube.common.savedColor[list[i]] = document.form1[list[i]].style.backgroundColor; |
---|
452 | document.form1[list[i]].style.backgroundColor = color;//"#f0f0f0"; |
---|
453 | } |
---|
454 | } |
---|
455 | } |
---|
456 | }; |
---|
457 | |
---|
458 | // ログイン時の入力チェック |
---|
459 | common.checkLoginFormInputted = function(form, emailKey, passKey) { |
---|
460 | var checkItems = []; |
---|
461 | |
---|
462 | if (typeof emailKey === 'undefined') { |
---|
463 | checkItems[0] = 'login_email'; |
---|
464 | } else { |
---|
465 | checkItems[0] = emailKey; |
---|
466 | } |
---|
467 | if (typeof passKey === 'undefined') { |
---|
468 | checkItems[1] = 'login_pass'; |
---|
469 | } else { |
---|
470 | checkItems[1] = passKey; |
---|
471 | } |
---|
472 | |
---|
473 | var max = checkItems.length; |
---|
474 | var errorFlag = false; |
---|
475 | |
---|
476 | // 必須項目のチェック |
---|
477 | for(var cnt = 0; cnt < max; cnt++) { |
---|
478 | if(document.forms[form][checkItems[cnt]].value == "") { |
---|
479 | errorFlag = true; |
---|
480 | break; |
---|
481 | } |
---|
482 | } |
---|
483 | |
---|
484 | // 必須項目が入力されていない場合 |
---|
485 | if(errorFlag == true) { |
---|
486 | alert('メールアドレス/パスワードを入力して下さい。'); |
---|
487 | return false; |
---|
488 | } else { |
---|
489 | return true; |
---|
490 | } |
---|
491 | }; |
---|
492 | |
---|
493 | //親ウィンドウのページを変更する. |
---|
494 | common.changeParentUrl = function(url) { |
---|
495 | // 親ウィンドウの存在確認 |
---|
496 | if(eccube.common.isOpener()) { |
---|
497 | window.opener.location.href = url; |
---|
498 | } else { |
---|
499 | window.close(); |
---|
500 | } |
---|
501 | }; |
---|
502 | |
---|
503 | //文字数をカウントする。 |
---|
504 | //引数1:フォーム名称 |
---|
505 | //引数2:文字数カウント対象 |
---|
506 | //引数3:カウント結果格納対象 |
---|
507 | common.countChars = function(form,sch,cnt) { |
---|
508 | document.forms[form][cnt].value= document.forms[form][sch].value.length; |
---|
509 | }; |
---|
510 | |
---|
511 | // テキストエリアのサイズを変更する. |
---|
512 | common.toggleRows = function(buttonSelector, textAreaSelector, max, min) { |
---|
513 | if ($(textAreaSelector).attr('rows') <= min) { |
---|
514 | $(textAreaSelector).attr('rows', max); |
---|
515 | $(buttonSelector).text('縮小'); |
---|
516 | } else { |
---|
517 | $(textAreaSelector).attr('rows', min); |
---|
518 | $(buttonSelector).text('拡大'); |
---|
519 | } |
---|
520 | }; |
---|
521 | |
---|
522 | // 名前空間の重複を防ぐ |
---|
523 | if (window.eccube === undefined) { |
---|
524 | window.eccube = {}; |
---|
525 | } |
---|
526 | // グローバルに使用できるようにする |
---|
527 | window.eccube.common = common; |
---|
528 | })(window); |
---|
529 | |
---|