console.log('ready commmon !'); /* cunstom location */ $('.location').on('click',function(e) { $href = $(this).data('href'); $tgt = $(this).data('tgt'); if( $tgt == '_blank' ) { window.open($href,"_blank"); } else { location.href = $href; } return false; }); /* modal common */ $('.js-modal-close').on('click',function(e) { $('.js-modal').fadeOut(); return false; }); /* cunstom done alert */ function done_alert( done_code ) { let dones = { '0001': { "title":"保存完了" , "text":"保存しました" }, '0002': { "title":"削除完了" , "text":"削除しました" } }; if( dones[done_code] ) { $.alert({ title: dones[done_code]['title'], type:'black', theme:'Modern', animation: 'opacity', closeAnimation: 'opacity', animateFromElement: false, columnClass: 'small', content: dones[done_code]['text'], }); } } /* cunstom error alert */ function error_alert( error_code ) { let errors = { '0001': { "title":"システムエラー" , "text":"システムエラーが発生しました[error_code:0001]" }, '0002': { "title":"ログインエラー" , "text":"ログイン出来ませんでした[error_code:0002]" }, '0003': { "title":"ログインエラー" , "text":"ユーザーセッションが存在しないためログイン出来ませんでした[error_code:0003]" }, '0004': { "title":"ログインエラー" , "text":"セッションが存在しないためログイン出来ませんでした[error_code:0004]" }, '0005': { "title":"ログインエラー" , "text":"セッションタイムアウトが発生しました[error_code:0005]" }, '0006': { "title":"ログインエラー" , "text":"プロジェクトコードエラーが発生しました[error_code:0006]" }, '9999': { "title":"エラー" , "text":"予期せぬbエラーが発生しました[error_code:9999]" } }; if( errors[error_code] ) { $.alert({ title: errors[error_code]['title'], type:'black', theme:'Modern', animation: 'opacity', closeAnimation: 'opacity', animateFromElement: false, columnClass: 'small', content: errors[error_code]['text'], }); } } /* cunstom validation */ function validation(form_id) { $( form_id ).find('.error_text').remove(); error = 0; $( form_id ).find('.required').each(function(i,e) { if( $(e).attr('type') == 'text' || $(e).attr('type') == 'number' || $(e).attr('type') == 'date' || $(e).attr('type') == 'hidden' || $(e).attr('type') == 'email' || $(e).attr('type') == 'password' || $(e).attr('type') == 'textarea' || $(e).attr('type') == 'tel' ) { //共通必須処理 if( $(e).val() == '' ) { $(e).parent().after('

' + $(e).data('placeholder') + 'が入力されていません

'); error++; } //文字数処理 if( $(e).val() != '' && $(e).data('length-min') !== undefined ) { if( $(e).val().length < $(e).data('length-min') ) { $(e).after('

' + $(e).data('length-min') + '文字以上で入力してください

'); error++; } } if( $(e).val() != '' && $(e).data('length-max') !== undefined ) { if( $(e).val().length > $(e).data('length-max') ) { $(e).after('

' + $(e).data('length-max') + '文字以下で入力してください

'); error++; } } //数値処理 if( $(e).val() != '' && $(e).attr('type') == 'number' && $(e).data('number-min') !== undefined ) { if( $(e).val() < $(e).data('number-min') ) { $(e).after('

' + $(e).data('number-min') + '以上で入力してください

'); error++; } } if( $(e).val() != '' && $(e).attr('type') == 'number' && $(e).data('number-max') !== undefined ) { if( $(e).val() > $(e).data('number-max') ) { $(e).after('

' + $(e).data('number-max') + '以下で入力してください

'); error++; } } //メールアドレス処理 if( $(e).attr('type') == 'email' && $(e).val() != '' && !$(e).val().match(/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/) ) { $(e).after('

メールアドレスが正しくありません

'); error++; } // if( $(e).val() != '' && $(e).data('match') !== undefined ) { if( $(e).data('match') == 'ひらがな' && !$(e).val().match( /^[\u3040-\u309f]+$/ ) ) { $(e).after('

' + $(e).data('match') + 'で入力してください

'); error++; } if( $(e).data('match') == 'カタカナ' && !$(e).val().match( /^[\u30a0-\u30ff]+$/ ) ) { $(e).after('

' + $(e).data('match') + 'で入力してください

'); error++; } if( $(e).data('match') == '数字' && !$(e).val().match( /^([1-9]\d*|0)$/ ) ) { $(e).after('

' + $(e).data('match') + 'で入力してください

'); error++; } } } //SELECT if( $(e).val() == '' && $(e).attr('type') == 'select' ) { $(e).after('

' + $(e).data('placeholder') + 'が選択されていません

'); error++; } //CHECKBOX requirednumberで最低個数を指定可能 if( $(e).data('type') !== undefined && $(e).data('type') == 'checkbox' ) { $chk = 0; $(e).find('input[type="checkbox"]').each( function( index, element ) { if( $(element).prop('checked') ){$chk++;} }); if( $(e).data('requirednumber') !== undefined ){$requirednumber = $(e).data('requirednumber');}else{$requirednumber = 1;} if( $chk < $requirednumber ){ $(e).after('

' + $(e).data('placeholder') + 'が' + $requirednumber + 'つ以上選択されていません

'); error++; } } //RADIO if( $(e).data('type') !== undefined && $(e).data('type') == 'radio' ) { $chk = 0; $(e).find('input[type="radio"]').each( function( index, element ) { if( $(element).prop('checked') ){$chk++;} }); if( $chk == 0 ){ $(e).after('

' + $(e).data('placeholder') + 'が選択されていません

'); error++; } } }); return error; } /* all check */ $('.all_checked').on('click',function(e) { $(this).parent().find('input[type="checkbox"]').prop('checked','true'); return false; }); /* FROM STEPS */ $('.back-btn').on('click',function() { if( $(this).data('validation') !== undefined ) { error = validation( $(this).data('validation') ); if( error != 0 ){ return false; } } $( $(this).data('tgtid') ).removeClass('d-none'); $( $(this).data('thistgtid') ).addClass('d-none'); return false; }); $(".next-btn").on('click',function() { if( $(this).data('validation') !== undefined ) { error = validation( $(this).data('validation') ); if( error != 0 ){ return false; } } $( $(this).data('tgtid') ).removeClass('d-none'); $( $(this).data('thistgtid') ).addClass('d-none'); return false; }); $(".ragist-btn").on('click',function() { if( $(this).data('validation') !== undefined ) { error = validation( $(this).data('validation') ); if( error != 0 ){ return false; } } if( $(this).data('spinner') !== undefined ) { $( $(this).data('spinner') ).removeClass('d-none'); $( $(this).data('tgtform') ).addClass('d-none'); } //$( $(this).data('tgtform') ).submit(); }); /* 問い合わせ分析モーダル */ $('.inquiry_type_div').on('click',function() { $('.inquiry_type_div > div').removeClass('checked'); $('input.inquiry_type').prop('checked',false); $($(this).data('for')).prop('checked',true); $(this).find('div').addClass('checked'); $('.chg_required').removeClass('required'); $( $(this).data('required') ).addClass('required'); $('.hideclass').addClass('d-none'); $($(this).data('showclass')).removeClass('d-none'); return false; }); /* イベントモーダル */ $('.event_type_div').on('click',function() { $('.event_type_div > div').removeClass('checked'); $('input.event_type').prop('checked',false); $($(this).data('for')).prop('checked',true); $(this).find('div').addClass('checked'); $('.chg_required').removeClass('required'); $( $(this).data('required') ).addClass('required'); return false; }); /* イベント検索 */ $('.event_search').on('keyup change',function() { $('.event_id').html('') setEvent( $('.csrf_token').val() , $(this).val() , $('.event_id') , $('.root').val() ); return true; }); function setEvent($csrf_token,$event_date,$select,$root) { if( $event_date == '' ) { return false; } $.ajax({ url: $root + "php/api.php", type: 'POST', data : { event_date : $event_date, endpoint : 'event', csrf_token : $csrf_token } }) .done(function( data, textStatus, jqXHR ) { $select.html(data); }) .fail(function( jqXHR, textStatus, errorThrown ) { }); return true; } /* 学校検索 */ $('.school_search').on('keyup',function() { $parent = $(this).parent(); $parent.find('.school').val(''); setSchool( $('.csrf_token').val() , $(this).val() , $parent.find('.school_list') , $('.root').val() ); $parent.find('.school_list').removeClass('d-none'); return false; }); $('.school_list').on('change',function() { $parent = $(this).parent(); $parent.find('.school').val($parent.find('.school_list').val()); $parent.find('.school_name').val($parent.find('.school_list option:selected').text()); $parent.find('.school_list').addClass('d-none'); return false; }); function setSchool($csrf_token,$search_text,$select,$root) { if( $search_text.length < 2 ) { return false; } $.ajax({ url: $root + "php/api.php", type: 'POST', data : { search_text : $search_text, endpoint : 'school', csrf_token : $csrf_token } }) .done(function( data, textStatus, jqXHR ) { $select.html(data); }) .fail(function( jqXHR, textStatus, errorThrown ) { }); return true; } /* 住所取得 */ $('.zip').on('keyup',function(e){ setState( $('.csrf_token').val() , $(this).val() , $('#add1') , $('.root').val() ); }); function setState($csrf_token,$zip,$add,$root) { if( $zip.length != 7 ) { return false; } if( !$zip.match(/^[0-9]+$/) ) { return false; } $.ajax({ url: $root + "php/api.php", type: 'POST', data : { zip : $zip, endpoint : 'state', csrf_token : $csrf_token } }) .done(function( data, textStatus, jqXHR ) { result = JSON.parse(data); if( result['state'] == 200 ) { $add.val(result['tdfk_name'] + result['address1'] + result['address2']); } }) .fail(function( jqXHR, textStatus, errorThrown ) { }); return true; }