<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>
<link rel="stylesheet" href="${contextPath}/static/assets/css/jquery-ui.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/datepicker.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/ui.jqgrid.css" />

<div class="row">
    <div class="col-xs-12">
        <table id="grid-table">

        </table>

        <div id="grid-pager"></div>

        <script type="text/javascript">
            var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
        </script>

    </div>
</div>
<!-- 模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" onclick="close1()" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>

        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script type="text/javascript">

    var myGrid = null;
    var scripts = [ null,  "${contextPath}/static/assets/js/date-time/bootstrap-datepicker.js",
        "${contextPath}/static/assets/js/date-time/locales/bootstrap-datepicker.zh-CN.js",
        "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js",
        "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js", null ]
    $('.page-content-area').ace_ajax('loadScripts', scripts, function() {
        jQuery(function ($) {
            var grid_selector = "#grid-table";
            var pager_selector = "#grid-pager";
            myGrid=	jQuery(grid_selector).jqGrid({
                subGrid : false,
                url : "${contextPath}/lszp/Job/lszpJobDetails?id=${id}",
                datatype : "json",
                mtype:'POST',
                height:'100%',
                width:'auto',
                colNames : [ '创建时间', '消息', '应聘者名字', '应聘者电话', '应聘岗位', '详情'],
                colModel : [  {
                    name : 'createDate',
                    index : 'createDate',
                    width : 300,
                    sortable : true,
                    editable : false,
                }, {
                    name : 'message',
                    index : 'message',
                    width : 300,
                    editable : false,

                }, {
                    name : 'realName',
                    index : 'realName',
                    width : 300,
                    editable : false,
                    search : false
                }, {
                    name : 'phone',
                    index : 'phone',
                    width : 200,
                    editable : true,
                }, {
                    name : 'post',
                    index : 'post',
                    width : 200,
                    editable : false,
                    search : false
                }, {
                        name : 'type',
                        index : 'type',
                        label : '详情',
                        width : 100,
                        editable : false,
                        search : false,
                        sortable : false,
                        fixed:true,
                        formatter : optionFormatter
                    }

                ],
                sortname : "createDate",
                sortorder : "desc",
                viewrecords : true,
                rowNum : 30,
                rowList : [ 10, 20, 30 ],
                pager : pager_selector,
                altRows : true,
                multiselect: true,
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            function updatePagerIcons(table) {
                var replacement = {
                    'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
                    'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
                    'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
                    'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
                };
                $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function() {
                    var icon = $(this);
                    var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
                    if ($class in replacement)
                        icon.attr('class', 'ui-icon ' + replacement[$class]);
                })
            }

            function enableTooltips(table) {
                $('.navtable .ui-pg-button').tooltip({
                    container : 'body'
                });
                $(table).find('.ui-pg-div').tooltip({
                    container : 'body'
                });
            };


            function optionFormatter(cellvalue, options, cell) {
                var topic=cell.topic;
                console.log(topic);
                var template ="<button class=\"btn btn-primary btn-lg\" data-toggle=\"modal\" " +
                    "onclick='showModal(\""+topic+"\")'>聊天记录</button>\n"
                return template;


            };

        });
    });
    function showModal(topic) {
        $('#myModal').modal('show')
        $.ajax({
            type:"post",
            url:"${contextPath}/lszp/Job/lszpJobDialogue",
            data:{
                "topic":topic
            },
            dataType:"json",
            success:function(retMsg){
                var zz = $(".modal-header")
                for(var i=0;i<retMsg.length;i++){
                    zz.append("<p class='createP'>"+retMsg[i]+"</p>")
                }
            }
        })
    }
    function close1() {
        console.log("111")
        var zz = $(".createP");
        zz.remove();
    }
</script>