<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head th:fragment="head">
        <meta charset="utf-8"/>
        <title>
            [[${(title!=null?title:'后台管理') + ' - Doghouse'}]]
        </title>
        <link rel="shortcut icon" th:href="@{/favicon.ico}" />
        <meta name="renderer" content="webkit"/>
        <meta name="base" th:content="@{/}"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
        <link rel="stylesheet" th:href="@{/admin/layuiadmin/layui/css/layui.css}" media="all"/>
        <link rel="stylesheet" th:href="@{/admin/layuiadmin/style/login.css}" media="all"/>
        <link rel="stylesheet" th:href="@{/admin/css/admin.css}" media="all"/>
        <link rel="stylesheet" th:href="@{/blog/plugins/fa5/css/all.min.css}" media="all"/>
    </head>
    
    <body style="background-color: #f2f2f2">
    <div th:fragment="nav">
        <ul class="doghouse-admin-nav layui-nav" style="display:table;width:100%">
          <li class="layui-nav-item">
            <a href="#">控制台</a>
            <dl class="layui-nav-child">
              <dd><a th:href="@{/admin/v2/index}">概要</a></dd>
              <dd><a href="#">个人设置</a></dd>
              <dd><a href="#">插件</a></dd>
              <dd><a th:href="@{/admin/v2/themes}">主题</a></dd>
              <dd><a href="#">备份</a></dd>
            </dl>
            </li>
          <li class="layui-nav-item">
            <a href="javascript:;">管理</a>
            <dl class="layui-nav-child">
              <dd><a th:href="@{/admin/v2/post/}">文章</a></dd>
              <dd><a th:href="@{/admin/v2/page}">页面</a></dd>
              <dd><a th:href="@{/admin/v2/wiki}">Wiki</a></dd>
              <dd><a th:href="@{/admin/v2/tweet}">说说</a></dd>
              <dd><a th:href="@{/admin/v2/comment}">评论</a></dd>
              <dd><a th:href="@{/admin/v2/tag}">标签</a></dd>
              <dd><a th:href="@{/admin/v2/category}">分类</a></dd>
              <dd><a th:href="@{/admin/v2/asset}">文件</a></dd>
              <dd><a th:href="@{/admin/v2/link}">友链</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item">
            <a href="javascript:;">设置</a>
            <dl class="layui-nav-child">
              <dd><a th:href="@{/admin/v2/config/site}">站点</a></dd>
              <dd><a th:href="@{/admin/v2/config/wiki}">Wiki</a></dd>
              <dd><a th:href="@{/admin/v2/config/tweet}">说说</a></dd>
              <dd><a th:href="@{/admin/v2/config/comment}">评论</a></dd>
              <dd><a th:href="@{/admin/v2/config/mail}">邮件</a></dd>
              <dd><a th:href="@{/admin/v2/config/network}">网络</a></dd>
            </dl>
          </li>
          <li class="layui-nav-item" style="float:right;right: 2px;" lay-unselect="">
            <a href="javascript:;">
                <img id="adminUserGravatar" loading="lazy" referrerpolicy="same-origin" th:src="${session.loginUser.getAvatarUrl()}" class="layui-nav-img"/>
                <span id="adminUserNickname">[[${session.loginUser.nickname}]]</span>
            </a>
            <dl class="layui-nav-child">
              <dd><a href="#" class="change-user-info">修改信息</a></dd>
              <dd><a th:href="@{/admin/v2/logout}">退出登录</a></dd>
            </dl>
          </li>
          <li th:if="${@tweetConfig.tweetMode}" class="layui-nav-item" style="float:right">
            <a th:href="@{/tweet/}">说说</a>
          </li>
          <li th:if="${@wikiConfig.wikiMode}" class="layui-nav-item" style="float:right">
            <a th:href="@{/wiki/}">Wiki</a>
          </li>
          <li class="layui-nav-item" style="float:right">
            <a th:href="@{/}">Blog</a>
          </li>
        </ul>
        <script type="text/html" id="editUser">
            <div class="layui-form" style="margin:10px 15px" id="editUserForm" lay-filter="editUserForm">
                <div class="layui-form-item">
                    <input type="hidden" name="id"/>
                    <label class="layui-form-label">用户昵称<span>*</span></label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" name="nickname" placeholder="" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">邮箱<span>*</span></label>
                    <div class="layui-input-block">
                        <input type="text" lay-verify="required" name="email" placeholder="" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站</label>
                    <div class="layui-input-block">
                        <input type="text" name="site" placeholder="" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item" id="old-pass">
                    <label class="layui-form-label">旧密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="password" placeholder="" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
                <div class="layui-form-item" id="new-pass">
                    <label class="layui-form-label">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="newPassword" placeholder="" autocomplete="off" class="layui-input"/>
                    </div>
                </div>
                <div style="display:none" class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="*" lay-filter="editUser">提交</button>
                    </div>
                </div>
            </div>
        </script>
        </div>
        <th:block th:fragment="head-script">
        <script th:src="@{/admin/layuiadmin/layui/layui.js}"></script>
        <script th:src="@{/blog/plugins/jquery/1.12.4/jquery-1.12.4.min.js}"></script>
        <script th:src="@{/blog/plugins/js-sha3/sha3.min.js}"></script>
        <script th:src="@{/admin/js/admin.js}"></script>
            <script>
            layui.use(['element', 'form', 'layer'], function(){
                  var element = layui.element, form = layui.form, layer = layui.layer;
                  element.on('nav(demo)', function(elem){
                    layer.msg(elem.text());
                  });
                  $('.change-user-info').on('click', function(e){
                	  e.preventDefault();
                	  
                	  $.ajax({
                		  url: '/admin/v2/getCurrentUserInfo',
                		  success: function (r) {
                              layui.layer.open({
                                  type: 1,
                                  title: '修改用户',
                                  btn: ['提交', '关闭'],
                                  yes: function(index, layero) {
                                      layero.find('[lay-filter="editUser"]').click();
                                  },
                                  area: ['500px', '450px'],
                                  content: $('#editUser').html(),
                                  success: function (layero, layerIndex) {
                                      var el = $(layero), o = el.find('#old-pass'), n = el.find('#new-pass');
                                      el.find('[name="nickname"]').val(r.data.nickname);
                                      el.find('[name="email"]').val(r.data.email);
                                      el.find('[name="site"]').val(r.data.site);
                                      el.on('input propertychange', '#new-pass input', function (){
                                          var that = $(this);
                                          if (that.val()) {
                                              if(!o.find('.layui-form-label span').length){
                                                  o.find('.layui-form-label').append('<span>*</span>');
                                                  o.find('input').attr('lay-verify', 'required');
                                                  n.find('.layui-form-label').append('<span>*</span>');
                                                  n.find('input').attr('lay-verify', 'required');
                                              }
                                          }
                                          else {
                                              o.find('.layui-form-label span').remove();
                                              o.find('input').removeAttr('lay-verify');
                                              n.find('.layui-form-label span').remove();
                                              n.find('input').removeAttr('lay-verify');
                                          }
                                      });
                                      layui.form.on('submit(editUser)', function (data) {
                                          if (data.field.password && data.field.newPassword) {
                                              data.field['password'] = sha3_224(data.field.password);
                                              data.field['newPassword'] = sha3_224(data.field.newPassword);
                                          }
                                          $.ajax({
                                              url: '/admin/v2/setCurrentUserInfo',
                                              method: 'POST',
                                              data: data.field,
                                              success: function (r) {
                                                  layui.layer.close(layerIndex);
                                                  layer.msg('修改用户信息成功', {
                                                      offset: '15px',
                                                      icon: 1,
                                                      time: 1000
                                                  });
                                                  $('#adminUserNickname').text(r.data.nickname);
                                                  $('#adminUserGravatar').attr('src', r.data.avatarUrl);
                                              },
                                              error: function (res) {
                                                  var r = res.responseJSON;
                                                  layer.msg(r && r.data||'服务器错误', {
                                                      offset: '15px',
                                                      icon: 2,
                                                      time: 2000
                                                  });
                                              }
                                          })
                                      });
                                      layui.form.render();
                                  }
                              });
                		  },
                		  error: function (xhr) {
                              var r = xhr.responseJSON;
                              layer.msg(r && r.data||'服务器错误', {
                                  offset: '15px',
                                  icon: 2,
                                  time: 2000
                              });
                		  }
                	    
                	  })
                  })
            });
            /*$(function(){
            	$(window).on('resize')
            })*/
            </script>
        </th:block>
        <div th:fragment="feet" class="layui-trans layadmin-user-login-footer">
            由 Doghouse 全力驱动<br/>
            &copy;2016-[[${#temporals.format(T(java.time.LocalDate).now(),'yyyy')}]]
            <a href="https://smileat.me/" target="_blank">Doghole</a>
            All Rights Reserved.
        </div>
    </body>

</html>