contentview_CallApi.js 15.5 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 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486

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

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

/* get Json stored content info */
CONTENTVIEW_CALLAPI.getJsonContentInfo = function( doneFunc ) {

	//console.log("CONTENTVIEW_CALLAPI.getJsonContentInfo");
	AVWEB.avwGrabContentPageImage(ClientData.userInfo_accountPath(),
	     { contentId: CONTENTVIEW_GENERAL.contentID, sid: CONTENTVIEW.getSessionId(), pageNo: 1 },
	     function (data) {
	    	CONTENTVIEW_GENERAL.pageImages = data;
	    	CONTENTVIEW_CALLAPI.getJsonContentInfoDone(doneFunc);
	     },
	     function (xmlHttpRequest, txtStatus, errorThrown) {
	    	 CONTENTVIEW.showErrorScreen();
	     }
	);
};

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) {
        //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);
        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();
        }
    });

};
//END TRB00097 - Editor: Long - Date: 09/30/2013 - Summary : Get All Page size of content

//未使用
CONTENTVIEW_CALLAPI.webGetPageImageContentSize = function() {

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            isStreaming: ClientData.isStreamingMode()
    };

    AVWEB.avwCmsApi(ClientData.userInfo_accountPath(),
         "webContentPageSize",
         "GET",
         { contentId: CONTENTVIEW_GENERAL.contentID, sid: CONTENTVIEW.getSessionId() },
         function (data) {
             CONTENTVIEW_GENERAL.widthContentImage = data.width;
             CONTENTVIEW_GENERAL.heightContentImage = data.height;
         },
         null);
};

CONTENTVIEW_CALLAPI.webGetContentPageSizeWhen = function(){

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            getType: 6,
            isStreaming: ClientData.isStreamingMode()
    };

    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();
    }
};

//Get Pagesize by pageNo
CONTENTVIEW_CALLAPI.getPageSizeByPageNo = function(pageNo){
    for(var i = 0; i < CONTENTVIEW_GENERAL.contentPageSizeArr.length; i++){
        var page = CONTENTVIEW_GENERAL.contentPageSizeArr[i];

        if(page.pageNo == pageNo){
            CONTENTVIEW_GENERAL.widthContentImage = page.pageWidth;
            CONTENTVIEW_GENERAL.heightContentImage = page.pageHeight;
        }
    }
};

CONTENTVIEW_CALLAPI.webGetContentDataWhen = function() {

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            getType: 1,
            isStreaming: ClientData.isStreamingMode()
    };

    return AVWEB._callCmsApiWhen(
            ClientData.userInfo_accountPath(),
            "webGetContent",
            "GET",
            params
    );

};

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

/* get Json stored page title */
CONTENTVIEW_CALLAPI.getJsonDataPageTitleWhen = function() {

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            getType: 3,
            isStreaming: ClientData.isStreamingMode()
    };

    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;
         }
     }
};

/* get Json webGetContent4 */
CONTENTVIEW_CALLAPI.getJsonDataType4When = function() {

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            getType: 4,
            isStreaming: ClientData.isStreamingMode()
    };

    return AVWEB._callCmsApiWhen(
            ClientData.userInfo_accountPath(),
            "webGetContent",
            "GET",
            params
    );

};

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

/* get Json webGetContent5 */
CONTENTVIEW_CALLAPI.getJsonDataType5When = function() {

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            getType: 5,
            isStreaming: ClientData.isStreamingMode()
    };

    return AVWEB._callCmsApiWhen(
            ClientData.userInfo_accountPath(),
            "webGetContent",
            "GET",
            params
    );

};

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

/* read file Json -> get page objects */
CONTENTVIEW_CALLAPI.getDataJsonFileWhen = function() {

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            getType: 2,
            isStreaming: ClientData.isStreamingMode()
    };

    return AVWEB._callCmsApiWhen(
            ClientData.userInfo_accountPath(),
            "webGetContent",
            "GET",
            params
    );

};

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{
    	
    	//#25861 オーサリング機能のプレビュー機能が無反応となる
        if (JsonFile.content) {
        	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 = [];
        if(JsonFile.height){
        	pageDataInfo["height"] = JsonFile.height;
        } else {
        	pageDataInfo["height"] = "1004";
        }
        if(JsonFile.width){
        	pageDataInfo["width"] = JsonFile.width;
        } else {
        	pageDataInfo["width"] = "710";
        }
        if(JsonFile.backgroundAlpha){
        	pageDataInfo["alpha"] = JsonFile.backgroundAlpha;
        } else {
        	pageDataInfo["alpha"] = "1";
        }
        if(JsonFile.backgroundColor){
        	pageDataInfo["color"] = JsonFile.backgroundColor;
        } else {
        	pageDataInfo["color"] = "ffffff";
        }
        if(JsonFile.totalPageNum){
        	CONTENTVIEW_GENERAL.totalPage = parseInt(JsonFile.totalPageNum);
        } else {
        	CONTENTVIEW_GENERAL.totalPage = 1;
        }

        CONTENTVIEW_GENERAL.pageImages = CONTENTVIEW_CONTENTTYPENONE.returnImageString(pageDataInfo);
        CONTENTVIEW_GENERAL.widthContentImage = pageDataInfo["width"];
        CONTENTVIEW_GENERAL.heightContentImage = pageDataInfo["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);

};

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

        var params = {
                contentId: CONTENTVIEW_GENERAL.contentID,
                sid: CONTENTVIEW.getSessionId(),
                pageNos: lstPageNo[0],
                thumbnailFlg: 1,
                isStreaming: ClientData.isStreamingMode()
        };

        AVWEB.avwCmsApi(ClientData.userInfo_accountPath(),
             "webContentPage",
             "GET",
             params,
             function (data) {
                 CONTENTVIEW_GETDATA.getDataLoaded(data.pages);

                 //Resize Image
                 var imgTemp = new Image();
                 $('#img_bookmark_' + data.pages[0].pageNo).attr('src', COMMON.formatStringBase64(data.pages[0].pageThumbnail));

                 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');
                     }
                 };

                 imgTemp.src = COMMON.formatStringBase64(data.pages[0].pageThumbnail);

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

                 if (lstPageNo.length > 0) {
                     CONTENTVIEW_CALLAPI.loadDataBookmark(lstPageNo);
                 } else {
                     CONTENTVIEW_GENERAL.isSendingData = false;
                 }
             },
             null);
    }
};

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

    var arrPageNo = '';
    for (var nIndex = 0; nIndex < CONTENTVIEW_GENERAL.totalPage; nIndex++) {
        if (nIndex == 0) {
            arrPageNo += (nIndex + 1);
        } else {
            arrPageNo += "," + (nIndex + 1);
        }
    }

    var params = {
            contentId: CONTENTVIEW_GENERAL.contentID,
            sid: CONTENTVIEW.getSessionId(),
            thumbnailFlg: 0,
            isStreaming: ClientData.isStreamingMode()
    };

    return AVWEB._callCmsApiWhen(
            ClientData.userInfo_accountPath(),
            "webContentPage",
            "GET",
            params
    );

};

CONTENTVIEW_CALLAPI.getSearchDataFromJsonDone = function(data) {
    CONTENTVIEW_GENERAL.contentName = data.contentTitle;
    CONTENTVIEW_GENERAL.dataWebContentPage = data;
};

CONTENTVIEW_CALLAPI.loadDataSearch = function(lstPageNo) {
    if (CONTENTVIEW_GENERAL.isSendingData == true) {

        var params = {
                contentId: CONTENTVIEW_GENERAL.contentID,
                sid: CONTENTVIEW.getSessionId(),
                pageNos: lstPageNo[0],
                thumbnailFlg: 1,
                isStreaming: ClientData.isStreamingMode()
        };

        AVWEB.avwCmsApi(ClientData.userInfo_accountPath(),
             "webContentPage",
             "GET",
             params,
             function (data) {
                 CONTENTVIEW_GETDATA.getDataLoaded(data.pages);

                 //Resize Image
                 var imgTemp = new Image();
                 $('#img_search_' + data.pages[0].pageNo).attr('src', COMMON.formatStringBase64(data.pages[0].pageThumbnail));

                 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');
                     }
                 };

                 imgTemp.src = COMMON.formatStringBase64(data.pages[0].pageThumbnail);

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

                 if (lstPageNo.length > 0) {
                     CONTENTVIEW_CALLAPI.loadDataSearch(lstPageNo);
                 } else {
                     CONTENTVIEW_GENERAL.isSendingData = false;
                 }
             },
             null);
    }
};

CONTENTVIEW_CALLAPI.ready = function(){
};