detail.js 12.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 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 62 63 64 65 66 67 68 69 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 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 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 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
/// コンテンツ詳細画面

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

DETAIL.displayData = {
    contentID: "",
    contentTitle: "",
    contentDetail: "",
    contentShare: "",
    contentThumbnail: "",
    deliveryDate: (new Date()),
    pages: []
};


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

});

// Show content detail
DETAIL.openContentDetail = function() {
	if(!COMMON.isPdfContent(ClientData.contentInfo_contentType())){
		$('#sectionContentDetail').removeClass().addClass('sectiondetailnopdf');
	}
	else {
		$('#sectionContentDetail').removeClass().addClass('sectiondetail');
	}

	DETAIL.displayData = {
			contentID: "",
			contentTitle: "",
			contentDetail: "",
			contentShare: "",
			contentThumbnail: "",
			deliveryDate: (new Date()),
			pages: []
	};

	// Clear childs
	$('#book_list').html('');

    // Clear display info
	$("#imgContentThumbnail").attr('src', "img/data_loading.gif");
	DETAIL.resetLoadingImageSize();

	$("#txtContentTitle").text('');
	$("#txtPubDt2_Dsp").text('');
	$("#txtContentDetail").text('');

	$("#contentDetailClose").unbind("click");
	$("#contentDetailClose").click(DETAIL.contentDetailClose_Click);
	$("#contentdetail_dspRead").unbind("click");
	$("#contentdetail_dspRead").click(DETAIL.contentdetail_dspRead_Click);

	//if( ClientData.serviceOpt_content_share() != '2'){
	//$("#contentdetail_dspShare").click(SHARE.openContentShare);
	$("#contentdetail_dspShare").hide();
	//}

	COMMON.lockLayout();
	$("#contentDetail").css('z-index', 101);
	$("#sectionContentDetail").show();
	$("#contentDetail").show();
	$("#contentDetail").center();
	if ($("#contentDetail").height() > $(window).height()){
		$("#contentDetail").css('top', '0');
	}

	// Get contentid, thumbnail from list screen
	DETAIL.displayData.contentID = ClientData.contentInfo_contentId();
	DETAIL.displayData.contentThumbnail = ClientData.contentInfo_contentThumbnail();

	var params = {
		sid: ClientData.userInfo_sid(),
		getType: '1',
		contentId: DETAIL.displayData.contentID
	};

	// Get content detail
	AVWEB.avwCmsApi(ClientData.userInfo_accountPath(), "webGetContent", "GET", params,
			function (data) {
				var contentType = ClientData.contentInfo_contentType();
				// Get content detail
				DETAIL.displayData.contentTitle = data.contentData.contentName;
				DETAIL.displayData.contentDetail = data.contentData.contentDetail;
				if( ClientData.serviceOpt_content_share() == '2'){
					if( data.contentData.readerShare ){
						//SHARE.contentId = DETAIL.displayData.contentID;
						DETAIL.displayData.contentShare = data.contentData.readerShare;
					}
				}
				DETAIL.displayData.deliveryDate = COMMON.convertToDate(data.contentData.deliveryStartDate);

				//Start Function : No.12 -- Editor : Viet Nguyen -- Date : 08/01/2013 -- Summary : Create new function to return content type of content.
				if(!COMMON.isPdfContent(contentType)){
					DETAIL.showContentNotPDF(DETAIL.displayData);
				}
				else{
					// Get pages
					AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), "webContentPage", "GET", { contentId: ClientData.contentInfo_contentId(), sid: ClientData.userInfo_sid(), thumbnailFlg: 1, pageNos: '1,2,3,4,5,6'},
							function (data) {
								// Get pages
								for (var nIndex = 0; nIndex < data.pages.length; nIndex++) {
									if (nIndex < 6) {
										DETAIL.displayData.pages.push({ pageNo: data.pages[nIndex].pageNo, pageText: data.pages[nIndex].pageText, pageThumbnail: ("data:image/jpeg;base64," + data.pages[nIndex].pageThumbnail) });
									}
								}
								// Show to screen
								DETAIL.showContent(DETAIL.displayData);
							},
							null
					);
				}

				//End Function : No.12 -- Editor : Viet Nguyen -- Date : 08/01/2013 -- Summary : Create new function to return content type of content.

			},
			null
	);
};

// Close content detail
DETAIL.contentDetailClose_Click = function(e) {
	if( e != null ){
		e.preventDefault();
	}
	COMMON.unlockLayout();
	$("#contentDetail").hide();
	$("#sectionContentDetail").hide();
};

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

DETAIL.contentdetail_dspRead_Click = function(e) {
	e.preventDefault();
	var outputId = ClientData.contentInfo_contentId();
	LIMIT_ACCESS_CONTENT.checkLimitContent(outputId,
			function () {
				DETAIL.contentdetail_dspRead_Click_callback(outputId);
			},
			function(){
			},
			1
	);
};

DETAIL.contentdetail_dspRead_Click_callback = function(outputId) {

	var date = new Date();
	var month = date.getMonth() + 1;
	var day = date.getDate();
	var outputDate = COMMON.formatNormalDate(day, month, date.getFullYear());
	var contentIdArray = [];
	var checkflag = false;

	//Store Content id that user has read
	if (ClientData.ReadingContentIds().length > 0) {
		contentIdArray = ClientData.ReadingContentIds();

		for (var nIndex = 0; nIndex < contentIdArray.length; nIndex++) {
			if (contentIdArray[nIndex].contentid == outputId) {
				checkflag = true;
				if (contentIdArray[nIndex].viewdate == '' || contentIdArray[nIndex].viewdate == null || contentIdArray[nIndex].viewdate == 'undefined') {
					contentIdArray[nIndex].viewdate = outputDate;
					contentIdArray[nIndex].originviewdate = date;
				}
				break;
			}
			else {
				checkflag = false;
			}
		}

		if (!checkflag) {
			contentIdArray.push({ contentid: outputId, viewdate: outputDate, originviewdate: date });
		}
	}
	else {
		contentIdArray.push({ contentid: outputId, viewdate: outputDate, originviewdate: date });
	}

	//Renew ReadingContentID
	var newArray = [];
	ClientData.ReadingContentIds(newArray);

	//Set data for readingcontentid
	ClientData.ReadingContentIds(contentIdArray);

	//Set ResouceVersion for content
	COMMON.setResourceVersionData(outputId);

	//Set MetaVersion for content
	COMMON.setMetaVersionData(outputId);

	// Redirect to screen: contentview
	//$('body,html').animate({ scrollTop: 0 }, 0);
	ClientData.IsRefresh(false);

	if (ClientData.contentInfo_contentType() == COMMON.ContentTypeKeys.Type_Others) {
		// Get content detail
		HEADER.downloadResourceById(ClientData.contentInfo_contentId());
	}
	else if(ClientData.contentInfo_contentType() == COMMON.ContentTypeKeys.Type_Link){
		// Get content detail
		HEADER.viewLinkContentById(ClientData.contentInfo_contentId());
	}
	else {
		//AVWEB.avwScreenMove(COMMON.ScreenIds.ContentView);
    	//試験
		//詳細閉じる
		DETAIL.contentDetailClose_Click(null);
		if( $('#bookshelf').length || $('#list').length ){
			//ビューア表示
			HOME.showContentView();
		} else if( $('#bookmark').length ){
			//ビューア表示
			BOOKMARK.showContentView();
		} else if( $('#history').length ){
			//ビューア表示
			HISTORY.showContentView();
		} else if( $('#contentsearch').length ){
			//ビューア表示
			CONTENTSEARCH.showContentView();
		}
	}
};

//Start Function : No.12 -- Editor : Viet Nguyen -- Date : 08/01/2013 -- Summary : Create new function to return content type of content.

DETAIL.showContentNotPDF = function(displayData) {
    $("#txtPubDt2_Dsp").text(displayData.deliveryDate.jpDateString() + " " + displayData.deliveryDate.jpShortTimeString());
    $("#txtContentDetail").text(displayData.contentDetail);
    //$("#txtContentTitle").text(COMMON.truncate(displayData.contentTitle, 20));
    $("#txtContentTitle").text(displayData.contentTitle);

    //コンテンツ共有
    if( displayData.contentShare == '1' ){
        SHARE.contentId = displayData.contentID;
        SHARE.contentTitle = displayData.contentTitle;
        $("#contentdetail_dspShare").show();
    	$("#contentdetail_dspShare").unbind("click");
        $("#contentdetail_dspShare").click(SHARE.openContentShare);
    }

    var tempContentType = ClientData.contentInfo_contentType();

    if(displayData.contentThumbnail == '' || displayData.contentThumbnail == null || displayData.contentThumbnail == 'undefined'){
        if(!COMMON.isPdfContent(tempContentType)){
            var src = HEADER.getThumbnailForOtherType(contentType);
            if( src != '' ){
            	displayData.contentThumbnail = src;
            }
        }
        //}else{
        //contentThumbnail = contentThumbnail;
    }

    var imgTemp = new Image();
    $("#imgContentThumbnail").attr("src", displayData.contentThumbnail);
    imgTemp.onload = function () {

        //resize Image
        if (imgTemp.width > imgTemp.height) {

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

            $("#imgContentThumbnail").css('padding-top', "12px");
        }

    };

    imgTemp.src = displayData.contentThumbnail;
};

//End Function : No.12 -- Editor : Viet Nguyen -- Date : 08/01/2013 -- Summary : Create new function to return content type of content.

// Show detail content
DETAIL.showContent = function(displayData) {
    $("#txtPubDt2_Dsp").text(displayData.deliveryDate.jpDateString() + " " + displayData.deliveryDate.jpShortTimeString());
    $("#txtContentDetail").text(displayData.contentDetail);
    $("#txtContentTitle").text(displayData.contentTitle);

    //コンテンツ共有
    if( displayData.contentShare == '1' ){
        SHARE.contentId = displayData.contentID;
        SHARE.contentTitle = displayData.contentTitle;
        $("#contentdetail_dspShare").show();
    	$("#contentdetail_dspShare").unbind("click");
        $("#contentdetail_dspShare").click(SHARE.openContentShare);
    }

    $("#imgContentThumbnail").attr("src", displayData.contentThumbnail);
    var imgTemp = new Image();

    imgTemp.onload = function () {

        //resize Image
        if (imgTemp.width > imgTemp.height) {

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

            $("#imgContentThumbnail").css('padding-top', "12px");
        }

    };

    imgTemp.src = displayData.contentThumbnail;

    //resizeThumbnailContentDetail(contentThumbnail, 120, 160);
    // Show pages
    for (var nIndex = 0; nIndex < displayData.pages.length; nIndex++) {
        //insertRow(imgSample, pages[nIndex].pageText, pages[nIndex].pageNo);
    	DETAIL.insertRow(displayData.pages[nIndex].pageThumbnail, COMMON.truncate(COMMON.getLines(displayData.pages[nIndex].pageText, 3), 45), displayData.pages[nIndex].pageNo); //55
    }
};

DETAIL.insertRow = function(pageThumbnail, pageText, pageNo) {
    var newRow = "";
    newRow += "<ul>";
    newRow += '<li class="list_img"><img src="' + pageThumbnail + '" alt="" width="90" /></li>';
    newRow += '<li class="list_title"><a href="#">' + COMMON.htmlEncode(pageText) + '</a></li>';
    newRow += '<li class="page"><label id="Label2" class="lang" lang="txtPage">' + I18N.i18nText('txtPage') + '</label>' + pageNo + '</li>';
    newRow += "</ul>";

    $('#book_list').append(newRow);
    I18N.i18nReplaceText();

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

    imgTemp.onload = function(){

    	if(imgTemp.width > imgTemp.height) {

    		$("li.list_img img").attr('height', '');
    		$("li.list_img img").removeAttr('height');
    		$("li.list_img img").attr('width', '90');
    	}
    	else {
    		$("li.list_img img").attr('width', '');
    		$("li.list_img img").removeAttr('width');
    		$("li.list_img img").attr('height', '90');
    	}
	};

    imgTemp.src = pageThumbnail;
};

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

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

DETAIL.resetLoadingImageSize = function(){
	$("#imgContentThumbnail").attr('height','25px');
	$("#imgContentThumbnail").attr('width','25px');
};