history.js 50.8 KB
Newer Older
1

2 3 4
//名前空間用のオブジェクトを用意する
var HISTORY = {};

5
//Start Declare Variables
Masaru Abe committed
6 7 8 9 10 11
//----Constant-----------//
//var DEFAULT_DISP_NUMBER_RECORD_FROM = 1;
//var DEFAULT_DISP_NUMBER_RECORD_TO = 15;
HISTORY.DEFAULT_SORT_TYPE = '4';
HISTORY.DEFAULT_SORT_ORDER = '2';
HISTORY.DEFAULT_SEARCH_DIVISION = 0;
12

Masaru Abe committed
13
//var iNumberOfNextRecord = 15;
14 15

//Thumbnail array
Masaru Abe committed
16
HISTORY.thumbnailArr = [];
17
//Contdent type array.
Masaru Abe committed
18 19 20 21 22 23 24 25
HISTORY.contentTypeArr = [];
HISTORY.contentIdArray = [];

HISTORY.totalPage;
HISTORY.contentViewData = [];
HISTORY.noRecordFlg = false;
HISTORY.home_isMove = false;
HISTORY.history_contentTitleKana = [];
26 27
//スクロール復帰
HISTORY.scrollTop = 0;
28 29

$(document).ready(function(){
30

31
 	if (!AVWEB.avwCheckLogin(COMMON.ScreenIds.Login)){
32
 		return;
33 34
 	}

Masaru Abe committed
35
 	COMMON.LockScreen();
36

37
	document.title = I18N.i18nText('dspViewHistory') + ' | ' + I18N.i18nText('sysAppTitle');
38

39
	ClientData.BookmarkScreen(COMMON.ScreenIds.History);
40

41
 	if(ClientData.requirePasswordChange() != 1){
42
 		if(ClientData.ReadingContentIds() == null || ClientData.ReadingContentIds() == 'undefined' || ClientData.ReadingContentIds().length == 0){
43
		}else{
Masaru Abe committed
44
			HISTORY.syncReadingContent();
45
		}
46

47
	 	//remove hover effect when is touch device
Masaru Abe committed
48
 		HISTORY.removeHoverCss();
49

50
	 	//Render Grid
Masaru Abe committed
51
	 	HISTORY.renderGridView();
52

53
		//Go To Details Page
54
		$('#main-ws canvas').live('click', HISTORY.canvasClickFunction);
55 56
	    $('#main-ws canvas').live('touchend', HISTORY.canvasClickFunction);
	    $('#main-ws canvas').live('touchmove', function () { HISTORY.home_isMove = true; });
57 58


59
		//Open dialog
60 61
		$('.dialog').live('click', HISTORY.titleClickFunction);
		//$('.dialog').live('touchstart', HISTORY.titleClickFunction);
Masaru Abe committed
62 63
	    $('.dialog').live('touchend', HISTORY.titleClickFunction);
	    $('.dialog').live('touchmove', function () { HISTORY.home_isMove = true; });
64

65
		//Sort Title
66 67
		$('#control-sort-title').click(HISTORY.sortByTitleFunction);

68
		//Sort by title kana
69 70
		$('#control-sort-titlekana').click(HISTORY.sortByTitleKanaFunction);

71
		//sort by release date
72 73
		$('#control-sort-releasedate').click(HISTORY.sortByReleaseDateFunction);

Masaru Abe committed
74
		$('#control-sort-viewdate').click(HISTORY.sortByViewDateFunction);
75

76
		//Go To Details Page
Masaru Abe committed
77 78 79 80
		$('.button-details').live('click', HISTORY.readSubmenuFunction);
		//$('.button-details').live('touchstart', HISTORY.readSubmenuFunction);
		$('.button-details').live('touchend', HISTORY.readSubmenuFunction);
		$('.button-details').live('touchmove', function () { HISTORY.home_isMove = true; });
81

82 83 84
		//Show Share Dialog
		$('.button-share').live('click', HISTORY.showContentShareDlgFunction);
		$('.button-share').live('touchend', HISTORY.showContentShareDlgFunction);
Masaru Abe committed
85
		$('.button-share').live('touchmove', function () { HISTORY.home_isMove = true; });
86

87 88 89 90 91 92 93 94 95 96 97 98
	    $(window).resize(function () {
	        if ($("#contentDetail").css("display") != "none") {
	            // Refresh panel of detail to center.
	            $("#contentDetail").center();
	            if ($("#contentDetail").height() > $(window).height()){
					$("#contentDetail").css('top', '0');
				}
	        }
	    });
 	}
 	else{
 		//Check if Force Change password
Masaru Abe committed
99
		HEADER.checkForceChangePassword();
Masaru Abe committed
100
 	}
101

Masaru Abe committed
102
    if (COMMON.isAnonymousLogin()) {
Masaru Abe committed
103 104 105
        //プッシュメッセージ隠す
        $('#dspPushMessage').hide();
    }
106

107
    //詳細、共有表示パーツ読み込み
108
    $("#inc_detail").load("./inc_detail.html?__UPDATEID__", function (myData, myStatus, xhr){
109
        //読み込み完了時の処理
Masaru Abe committed
110 111 112 113
    	I18N.i18nReplaceText();
    	$('.datepicker').pickadate({
    		format: 'yyyy-mm-dd'
    	});
114
    });
115

116 117 118 119 120
    //ビューア、共有表示パーツ読み込み
    $("#viewer").load("./inc_contentview.html?__UPDATEID__", function (myData, myStatus, xhr){
    	//読み込み完了時の処理
    	I18N.i18nReplaceText();
    });
121 122

});
123 124

//Call API
Masaru Abe committed
125
//HISTORY.abapi = function(name, param, method, callback){
126
//	AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), name, method, param, callback, null);
Masaru Abe committed
127
//};
128 129

///Render Content
Masaru Abe committed
130
HISTORY.renderContent = function(id, text, division, type, order, from, to, cateid, grpid) {
131 132 133 134 135 136 137 138 139 140 141 142
    var params = {
        sid: id,
        searchText: text,
        searchDivision: division,
        sortType: type,
        sortOrder: order,
        //recordFrom: from,
        //recordTo: to,
        categoryId: cateid,
        groupId: grpid
    };

143
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), 'webContentList', 'POST', params,
144
            function (data) {
145

146 147 148 149 150
                $('#content-grid').html('');
                //var htmlTemp = "";
                for (var i = 0; i < data.contentList.length; i++) {
                    post = data.contentList[i];

Masaru Abe committed
151
                    var outputDate = COMMON.formatDeliveryDate(post.contentDeliveryDate);
152
                    //renderViewDate
Masaru Abe committed
153
                    var viewdate = HISTORY.renderViewDate(post.contentId);
154
                    /*
155 156 157 158 159 160 161 162 163 164
                    if (viewdate != null && viewdate != 'undefined' && viewdate != '') {
                       var htmlTemp = '<section class="sectionhistory">'
						+ '	<div class="cnt_section_list">'
						+ '		<a class="img">'
						+ '			<canvas height="110" width="150" id="content-thumbnail' + post.contentId + '" contentid="' + post.contentId + '" style="display:none;">'
						+ '			</canvas>'
	                    + '	        <img id="imgloading' + post.contentId + '" src="./img/data_loading.gif" height="25px" width="25px" style="padding: 46px; "/>'
						+ '		</a>'
						+ '		<div class="text">'
						+ '			<a id="title' + post.contentId + '" class="name dialog" contentid="' + post.contentId + '">'
Masaru Abe committed
165
						+ '             <img class="listIcon" src="' + HEADER.getIconTypeContent(post.contentType)+'" width="20" height="20">'
166
						+               COMMON.truncate(COMMON.htmlEncode(post.contentTitle), 20)
167 168 169 170 171 172 173
						+ '         </a>'
						+ '			<div class="info">'
						+ '				<ul class="date">'
						+ '					<li><span class="lang" lang="txtPubDt"> </span> : ' + outputDate + '</li>'
						+ '					<li><span class="lang" lang="txtViewDt"> </span>:<span id="lblVdate' + post.contentId + '"> </span></li>'
						+ '				</ul>'
						+ '				<ul class="pic">'
174 175
						+ '					<li><img src="' + COMMON.DEFAULT_IMG_OPTION_MEMO + '" id="imgMemo' + post.contentId + '" class="sticker"  /></li>'
						+ '					<li><img src="' + COMMON.DEFAULT_IMG_OPTION_MARKING + '" id="imgBookMark' + post.contentId + '" class="pen"  /></li>'
176
						+ '					<li><ul class="iconList">{share}<li><a class="read lang button-details" contentid="' + post.contentId + '" lang="txtRead">'+I18N.i18nText("txtRead")+'</a></li></ul></li>'
177 178 179 180 181
						+ '				</ul>'
						+ '			</div>'
						+ '		</div>'
						+ '	</div>'
						+ '</section>';
182 183 184 185 186
						var shareHtml = "";
						if( post.readerShare == '1' ){
							shareHtml ='<li><a class="read lang button-share" contentid="' + post.contentId + '" lang="txtShare">'+I18N.i18nText("txtShare")+'</a></li>';
						}
						htmlTemp = htmlTemp.replace(/\{share\}/g, shareHtml);
187 188
						//効率化
						//$('#content-grid').append(htmlTemp);
189
                    }*/
190
                }
191

192 193 194

                for (var i = 0; i < data.contentList.length; i++) {
                    post = data.contentList[i];
Masaru Abe committed
195
                    var viewdate = HISTORY.renderViewDate(post.contentId);
196 197

                    // save alert message level
Masaru Abe committed
198
                    LIMIT_ACCESS_CONTENT.messageLevel[post.contentId] = { alertMessageLevel:post.alertMessageLevel, alertMessage:post.alertMessage};
199 200

                    if (viewdate != null && viewdate != 'undefined' && viewdate != '') {
201

202 203 204
                        //assign thumbnail to array
                        var formatThumbnail = post.contentThumbnail;
                        if((formatThumbnail != null) && (formatThumbnail != 'undefined') && (formatThumbnail != '')){
Masaru Abe committed
205
                            formatThumbnail = COMMON.formatStringBase64(formatThumbnail);
206
                        }
207

Masaru Abe committed
208
                        HISTORY.thumbnailArr.push({ contentId: post.contentId, thumbnail:  formatThumbnail});
209 210

                        //Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Assign content type to array to manage.
211
                        //assign content type to array
Masaru Abe committed
212
                        HISTORY.contentTypeArr.push({ contentId: post.contentId, contentType: post.contentType });
213 214
                        //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Assign content type to array to manage.

215
                        //効率化
216
                        //Check if user has read this content or not.
217
                        //HISTORY.checkUserHasReadContent(post.contentId, post.resourceVersion, post.metaVersion);
218 219

                        //assign version to array
Masaru Abe committed
220
                        COMMON.resourceVersionArr.push({ contentid: post.contentId, resourceversion: post.resourceVersion });
221 222

                        //assign meta version to array
Masaru Abe committed
223
                        COMMON.metaVersionArr.push({ contentid: post.contentId, metaversion: post.metaVersion });
224 225

                        //Check if content has marking or memo
Masaru Abe committed
226
                        HISTORY.checkContentMarkingMemoOption(post.contentId);
227

228 229
                        //効率化
                        //$('#lblVdate' + post.contentId).html(viewdate);
230

Masaru Abe committed
231
                        HISTORY.addReadContentToArray(post.contentId, post.resourceVersion, post.metaVersion, post.contentThumbnail, post.contentTitle, HISTORY.returnContentTitleKana(post.contentId), post.contentDeliveryDate,post.contentType, post.readerShare );
232

Masaru Abe committed
233
                        //HISTORY.showContentThumbnail();
234 235 236 237 238 239 240 241 242
                    }
                }

                if (data.recordFrom) {
                    ClientData.searchCond_recordFrom(data.recordFrom);
                }
                if (data.recordTo) {
                    ClientData.searchCond_recordTo(data.recordTo);
                }
Masaru Abe committed
243
                HISTORY.totalPage = data.totalRecord;
244
                //Render Page number
Masaru Abe committed
245
                HISTORY.reRenderPageNumber(HISTORY.totalPage, HISTORY.totalPage);
246 247 248 249 250

            }, null);
};

//Handle language
Masaru Abe committed
251
HISTORY.handleLanguage = function(){
252

253
	//if(ClientData.userInfo_language() == COMMON.Consts.ConstLanguage_En || ClientData.userInfo_language() == COMMON.Consts.ConstLanguage_Ko)
Masaru Abe committed
254
    if (I18N.getCurrentLanguage() == COMMON.Consts.ConstLanguage_En || I18N.getCurrentLanguage() == COMMON.Consts.ConstLanguage_Ko)
255 256 257 258 259 260 261
	{
		$('#control-sort-titlekana').css('display','none');
		$('#control-sort-titlekana-off').css('display','none');
		$('#label-sort-titlekana').css('display','none');
		$('#separate').css('display','none');
		$("#titlekana-sorttype").html('');
	}
262
	else {
263 264 265
	    if (ClientData.searchCond_sortOrder() != null && ClientData.searchCond_sortOrder() != 'undefined' || ClientData.searchCond_sortType() != '') {
	        var typeSort = ClientData.searchCond_sortType();
	        var orderSort = ClientData.searchCond_sortOrder();
266
            HEADER.setStatusSort('#'+$('#menu_sort li.current a').attr('id'),orderSort == COMMON.Consts.ConstOrderSetting_Asc);
267
	    }
268

Masaru Abe committed
269
		if(HISTORY.noRecordFlg){
270 271
			$('#label-sort-titlekana').css('display','block');
			$('#separate').css('display','block');
272

273
			$('#control-sort-titlekana-off').css('display','block');
274

275
			$('#content-grid').html("<div id='msgHistoryNotExist'>" + I18N.i18nText('msgHistoryNotExist') + "</div>");
276 277 278 279
		}else{
			$('#control-sort-titlekana').css('display','block');
			$('#separate').css('display','block');
		}
280 281
	}

282 283 284
};

//Initial Screen
Masaru Abe committed
285
HISTORY.renderGridView = function(){
286

287 288
	var fromPage = '';
	var toPage = '';
Masaru Abe committed
289 290
	var sortType = HISTORY.DEFAULT_SORT_TYPE;
	var sortOrder = HISTORY.DEFAULT_SORT_ORDER;
291
	var searchText = '';
Masaru Abe committed
292
	var searchDivision = HISTORY.DEFAULT_SEARCH_DIVISION;
293 294 295
	var genreId = '';
	var groupId = '';
	var sid = ClientData.userInfo_sid();
296

297
	ClientData.searchCond_recordFrom(fromPage);
298

299
	ClientData.searchCond_recordTo(toPage);
300

301 302 303 304 305 306 307
	ClientData.searchCond_sortType(sortType);

	ClientData.searchCond_sortOrder(sortOrder);

	ClientData.searchCond_searchDivision(searchDivision);

	//Handle display sort
Masaru Abe committed
308
	HISTORY.handleSortDisp();
309

310 311
	//Display user name
	$('#login-username').html(ClientData.userInfo_loginId_session());
312

313
	//Refresh GridView
Masaru Abe committed
314
	HISTORY.refreshGrid();
315

316
	if(ClientData.ReadingContentIds() == null || ClientData.ReadingContentIds() == 'undefined' || ClientData.ReadingContentIds().length == 0){
Masaru Abe committed
317 318 319
		HISTORY.displayResultNoRecord();
		HISTORY.noRecordFlg = true;
		HISTORY.reRenderPageNumber(0,0);
320 321 322
	}
	else{
		//Render Gridview
Masaru Abe committed
323 324
		HISTORY.renderContent(sid, searchText, searchDivision, 3, sortOrder, fromPage, toPage, genreId, groupId);
		HISTORY.sortByViewDateDesc();
325
	}
326

327
	//Language Handle
Masaru Abe committed
328
	HISTORY.handleLanguage();
329 330
};

331
//Canvas Click function
Masaru Abe committed
332
HISTORY.canvasClickFunction = function(e){
333 334 335
    if (e) {
        e.preventDefault();
    }
Masaru Abe committed
336 337
    if (HISTORY.home_isMove == true) {
    	HISTORY.home_isMove = false;
338 339
        return;
    }
340

341 342 343 344 345
	var contentId = $(this).attr('id');
	var outputId = contentId.substring(17);

    // Set content id for screen: content detail
	ClientData.contentInfo_contentId(outputId);
346

347
	// Get image of selected image
Masaru Abe committed
348
	var base64String = HISTORY.returnThumbnail(outputId);
349 350 351
	ClientData.contentInfo_contentThumbnail(base64String);

    //Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Declare variable handle contentType of content.
Masaru Abe committed
352
    var contentType = HISTORY.returnContentType(outputId);
353 354
    ClientData.contentInfo_contentType(contentType);
    //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Declare variable handle contentType of content.
355

356 357
	//Store Content id that user has read
	if(ClientData.ReadingContentIds().length > 0){
Masaru Abe committed
358
		HISTORY.contentIdArray = ClientData.ReadingContentIds();
359

Masaru Abe committed
360 361
		for(var nIndex = 0; nIndex < HISTORY.contentIdArray.length; nIndex++){
			if(HISTORY.contentIdArray[nIndex].contentid == outputId){
362 363 364 365 366
				checkflag = true;
				break;
			}
			else{
				checkflag = false;
367
			}
368
		}
369

370
		if(!checkflag){
Masaru Abe committed
371
			HISTORY.contentIdArray.push({contentid: outputId, viewdate: '', originviewdate: ''});
372 373 374
		}
	}
	else{
Masaru Abe committed
375
		HISTORY.contentIdArray.push({contentid: outputId, viewdate: '', originviewdate: ''});
376
	}
377

378 379 380
	//Renew ReadingContentID
	var newArray = [];
	ClientData.ReadingContentIds(newArray);
381

382
	//Set data for readingcontentid
Masaru Abe committed
383
	ClientData.ReadingContentIds(HISTORY.contentIdArray);
384

385
	//Set ResouceVersion for content
Masaru Abe committed
386
	COMMON.setResourceVersionData(outputId);
387

388
	//Set MetaVersion for content
Masaru Abe committed
389
	COMMON.setMetaVersionData(outputId);
390

391
	//Delete 'new' icon
Masaru Abe committed
392
	HISTORY.drawEditImage(outputId);
393 394

	//Open content Detail
Masaru Abe committed
395
	DETAIL.openContentDetail();
396 397 398
};

//Re-render page from and total record
Masaru Abe committed
399
HISTORY.reRenderPageNumber = function(dispRecord, dispTotal){
Masaru Abe committed
400

Masaru Abe committed
401 402 403
	if( HISTORY.contentViewData.length ){
		$('#dispPage').html(HISTORY.contentViewData.length);
		$('#totalPage').html(HISTORY.contentViewData.length);
Masaru Abe committed
404 405 406 407 408 409 410 411 412
		$('#dispPage').css('visibility','visible');
		$('#totalPage').css('visibility','visible');
		$('.pageNumControl').css('visibility','visible');
	} else {
		$('#dispPage').css('visibility','hidden');
		$('#totalPage').css('visibility','hidden');
		$('.pageNumControl').css('visibility','hidden');
	}

413 414 415
};

//Sort By Title Function
Masaru Abe committed
416
HISTORY.sortByTitleFunction = function(){
417

418 419 420 421 422 423
	var sortOrder = ClientData.searchCond_sortOrder();
	var sortType = ClientData.searchCond_sortType();
	var sid = ClientData.userInfo_sid();
	var recordFrom = null;
	var recordTo = null;
	var genreId = ClientData.searchCond_genreId();
424
	var groupId = ClientData.searchCond_groupId();
425

426
	if(sortOrder == COMMON.Consts.ConstOrderSetting_Asc)
427 428
	{
		if(sortType == '1'){
429
			sortOrder = COMMON.Consts.ConstOrderSetting_Desc;
430
			HISTORY.sortByTitleDesc();
431 432
		}
		else{
433
			sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
434 435 436
			HISTORY.sortByTitleAsc();
		}
		ClientData.searchCond_sortOrder(sortOrder);
437 438
	}
	else
439
	{
440
		sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
441 442 443
		ClientData.searchCond_sortOrder(sortOrder);
		HISTORY.sortByTitleAsc();
	}
444

445
    HEADER.setStatusSort('#control-sort-title',sortOrder == COMMON.Consts.ConstOrderSetting_Asc);
446 447 448 449 450

	sortType = '1';
	ClientData.searchCond_sortType(sortType);

	//refresh Gridview
Masaru Abe committed
451
	//HISTORY.refreshGrid();
452

Masaru Abe committed
453
	//HISTORY.renderContent(sid, '', ClientData.searchCond_searchDivision(), sortType, sortOrder, recordFrom, recordTo, genreId, groupId);
454 455 456
};

//Sort By Title Kana function
Masaru Abe committed
457
HISTORY.sortByTitleKanaFunction = function(){
458

459 460 461 462 463 464
	var sortOrder = ClientData.searchCond_sortOrder();
	var sortType = ClientData.searchCond_sortType();
	var sid = ClientData.userInfo_sid();
	var recordFrom = null;
	var recordTo = null;
	var genreId = ClientData.searchCond_genreId();
465
	var groupId = ClientData.searchCond_groupId();
466

467
	if(sortOrder == COMMON.Consts.ConstOrderSetting_Asc)
468
	{
469
		if(sortType == '2'){
470
			sortOrder = COMMON.Consts.ConstOrderSetting_Desc;
Masaru Abe committed
471
			HISTORY.sortByTitleKanaDesc();
472 473
		}
		else{
474
			sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
Masaru Abe committed
475
			HISTORY.sortByTitleKanaAsc();
476 477
		}
		ClientData.searchCond_sortOrder(sortOrder);
478 479 480
	}
	else
	{
481
		sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
482
		ClientData.searchCond_sortOrder(sortOrder);
Masaru Abe committed
483
		HISTORY.sortByTitleKanaAsc();
484 485
	}

486
    HEADER.setStatusSort('#control-sort-titlekana',sortOrder == COMMON.Consts.ConstOrderSetting_Asc);
487

488 489
	sortType = '2';
	//refresh gridview
Masaru Abe committed
490
	//HISTORY.refreshGrid();
491

492
	ClientData.searchCond_sortType(sortType);
Masaru Abe committed
493
	//HISTORY.renderContent(sid, '', ClientData.searchCond_searchDivision(), sortType, sortOrder, null, null, genreId, groupId);
494

495 496 497
};

//Sort By Release Date
Masaru Abe committed
498
HISTORY.sortByReleaseDateFunction = function(){
499

500 501 502 503 504 505
	var sortOrder = ClientData.searchCond_sortOrder();
	var sortType = ClientData.searchCond_sortType();
	var sid = ClientData.userInfo_sid();
	var recordFrom = null;
	var recordTo = null;
	var genreId = ClientData.searchCond_genreId();
506
	var groupId = ClientData.searchCond_groupId();
507

508
	if(sortOrder == COMMON.Consts.ConstOrderSetting_Asc)
509 510
	{
		if(sortType == '3'){
511
			sortOrder = COMMON.Consts.ConstOrderSetting_Desc;
Masaru Abe committed
512
			HISTORY.sortByPublishDateDesc();
513 514
		}
		else{
515
			sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
Masaru Abe committed
516
			HISTORY.sortByPublishDateAsc();
517
		}
518
		ClientData.searchCond_sortOrder(sortOrder);
519 520 521
	}
	else
	{
522 523
		sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
		ClientData.searchCond_sortOrder(sortOrder);
Masaru Abe committed
524
		HISTORY.sortByPublishDateAsc();
525
	}
526

527
    HEADER.setStatusSort('#control-sort-releasedate',sortOrder == COMMON.Consts.ConstOrderSetting_Asc);
528 529 530

	sortType = '3';
	ClientData.searchCond_sortType(sortType);
Masaru Abe committed
531
	//HISTORY.renderContent(sid, '', ClientData.searchCond_searchDivision(), sortType, sortOrder, recordFrom, recordTo, genreId, groupId);
532 533 534
};

//Sort By View Date
Masaru Abe committed
535
HISTORY.sortByViewDateFunction = function(){
536

537 538 539
	var sortOrder = ClientData.searchCond_sortOrder();
	var sortType = ClientData.searchCond_sortType();

540
	if(sortOrder == COMMON.Consts.ConstOrderSetting_Asc)
541 542
	{
		if(sortType == '4'){
543
			sortOrder = COMMON.Consts.ConstOrderSetting_Desc;
Masaru Abe committed
544
			HISTORY.sortByViewDateDesc();
545 546
		}
		else{
547
			sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
Masaru Abe committed
548
			HISTORY.sortByViewDateAsc();
549
		}
550
		ClientData.searchCond_sortOrder(sortOrder);
551 552 553
	}
	else
	{
554
		sortOrder = COMMON.Consts.ConstOrderSetting_Asc;
Masaru Abe committed
555
		HISTORY.sortByViewDateAsc();
556 557
		ClientData.searchCond_sortOrder(sortOrder);
	}
558

559
	HEADER.setStatusSort('#control-sort-viewdate',sortOrder == COMMON.Consts.ConstOrderSetting_Asc);
560 561

	sortType = '4';
562 563 564

	ClientData.searchCond_sortType(sortType);

565 566 567
};

//Get Thumnail base on contentid
Masaru Abe committed
568
HISTORY.returnThumbnail = function(contentid){
569

Masaru Abe committed
570 571 572
	for(var i = 0; i < HISTORY.thumbnailArr.length; i++){
		if(HISTORY.thumbnailArr[i].contentId == contentid){
			return HISTORY.thumbnailArr[i].thumbnail;
573 574 575 576 577 578
		}
	}
};

//Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Create new function to return content type of content.
//Get content type base on contentid
Masaru Abe committed
579
HISTORY.returnContentType = function(contentid){
580
    //Array Length
Masaru Abe committed
581
    var iArrCnt = HISTORY.contentTypeArr.length;
582

583 584
    //Get contentType in array by contentId
    for(var i = 0; i < iArrCnt; i++){
Masaru Abe committed
585 586
        if (HISTORY.contentTypeArr[i].contentId == contentid) {
            return HISTORY.contentTypeArr[i].contentType;
587 588 589 590 591
        }
    }
};

//Dialog Read Button CLick
Masaru Abe committed
592
HISTORY.readSubmenuFunction = function(e){
593 594 595
    if (e) {
        e.preventDefault();
    }
Masaru Abe committed
596 597
    if (HISTORY.home_isMove == true) {
    	HISTORY.home_isMove = false;
598 599
        return;
    }
600

601 602 603
	var contentId = $(this).attr('contentid');

    // check limit of content
Masaru Abe committed
604
	LIMIT_ACCESS_CONTENT.checkLimitContent(contentId,
Masaru Abe committed
605
        function()
606
        {
Masaru Abe committed
607
    		HISTORY.readSubmenuFunction_callback(contentId);
Masaru Abe committed
608 609 610 611
        },
        function(){
        }
    );
612 613 614 615

};

// read content callback
616
HISTORY.readSubmenuFunction_callback = function(contentId){
Masaru Abe committed
617
    var contentThumbnail = HISTORY.returnThumbnail(contentId);
618 619 620
	var date = new Date();
	var month = date.getMonth()+1;
	var day = date.getDate();
621

Masaru Abe committed
622
	var outputDate = COMMON.formatNormalDate(day, month, date.getFullYear());
623

624 625
	ClientData.contentInfo_contentId(contentId);
	ClientData.contentInfo_contentThumbnail(contentThumbnail);
626 627

	//Start Function : No.12 -- Editor : Le Long -- Date : 08/01/2013 -- Summary : Store contentType to storage.
Masaru Abe committed
628
	var contentType = HISTORY.returnContentType(contentId);
629
	ClientData.contentInfo_contentType(contentType);
630
	//End Function : No.12 -- Editor : Le Long -- Date : 08/01/2013 -- Summary : Store contentType to storage.
631
	var checkflag = false;
632

633 634
	//Store Content id that user has read
	if(ClientData.ReadingContentIds().length > 0){
Masaru Abe committed
635
		HISTORY.contentIdArray = ClientData.ReadingContentIds();
636

Masaru Abe committed
637 638
		for(var nIndex = 0; nIndex < HISTORY.contentIdArray.length; nIndex++){
			if(HISTORY.contentIdArray[nIndex].contentid == contentId){
639
				checkflag = true;
Masaru Abe committed
640 641 642
				if(HISTORY.contentIdArray[nIndex].viewdate == null || HISTORY.contentIdArray[nIndex].viewdate == 'undefined' || HISTORY.contentIdArray[nIndex].viewdate == ''){
					HISTORY.contentIdArray[nIndex].viewdate = outputDate;
					HISTORY.contentIdArray[nIndex].originviewdate = date;
643 644 645 646 647
				}
				break;
			}
			else{
				checkflag = false;
648
			}
649
		}
650

651
		if(!checkflag){
Masaru Abe committed
652
			HISTORY.contentIdArray.push({contentid: contentId, viewdate: outputDate, originviewdate: date});
653 654 655
		}
	}
	else{
Masaru Abe committed
656
		HISTORY.contentIdArray.push({contentid: contentId, viewdate: outputDate, originviewdate: date});
657
	}
658

659 660 661
	//Renew ReadingContentID
	var newArray = [];
	ClientData.ReadingContentIds(newArray);
662

663
	//Set ResouceVersion for content
Masaru Abe committed
664
	COMMON.setResourceVersionData(contentId);
665

666
	//Set MetaVersion for content
Masaru Abe committed
667
	COMMON.setMetaVersionData(contentId);
668

669
	//Set data for readingcontentid
Masaru Abe committed
670
	ClientData.ReadingContentIds(HISTORY.contentIdArray);
671 672

	ClientData.IsRefresh(false);
673 674

    //Start Function : No.12 -- Editor : Le Long -- Date : 08/02/2013 -- Summary : Check content type other for download.
675
    //For testing without other Type.
676
    //contentType = COMMON.ContentTypeKeys.Type_Others;
677

678
    if(contentType == COMMON.ContentTypeKeys.Type_Others){
679
        //Download content
Masaru Abe committed
680
        HEADER.downloadResourceById(contentId);
681
        // redraw content remove new icon
Masaru Abe committed
682
        HISTORY.drawEditImage(contentId);
683
    }
684
    else if( contentType == COMMON.ContentTypeKeys.Type_Link ){
685
        //link content
Masaru Abe committed
686
        HEADER.viewLinkContentById(contentId);
687
        // redraw content remove new icon
Masaru Abe committed
688
        HISTORY.drawEditImage(contentId);
689 690 691
    }
    else{
        //Go to Conten view page
692
    	//AVWEB.avwScreenMove(COMMON.ScreenIds.ContentView);
693

694 695
        HISTORY.drawEditImage(contentId);
    	HISTORY.showContentView();
696

697
    }
698
    //End Function : No.12 -- Editor : Le Long -- Date : 08/02/2013 -- Summary : Check content type other for download.
699
};
700 701 702 703



//Check if Content Has marking or memo
Masaru Abe committed
704
HISTORY.checkContentMarkingMemoOption = function(contentId){
705
	//Check if contentid has marking
706 707 708 709 710
	if(ClientData.MarkingData().length == 0){
		$('#imgBookMark'+contentId).css('visibility','hidden');
	}
	else{
		for (var nIndex1 = 0; nIndex1 < ClientData.MarkingData().length; nIndex1++) {
711
		    if (ClientData.MarkingData()[nIndex1].contentid == contentId) {
712 713 714 715 716 717 718 719
		        $('#imgBookMark'+contentId).css('visibility','visible');
		        break;
		    }
		    else{
		    	$('#imgBookMark'+contentId).css('visibility','hidden');
		    }
		}
	}
720

721 722 723 724
	if(ClientData.MemoData().length == 0){
		$('#imgMemo'+contentId).css('visibility','hidden');
	}
	else{
725 726
		// Check if contentid has memo
		for (var nIndex1 = 0; nIndex1 < ClientData.MemoData().length; nIndex1++) {
727 728 729 730 731 732 733 734 735 736 737 738 739
	        if (ClientData.MemoData()[nIndex1].contentid == contentId) {
	        	$('#imgMemo'+contentId).css('visibility','visible');
	        	break;
	        }
	        else
	        {
	        	$('#imgMemo'+contentId).css('visibility','hidden');
	        }
	    }
	}
};

//Check if User has read content
Masaru Abe committed
740
HISTORY.checkUserHasReadContent = function(contId, resourceVer, metaVer){
741

742
	var imgThumb = new Image();
Masaru Abe committed
743
    //imgThumb.src = HISTORY.returnThumbnail(contId);
744

745
    var imgIconNew = new Image();
746
    //imgIconNew.src = COMMON.DEFAULT_IMG_CONTENT_NEW;
747

748
    var imgIconEdit = new Image();
749
   //imgIconEdit.src = COMMON.DEFAULT_IMG_CONTENT_EDIT;
750 751

    var c = document.getElementById('content-thumbnail'+contId);
752
    var ctx = c.getContext('2d');
753

754 755 756 757
    var readFlg = false;
    var versionArr = ClientData.ResourceVersion();
    var metaArr = ClientData.MetaVersion();
    var readArr = ClientData.ReadingContentIds();
758

759
    //Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Declare variable handle contentType and Thumbnail of content.
Masaru Abe committed
760 761
    var contentThumbnail = HISTORY.returnThumbnail(contId);
    var contentType = HISTORY.returnContentType(contId);
762
    //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Declare variable handle contentType and Thumbnail of content.
763 764 765 766

    if(readArr == null || readArr <= 0 || readArr == 'undefined'){
		imgThumb.onload = function(){
		 	var resizeImg = HISTORY.resizeResourceThumbnail(imgThumb, c.width, c.height);
767 768 769
			ctx.drawImage(imgThumb, c.width/2 - resizeImg[0]/2, 0, resizeImg[0],  resizeImg[1]);
			imgIconNew.onload = function(){
				ctx.drawImage(imgIconNew, c.width/2 - resizeImg[0]/2, 0);
Masaru Abe committed
770
				HISTORY.showContentThumbnail(contId);
771
			};
772
			imgIconNew.src = COMMON.DEFAULT_IMG_CONTENT_NEW;
773
		};
774

775 776
		//Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
        if(contentThumbnail == '' || contentThumbnail == null){
Masaru Abe committed
777
            if(!COMMON.isPdfContent(contentType)){
778
                var src = HEADER.getThumbnailForOtherType(contentType);
779 780 781
                if( src != '' ){
                    imgThumb.src = src;
                }
782 783 784 785
            }
        }else{
            imgThumb.src = contentThumbnail;
        }
786

787
        //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
788

789 790 791
    }
    else{
    	//Check if user has read this content or not
792
		for (var nIndex1 = 0; nIndex1 < ClientData.ReadingContentIds().length; nIndex1++) {
793
			if(ClientData.ReadingContentIds()[nIndex1].contentid == contId){
794 795
			    imgThumb.onload = function(){
		 			var resizeImg = HISTORY.resizeResourceThumbnail(imgThumb, c.width, c.height);
796
					ctx.drawImage(imgThumb, c.width/2 - resizeImg[0]/2, 0, resizeImg[0],  resizeImg[1]);
Masaru Abe committed
797
					HISTORY.showContentThumbnail(contId);
798 799 800
	    		};
		    	//Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
                if(contentThumbnail == '' || contentThumbnail == null){
Masaru Abe committed
801
                    if(!COMMON.isPdfContent(contentType)){
802
                        var src = HEADER.getThumbnailForOtherType(contentType);
803 804 805
                        if( src != '' ){
                            imgThumb.src = src;
                        }
806 807 808 809
                    }
                }else{
                    imgThumb.src = contentThumbnail;
                }
810

811 812 813 814 815
                //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
		    	readFlg = true;
		    	break;
			}
			else{
816 817
				imgThumb.onload = function(){
				 	var resizeImg = HISTORY.resizeResourceThumbnail(imgThumb, c.width, c.height);
818
					ctx.drawImage(imgThumb, c.width/2 - resizeImg[0]/2, 0, resizeImg[0],  resizeImg[1]);
Masaru Abe committed
819
					HISTORY.showContentThumbnail(contId);
820 821 822
		    		imgIconNew.onload = function(){
		    			ctx.drawImage(imgIconNew, c.width/2 - resizeImg[0]/2, 0);
		    		};
823
		    		imgIconNew.src = COMMON.DEFAULT_IMG_CONTENT_NEW;
824 825 826
		    	};
		    	//Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
                if(contentThumbnail == '' || contentThumbnail == null){
Masaru Abe committed
827
                    if(!COMMON.isPdfContent(contentType)){
828
                        var src = HEADER.getThumbnailForOtherType(contentType);
829 830 831
                        if( src != '' ){
                            imgThumb.src = src;
                        }
832 833 834 835
                    }
                }else{
                    imgThumb.src = contentThumbnail;
                }
836 837 838

                //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
			}
839 840
		}
    }
841

842 843 844 845 846 847 848 849
	//Check if resource version has change
	if(readFlg){
		if(versionArr == null || versionArr <= 0 || versionArr == 'undefined'){
		}
		else{
			for(var nIndex2 = 0; nIndex2 < versionArr.length; nIndex2++){
				if(versionArr[nIndex2].contentid == contId){
					if(versionArr[nIndex2].resourceversion != resourceVer){
850 851
						imgThumb.onload = function(){
    					 	var resizeImg = HISTORY.resizeResourceThumbnail(imgThumb, c.width, c.height);
852
							ctx.drawImage(imgThumb, c.width/2 - resizeImg[0]/2, 0, resizeImg[0],  resizeImg[1]);
Masaru Abe committed
853
							HISTORY.showContentThumbnail(contId);
854 855 856
			    			imgIconEdit.onload = function(){
			    				ctx.drawImage(imgIconEdit, c.width/2 - resizeImg[0]/2, 0);
			    			};
857
							imgIconEdit.src = COMMON.DEFAULT_IMG_CONTENT_EDIT;
858 859 860
			    		};
			    		//Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
                        if(contentThumbnail == '' || contentThumbnail == null){
Masaru Abe committed
861
                            if(!COMMON.isPdfContent(contentType)){
862
                                var src = HEADER.getThumbnailForOtherType(contentType);
863 864 865
                                if( src != '' ){
                                    imgThumb.src = src;
                                }
866 867 868 869
                            }
                        }else{
                            imgThumb.src = contentThumbnail;
                        }
870

871 872
                        //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
			    		break;
873 874
					}
				}
875 876
			}
		}
877

878 879 880 881 882 883
		if(metaArr == null || metaArr <= 0 || metaArr == 'undefined'){
		}
		else{
			for(var nIndex2 = 0; nIndex2 < metaArr.length; nIndex2++){
				if(metaArr[nIndex2].contentid == contId){
					if(metaArr[nIndex2].metaversion != metaVer){
884 885
						imgThumb.onload = function(){
    					 	var resizeImg = HISTORY.resizeResourceThumbnail(imgThumb, c.width, c.height);
886
							ctx.drawImage(imgThumb, c.width/2 - resizeImg[0]/2, 0, resizeImg[0],  resizeImg[1]);
Masaru Abe committed
887
							HISTORY.showContentThumbnail(contId);
888 889 890
			    			imgIconEdit.onload = function(){
			    				ctx.drawImage(imgIconEdit, c.width/2 - resizeImg[0]/2, 0);
			    			};
891
							imgIconEdit.src = COMMON.DEFAULT_IMG_CONTENT_EDIT;
892 893 894
			    		};
			    		//Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
                        if(contentThumbnail == '' || contentThumbnail == null){
Masaru Abe committed
895
                            if(!COMMON.isPdfContent(contentType)){
896
                                var src = HEADER.getThumbnailForOtherType(contentType);
897 898 899
                                if( src != '' ){
                                    imgThumb.src = src;
                                }
900 901 902 903
                            }
                        }else{
                            imgThumb.src = contentThumbnail;
                        }
904

905 906
                        //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Check contentType to set thumbnail.
			    		break;
907 908
					}
				}
909 910 911 912 913 914 915
			}
		}
		readFlg = false;
	}
};

//draw Edit Image
Masaru Abe committed
916
HISTORY.drawEditImage = function(id) {
917
    var img = new Image();
Masaru Abe committed
918
    var imgSrc = HISTORY.returnThumbnail(id);
919

920
    if(imgSrc != null){
921

922 923
    }
    else{
Masaru Abe committed
924
        var contentType = HISTORY.returnContentType(id);
925

926
        var src = HEADER.getThumbnailForOtherType(contentType);
927 928 929
        if( src != '' ){
            imgSrc = src;
        }
930

931
    }
932 933 934

    var c = document.getElementById('content-thumbnail' + id);

935 936 937 938
    //use getContext to use the canvas for drawing
    var ctx = c.getContext('2d');
    ctx.clearRect(0, 0, c.width, c.height);
    img.onload = function () {
Masaru Abe committed
939
        var resizeImg = HISTORY.resizeResourceThumbnail(img, c.width, c.height);
940 941 942
        ctx.drawImage(img, (c.width / 2) - (resizeImg[0] / 2) + 4, c.height - resizeImg[1] + 4, resizeImg[0], resizeImg[1]);
        $("#loadingIcon" + id).fadeOut('slow', function () {
            $('#content-thumbnail' + id).fadeIn('slow');
943
        });
944
    };
945

946 947 948 949
    img.src = imgSrc;
};

//Render User view date
Masaru Abe committed
950
HISTORY.renderViewDate = function(id){
951 952 953 954 955 956 957 958

	for(var i = 0; i < ClientData.ReadingContentIds().length; i++){
		if(ClientData.ReadingContentIds()[i].contentid == id){
			return ClientData.ReadingContentIds()[i].viewdate;
		}
	}
};

Masaru Abe committed
959
HISTORY.returnOriginalViewDate = function(id){
960 961 962 963 964 965 966 967
	for(var i = 0; i < ClientData.ReadingContentIds().length; i++){
		if(ClientData.ReadingContentIds()[i].contentid == id){
			return ClientData.ReadingContentIds()[i].originviewdate;
		}
	}
};

//handle display sort direction
Masaru Abe committed
968
HISTORY.handleSortDisp = function(){
969

970 971 972 973
	$('#control-sort-title').removeClass('active_tops');
	$('#control-sort-titlekana').removeClass('active_tops');
	$('#control-sort-releasedate').removeClass('active_tops');
	$('#control-sort-viewdate').removeClass('active_tops');
974

975 976
	var typeSort;
	var orderSort;
977

978 979 980 981 982 983 984 985 986 987 988
	if(ClientData.searchCond_sortType() == null || ClientData.searchCond_sortType() == 'undefined' || ClientData.searchCond_sortType() == ''){
		$('#title-sorttype').html('');
		$('#title-sorttype').html('');
		$('#titlekana-sorttype').html('');
		$('#rDate-sorttype').html('');
		$('#vDate-sorttype').html('');
	}
	else{
		if(ClientData.searchCond_sortOrder() != null && ClientData.searchCond_sortOrder() != 'undefined' && ClientData.searchCond_sortType() != ''){
			typeSort = ClientData.searchCond_sortType();
			orderSort = ClientData.searchCond_sortOrder();
989

990
			if(typeSort == 1){
991
                HEADER.setStatusSort('#control-sort-title',orderSort == COMMON.Consts.ConstOrderSetting_Asc);
992 993
			}
			else if(typeSort == 2){
994
                HEADER.setStatusSort('#control-sort-titlekana',orderSort == COMMON.Consts.ConstOrderSetting_Asc);
995 996
			}
			else if(typeSort == 3){
997
                HEADER.setStatusSort('#control-sort-releasedate',orderSort == COMMON.Consts.ConstOrderSetting_Asc);
998 999
			}
			else{
1000
                HEADER.setStatusSort('#control-sort-viewdate',orderSort == COMMON.Consts.ConstOrderSetting_Asc);
1001
			}
1002
		}
1003 1004 1005 1006
	}
};

//function Open SubMenu Dialog
Masaru Abe committed
1007
HISTORY.titleClickFunction = function(e){
1008 1009 1010
    if (e) {
        e.preventDefault();
    }
Masaru Abe committed
1011 1012
    if (HISTORY.home_isMove == true) {
    	HISTORY.home_isMove = false;
1013 1014
        return;
    }
1015

1016 1017
	var contentid = $(this).attr('contentid');
	// Get image of selected image
Masaru Abe committed
1018
	var base64String = HISTORY.returnThumbnail(contentid);
1019 1020
	ClientData.contentInfo_contentThumbnail(base64String);
	ClientData.contentInfo_contentId(contentid);
1021

1022
    //Start Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Declare variable handle contentType of content.
Masaru Abe committed
1023
    var contentType = HISTORY.returnContentType(contentid);
1024 1025 1026 1027 1028
    ClientData.contentInfo_contentType(contentType);
    //End Function : No.12 -- Editor : Le Long -- Date : 07/31/2013 -- Summary : Declare variable handle contentType of content.

	//Store Content id that user has read
	if(ClientData.ReadingContentIds().length > 0){
Masaru Abe committed
1029
		HISTORY.contentIdArray = ClientData.ReadingContentIds();
1030

Masaru Abe committed
1031 1032
		for(var nIndex = 0; nIndex < HISTORY.contentIdArray.length; nIndex++){
			if(HISTORY.contentIdArray[nIndex].contentid == contentid){
1033 1034 1035 1036 1037
				checkflag = true;
				break;
			}
			else{
				checkflag = false;
1038
			}
1039
		}
1040

1041
		if(!checkflag){
Masaru Abe committed
1042
			HISTORY.contentIdArray.push({contentid: contentid, viewdate: '', originviewdate: ''});
1043 1044 1045
		}
	}
	else{
Masaru Abe committed
1046
		HISTORY.contentIdArray.push({contentid: contentid, viewdate: '', originviewdate: ''});
1047
	}
1048

1049 1050 1051
	//Renew ReadingContentID
	var newArray = [];
	ClientData.ReadingContentIds(newArray);
1052

1053
	//Set data for readingcontentid
Masaru Abe committed
1054
	ClientData.ReadingContentIds(HISTORY.contentIdArray);
1055

1056
	//Set ResouceVersion for content
Masaru Abe committed
1057
	COMMON.setResourceVersionData(contentid);
1058

1059
	//Set MetaVersion for content
Masaru Abe committed
1060
	COMMON.setMetaVersionData(contentid);
1061

1062
	//Delete 'new' icon
Masaru Abe committed
1063
	HISTORY.drawEditImage(contentid);
1064 1065

	//Open content Detail
Masaru Abe committed
1066
	DETAIL.openContentDetail();
1067 1068 1069
};

//refresh sort order
Masaru Abe committed
1070 1071 1072 1073 1074 1075 1076
//HISTORY.refreshSortTypeOrder = function(){
//	$('#title-sorttype').html('');
//	$('#titlekana-sorttype').html('');
//	$('#rDate-sorttype').html('');
//	$('#rDate-sorttype').html('');
//	$('#vDate-sorttype').html('');
//};
1077 1078

//refresh GridView
Masaru Abe committed
1079
HISTORY.refreshGrid = function(){
1080 1081 1082 1083 1084
    //$('#content-grid').html('');
    $('#content-grid').empty();
	$('.pageNumControl').css('visibility','hidden');
};

Masaru Abe committed
1085 1086
HISTORY.sortByViewDateAsc = function(){
 	var sortArr = HISTORY.contentViewData;
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
  	var t;
  	for(var i = 0; i < sortArr.length; i++){
  		for(var j = 1; j < sortArr.length - i; j++){
  			if(sortArr[j-1].originviewdate > sortArr[j].originviewdate){
  				t = sortArr[j-1];
  				sortArr[j-1] = sortArr[j];
  				sortArr[j] = t;
  			}
  		}
  	}
1097

1098
  	var resultArr = sortArr;
Masaru Abe committed
1099
  	HISTORY.renderContentAfterSort(resultArr);
1100 1101
};

Masaru Abe committed
1102
HISTORY.formatDate = function(originDate){
1103 1104 1105 1106 1107 1108 1109 1110
	var sourceDate = new Date(originDate);
	var year = sourceDate.getFullYear() + 1;
	var month = sourceDate.getMonth();
	var day = sourceDate.getDate();
	var hour = sourceDate.getHours();
	var minute = sourceDate.getMinutes();
	var second = sourceDate.getSeconds();
	var milisecond = sourceDate.getMilliseconds();
1111

1112 1113 1114 1115
	var newDate = new Date(year, month, day, hour, minute, second, milisecond);
	return newDate;
};

Masaru Abe committed
1116 1117
HISTORY.sortByViewDateDesc = function(){
	var sortArr = HISTORY.contentViewData;
1118

1119 1120 1121 1122 1123 1124 1125 1126 1127 1128
	var temp;
	for(var i = 0; i < sortArr.length; i++){
		for(var j = sortArr.length - 1; j > i; j--){
			if(sortArr[j].originviewdate > sortArr[j - 1].originviewdate){
				temp = sortArr[j];
				sortArr[j] = sortArr[j - 1];
			 	sortArr[j - 1] = temp;
			}
		}
	}
1129

1130
	var resultArr = sortArr;
Masaru Abe committed
1131
	HISTORY.renderContentAfterSort(resultArr);
1132 1133
};

Masaru Abe committed
1134 1135
HISTORY.addReadContentToArray = function(strContentId, strResourceVersion, strMetaVersion, strThumbnail, strTitle, strTitleKana, strDelivDate,contentType, readerShare){
    if (HISTORY.contentViewData.length > 0) {
1136
        var flag;
Masaru Abe committed
1137
		for(var j = 0; j < HISTORY.contentViewData.length; j++){
1138
			if(HISTORY.contentViewData[j].contentid == strContentId){
1139 1140 1141 1142 1143 1144 1145
				flag = true;
				break;
			}
			else{
				flag = false;
			}
		}
1146

1147
		if(!flag){
Masaru Abe committed
1148
			HISTORY.contentViewData.push({contentid: strContentId, originviewdate: HISTORY.formatDate(HISTORY.returnOriginalViewDate(strContentId)), contenttitle: strTitle, contenttitlekana: strTitleKana, deliverydate: strDelivDate, resourceversion: strResourceVersion, metaversion: strMetaVersion, thumbnail: COMMON.formatStringBase64(strThumbnail),contenttype:contentType, readerShare:readerShare });
1149
		}
1150

1151
	}else{
Masaru Abe committed
1152
		HISTORY.contentViewData.push({contentid: strContentId, originviewdate: HISTORY.formatDate(HISTORY.returnOriginalViewDate(strContentId)), contenttitle: strTitle, contenttitlekana: strTitleKana, deliverydate: strDelivDate, resourceversion: strResourceVersion, metaversion: strMetaVersion, thumbnail: COMMON.formatStringBase64(strThumbnail),contenttype:contentType, readerShare:readerShare });
1153
	}
1154 1155
};

Masaru Abe committed
1156
HISTORY.showContentThumbnail = function(conid) {
1157 1158 1159 1160 1161 1162

	$('img#imgloading'+conid).fadeOut('slow',function(){
		$('canvas#content-thumbnail'+conid).fadeIn('slow');
	});
};

Masaru Abe committed
1163
HISTORY.syncReadingContent = function(){
1164 1165 1166 1167 1168 1169 1170
	var readArr = ClientData.ReadingContentIds();
	var metaArr = ClientData.MetaVersion();
	var resourceArr = ClientData.ResourceVersion();

	for (var i = readArr.length - 1; i >= 0; i--) {
	    var readContent = readArr[i];

Masaru Abe committed
1171
	    if (!HISTORY.IsExistContent(readContent.contentid)) {
1172 1173 1174 1175 1176
	        readArr.splice(i, 1);
	        metaArr.splice(i, 1);
	        resourceArr.splice(i, 1);
	    }
	    // Do not process next
1177
	    if (AVWEB.avwHasError()) {
1178 1179 1180
	        return;
	    }
	}
1181

1182 1183 1184 1185 1186 1187 1188 1189
	ClientData.ReadingContentIds(readArr);
	ClientData.MetaVersion(metaArr);
	ClientData.ResourceVersion(resourceArr);
};

/*
    Get content title kana if it existed
*/
Masaru Abe committed
1190
HISTORY.getContentNameKana = function(strContentId) {
1191
    var strContentNameKana = null;
Masaru Abe committed
1192 1193 1194
    for (var nIndex = 0; nIndex < HISTORY.history_contentTitleKana.length; nIndex++) {
        if (HISTORY.history_contentTitleKana[nIndex].contentId == strContentId) {
            strContentNameKana = HISTORY.history_contentTitleKana[nIndex].contentNameKana;
1195 1196 1197 1198 1199 1200 1201 1202 1203
            break;
        }
    }
    return strContentNameKana;
};

/*
Check content whether existed or not
*/
Masaru Abe committed
1204
HISTORY.IsExistContent = function(strContentId) {
1205

1206 1207 1208
	if( strContentId == null || strContentId == "" ){
		return false;
	}
1209

1210 1211 1212 1213 1214 1215
    var isExisted = true;
    var params = {
        sid: ClientData.userInfo_sid(),
        getType: '1',
        contentId: strContentId
    };
1216
    AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webGetContent", 'GET', params,
1217 1218
                function (data) {
                    isExisted = true;
Masaru Abe committed
1219
                    HISTORY.history_contentTitleKana.push({ contentId: strContentId, contentNameKana: data.contentData.contentNameKana });
1220 1221 1222 1223 1224 1225 1226 1227
                },
                function (xmlHttpRequest, txtStatus, errorThrown) {
                    if (xmlHttpRequest.status == 404) {
                        isExisted = false;
                    }
                    else {
                        // Show system error
                        isExisted = true;  // Mark this flag to prevent bookmarks from deleting
1228
                        AVWEB.showSystemError();
1229 1230 1231 1232 1233
                    }
                });
    return isExisted;
};

Masaru Abe committed
1234 1235 1236 1237
//HISTORY.changeLanguageCallBackFunction = function(){
//	HISTORY.handleLanguage();
//	document.title = I18N.i18nText('dspViewHistory') + ' | ' + I18N.i18nText('sysAppTitle');
//};
1238

Masaru Abe committed
1239
HISTORY.displayResultNoRecord = function(){
1240
	I18N.i18nReplaceText();
1241
	$('#content-grid').html("<div id='msgHistoryNotExist'>" + I18N.i18nText('msgHistoryNotExist') + "</div>");
1242 1243 1244 1245 1246 1247
	$('#control-nextrecord').css('visibility','hidden');
    $('.control_sort_on').hide();
    $('.control_sort_off').show();
    $('#off-default').addClass('descending_sort');
};

Masaru Abe committed
1248 1249 1250
//HISTORY.enableSort = function(){
//	$('.control_sort_on').show();
//	$('.control_sort_off').hide();
Masaru Abe committed
1251
//};
1252

Masaru Abe committed
1253
HISTORY.sortByTitleAsc = function(){
1254

1255
	var sortArr = HISTORY.contentViewData;
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
  	var t;
  	for(var i = 0; i < sortArr.length; i++){
  		for(var j = 1; j < sortArr.length - i; j++){
  			if(sortArr[j-1].contenttitle.toUpperCase() > sortArr[j].contenttitle.toUpperCase()){
  				t = sortArr[j-1];
  				sortArr[j-1] = sortArr[j];
  				sortArr[j] = t;
  			}
  		}
  	}
1266

1267
	var resultArr = sortArr;
Masaru Abe committed
1268
	HISTORY.renderContentAfterSort(resultArr);
1269 1270
};

Masaru Abe committed
1271 1272
HISTORY.sortByTitleDesc = function(){
	var sortArr = HISTORY.contentViewData;
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
	var temp;
	for(var i = 0; i < sortArr.length; i++){
		for(var j = sortArr.length - 1; j > i; j--){
			if(sortArr[j].contenttitle.toUpperCase() > sortArr[j - 1].contenttitle.toUpperCase()){
				temp = sortArr[j];
				sortArr[j] = sortArr[j - 1];
			 	sortArr[j - 1] = temp;
			}
		}
	}
1283

Masaru Abe committed
1284 1285
	var resultArr = HISTORY.contentViewData;
	HISTORY.renderContentAfterSort(resultArr);
1286 1287
};

Masaru Abe committed
1288
HISTORY.sortByPublishDateAsc = function(){
1289 1290
	var sortArr = HISTORY.contentViewData;

1291 1292 1293
  	var t;
  	for(var i = 0; i < sortArr.length; i++){
  		for(var j = 1; j < sortArr.length - i; j++){
Masaru Abe committed
1294
  			if(HISTORY.formatOriginalPublishDate(sortArr[j-1].deliverydate) > HISTORY.formatOriginalPublishDate(sortArr[j].deliverydate)){
1295 1296 1297 1298 1299 1300 1301 1302
  				t = sortArr[j-1];
  				sortArr[j-1] = sortArr[j];
  				sortArr[j] = t;
  			}
  		}
  	}

	var resultArr = sortArr;
Masaru Abe committed
1303
	HISTORY.renderContentAfterSort(resultArr);
1304 1305
};

Masaru Abe committed
1306 1307
HISTORY.sortByPublishDateDesc = function(){
	var sortArr = HISTORY.contentViewData;
1308 1309 1310
	var temp;
	for(var i = 0; i < sortArr.length; i++){
		for(var j = sortArr.length - 1; j > i; j--){
Masaru Abe committed
1311
			if(HISTORY.formatOriginalPublishDate(sortArr[j].deliverydate) > HISTORY.formatOriginalPublishDate(sortArr[j - 1].deliverydate)){
1312 1313 1314 1315 1316 1317
				temp = sortArr[j];
				sortArr[j] = sortArr[j - 1];
			 	sortArr[j - 1] = temp;
			}
		}
	}
1318

1319
	var resultArr = sortArr;
Masaru Abe committed
1320
	HISTORY.renderContentAfterSort(resultArr);
1321 1322
};

Masaru Abe committed
1323
HISTORY.sortByTitleKanaAsc = function(){
1324
	var sortArr = HISTORY.contentViewData;
1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
  	var t;
  	for(var i = 0; i < sortArr.length; i++){
  		for(var j = 1; j < sortArr.length - i; j++){
  			if(sortArr[j-1].contenttitlekana > sortArr[j].contenttitlekana){
  				t = sortArr[j-1];
  				sortArr[j-1] = sortArr[j];
  				sortArr[j] = t;
  			}
  		}
  	}

	var resultArr = sortArr;
Masaru Abe committed
1337
	HISTORY.renderContentAfterSort(resultArr);
1338 1339
};

Masaru Abe committed
1340 1341
HISTORY.sortByTitleKanaDesc = function(){
	var sortArr = HISTORY.contentViewData;
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
	var temp;
	for(var i = 0; i < sortArr.length; i++){
		for(var j = sortArr.length - 1; j > i; j--){
			if(sortArr[j].contenttitlekana > sortArr[j - 1].contenttitlekana){
				temp = sortArr[j];
				sortArr[j] = sortArr[j - 1];
			 	sortArr[j - 1] = temp;
			}
		}
	}
1352

1353
	var resultArr = sortArr;
Masaru Abe committed
1354
	HISTORY.renderContentAfterSort(resultArr);
1355 1356 1357
};


Masaru Abe committed
1358 1359
HISTORY.renderContentAfterSort = function(contentSortArr){
	HISTORY.refreshGrid();
1360
    //var htmlTemp = "";
1361 1362 1363
	for(var i = 0; i < contentSortArr.length; i++) {
        post = contentSortArr[i];

Masaru Abe committed
1364
		var outputDeliveryDate = COMMON.formatDeliveryDate(post.deliverydate);
1365

1366 1367 1368 1369 1370 1371 1372 1373 1374 1375
        var htmlTemp = '<section class="sectionhistory">'
			+ '	<div class="cnt_section_list">'
			+ '		<a class="img">'
			+ '			<canvas height="110" width="150" id="content-thumbnail' + post.contentid + '" contentid="' + post.contentid + '" style="display:none;">'
			+ '			</canvas>'
			+ '	        <img id="imgloading' + post.contentid + '" src="./img/data_loading.gif" height="25px" width="25px" style="padding: 46px; "/>'
			+ '		</a>'
			+ '		<div class="text">'
			+ '			<a id="title' + post.contentid + '" class="name dialog" contentid="' + post.contentid + '">'
			+ '             <img class="listIcon" src="' + HEADER.getIconTypeContent(post.contenttype)+'" width="20" height="20">'
1376
			+               COMMON.truncate(COMMON.htmlEncode(post.contenttitle), 20)
1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
			+ '         </a>'
			+ '			<div class="info">'
			+ '				<ul class="date">'
			+ '					<li><span class="lang" lang="txtPubDt">'+I18N.i18nText("txtPubDt")+'</span> : ' + outputDeliveryDate + '</li>'
			+ '					<li><span class="lang" lang="txtViewDt">'+I18N.i18nText("txtViewDt")+'</span>:<span id="lblVdate' + post.contentid + '"> </span></li>'
			+ '				</ul>'
			+ '				<ul class="pic">'
			+ '					<li><img src="' + COMMON.DEFAULT_IMG_OPTION_MEMO + '" id="imgMemo' + post.contentid + '" class="sticker"  /></li>'
			+ '					<li><img src="' + COMMON.DEFAULT_IMG_OPTION_MARKING + '" id="imgBookMark' + post.contentid + '" class="pen"  /></li>'
			+ '					<li><ul class="iconList">{share}<li><a class="read lang button-details" contentid="' + post.contentid + '" lang="txtRead">'+I18N.i18nText("txtRead")+'</a></li></ul></li>'
			+ '				</ul>'
			+ '			</div>'
			+ '		</div>'
			+ '	</div>'
			+ '</section>';
1392

1393 1394 1395 1396 1397 1398
		var shareHtml = "";
		if( post.readerShare == '1' ){
			shareHtml ='<li><a class="read lang button-share" contentid="' + post.contentid + '" lang="txtShare">'+I18N.i18nText("txtShare")+'</a></li>';
		}
		htmlTemp = htmlTemp.replace(/\{share\}/g, shareHtml);
		$('#content-grid').append(htmlTemp);
1399

1400
	}
1401 1402 1403 1404

	for (var i = 0; i < contentSortArr.length; i++) {
	    post = contentSortArr[i];

Masaru Abe committed
1405
	    var viewdate = HISTORY.renderViewDate(post.contentid);
1406

Masaru Abe committed
1407
	    HISTORY.reRenderPageNumber(HISTORY.totalPage, HISTORY.totalPage);
1408
	    //Check if user has read this content or not.
Masaru Abe committed
1409
	    HISTORY.checkUserHasReadContent(post.contentid, post.resourceversion, post.metaversion);
1410 1411

	    //Check if content has marking or memo
Masaru Abe committed
1412
	    HISTORY.checkContentMarkingMemoOption(post.contentid);
1413 1414 1415

	    $('#lblVdate' + post.contentid).html(viewdate);

Masaru Abe committed
1416
	    HISTORY.showContentThumbnail();
1417 1418 1419 1420

	}
};

Masaru Abe committed
1421
HISTORY.formatOriginalPublishDate = function(date){
1422 1423 1424 1425 1426 1427 1428

	var day = date.date;
	var month = date.month + 1;
	var year = date.year + 1900;
	var hour = date.hours;
	var minute = date.minutes;
	var second = date.seconds;
1429

1430 1431 1432 1433
	var resultDate = new Date(year, month, day, hour, minute, second);
	return resultDate;
};

Masaru Abe committed
1434
HISTORY.returnContentTitleKana = function(id) {
1435 1436 1437
    var titleKana;

    // Get title kana from existed contents
Masaru Abe committed
1438
    titleKana = HISTORY.getContentNameKana(id);
1439 1440 1441 1442 1443 1444 1445 1446 1447 1448

    if (titleKana != null) {
        // Skip this case
    }
    else {
        var params = {
            contentId: id,
            sid: ClientData.userInfo_sid(),
            getType: 1
        };
1449

1450 1451

        // Get all pages of content
1452
        AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webGetContent", 'GET', params,
1453
	    function (data) {
1454
	        // Success
1455 1456 1457 1458 1459 1460 1461
	        titleKana = data.contentData.contentNameKana;
	    }, null);

	}
	return titleKana;
};

Masaru Abe committed
1462
HISTORY.resizeResourceThumbnail = function(mg, width, height) {
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474
	var newWidth;
	var newHeight;
    var delta=Math.min(width/mg.width,height/mg.height);

    newHeight=parseInt(delta*mg.height);
    newWidth=parseInt(delta*mg.width);
    var result = [newWidth, newHeight];

    return result;

};

Masaru Abe committed
1475
HISTORY.removeHoverCss = function(){
1476

Masaru Abe committed
1477
	if(COMMON.isTouchDevice()){
1478 1479 1480
		$('#control-sort-title').removeClass('nottouchdevice');
		$('#control-sort-titlekana').removeClass('nottouchdevice');
		$('#control-sort-releasedate').removeClass('nottouchdevice');
1481
		$('#control-sort-viewdate').removeClass('nottouchdevice');
1482 1483
	}
};
1484 1485 1486

//Dialog Read Button CLick
HISTORY.showContentShareDlgFunction = function(e) {
1487

1488 1489 1490 1491
    if (e) {
        e.preventDefault();
    }

Masaru Abe committed
1492 1493
    if (HISTORY.home_isMove == true) {
    	HISTORY.home_isMove = false;
1494 1495 1496 1497 1498
        return;
    }

    var contentId = $(this).attr('contentid');
    // check limit of content
Masaru Abe committed
1499
    LIMIT_ACCESS_CONTENT.checkLimitContent(contentId,
1500
        function()
1501
        {
1502 1503 1504
        	SHARE.contentId = contentId;
        	SHARE.contentTitle = "";
        	SHARE.openContentShare();
1505

1506 1507 1508 1509 1510 1511 1512 1513
        },
        function(){
        	//console.log("checkLimitContent_bbb");
        }
    );

};

1514
HISTORY.showContentView = function(){
1515

1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530
	var y = 0;
	if( document.documentElement.scrollTop ){
		y = document.documentElement.scrollTop;
	}
	if( document.body.scrollTop ){
		if( y == undefined || y == 0){
			y = document.body.scrollTop;
		}
	}
	if( y == undefined || y == null){
		y = 0;
	}
	//console.log("scrollTop:" + y);
	HISTORY.scrollTop = y;
	window.scrollTo(0,0);
1531

1532 1533 1534
    $("#header-ws").hide();
    $("#ws-body").hide();
    $("#topcontrol").hide();
1535

1536 1537 1538
    CONTENTVIEW_INITOBJECT.clearViewerComponent();
    CONTENTVIEW.cssInit();
    $("#viewer").show();
1539

1540
	CONTENTVIEW.ready();
1541

1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
};

HISTORY.cssInit = function(){
	$('html').css({
		'overflow-y':'scroll'
		});
	$('html,body').css({
		'height':'100%',
		'margin': '0',
		'padding': '0'
		});
	$('html>body').css({
		'font-size':'16px',
		'font-size':'68.75%'
		});
	$('body').css({
		'font-family':'Verdana, helvetica, arial, sans-serif',
		'font-size':'68.75%',
		'background':'#fff',
		'color':'#333'
		});
};

HISTORY.downloadFunction = function(e) {
    if (e) {
        e.preventDefault();
    }

    var contentId = $(this).attr('contentid');
    //Download content
    HEADER.downloadResourceById(contentId);
1573

1574 1575 1576 1577
};