operationList.js 19.3 KB
Newer Older
Takumi Imai committed
1
/**
2
 * It is one of the js in index.html.
Takumi Imai committed
3
 * index.html is made of operations List , dashboard and topPage.
4
 *
Takumi Imai committed
5 6 7
 * @since cms:1.4.3.2&1.4.3.3 web:1.0
 */

8 9 10 11 12
var OL = {};

OL.operationList; //Operation json data
OL.operationGroupMaster; //category(operationGroupMaster) json data
OL.isOperationGroupMaster = 0; //0: category(operationGroupMaster) not exist 1: category(operationGroupMaster) exist
13

14 15 16 17 18 19 20 21 22 23 24
OL.sortIndex;
OL.operationGroupMasterId;

/**
 * process on page load.
 * 1.get all data.
 * 2.show operationList.
 * 3.show category(operationGroupMaster).
 */
OL.init = function () {
    console.log('OperationList start');
25
    sessionStorage.activeHomePage = CONSTANT.PAGE_TAB.OPERATION_LIST;
26 27
    sessionStorage.removeItem('operationId');
    sessionStorage.removeItem('RL_searchWord');
Kang Donghun committed
28
    TEMPLATE.loadHeader('#includedHeader');
29

30
    TEMPLATE.loadMainNavsTitle('#includedMainTitle', 'workList', true, null);
31
    TEMPLATE.loadConfirmModal('#includedConfirmModal');
32 33 34 35 36 37 38
    //get all data of operation list scene
    OL.getAllDataWeb(sessionStorage.OL_searchKeyWord, sessionStorage.OL_sortIndex, sessionStorage.OL_searchStartDate, sessionStorage.OL_searchEndDate, sessionStorage.OL_operationGroupMasterId);

    //show operation list
    OL.createOperationList(OL.operationList);

    //show category(operationGroupMaster)
Takumi Imai committed
39
    $('#includedCategoryModal').load('../common/html/category-modal.html', function () {
40 41 42
        OL.createCategory();
        I18N.initi18n();
    });
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
};

/**
 * get operation list all data
 * 1.operation list
 * 2.category(operationGroupMaster) list
 *
 * @param {String} searchKeyword
 * @param {Number} sortIndex
 * @param {String} searchStartDate
 * @param {String} searchEndDate
 * @param {Number} operationGroupMasterId
 */
OL.getAllDataWeb = function (searchKeyWord, sortIndex, searchStartDate, searchEndDate, operationGroupMasterId) {
    let param = {};
    param.sid = COMMON.getSid();
    if (typeof searchKeyWord !== 'undefined') {
        param.operationName = searchKeyWord;
    }
    if (typeof sortIndex !== 'undefined') {
        param.sort = sortIndex;
    }
    if (typeof searchStartDate !== 'undefined') {
        param.startDate = searchStartDate;
    }
    if (typeof searchEndDate !== 'undefined') {
        param.endDate = searchEndDate;
    }
    if (typeof operationGroupMasterId !== 'undefined') {
        param.operationGroupMasterId = operationGroupMasterId;
    }

Kang Donghun committed
75
    const url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.ALL_OPERATION_LIST;
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

    COMMON.cmsAjax(url, param, false, function (json) {
        OL.saveSearchKeyWord(searchKeyWord, sortIndex, searchStartDate, searchEndDate, operationGroupMasterId);
        OL.setSearchInfoWeb();
        OL.operationList = json.operationList;
        OL.operationGroupMaster = json.operationGroupMasterList;
        OL.isOperationGroupMaster = json.isOperationGroupMaster;
    });
};

/**
 * Transfer search criteria to session.
 * Keep value after page move.
 *
 * @param {String} searchKeyword
 * @param {String} sortIndex
 * @param {String} searchStartDate
 * @param {String} searchEndDate
 * @param {String} operationGroupMasterId
 */
OL.saveSearchKeyWord = function (searchKeyword, sortIndex, searchStartDate, searchEndDate, operationGroupMasterId) {
    if (typeof searchKeyword !== 'undefined') {
        sessionStorage.OL_searchKeyWord = searchKeyword;
    }
    if (typeof sortIndex !== 'undefined') {
        sessionStorage.OL_sortIndex = sortIndex;
    }
    if (typeof searchStartDate !== 'undefined') {
        sessionStorage.OL_searchStartDate = searchStartDate;
    }
    if (typeof searchEndDate !== 'undefined') {
        sessionStorage.OL_searchEndDate = searchEndDate;
    }
    if (typeof operationGroupMasterId !== 'undefined') {
        sessionStorage.OL_operationGroupMasterId = operationGroupMasterId;
    }
};

/**
 * set search criteria when Initial display.
 */
OL.setSearchInfoWeb = function () {
    if (sessionStorage.OL_sortIndex) {
        OL.sortIndex = sessionStorage.OL_sortIndex;
    }
    if (sessionStorage.OL_searchKeyWord) {
        $('#searchTaskName').val(sessionStorage.OL_searchKeyWord);
    }
    if (sessionStorage.OL_searchStartDate) {
        $('#searchStartDate').val(sessionStorage.OL_searchStartDate);
    }
    if (sessionStorage.OL_searchEndDate) {
        $('#searchEndDate').val(sessionStorage.OL_searchEndDate);
    }
    if (sessionStorage.OL_operationGroupMasterId) {
        OL.operationGroupMasterId = sessionStorage.OL_operationGroupMasterId;
    }
};

/**
 * create operation list
Takumi Imai committed
137
 * @param operarionList
138 139 140 141 142 143 144 145 146 147 148 149 150
 */
OL.createOperationList = function (operationList) {
    //Initialization
    OL.initActiveSortIndex();
    $('#operationTable').empty();
    $('#operationCount').text(0);

    if (!operationList) {
        return;
    }
    $('#operationCount').text(operationList.length);
    //create & show
    for (let i = 0; i < operationList.length; i++) {
151 152
        let classIcon;
        switch (operationList[i].reportType) {
Takumi Imai committed
153
            case CONSTANT.REPORT_TYPE_INT.REPORT:
154
                classIcon = 'report';
155
                break;
Takumi Imai committed
156
            case CONSTANT.REPORT_TYPE_INT.ROUTINE:
157
                classIcon = 'inspection';
158
                break;
Takumi Imai committed
159
            case CONSTANT.REPORT_TYPE_INT.ANSWER:
160
                classIcon = 'questionary';
161
                break;
Takumi Imai committed
162
            case CONSTANT.REPORT_TYPE_INT.WORKFLOW:
163
                classIcon = 'proccess';
164 165 166
                break;
        }
        let messageli = $("<li class='card mb-2' name = 'operationId_" + operationList[i].operationId + "' ></li>");
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
        let ahrefRequiredFlg = $(
            '<a href="javascript:OL.sendOperation(\'' +
                operationList[i].operationId +
                "', '" +
                operationList[i].operationType +
                "', '" +
                operationList[i].reportType +
                "', '" +
                operationList[i].enableAddReport +
                "');\" class='h-100 d-block px-3 py-2 text-decoration-none text-dark position-relative'></a>",
        );
        let divIcon = $("<div class='position-absolute translate-middle top-50 left-0 ml-3'>" + "<div class='type-icon'>" + "<span class='" + classIcon + "'></span>" + '</div></div>');

        let divDate =
            "<div class='fs-8 text-secondary text-truncate'>" + OL.setOperationDate(operationList[i].operationStartDate) + ' ~ ' + OL.setOperationDate(operationList[i].operationEndDate) + '</div>';

        let divText = $(
            "<div class='pl-5 h-100 d-flex align-items-center'>" + "<div class='w-100'>" + "<div class='fs-12 text-truncate'>" + operationList[i].operationName + '</div>' + divDate + '</div></div>',
        );
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
        ahrefRequiredFlg.append(divIcon);
        ahrefRequiredFlg.append(divText);
        messageli.append(ahrefRequiredFlg);

        $('#operationTable').append(messageli);
    }
};

/**
 * add color to any sorting type when sortIndex exsist
 *
 * @param {Number} sortIndex
 */
OL.initActiveSortIndex = function (sortIndex) {
    if (!sortIndex && !OL.sortIndex) {
        OL.sortIndex = CONSTANT.SORT_TYPE.START_DATE_DESC;
    }

    $('.sort-type').each(function () {
        const sortType = $(this).data('sort');
        if (sortType == OL.sortIndex) {
            $('.sort-type').removeClass('active');
            $(this).addClass('active');
        }
    });
};

/**
 * set date for OperationList
 *
 * @param {String} date
 * @returns operationDate
 */
OL.setOperationDate = function (date) {
    const operationDate = date.replace(/-/g, '/').substring(0, 10);
    return operationDate;
};

/**
 * create category(operationGroupMaster).
 */
OL.createCategory = function () {
    if (!OL.isOperationGroupMaster) {
        return;
    }
    OL.initCategory();
    OL.createBreadcrumbList();
    OL.createCategoryList();
};

/**
 * Initial processing of category(operationGroupMaster).
 */
OL.initCategory = function () {
    if (!OL.isOperationGroupMaster) {
        return;
    }
    $('#operationGroupMasterButton').removeClass('d-none');
};

/**
 * create Breadcrumb List
 */
OL.createBreadcrumbList = function () {
    if (!OL.isOperationGroupMaster) {
        return;
    }

    $('#groupMasterPath').empty();
    if (typeof OL.operationGroupMasterId === 'undefined' || OL.operationGroupMasterId == 0) {
256
        $('#groupMasterPath').append('<li class="breadcrumb-item"><a href="#" class="text-decoration-none text-underline">' + I18N.i18nText('categoryAll') + '</a></li>');
257 258 259 260
    } else {
        let treeList = [];
        OL.createBreadcrumbTree(treeList, OL.operationGroupMasterId);
        treeList.forEach(function (operationGroupMaster) {
261 262 263 264 265 266 267 268 269
            if (operationGroupMaster.operationGroupMasterId != OL.operationGroupMasterId) {
                $('#groupMasterPath').append(
                    '<li class="breadcrumb-item"><a onclick="OL.changeOperationGroupMaster(' +
                        operationGroupMaster.operationGroupMasterId +
                        ');" class="text-decoration-none text-underline">' +
                        operationGroupMaster.operationGroupMasterName +
                        '</a></li>',
                );
            } else {
270
                $('#groupMasterPath').append('<li class="breadcrumb-item active" aria-current="page"><span>' + operationGroupMaster.operationGroupMasterName + '</span></li>');
271
            }
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
        });
    }
};

/**
 * create Breadcrumb tree List
 *
 * @param {list} treeList
 * @param {string} operationGroupMasterId
 * @returns
 */
OL.createBreadcrumbTree = function (treeList, operationGroupMasterId) {
    if (operationGroupMasterId == 0) {
        return treeList;
    }

    const groupMaster = OL.operationGroupMaster.filter(it => it.operationGroupMasterId == operationGroupMasterId)[0];
    OL.createBreadcrumbTree(treeList, groupMaster.parentOperationGroupMasterId);
    treeList.push(groupMaster);
    return treeList;
};

/**
 * create category(operationGroupMaster) structure
 */
OL.createCategoryList = function () {
    if (!OL.isOperationGroupMaster) {
        return;
    }
    //Create a side menu category structure
302 303
    var categoryListElement = $('#categoryListMenu');
    categoryListElement.empty();
304
    //sort group master list by level low to hight
305 306 307 308 309
    OL.operationGroupMaster.sort(function (a, b) {
        if (a.operationGroupMasterLevel < b.operationGroupMasterLevel) return -1;
        if (a.operationGroupMasterLevel > b.operationGroupMasterLevel) return 1;
        return 1;
    });
310 311 312 313
    let allChecked = '';
    if (typeof OL.operationGroupMasterId === 'undefined' || OL.operationGroupMasterId == 0) {
        allChecked = ' checked';
    }
314
    const allCategory = $('<ul><li><label><input type="radio" name="category" value="0"' + allChecked + '> <span>' + I18N.i18nText('categoryAll') + '</span></label></li></ul>');
315
    categoryListElement.append(allCategory);
316 317
    //create category(operationGroupMaster) structure
    for (let i = 0; i < OL.operationGroupMaster.length; i++) {
318
        const item = OL.operationGroupMaster[i];
319
        // console.log(item);
320 321 322 323 324 325 326 327
        let inputLabel = $('<label>');
        let inputRadio = $('<input type="radio" name="category">');
        inputRadio.val(item.operationGroupMasterId);
        if (OL.operationGroupMasterId && OL.operationGroupMasterId == item.operationGroupMasterId) {
            inputRadio.prop('checked', true);
        }
        let groupSpan = $('<span>' + item.operationGroupMasterName + '</span>');
        inputLabel.append(inputRadio);
328
        inputLabel.append(' ');
329
        inputLabel.append(groupSpan);
330
        const isParent = OL.operationGroupMaster.find(function (child) {
331 332 333 334 335 336 337 338
            return item.operationGroupMasterId == child.parentOperationGroupMasterId;
        });
        let parentElement = categoryListElement;
        if (item.parentOperationGroupMasterId != 0) {
            parentElement = $('#collapse' + item.parentOperationGroupMasterId + ' > ul');
        }
        if (isParent) {
            //accordion
339 340 341
            const accordionId = 'accordion' + item.operationGroupMasterId;
            const headingId = 'heading' + item.operationGroupMasterId;
            const collapseId = 'collapse' + item.operationGroupMasterId;
342 343
            let accordionElm = $('<li class="accordion" id="' + accordionId + '" />');
            //heading
344 345 346 347 348 349 350 351 352
            let headingDiv = $('<div id="' + headingId + '" />');
            let linkA = $('<a class="list-menu-link" />');
            let collapseButton = $('<button type="button" class="collapsed" data-toggle="collapse" aria-expanded="true" />');
            collapseButton.attr('data-target', '#' + collapseId);
            collapseButton.attr('aria-controls', collapseId);
            collapseButton.append('<div class="arrow-icon"></div>');
            linkA.append(collapseButton);
            linkA.append(inputLabel);
            headingDiv.append(linkA);
353 354 355 356 357 358 359 360 361
            //collapse
            let collapseElm = $('<div id="' + collapseId + '" class="collapse">');
            collapseElm.attr('data-parent', '#' + accordionId);
            collapseElm.attr('aria-labelledby', headingId);
            let ul = $('<ul>');
            collapseElm.append(ul);
            accordionElm.append(headingDiv);
            accordionElm.append(collapseElm);
            parentElement.append(accordionElm);
362
        } else {
363 364
            let li = $('<li>');
            li.append(inputLabel);
365
            parentElement.append(li);
366 367 368 369 370
        }
    }
};

/**
371
 * Handle onclick category selection button
372
 */
373
OL.onClickCategorySelection = function () {
374 375 376
    const operationGroupMasterId = $('input[name="category"]:checked').val();
    $('#category-modal .close').click();
    OL.changeOperationGroupMaster(operationGroupMasterId);
377 378 379 380 381 382 383 384 385 386 387
};

/**
 * Sort the operationList by screen operation
 *
 * @param {Object} sortType
 */
OL.changeSortType = function (sortType) {
    $('.sort-type').removeClass('active');
    $(sortType).addClass('active');
    OL.sortIndex = $(sortType).attr('data-sort');
388
    const sortNumber = parseFloat(OL.sortIndex);
389 390 391 392 393 394 395 396 397 398 399
    OL.sortOperationList(sortNumber);
    OL.createOperationList(OL.operationList);
};

/**
 * sort the operationList
 *
 * @param {Number} sortNumber
 */

OL.sortOperationList = function (sortNumber) {
400 401 402
    if (!OL.operationList) {
        return;
    }
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
    switch (sortNumber) {
        case CONSTANT.SORT_TYPE.NAME:
            OL.operationList.sort(function (a, b) {
                if (a.operationName > b.operationName) return 1;
                if (a.operationName < b.operationName) return -1;
                return 0;
            });
            break;
        case CONSTANT.SORT_TYPE.START_DATE_DESC:
            OL.operationList.sort(function (a, b) {
                if (OL.setOperationDate(a.operationStartDate) < OL.setOperationDate(b.operationStartDate)) return 1;
                if (OL.setOperationDate(a.operationStartDate) > OL.setOperationDate(b.operationStartDate)) return -1;
                return 0;
            });
            break;
        case CONSTANT.SORT_TYPE.START_DATE_ASC:
            OL.operationList.sort(function (a, b) {
                if (OL.setOperationDate(a.operationStartDate) > OL.setOperationDate(b.operationStartDate)) return 1;
                if (OL.setOperationDate(a.operationStartDate) < OL.setOperationDate(b.operationStartDate)) return -1;

                return 0;
            });
            break;
        case CONSTANT.SORT_TYPE.TYPE:
            OL.operationList.sort(function (a, b) {
                if (a.operationType < b.operationType) return 1;
                if (a.operationType > b.operationType) return -1;
                return 0;
            });
            break;
        case CONSTANT.SORT_TYPE.LAST_EDIT_DATE:
            const defaultDate = '1900-01-01 09:00:00';
            OL.operationList.sort(function (a, b) {
                if (!a.operationOpenDate) {
                    a.operationOpenDate = defaultDate;
                }
                if (!b.operationOpenDate) {
                    b.operationOpenDate = defaultDate;
                }
                if (a.operationOpenDate < b.operationOpenDate) return 1;
                if (a.operationOpenDate > b.operationOpenDate) return -1;
                return 0;
            });
            break;
    }
};

/**
 * search operarionList
 */
OL.search = function () {
    const searchKeyword = $('#searchTaskName').val();
    const searchStartDate = $('#searchStartDate').val();
    const searchEndDate = $('#searchEndDate').val();

    if (searchStartDate && searchEndDate && searchStartDate > searchEndDate) {
        COMMON.closeLoading();
460
        COMMON.showAlert('dateError');
461 462 463
        return;
    }

464
    COMMON.showLoading();
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486
    OL.getAllDataWeb(searchKeyword, OL.sortIndex, searchStartDate, searchEndDate, OL.operationGroupMasterId);
    OL.createOperationList(OL.operationList);
    OL.createCategory();
    COMMON.closeLoading();
};

/**
 * change the operationList by select the category(OperationGroupMaster)
 * @param {Number} operationGroupMasterId
 */
OL.changeOperationGroupMaster = function (operationGroupMasterId) {
    if ($('#category-menu').hasClass('open')) {
        $('#category-toggle-button').click();
        $('body').css('overflow', 'visible');
    }
    OL.operationGroupMasterId = operationGroupMasterId;
    OL.search();
};

/**
 * open the category(OperationGroupMaster)
 */
487
OL.openCategory = function () {};
488 489 490 491 492 493 494 495 496 497 498 499 500

/**
 * reset search
 */
OL.resetSearch = function () {
    $('#searchTaskName').val('');
    $('#searchStartDate').val('');
    $('#searchEndDate').val('');
    OL.changeSortType($('#defaultSort'));
};

/**
 * Transition to the report form or operation list screen
Takumi Imai committed
501 502 503 504
 * @param {*} operationId
 * @param {*} operationType
 * @param {*} reportType
 * @param {*} enableAddReport
505 506 507 508 509
 */
OL.sendOperation = function (operationId, operationType, reportType, enableAddReport) {
    //save operation logs. needed for sorting
    OL.saveOperationReadingLog(operationId, operationType, reportType);
    //Transition to the report form or operation list screen
Takumi Imai committed
510
    sessionStorage.setItem('operationId', operationId);
511 512 513
    if (enableAddReport == '1' || reportType == CONSTANT.REPORT_TYPE.ROUTINE) {
        COMMON.avwScreenMove('reportList.html');
    } else {
Takumi Imai committed
514
        const url = 'reportForm.html?operationId=' + operationId + '&addReport=' + enableAddReport;
515 516
        COMMON.avwScreenMove(url);
    }
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533
};

/**
 * save operation logs. needed for sorting
 *
 * @param {String} operationId
 * @param {String} operationType
 * @param {String} reportType
 */
OL.saveOperationReadingLog = function (operationId, operationType, reportType) {
    let params = {};
    params.sid = COMMON.getSid();
    params.operationId = operationId;
    params.deviceType = CONSTANT.DEVICE_TYPE.WEB;
    params.operationType = operationType;
    params.reportType = reportType;
    params.viewingStartDate = COMMON.currentTime();
Kang Donghun committed
534
    const url = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.API.OPERATION_VIEW_LOG;
535 536 537 538 539 540 541 542 543 544 545
    COMMON.cmsAjax(url, params, false);
};

/**
 * return url of cms Operation Scene
 *
 * @param {boolean} enableAddReport
 * @param {Number} reportType
 * @returns url
 */
OL.createUrlOfOperation = function (enableAddReport, reportType) {
Kang Donghun committed
546
    let baseUrl = COMMON.format(ClientData.conf_checkApiUrl(), ClientData.userInfo_accountPath()) + CONSTANT.URL.CMS.HTML.BASE;
547 548 549 550 551 552
    if (reportType == CONSTANT.REPORT_TYPE.ROUTINE || enableAddReport == '1') {
        return baseUrl + CONSTANT.URL.CMS.HTML.TASK_REPORT_LIST;
    } else {
        return baseUrl + CONSTANT.URL.CMS.HTML.LIST_REPORT_FORM;
    }
};