operationSelect.js 3.96 KB
Newer Older
1
/**
NGO THI HONG committed
2
 * Operation Select js in operationSelect.html
3
 *
4
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
5 6
 */
var OperationSelect = {};
7
OperationSelect.changeSelectCallback = function () {};
8

9 10
OperationSelect.operationIdSelected = '';
OperationSelect.operationNameSelected = '';
11 12 13 14 15 16 17 18

/**
 * default operation select data JSON
 */
OperationSelect.defaultOperationSelectJson = [];

/**
 * get operation select data from cms
19
 * @param {function} callback
20 21 22 23 24
 */
OperationSelect.getOperationSelectData = function (callback) {
    let param = {
        sid: COMMON.getSid(),
    };
Kang Donghun committed
25
    const url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.OPERATION_SELECT;
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    COMMON.cmsAjax(
        url,
        param,
        false,
        function (json) {
            if (callback) {
                callback(json);
            }
        },
        function () {
            console.log('OperationSelect.getOperationSelectData error');
            if (callback) {
                callback(OperationSelect.defaultOperationSelectJson);
            }
        },
    );
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
};

/**
 * handle click operation setting
 */
OperationSelect.selectOperationClick = function () {
    $('.select-card-list .card .select-label').on('click', function () {
        $(this).closest('.select-card-list').find('.card').removeClass('selected');
        $(this).closest('.card').addClass('selected');
        OperationSelect.operationIdSelected = $(this).attr('data-key');
        OperationSelect.operationNameSelected = $(this).attr('data-name');
    });
};

/**
 * init data, action when screen onload
Takumi Imai committed
58
 * @param selectedCallback
59
 */
60
OperationSelect.init = function (selectedCallback) {
61
    OperationSelect.getOperationSelectData(function (data) {
NGO THI HONG committed
62 63
        if (typeof data === 'undefined' || data == null) return;
        OperationSelect.createOperationSelectList(data.operationList);
64 65
    });
    OperationSelect.selectOperationClick();
66
    OperationSelect.changeSelectCallback = selectedCallback;
67 68 69 70
};

/**
 * Implement operation select html
Takumi Imai committed
71
 * @param operarionList
72
 * @returns
73
 */
74 75
OperationSelect.createOperationSelectList = function (operationList) {
    $('#operationSelectList').empty();
76 77 78 79 80 81 82 83
    
    // sort operation list by operationId
    operationList = operationList.sort(function (a, b) {
        if (a.operationId < b.operationId) return 1;
        if (a.operationId > b.operationId) return -1;
        return 0;
    });

NGO THI HONG committed
84 85
    if (typeof operationList === 'undefined' || operationList.length < 1) return;
    for (let i = 0; i < operationList.length; i++) {
86 87 88 89 90
        let messageli = $("<li class='card mb-2' name = 'operationId_" + operationList[i].operationId + "' ></li>");
        let ahrefRequiredFlg = $(
            "<a href='#' class='d-block px-5 py-3 text-decoration-none select-label' data-key='" + operationList[i].operationId + "' data-name='" + operationList[i].operationName + "' ></a>",
        );
        let divText = $("<div class='fs-12 text-truncate d-block'>" + operationList[i].operationName + '</div>');
91

92 93
        ahrefRequiredFlg.append(divText);
        messageli.append(ahrefRequiredFlg);
94

95 96 97 98
        $('#operationSelectList').append(messageli);
    }
    $('#operationSelectList :first-child').addClass('selected');
};
99 100 101 102

/**
 * handle click event of select button
 */
103
OperationSelect.onClickSelect = function () {
104 105 106 107 108 109
    OperationSelect.chooseOperationSelect();
};

/**
 * Get operation select and call back function in main page
 */
110
OperationSelect.chooseOperationSelect = function () {
111 112 113 114 115
    let param = {};
    param.operationIdSelected = OperationSelect.operationIdSelected;
    param.operationNameSelected = OperationSelect.operationNameSelected;
    OperationSelect.closeModal();
    if (OperationSelect.changeSelectCallback && typeof OperationSelect.changeSelectCallback === 'function') {
116
        OperationSelect.changeSelectCallback(param.operationIdSelected, param.operationNameSelected);
117 118 119 120 121 122
    }
};

/**
 * close setting dialog
 */
123
OperationSelect.closeModal = function () {
124
    $('#task-list-modal .close').click();
125
};