bookmark.js 30.9 KB
Newer Older
1 2 3 4 5 6 7 8 9
/// しおりリスト画面 - SCRSLS0100

var contentTypes = {};
var contentName = {};
var pathImgContentNone = './img/page-none.png';

// Init function of page
$(document).ready(function () {

10
    if (!AVWEB.avwCheckLogin(COMMON.ScreenIds.Login)) return;
11

Masaru Abe committed
12
    COMMON.LockScreen();
13

14
    document.title = I18N.i18nText('dspShiori') + ' | ' + I18N.i18nText('sysAppTitle');
15 16

    // Set bookmark screen
17
    ClientData.BookmarkScreen(COMMON.ScreenIds.BookmarkList);
18 19 20 21 22 23 24 25 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 53 54 55 56 57 58 59 60 61

    //Check if Force Change password
    if (ClientData.requirePasswordChange() != 1) {

        // Synchronize bookmarks with server
        SyncContent();

        // Collection all detail of pages
        bookmark_collectAllPages();

        $("#dspDelete").click(dspDelete_Click);        

        $("#dspDelete1").click(dspDelete1_Click);
        $("#dspCancel").click(dspCancel_Click);
        $("#dspConfirmOK").click(dspConfirmOK_Click);

        ClearGrid();

        if (ClientData.BookMarkData().length == 0) {
            // Show error
            $("#msgShioriNotExists").show();
            $("#dspDelete").hide();
            $("#dspDelete1").hide();
        }
        else {
            $("#msgShioriNotExists").hide();
            $("#dspDelete").show();
            $("#dspDelete1").show();
        }

        // Show book in local storage
        //ShowBookmark();

        $("a[name='dspRead']").unbind('click');
        $("a[name='dspRead']").click(dspRead_Click);

        HideSorting();

        // Default sort is タイトル名, default is asc
        ClientData.sortOpt_searchDivision(1);
        ClientData.sortOpt_sortType(2);
        dspTitleNm_Click();
    }
    else {
Masaru Abe committed
62
        HEADER.checkForceChangePassword();
63
    }
Masaru Abe committed
64
    
Masaru Abe committed
65
    if (COMMON.isAnonymousLogin()) {
Masaru Abe committed
66 67 68 69
        //プッシュメッセージ隠す
        $('#dspPushMessage').hide();
    }
    
70 71 72 73 74 75 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
});

/*
----------------------------------------------------------------------------
Event groups [start]
----------------------------------------------------------------------------
*/

// update status sort
//function changeStatusSort(obj, isAsc) {
//    $('#sortingDiv .sort li a').removeClass().addClass('lang');
//    $('#sortingDiv .sort li').removeClass('current');
//    $(obj).addClass(isAsc ? 'ascending_sort' : 'descending_sort').parent().addClass("current");
//};

function dspTitleNm_Click() {
    
    var isAsc = false;
    if (ClientData.sortOpt_searchDivision() == 1) { // Name
        if (ClientData.sortOpt_sortType() == 1) {   // ASC
            isAsc = false;
            ClientData.sortOpt_sortType(2);
        }
        else {
            isAsc = true;
            ClientData.sortOpt_sortType(1);
        }
    }
    else {
        ClientData.sortOpt_searchDivision(1);
        ClientData.sortOpt_sortType(1); // default is asc
        isAsc = true;
    }
    
    SortTitleName(isAsc);
//    $("#dspTitleNm").addClass("active_tops");        
//    $("#dspTitleNmKn").removeClass("active_tops");
//    $("#dspPubDt").removeClass("active_tops");

    //changeStatusSort(this, isAsc);
Masaru Abe committed
110
    HEADER.setStatusSort('#dspTitleNm', isAsc);
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 137

};
function dspTitleNmKn_Click() {
    var isAsc = false;
    if (ClientData.sortOpt_searchDivision() == 2) { // Kana
        if (ClientData.sortOpt_sortType() == 1) {   // ASC
            isAsc = false;
            ClientData.sortOpt_sortType(2);
        }
        else {
            isAsc = true;
            ClientData.sortOpt_sortType(1);
        }
    }
    else {
        ClientData.sortOpt_searchDivision(2); // Kana
        ClientData.sortOpt_sortType(1); // default is asc
        isAsc = true;
    }

    SortTitleNameKana(isAsc);

//    $("#dspTitleNm").removeClass("active_tops");        
//    $("#dspTitleNmKn").addClass("active_tops");    
    //    $("#dspPubDt").removeClass("active_tops");

    //changeStatusSort(this, isAsc);
Masaru Abe committed
138
    HEADER.setStatusSort('#dspTitleNmKn', isAsc);
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165

};
function dspPubDt_Click() {
    var isAsc = false;
    if (ClientData.sortOpt_searchDivision() == 3) { // Publish date
        if (ClientData.sortOpt_sortType() == 1) {   // ASC
            isAsc = false;
            ClientData.sortOpt_sortType(2);
        }
        else {
            isAsc = true;
            ClientData.sortOpt_sortType(1);
        }
    }
    else {
        ClientData.sortOpt_searchDivision(3); // Kana
        ClientData.sortOpt_sortType(1); // default is asc
        isAsc = true;
    }

    SortPubDate(isAsc);

//    $("#dspTitleNm").removeClass("active_tops");        
//    $("#dspTitleNmKn").removeClass("active_tops");    
    //    $("#dspPubDt").addClass("active_tops");

    //changeStatusSort(this, isAsc);
Masaru Abe committed
166
    HEADER.setStatusSort('#dspPubDt', isAsc);
167 168 169 170 171 172 173
};

// Event of each button [読む]
function dspRead_Click() {     	    
    var jsondata = $(this).attr("value");
    var data = JSON.parse(jsondata);

Masaru Abe committed
174 175 176 177 178 179 180 181
    checkLimitContent(
        data.contentid,
        function (){
            dspRead_Click_callback(data);
        },
        function(){
        }
    );
182 183 184 185 186 187 188 189
};
//
function dspRead_Click_callback(data) {

    ClientData.contentInfo_contentId(data.contentid);
    ClientData.bookmark_pageNo(data.pageNo);
    ClientData.contentInfo_contentType(data.contentType);
    ClientData.IsRefresh(false);
190
    AVWEB.avwScreenMove(COMMON.ScreenIds.ContentView);
191 192 193 194 195 196 197 198
};


// Cancel dialog of deleting
function dspCancel_Click() {
    // Close dialog
    //$('#dlgConfirm').dialog('close');
    $("#delete_shiori").hide();
Masaru Abe committed
199
    COMMON.unlockLayout();
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
};
// Process deleting
function dspConfirmOK_Click() {
    // --------------------------------
    // Process deleting [start]
    // --------------------------------
    
    // Get selected bookmarks
    var arrSelectedBookmarks = $("input[name='chkDelete']:checked");
    $.each(arrSelectedBookmarks, function () {
        // Delete selected items on layout

        var contentid = JSON.parse(this.value).contentid;
        var pageNo = JSON.parse(this.value).pageNo;

        $(this).parent().parent().parent().remove();

        // Remove from ClientData
        var bm = ClientData.BookMarkData();

        for (var nIndex = bm.length - 1; nIndex >= 0; nIndex--) {
            if (bm[nIndex].contentid == contentid && bm[nIndex].pageNo == pageNo) {
                bm.splice(nIndex, 1);
                ClientData.isChangedBookmark(true);
            }
        }
        ClientData.BookMarkData(bm);

        if (ClientData.BookMarkData().length == 0) {
            // Show error
            $("#msgShioriNotExists").show();
            $("#dspDelete").hide();
            $("#dspDelete1").hide();
        }
    });
    
    // --------------------------------
    // Process deleting [ end ]
    // --------------------------------

    $("#delete_shiori").hide();
Masaru Abe committed
241
    COMMON.unlockLayout();
242 243 244 245 246 247 248 249
};

function dspDelete1_Click() {
    dspDelete_Click();
};

function dspDelete_Click() {    
    if ($("input[name='chkDelete']:checked").length > 0) {
Masaru Abe committed
250
    	COMMON.lockLayout();
251 252 253 254 255 256 257
    	$("#delete_shiori").show();
    	$("#delete_shiori").center();
    }    
};

// Show detail content
function ShowBookmark() {
258
    if (AVWEB.avwHasError()) {
259 260 261 262 263 264 265 266 267 268 269 270 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 302 303 304 305 306 307
        return;
    }
    else {
        var hasMemo = false;
        var hasMarking = false;
        var contentid = "";
        var pageNo = 0;

        if (ClientData.BookMarkData().length > 0) {
            $("#dspDelete").show();
            $("#dspDelete1").show();
        }
        //TotalThread = ClientData.BookMarkData().length;
        for (var nIndex = ClientData.BookMarkData().length - 1; nIndex >= 0; nIndex--) {
            hasMarking = false;
            hasMemo = false;

            contentid = ClientData.BookMarkData()[nIndex].contentid;
            pageNo = ClientData.BookMarkData()[nIndex].pageNo;

            // Check if contentid has marking
            for (var nIndex1 = 0; nIndex1 < ClientData.MarkingData().length; nIndex1++) {

                if (ClientData.MarkingData()[nIndex1].contentid == contentid
               && ClientData.MarkingData()[nIndex1].pageNo == pageNo) {
                    hasMarking = true;
                }
            }

            // Check if contentid has memo
            for (var nIndex1 = 0; nIndex1 < ClientData.MemoData().length; nIndex1++) {

                if (ClientData.MemoData()[nIndex1].contentid == contentid
               && ClientData.MemoData()[nIndex1].pageNo == pageNo) {
                    hasMemo = true;
                }
            }

            var pageDetail;
            var contentTitle = "";
            var contentTitleKana = "";
            var contentType = "";
            // Search current page if collection that get details before
            for (var nIndex2 = 0; nIndex2 < collection_contents.length; nIndex2++) {
                if (collection_contents[nIndex2].contentid == contentid) {
                    contentTitle = collection_contents[nIndex2].contentTitle;
                    contentTitleKana = collection_contents[nIndex2].contentTitleKana;
                    contentType = collection_contents[nIndex2].contentType;
                    
308 309 310 311 312 313
                    // Search in pages
                    for (var nIndex3 = 0; nIndex3 < collection_contents[nIndex2].pages.length; nIndex3++) {
                        if (pageNo == collection_contents[nIndex2].pages[nIndex3].pageNo) {
                            pageDetail = collection_contents[nIndex2].pages[nIndex3];
                            if(contentType != COMMON.ContentTypeKeys.Type_PDF){
                                pageDetail.pageText = "";
314
                            }
315
                            break;
316 317
                        }
                    }
318
                    
319 320 321 322 323 324 325 326 327 328
                }
            }            
            if (pageDetail) {
                // If bookmark does not exist
                if (pageDetail.existed == true) {
                    // Show normal
                    UpdateBookmark(contentid, pageDetail.pageNo, contentTitle, contentTitleKana);

                    var pageThumbnail = (pageDetail.pageThumbnail != pathImgContentNone) ? ("data:image/jpeg;base64," + pageDetail.pageThumbnail) : pathImgContentNone;

Masaru Abe committed
329
                    insertRow(contentid, pageThumbnail, COMMON.htmlEncode(contentTitle),
330 331 332 333
                        pageDetail.pageText, pageDetail.pageNo, hasMemo, hasMarking, nIndex, contentType);
                }
                else {                    
                    // Not existed -> Show error
Masaru Abe committed
334
                    insertRowError(contentid, COMMON.htmlEncode(contentTitle), pageDetail.pageNo);
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
                }
            }

        }
        $("a[name='dspRead']").unbind('click');
        $("a[name='dspRead']").click(dspRead_Click);
    }
};
// Hide all sorting symbol
function HideSorting() {
    $('#menu_sort li a').removeClass('ascending_sort').removeClass('descending_sort');
};
// Sort by title name
function SortTitleName(isAsc) {

Masaru Abe committed
350
    HEADER.setStatusSort('#dspTitleNm', isAsc);
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406

    var arrSource = ClientData.BookMarkData();
    var arrTarget = [];
    var strTemp = "";
    var nTempIndex = 0;
    var isStop = false;
    while (!isStop) {
        if (arrSource.length > 0) {
            strTemp = "";
            // Lookup min item
            for (var nIndex = 0; nIndex < arrSource.length; nIndex++) {
                if (strTemp == "") {
                    strTemp = arrSource[nIndex].contentTitle;
                    nTempIndex = nIndex;
                }
                else {
                    // ASC
                    if (isAsc) {
                        if (arrSource[nIndex].contentTitle < strTemp) {
                            strTemp = arrSource[nIndex].contentTitle;
                            nTempIndex = nIndex;
                        }
                    }
                    else {
                        if (arrSource[nIndex].contentTitle > strTemp) {
                            strTemp = arrSource[nIndex].contentTitle;
                            nTempIndex = nIndex;
                        }
                    }
                }
            }
            // Add to target array
            arrTarget.push(arrSource[nTempIndex]);
            // Remove min item from source array
            arrSource.splice(nTempIndex, 1);
        }
        else {
            isStop = true;
        }
    }
    ClearGrid();
    ClientData.BookMarkData(arrTarget);
    ShowBookmark();
};
// Clear all rows of grid
function ClearGrid() {

    var arrSelectedBookmarks = $("input[name='chkDelete']");
    $.each(arrSelectedBookmarks, function () {
        $(this).parent().parent().parent().remove();
    });
    
};
// Sort by title name kana
function SortTitleNameKana(isAsc) {

Masaru Abe committed
407
    HEADER.setStatusSort('#dspTitleNmKn', isAsc);
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

    var arrSource = ClientData.BookMarkData();
    var arrTarget = [];
    var strTemp = "";
    var nTempIndex = 0;
    var isStop = false;
    while (!isStop) {
        if (arrSource.length > 0) {
            strTemp = "";
            // Lookup min item
            for (var nIndex = 0; nIndex < arrSource.length; nIndex++) {
                if (strTemp == "") {
                    strTemp = arrSource[nIndex].contentTitleKana;
                    nTempIndex = nIndex;
                }
                else {
                    // ASC
                    if (isAsc) {
                        if (arrSource[nIndex].contentTitleKana < strTemp) {
                            strTemp = arrSource[nIndex].contentTitleKana;
                            nTempIndex = nIndex;
                        }
                    }
                    else {
                        if (arrSource[nIndex].contentTitleKana > strTemp) {
                            strTemp = arrSource[nIndex].contentTitleKana;
                            nTempIndex = nIndex;
                        }
                    }
                }
            }
            // Add to target array
            arrTarget.push(arrSource[nTempIndex]);
            // Remove min item from source array
            arrSource.splice(nTempIndex, 1);
        }
        else {
            isStop = true;
        }
    }
    ClearGrid();
    ClientData.BookMarkData(arrTarget);
    ShowBookmark();
};
// Sort by publish date
function SortPubDate(isAsc) {

Masaru Abe committed
455
    HEADER.setStatusSort('#dspPubDt', isAsc);
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536

    var arrSource = ClientData.BookMarkData();
    var arrTarget = [];
    var dateTemp = undefined;
    var nTempIndex = 0;
    var isStop = false;
    while (!isStop) {
        if (arrSource.length > 0) {
            dateTemp = undefined;
            // Lookup min item
            for (var nIndex = 0; nIndex < arrSource.length; nIndex++) {
                if (dateTemp == undefined) {
                    dateTemp = arrSource[nIndex].registerDate;
                    nTempIndex = nIndex;
                }
                else {
                    // ASC
                    if (isAsc) {
                        if (arrSource[nIndex].registerDate < dateTemp) {
                            dateTemp = arrSource[nIndex].registerDate;
                            nTempIndex = nIndex;
                        }
                    }
                    else {
                        if (arrSource[nIndex].registerDate > dateTemp) {
                            dateTemp = arrSource[nIndex].registerDate;
                            nTempIndex = nIndex;
                        }
                    }
                }
            }
            // Add to target array
            arrTarget.push(arrSource[nTempIndex]);
            // Remove min item from source array
            arrSource.splice(nTempIndex, 1);
        }
        else {
            isStop = true;
        }
    }
    ClearGrid();
    ClientData.BookMarkData(arrTarget);
    ShowBookmark();
};
/*
Update information of specified bookmark
*/
function UpdateBookmark(contentid, pageNo, contentTitle, contentTitleKana) {
    var arrBookmarks = ClientData.BookMarkData();

    for (var nIndex = 0; nIndex < arrBookmarks.length; nIndex++) {
        if (contentid == arrBookmarks[nIndex].contentid && pageNo == arrBookmarks[nIndex].pageNo) {
            if (contentTitle != null && contentTitle != undefined) {
                arrBookmarks[nIndex].contentTitle = contentTitle;
            }
            if (contentTitleKana != null && contentTitleKana != undefined) {
                arrBookmarks[nIndex].contentTitleKana = contentTitleKana;
            }
            break;
        }
    }
    // Set bookmark back to client data
    ClientData.BookMarkData(arrBookmarks);
};


/*
 Insert error row
*/
function insertRowError(contentid, pageTitle, pageNo) {

    var newRow = "";

    newRow += "<section class='sectionBookmark'>";
    newRow += "     <div class='cnt_section'>";

    newRow += '<span class="check">';
    newRow += "<input type='checkbox' name='chkDelete' value='{\"contentid\":" + contentid + ", \"pageNo\":" + pageNo +"}' />";
    newRow += '</span>';

    newRow += "     <div class='text'>";
Masaru Abe committed
537
    newRow += '         <label class="name">' + COMMON.truncate(pageTitle, 20) + '</label>';
538
    newRow += '         <div class="info">';
539
    newRow += "                 <label class='lang name' lang='msgShioriDeleted'>" + I18N.i18nText('msgShioriDeleted') + "</label>";
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
    
    newRow += "         </div>";
    newRow += "     </div>";
    
    newRow += "</section>";
    $('#pnlTop').after(newRow);
};

// Insert row to grid       
function insertRow(contentid, pageThumbnail, pageTitle, pageText, pageNo, hasMemo, hasMarking, index, contentType) {
    var imgMarkingHide = '<img style="visibility:hidden" class="pen" alt="" src="./img/list/icon_pen.png" />';
    var imgMemoHide = '<img style="visibility:hidden" class="sticker" alt="" src="./img/list/icon_sticker.png" />';
    var imgMarking = '<img class="pen" alt="" src="./img/list/icon_pen.png" />';
    var imgMemo = '<img class="sticker" alt="" src="./img/list/icon_sticker.png" />';
    var newRow = "";
    
    newRow += "<section class='sectionBookmark'>";
    
    newRow +='<div class="cnt_section">';
    newRow +='<span class="check">';
    newRow += "<input type='checkbox' name='chkDelete' value='{\"contentid\":" + contentid + ", \"pageNo\":" + pageNo + ", \"index\": " + index + "}'/>";
    newRow +='</span>';
    newRow +='<a class="img" href="#">';
    newRow +='<img id="pageImg' + contentid + '" src="' + pageThumbnail + '" width="160" height="120" style="display:none;">';
    newRow +='<img id="loadingIcon' + contentid + "_" + pageNo + '" src="./img/data_loading.gif" height="25px" width="25px" style="padding: 46px; "/>';
    newRow +='</a>';

    newRow +='<div class="text">';
Masaru Abe committed
568
    newRow += '<a class="name" href="#">' + COMMON.truncate(pageTitle, 20) + '</a>';
569 570 571 572

    newRow +='<div class="info">';
    newRow += '<ul class="date">';

Masaru Abe committed
573
    var contentText = COMMON.htmlEncode(COMMON.getLines(pageText, 3));
574

Masaru Abe committed
575
    newRow += '<li><label id="Label1">' + COMMON.truncate(contentText, 60) + '</label></li>';
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622

    newRow +='</ul>';
    newRow += '<ul class="pic">';


    //Resize Image
    var imgTemp = new Image();

    imgTemp.onload = function () {

        if (imgTemp.width > imgTemp.height) {

            $("img#pageImg" + contentid).attr('height', '');
            $("img#pageImg" + contentid).removeAttr('height');
            $("img#pageImg" + contentid).attr('width', '120');
            var realHeight = (120 * imgTemp.height) / imgTemp.width;
            $("img#pageImg" + contentid).css('padding-top', (120 - realHeight) / 2 + 'px');
        }
        else {
            $("img#pageImg" + contentid).attr('width', '');
            $("img#pageImg" + contentid).removeAttr('width');
            $("img#pageImg" + contentid).attr('height', '120');
            $("img#pageImg" + contentid).css('padding-top', '0px');
        }

        $("#loadingIcon" + contentid + "_" + pageNo).fadeOut('slow', function () {
            $("img#pageImg" + contentid).fadeIn('slow');
        });
    };

    imgTemp.src = pageThumbnail;

    if (hasMemo) {
        newRow += '<li><a href="#">' + imgMemo + '</a></li>';
    }
    else {
        newRow += '<li><a href="#">' + imgMemoHide + '</a></li>';
    }

    if (hasMarking) {
        newRow += '<li><a href="#">' + imgMarking + '</a></li>';
    }
    else {
        newRow += '<li><a href="#">' + imgMarkingHide + '</a></li>';
    }


623
    newRow += '<li class="pageno"><label id="Label2" class="lang" lang="txtPage">' + I18N.i18nText('txtPage') + '</label><label id="Label3">' + pageNo + '</label></li>';
624

625
    newRow += "<li><a class='read lang' name='dspRead' value='{\"contentid\":\"" + contentid + "\", \"pageNo\":\"" + pageNo + "\", \"contentType\":\"" + contentType + "\" }' lang='txtRead'>" + I18N.i18nText('txtRead') + "</a></li>";  	
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
    newRow +='</ul>';
    newRow +='</div>';
    newRow +='</div>';
    newRow +='</div>';

    newRow += "</section>";

    $('#pnlTop').after(newRow);
};


/*
----------------------------------------------------------------------------
Event groups [ end ]
----------------------------------------------------------------------------
*/



/*
----------------------------------------------------------------------------
Setting dialog [start]
----------------------------------------------------------------------------
*/
$(function () {
    
    $("#dspTitleNm").click(dspTitleNm_Click);
    $("#dspTitleNmKn").click(dspTitleNmKn_Click);
    $("#dspPubDt").click(dspPubDt_Click);

    // Check JP language and show title kana
657
    if (getCurrentLanguage() != COMMON.Consts.ConstLanguage_Ja) {
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
        $("#dspTitleNmKn").hide();
        $("#dspTitleNmKn_Seperate").hide();
    }
    else {
        $("#dspTitleNmKn").show();
        $("#dspTitleNmKn_Seperate").show();
    }
});


// Contains non-exist content
var bookmark_errorContent = [];

// Contain contents
var collection_contents = [];

/*
    Get all detail pages of content in bookmark
*/
function bookmark_collectAllPages() {
    var arrBookMarks = ClientData.BookMarkData();
    for (var nIndex = 0; nIndex < collection_contents.length; nIndex++) {

        var contentid = collection_contents[nIndex].contentid;
        var pages = [];

        // Collect all pages of current content
        for (var nIndex1 = 0; nIndex1 < arrBookMarks.length; nIndex1++) {
            // Found content
            if (arrBookMarks[nIndex1].contentid == contentid) {
                pages.push({ pageNo: arrBookMarks[nIndex1].pageNo, pageText: "", pageThumbnail: "", existed: false });
            }
        }
        // Add collected pages to content
        collection_contents[nIndex].pages = pages;

        // Join pages to request to server
        var strPageNos = buildPageNos(collection_contents[nIndex].pages);
        
            // Call api to get all details of pages 1 time
698
        AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webContentPage", "GET",
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
                    { contentId: contentid, sid: ClientData.userInfo_sid(), pageNos: strPageNos, thumbnailFlg: 1 },
                    function (data) {

                        collection_contents[nIndex].contentTitle = data.contentTitle;
                        collection_contents[nIndex].contentTitleKana = data.contentTitleKana;
                        for (var nIndex2 = 0; nIndex2 < collection_contents[nIndex].pages.length; nIndex2++) {

                            var comparePageNo = collection_contents[nIndex].pages[nIndex2].pageNo;

                            for (var nIndex3 = 0; nIndex3 < data.pages.length; nIndex3++) {
                                if (data.pages[nIndex2] && comparePageNo == data.pages[nIndex2].pageNo) {
                                    // Set flag to determine page existed
                                    collection_contents[nIndex].pages[nIndex2].existed = true;
                                    // Store detail of page
                                    collection_contents[nIndex].pages[nIndex2].pageText = data.pages[nIndex2].pageText;
                                    collection_contents[nIndex].pages[nIndex2].pageThumbnail = data.pages[nIndex2].pageThumbnail;
                                }
                                else if (contentTypes[contentid] == "none" && data.pages.length > 0) {
                                    collection_contents[nIndex].pages[nIndex2].existed = true;
                                    // Store detail of page
                                    collection_contents[nIndex].pages[nIndex2].pageText = ''; //data.pages[0].pageText;
                                    collection_contents[nIndex].pages[nIndex2].pageThumbnail = pathImgContentNone; //data.pages[nIndex2].pageThumbnail;
                                }
                            }

                        }
                    },
                    function () { // when server response error

                        if (contentTypes[contentid] == "none") {
                            collection_contents[nIndex].contentTitle = contentName[contentid];
                            for (var nIndex2 = 0; nIndex2 < collection_contents[nIndex].pages.length; nIndex2++) {
                                collection_contents[nIndex].pages[nIndex2].existed = true;
                                collection_contents[nIndex].pages[nIndex2].pageThumbnail = pathImgContentNone;
                                collection_contents[nIndex].pages[nIndex2].pageText = '';

                            }
                        }
                    }
        );
       
    }
};
/*
    Build pageNos
*/
function buildPageNos(pages) {
    var strResult = "";
    for (var nIndex = 0; nIndex < pages.length; nIndex++) {
        if (strResult == "") {
            strResult = "" + pages[nIndex].pageNo;
        }
        else {
            strResult += "," + pages[nIndex].pageNo;
        }
    }
    return strResult;
};

/*
Check a content is error or not 
*/
function IsErrorContent(strContentId) {
    var isError = false;
    
    for (var nIndex = 0; nIndex < bookmark_errorContent.length; nIndex++) {
        if (strContentId == bookmark_errorContent[nIndex].contentid) {
            isError = true;
            break;
        }
    }
    return isError;
};

/*
Check a content is checked + ok 
*/
function IsOKCheckedContent(strContentId) {
    var isOK = false;

    for (var nIndex = 0; nIndex < collection_contents.length; nIndex++) {
        if (strContentId == collection_contents[nIndex].contentid) {
            isOK = true;
            break;
        }
    }
    return isOK;
};

// Add OK checked content
function AddContent(strContentId, contentType) {
    var isFound = false;
    for (var nIndex = 0; nIndex < collection_contents.length; nIndex++) {
        if (collection_contents[nIndex].contentid == strContentId) {
            isFound = true;
            break;
        }
    }
    // Add to bufer if it does not exist
    if(!isFound) {
        collection_contents.push({ 'contentid': strContentId, 'contentType': contentType,  'contentTitle': "", 'contentTitleKana': "", 'pages': [] });
    }
};

/*
  event of changing language
*/
function changeLanguageCallBackFunction() {
807
    if (getCurrentLanguage() != COMMON.Consts.ConstLanguage_Ja) {
808 809 810 811 812 813 814 815 816
        $("#dspTitleNmKn").hide();
        $("#dspTitleNmKn_Seperate").hide();
        $("#txtTitleNmKnAsc").hide();
        $("#txtTitleNmKnDesc").hide();
    }
    else {
        $("#dspTitleNmKn").show();
        $("#dspTitleNmKn_Seperate").show();
        if (ClientData.sortOpt_searchDivision() == 2) { // Kana
817
            HEADER.setStatusSort('#dspTitleNmKn', orderSort == COMMON.Consts.ConstOrderSetting_Asc);
818 819
        }
    }
820
    document.title = I18N.i18nText('dspShiori') + ' | ' + I18N.i18nText('sysAppTitle');
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
};
/*
Synchronize bookmark with server
. Check existence of content
-> Delete absence content in local

. Check existence of pages
-> Delete absence pages in local
*/
function SyncContent() {

    // Reset error contents
    bookmark_errorContent = [];

    // Reset ok checked content
    collection_contents = [];

    // Get bookmarks from local storage
    var arrBookmarks = ClientData.BookMarkData();

    for (var nIndex = arrBookmarks.length - 1; nIndex >= 0; nIndex--) {

        var oneBookMark = arrBookmarks[nIndex];
        // ==================================
        // Check existence of content [start]
        // ==================================
        if (IsErrorContent(oneBookMark.contentid) == false) {
            // If content is ok + checked
            if (IsOKCheckedContent(oneBookMark.contentid) == false) {
                if (!IsExistContent(oneBookMark.contentid)["isExisted"]) {
851
                    if (AVWEB.avwHasError()) {
852
                        // System error excepting 404
853
                    	AVWEB.showSystemError();
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
                        return;
                    }
                    else {
                        // Add to list of error content
                        bookmark_errorContent.push({ contentid: oneBookMark.contentid });
                        // Remove bookmark
                        arrBookmarks.splice(nIndex, 1);
                        ClientData.isChangedBookmark(true);
                    }
                }
                // ==================================
                // Check existence of content [ end ]
                // ==================================
                else {
                    // Add nromal content
                    AddContent(oneBookMark.contentid, IsExistContent(oneBookMark.contentid)["contentType"]);
                }
            }
        }
        else {
            arrBookmarks.splice(nIndex, 1);
            ClientData.isChangedBookmark(true);
        }
    }

    // Set back to storage
    ClientData.BookMarkData(arrBookmarks);

};

/*
Check content whether existed or not
*/
function IsExistContent(strContentId) {
    var isExisted = false;
    var contentType = '';
    var result = [];
    var params = {
        sid: ClientData.userInfo_sid(),
        getType: '1',
        contentId: strContentId
    };
896
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webGetContent", 'GET', params,
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917
                function (data) {
                    isExisted = true;
                    contentType = data.contentData.contentType;

                    result["isExisted"] = isExisted;
                    result["contentType"] = contentType;

                    // save content type
                    contentTypes[strContentId] = contentType;
                    contentName[strContentId] = data.contentData.contentName;
                    // save alert message level
                    messageLevel[strContentId] = { alertMessageLevel: data.contentData.alertMessageLevel, alertMessage: data.contentData.alertMessage };

                },
                function (xmlHttpRequest, txtStatus, errorThrown) {
                    if (xmlHttpRequest.status == 404) {
                        isExisted = false;
                    }
                    else {
                        // Show system error
                        isExisted = true;  // Mark this flag to prevent bookmarks from deleting
918
                        AVWEB.showSystemError();
919 920 921 922 923 924 925 926 927 928 929 930
                    }
                });
                
    return result;
};

/*
----------------------------------------------------------------------------
Setting dialog [ end ]
----------------------------------------------------------------------------
*/

Masaru Abe committed
931 932 933 934 935 936 937 938 939 940
//function truncate(strInput, length){
//    if (strInput.length <= length)
//    {
//        return strInput;
//    }
//    else
//    {
//        return strInput.substring(0, length) + "...";
//    }
//};