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