operation-select.js 3.52 KB
Newer Older
1 2 3 4 5 6
/**
 * Operation Select js in operation-select.html
 *
 * @since 1.0 check web
 */
var OperationSelect = {};
7
OperationSelect.changeSelectCallback = function() {};
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

OperationSelect.operationIdSelected="";
OperationSelect.operationNameSelected="";

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

/**
 * get operation select data from cms
 * @param {function} callback 
 */
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 42 43 44 45 46 47 48 49 50 51 52
    COMMON.cmsAjax(url, param, false, function (json) {
        if (callback) {
            callback(json);
        }
    }, function() {
        console.log('OperationSelect.getOperationSelectData error');
        if (callback) {
            callback(OperationSelect.defaultOperationSelectJson);
        }
    });
};

/**
 * 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
 */
53
OperationSelect.init = function (selectedCallback) {
54
    OperationSelect.getOperationSelectData(function (data) {
NGO THI HONG committed
55 56
        if (typeof data === 'undefined' || data == null) return;
        OperationSelect.createOperationSelectList(data.operationList);
57 58
    });
    OperationSelect.selectOperationClick();
59
    OperationSelect.changeSelectCallback = selectedCallback;
60 61 62 63 64 65
};

/**
 * Implement operation select html
 * @returns 
 */
NGO THI HONG committed
66
 OperationSelect.createOperationSelectList = function(operationList) {
67
	$("#operationSelectList").empty();
NGO THI HONG committed
68 69
    if (typeof operationList === 'undefined' || operationList.length < 1) return;
    for (let i = 0; i < operationList.length; i++) {
70
		
NGO THI HONG committed
71 72 73
		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>");
74 75 76 77 78 79 80 81 82
		
		ahrefRequiredFlg.append(divText);
		messageli.append(ahrefRequiredFlg);

		$("#operationSelectList").append(messageli);
	}
    $("#operationSelectList :first-child").addClass("selected");
}

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

/**
 * handle click event of select button
 */
 OperationSelect.onClickSelect = function () {
    OperationSelect.chooseOperationSelect();
};


/**
 * Get operation select and call back function in main page
 */
 OperationSelect.chooseOperationSelect = function () {
    let param = {};
    param.operationIdSelected = OperationSelect.operationIdSelected;
    param.operationNameSelected = OperationSelect.operationNameSelected;
    OperationSelect.closeModal();
    if (OperationSelect.changeSelectCallback && typeof OperationSelect.changeSelectCallback === 'function') {
NGO THI HONG committed
101
        OperationSelect.changeSelectCallback(param.operationIdSelected,param.operationNameSelected );
102 103 104 105 106 107 108 109 110
    }
};

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