<a01>
    <link rel="stylesheet" href="css/A01.css">

    <div class="main">
      <div class="content">
        <div class="page-title">
          <h2>利用法人設定</h2>
        </div>
        <div class="tab-content">
          <div class="tab-child active" data-panel="panel_first" id="first_tab">個別設定</div>
          <div class="tab-child" data-panel="panel_second" id="second_tab">コピー設定</div>
        </div>
        <div class="wrap_content active" id="panel_first">
          <div class="form-wrapper">
            <table>
              <tr>
                <th style="width:65px">法人名：</th>
                <td ><div class="div-wraper-autocompleter"><input type="text" id="comp_name"></div></td>
                <td style="width:100px"><button onclick="{searchList}">表示</button></td>
              </tr>
            </table>
          </div>
          <div class="result-wrapper">
            <div class="comp-name">
              <dl>
                <dt></dt>
                <dd></dd>
              </dl>
              <dl>
                <dt></dt>
                <dd></dd>
              </dl>
            </div>
            <div class="comp-data">
              <div class="tab-area">
                <div class="tab active" data-panel="panel_1" id="user_tab">ユーザー設定</div>
                <div class="tab" data-panel="panel_2" id="supplier_tab">開示対象メーカー設定</div>
                <div class="tab" data-panel="panel_3" id="other_tab">その他の開示設定</div>
                <div class="tab" data-panel="panel_4" id="navigation_tab">ナビゲーション設定</div>
              </div>
              <div class="panel-area">
                <div class="panel active" id="panel_1">
                  <table class="blue-table">
                    <thead>
                      <tr>
                        <th>ユーザーID</th>
                        <th>氏名</th>
                        <th>EMAIL</th>
                        <th>ログインパスワード</th>
                        <th>権限</th>
                        <th>会員種別</th>
                        <th colspan="2"><button type="button" class="addNewBtn">新規追加</button></th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr each={ element, index in users_list }>
                        <td>
                          <p class="display">{element.id}</p>
                          <input type="hidden" class="id_user_hidden_edit" value="{element.id}" index={index}>
                          <input type="text" class="edit input_edit_user id_user_edit" value="{element.id}" disabled="disabled">
                        </td>
                        <td>
                          <p class="display">{element.name}</p>
                          <input type="text" class="edit input_edit_user user_name_edit" value="{element.name}">
                        </td>
                        <td>
                          <p class="display">{element.email}</p>
                          <input type="text" class="edit input_edit_user user_email_edit" value="{element.email}">
                          <input type="hidden" class="edit user_old_email_edit" value="{element.email}">
                        </td>
                        <td>
                          <p class="display">*******</p>
                          <input type="text" class="edit input_edit_user user_password_edit" value="" placeholder="*******">
                        </td>
                        <td>
                          <p class="display">{element.member_authority}</p>
                          <!-- <input type="text" class="edit input_edit_user user_member_authority_edit" value="{element.member_authority}"> -->
                          <select class="edit input_edit_user user_member_authority_edit">
                            <option value="1" selected="{element.member_authority == 1 ? 'selected' : ''}">1</option>
                            <option value="9" selected="{element.member_authority == 9 ? 'selected' : ''}">9</option>
                            <option value="5" selected="{element.member_authority == 5 ? 'selected' : ''}">5</option>
                          </select>
                        </td>
                        <td>
                          <p class="display">{element.member_type}</p>
                          <!-- <input type="text" class="edit input_edit_user user_member_authority_edit" value="{element.member_authority}"> -->
                          <select class="edit input_edit_user user_member_type_edit">
                            <option value="1" selected="{element.member_type == 1 ? 'selected' : ''}">1</option>
                            <option value="2" selected="{element.member_type == 2 ? 'selected' : ''}">2</option>
                            <option value="3" selected="{element.member_type == 3 ? 'selected' : ''}">3</option>
                            <option value="4" selected="{element.member_type == 4 ? 'selected' : ''}">4</option>
                          </select>
                        </td>
                        <td class="btnTd">
                          <button type="button" class="editBtn display">編集</button>
                          <button type="button" class="registerBtn edit" onclick="{editUser}">登録</button>
                        </td>
                        <td class="btnTd">
                          <button type="button" class="color-btn red-btn removeBtn display" onclick="{deleteUser}">削除</button>
                          <button type="button" class="reset-btn hideBtn edit" onclick="{resetButtonEdit}"><i class="fa fa-times"></i>取消</button>
                        </td>
                      </tr>
                    </tbody>
                    <tfoot class="addNewWrap">
                      <tr>
                        <td><input type="text" id="id_user" class="input_create_user"></td>
                        <td><input type="text" id="name_user" class="input_create_user"></td>
                        <td><input type="text" id="email_user" class="input_create_user"></td>
                        <td><input type="text" id="password_user" class="input_create_user"></td>
                        <td>
                          <select id="member_authority_user" class="input_create_user">
                            <option value="1">1</option>
                            <option value="9">9</option>
                          </select>
                          <!-- <input type="text" id="member_authority_user" class="input_create_user"></td> -->
                        <td class="btnTd"><button type="button" class="registerNewBtn" onclick="{createUser}">登録</button></td>
                        <td class="btnTd"><button type="button" class="hideNewWrap reset-btn" id="reset_user_add" onclick="{resetButtonAdd}"><i class="fa fa-times"></i>取消</button></td>
                      </tr>
                    </tfoot>
                  </table>
                  <div id="paging" class="text-center">
                    <ul class="pagination" id="pagination_users_list"></ul>
                  </div>
                  <div class="btn-wrapper">
                    <button id="a02_redirect_user">ユーザー設定を更新</button>
                  </div>
                </div>
                <div class="panel" id="panel_2">
                  <table class="blue-table">
                    <thead>
                      <tr>
                        <th style="width:150px">メーカー法人コード</th>
                        <th>メーカー名</th>
                        <th>アイテム数</th>
                        <th>開示する </th>
                        <th colspan="2">
                          <!-- <button type="button" class="addNewBtn">新規追加</button> -->
                        </th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr each={ element, index in supplier_setting }>
                        <td>
                          <p>{element.comp_code}</p>
                          <input type="hidden" value="{element.seq}" index={index} class="seq_supplier_setting">
                          <input type="hidden" class="edit supplier_setting_edit_value" value="{element.comp_code}">
                        </td>
                        <td>
                          <p class="display">{element.comp_name}</p>
                          <div class="div-wraper-autocompleter"><input type="text" class="edit supplier_setting_edit_name" value="{element.comp_name}" disabled="disabled"></div>
                        </td>
                        <td>{element.count_comp_code}</td>
                        <td>
                          <div if={element.check_comp_code_vs_control_field_value}>
                            <input type="checkbox" class="supplier_setting_edit_comp_code_field_value" checked="checked" style="display: block" disabled="disabled">
                          </div>
                          <div if={!element.check_comp_code_vs_control_field_value}>
                            <input type="checkbox" class="supplier_setting_edit_comp_code_field_value" style="display: block" disabled="disabled">
                          </div>
                        </td>
                        <td class="btnTd">
                          <button type="button" class="editBtn display">編集</button>
                          <button type="button" class="registerBtn edit" onclick="{postSupplierSetting}">登録</button>
                        </td>
                        <td class="btnTd">
                          <!-- <button type="button" class="color-btn red-btn removeBtn display" onclick="{deleteSupplierSetting}">削除</button> -->
                          <button type="button" class="reset-btn hideBtn edit" onclick="{resetButtonEdit}"><i class="fa fa-times"></i>取消</button>
                        </td>
                      </tr>
                    </tbody>
                    <tfoot class="addNewWrap">
                      <tr>
                        <td><input type="text" id="add_control_field_value" disabled="disabled"></td>
                        <td><div class="div-wraper-autocompleter"><input type="text" id="add_control_field_name"></div></td>
                        <td></td>
                        <td></td>
                        <td class="btnTd"><button type="button" class="registerNewBtn add" onclick="{postSupplierSetting}">登録</button></td>
                        <td class="btnTd"><button type="button" class="hideNewWrap reset-btn" id="reset_supplier_add" onclick="{resetButtonAdd}"><i class="fa fa-times"></i>取消</button></td>
                      </tr>
                    </tfoot>
                  </table>
                  <div id="paging" class="text-center">
                    <ul class="pagination" id="pagination_supplier_setting"></ul>
                  </div>
                  <div class="btn-wrapper">
                    <button id="a02_redirect_supplier">開示対象メーカー設定を更新</button>
                  </div>
                </div>
                <div class="panel" id="panel_3">
                  <table class="blue-table">
                    <thead>
                      <tr>
                        <th style="width:150px">開示制御フィールド</th>
                        <th>開示制御フィールド値</th>
                        <th colspan="2"><button type="button" class="addNewBtn">新規追加</button></th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr each={ element, index in other_setting }>
                        <td>
                          <p class="display">{element.control_field_name}</p>
                          <input type="hidden" value="{element.seq}" index={index} class="seq_other_setting">
                          <div class="div-wraper-autocompleter"><input type="text" class="edit other_setting_edit_name" value="{element.control_field_name}"></div>
                        </td>
                        <td>
                          <p class="display">{element.control_field_value}</p>
                          <div class="div-wraper-autocompleter"><input type="text" class="edit other_setting_edit_value" value="{element.control_field_value}"></div>
                        </td>
                        <td class="btnTd">
                          <button type="button" class="editBtn display">編集</button>
                          <button type="button" class="registerBtn edit" onclick="{postOtherSetting}">登録</button>
                        </td>
                        <td class="btnTd">
                          <button type="button" class="color-btn red-btn removeBtn display"  onclick="{deleteOtherSetting}">削除</button>
                          <button type="button" class="reset-btn hideBtn edit" onclick="{resetButtonEdit}"><i class="fa fa-times"></i>取消</button>
                        </td>
                      </tr>
                    </tbody>
                    <tfoot class="addNewWrap">
                      <tr>
                        <td><div class="div-wraper-autocompleter"><input type="text" id="add_control_field_name_other"></div></td>
                        <td><div class="div-wraper-autocompleter"><input type="text" id="add_control_field_value_other"></div></td>
                        <td class="btnTd"><button type="button" class="registerNewBtn" onclick="{postOtherSetting}">登録</button></td>
                        <td class="btnTd"><button type="button" class="hideNewWrap reset-btn" id="reset_other_add" onclick="{resetButtonAdd}"><i class="fa fa-times"></i>取消</button></td>
                      </tr>
                    </tfoot>
                  </table>
                  <div id="paging" class="text-center">
                    <ul class="pagination" id="pagination_other_setting"></ul>
                  </div>
                  <div class="btn-wrapper">
                    <button id="a02_redirect_other">その他の開示設定を更新</button>
                  </div>
                </div>
                <div class="panel" id="panel_4">
                  <table class="blue-table">
                    <thead>
                      <tr>
                        <th style="width:150px">ナビゲーションID</th>
                        <th>区分</th>
                        <th>名称</th>
                        <th>会員種別</th>
                        <th>会員権限</th>
                        <th>表示名</th>
                        <th>表示ステータス</th>
                        <th>表示順序</th>
                        <th colspan="2"><button type="button" class="addNewBtn">新規追加</button></th>
                      </tr>
                    </thead>
                    <tbody>
                      <tr each={ element, index in navigation_setting }>
                        <td>
                          <p class="display">{element.navigation_id}</p>
                          <input type="hidden" value="{element.seq}" index={index} class="seq_navigation_setting">
                          <input type="text" class="edit navigation_navigation_id_edit" value="{element.navigation_id}" disabled="disabled">
                        </td>
                        <td>
                          <p class="display">{element.div}</p>
                          <input type="text" class="edit navigation_div_edit" value="{element.div}" disabled="disabled">
                        </td>
                        <td>
                          <p class="display">{element.name}</p>
                          <input type="text" class="edit navigation_name_edit" value="{element.name}" disabled="disabled">
                        </td>
                        <td>
                          <p class="display">{element.member_type}</p>
                          <input type="text" class="edit navigation_member_type_edit" value="{element.member_type}" disabled="disabled">
                        </td>
                        <td>
                          <p class="display">{element.member_authority}</p>
                          <input type="text" class="edit navigation_member_authority_edit" value="{element.member_authority}" disabled="disabled">
                        </td>
                        <td>
                          <p class="display">{element.display_contents}</p>
                          <input type="text" class="edit navigation_display_contents_edit" value="{element.display_contents}">
                        </td>
                        <td>
                          <p class="display">{element.display_status}</p>
                          <div class="div-wraper-autocompleter"><input type="text" class="edit navigation_display_status_edit" value="{element.display_status}"></div>
                        </td>
                        <td>
                          <p class="display">{element.display_order}</p>
                          <input type="text" class="edit navigation_display_order_edit" value="{element.display_order}">
                        </td>
                        <td class="btnTd">
                          <button type="button" class="editBtn display">編集</button>
                          <button type="button" class="registerBtn edit" onclick="{postNavigationSetting}">登録</button>
                        </td>
                        <td class="btnTd">
                          <button type="button" class="color-btn red-btn removeBtn display" onclick="{deleteNavigationSetting}" if={element.seq}>削除</button>
                          <button type="button" class="reset-btn hideBtn edit" onclick="{resetButtonEdit}"><i class="fa fa-times"></i>取消</button>
                        </td>
                      </tr>
                    </tbody>
                    <tfoot class="addNewWrap">
                      <tr>
                        <td><input type="text" id="navigation_setting_add_navigation_id" onchange="{checkExistNavigationId}"></td>
                        <td><input type="text" id="navigation_setting_add_div" disabled="disabled"></td>
                        <td><input type="text" id="navigation_setting_add_name" disabled="disabled"></td>
                        <td><input type="text" id="navigation_setting_add_member_type" disabled="disabled"></td>
                        <td><input type="text" id="navigation_setting_add_member_authority" disabled="disabled"></td>
                        <td><input type="text" id="navigation_setting_add_display_contents"></td>
                        <td><div class="div-wraper-autocompleter"><input type="text" id="navigation_setting_add_display_status"></div></td>
                        <td><input type="text" id="navigation_setting_add_display_order"></td>
                        <td class="btnTd"><button type="button" class="registerNewBtn" onclick="{postNavigationSetting}">登録</button></td>
                        <td class="btnTd"><button type="button" class="hideNewWrap reset-btn" id="reset_navigation_add" onclick="{resetButtonAdd}"><i class="fa fa-times"></i>取消</button></td>
                      </tr>
                    </tfoot>
                  </table>
                  <div id="paging" class="text-center">
                    <ul class="pagination" id="pagination_navigation_setting"></ul>
                  </div>
                  <div class="btn-wrapper">
                    <button id="a02_redirect_navigation">ナビゲーション設定を更新</button>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="wrap_content" id="panel_second">
          <div class="users-wrapper">
            <div class="users-label">
              <label>開示対象メーカー設定</label>
              <label>その他の開示設定</label>
            </div>
            <div class="users-content">
              <div class="table-wrapper">
                <table>
                  <tr>
                      <th style="width:100px">コピー元法人：</th>
                      <td><div class="div-wraper-autocompleter"><input type="text" class="user_input" id="origin_users_comp_name"></div></td>
                  </tr>
                </table>
              </div>
              <div class="table-wrapper">
                <table>
                  <tr>
                      <th style="width:85px">設定先法人：</th>
                      <td><div class="div-wraper-autocompleter"><input type="text" class="user_input" id="des_users_comp_name"></div></td>
                  </tr>
                </table>
              </div>
            </div>
            <div class="btn-submit btn-users">
              <button type="button" class="submit" id="users-submit">更新</button>
            </div>
          </div>
          <div class="navigation-wrapper">
            <div class="navigation-label">
              <label>ナビゲーション設定</label>
            </div>
            <div class="navigation-content">
              <div class="table-wrapper">
                <table>
                  <tr>
                      <th style="width:100px">コピー元法人：</th>
                      <td><div class="div-wraper-autocompleter"><input type="text" class="navigation_input" id="origin_navigation_comp_name"></div></td>
                  </tr>
                </table>
              </div>
              <div class="table-wrapper">
                <table>
                  <tr>
                      <th style="width:85px">設定先法人：</th>
                      <td><div class="div-wraper-autocompleter"><input type="text" class="navigation_input" id="des_navigation_comp_name"></div></td>
                  </tr>
                </table>
              </div>
            </div>
            <div class="btn-submit">
              <button type="button" class="submit" id="navigations-submit">更新</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <script>
      var thisTag = this;
      this.list_companies_search = opts.companies_list;
      this.companiesList = [];
      this.navigation_setting = [];
      this.supplier_setting = [];
      this.other_setting = [];
      this.users_list = [];
      this.total_navigation_setting = 1;
      this.total_supplier_setting = 1;
      this.total_other_setting = 1;
      this.total_users_list = 1;
      this.page_navigation_setting = 1;
      this.page_supplier_setting = 1;
      this.page_other_setting = 1;
      this.page_users_list = 1;
      this.comp_code = '';
      this.control_field_value = '';
      this.current_page = 1;
      this.listOther = [
        {label:'list_price'},
        {label:'product_classify_id'}
      ];
      this.listOther_check = ['list_price','product_classify_id'];
      this.listPrice = [{label:'<>0'}];
      this.listPrice_check = ['<>0'];
      this.listProductClassifyId = [
        {code: 10 ,name: '臨床', label: '臨床'},
        {code: 20 ,name: '試薬', label: '試薬'},
        {code: 30 ,name: '機材', label: '機材'},
        {code: 40 ,name: '化成品', label: '化成品'},
        {code: 50 ,name: '消耗品', label: '消耗品'},
        {code: 60 ,name: '抗体', label: '抗体'},
        {code: 70 ,name: '受託', label: '受託'},
        {code: 99 ,name: 'その他または未設定', label: 'その他または未設定'}
      ];
      this.listProductClassifyId_check = ['臨床','試薬','機材','化成品','消耗品','抗体','受託','その他または未設定'];
      this.display_status = [
        {label:'Y'},
        {label:'N'}
      ];
      this.display_status_check = ['Y','N'];
      /* global $ */
      $(function(){
        // $('.addNewBtn').prop('disabled', true);
        $("#a02_redirect_navigation").hide();
        $("#a02_redirect_other").hide();
        $("#a02_redirect_supplier").hide();
        $("#a02_redirect_user").hide();
        var arrCompanies = [];
        $.each(thisTag.list_companies_search, function(index,element){
          arrCompanies.push({label:element});
        });

        $('#origin_users_comp_name').autocompleter({ limit:10000,highlightMatches:true, source: arrCompanies });
        $('#des_users_comp_name').autocompleter({ limit:10000,highlightMatches:true, source: arrCompanies });
        $('#origin_navigation_comp_name').autocompleter({ limit:10000,highlightMatches:true,  source: arrCompanies });
        $('#des_navigation_comp_name').autocompleter({ limit:10000,highlightMatches:true,  source: arrCompanies });
        $('#comp_name').autocompleter({ limit:10000,highlightMatches:true,  source: arrCompanies });
        $(".comp-name").hide();
        /* tab content*/
        $('.tab-child').on('click',function(){
          if(!$(this).hasClass('active')){
            $('.tab-child').removeClass('active');
            $(this).addClass('active');
            var panel = $(this).attr('data-panel');
            $('.wrap_content').removeClass('active');
            $('#' + panel).addClass('active');
          }
        })
        /* tab & panel */
        $('.tab').on('click',function(){
          if(!$(this).hasClass('active')){
            /*tab*/
            $('.tab').removeClass('active');
            $(this).addClass('active');
            /*panel*/
            var panel = $(this).attr('data-panel');
            $('.panel').removeClass('active');
            $('#' + panel).addClass('active');
          }
        });

        $("#user_tab").click(function(e){
            var page = 1;
            thisTag.page_users_list = 1;
            thisTag.getUsersList(page);
        });
        $("#supplier_tab").click(function(e){
            var page = 1;
            thisTag.page_supplier_setting = 1;
            thisTag.getSupplierSetting(page);
        });
        $("#other_tab").click(function(e){
            var page = 1;
            thisTag.page_other_setting = 1;
            thisTag.getOtherSetting(page);
        });
        $("#navigation_tab").click(function(e){
            var page = 1;
            thisTag.page_navigation_setting = 1;
            thisTag.getNavigationSetting(page);
        });
        thisTag.action();
        $("#users-submit").on('click',function(){
          thisTag.copyOtherSetting();
        });
        $("#navigations-submit").on('click',function(){
          thisTag.copyNavigationSetting();
        });
      });

      this.validateEmail = function(email) {      
        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return re.test(email);
      }
      
      this.validateID = function(id) {
        var re = /[\u3000-\u303F]|[\u3040-\u309F]|[\u30A0-\u30FF]|[\uFF00-\uFFEF]|[\u4E00-\u9FAF]|[\u2605-\u2606]|[\u2190-\u2195]|[\u203B]/;
        return re.test(id);
      }

      this.validateIDSpecialCharacters = function(id) {
        var re = /^[A-Za-z0-9!@#$%^&*()={}:;,."'¥`~<>?\|\+\_\-\[\]\/\\]*$/;
        return re.test(id);
      }

      this.validatePassword = function(pass) {
        var re = /^(?=.*$)^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$/;
        return re.test(pass);
      }
      
      this.validatePasswordSpecialCharacters = function(pass) {
        var re = /^(?=[A-Za-z0-9!@#$%^&*()={}:;,."'¥`~<>?\|\+\_\-\[\]\/\\]*$)^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$/;
        return re.test(pass);
      }
      this.resetButtonAdd = function(e){
        var classifiy = $(e.target).attr('id');
        var target = $(e.target).parents('td').siblings();
        switch(classifiy){
          case 'reset_navigation_add':
            $('#navigation_setting_add_navigation_id').val('');
            $('#navigation_setting_add_div').val('');
            $('#navigation_setting_add_name').val('');
            $('#navigation_setting_add_member_type').val('');
            $('#navigation_setting_add_member_authority').val('');
            $('#navigation_setting_add_display_contents').val('');
            $('#navigation_setting_add_display_status').val('');
            $('#navigation_setting_add_display_order').val('');
            break;
          case 'reset_other_add':
            $('#add_control_field_name_other').val('');
            $('#add_control_field_value_other').val('');
            break;
          case 'reset_supplier_add':
            $('#add_control_field_value').val('');
            $('#add_control_field_name').val('');
            break;
          case 'reset_user_add':
            $('#id_user').val('');
            $('#name_user').val('');
            $('#email_user').val('');
            $('#password_user').val('');
            break;
        }
      }
      
      this.resetButtonEdit = function(e){
        var target = $(e.target).parents('td').siblings();
        var index = target.find('input[type=hidden]').attr('index');
        var classifiy = target.find('input[type=hidden]').attr('class');
        switch(classifiy){
          case 'seq_navigation_setting':
            target.find('.navigation_display_contents_edit').val(thisTag.navigation_setting[index].display_contents);
            target.find('.navigation_display_status_edit').val(thisTag.navigation_setting[index].display_status);
            target.find('.navigation_display_order_edit').val(thisTag.navigation_setting[index].display_order);
            break;
          case 'seq_other_setting':
            target.find('.other_setting_edit_value').val(thisTag.other_setting[index].control_field_value);
            target.find('.other_setting_edit_name').val(thisTag.other_setting[index].control_field_name);
            break;
          case 'seq_supplier_setting':
            target.find('.supplier_setting_edit_value').val(thisTag.supplier_setting[index].control_field_value);
            target.find('.supplier_setting_edit_name').val(thisTag.supplier_setting[index].comp_name);
            break;
          case 'seq_user':
            target.find('.user_name_edit').val(thisTag.users_list[index].name);
            target.find('.user_email_edit').val(thisTag.users_list[index].email);
            target.find('.user_password_edit').val('');
            break;
        }
      }
      this.action = function(e){
        /*edit & register & remove & hide*/
        $('.editBtn').on('click',function(){
          var thisTr = $(this).parents('tr');
          thisTr.find('.display').hide();
          thisTr.find('.edit').show();
          thisTr.find('.supplier_setting_edit_comp_code_field_value').removeAttr( "disabled" );
        });
        // $('.registerBtn').on('click',function(){
        //   var thisTr = $(this).parents('tr');
        //   thisTr.find('.edit').hide();
        //   thisTr.find('.display').show();
        // });
        $('.hideBtn').on('click',function(){
          var thisTr = $(this).parents('tr');
          thisTr.find('.display').show();
          thisTr.find('.edit').hide();
          thisTr.find('.supplier_setting_edit_comp_code_field_value').attr( "disabled", "disabled" );
        });
        
        /*new data*/
        $('.addNewBtn').on('click',function(e){
          if($("#comp_name").val() == '' || thisTag.comp_code == ''){
            alert("法人名を選択してください。");
            e.stopPropagation();
            e.stopImmediatePropagation();
            return false;
          }
          var thisTable = $(this).parents('table');
          thisTable.find('.addNewWrap').show();
          thisTable.find('.edit').hide();
          thisTable.find('.display').show();
          $(this).attr('disabled',true);
        });
        // $('.registerNewBtn').on('click',function(){
        //   $(this).parents('.addNewWrap').hide();
        //   $(this).parents('table').find('.addNewBtn').attr('disabled',false);
        // });
        $('.hideNewWrap').on('click',function(){
          $(this).parents('.addNewWrap').hide();
          $(this).parents('table').find('.addNewBtn').attr('disabled',false);
          $(".input_create_user").val('');
        });
      }

      // ============================ Validation =========================
      this.checkExistNavigationId = function(e){
        var navigation_id = $("#navigation_setting_add_navigation_id").val();
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var querySuggest = [];
        querySuggest.push('token=' + accessTokenCognito);
        querySuggest.push('navigation_id=' + navigation_id);
        var url = URL_API + '/api/check_exist_navigation_id';
        url += '?' + querySuggest.join('&');
        
        $.ajax({
            url: url,
            type: 'GET',
            timeout: 60000,
            success: function (res) {
                var res = JSON.parse(res);
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                if(res.status == 'not_authorize'){
                    var url = "#";
                    $(location).attr("href", url );
                    return false;
                }
                if(res.boolean == false){
                    alert('ナビゲーションIDが存在していません。');
                    $("#navigation_setting_add_navigation_id").val('');
                    return false;
                }
            },
            error: function (xhr, stt, err) {
                alert('error');
            }
        });
      }
      // ================================================================= 
      this.deleteNavigationSetting = function(e){
        if(!confirm('削除します。よろしいですか？')){
          return false;
        } else{
          var tag = $(e.target).parents('td').siblings(); 

          var seq = tag.find(".seq_navigation_setting").val();
          var accessTokenCognito = localStorage.getItem('accessTokenCognito');
          var querySuggest = [];
          querySuggest.push('token=' + accessTokenCognito);
          var url = URL_API + '/api/a01/delete_navigation_setting';
          url += '?' + querySuggest.join('&');
          var data = {
              seq: seq
          };

          $.ajax({
              url: url,
              type: 'POST',
              data: {
                  data:data
              },
              timeout: 60000,
              success: function (res) {
                  if(res.status == 100){
                      riot.mount('app','maintain',{ messege:res.messege });
                      return false;
                  }
                  if(res.status == 'not_authorize'){
                      var url = "#";
                      $(location).attr("href", url );
                      return false;
                  }
                  if(res.messege == 'success'){
                      alert('削除しました。');
                      var page = 1;
                      var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                      thisTag.getNavigationSetting(page);
                  }
              },
              error: function (xhr, stt, err) {
                  alert('error');
              }
          });
        }
      }
      this.deleteSupplierSetting = function(e){
        if(!confirm('削除します。よろしいですか？')){
          return false;
        } else{
          var tag = $(e.target).parents('td').siblings(); 

          var seq = tag[0].children[1].value;
          var accessTokenCognito = localStorage.getItem('accessTokenCognito');
          var querySuggest = [];
          querySuggest.push('token=' + accessTokenCognito);
          var url = URL_API + '/api/a01/delete_supplier_setting';
          url += '?' + querySuggest.join('&');
          var data = {
              seq: seq
          };

          $.ajax({
              url: url,
              type: 'POST',
              data: {
                  data:data
              },
              timeout: 60000,
              success: function (res) {
                  if(res.status == 100){
                      riot.mount('app','maintain',{ messege:res.messege });
                      return false;
                  }
                  if(res.status == 'not_authorize'){
                      var url = "#";
                      $(location).attr("href", url );
                      return false;
                  }
                  if(res.messege == 'not_exist'){
                      return false;
                  }
                  if(res.messege == 'success'){
                      alert('削除しました。');
                      var page = 1;
                      var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                      thisTag.getSupplierSetting(page);
                  }
              },
              error: function (xhr, stt, err) {
                  alert('error');
              }
          });
        }
      }
      this.deleteOtherSetting = function(e){
        if(!confirm('削除します。よろしいですか？')){
          return false;
        } else{
          var tag = $(e.target).parents('td').siblings(); 

          var seq = tag[0].children[1].value;
          var accessTokenCognito = localStorage.getItem('accessTokenCognito');
          var querySuggest = [];
          querySuggest.push('token=' + accessTokenCognito);
          var url = URL_API + '/api/a01/delete_other_setting';
          url += '?' + querySuggest.join('&');
          var data = {
              seq: seq
          };

          $.ajax({
              url: url,
              type: 'POST',
              data: {
                  data:data
              },
              timeout: 60000,
              success: function (res) {
                  if(res.status == 100){
                      riot.mount('app','maintain',{ messege:res.messege });
                      return false;
                  }
                  if(res.status == 'not_authorize'){
                      var url = "#";
                      $(location).attr("href", url );
                      return false;
                  }
                  if(res.messege == 'success'){
                      alert('削除しました。');
                      var page = 1;
                      var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                      thisTag.getOtherSetting(page);
                  }
              },
              error: function (xhr, stt, err) {
                  alert('error');
              }
          });
        }
      }
      this.deleteUser = function(e){
        if(!confirm('削除します。よろしいですか？')){
          return false;
        } else{
          var tag = $(e.target).parents('td').siblings(); 

          var id_user = tag[0].children[1].value;
          var accessTokenCognito = localStorage.getItem('accessTokenCognito');
          var querySuggest = [];
          querySuggest.push('token=' + accessTokenCognito);
          var url = URL_API + '/api/a01/delete_user';
          url += '?' + querySuggest.join('&');
          var data = {
              id: id_user
          };

          $.ajax({
              url: url,
              type: 'POST',
              data: {
                  data:data
              },
              timeout: 60000,
              success: function (res) {
                  if(res.status == 100){
                      riot.mount('app','maintain',{ messege:res.messege });
                      return false;
                  }
                  if(res.status == 'not_authorize'){
                      var url = "#";
                      $(location).attr("href", url );
                      return false;
                  }
                  if(res.messege == 'success'){
                      alert('削除しました。');
                      var page = 1;
                      var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                      thisTag.getUsersList(page);
                  }
              },
              error: function (xhr, stt, err) {
                  alert('error');
              }
          });
        }
      }
      this.createUser = function(e){
        var id_user = $("#id_user").val();
        var name_user = $("#name_user").val();
        var email_user = $("#email_user").val();
        var password_user = $("#password_user").val();
        var member_authority_user = $("#member_authority_user").val();
        var err = [];
        if(id_user == ''){
          err.push('ユーザーIDの入力が必須です。\n');
        }
        if(id_user != ''){
          if(id_user.length > 255){
            err.push('ユーザーIDを255文字以内に入力してください。\n');
            $("#id_user").val('');
          }
          if (thisTag.validateID(id_user)) {
            err.push("ユーザーIDは半角英数字を利用してください。\n");
            $("#id_user").val('');
          }
          else {
            if (!thisTag.validateIDSpecialCharacters(id_user)) {
              err.push("ユーザーIDはASCII文字を利用してください。\n");
              $("#id_user").val('');
            }
          }
        } 
        if(name_user == ''){
          err.push('氏名の入力が必須です。\n');
        }
        if(name_user != ''){
          if(name_user.length > 255){
            err.push('氏名を255文字以内に入力してください。\n');
            $("#name_user").val('');
          }
        } 
        if(email_user == ''){
          err.push('メールの入力が必須です。\n');
        }
        
        if(email_user != ''){
          if(email_user.length > 255){
            err.push('メールを255文字以内に入力してください。\n');
            $("#email_user").val('');
          }
          if (!thisTag.validateEmail(email_user)){
            err.push('メールアドレスの形式ではありません。\n');
            $("#email_user").val('');
          } 
        } 
        if(password_user == ''){
          err.push('パスワードの入力が必須です。\n');
        }
        
        if(password_user != ''){
          if(password_user.length < 8 || password_user.length > 20){
            err.push('パスワードを最小文字数8文字～20文字まで入力してください。\n');
            $("#password_user").val('');
          } else if(!thisTag.validatePassword(password_user)){
            err.push("パスワードを大文字/小文字/数字から最低一個入力してください。\n");
            $("#password_user").val('');
          } else if(!thisTag.validatePasswordSpecialCharacters(password_user)){
            err.push("パスワードはASCII文字を利用してください。\n");
            $("#password_user").val('');
          }
        }

        if(id_user != '' && password_user != '') {
          if(id_user === password_user) {
            err.push('パスワードとログインIDは同じに入力できません。\n');
            $("#id_user").val('');
            $("#password_user").val('');
          }
        }
        
        if(err.length > 0){
          alert(err.join(''));
          return false;
        }

        var corporate = $(".comp-name dl:nth-child(2) dd").html();
        var member_type = '';
        switch(corporate){
            case '法人区分:メーカー':
                member_type = 3;
                break;
            case '法人区分:販売店':
                member_type = 2;
                break;
            case '法人区分:カスタマ':
                member_type = 1;
                break;
            default:
                break;
        }

        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var querySuggest = [];
        querySuggest.push('token=' + accessTokenCognito);
        var url = URL_API + '/api/a01/create_user';
        url += '?' + querySuggest.join('&');
        var data = {
            id:id_user,
            name:name_user,
            email:email_user,
            member_type:member_type,
            password:password_user,
            kikan_code:thisTag.comp_code,
            memberAuthority: member_authority_user,
            usedStatus: 0
        };
        $.ajax({
            url: url,
            type: 'POST',
            data: {
                data:data
            },
            timeout: 60000,
            success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                if(res.status == 'not_authorize'){
                    var url = "#";
                    $(location).attr("href", url );
                    return false;
                }
                if(res.messege == 'id_duplicate'){
                    $("#id_user").val('');
                    alert('入力されたユーザーIDは既に存在しています。');
                    return false;
                }
                if(res.messege == 'email_duplicate'){
                    $("#email_user").val('');
                    alert('入力されたメールは既に存在しています。');
                    return false;
                }
                if(res.messege == 'success'){
                    alert('追加しました。');
                    $(".input_create_user").val('');
                    var page = 1;
                    var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                    thisTag.getUsersList(page);
                    $(".hideNewWrap").parents('.addNewWrap').hide();
                    $(".hideNewWrap").parents('table').find('.addNewBtn').attr('disabled',false);
                }

            },
            error: function (xhr, stt, err) {
                alert('error');
            }
        });
      }
      this.editUser = function(e){
        var tag = $(e.target).parents('td').siblings(); 
        var index = tag.find('input[type=hidden]').attr('index');
        var id_user = tag.children(".id_user_edit").val();
        var name_user = tag.children(".user_name_edit").val();
        var email_user = tag.children(".user_email_edit").val();
        var old_email_user = tag.children(".user_old_email_edit").val();
        var password_user = tag.children(".user_password_edit").val();
        var member_authority_user = tag.children(".user_member_authority_edit").val();
        var member_type_user = tag.children(".user_member_type_edit").val();
        var err = [];

        if(id_user == ''){
          err.push('ユーザーIDの入力が必須です。\n');
        }
        if(id_user != ''){
          if(id_user.length > 255){
            err.push('ユーザーIDを255文字以内に入力してください。\n');
            tag[0].children[2].value = thisTag.users_list[index].id;
          }
          if (thisTag.validateID(id_user)) {
            err.push("ユーザーIDは半角英数字を利用してください。\n");
            $("#id_user").val('');
          }
          else {
            if (!thisTag.validateIDSpecialCharacters(id_user)) {
              err.push("ユーザーIDはASCII文字を利用してください。\n");
              $("#id_user").val('');
            }
          }
        } 
        if(name_user == ''){
          err.push('氏名の入力が必須です。\n');
        }
        if(name_user != ''){
          if(name_user.length > 255){
            err.push('氏名を255文字以内に入力してください。\n');
            tag[1].children[1].value = thisTag.users_list[index].name;
          }
        } 
        if(email_user == ''){
          err.push('メールの入力が必須です。\n');
        }
        
        if(email_user != ''){
          if(email_user.length > 255){
            err.push('メールを255文字以内に入力してください。\n');
            tag[2].children[1].value = thisTag.users_list[index].email;
          }
          if (!thisTag.validateEmail(email_user)){
            err.push('メールアドレスの形式ではありません。\n');
            tag[2].children[1].value = thisTag.users_list[index].email;
          } 
        } 
        
        if(password_user != ''){
          if(password_user.length < 8 || password_user.length > 20){
            err.push('パスワードを最小文字数8文字～20文字まで入力してください。\n');
            tag[3].children[1].value = '';
          } else if(!thisTag.validatePassword(password_user)){
            err.push("パスワードを大文字/小文字/数字から最低一個入力してください。\n");
            tag[3].children[1].value = '';
          } else if(!thisTag.validatePasswordSpecialCharacters(password_user)){
            err.push("パスワードはASCII文字を利用してください。\n");
            tag[3].children[1].value = '';
          }
        }

        if(id_user != '' && password_user != '') {
          if(id_user === password_user) {
            err.push('パスワードとログインIDは同じに入力できません。');
            tag[0].children[2].value = thisTag.users_list[index].id;
            tag[3].children[1].value = '';
          }
        }
        
        if(err.length > 0){
          alert(err.join(''));
          return false;
        }

        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var querySuggest = [];
        querySuggest.push('token=' + accessTokenCognito);
        var url = URL_API + '/api/a01/edit_user';
        url += '?' + querySuggest.join('&');
        var data = {
            id: id_user,
            name:name_user,
            email:email_user,
            old_email:old_email_user,
            password:password_user,
            member_authority: member_authority_user,
            member_type: member_type_user
        };

        $.ajax({
            url: url,
            type: 'POST',
            data: {
                data:data
            },
            timeout: 60000,
            success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                if(res.status == 'not_authorize'){
                    var url = "#";
                    $(location).attr("href", url );
                    return false;
                }
                if(res.messege == 'email_duplicate'){
                    tag[2].children[1].value = old_email_user;
                    alert('入力されたメールは既に存在しています');
                    return false;
                }
                if(res.messege == 'success'){
                    alert('編集しました。');
                    var page = 1;
                    var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                    thisTag.getUsersList(page);
                }
                // $(".comp-name dl:nth-child(1) dd").html(res.comp_name);
                

            },
            error: function (xhr, stt, err) {
                alert('error');
            }
        });
      } 
      this.postSupplierSetting = function(e){
        var target = e.target;
        if(target.classList.contains('edit')){
            if(!$(target).parents("td").parents("tr").find(".supplier_setting_edit_comp_code_field_value").prop("checked")){
                thisTag.deleteSupplierSetting(e);
                return false;
            } else {
                var control_field_value = $(target).parents("td").parents("tr").find(".supplier_setting_edit_value").val();
                var control_field_name = 'supplier_comp_code';
                var accessTokenCognito = localStorage.getItem('accessTokenCognito');
                var querySuggest = [];
                querySuggest.push('token=' + accessTokenCognito);
                var url = URL_API + '/api/a01/post_supplier_setting';
                url += '?' + querySuggest.join('&');
                var data = {
                    control_field_value: control_field_value,
                    control_field_name: control_field_name,
                    customer_co_cd: thisTag.comp_code,
                    customer_dep_cd: null
                };
            }
        }

        // if(!e.target.classList.contains('edit')){
        //   if($("#add_control_field_name").val() == ''){
        //       alert("法人名を選択してください。");
        //       return false;
        //   }
        //   if($("#add_control_field_value").val() == ''){
        //       alert("法人名を選択してください。");
        //       return false;
        //   }
        // }
        
        // var control_field_value = $("#add_control_field_value").val();
        // var control_field_name = 'supplier_comp_code';
        
        // var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        // var querySuggest = [];
        // querySuggest.push('token=' + accessTokenCognito);
        // var url = URL_API + '/api/a01/post_supplier_setting';
        // url += '?' + querySuggest.join('&');
        // var data = {
        //     control_field_value: control_field_value,
        //     control_field_name: control_field_name,
        //     customer_co_cd: thisTag.comp_code,
        //     customer_dep_cd: null
        // };

        // if(e.target.classList.contains('edit')){
        //     var tag = $(e.target).parents('td').siblings(); 
        //     var index = tag.find('input[type=hidden]').attr('index');
            
        //     var seq = tag[0].children[1].value;
        //     var control_field_value = tag[0].children[2].value;
            // var control_field_name = 'supplier_comp_code';
            
            // if(tag[1].children[1].children[0].value == ''){
            //   alert("法人名を選択してください。");
            //   tag[1].children[1].children[0].value = thisTag.supplier_setting[index].comp_name;
            //   return false;
            // }
        //     if(control_field_value == ''){
        //         alert("法人名を選択してください。");
        //         return false;
        //     }
        //     var data = {
        //         seq: seq,
        //         control_field_value: control_field_value
        //     };
        // } 
        $.ajax({
            url: url,
            type: 'POST',
            data: {
                data:data
            },
            timeout: 60000,
            success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }

                if(res.status == 'not_authorize'){
                    var url = "#";
                    $(location).attr("href", url );
                    return false;
                }
                if(res.messege == 'code_exist'){
                    alert('開示制御フィールド値が存在しています。');
                    $("#add_control_field_name").val('');
                    $("#add_control_field_value").val('');
                    return false;
                }
                if(res.messege == 'success'){
                    if(e.target.classList.contains('edit')){
                        alert('編集しました。 ');
                    } else {
                        alert('追加しました。');
                        $("#supplier_setting_edit_name").val('');
                        $("#supplier_setting_edit_value").val('');
                    }
                    var page = thisTag.page_supplier_setting;
                    thisTag.getSupplierSetting(page);
                }
            },
            error: function (xhr, stt, err) {
                alert('error');
            }
        });
      }
      this.postOtherSetting = function(e){
        var control_field_value = thisTag.control_field_value;
        var control_field_name = $("#add_control_field_name_other").val();

        if($("#add_control_field_name_other").val() == ''){
          alert("法人名を選択してください。");
          return false;
        }
        if($("#add_control_field_value_other").val() == ''){
          alert("法人名を選択してください。");
          return false;
        }
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var querySuggest = [];
        querySuggest.push('token=' + accessTokenCognito);
        var url = URL_API + '/api/a01/post_other_setting';
        url += '?' + querySuggest.join('&');
        var data = {
            control_field_value: control_field_value,
            control_field_name: control_field_name,
            customer_co_cd: thisTag.comp_code,
            customer_dep_cd: null
        };

        if(e.target.classList.contains('edit')){
            var tag = $(e.target).parents('td').siblings(); 
            var index = tag.find('input[type=hidden]').attr('index');

            var seq = tag[0].children[1].value;
            var control_field_value = tag[1].children[1].children[0].value;
            var control_field_name = tag[0].children[2].children[0].value;
            if(control_field_name == ''){
                alert("法人名を選択してください。");
                tag[0].children[2].children[0].value = thisTag.other_setting[index].control_field_name;
                return false;
            }
            if(control_field_value == ''){
                alert("法人名を選択してください。");
                tag[1].children[1].children[0].value = thisTag.other_setting[index].control_field_value
                return false;
            }
            var data = {
                seq: seq,
                control_field_value: control_field_value,
                control_field_name: control_field_name
            };
        } 

        $.ajax({
            url: url,
            type: 'POST',
            data: {
                data:data
            },
            timeout: 60000,
            success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                if(res.status == 'not_authorize'){
                    var url = "#";
                    $(location).attr("href", url );
                    return false;
                }
                if(res.messege == 'success'){
                    if(e.target.classList.contains('edit')){
                        alert('編集しました。 ');
                    } else {
                        alert('追加しました。');
                        $(".addNewWrap").hide();
                        $("#add_control_field_name_other").val('');
                        $("#add_control_field_value_other").val('');
                    }
                    var page = 1;
                    var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                    thisTag.getOtherSetting(page);
                }
            },
            error: function (xhr, stt, err) {
                alert('error');
            }
        });
      }
      
      this.postNavigationSetting = function(e){
        var navigation_id = $("#navigation_setting_add_navigation_id").val();
        var display_contents = $("#navigation_setting_add_display_contents").val();
        var display_status = $("#navigation_setting_add_display_status").val();
        var display_order = $("#navigation_setting_add_display_order").val();

        var err = [];
        if(!e.target.classList.contains('edit')){
            if(navigation_id == ''){
                err.push('ナビゲーションIDの入力が必須です。\n');
            }
            
            if(display_contents == ''){
                err.push('表示名の入力が必須です。\n');
            }
            
            if(display_status == ''){
                err.push('表示ステータスの入力が必須です。\n');
            }

            if(display_order == ''){
                err.push('表示順序の入力が必須です。\n');
            }

            if(err.length > 0){
              alert(err.join(''));
              return false;
            }
        }
        var accessTokenCognito = localStorage.getItem('accessTokenCognito');
        var querySuggest = [];
        querySuggest.push('token=' + accessTokenCognito);
        var url = URL_API + '/api/a01/post_navigation_setting';
        url += '?' + querySuggest.join('&');
        var data = {
            navigation_id: navigation_id,
            display_contents: display_contents,
            display_status: display_status,
            display_order: display_order,
            comp_code: thisTag.comp_code
        };

        if(e.target.classList.contains('edit')){
            var tag = $(e.target).parents('td').siblings(); 
            var index = tag.find('input[type=hidden]').attr('index');

            // var seq = tag[0].children[1].value;
            // var navigation_id = tag[0].children[2].value;
            // var display_contents = tag[5].children[1].value;
            // var display_status = tag[6].children[1].value;
            // var display_order = tag[7].children[1].value;

            var seq = tag.find(".seq_navigation_setting").val();
            var navigation_id = tag.find(".navigation_navigation_id_edit").val();
            var display_contents = tag.find(".navigation_display_contents_edit").val();
            var display_status = tag.find(".navigation_display_status_edit").val();
            var display_order = tag.find(".navigation_display_order_edit").val();     

            if(navigation_id == ''){
                err.push('ナビゲーションIDの入力が必須です。\n');
                tag.find(".navigation_navigation_id_edit").val(thisTag.navigation_setting[index].navigation_id);
            }
            
            if(display_contents == ''){
                err.push('表示名の入力が必須です。\n');
                tag.find(".navigation_display_contents_edit").val(thisTag.navigation_setting[index].display_contents);
            }
            
            if(display_status == ''){
                err.push('表示ステータスの入力が必須です。\n');
                tag.find(".navigation_display_status_edit").val(thisTag.navigation_setting[index].display_status);
            }

            if(display_order == ''){
                err.push('表示順序の入力が必須です。\n');
                tag.find(".navigation_display_order_edit").val(thisTag.navigation_setting[index].display_order);
            }

            if(err.length > 0){
              alert(err.join(''));
              return false;
            }
            var data = {
                seq: seq,
                navigation_id: navigation_id,
                display_contents: display_contents,
                display_status: display_status,
                display_order: display_order,
                comp_code: thisTag.comp_code
            };
        } 

        $.ajax({
            url: url,
            type: 'POST',
            data: {
                data:data
            },
            timeout: 60000,
            success: function (res) {
                if(res.status == 100){
                    riot.mount('app','maintain',{ messege:res.messege });
                    return false;
                }
                if(res.status == 'not_authorize'){
                    var url = "#";
                    $(location).attr("href", url );
                    return false;
                }

                if(res.messege == 'exist'){
                  if(e.target.classList.contains('edit')){
                        alert('ナビゲーションIDが存在しています。');
                        return false;
                    } else {
                        alert('ナビゲーションIDが存在しています。');
                        $("#navigation_setting_add_display_order").val('');
                        $("#navigation_setting_add_display_status").val('');
                        $("#navigation_setting_add_display_contents").val('');
                        $("#navigation_setting_add_navigation_id").val('');
                        return false;
                    }
                }
                if(res.messege == 'success'){
                    if(e.target.classList.contains('edit')){
                        alert('編集しました。 ');
                    } else {
                        alert('追加しました。');
                        $(".navigation_setting_add_navigation_id").val('');
                        $(".addNewWrap").hide();
                        $(".addNewBtn").attr('disabled',false);
                    }
                    var page = 1;
                    var page = $('#pagination_navigation_setting').find('li.active').find('a').text();
                    thisTag.getNavigationSetting(page);
                }
            },
            error: function (xhr, stt, err) {
                alert('error');
            }
        });
      }
      this.getNavigationSetting = function(page){
        if($("#comp_name").val() == ''){
            return false;
        }
        if($("#navigation_tab").hasClass('active')){
            var comp_name = $("#comp_name").val();
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var querySuggest = [];
            querySuggest.push('token=' + accessTokenCognito);
            querySuggest.push('comp_name=' + comp_name);
            querySuggest.push('page=' + page);
            var url = URL_API + '/api/a01/get_navigation_setting';
            url += '?' + querySuggest.join('&');
            $.ajax({
                url: url,
                type: 'GET',
                timeout: 60000,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.status == 'not_authorize'){
                        var url = "#";
                        $(location).attr("href", url );
                        return false;
                    }

                    
                    $("#a02_redirect_navigation").show();
                    $(".comp-name").show();
                    // $(".comp-name dl:nth-child(1) dd").html(res.comp_code + ' ' + res.comp_name);
                    // $(".comp-name dl:nth-child(2) dd").html(res.corporate);
                    thisTag.comp_code = res.comp_code;
                    thisTag.navigation_setting = res.navigation_setting.list;
                    thisTag.total_navigation_setting = res.navigation_setting.total;
                    
                    if(thisTag.total_navigation_setting === 0){
                      $("#a02_redirect_navigation").hide();
                    }
                    $.each(res.navigation_setting.list, function(i, val) {
                      val.member_authority = val.member_authority.replace('1', '一般ユーザー').replace('2', '法人管理者アカウント').replace('3', '部署管理者アカウント').replace('5', 'ゲストユーザー').replace('9', '管理者').replace(/\|/g, ', ');
                      val.div = val.div.replace('H', 'ヘッダー').replace('S', '画面').replace('B', 'ボタン').replace('F', 'フィールド');
                    });
                    thisTag.update(thisTag.navigation_setting);
                    thisTag.action();
                    thisTag.pagination('pagination_navigation_setting', page);
                    if(res.comp_code && res.comp_name){
                        $(".comp-name dl:nth-child(1) dd").html('法人名:' + res.comp_code + ' ' + res.comp_name);
                        $("#panel_2 button.editBtn").removeAttr("disabled");
                    } else {
                        $(".comp-name dl:nth-child(1) dd").html('');
                        $("#panel_2 button.editBtn").attr("disabled","disabled");
                    }
                    if(res.corporate){
                        $(".comp-name dl:nth-child(2) dd").html('法人区分:' + res.corporate);
                    } else {
                        $(".comp-name dl:nth-child(2) dd").html('');
                    }
                    $('.navigation_display_status_edit').autocompleter({ limit:10000,highlightMatches:true,  source: thisTag.display_status });
                    $('#navigation_setting_add_display_status').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.display_status });
                },
                error: function (xhr, stt, err) {
                    alert('error');
                }
            });
        }
        
      }
      this.getSupplierSetting = function(page){
        if($("#comp_name").val() == ''){
            return false;
        }
        if($("#supplier_tab").hasClass('active')){
            var comp_name = $("#comp_name").val();
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var querySuggest = [];
            querySuggest.push('token=' + accessTokenCognito);
            querySuggest.push('comp_name=' + comp_name);
            querySuggest.push('page=' + thisTag.page_supplier_setting);
            
            var url = URL_API + '/api/a01/get_supplier_setting';
            url += '?' + querySuggest.join('&');
            $.ajax({
                url: url,
                type: 'GET',
                timeout: 60000,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.status == 'not_authorize'){
                        var url = "#";
                        $(location).attr("href", url );
                        return false;
                    }
                    $("#a02_redirect_supplier").show();
                    $(".comp-name").show();

                    
                    
                    thisTag.comp_code = res.comp_code;
                    thisTag.supplier_setting = res.supplier_setting.list;
                    thisTag.total_supplier_setting = res.supplier_setting.total;
                    thisTag.companiesList = res.comp_list;
                    // if(thisTag.total_supplier_setting > 0){
                    //   $('.addNewBtn').prop('disabled', false);
                    // }
                    if(thisTag.total_supplier_setting === 0){
                      $("#a02_redirect_supplier").hide();
                    }
                    thisTag.update(thisTag.supplier_setting);
                    thisTag.action();
                    thisTag.pagination('pagination_supplier_setting', page);

                    if(res.comp_code && res.comp_name){
                        $(".comp-name dl:nth-child(1) dd").html('法人名:' + res.comp_code + ' ' + res.comp_name);
                        $("#panel_2 button.editBtn").removeAttr("disabled");
                    } else {
                        $(".comp-name dl:nth-child(1) dd").html('');
                        $("#panel_2 button.editBtn").attr("disabled","disabled");
                    }
                    if(res.corporate){
                        $(".comp-name dl:nth-child(2) dd").html('法人区分:' + res.corporate);
                    } else {
                        $(".comp-name dl:nth-child(2) dd").html('');
                    }
                    $('.supplier_setting_edit_name').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.companiesList });
                    $('.supplier_setting_edit_name').on('change',function(e){
                        var value = $(this).val();

                        if(value != ''){
                            var comp_code = '';
                            $.each(thisTag.companiesList, function(index, element){
                                if(element['comp_name'] == value){
                                    comp_code = element['comp_code'];
                                    return false;
                                }
                            });
                            $(this).parents('div').parents('td').siblings().find(".supplier_setting_edit_value")[0].value = comp_code;

                        }

                    });
                    $('#add_control_field_name').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.companiesList });
                    $('#add_control_field_name').on('change',function(e){
                        var value = $(this).val();

                        if(value != ''){
                            var comp_code = '';
                            $.each(thisTag.companiesList, function(index, element){
                                if(element['comp_name'] == value){
                                    comp_code = element['comp_code'];
                                    return false;
                                }
                            });
                            
                            $('#add_control_field_value').val(comp_code);
                        }

                    });
                },
                error: function (xhr, stt, err) {
                    alert('error');
                }
            });
        }
        
      }
      this.getOtherSetting = function(page){
        if($("#comp_name").val() == ''){
            return false;
        }

        if($("#other_tab").hasClass('active')){
            var comp_name = $("#comp_name").val();
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var querySuggest = [];
            querySuggest.push('token=' + accessTokenCognito);
            querySuggest.push('comp_name=' + comp_name);
            querySuggest.push('page=' + page);
            
            var url = URL_API + '/api/a01/get_other_setting';
            url += '?' + querySuggest.join('&');
            $.ajax({
                url: url,
                type: 'GET',
                timeout: 60000,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.status == 'not_authorize'){
                        var url = "#";
                        $(location).attr("href", url );
                        return false;
                    }
                    
                    $("#a02_redirect_other").show();
                    $(".comp-name").show();
                    // $(".comp-name dl:nth-child(1) dd").html('法人名:' + res.comp_code + ' ' + res.comp_name);
                    // $(".comp-name dl:nth-child(2) dd").html('法人区分:' + res.corporate);
                    thisTag.comp_code = res.comp_code;
                    thisTag.other_setting = res.other_setting.list;
                    thisTag.total_other_setting = res.other_setting.total;
                    // if(thisTag.total_other_setting > 0){
                    //   $('.addNewBtn').prop('disabled', false);
                    // }
                    if(thisTag.total_other_setting === 0){
                      $("#a02_redirect_other").hide();
                    }
                    thisTag.update(thisTag.other_setting);
                    thisTag.action();
                    thisTag.pagination('pagination_other_setting', page);
                    if(res.comp_code && res.comp_name){
                        $(".comp-name dl:nth-child(1) dd").html('法人名:' + res.comp_code + ' ' + res.comp_name);
                        $("#panel_2 button.editBtn").removeAttr("disabled");
                    } else {
                        $(".comp-name dl:nth-child(1) dd").html('');
                        $("#panel_2 button.editBtn").attr("disabled","disabled");
                    }
                    if(res.corporate){
                        $(".comp-name dl:nth-child(2) dd").html('法人区分:' + res.corporate);
                    } else {
                        $(".comp-name dl:nth-child(2) dd").html('');
                    }
                    // ============ add ==============
                    $('#add_control_field_name_other').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listOther });

                    switch($('#add_control_field_name_other').val()){
                        case 'list_price':
                            $('#add_control_field_value_other').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listPrice });
                            break;
                        case 'product_classify_id':
                            $('#add_control_field_value_other').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listProductClassifyId });
                            break;
                    }
                    $('#add_control_field_name_other').on('change',function(e){
                        var value = $(this).val();
                        switch(value){
                            case 'list_price':
                                $('#add_control_field_value_other').autocompleter('destroy');
                                $('#add_control_field_value_other').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listPrice });
                                break;
                            case 'product_classify_id':
                                $('#add_control_field_value_other').autocompleter('destroy');
                                $('#add_control_field_value_other').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listProductClassifyId });
                                break;
                        }
                    });
                    $('#add_control_field_value_other').on('change',function(e){
                        var value = $(this).val();
                        if(value != ''){
                            var control_field_value = value;
                            $.each(thisTag.listProductClassifyId, function(index, element){
                                if(element['name'] == value){
                                    control_field_value = element['code'];
                                    return false;
                                }
                            });
                            
                            thisTag.control_field_value = control_field_value;
                        }
                    });
                    //============ edit =============
                    $('.other_setting_edit_name').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listOther });
                    switch($('.other_setting_edit_name').val()){
                        case 'list_price':
                            $('.other_setting_edit_value').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listPrice });
                            break;
                        case 'product_classify_id':
                            $('.other_setting_edit_value').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listProductClassifyId });
                            break;
                    }
                    $('.other_setting_edit_name').on('change',function(e){
                        var value = $(this).val();
                        switch(value){
                            case 'list_price':
                                $('.other_setting_edit_value').autocompleter('destroy');
                                $('.other_setting_edit_value').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listPrice });
                                break;
                            case 'product_classify_id':
                                $('.other_setting_edit_value').autocompleter('destroy');
                                $('.other_setting_edit_value').autocompleter({ limit:10000,highlightMatches:true, source: thisTag.listProductClassifyId });
                                break;
                        }
                    });
                    $('.other_setting_edit_value').on('change',function(e){
                        var value = $(this).val();
                        if(value != ''){
                            var control_field_value = value;
                            $.each(thisTag.listProductClassifyId, function(index, element){
                                if(element['name'] == value){
                                    control_field_value = element['code'];
                                    return false;
                                }
                            });
                            
                            thisTag.control_field_value = control_field_value;
                        }
                    });
                },
                error: function (xhr, stt, err) {
                    alert('error');
                }
            });
        }
        
      }
      this.getUsersList = function(page){
        if($("#comp_name").val() == ''){
            return false;
        }

        if($("#user_tab").hasClass('active')){
            var page = thisTag.page_users_list;
            var comp_name = $("#comp_name").val();
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var querySuggest = [];
            querySuggest.push('token=' + accessTokenCognito);
            querySuggest.push('comp_name=' + comp_name);
            querySuggest.push('page=' + page);
            var url = URL_API + '/api/a01/get_users_list';
            url += '?' + querySuggest.join('&');
            $.ajax({
                url: url,
                type: 'GET',
                timeout: 60000,
                success: function (res) {
                    if(res.status == 100){
                        riot.mount('app','maintain',{ messege:res.messege });
                        return false;
                    }
                    if(res.status == 'not_authorize'){
                        var url = "#";
                        $(location).attr("href", url );
                        return false;
                    }
                    $("#a02_redirect_user").show();
                    $(".comp-name").show();
                    // $(".comp-name dl:nth-child(1) dd").html('法人名:' + res.comp_code + ' ' + res.comp_name);
                    // $(".comp-name dl:nth-child(2) dd").html('法人区分:' + res.corporate);
                    thisTag.comp_code = res.comp_code;
                    thisTag.users_list = res.users_list.list;
                    thisTag.total_users_list = res.users_list.total;
                    // if(thisTag.total_users_list > 0){
                    //   $('.addNewBtn').prop('disabled', false);
                    // }
                    if(thisTag.total_users_list === 0){
                      $("#a02_redirect_user").hide();
                    }
                    thisTag.update(thisTag.users_list);
                    thisTag.action();
                    thisTag.pagination('pagination_users_list', page);
                    if(res.comp_code && res.comp_name){
                        $(".comp-name dl:nth-child(1) dd").html('法人名:' + res.comp_code + ' ' + res.comp_name);
                        $("#panel_2 button.editBtn").removeAttr("disabled");
                    } else {
                        $(".comp-name dl:nth-child(1) dd").html('');
                        $("#panel_2 button.editBtn").attr("disabled","disabled");
                    }
                    if(res.corporate){
                        $(".comp-name dl:nth-child(2) dd").html('法人区分:' + res.corporate);
                    } else {
                        $(".comp-name dl:nth-child(2) dd").html('');
                    }
                },
                error: function (xhr, stt, err) {
                    alert('error');
                }
            });
        }
        
      }
      this.pagination = function(tab_pagination, page){
        var total = 1;
        var currentPage = page;
        switch(tab_pagination){
            case 'pagination_navigation_setting':
                total = thisTag.total_navigation_setting;
                currentPage = thisTag.page_navigation_setting;
                break;
            case 'pagination_supplier_setting':
                total = thisTag.total_supplier_setting;
                currentPage = thisTag.page_supplier_setting;
                break;
            case 'pagination_other_setting':
                total = thisTag.total_other_setting;
                currentPage = thisTag.page_other_setting;
                break;
            case 'pagination_users_list':
                total = thisTag.total_users_list;
                currentPage = thisTag.page_users_list;
                break;
            default:
                break;
        }  
        var totalPages = Math.ceil(total/LIMIT_ON_PAGE);
        var visiblePages = 1;
        if(totalPages != 0){
            visiblePages =  5;
        }
        var $pagination = $('#' + tab_pagination);
        $pagination.twbsPagination('destroy');
        $pagination.twbsPagination({
            totalPages: totalPages,
            visiblePages: visiblePages,
            startPage: currentPage,
            initiateStartPageClick: false,
            onPageClick: function (event, page) {
                switch(tab_pagination){
                    case 'pagination_navigation_setting':
                        thisTag.page_navigation_setting = page;
                        thisTag.getNavigationSetting(page);
                        break;
                    case 'pagination_supplier_setting':
                        thisTag.page_supplier_setting = page;
                        thisTag.getSupplierSetting(page);
                        break;
                    case 'pagination_other_setting':
                        thisTag.page_other_setting = page;
                        thisTag.getOtherSetting(page);
                        break;
                    case 'pagination_users_list':
                        thisTag.page_users_list = page;
                        thisTag.getUsersList(page);
                        break;
                    default:
                        break;
                }
                
            }
        });
      }
      this.searchList = function(page){
        $("#user_tab").trigger("click");
      }
      this.copyOtherSetting = function(e) {
        if($("#second_tab").hasClass('active')){
          var user_input = $('.user_input');
          var user_value_check = new Array();
          var error = true;
          $.each(user_input, function(i, val) {
            var input_value = $(val).val();
            if(input_value == '') {
              error = false;
            }
            else {
              user_value_check.push(input_value);
            }
          });
          if(user_value_check.length == 0) {
            error = true;
          }

          if(!error) {
            alert('法人名を選択してください。');
            return false;
          }
          else if(error && user_value_check.length > 1) {
            var origin_comp_cd = $('#origin_users_comp_name').val();
            origin_comp_cd = origin_comp_cd.split(" ")[0];
            var des_comp_cd = $('#des_users_comp_name').val();
            des_comp_cd = des_comp_cd.split(" ")[0];
            if(origin_comp_cd == des_comp_cd) {
              alert('コピー元法人と違う設定先法人を選択してください。');
              return false;
            }
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var querySuggest = [];
            querySuggest.push('token=' + accessTokenCognito);
            var url = URL_API + '/api/a01/copy_other_setting';
            url += '?' + querySuggest.join('&');
            var data = {
              origin_comp_cd: origin_comp_cd,
              des_comp_cd: des_comp_cd
            };
            $.ajax({
                url: url,
                type: 'POST',
                data: {
                  data: data
                },
                success: function (res) {
                  if(res.messege == 'users_empty'){
                    alert('選択された法人の設定はありません。');
                    return false;
                  }
                  if(res.message == 'success') {
                    $('.user_input').val('');
                    alert('設定先法人が更新されました。');
                  }
                },
                error: function (xhr, stt, err) {
                    alert('error');
                }
            });
          }
        }
      }
      this.copyNavigationSetting = function(e) {
        if($("#second_tab").hasClass('active')){
          var navigation_input = $('.navigation_input');
          var navigation_value_check = new Array();
          var error = true;
          $.each(navigation_input, function(i, val) {
            var input_value = $(val).val();
            if(input_value == '') {
              error = false;
            }
            else {
              navigation_value_check.push(input_value);
            }
          });
          if(navigation_value_check.length == 0) {
            error = true;
          }

          if(!error) {
            alert('法人名を選択してください。');
            return false;
          }
          else if(error && navigation_value_check.length > 1) {
            var origin_comp_cd = $('#origin_navigation_comp_name').val();
            origin_comp_cd = origin_comp_cd.split(" ")[0];
            var des_comp_cd = $('#des_navigation_comp_name').val();
            des_comp_cd = des_comp_cd.split(" ")[0];
            if(origin_comp_cd == des_comp_cd) {
              alert('コピー元法人と違う設定先法人を選択してください。');
              return false;
            }
            var accessTokenCognito = localStorage.getItem('accessTokenCognito');
            var querySuggest = [];
            querySuggest.push('token=' + accessTokenCognito);
            var url = URL_API + '/api/a01/copy_navigation_setting';
            url += '?' + querySuggest.join('&');
            var data = {
              origin_comp_cd: origin_comp_cd,
              des_comp_cd: des_comp_cd
            };
            $.ajax({
                url: url,
                type: 'POST',
                data: {
                  data: data
                },
                success: function (res) {
                  if(res.messege == 'navigations_empty'){
                    alert('選択された法人の設定はありません。');
                    return false;
                  }
                  if(res.message == 'success') {
                    $('.navigation_input').val('');
                    alert('設定先法人が更新されました。');
                  }
                },
                error: function (xhr, stt, err) {
                    alert('error');
                }
            });
          }
        }
      }
    </script>
</a01>
