/**
 * Created by zhenglishan on 2017/10/25.
 */

//初始化summernot
$(function () {
    $("#summernote-content-top").summernote({
        height: 300,
        minHeight: 200,
        maxHeight: 400,
        toolbar:[]
    });
});
//
function getNoReadMessage(userId){
    $("#dropdown-messages-wrapper-ul").empty();
    $.ajax({
        url:"ucMessage/getMessage",
        data:{id:userId},
        dataType:"json",
        success:function (data) {
            var oArr="";
            var count=0;
            $("#warning-num").html(data.length);
            $.each(data, function (i, obj) {
                if(count>2) return false;
                if(obj.isRead==0 ){
                    oArr += "<li><div onclick='showMessageDialog(\""+obj.id+"\",\""+userId+"\")'><div class='media-body'><strong >"
                        +obj.title+
                        "</strong><br><small class='text-muted'>"
                        +obj.publicDate+
                        "</small></div></div></li><li class='divider'></li><li>";
                    count++;
                }
            });
            $("#dropdown-messages-wrapper-ul").append(oArr);
            $("#dropdown-messages-wrapper-ul").append("<li><div class='text-center link-block'><a href='/ucMessage'><i class='fa fa-envelope'></i><strong>读取所有消息</strong></a></div></li>");
        }
    } );
}
//dialog显示消息详情
function showMessageDialog(msgId,userId){
    // alert("tanchuang");
    $("#dialogMessage").find("form")[0].reset();
    if(msgId){
        $.ajax({
            url: "ucMessage/getDialogMessage",
            data: {msgId: msgId},
            dataType : "json",
            success : function(data){
                //alert("aaaa");
                data.userPass = "";
                $("#dialogMessage").modal('show');
                $("#dialogMessage").find("form").setForm(data);
                $("#summernote-content-top").code(data.content);
                $.ajax({
                    url: "ucMessage/updateMessageAndUserStatus",
                    data: {userId:userId,msgId: msgId},
                    dataType : "json",
                    success : function(data){

                    }
                });
            }
        });
    }
}
