"use strict";
var commonScript;
(function (commonScript) {
commonScript.shop_list = null;
commonScript.case_list = null;
commonScript.page_no = 0;
commonScript.max_page = 0;
commonScript.scroll_flg = true;
var apiUrlReverseGeo = "/membership/api/reverse_geocoding";
var apiUrlCity = "/membership/api/city";
var apiUrlShop = "/membership/api/shop";
var apiUrlShopCount = "/membership/api/shop/count";
var apiUrlCase = "/membership/api/case";
var apiUrlCaseCount = "/membership/api/case/count";
function initializeCommonButton() {
$(document).bind("ajaxSend", function (c, xhr) {
$(window).bind('beforeunload', function () {
xhr.abort();
});
});
$(".btn_location").on("click", function () {
getCurrentPlace(true);
});
$("#select_pref").change(function (e, when) {
initSelectCity();
if ($('#select_pref').val() == '00') {
return;
}
var init_flg = (when == 'init' ? 1 : null);
getCity(init_flg, $('#select_pref').val());
});
$("#select_city").change(function () {
$('.btn_submit').click();
});
}
commonScript.initializeCommonButton = initializeCommonButton;
function getCurrentPlace(search_flg) {
if (search_flg === void 0) { search_flg = false; }
var success = function (position) {
$.ajax({
url: apiUrlReverseGeo,
type: 'get',
data: {
lat: position.coords.latitude,
lon: position.coords.longitude
},
async: true,
dataType: 'json'
}).done(function (data, textStatus, jqXHR) {
if (data == null || data == '' || !data['pref_code'] || data['pref_code'] == '' || !data['city_code'] || data['city_code'] == '') {
$('#errmsg').append('エラーが発生したため、会員店情報をダウンロードすることができませんでした。(サーバーからの情報の取得中にエラーが発生しました。[' + jqXHR.status + '])').removeClass('non-display');
return;
}
var pref_code = data['pref_code'];
var city_code = data['city_code'];
if ($('#select_pref').length) {
$('#select_pref').val(pref_code);
$('#select_city').prop('disabled', false);
getCity(null, pref_code, city_code, search_flg);
}
else {
getShopListByCurrentPlace(city_code);
$('#more').removeClass('non-display');
$('#more').attr('city', city_code);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
$('#more').addClass('non-display');
$('#errmsg').append('エラーが発生したため、会員店情報をダウンロードすることができませんでした。(サーバーからの情報の取得中にエラーが発生しました。[' + jqXHR.status + '])').removeClass('non-display');
});
};
var error = function (error) {
$('#more').addClass('non-display');
switch (error.code) {
case 1:
$('#errmsg').append('位置情報を取得できませんでした。端末の位置情報取得機能をONにするか、電波状況の良い所で再度お試しください。').removeClass('non-display');
break;
default:
$('#errmsg').append('エラーが発生したため、会員店情報をダウンロードすることができませんでした。(サーバーからの情報の取得中にエラーが発生しました。[' + error.code + '])').removeClass('non-display');
break;
}
};
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
}
}
commonScript.getCurrentPlace = getCurrentPlace;
function getShopListByCurrentPlace(city_code) {
$.ajax({
url: apiUrlShop,
type: 'get',
data: {
city_code: city_code,
limit: top_shop_limit
},
async: true,
dataType: 'html',
beforeSend: function () {
$('.loading').removeClass('hide');
}
}).done(function (data, textStatus, jqXHR) {
var html = $(data).children('div');
$('#shop_list').append(html);
}).fail(function (jqXHR, textStatus, errorThrown) {
alert('会員店情報が取得できませんでした(1)');
$('#cation').append('現在、エラー(コードNo.' + jqXHR.status + ')のため表示することができません。時間をおいてから再度お試しください。').removeClass('non-display');
}).always(function () {
$('.loading').addClass('hide');
});
}
commonScript.getShopListByCurrentPlace = getShopListByCurrentPlace;
function getShopListByConditions(city_code, construction_type, reform_place_code, name) {
// alert("名前:" + name);
$.ajax({
url: apiUrlShop,
type: 'get',
data: {
city_code: city_code == null ? '' : city_code,
construction_type: construction_type,
reform_place_code: reform_place_code,
name: name
},
async: true,
dataType: 'html',
beforeSend: function () {
$('#shop_list_inbox').html('');
$('#num_all').html('');
$('.loading').removeClass('hide');
}
}).done(function (data, textStatus, jqXHR) {
commonScript.shop_list = data;
commonScript.page_no = 1;
var html = getHtmlPage(commonScript.shop_list, 'div', shop_cnt_per_scroll, shop_cnt_default);
$('#shop_list_inbox').append(html);
// var cnt = $(commonScript.shop_list).children('div').length;
var elemShopList = document.createElement('div');
elemShopList.innerHTML = data;
var cnt = elemShopList.getElementsByClassName('shop_each').length;
$('#num_all').html('全' + cnt.toString() + '件');
}).fail(function (jqXHR, textStatus, errorThrown) {
alert('会員店情報が取得できませんでした(2)');
$('#cation').append('現在、エラー(コードNo.' + jqXHR.status + ')のため表示することができません。時間をおいてから再度お試しください。').removeClass('non-display');
}).always(function () {
$('.loading').addClass('hide');
});
}
commonScript.getShopListByConditions = getShopListByConditions;
function getShopCount() {
var city_code = $('#select_city').val();
var construction_type = $('input[name="group1"]:checked').val();
var name =$('#name_search').val();
var reform_place_code = '' + $('[name="group3"]:checked').map(function () {
return $(this).val();
}).get();
$.ajax({
url: apiUrlShopCount,
type: 'get',
data: {
city_code: city_code,
construction_type: construction_type,
reform_place_code: (construction_type == '1' ? reform_place_code : null),
name: name
},
async: true,
dataType: 'json'
}).done(function (data, textStatus, jqXHR) {
$('#num').html(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
alert('会員店情報が取得できませんでした(3)');
});
}
commonScript.getShopCount = getShopCount;
function getCaseListByConditions(city_code, place_code, construction_type, preference_code) {
$.ajax({
url: apiUrlCase,
type: 'get',
data: {
city_code: city_code == null ? '' : city_code,
place_code: place_code,
construction_type: construction_type,
preference_code: preference_code,
shop_code: param_shop_code
},
async: true,
dataType: 'html',
beforeSend: function () {
$('#case_list_inbox').html('');
$('.loading').removeClass('hide');
}
}).done(function (data, textStatus, jqXHR) {
commonScript.case_list = data;
commonScript.page_no = 1;
var html = getHtmlPage(commonScript.case_list, 'a', case_cnt_per_scroll, case_cnt_default);
if (html == '') {
$('#cation').removeClass('case_cation').html('この場所が対応エリアの会員店事例は、現在掲載しておりません。');
}
else {
$('#cation').addClass('case_cation').html('※事例に掲載されているトクラス商品は、既に廃番の商品も含まれます。');
}
$('#case_list_inbox').append(html);
}).fail(function (jqXHR, textStatus, errorThrown) {
alert('施工事例情報が取得できませんでした(1)');
$('#cation').append('現在、エラー(コードNo.' + jqXHR.status + ')のため表示することができません。時間をおいてから再度お試しください。').removeClass('non-display').removeClass('case_cation');
}).always(function () {
$('.loading').addClass('hide');
});
}
commonScript.getCaseListByConditions = getCaseListByConditions;
function getCaseCount() {
var city_code = $('#select_city').val();
if (city_code != null && param_shop_code != '') {
param_shop_code = '';
var url = location.href;
var param = location.search;
var replace_url = url.replace(param, '');
history.pushState(null, '', replace_url);
}
var place_code = '' + $('[name="group1"]:checked').map(function () {
return $(this).val();
}).get();
var construction_type = $('input[name="group2"]:checked').val();
var preference_code_new = '' + $('[name="group3"]:checked').map(function () {
return $(this).val();
}).get();
var preference_code_reform = '' + $('[name="group4"]:checked').map(function () {
return $(this).val();
}).get();
$.ajax({
url: apiUrlCaseCount,
type: 'get',
data: {
city_code: city_code,
place_code: place_code,
construction_type: construction_type,
preference_code: (construction_type == '1' ? preference_code_reform : preference_code_new),
shop_code: param_shop_code
},
async: true,
dataType: 'json'
}).done(function (data, textStatus, jqXHR) {
$('#num').html(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
alert('施工事例情報が取得できませんでした(2)');
});
}
commonScript.getCaseCount = getCaseCount;
function getHtmlPage(list, tag, cnt_per_scroll, cnt_default) {
var from = commonScript.page_no == 1 ? 1 : cnt_default + (commonScript.page_no - 2) * cnt_per_scroll + 1;
var to = commonScript.page_no == 1 ? cnt_default : cnt_default + (commonScript.page_no - 1) * cnt_per_scroll;
var no = 1;
var html = '';
var div = $(list).children(tag);
var cnt = 0;
div.each(function () {
cnt++;
no = parseInt($(this).attr('no'));
if (no < from) {
return;
}
if (no > to) {
return;
}
html += $(this).prop('outerHTML');
});
commonScript.max_page = Math.ceil(cnt / cnt_per_scroll);
commonScript.page_no++;
return html;
}
commonScript.getHtmlPage = getHtmlPage;
function getCity(init_flg, pref_code, city_code, search_flg) {
if (init_flg === void 0) { init_flg = null; }
if (city_code === void 0) { city_code = null; }
if (search_flg === void 0) { search_flg = false; }
$.ajax({
url: apiUrlCity,
type: 'get',
data: {
pref_code: pref_code
},
async: true,
dataType: 'json'
}).done(function (data, textStatus, jqXHR) {
initSelectCity();
Object.keys(data).forEach(function (key) {
var row = data[key];
$('#select_city').append($('');
}
commonScript.initSelectCity = initSelectCity;
})(commonScript || (commonScript = {}));
$(document).ready(commonScript.initializeCommonButton);