pushMessageList.js 4.36 KB
Newer Older
1
/**
NGO THI HONG committed
2
 * Push Message List JS in pushMessageList.html
3 4
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
 */
5
var PushMessageList = {};
Kang Donghun committed
6
PushMessageList.baseApiUrl = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.PUSH_MESSAGE_LIST;
7

8
/**
9
 * Init when html onload
10
 */
11 12
PushMessageList.init = function () {
    //Check if user is logged in
13
    COMMON.showLoading();
14
    COMMON.checkAuth(false);
Kang Donghun committed
15
    TEMPLATE.loadHeader('#includedHeader');
16
    TEMPLATE.loadConfirmModal();
17 18 19 20 21 22
    const navs = [
        {
            titleLang: 'dashboard',
            href: 'dashboard.html',
        },
        {
NGUYEN HOANG SON committed
23
            titleLang: 'pushMessageList',
24 25 26
        },
    ];
    TEMPLATE.loadMainNavsTitle('#includedMainTitle', 'pushMessageList', navs, null);
27
    PushMessageList.getMessageList(function (messageList) {
28
        PushMessageList.generateMessageListHtml(messageList.pushMessageList);
29
    });
30
    COMMON.closeLoading();
31
};
32

33 34
/**
 * get Message List from CMS
35
 * @param {function} callback
36 37 38 39 40 41
 */
PushMessageList.getMessageList = function (callback) {
    let param = {
        sid: COMMON.getSid(),
    };
    const url = PushMessageList.baseApiUrl;
42 43 44 45 46 47 48 49 50 51 52 53 54
    COMMON.cmsAjax(
        url,
        param,
        true,
        function (json) {
            if (callback) {
                callback(json);
            }
        },
        function () {
            console.log('PushMessageList.getMessageList error');
        },
    );
55
};
56

57 58
/**
 * handle click message event
59
 * @param {string} pushMessageId
60
 */
61 62 63
PushMessageList.clickMessage = function (pushMessageId) {
    COMMON.goUrlWithCurrentParams('pushMessageDetail.html', { pushMessageId: pushMessageId });
};
64

65 66
/**
 * generate message list html
67 68
 * @param {array} messageList
 * @returns
69
 */
70
PushMessageList.generateMessageListHtml = function (messageList) {
71
    if (typeof messageList === 'undefined' || messageList.length < 1) {
72
        //show not found
73 74 75
        $('#messageList .not-found').removeClass('d-none');
        return;
    }
NGUYEN HOANG SON committed
76 77 78 79 80 81
    //sort message list by send date
    messageList.sort(function (a, b) {
        if (a.pushSendDate > b.pushSendDate) return -1;
        if (a.pushSendDate < b.pushSendDate) return 1;
        return 0;
    });
82 83 84 85 86 87 88
    $('#messageList .not-found').addClass('d-none');
    for (var i = 0; i < messageList.length; i++) {
        let message = messageList[i];
        var messageId = message.pushMessageId;
        var mTitle = message.pushMessage;
        var mDate = message.pushSendDate;
        var mSubtitle = message.operationName;
89
        var messageLi = $('<li class="card mb-2" id="pushMessageId_' + messageId + '"/>');
90
        if (message.readingFlg) {
91
            messageLi.addClass('read');
92 93
        } else {
            messageLi.addClass('unread');
94 95
        }
        var messageA = $('<a class="d-block px-3 py-2 text-decoration-none text-dark"/>');
96
        messageA.attr('href', "javascript:PushMessageList.clickMessage('" + messageId + "');");
97 98
        var titleDiv = $('<div class="fs-12 text-truncate">' + mTitle + '</div>');
        var subTitleMainDiv = $('<div class="d-flex justify-content-between align-items-center"></div>');
99
        var subTitleDiv = $('<div class="fs-10 text-truncate">' + mSubtitle + '</div>');
100
        var dateDiv = $('<div class="fs-8 text-secondary text-nowrap">' + mDate + '</div>');
101
        subTitleMainDiv.append(subTitleDiv);
102
        subTitleMainDiv.append(dateDiv);
103 104 105
        messageA.append(titleDiv);
        messageA.append(subTitleMainDiv);
        messageLi.append(messageA);
106 107
        $('#messageList').append(messageLi);
    }
108 109
};

110
/**
111
 * dummy message list JSON for test
112
 */
113
PushMessageList.dummyMessageListJson = {
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    pushMessageList: [
        {
            pushMessageId: 1,
            pushMessage: 'メッセージ内容が入ります。',
            pushSendDate: '2022/07/06 14:14',
            operationName: '作業名が入ります。',
            readingFlg: 0,
        },
        {
            pushMessageId: 2,
            pushMessage: 'メッセージ内容が入ります。メッセージ内容が入ります。メッセージ内容が入ります。メッセージ内容が入ります。',
            pushSendDate: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
            operationName: '作業名が入ります。作業名が入ります。作業名が入ります。作業名が入ります。作業名が入ります。作業名が入ります。',
            readingFlg: 1,
        },
    ],
130
};