contentview_CallApi.js 15.7 KB
Newer Older
1

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

//Call API
6
CONTENTVIEW_CALLAPI.abapi = function(name, param, method, callback) {
7
	AVWEB.avwCmsApiSync(ClientData.userInfo_accountPath(), name, method, param, callback, null);
8
};
9

10
/* get Json stored content info */
11
CONTENTVIEW_CALLAPI.getJsonContentInfo = function( doneFunc ) {
12
	
13 14 15 16 17
	//ファイルシステムが有効であればキャッシュ確認
	if( CONTENTVIEW_FILESYSTEM.fs == null ){
		//console.log("CONTENTVIEW_CALLAPI.getJsonContentInfo");
		AVWEB.avwGrabContentPageImage(ClientData.userInfo_accountPath(),
		     { contentId: CONTENTVIEW_GENERAL.contentID, sid: ClientData.userInfo_sid(), pageNo: 1 },
18 19 20
		     function (data) {
		    	CONTENTVIEW_GENERAL.pageImages = data;
		    	CONTENTVIEW_CALLAPI.getJsonContentInfoDone(doneFunc);
21 22 23 24 25 26 27
		     },
		     function (xmlHttpRequest, txtStatus, errorThrown) {
		    	 CONTENTVIEW.showErrorScreen();
		     }
		);
	} else {
		// 1ページ目のファイル取得
Masaru Abe committed
28 29
		var fileName = '/abook/' + CONTENTVIEW_GENERAL.contentID + "/page_1.dat";
		CONTENTVIEW_FILESYSTEM.fs.root.getFile( fileName, { create: false },
30 31 32 33 34 35
				function(fileEntry){
					fileEntry.file(function(file){
						var reader = new FileReader();
						reader.onloadend = function(e) {
							AVWEB.avwLog("read FileSystem");
							CONTENTVIEW_GENERAL.pageImages = e.target.result;
36
					    	CONTENTVIEW_CALLAPI.getJsonContentInfoDone(doneFunc);
37 38 39 40 41 42 43 44 45
						};
						//reader.readAsBinaryString(fileEntry);
						reader.readAsText(file);
						//reader.readAsArrayBuffer(fileEntry);
					});
				},
				function(err){
					// 失敗時のコールバック関数
					AVWEB.avwLog("NotRead FileSystem");
Masaru Abe committed
46
					AVWEB.avwGrabContentPageImage(
47 48 49 50
							ClientData.userInfo_accountPath(),
							{ contentId: CONTENTVIEW_GENERAL.contentID, sid: ClientData.userInfo_sid(), pageNo: 1 },
							function (data) {
								CONTENTVIEW_GENERAL.pageImages = data;
51
						    	CONTENTVIEW_CALLAPI.getJsonContentInfoDone(doneFunc);
52 53 54 55 56 57 58 59
							},
							function (xmlHttpRequest, txtStatus, errorThrown) {
								CONTENTVIEW.showErrorScreen();
							}
					);
				}
		);
	}
60
};
61 62 63 64 65 66 67 68 69 70 71 72 73

CONTENTVIEW_CALLAPI.getJsonContentInfoDone = function(doneFunc){
	
	var ajax1 = CONTENTVIEW_CALLAPI.webGetContentDataWhen();
	var ajax2 = CONTENTVIEW_CALLAPI.getSearchDataFromJsonWhen();
	var ajax3 = CONTENTVIEW_CALLAPI.getJsonDataPageTitleWhen();
	var ajax4 = CONTENTVIEW_CALLAPI.getJsonDataType4When();
	var ajax5 = CONTENTVIEW_CALLAPI.getJsonDataType5When();
	var ajax6 = CONTENTVIEW_CALLAPI.getDataJsonFileWhen();
	var ajax7 = CONTENTVIEW_CALLAPI.webGetContentPageSizeWhen();
	$.when(
    	 ajax1,ajax2,ajax3,ajax4,ajax5,ajax6,ajax7
	).done(function(data1, data2, data3, data4, data5, data6, data7) {
Masaru Abe committed
74 75 76 77 78 79 80
		//console.log("done:data1:" + data1);
		//console.log("done:data2:" + data2);
		//console.log("done:data3:" + data3);
		//console.log("done:data4:" + data4);
		//console.log("done:data5:" + data5);
		//console.log("done:data6:" + data6);
		//console.log("done:data7:" + data7);
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
		if(data1){
			CONTENTVIEW_CALLAPI.webGetContentDataDone(data1[0]);
		}
		if(data2){
			CONTENTVIEW_CALLAPI.getSearchDataFromJsonDone(data2[0]);
		}
		if(data3){
			CONTENTVIEW_CALLAPI.getJsonDataPageTitleDone(data3[0]);
		}
		if(data4){
			CONTENTVIEW_CALLAPI.getJsonDataType4Done(data4[0]);
		}
		if(data5){
			CONTENTVIEW_CALLAPI.getJsonDataType5Done(data5[0]);
		}
		if(data6){
			CONTENTVIEW_CALLAPI.getDataJsonFileDone(data6[0]);
		}
		if(data7){
			CONTENTVIEW_CALLAPI.webGetContentPageSizeDone(data7[0]);
		}
		if(doneFunc){
			doneFunc();
		}
	});
	
};

109

110 111
//未使用
CONTENTVIEW_CALLAPI.webGetPageImageContentSize = function() {
Masaru Abe committed
112 113 114 115
	
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
Masaru Abe committed
116 117
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
118 119
    };
	
120
	AVWEB.avwCmsApi(ClientData.userInfo_accountPath(),
121 122
	     "webContentPageSize",
	     "GET",
123
	     { contentId: CONTENTVIEW_GENERAL.contentID, sid: ClientData.userInfo_sid() },
124
	     function (data) {
125 126
	    	 CONTENTVIEW_GENERAL.widthContentImage = data.width;
	    	 CONTENTVIEW_GENERAL.heightContentImage = data.height;
127 128 129 130
	     },
	     null);
};

131
CONTENTVIEW_CALLAPI.webGetContentPageSizeWhen = function(){
Masaru Abe committed
132 133 134 135 136
	
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
    		getType: 6,
Masaru Abe committed
137 138
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
139 140
    };
	
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    return AVWEB._callCmsApiWhen(
    		ClientData.userInfo_accountPath(),
    		"webGetContent",
    		"GET",
    		params
    );
    
};

CONTENTVIEW_CALLAPI.webGetContentPageSizeDone = function(data){
	if( data.contentData.pageInfoData.pagesInfo ){
		$.each(data.contentData.pageInfoData.pagesInfo, function(i, n){
			CONTENTVIEW_GENERAL.contentPageSizeArr.push(n);
		});
		
		//Get Page size of firstPage
		CONTENTVIEW_CALLAPI.getPageSizeByPageNo(1);
	} else {
		CONTENTVIEW.showErrorScreen();
	}
161 162 163
};

//Get Pagesize by pageNo
164 165 166
CONTENTVIEW_CALLAPI.getPageSizeByPageNo = function(pageNo){
    for(var i = 0; i < CONTENTVIEW_GENERAL.contentPageSizeArr.length; i++){
        var page = CONTENTVIEW_GENERAL.contentPageSizeArr[i];
167 168
        
        if(page.pageNo == pageNo){            
169 170
        	CONTENTVIEW_GENERAL.widthContentImage = page.pageWidth;
        	CONTENTVIEW_GENERAL.heightContentImage = page.pageHeight;            
171 172 173 174
        }
    }
};

175
CONTENTVIEW_CALLAPI.webGetContentDataWhen = function() {
Masaru Abe committed
176 177 178 179 180
	
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
    		getType: 1,
Masaru Abe committed
181 182
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
183
    };
184 185 186 187 188 189 190 191 192 193 194 195
    
    return AVWEB._callCmsApiWhen(
    		ClientData.userInfo_accountPath(),
    		"webGetContent",
    		"GET",
    		params
    );
    
};

CONTENTVIEW_CALLAPI.webGetContentDataDone = function(data) {
	 CONTENTVIEW_GENERAL.totalPage = data.contentData.allPageNum;
196 197 198
};

/* get Json stored page title */
199
CONTENTVIEW_CALLAPI.getJsonDataPageTitleWhen = function() {
Masaru Abe committed
200 201 202 203 204
	
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
    		getType: 3,
Masaru Abe committed
205 206
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
207 208
    };
	
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
    return AVWEB._callCmsApiWhen(
    		ClientData.userInfo_accountPath(),
    		"webGetContent",
    		"GET",
    		params
    );
    
};

CONTENTVIEW_CALLAPI.getJsonDataPageTitleDone = function(data) {
	 CONTENTVIEW_GENERAL.dataPageTitle = [];
     for (var nIndex = 0; nIndex < CONTENTVIEW_GENERAL.totalPage; nIndex++) {
    	 CONTENTVIEW_GENERAL.dataPageTitle.push("");
     }
     if (data.contentData) {

         if (data.contentData.titleInfo) {
        	 CONTENTVIEW_GENERAL.dataPageTitle = data.contentData.titleInfo;
         }
     }
229 230 231
};

/* get Json webGetContent4 */
232
CONTENTVIEW_CALLAPI.getJsonDataType4When = function() {
Masaru Abe committed
233 234 235 236 237
	
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
    		getType: 4,
Masaru Abe committed
238 239
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
240 241
    };
	
242 243 244 245 246 247 248 249 250 251 252
    return AVWEB._callCmsApiWhen(
    		ClientData.userInfo_accountPath(),
    		"webGetContent",
    		"GET",
    		params
    );
    
};

CONTENTVIEW_CALLAPI.getJsonDataType4Done = function(data) {
	 CONTENTVIEW_GENERAL.dataJsonType4 = data.contentData.linkData;
253 254 255
};

/* get Json webGetContent5 */
256
CONTENTVIEW_CALLAPI.getJsonDataType5When = function() {
Masaru Abe committed
257 258 259 260 261
	
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
    		getType: 5,
Masaru Abe committed
262 263
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
264 265
    };
	
266 267 268 269 270 271 272 273 274 275 276
    return AVWEB._callCmsApiWhen(
    		ClientData.userInfo_accountPath(),
    		"webGetContent",
    		"GET",
    		params
    );
    
};

CONTENTVIEW_CALLAPI.getJsonDataType5Done = function(data) {
	 CONTENTVIEW_GENERAL.dataJsonType5 = data.contentData.outlineData;
277 278 279
};

/* read file Json -> get page objects */
280
CONTENTVIEW_CALLAPI.getDataJsonFileWhen = function() {
Masaru Abe committed
281 282 283 284 285
	
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
    		getType: 2,
Masaru Abe committed
286 287
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
288 289
    };
	
290 291 292 293 294 295 296
    return AVWEB._callCmsApiWhen(
    		ClientData.userInfo_accountPath(),
    		"webGetContent",
    		"GET",
    		params
    );
    
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
CONTENTVIEW_CALLAPI.getDataJsonFileDone = function(data) {
	
    var JsonFile = data.contentData;
    CONTENTVIEW_GENERAL.pageObjectsData = [];
    if (JsonFile.vertical) {
        if (JsonFile.vertical.pages) {
       	 CONTENTVIEW_GENERAL.pageObjectsData = JsonFile.vertical.pages;
            
            //Start Function : No.9 - Editor : Long - Date : 08/16/2013 - Summary : 
            if(data.contentDataSub != null && data.contentDataSub.length > 0){                          
                for(var i = 0; i < CONTENTVIEW_GENERAL.pageObjectsData.length; i++){
                    var obj = CONTENTVIEW_GENERAL.pageObjectsData[i];
                    obj["contentDataSub"] = data.contentDataSub;
                }                                              
            }
            //End Function : No.9 - Editor : Long - Date : 08/16/2013 - Summary :
        }
    }
    else if (JsonFile.horizontal) {
        if (JsonFile.horizontal.pages) {
       	 CONTENTVIEW_GENERAL.pageObjectsData = JsonFile.horizontal.pages;
            //Start Function : No.9 - Editor : Long - Date : 08/16/2013 - Summary : 
            if(data.contentDataSub != null && data.contentDataSub.length > 0){		                     
                for(var i = 0; i < CONTENTVIEW_GENERAL.pageObjectsData.length; i++){
                    var obj = CONTENTVIEW_GENERAL.pageObjectsData[i];
                    obj["contentDataSub"] = data.contentDataSub;
                }		                     		            
            }
            //End Function : No.9 - Editor : Long - Date : 08/16/2013 - Summary : 	                 
        }
    }
    //Start : Function : No.12 - Editor : Long - Date: 08/27/2013 - Summary : Get Page Object for content type none
    else{
   	 CONTENTVIEW_GENERAL.pageObjectsData = JsonFile.content.pages;
        
        if(data.contentDataSub != null && data.contentDataSub.length > 0){                            
            for(var i = 0; i < CONTENTVIEW_GENERAL.pageObjectsData.length; i++){
                var obj = CONTENTVIEW_GENERAL.pageObjectsData[i];
                obj["contentDataSub"] = data.contentDataSub;
            }                                              
        }
    }
    
    //Get Data Of page to draw page
    if(CONTENTVIEW_GENERAL.contentType == COMMON.ContentTypeKeys.Type_NoFile){
        
        var pageDataInfo = [];
        pageDataInfo["height"] = JsonFile.height;
        pageDataInfo["width"] = JsonFile.width;
        pageDataInfo["alpha"] = JsonFile.backgroundAlpha;
        pageDataInfo["color"] = JsonFile.backgroundColor;
        
        CONTENTVIEW_GENERAL.totalPage = parseInt(JsonFile.totalPageNum);
        
        CONTENTVIEW_GENERAL.pageImages = CONTENTVIEW_CONTENTTYPENONE.returnImageString(pageDataInfo);
        CONTENTVIEW_GENERAL.widthContentImage = JsonFile.width;
        CONTENTVIEW_GENERAL.heightContentImage = JsonFile.height;
    }	 
            		        
    //End : Function : No.12 - Editor : Long - Date: 08/27/2013 - Summary : Get Page Object for content type none

    CONTENTVIEW_GETDATA.getPageObjectsByPageIndex(CONTENTVIEW_GENERAL.pageObjectsData, 0);
	
};


365 366
CONTENTVIEW_CALLAPI.loadDataBookmark = function(lstPageNo) {
    if (CONTENTVIEW_GENERAL.isSendingData == true) {
367

Masaru Abe committed
368 369 370 371 372
        var params = {
        		contentId: CONTENTVIEW_GENERAL.contentID,
        		sid: ClientData.userInfo_sid(),
        		pageNos: lstPageNo[0],
        		thumbnailFlg: 1,
Masaru Abe committed
373 374
        		isStreaming: ClientData.isStreamingMode(),
        		authCode: ClientData.authCode()
Masaru Abe committed
375 376
        };
    	
377
    	AVWEB.avwCmsApi(ClientData.userInfo_accountPath(),
378 379
		     "webContentPage",
		     "GET",
Masaru Abe committed
380
		     params,
381
		     function (data) {
382
		    	 CONTENTVIEW_GETDATA.getDataLoaded(data.pages);
383 384 385

		         //Resize Image
		         var imgTemp = new Image();
386
		         $('#img_bookmark_' + data.pages[0].pageNo).attr('src', COMMON.formatStringBase64(data.pages[0].pageThumbnail));
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402

		         imgTemp.onload = function () {

		             if (imgTemp.width > imgTemp.height) {

		                 $("img.imgbox").attr('height', '');
		                 $("img.imgbox").removeAttr('height');
		                 $("img.imgbox").attr('width', '43');
		             }
		             else {
		                 $("img.imgbox").attr('width', '');
		                 $("img.imgbox").removeAttr('width');
		                 $("img.imgbox").attr('height', '43');
		             }
		         };

403
		         imgTemp.src = COMMON.formatStringBase64(data.pages[0].pageThumbnail);
404 405 406 407 408 409

		         lstPageNo = jQuery.grep(lstPageNo, function (value) {
		             return value != lstPageNo[0];
		         });

		         if (lstPageNo.length > 0) {
410
		        	 CONTENTVIEW_CALLAPI.loadDataBookmark(lstPageNo);
411
		         } else {
412
		        	 CONTENTVIEW_GENERAL.isSendingData = false;
413 414 415 416 417 418 419
		         }
		     },
		     null);
    }
};

/* get data using for search */
420
CONTENTVIEW_CALLAPI.getSearchDataFromJsonWhen = function() {
421 422 423
    //get data from JSON file

    var arrPageNo = '';
424
    for (var nIndex = 0; nIndex < CONTENTVIEW_GENERAL.totalPage; nIndex++) {
425 426 427 428 429 430
        if (nIndex == 0) {
            arrPageNo += (nIndex + 1);
        } else {
            arrPageNo += "," + (nIndex + 1);
        }
    }
Masaru Abe committed
431 432 433 434 435
    
    var params = {
    		contentId: CONTENTVIEW_GENERAL.contentID,
    		sid: ClientData.userInfo_sid(),
    		thumbnailFlg: 0,
Masaru Abe committed
436 437
    		isStreaming: ClientData.isStreamingMode(),
    		authCode: ClientData.authCode()
Masaru Abe committed
438 439
    };
    
440 441 442 443 444 445 446 447
    return AVWEB._callCmsApiWhen(
    		ClientData.userInfo_accountPath(),
    		"webContentPage",
    		"GET",
    		params
    );
    
};
448

449 450 451
CONTENTVIEW_CALLAPI.getSearchDataFromJsonDone = function(data) {
	CONTENTVIEW_GENERAL.contentName = data.contentTitle;
	CONTENTVIEW_GENERAL.dataWebContentPage = data;
452 453
};

454 455
CONTENTVIEW_CALLAPI.loadDataSearch = function(lstPageNo) {
    if (CONTENTVIEW_GENERAL.isSendingData == true) {
Masaru Abe committed
456 457 458 459 460 461
    	
        var params = {
        		contentId: CONTENTVIEW_GENERAL.contentID,
        		sid: ClientData.userInfo_sid(),
        		pageNos: lstPageNo[0],
        		thumbnailFlg: 1,
Masaru Abe committed
462 463
        		isStreaming: ClientData.isStreamingMode(),
        		authCode: ClientData.authCode()
Masaru Abe committed
464 465
        };
    	
466
    	AVWEB.avwCmsApi(ClientData.userInfo_accountPath(),
467 468
		     "webContentPage",
		     "GET",
Masaru Abe committed
469
		     params,
470
		     function (data) {
471
		    	 CONTENTVIEW_GETDATA.getDataLoaded(data.pages);
472 473 474

		         //Resize Image
		         var imgTemp = new Image();
475
		         $('#img_search_' + data.pages[0].pageNo).attr('src', COMMON.formatStringBase64(data.pages[0].pageThumbnail));
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491

		         imgTemp.onload = function () {

		             if (imgTemp.width > imgTemp.height) {

		                 $("img.imgbox").attr('height', '');
		                 $("img.imgbox").removeAttr('height');
		                 $("img.imgbox").attr('width', '43');
		             }
		             else {
		                 $("img.imgbox").attr('width', '');
		                 $("img.imgbox").removeAttr('width');
		                 $("img.imgbox").attr('height', '43');
		             }
		         };

492
		         imgTemp.src = COMMON.formatStringBase64(data.pages[0].pageThumbnail);
493 494 495 496 497 498

		         lstPageNo = jQuery.grep(lstPageNo, function (value) {
		             return value != lstPageNo[0];
		         });

		         if (lstPageNo.length > 0) {
499
		        	 CONTENTVIEW_CALLAPI.loadDataSearch(lstPageNo);
500
		         } else {
501
		        	 CONTENTVIEW_GENERAL.isSendingData = false;
502 503 504 505 506 507
		         }
		     },
		     null);
    }
};

508 509 510
CONTENTVIEW_CALLAPI.ready = function(){
};