check.js 116 KB
Newer Older
Yujin Seo committed
1 2 3 4 5 6
// 名前空間
var CHK = {};

CHK.operationType;       //プロジェクトタイプ 0:リストコンテンツ 1:図面コンテンツ 2:360コンテンツ 3:PDFコンテンツ
CHK.isCms = false;           //true:CMSモード
CHK.isWeb = false;           //true:Web表示モード
7
CHK.isAndroid = false;
8
CHK.isIOS = false;
Yujin Seo committed
9 10 11
CHK.reportMode = "1";              //報告モード default1で、定期点検で変更される
CHK.debug;                   //1:デバッグモード
CHK.isMobile;           //1:モバイル対応で表示
12
CHK.isRFIDBarcodeScan;           //1:RFID,バーコードスキャン使用
Yujin Seo committed
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
CHK.reportType;       //0:報告(Type1) 1:定期点検(Type2) 2:報告・回答(Type3) 3:複数工程(Type4)
CHK.useKrpano = true;        //true:krpanoを使用 false:krpanoを使用しない
CHK.lookHotspot;             //移動先ホットスポット保持用
CHK.saveAttachedDataUrl;     //添付ファイルBase64文字列保持
CHK.content;                 //コンテンツJSON
CHK.taskHotspot;             //ホットスポットJSON
CHK.taskReport;              //作業報告JSON
CHK.workingGroup;             //作業者グループマスタJSON
CHK.taskReportSuggest;       //作業報告入力補完JSON
CHK.taskReportQuestion;      //作業報告設問情報JSON
CHK.routineTask;          //定期点検情報JSON
CHK.setBigFontFlg;           //レポートフォント表示サイズを保存
CHK.taskTapMode = 1;       //タスク移動・報告モード 0:移動       1:報告(デフォルト)
CHK.appRelationVer = 1;    //アプリとの連携で行われた修正のバージョン
//絞り検索追加
CHK.questionApertureList;		//絞り検索グループ

CHK.groupTreeInfo;      //担当グループ参照用 ログインユーザーが所属しているグループ情報
CHK.operationGroup;    //担当グループ参照用 作業の報告担当グループ情報

// PDFプロジェクト対応
CHK.pdf_numPages;
CHK.pdf_pageNum;

CHK.deleteName;  //削除ホットスポット名保持用
CHK.reportBasePath = "./";		//	レポートデータのベースパス

40 41 42 43
CHK.operation;  //作業一覧データ
CHK.operationGroupMaster;  //カテゴリーデータ
CHK.operationGroupMasterRelation;  //作業・カテゴリー関係データ
CHK.pushMessage;  //コミュニケーションデータ
44
CHK.pushMessageList;
45

46 47
CHK.scanResultCode;  //スキャンしたRFID,バーコード
CHK.scanType;  //スキャン種別(0:バーコード、1:RFID)
48
CHK.isChat;
49 50 51 52 53 54
CHK.dashboardSetting = {
	newReport: true,
    continousWork: true,
    reportWarning: true,
    dashboardHome: false,
};
55

56 57 58 59 60 61
CHK.dashboardBatch = {
	newReport: 0,
    continousWork: 0,
    reportWarning: 0,
};

62
var pageLang; // ページ設定言語
63
var CATEGORY_HEIGHT; //カテゴリー描画用固定値(高さ)
64
var msgMap = { // velocity?
65
    all:{ja:"全て", ko:"전체", en:"All"},
66 67 68 69 70 71 72 73 74 75 76 77 78
    inputLoginInfo: {ja:"ログイン情報を入力してください", ko:"로그인 정보를 입력해주세요.", en:"Please enter your login information"},
    txtLoginAccPath: {ja:"アカウントパス", ko:"사업자경로", en:"Account path"},
    txtLoginId: {ja:"ログインID", ko:"아이디", en:"ID"},
    txtLoginPwd: {ja:"パスワード", ko:"패스워드", en:"Password"},
    txtLoginPwdRbr: {ja:"アカウントパスとログインIDを記憶する", ko:"사업자경로와 아이디를 저장", en:"Remember your account path and login ID"},
    dspLogin: {ja:"ログイン・伝送", ko:"로그인·전송", en:"Login·Transmission"},
    inputError: {ja:"アカウントパス、ログインID、パスワードは必須です。", ko:"사업자경로, 아이디, 패스워드는 필수입니다.", en:"Account path, login ID, password are mandatory."},
    loginError: {ja:"ユーザアカウントをご確認の上、再度ログインしてください。", ko:"로그인 정보를 확인한 후, 다시 로그인 해주세요.", en:"Please check your user account and login again."},
    doUpload: {ja:"アップロード中", ko:"업로드합니다.", en:"Upload."},
    uploadError: {ja:"アップロードに失敗しました。", ko:"파일업로드가 실패했습니다.", en:"Upload failed."},
    completeUpload: {ja:"登録が完了しました。<br/>右上の閉じるボタンをクリックし、画面を閉じてください。", ko:"등록했습니다. <br/>오른쪽 위의 닫기버튼을 클릭해, 화면을 닫아주세요.", en:"Registered. <br/>Please click the close button in the upper right and close the screen."},
    Yes: {ja:"はい", ko:"Yes", en:"Yes"},
    No: {ja:"いいえ", ko:"No", en:"No"},
79
    onlyRfid:{ja:"RFID又はバーコードが設定されています。\n該当コードを読み込んでください。", ko:"RFID또는 바코드가 설정되어있습니다.\n해당코드를 스캔해주십시오.", en:"RFID or barcode is set.\nPlease scan the code."},
80
    overwriteCheck: {ja:"未公開のバージョンの簡易帳票が存在します。<br/>上書きしますか?", ko:"미공개 버전의 간이 서류가 존재합니다. <br/>덮어 쓰시겠습니까?", en:"There is an unpublished version of the quick report. <br/>Do you want to overwrite?"},
Yujin Seo committed
81 82 83 84
    dateError: { ja: "開始日は終了日の前に設定してください。", ko: "잘못된 검색일입니다.", en: "Please enter correct search date." },

    buttonCategory: { ja: "カテゴリー", ko: "카테고리", en: "Category" },
    buttonRefresh: { ja: "更新", ko: "갱신", en: "Refresh" },
85
    buttonBack: { ja: "戻る", ko: "Back", en: "Back" },
Yujin Seo committed
86 87 88 89 90 91 92 93 94 95 96 97
    buttonScan: { ja: "スキャン", ko: "스캔", en: "Scan" },
    placeholderOperationName: { ja: "作業名", ko: "작업명", en: "Working Name" },
    labelPeriod: { ja: "期間", ko: "기간", en: "Period" },
    labelStartDate: { ja: "開始日", ko: "시작일", en: "Start date" },
    labelEndDate: { ja: "終了日", ko: "종료일", en: "End date" },
    placeholderSelect: { ja: "選択", ko: "선택", en: "Choice" },
    labelSort: { ja: "並び替え", ko: "정렬", en: "Sort" },
    labelSortName: { ja: "作業名順", ko: "작업명순", en: "By working name" },
    labelSortNew: { ja: "作業期間が新しい順", ko: "작업기간이 최신순", en: "By newest period" },
    labelSortOld: { ja: "作業期間が古い順", ko: "작업기간이 오래된순", en: "By oldest period" },
    labelSortType: { ja: "報告タイプ順", ko: "보고타입순", en: "By report type" },
    labelSortOpen: { ja: "閲覧日が新しい順", ko: "열람순", en: "By newest viewing date" },
98
    labelReset: { ja: "クリア", ko: "클리어", en: "Clear" },
99
    headerItemName: { ja: "作業名", ko: "작업명", en: "Working Name" },
Yujin Seo committed
100 101 102 103 104 105
    headerStartDate: { ja: "開始日", ko: "시작일", en: "Start date" },
    headerEndDate: { ja: "終了日", ko: "종료일", en: "End date" },
    buttonHome: { ja: "ホーム", ko: "홈", en: "Home" },
    buttonRelatedContent: { ja: "関連資料", ko: "관련자료", en: "Related Content" },
    buttonCommunication: { ja: "コミュニケーション", ko: "커뮤니케이션", en: "Communication" },
    buttonSetting: { ja: "設定", ko: "설정", en: "Setting" },
106 107 108
    labelLoading: { ja: "読み込み中", ko: "로딩중", en: "Loading" },
	buttonOperationList: { ja: "作業一覧", ko: "Operations List", en: "Operations List" },
	buttonDashboard: { ja: "ダッシュボード", ko: "Dashboard", en: "Dashboard" },
109 110 111 112 113 114 115 116 117 118 119
	dashboardHeaderTitle: { ja: "ダッシュボード", ko: "Dashboard", en: "Dashboard" },
	buttonDashboardSetting: { ja: "設定", ko: "Dashboard Setting", en: "Dashboard Setting" },
	pickupHeaderTitle: { ja: "ピックアップ", ko: "Pickup", en: "Pickup" },
	communicationHeaderTitle: { ja: "コミュニケーション", ko: "Communication", en: "Communication" },
	newRegistrationTitle: { ja: "新規報告", ko: "New Registration", en: "New Registration" },
	continousWorkTitle: { ja: "工程管理", ko: "Continous Work", en: "Continous Work" },
	reportWarningTitle: { ja: "警告を含む報告", ko: "Report Warning", en: "Report Warning" },
	messageListTitle: { ja: "メッセージ一覧", ko: "Message List", en: "Message List" },
	sendMessageTitle: { ja: "メッセージ送信", ko: "Send Message", en: "Send Message" },
	distanceSupportTitle: { ja: "遠隔支援", ko: "Distance Support", en: "Distance Support" },
	chatTitle: { ja: "チャット", ko: "Chat", en: "Chat" },
120 121 122 123 124 125 126
	//dashboard setting screen
	dashboardSettingHeaderTitle: { ja: "ダッシュボード設定", ko: "Dashboard Settings", en: "Dashboard Settings" },
	dashboardSettingDisplayHeader: { ja: "表示切替", ko: "Display", en: "Display"},
	dashboardSettingNewRegistrationTitle: { ja: "新規報告", ko: "New Registration", en: "New Registration"},
	dashboardSettingContinousWorkTitle: { ja: "工程作業", ko: "Continous Work", en: "Continous Work"},
	dashboardSettingReportWarningTitle: { ja: "警告を含む作業", ko: "Report Warning", en: "Report Warning"},
	dashboardSettingDashboardHomeTitle: { ja: "ダッシュボードをホーム画面にする", ko: "Dashboard Home", en: "Dashboard Home"},
127 128
	labelPickUp: { ja: "ピックアップ", ko: "Pick up", en: "Pick up" },
	labelNewReport: { ja: "新規報告", ko: "New report", en: "New report" },
129
	labelContinousWork: { ja: "工程作業", ko: "Process work", en: "Process work" },
130
	labelReportWithWarning: { ja: "警告を含む報告", ko: "Reports with warnings", en: "Reports with warnings" }
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
};

// 言語取得
function getLang() {
    if (!pageLang) {
        if (localStorage["lang"]) {
            pageLang = localStorage["lang"];
        }
        else {
            pageLang = (window.navigator.languages && window.navigator.languages[0]) ||
                window.navigator.language ||
                window.navigator.userLanguage ||
                window.navigator.browserLanguage;
            localStorage["lang"] = pageLang;
        }
    }

    return pageLang;
}

151 152 153
// 言語コードをセット
function setLangCode() {
	lang = getLang();
154 155 156 157 158 159 160
    if (lang.split("-")[0] == "ja") {
        lang = "ja";
    } else if (lang.split("-")[0] == "ko") {
        lang = "ko";
    } else {
        lang = "en";
    }
161 162 163 164
}

// メッセージを取得
function getMsg(key) {
165 166 167 168 169
    var msg = msgMap[key];
    if (!msg) {
        return "";
    }

Yujin Seo committed
170
    return msg[CHK.lang];
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
}

// 言語の変更処理
function changeLang(lang) {
    localStorage["lang"] = lang;
    pageLang = lang;

    if ($("#btnLogin").is(":visible")) {
        showMessage(getMsg("inputLoginInfo"));
    } else {
        showMessage(getMsg("completeUpload"));
    }

    $(".lang").each(function() {
        var key = $(this).attr("lang");
        if (key) {
            if ($(this).prop("tagName") == "input" && ($(this).attr("type") == "button" || $(this).attr("type") == "submit")) {
                $(this).val(getMsg(key));
            } else {
                $(this).html(getMsg(key));
            }
        }
    });
}

Yujin Seo committed
196 197
//JSONファイルパス
CHK.jsonPath = {
Yujin Seo committed
198
    operationList: "operationList.json", // 作業一覧JSONデータ
199 200
    operationGroupMasterList: "operationGroupMasterList.json", // カテゴリーJSONデータ
    operationGroupMasterRelationList: "operationGroupMasterRelationList.json", // 作業・カテゴリー関係JSONデータ
201 202
    pushMessageList: "pushMessageList.json", // コミュニケーションデータJSONデータ
	dashboardSetting: "dashboardSetting.json"
Yujin Seo committed
203 204 205
};
//アプリ送信用コマンド
CHK.apiCmd = {
Yujin Seo committed
206
    finishInit: "finishInit",                   //初期化完了
Yujin Seo committed
207
    goRelationContent: "goRelationContent",     //関連資料
208
    goCommunication: "goCommunication",
Yujin Seo committed
209
    goSetting: "goSetting",                     //設定
Yujin Seo committed
210
    goOperation: "goOperation",                 //作業開始
Yujin Seo committed
211
    goPanoramaEdit: "goPanoramaEdit",           //パノラマ作業資料編集
Yujin Seo committed
212
    refreshContent: "refreshContent",           //新着更新
213
    resetSearch: "resetSearch",                 //検索条件初期化
Yujin Seo committed
214
    saveSortType: "saveSortType",               //並び替え保存
Yujin Seo committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
	editAttached: "editAttached",				//添付ファイル編集
	saveAttached: "saveAttached",               //添付ファイル保存
	insertReport: "insertTaskReport",           //作業報告保存
	updateReport: "updateTaskReport",           //作業報告更新
	moveHotspot: "moveHotspot",                 //ホットスポット移動
	cancelReport: "cancelTaskReport",           //作業報告キャンセル
	deleteReport: "deleteTaskReport",           //作業報告削除
	showReportOzd: "showReportOzd",             //作業報告レポート表示
	previewReportOzd: "previewReportOzd",       //作業報告ozdプレビュー
	getGpsInfo: "getGpsInfo",                   //GPS取得
	changeDisplayStatus: "changeDisplayStatus", //コンテンツ表示変更(ヘルプ表示用)
	showRelatedContent: "showRelatedContent",   //関連資料表示
	localSave: "localSaveTaskReport",           //ローカル保存
	changeReport: "changeTaskReport",            //報告レポート変更
	getGroupTreeInfo: "getGroupTreeInfo",   //担当グループ参照用 ログインユーザーが所属しているグループ取得
230
	deleteProcess: "deleteProcess",
231
	changeOperationGroupMaster: "changeOperationGroupMaster",
232
	actionPushMessage: "actionPushMessage",
233 234 235 236
	saveJson: "saveJson",
	goSendMessage: "goSendMessage",
	goDistanceSupport: "goDistanceSupport",
	goChat: "goChat"
Yujin Seo committed
237 238 239 240 241 242 243 244 245 246 247 248 249 250
};
//CMS送信用コマンド
CHK.actCmd = {
	editAttached: "editAttached",				//添付ファイル編集
	getTaskReport: "getTaskReport",            //初期情報取得(作業報告)
	saveAttached: "saveAttached",              //添付ファイル保存
	insertReport: "actTaskReport",             //作業報告保存
	updateReport: "actTaskReport",             //作業報告更新
	saveRoutineTaskReport: "actRoutineTaskReport", //点検作業報告保存・更新
	moveHotspot: "actTaskReport",          //ホットスポット移動
	cancelReport: "cancelTaskReport",          //作業報告キャンセル
	deleteReport: "actTaskReport",          //作業報告削除
	deleteRoutineTaskReport: "actRoutineTaskReport", //点検作業報告保存・更新
};
251 252 253 254 255 256
//iOS送信用コマンド
const NATIVE_KEY_IOS = {
	getCachePath: "getCachePath",
	getOperationListJson: "getOperationListJson",
	getOperationGroupMasterListJson: "getOperationGroupMasterListJson",
	getOperationGroupMasterRelationListJson: "getOperationGroupMasterRelationListJson",
257
	getPushMessageListJson: "getPushMessageListJson",
258
	searchOperationList: "searchOperationList",
259 260
	getSortType: "getSortType",
	getDashboardSettingJson: "getDashboardSettingJson"
261
};
Yujin Seo committed
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
// レポートファイル保存タイプ
CHK.REPORT_SAVE_TYPE = {
	OZD: "0",
	PDF: "1",
	HTML: "2",
	JPG: "3"
};
// OZDビューアポストメッセージ送信用コマンド
CHK.ozdCmd = {
	ozdSave: "ozdSave",
	ozdClear: "ozdClear",
	ozdOpened: "ozdOpened",
	close: "close",
	fixed: "fixed",
	unfixed: "unfixed"
};
//プロジェクトタイプ
CHK.OPERATION_TYPE = {
	LIST: "0",
	DRAWING: "1",
	VTOUR: "2",
    PDF: "3"
};
// 表示状態
CHK.DISPLAY_STATUS = {
	init: "0",           //初期表示
	showingForm: "1",    //報告入力
	previewing: "2",     //報告プレビュー
	showingList: "3"     //作業一覧
};

//プロジェクト報告タイプ
CHK.REPORT_TYPE = {
	REPORTONLY: "0",     //報告のみ
	INSPECT: "1",        //定期点検
	WITHREPLY: "2",      //報告・回答(チェーン)
	WORKFLOW: "3"        //複数工程(ワークフロー)
}

// タスクレポート追加区分
CHK.ADD_REPORT_FLG = {
	UNABLE: "0",
	ABLE: "1"
}

// 一時保存区分
CHK.LOCAL_SAVE_FLG = {
	UNABLE: "0",
	ABLE: "1"
}

// 権限区分
CHK.HAS_AUTHORITY = {
	FALSE: "0",
	TRUE: "1"
}

/**
 * タップモード
 *
 */
CHK.TAP_MODE = {
	MOVE : 0,                           //移動
	SHOW : 1                            //報告
}

// 表示・情報取得の基準となるタスクのベースチェーンNo(0)
CHK.BASE_TASK_REPLY_NO = 0;   //タイプに関係なく、基準となる報告のreplyNo
//タスク回答番号保存用
CHK.taskReplyNo = CHK.BASE_TASK_REPLY_NO;

// タスクレポート追加可能ユーザか判定
CHK.hasAddTaskAuthority = function() {
	// 追加されたタスクレポートがまだ存在しない、もしくはチェーンNoが0のタスクに権限がある場合タスク追加できるユーザだと判定する
	return CHK.reportType != CHK.REPORT_TYPE.WITHREPLY || CHK.taskReport.taskReport_0.length == 0
	|| CHK.taskReport.taskReport_0.some(function(taskReport, i) {
		if (taskReport.hasAuthority == CHK.HAS_AUTHORITY.TRUE) return true;
	});
};

342 343
CHK.sessionKeys = [
	'reportType', 'isCms', 'isWeb', 'isWindows', 'isAndroid', 'isIOS', 'isRFIDBarcodeScan', 'isOperationGroupMaster', 
344
	'lang', 'debug', 'isMobile', 'isChat',
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
];

CHK.loadSessionData = function() {
	if (typeof sessionStorage.CHK === 'undefined') {
		return {};
	}
	let sessionData = JSON.parse(sessionStorage.CHK);
	if (typeof sessionData !== 'object') {
		return {};
	}
	return sessionData;
}

CHK.loadSessionKey = function(key) {
	let sessionData = CHK.loadSessionData();
	if (typeof sessionData[key] !== 'undefined' && typeof CHK[key] === 'undefined') {
		CHK[key] = sessionData[key];
	}
}

CHK.loadInitSession = function() {
	let sessionData = CHK.loadSessionData();
	CHK.sessionKeys.forEach(function(key) {
		if (typeof sessionData[key] !== 'undefined' && typeof CHK[key] === 'undefined') {
			CHK[key] = sessionData[key];
		}
	});
}

CHK.saveInitSession = function() {
	var sessionData = {};
	CHK.sessionKeys.forEach(function(key) {
		if (typeof CHK[key] !== 'undefined') {
			sessionData[key] = CHK[key];
		}
	});
	sessionStorage.CHK = JSON.stringify(sessionData);
}

Yujin Seo committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397
// 共通初期処理
CHK.initCommon = function() {
	//JSON初期化
	//作業報告情報初期化
	CHK.taskReport = {taskReport_0: []};
	//作業報告入力補完初期化
	CHK.taskReportSuggest = {taskReportSuggest_0: []};
	//ホットスポット情報初期化
	CHK.taskHotspot = {hotspot: []};
	var urlParam = CHK.getUrlParameter();
	CHK.reportType = urlParam.report_type;
	CHK.isCms = urlParam.is_cms;
	CHK.isWeb = urlParam.is_web;
	CHK.isWindows = urlParam.app && urlParam.app == "windows"; // windowsアプリの対応追加 v1.1.0
398
	CHK.isAndroid = urlParam.app && urlParam.app == "android";
Yujin Seo committed
399
    CHK.isIOS = urlParam.app && urlParam.app == "ios";
400
    CHK.isRFIDBarcodeScan = urlParam.isRFIDBarcodeScan && urlParam.isRFIDBarcodeScan == "1";
401
    CHK.isOperationGroupMaster = urlParam.isOperationGroupMaster && urlParam.isOperationGroupMaster == "1";
402
    if (typeof CHK.sortIndex == 'undefined') CHK.sortIndex = urlParam.sortIndex;
Yujin Seo committed
403
    CHK.lang = urlParam.lang;
404 405
	CHK.debug = urlParam.debug;
	CHK.isMobile = urlParam.mobile_flg && urlParam.mobile_flg == "1";
406
	CHK.isChat = urlParam.isChat && urlParam.isChat == "1";
407 408 409 410 411 412

	CHK.loadInitSession();
	if (typeof location.pathname === 'string' && location.pathname.includes('index.html') == true) {
		//save url parameter of top page
		CHK.saveInitSession();
	}
413
	CHK.loadDashboardSetting();
Yujin Seo committed
414

Yujin Seo committed
415 416 417
	// ウェブの場合、作業一覧の表示広さを変更
	if (CHK.isWeb) {
		$("#checkList").addClass("web");
Yujin Seo committed
418 419 420
    }
    // Windowsの場合、RFID未使用
    if (CHK.isWindows) {
421
        $("#rfidScanButton").hide();
Yujin Seo committed
422
    }
423 424

    // アンドロイド・IOSの場合スキャンオプションによってスキャン表示
425
    if (CHK.isIOS && CHK.isRFIDBarcodeScan) {
426 427
        $("#rfidScanButton").removeClass("d-none");
    }
428 429 430
    if (CHK.isOperationGroupMaster) {
        $("#operationGroupMasterButton").removeClass("d-none");
    }
431

Yujin Seo committed
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 487 488 489 490 491 492 493 494
	if (CHK.isCms) {
		CHK.setBeforeunload();
	}
	if (CHK.isMobile != 1) {
		if (CHK.isFullScreen()) CHK.isMobile = 1;
	}
	// モバイルまたはリストの場合、フォーム・作業リストを全画面表示
	// 以外の場合、min-widthを400pxとして表示する
	if (CHK.isMobile == 1 || CHK.operationType == CHK.OPERATION_TYPE.LIST) {
		$("#checkInput").css("width", "calc(100% - 0px)");
		$("#checkList").css("width", "calc(100% - 2px)");
	} else {
		$("#checkInput").css("min-width", "400px");
		$("#checkList").css("min-width", "400px");
	}

}

/**
 * 初期処理
 *
 */
CHK.init = function() {
	//共通処理
	CHK.initCommon();
	//VR設定
	krpano.call("set(content[def].useVr, false);");

	if (!CHK.operationType) CHK.operationType = CHK.OPERATION_TYPE.VTOUR;
	if (CHK.operationType == CHK.OPERATION_TYPE.VTOUR) {
		//360
		CHK_V.init();
		$("#sceneName").text(krpano.get("scene[get(xml.scene)].title"));
		if ($("#topnav").length > 0) {
			$("#sceneName").css("margin", "45px 10px");
		}
	} else if (CHK.operationType == CHK.OPERATION_TYPE.DRAWING) {
		//図面
		CHK_Z.init();
		$("#sceneName").hide();
	}

	// 表示状態変更通知
	CHK.sendDisplayStatus($("#checkList").is(':visible')? CHK.DISPLAY_STATUS.showingList : CHK.DISPLAY_STATUS.init);

	$(window).bind("resize", function() {
		if (krpano.get("isOpen") == "1") {
			krpano.call("toggleAllTaskLayerOnMap()");
			setTimeout(function() {
				krpano.call("update_scale()");
				krpano.call("delayedcall(0.5, toggleAllTaskLayerOnMap();)");
			}, 1000);
		}
		$(".ui-dialog").css("top", "calc(50%)");
	});
	if (CHK.isWeb) {
		// OZDビューワのリサイズ処理
		$(window).bind("resize", function() {
			if ($("#report_dialog").is(":visible")) {
				$(".noTitleDialog:visible").width("80%").height(window.innerHeight*0.9).position({my: 'center', at: "center", of: window});
				$("#report_dialog").height($(".noTitleDialog:visible").height() - 100);
			}
		});
Yujin Seo committed
495
    }
Yujin Seo committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
}

/**
 * 全画面判定
 *
 */
CHK.isFullScreen = function() {
	if (CHK.isWeb) return false;
	var minSize = 550;
	console.log("innerWidth:" + window.innerWidth);
	console.log("innerHeight:" + window.innerHeight);
	return window.innerWidth < minSize || window.innerHeight < minSize;
}

/**
 * 作業報告初期処理
 *
 * @param callback コールバック
 */
CHK.initReport = function(callback) {
	console.log("initReport start");
	if (!CHK.reportMode) {
		//報告モード切り替えボタンを表示
		$("#editHeader").show();
		CHK.changeReportMode("1");
	}

	if (CHK.isWeb) {
		CHK.initReportWeb(callback);
	} else {
		CHK.initReportApp(callback);
	}

}

/**
 * 作業報告初期処理、アプリ
 *
 * @param callback コールバック
 */
Yujin Seo committed
536
CHK.initReportApp = function (callback) {
537
	//カテゴリー高さ変更
538 539 540
	$(window).resize(function() {
		CHK.setCategoryHeight();
	});
Kim Eunchul committed
541 542 543
	CHK.isSearched = false;
	CHK.operationGroupMasterId = 0;
	// 作業一覧JSONデータ
544
	CHK.initOperationList();
545

Kim Eunchul committed
546 547
	// カテゴリーJSONデータ
	CHK.loadJson(CHK.jsonPath.operationGroupMasterList, function (json) {
548 549 550
		CHK.operationGroupMaster = json;
		//カテゴリー設定
		CHK.createCategory(CHK.operationGroupMaster.operationGroupMasterList);
Kim Eunchul committed
551
	});
Yujin Seo committed
552

Kim Eunchul committed
553 554 555 556
	// 作業・カテゴリー関係JSONデータ
	CHK.loadJson(CHK.jsonPath.operationGroupMasterRelationList, function (json) {
		CHK.operationGroupMasterRelation = json;
	});
Yujin Seo committed
557

558 559 560
}

CHK.initPushMessageList = function() {
Kim Eunchul committed
561
	CHK.loadJson(CHK.jsonPath.pushMessageList, function (json) {
562 563 564 565 566 567
		CHK.pushMessageList = json.pushMessageList;
		if (typeof CHK_Dashboard !== 'undefined') {
			//update batch message list at dashboard screen
			CHK_Dashboard.updateDataCommunications();
    		CHK_Dashboard.initCommunications();
		}
568 569 570
		if (typeof CHK_MessageList !== 'undefined') {
			CHK_MessageList.initPushMessageListCallback(CHK.pushMessageList);
		}
Kim Eunchul committed
571
	});
Yujin Seo committed
572 573
}

574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
CHK.loadDashboardBatch = function(operationList) {
	if (!operationList) return;
	CHK.dashboardBatch.newReport = operationList.length;
	CHK.dashboardBatch.continousWork = 0;
	CHK.dashboardBatch.reportWarning = 0;
	for (var i = 0; i < operationList.length; i++) {
		if (operationList[i].reportType == 3) {
			if (operationList[i].processList && operationList[i].processList.length > 0) {
				CHK.dashboardBatch.continousWork += 1;
			}
		}
		if (operationList[i].warningReportList && operationList[i].warningReportList.length > 0) {
			CHK.dashboardBatch.reportWarning += operationList[i].warningReportList.length;
		}
	}
	if (typeof CHK_Dashboard !== 'undefined') {
		//update batch pickup list at dashboard screen
		CHK_Dashboard.updateDataPickups();
		CHK_Dashboard.initPickups();
	}
}

596
CHK.loadDashboardSetting = function(callback) {
597 598 599 600
	CHK.loadJson(CHK.jsonPath.dashboardSetting, function(json) {
		if (json) {
			CHK.dashboardSetting = json;
		}
601 602 603
		if (callback) {
		    callback();
		}
604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
	});
	// ios clear localStorage when reopen index page
	// var setting = localStorage.getItem('dashboardSetting');
	// if (setting) {
	// 	CHK.dashboardSetting = JSON.parse(setting);
	// }
}

CHK.saveDashboardSetting = function(key, enabled) {
	if (key) {
		CHK.dashboardSetting[key] = enabled;
	}
	CHK.saveJson(CHK.jsonPath.dashboardSetting, CHK.dashboardSetting);
	//localStorage.setItem('dashboardSetting' , JSON.stringify(CHK.dashboardSetting));
}

Yujin Seo committed
620
/**
621 622 623 624 625 626 627 628
 * 作業一覧を描画
 */
CHK.initOperationList = function() {
	// 作業一覧JSONデータ
	CHK.loadJson(CHK.jsonPath.operationList, function (json) {
		CHK.operation = json;
		$('#operationTable').empty();
		CHK.operation.searchOperationList = json.operationList;
629
		CHK.loadDashboardBatch(CHK.operation.operationList);
630
		//作業一覧描画
631
		console.log("json.operationList",JSON.stringify( json.operationList) );
632
		CHK.createOperationList(CHK.operation.operationList);
633
		CHK_pu.initOperationList(CHK.operation.operationList);
634
	});
635 636 637

	// コミュニケーションデータJSONデータ
	CHK.initPushMessageList();
638 639 640
}

/**
641 642 643 644
 * カテゴリー表示領域の高さ調整
 */
CHK.setCategoryHeight = function() {
	//カテゴリー高さ固定
645 646 647
	CATEGORY_HEIGHT = $('footer').offset().top - $('#category-menu').offset().top;
	console.log(CATEGORY_HEIGHT);
	$("#category-menu").css("overflow", "scroll");
648
	$('#category-menu').height(CATEGORY_HEIGHT);
649 650 651 652
	$('#overlayDiv').height(CATEGORY_HEIGHT);
}

/**
Yujin Seo committed
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
 * 作業報告初期処理、Web
 *
 * @param callback コールバック
 */
CHK.initReportWeb = function(callback) {

	CHK.cmsAjax(CHK.getActionUrl(CHK.actCmd.getTaskReport), "", function(json) {
		CHK.updateReportJsonWeb(json, callback);
	});

}

/**
 * 作業報告「登録、更新、削除」の後、json更新
 *
 * @param json CMSから貰った物
 * @param callback コールバック
 */
CHK.updateReportJsonWeb = function(json, callback) {
	console.log(json);
	//JSON初期化
	CHK.taskReport = {taskReport_0: []};
	// オペレーションタイプが報告・回答の場合、念のためtaskReport_1のオブジェクトを作成しておく
	if (CHK.reportType == CHK.REPORT_TYPE.WITHREPLY) {
		CHK.taskReport.taskReport_1 = [];
	}
	CHK.taskReportSuggest = {taskReportSuggest_0: {}};
	CHK.taskHotspot = {hotspot: []};
	CHK.workingGroup = {taskGroup_0: []};
	json.taskReport_0.forEach(function(task) {
		task.taskHotspotInfo.taskId = task.taskId;
		//ホットスポット情報をロード
		CHK.taskHotspot.hotspot.push(task.taskHotspotInfo);
		//作業報告情報をロード
		if (task.taskReportInfo) {
			task.taskReportInfo.hasAuthority = task.hasAuthority;
			CHK.taskReport.taskReport_0.push(task.taskReportInfo);
		}
	});
	json.taskReport_1.forEach(function(task) {
		task.taskHotspotInfo.taskId = task.taskId;
		//作業報告情報をロード
		if (task.taskReportInfo) {
			task.taskReportInfo.hasAuthority = task.hasAuthority;
			CHK.taskReport.taskReport_1.push(task.taskReportInfo);
		}
	});

	//絞り検索
	if( CHK.questionApertureList == null){
		CHK.questionApertureList = json.apertureMaster;
	}

	if (callback) callback();

	//作業者グループマスタをロード
	json.workingGroup.taskGroup_0.forEach(function(workingGroup) {
		CHK.workingGroup.taskGroup_0.push(workingGroup)
	});
	//作業報告入力補完情報をロード
	CHK.taskReportSuggest = json.taskReportSuggest;
	//作業報告設問情報をロード
	CHK.taskReportQuestion = json.taskReportQuestion;
	//コンテンツ情報をロード
	CHK.content = json.content;
}

/**
 * JSONファイルをロード
 *
 * @param fileName JSONファイル名
 * @param callback コールバック
 */
CHK.loadJson = function(fileName, callback) {
727 728
	if (CHK.isAndroid) {
	    fileName = android.getCachePath() + "/" + fileName;
729
	} else if (CHK.isIOS) {
730 731 732 733
	} else {
	    //キャッシュ対応
	    fileName = fileName + "?" + new Date().getTime().toString(16);
	}
734 735 736 737 738 739

	if (CHK.isIOS) {
		if (fileName == CHK.jsonPath.operationList) {
			json = CHK_iOS.getOperationListJson();
			callback(json);
		} else if (fileName == CHK.jsonPath.operationGroupMasterList) {
740
			json = CHK_iOS.getOperationGroupMasterListJson();	
741 742 743 744 745 746 747
			callback(json);
		} else if (fileName == CHK.jsonPath.operationGroupMasterRelationList) {
			json = CHK_iOS.getOperationGroupMasterRelationListJson();
			callback(json);
		} else if (fileName == CHK.jsonPath.pushMessageList) {
			json = CHK_iOS.getPushMessageListJson();
			callback(json);
748 749 750
		} else if (fileName == CHK.jsonPath.dashboardSetting) {
			json = CHK_iOS.getDashboardSettingJson();
			callback(json);
751 752 753 754
		}
		return;
	}

Yujin Seo committed
755 756 757
	$.getJSON(fileName, function(json) {
		console.log("load json file", fileName, json);
		callback(json);
758
    }).fail(function(jqXHR, textStatus, errorThrown) {
Yujin Seo committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
        console.log("エラー:" + textStatus);
        console.log("テキスト:" + jqXHR.responseText);
    });
}

/**
 * JSONファイルを再ロード
 *
 * @param fileName JSONファイル名
 */
CHK.reloadJson = function(fileName) {
	CHK.loadJson(fileName, function(json) {
		for (var key in CHK.jsonPath) {
			if (CHK.jsonPath[key] == fileName) {
				CHK[key] = json;
			}
		}
	});
}

/**
 * ダイアログを表示
 *
 * @param message 表示メッセージ
 * @param ok OKボタン押下時の処理
 * @param cancel キャンセルボタン押下時の処理
 * @param isError true:エラーダイアログ
 */
CHK.showDialog = function(message, ok, cancel, isError, callback) {
	// メッセージがなく、ok時の処理があるとok処理を実行し、その以外は何もせずに処理を止める(ダイアログ表示しない)
	if (!message) {
		if (ok) ok();
		else CHK.closeLoading();
		return;
	}
	var okButton = {
		text: "OK",
		class: "dialog_okButton",
		click: function() {
			if (CHK.operationType == CHK.OPERATION_TYPE.PDF) $("body").css("overflow", "visible"); // スクロール制御
			if (ok) ok();
			$("#check_dialog").dialog('close');
		}
	}
	var buttons = { OK: okButton };
	if (!isError) {
		buttons[getMsg("cancel")] = {
			text: getMsg("cancel"),
			class: "dialog_cancelButton",
			click: function() {
				if (CHK.operationType == CHK.OPERATION_TYPE.PDF) $("body").css("overflow", "visible"); // スクロール制御
				if (cancel) cancel();
				$("#check_dialog").dialog('close');
			}
		};
	}
	$("#check_dialog").dialog({
		dialogClass: 'noTitleDialog ui-dialog-titlebar dialogNoBorder',
		autoOpen: false,
		resizable: false,
		modal: true,
		width: CHK.isMobile == 1 ? "90%" : "auto",
		height: 'auto',
		title: ' ',
		buttons: buttons,
		open: function(e) {
			if (CHK.operationType == CHK.OPERATION_TYPE.PDF) $("body").css("overflow", "hidden"); // スクロール制御
			$(e.target).parent().css('background-color', 'rgba(128,128,128)');
			$(e.target).parent().css('position', 'absolute');
			$(e.target).parent().css('top', 'calc(50% + ' + $(document).scrollTop() + 'px)');
			$(e.target).parent().css('left', 'calc(50% + ' + $(document).scrollLeft() + 'px)');
			$(e.target).parent().css('transform', 'translateY(-50%) translateX(-50%)');
			$(e.target).parent().css('-webkit- transform', 'translateY(-50%) translateX(-50%)');
			$(e.target).parent().children(".ui-dialog-buttonpane").css('background-color', 'rgba(128,128,128)').css('border', 'none');
			$("#checkDialogMessage").html(message);

			if (callback) callback();
	    },
		close: function() {}
	});
	$("#check_dialog").dialog('open');
}

/**
 * ローディングを表示
 *
 * @param message 表示メッセージ
 */
CHK.showLoading = function(message) {
	$("#check_loading").dialog({
		dialogClass: 'noTitleDialog ui-dialog-titlebar dialogNoBorder',
		autoOpen: false,
		resizable: false,
		modal: true,
		width: "40%",
		height: 'auto',
		title: ' ',
		open: function(e) {
			$(e.target).parent().css('background-color', 'rgba(128,128,128)');
			$(e.target).parent().css('position', 'absolute');
			$(e.target).parent().css('top', '50%');
			$(e.target).parent().css('left', '50%');
			$(e.target).parent().css('transform', 'translateY(-50%) translateX(-50%)');
			$(e.target).parent().css('-webkit- transform', 'translateY(-50%) translateX(-50%)');
			$(e.target).parent().children(".ui-dialog-buttonpane").css('background-color', 'rgba(128,128,128)').css('border', 'none');
			$("#checkLoadingMessage").html(message);
		},
		close: function() {}
	});
	$("#check_loading").dialog('open');
}

/**
 * ローディングを閉じる
 *
 */
CHK.closeLoading = function() {
	if ($("#check_loading").hasClass("ui-dialog-content")) {
		$("#check_loading").dialog('close');
	}
}


/**
 * 作業報告フォームを表示
 *
 * @param name ホットスポット名
 * @param taskKey taskKey
 * @param lookto true:視点移動する
 */
CHK.showTaskReportForm = function(name, taskKey, lookto, element) {
	// ウェブでの対応
	if (CHK.isWeb) {
		var formType = CHK.taskReplyNo == CHK.BASE_TASK_REPLY_NO? "instruct" : "report";
		element.setAttribute("src", CHK.getShopUrl() + "enqueteReply/" + formType + "/" + operationId + "/" + CHK.getTaskId(name, taskKey));
		$("#checkInput").css("top", "36px");
		$("#checkInput").css("height", "calc(100% - 36px)");
	}
	element.setAttribute("frameborder", "0");
	element.width = "100%";
	element.height = "100%";
	if (CHK.operationType == CHK.OPERATION_TYPE.LIST) {
		$("#checkInput").css("border", "none");
	}
	$("#checkInput").css("opacity", "0");
	CHK.showCheckInput(element, taskKey);

	if (lookto) {
		var fov = krpano.get("view.fov");
		krpano.call("looktohotspot(" + name + "," + fov + ")");
	}

	element.onload = function() {
		// 連続作業の場合申し送り部、承認部の生成
		if (CHK.reportType == CHK.REPORT_TYPE.WORKFLOW) {
			element.contentWindow.createProcessParts();
		}

		var taskReport = CHK.getTaskReport(name, taskKey);
		var isPreview = false;
		// 既存報告情報があるか確認
		if (taskReport && taskReport.task) {
			var baseReport = CHK.getRecentVersionReport(taskKey);
			var param = {name: name, taskKey: taskKey, pointNo: CHK.getPointNo(baseReport), taskProgress: CHK.getTaskProgress(name, taskKey), taskName: CHK.getTaskName(baseReport), mode: "1", attachedChangeFlag: "0"};
			var replyReportList;
			var createTaskBtnFlg;
			if (CHK.reportType == CHK.REPORT_TYPE.WITHREPLY) {
				replyReportList = CHK.getTaskReplyReportList(taskKey);
				if (replyReportList.length || CHK.taskReplyNo != CHK.BASE_TASK_REPLY_NO) createTaskBtnFlg = true;
			}
			// 報告権限がある場合は報告画面を、ない場合はプレビュー画面を表示する
			// Type1の場合はプレビューなし
			if (CHK.reportType == CHK.REPORT_TYPE.WITHREPLY && (taskReport.hasAuthority == CHK.HAS_AUTHORITY.FALSE || (CHK.isCms && CHK.taskReplyNo != CHK.BASE_TASK_REPLY_NO))) {
				var reportMode = CHK.reportMode == "1" ? 0 : 1;
				isPreview = true;
				element.contentWindow.createPreview(taskReport, CHK.taskReportQuestion, CHK.workingGroup, CHK.content, reportMode, replyReportList, param);
				if (createTaskBtnFlg) element.contentWindow.createTaskButton(name, taskKey, true);
				CHK.sendDisplayStatus(CHK.DISPLAY_STATUS.previewing, taskKey);
			} else {
				element.contentWindow.setCheckInitData(taskReport, CHK.taskReportQuestion, CHK.content, CHK.taskReportSuggest, param, replyReportList);
				if (createTaskBtnFlg) element.contentWindow.createTaskButton(name, taskKey);
				CHK.sendDisplayStatus(CHK.DISPLAY_STATUS.showingForm, taskKey);
			}
			//絞り検索追加: 初期化
			element.contentWindow.initSavedApertureSelectBox();
		} else {
			var param = {name: name, taskKey: taskKey, seqId: CHK.getNextSeqId(), mode: "0", attachedChangeFlag: "0"};
			if (CHK.reportType == CHK.REPORT_TYPE.WITHREPLY && CHK.taskReplyNo != CHK.BASE_TASK_REPLY_NO) {
				var baseReport = CHK.getRecentVersionReport(taskKey);
				param.pointNo = CHK.getPointNo(baseReport);
				param.taskName = CHK.getTaskName(baseReport);
				param.taskProgress = CHK.getTaskProgress(name, taskKey);
				element.contentWindow.createTaskButton(name, taskKey);
			}
			element.contentWindow.setCheckInitData(taskReport, CHK.taskReportQuestion, CHK.content, CHK.taskReportSuggest, param);
			CHK.sendDisplayStatus(CHK.DISPLAY_STATUS.showingForm, taskKey);
			//絞り検索追加: 初期化
			element.contentWindow.initApertureSelectBox();
		}
		//端末別に上段バーの選択
		if (CHK.isMobile || CHK.operationType != CHK.OPERATION_TYPE.LIST) {
			element.contentWindow.createDoubleHeader(isPreview);
		} else if (CHK.reportType == CHK.REPORT_TYPE.WORKFLOW) {
			//連続作業ならタブ表示
			element.contentWindow.initTab(false);
		}
		element.contentWindow.changeFontSize(CHK.setBigFontFlg);
	}
}

/**
 * iOS不具合対策
 * 報告フォームを一瞬再描画する
 * アプリとの連携で問題があったため、hide->showからheightの変更に修正
 *
 */
CHK.delayReportFormInit = function(closeLoading) {
	$("#checkInput").css("opacity", "0");
	$("#checkInput").height(0);
	$("#checkInput [id^='reportForm']").height(0);
	setTimeout(function() {
		var checkInputHeight = CHK.isWeb ? "calc(100% - 36px)" : "100%";
		$("#checkInput").height(checkInputHeight);
		// フォーム表示非表示設定
		if (closeLoading) {
			$("#checkInput [id^='reportForm']").each(function() {
				// 現在表示対象フォーム以外の高さを0に設定(リダイレクトの場合は常に100%)
				var reportFormDoc = this.contentWindow.document;
				if (this.id == "reportForm" + CHK.taskReplyNo || this.id == "reportForm") {
					$("body", reportFormDoc).show(); // IPAD対応
					$(this).height("100%");
					$("#checkInput").css("opacity", "1");
					$(".content", reportFormDoc).css("overflow", "hidden");
					$(".content", reportFormDoc).css("-webkit-overflow-scrolling", "none");
					setTimeout(function() {
						$(".content", reportFormDoc).css("overflow", "auto");
						$(".content", reportFormDoc).css("-webkit-overflow-scrolling", "touch");
						$("#whiteFrame").hide();
						CHK.closeLoading();
					}, 500);
				} else {
					$("body", reportFormDoc).hide(); // IPAD対応
				}
			});
		}
	}, 500);
}

/**
 * ホットスポットクリック時フォームを表示
 * TODO
 *
 * @param name ホットスポット名
 * @param taskKey taskKey
 * @param lookto true:視点移動する
 */
CHK.showReportForm = function(name, taskKey, lookto, replyNo, message) {
	CHK.showLoading(getMsg("Processing_w_dot"));
	// TODO 画面切り替え中に作業一覧を隠す
	if ($("#checkInput iframe[id^='reportForm']").length) {
		CHK.showWhiteFrame();
	}
	if (CHK.operationType == CHK.OPERATION_TYPE.PDF && !name) name = CHK.generateUuid(); // PDFタイプのみname値がない場合新規作成とする
	console.log({name: name});
	if (!taskKey) taskKey = CHK.getTaskKeyByName(name);
	if (!replyNo) replyNo = CHK.BASE_TASK_REPLY_NO; // replyNoの値が空の場合0を設定
	// グローバル変数として回答番号を設定
	CHK.taskReplyNo = replyNo;
	var element;
	// リダイレクトフラグがtrueの場合はiframeを1つ、以外の場合はiframeを2つ作って管理する
	if (CHK.isRedirectForm(taskKey)) {
		element = document.getElementById("reportForm");
		console.log(element);
		if (!element) {
			element = document.createElement("iframe");
			element.id = "reportForm";
			element.setAttribute("src", CHK.reportBasePath + "taskReport_" + replyNo + "/index.html?wmode=transparent");
			CHK.showTaskReportForm(name, taskKey, lookto, element);
		} else {
			CHK.showDialog(message, function() {
				$("#checkInput").hide();
				$("#checkInput").empty();
				CHK.changeReport(taskKey);
			}, function() {
				$("#whiteFrame").hide();
				CHK.closeLoading();
			});
		}
	} else {
		element = document.getElementById("reportForm" + replyNo);
		if (!element) {
			element = document.createElement("iframe");
			element.id = "reportForm" + replyNo;
			element.setAttribute("src", CHK.reportBasePath + "taskReport_" + replyNo + "/index.html?wmode=transparent");
			CHK.showTaskReportForm(name, taskKey, lookto, element);
			CHK.delayReportFormInit();
		} else {
			CHK.delayReportFormInit(true);
			element.contentWindow.changeFontSize(CHK.setBigFontFlg);
		}
	}
	CHK.closeLoading();
}

/**
 * 報告フォームを表示
 *
 * @param element 表示するHTML
 */
CHK.showCheckInput = function(element, taskKey) {
	// 新規・リダイレクト・初期表示の場合checkInputエレメントを空に設定する
	if (!taskKey || CHK.isRedirectForm(taskKey) || $("#unsupport_browser").length) {
		$("#checkInput").empty();
	}
	// checkInputに対象フォームが存在しない場合対象フォームを挿入する
	if (!$("#checkInput").has(element).length) {
		$("#checkInput").append(element);
	}

	// 表示処理を隠す
	CHK.showWhiteFrame();
	$("#checkInput").show();
	if (CHK.operationType == CHK.OPERATION_TYPE.VTOUR) {
		krpano.call("set(layer[skin_control_bar].visible,false);");
		krpano.call("skin_close_settings();");
		krpano.call("skin_hideskin();");
	}
}

/**
 * 作業報告フォームを非表示
 *
 */
CHK.hideReportForm = function() {
	// 作業追加区分なしの場合、画面を閉じる
	if (CHK.isWeb && addReportFlg == CHK.ADD_REPORT_FLG.UNABLE) {
		CHK.close();
	} else {
		$("#checkInput").hide();
		$("#checkInput").empty();
		if (CHK.useKrpano) {
			krpano.call("clear_blink()");
			krpano.call("clear_selected()");
			if (CHK.operationType == CHK.OPERATION_TYPE.VTOUR) {
				krpano.call("set(layer[skin_control_bar].visible,true);");
				krpano.call("skin_showskin();");
			}
		} else if (CHK.operationType == CHK.OPERATION_TYPE.PDF && CHK.isWeb) {
			CHK_P.showToolbar();
			CHK_P.selectedHsTaskKey = null;
			$("#checkList").css("visibility", "visible");
			$(".hotspot").removeClass("blinking");
		}
		// 表示状態変更通知
		CHK.sendDisplayStatus($("#checkList").is(':visible') ? CHK.DISPLAY_STATUS.showingList : CHK.DISPLAY_STATUS.init);
		// 回答番号を0に設定する
		CHK.taskReplyNo = CHK.BASE_TASK_REPLY_NO;
	}
	$("#whiteFrame").remove();
}


/**
 * 作業報告登録フォームの入力を保存
 *
 * @param param 入力パラメータ
 */
CHK.saveReportForm = function(param) {
	console.log(param);
	var inspect = CHK.reportType == CHK.REPORT_TYPE.INSPECT;
	var isInsert = false;

	var taskReport;
	// 定期点検対応
	if (inspect) {
		var routineTaskReport = CHK_I.getTaskReport(param.reportStartDate);
		if (routineTaskReport && routineTaskReport.task) {
			taskReport = routineTaskReport;
		}
	} else {
		taskReport = CHK.getTaskReport(null, param.taskKey);
	}
	// 更新・登録確認
	if (taskReport && taskReport.task) {
		taskReport.task = param.task;
		taskReport.taskReply = param.taskReply;
		taskReport.attached = param.attached;
		taskReport.suggest = param.suggest;
	} else {
		isInsert = true;
		param.mode = "0";
		var reportKey = "taskReport_" + CHK.taskReplyNo;
		taskReport = {};
		taskReport.taskKey = param.taskKey;
		taskReport.task = param.task;
		taskReport.taskReply = param.taskReply;
		taskReport.attached = param.attached;
		taskReport.suggest = param.suggest;
		if (CHK.reportType == CHK.REPORT_TYPE.WORKFLOW) {
			taskReport.processKey = CHK_PR.selectedProcessKey;
		}
		if (!CHK.taskReport[reportKey]) CHK.taskReport[reportKey] = [];
		if (CHK.debug == "1") CHK.taskReport[reportKey].push(taskReport); //DEBUG
	}
	// 報告(回答)の場合、バージョンを追加
	if (CHK.reportType == CHK.REPORT_TYPE.WITHREPLY) {
		var recentVersionNum = CHK.getRecentVersionNum(param.taskKey);
		console.log("recentVersionNum: " + recentVersionNum);
		taskReport.task.version = recentVersionNum + 1;
	}

	var callbackABookCheckApi = null;
	if (CHK.isWeb) {
		callbackABookCheckApi = function(json) {
			CHK.closeLoading();
			if (inspect) {
				CHK_I.updateInspectReportJsonWeb(json);
			} else {
				CHK.updateReportJsonWeb(json);
			}
			CHK.afterUpdateReport(param.taskKey);
		};
	}

	//アプリ・CMSに送信
	var apiParam = {};
	if (CHK.taskReplyNo == CHK.BASE_TASK_REPLY_NO) {
		var hotspot = CHK.getSaveHotspotParam(param);
		apiParam.hotspot = CHK.encodeParam(JSON.stringify(hotspot));
		apiParam.delFlag = 0;
	}
	apiParam.cmd = param.isLocalSave ? CHK.getCommand("localSave") : isInsert ? CHK.getCommand("insertReport") : CHK.getCommand("updateReport");
	apiParam.taskKey = param.taskKey;
	apiParam.taskReport = CHK.encodeParam(JSON.stringify(taskReport));
	apiParam.attachedChangeFlag = param.attachedChangeFlag;
	apiParam.taskReportLevel = CHK.taskReplyNo;
	apiParam.addReport = addReportFlg;
	// 定期点検対応
	if (inspect) {
		apiParam.taskReportId = param.taskReportId;
		apiParam.reportStartDate = CHK_I.getInspectIsoDate(new Date(param.reportStartDate));
		if (CHK.isWeb) {
			apiParam.reportStartDate = apiParam.reportStartDate.replace("T", " ");
			if (!apiParam.taskReportInfo) {
				apiParam.taskReportInfo = {};
			}
			apiParam.taskReportInfo.task = taskReport.task;
			apiParam.taskReportInfo.attached = taskReport.attached;
			apiParam.taskReportInfo = JSON.stringify(apiParam.taskReportInfo);
			if (!isInsert && param.taskReportInfoId) {
				apiParam.taskReportInfoId = param.taskReportInfoId;
			}
		}
	}
	// 連続作業対応
	if (CHK.reportType == CHK.REPORT_TYPE.WORKFLOW) {
		apiParam.phaseNo = CHK_PR.selectedPhaseInfo.phaseNo;
		apiParam.processKey = CHK_PR.selectedProcessKey;
		//連続作業の場合は保存後閉じさせない
		apiParam.addReport = CHK.ADD_REPORT_FLG.ABLE;
	}
	CHK.sendABookCheckApi(apiParam, callbackABookCheckApi);

	//DEBUG
	if (CHK.debug == "1") {
		CHK.closeLoading();
		CHK.afterUpdateReport(param.taskKey);
	}
}

/**
 * アプリにデータを送信
 *
 * @param param パラメータ
 */
CHK.sendABookCheckApi = function(param, callback) {
	if (CHK.isWeb) {
		var url = CHK.getActionUrl(param.cmd);
		CHK.cmsAjax(url, param, callback);
	} else if (CHK.isWindows) {
		// windowsアプリの場合の対応
		window.external.notify(JSON.stringify(param));
1241 1242
	} else if(CHK.isAndroid){
	    android.sendParam(JSON.stringify(param));
1243 1244
	} else if(CHK.isIOS){
		webkit.messageHandlers.sendParam.postMessage(JSON.stringify(param));
Yujin Seo committed
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 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 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628
	} else {
		var query = "";
		for (var key in param) {
			if (!query) {
				query = "?" + key + "=" + param[key];
			} else {
				query = query + "&" + key + "=" + param[key];
			}
		}

		var uri = "abookcheck-api://" + query;
		console.log({uri: uri});
		if (CHK.debug != "1") {
			var link = document.createElement('a');
			link.href = uri;
			link.click();
		}
	}
}

/**
 * アプリに添付ファイル情報を送信
 *
 * @param taskKey taskKey
 * @param attachedKey 添付ファイルのkey値
 * @param fileName ファイル名
 * @param dataUrl 添付ファイルBase64文字列
 */
CHK.sendAttachedFileName = function(taskKey, attachedKey, fileName, dataUrl, editable) {
	var param = {};
	param.cmd = CHK.getCommand("saveAttached");
	param.taskKey = taskKey;
	param.attachedKey = attachedKey;
	param.filename = fileName;
	param.editable = editable;
	CHK.saveAttachedDataUrl = dataUrl;
	CHK.sendABookCheckApi(param);
	if (CHK.debug == "1") {
		CHK.closeLoading();
	}
}

/**
 * アプリに編集したい添付ファイル情報を送信
 *
 * @param taskKey taskKey
 * @param fileName ファイル名
 * @param filePath ファイルパス
 */
CHK.editAttachedFile = function(taskKey, fileName, filePath) {
	var param = {};
	param.cmd = CHK.getCommand("editAttached");
	param.taskKey = taskKey;
	param.filename = fileName;
	param.filePath = filePath;
	CHK.sendABookCheckApi(param);
	if (CHK.debug == "1") {
		CHK.closeLoading();
	}
}

/**
 * 添付ファイルのBase64文字列を返却
 *
 */
CHK.getAttachedDataUrl = function() {
	var ret = CHK.saveAttachedDataUrl;
	CHK.saveAttachedDataUrl = "";
	return ret;
}

/**
 * アプリデータ送信結果コールバック
 *
 * @param cmd コマンド文字列
 * @param taskKey taskKey
 * @param result 処理結果(0:成功)
 * @param message エラーメッセージ
 * @param extParam 拡張パラメータ JSON形式
 */
CHK.afterABookCheckApi = function(cmd, taskKey, result, message, extParam) {
	console.log("afterABookCheckApi", cmd, taskKey, result, message, extParam);
	// 結果が成功じゃない場合
	if (result != "0") {
		if (cmd == CHK.apiCmd.getGpsInfo) {
			//手動取得時はエラーダイアログを表示
			var targetContentwindow;
			if ($("#checkInput").find("iframe#reportForm0").length) {
				targetContentwindow = $("#checkInput").find("iframe#reportForm" + CHK.taskReplyNo)[0].contentWindow;
			} else {
				targetContentwindow = $("#checkInput").find("iframe")[0].contentWindow;
			}
			if (targetContentwindow && targetContentwindow.isGpsManual()) {
				CHK.showDialog(getMsg("errorOccurred") + "<br>" + message, null, null, true);
			}
			$("#checkInput").find("iframe")[0].contentWindow.getGpsInfoAfter();
		} else if (addReportFlg == CHK.ADD_REPORT_FLG.UNABLE && (cmd == CHK.apiCmd.insertReport || cmd == CHK.apiCmd.updateReport)) {
			CHK.closeLoading();
		} else {
			CHK.showDialog(getMsg("errorOccurred") + "<br>" + message, null, null, true);
			if (cmd == CHK.apiCmd.saveAttached) {
				$("#checkInput").children()[0].contentWindow.deleteFile(extParam.key);
				CHK.closeLoading();
			} else if(cmd == CHK.apiCmd.editAttached) {
				$("#checkInput").children()[0].contentWindow.deleteFile(extParam.key);
				CHK.closeLoading();
			}
		}
		return;
	}
	//JSON再ロード
	switch (cmd) {
		case CHK.apiCmd.saveAttached: {
			CHK.closeLoading();
			break;
		}
		case CHK.apiCmd.editAttached: {
			CHK.closeLoading();
			break;
		}
		case CHK.apiCmd.insertReport:
		case CHK.apiCmd.updateReport: {
			CHK.closeLoading();
			//作業報告情報をロード
			CHK.loadJson(CHK.jsonPath.taskReport, function(taskReport) {
				CHK.taskReport = taskReport;
				//ホットスポット情報をロード
				CHK.loadJson(CHK.jsonPath.taskHotspot, function(jsonData) {
					CHK.taskHotspot = jsonData;
					CHK.afterUpdateReport(taskKey);
				});
			});
			//作業報告入力補完情報をロード
			CHK.reloadJson(CHK.jsonPath.taskReportSuggest);
			break;
		}
		case CHK.apiCmd.cancelReport: {
			CHK.afterCancelTask();
			break;
		}
		case CHK.apiCmd.deleteReport: {
			CHK.closeLoading();
			//作業報告情報をロード
			CHK.loadJson(CHK.jsonPath.taskReport, function(taskReport) {
				CHK.taskReport = taskReport;
				CHK.afterDeleteReport(taskKey);
			});
			break;
		}
		case CHK.apiCmd.moveHotspot: {
			//ホットスポット情報をロード
			CHK.loadJson(CHK.jsonPath.taskHotspot, function(jsonData) {
				CHK.taskHotspot = jsonData;
				var taskHotspot = CHK.getTaskHotspot(null, taskKey);
				var object = krpano.get("layer[" + taskHotspot.name + "]");
				//ウィンドウサイズ変更時の対応
				if (object) object.origin_x = taskHotspot.x;
				if (object) object.origin_y = taskHotspot.y;
			});
			break;
		}
		case CHK.apiCmd.getGpsInfo: {
			//GPS情報取得
			var gps = {};
			gps.latitude = extParam.latitude;
			gps.longitude = extParam.longitude;
			if ($("#checkInput").find("iframe#reportForm0").length) {
				$("#checkInput").find("iframe#reportForm" + CHK.taskReplyNo)[0].contentWindow.getGpsInfoAfter(gps);
			} else {
				$("#checkInput").find("iframe")[0].contentWindow.getGpsInfoAfter(gps);
			}
			break;
		}
		case CHK.apiCmd.localSave: {
			CHK.closeLoading();
			//作業報告情報をロード
			CHK.loadJson(CHK.jsonPath.taskReport, function(taskReport) {
				CHK.taskReport = taskReport;
				//ホットスポット情報をロード
				CHK.loadJson(CHK.jsonPath.taskHotspot, function(jsonData) {
					CHK.taskHotspot = jsonData;
					CHK.afterUpdateReport(taskKey, true);
				});
			});
			//作業報告入力補完情報をロード
			CHK.reloadJson(CHK.jsonPath.taskReportSuggest);
			break;
		}
		case CHK.apiCmd.changeReport: {
			// 添付ファイルの削除後レポート表示
			CHK.showReportForm(null, taskKey, null, CHK.taskReplyNo);
			break;
		}
		case CHK.apiCmd.getGroupTreeInfo: {
			// ログインユーザーの所属グループを保存
			CHK.groupTreeInfo = extParam;
		}
	}
}

/**
 * 作業報告更新後の処理
 *
 * @param taskKey taskKey
 */
CHK.afterUpdateReport = function(taskKey, isLocalSave) {
	// テキストを更新
	if (CHK.operationType == CHK.OPERATION_TYPE.PDF) {
		CHK.updateHotspotText(taskKey);
	} else if (CHK.operationType == CHK.OPERATION_TYPE.VTOUR) {
		var taskHotspot = CHK.getTaskHotspot(null, taskKey);
		var taskReport = CHK.getRecentVersionReport(taskKey);
		var pointNo = CHK.getPointNo(taskReport);
		CHK.changeTextColor(taskHotspot.name, pointNo);

	}
	// リスト更新、入力フォームをクローズ
	CHK.updateTaskList();
	if (!isLocalSave) CHK.hideReportForm();
	// 新規作成時削除対象になってあるため、クリア
	CHK.deleteName = null;
}

/**
 * 作業報告キャンセル後の処理
 *
 * @param taskKey taskKey
 */
CHK.afterCancelTask = function() {
	if (CHK.deleteName) {
		//ホットスポットを削除
		CHK.deleteHotspot(CHK.deleteName);
		CHK.deleteName = null;
	}
	CHK.hideReportForm();
}

/**
 * 作業報告削除後の処理
 *
 * @param taskKey taskKey
 */
CHK.afterDeleteReport = function(taskKey, json) {
	// 指示報告か回答報告かを確認
	if (CHK.taskReplyNo == CHK.BASE_TASK_REPLY_NO) {
		//ホットスポットを削除
		var targetHsName = taskKey;
		if (CHK.operationType != CHK.OPERATION_TYPE.PDF) {
			targetHsName = "hs" + CHK.getSceneId() + "-" + taskKey;
		}
		CHK.deleteHotspot(targetHsName);
		CHK.hideReportForm();
		if (CHK.isWeb) {
			//ホットスポット情報をロード
			CHK.updateReportJsonWeb(json);
			//ホットスポット一覧更新
			CHK.updateTaskList();
		} else {
			//ホットスポット情報をロード
			CHK.loadJson(CHK.jsonPath.taskHotspot, function(jsonData) {
				CHK.taskHotspot = jsonData;
				//ホットスポット一覧更新
				CHK.updateTaskList();
			});
		}
	} else {
		// テキストの色変更
		if (CHK.operationType != CHK.OPERATION_TYPE.PDF) {
			var taskHotspot = CHK.getTaskHotspot(null, taskKey);
			var taskReport = CHK.getRecentVersionReport(taskKey);
			var pointNo = CHK.getPointNo(taskReport);
			CHK.changeTextColor(taskHotspot.name, pointNo);
		}
		// リスト更新、入力フォームをクローズ
		CHK.updateTaskList();
		CHK.hideReportForm();
	}
}

/**
 * ホットスポットのテキストを更新
 *
 * @param taskKey taskKey
 */
CHK.updateHotspotText = function(taskKey) {
	var taskHotspot = CHK.getTaskHotspot(null, taskKey);
	var taskReport = CHK.getRecentVersionReport(taskKey);
	var pointNo = CHK.getPointNo(taskReport);

	if (CHK.operationType != CHK.OPERATION_TYPE.DRAWING && taskHotspot.sceneId != "0") {
		var layer = krpano.get("layer[" + taskHotspot.name + "_inner]");
		if (layer) layer.html = "[font size='4' color='#ffffff' style='border-style:solid;border-width:1px;border-color:#ffffff;padding:5px 15px;background-color:#ff7700;'][b]" + pointNo + "[/b][/font]";
	} else {
		var layer = krpano.get("layer[" + taskHotspot.name + "]");
		if (CHK.operationType == CHK.OPERATION_TYPE.DRAWING) {
			layer.html = "[font color='#ffffff' style='border-style:solid;border-width:1px;border-color:#ffffff;padding:5px 15px;background-color:#ff7700;'][b]" + pointNo + "[/b][/font]";
		} else {
			layer.html = "[font color='#ffffff' style='border-style:solid;border-width:1px;border-color:#ffffff;padding:5px 15px;background-color:#ff7700;'][b]" + pointNo + "[/b][/font]";
		}
	}
}

/**
 * ホットスポットのテキストカラーを変更
 *
 * @param name ホットスポット名
 * @param pointNo 指摘No
 */
CHK.changeTextColor = function(name, pointNo) {
	var isHotspot = true;
	var layer = krpano.get("layer[" + name + "_inner]");
	if (!layer) {
		isHotspot = false;
		layer = krpano.get("layer[" + name + "]");
		if (!layer) return;
	}
	layer.html = CHK.getHotspotHtml(name, isHotspot, pointNo);
}

/**
 * 作業報告を削除
 *
 * @param taskKey taskKey
 */
CHK.deleteReport = function(taskKey) {
	//アプリに作業報告の削除情報を送信
	var apiParam = {};
	apiParam.cmd = CHK.getCommand("deleteReport");
	apiParam.taskKey = taskKey;
	apiParam.delFlag = 1;
	apiParam.taskReportLevel = CHK.taskReplyNo;
	apiParam.addReport = addReportFlg;
	var callbackABookCheckApi = null;
	if(CHK.isWeb) {
		callbackABookCheckApi = function(json) {
			CHK.closeLoading();
			//作業報告情報をロード
			CHK.updateReportJsonWeb(json);
			CHK.afterDeleteReport(taskKey, json);
		};
	}

	CHK.sendABookCheckApi(apiParam, callbackABookCheckApi);

	//DEBUG
	if (CHK.debug == "1") {
		var taskReport = CHK.getTaskReport(null, taskKey);
		CHK.closeLoading();
		var index = 0;
		taskReport.some(function(report, i) {
			if (report.taskKey == taskKey) {
				index = i;
				return true;
			}
		});
		taskReport.splice(index, 1);
		CHK.afterDeleteReport(taskKey);
	}
}

/**
 * ホットスポットを削除
 *
 * @param name ホットスポット名
 */
CHK.deleteHotspot = function(name) {
	var isHotspot = krpano.get("hotspot[" + name + "]") != null;
	if (isHotspot) {
		krpano.call("removehotspot(" + name + ")");
		krpano.call("removelayer(" + name + "_inner)");
	} else {
		krpano.call("removelayer(" + name + ")");
	}
}

/**
 * 作業報告キャンセル処理
 *
 */
CHK.cancelTask = function(taskKey) {
	var apiParam = {};
	apiParam.cmd = CHK.getCommand("cancelReport");
	apiParam.taskKey = taskKey;
	apiParam.taskReportLevel = CHK.taskReplyNo;
1629

Yujin Seo committed
1630 1631 1632 1633 1634 1635
	//連続作業の場合追加無しでも工程一覧に戻したい
	if (window.parent.CHK.reportType == window.parent.CHK.REPORT_TYPE.WORKFLOW) {
		apiParam.addReport = CHK.ADD_REPORT_FLG.ABLE;
	} else {
		apiParam.addReport = addReportFlg;
	}
1636

Yujin Seo committed
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178
	CHK.sendABookCheckApi(apiParam);
	if (CHK.debug == "1" || CHK.isWeb) {
		CHK.afterCancelTask();
	}
}

/**
 * 作業報告変更処理
 *
 */
CHK.changeReport = function(taskKey) {
	var apiParam = {};
	apiParam.cmd = CHK.getCommand("changeReport");
	apiParam.taskKey = taskKey;
	CHK.sendABookCheckApi(apiParam);
}

/**
 * 指摘No一覧の表示を切り替える
 *
 */
CHK.showTaskList = function() {
	// フォームが表示されてる場合は何もしない
	if (CHK.isShowingForm()) {
		return;
	}
	if ($("#checkListValues").css('display') != "none") {
		$("#checkListValues").hide();
		$("#checkListValues #checkListCount").hide();
		$("#checkListValues").height("0px");
		$("#checkList").height("0px");
		$("#checkList").hide();
		// 表示状態変更通知
		CHK.sendDisplayStatus(CHK.DISPLAY_STATUS.init);
	} else {
		$("#checkListValues").show();
		$("#checkListValues #checkListCount").show();
		if ($("#topnav").length > 0) {
			$("#checkList").css("top", "36px");
		}
		$("#checkListValues").height("100%");
		$("#checkList").height("100%");
		$("#checkList").show();
		// 表示状態変更通知
		CHK.sendDisplayStatus(CHK.DISPLAY_STATUS.showingList);
	}
}


/**
 * フォントサイズ調整
 *
 */
CHK.changeFontSize = function(flg) {
    if (flg) {
	    $(".fontBtn.small").removeClass("selected");
	    $(".fontBtn.big").addClass("selected");
	    $("#checkList").addClass("big");

    } else {
        $(".fontBtn.small").addClass("selected");
        $(".fontBtn.big").removeClass("selected");
        $("#checkList").removeClass("big");

    }
    CHK.setBigFontFlg = flg;
}




/**
 * 指摘No一覧を更新
 *
 * @param searchWord 検索文
 */
CHK.updateTaskList = function(searchWord) {
	$("#checkListValues").empty();
	$("#fontBtnDiv").clone().appendTo($("#checkListValues"));
	$("#checkListValues #fontBtnDiv").css("display", "flex");
	$("#closeBtn").clone().appendTo($("#checkListValues"));
	$("#checkListValues #closeBtn").show();
	var ckeckList = [];
	CHK.taskHotspot.hotspot.forEach(function(hotspot) {
		var taskReport = CHK.getRecentVersionReport(hotspot.name, hotspot.taskKey);
		ckeckList.push({
			sceneId: hotspot.sceneId,
			name: hotspot.name? hotspot.name : hotspot.taskKey,
			pointno: CHK.getPointNo(taskReport),
			hotspot: hotspot.sceneId != "0"
		});
	});
	ckeckList.sort(function(a, b) {
		if (a.sceneId != "0" && b.sceneId == "0") return -1;
		if (a.sceneId == "0" && b.sceneId != "0") return 1;
		if (a.sceneId < b.sceneId) return -1;
		if (a.sceneId > b.sceneId) return 1;
		if (a.pointno < b.pointno) return -1;
		if (a.pointno > b.pointno) return 1;
		return 0;
	});
	var count = 0;
	var sceneId = "";
	if (!searchWord) searchWord = "";
	$("#searchWord").val(searchWord);
	$("#checkListSearch").clone().appendTo($("#checkListValues"));
	$("#checkListSearch").css("display", "flex");
	$("#checkListCount").clone().appendTo($("#checkListValues"));
	$("#checkListCount").show();
	$("#checkListValues").append("<div id='values'></div>");

	var sceneCnt = CHK.operationType == CHK.OPERATION_TYPE.PDF? CHK.pdf_numPages : krpano.get("scene").count;
	if (CHK.operationType != CHK.OPERATION_TYPE.PDF && krpano.get("layer[map].url")) {
		sceneCnt += 1;
	}
	// シーンから追加
	if (CHK.operationType == CHK.OPERATION_TYPE.VTOUR) {
		for (var i = 0; i < sceneCnt; i++) {
			var scene = krpano.get("scene[" + i + "]");
			if (!scene) {
				sceneId = "0";
			} else {
				sceneId = scene.name.substring(5);
			}

			var checkListSceneDiv = $("<div/>", {class:"checkListSceneDiv"});
			checkListSceneDiv.append($("<div/>", {class:"checkListScene", onclick:"CHK.clickTaskList(" + sceneId + ")"}).append($("<div/>").text(CHK.getSceneName(sceneId))));
			checkListSceneDiv.append($("<div/>", {id:sceneId+"_accordionBtn", class:"accordionBtn"}).append($("<p/>").text("▽")));
			$("#values").append(checkListSceneDiv);
			$("#values").append($("<div/>", {id: sceneId + "_values", class:"sceneValues"}));

			// 表示中のシーンの作業リストはオープンするため、ボタンのスタイルを設定
			if (searchWord || krpano.get("xml.scene") == "scene" + sceneId) {
				$("#" + sceneId + "_accordionBtn >p").css({transform: "rotate(180deg)", zIndex: "1"});
			}

			// 作業がないシーンの表示
			$("#nullValue").clone().appendTo($("#" + sceneId + "_values"));
			$("#nullValue").show();
		}
	} else if (CHK.operationType == CHK.OPERATION_TYPE.DRAWING) {
		$("#values").css("margin-top", "20px");
		$("#nullValue").clone().appendTo($("#values"));
		$("#nullValue").show();
	} else if (CHK.operationType == CHK.OPERATION_TYPE.PDF) {
		for (var i = 1; i <= sceneCnt; i++) {
			sceneId = i;

			var checkListSceneDiv = $("<div/>", {class:"checkListSceneDiv"});
			checkListSceneDiv.append($("<div/>", {class:"checkListScene", onclick:"CHK.clickTaskList(" + sceneId + ")"}).append($("<div/>").text(sceneId + getMsg("page"))));
			checkListSceneDiv.append($("<div/>", {id:sceneId+"_accordionBtn", class:"accordionBtn"}).append($("<p/>").text("▽")));
			$("#values").append(checkListSceneDiv);
			$("#values").append($("<div/>", {id: sceneId + "_values", class:"sceneValues"}));

			// 表示中のシーンの作業リストはオープンするため、ボタンのスタイルを設定
			if (searchWord || CHK.pdf_pageNum == sceneId) {
				$("#" + sceneId + "_accordionBtn >p").css({transform: "rotate(180deg)", zIndex: "1"});
			}

			// 作業がないシーンの表示
			$("#nullValue").clone().appendTo($("#" + sceneId + "_values"));
			$("#nullValue").show();
		}
	}

	// 検索文の英文字と数字を半角、小文字に設定
	var convertedSearchWord = CHK.kataToHira(CHK.fullwidthTohalfwidth(searchWord)).toLowerCase();

	// 作業をシーンごとに配置・表示
	for (var i = 0; i < ckeckList.length; i++) {
		var ckeck = ckeckList[i];
		var taskReport = CHK.getRecentVersionReport(ckeck.name, ckeck.taskKey);
		var taskName = CHK.getTaskName(taskReport);
		sceneId = ckeck.sceneId;
		if (CHK.hasSearchWord(taskName, convertedSearchWord)) {
			var color = CHK.getTextColor(ckeck.name);
			var targetList = CHK.operationType == CHK.OPERATION_TYPE.DRAWING ? $("#values"): $("#" + sceneId + "_values");
			var onclickAction = CHK.operationType == CHK.OPERATION_TYPE.PDF ? "CHK.clickTaskList('" + sceneId + "', '" + ckeck.name + "')" : "CHK.clickTaskList('" + sceneId + "', '" + ckeck.name + "', " + ckeck.hotspot + ")";
			var checkListValue = $("<div/>", {class:'checkListValue', style:"color:" + color, onclick: onclickAction});
			checkListValue.append($("<div/>").append($("<span/>").text(ckeck.pointno)).append($("<div/>").text(taskName)));
			targetList.append(checkListValue);
			// 表示中のシーン以外の作業はクローズ
			var isOtherScene = CHK.operationType == CHK.OPERATION_TYPE.PDF ? CHK.pdf_pageNum != sceneId : krpano.get("xml.scene") != "scene" + sceneId;
			if (!searchWord && isOtherScene) {
				$("#" + sceneId + "_values").hide();
			}
			// 作業があるシーンの表示
			if ($("#" + sceneId + "_values #nullValue")) { // 360
				$("#" + sceneId + "_values #nullValue").remove();
				$("#" + sceneId + "_accordionBtn").css({ 'color': '#0068CB', 'background-color': '#fff', 'border': '1px solid #0068CB', 'cursor': 'pointer' });
			}
			if ($("#values > #nullValue")) { // 図面
				$("#values > #nullValue").remove();
			}
			// 合計作業数(検索結果)
			count++;
		}
	}
	$("#checkListNum").text(count);
	// 作業一覧が表示されてる状態でシーン移動すると、該当シーンの作業一覧にスクロール移動する
	if (!searchWord && CHK.operationType != CHK.OPERATION_TYPE.DRAWING) {
		var idx = CHK.operationType == CHK.OPERATION_TYPE.PDF? CHK.pdf_pageNum-1 : krpano.get("scene[get(xml.scene)].index");
		$("#values").scrollTop($($(".checkListSceneDiv")[idx]).position().top+$("#values").scrollTop()-$("#values").position().top);
	}
	// アコーディオンボタンクリックイベント
	$(".accordionBtn").on("click", function() {
		var panel = $(this).parent().next();
		if ($(panel.children()[0]).attr("id") == "nullValue") return;
		var btnImg = $($(this).children()[0]);
		if (panel.is(':visible') && $("#" + $(panel[0]).prop("id") + " .checkListValue").length > 0) {
			btnImg.animate({zIndex:0}, {duration:500, step:function(now){ btnImg.css({transform:'rotate(' + now * 180 + 'deg)'}); }, complete:function(){ }}); // アコーディオンボタンのイメージアニメーション
			panel.animate({zIndex:1}, {duration:500, step:function(now){ panel.css("max-height", 100-(now*100) + "%"); }, complete:function(){ panel.hide(); panel.css("max-height", ""); }}); // パネルを閉めるアニメーション
		} else {
			panel.show();
			btnImg.animate({zIndex:1}, {duration:500, step:function(now){ btnImg.css({transform:'rotate(' + now * 180 + 'deg)'}); }, complete:function(){ }}); // アコーディオンボタンのイメージアニメーション
			panel.animate({zIndex:1}, {duration:500, step:function(now){ panel.css("max-height", now*100 + "%"); }, complete:function(){ panel.css("max-height", ""); }}); // パネルを開くアニメーション
			$(this).parent().parent().animate({scrollTop: $(this).parent().position().top+$("#values").scrollTop()-$("#values").position().top }, 600, "swing"); // 作業一覧のスクロール移動アニメーション
		}
	});

	if (CHK.operationType == CHK.OPERATION_TYPE.PDF) {
		$("#checkList .checkListSceneDiv").css({"color": "#FFF"});
	}
}

/**
 * 文章のカタカナをひらがなに変換
 *
 * @param str 変換対象文章
 */
CHK.kataToHira = function(str) {
	if (str) {
		return str.replace(/[\u30a1-\u30f6]/g, function(match) {
			var chr = match.charCodeAt(0) - 0x60;
			return String.fromCharCode(chr);
		});
	}
	return "";
}

/**
 * 文章の全角を半角に変換(英文字と数字のみ)
 *
 * @param str 変換対象文章
 */
CHK.fullwidthTohalfwidth = function(str) {
	if (str) {
		return str.replace(/[A-Za-z0-9]/g, function(match) {
			var chr = match.charCodeAt(0) - 0xFEE0;
			return String.fromCharCode(chr);
		});
	}
	return "";
}

/**
 * targetStrを変換し、convertedSearchStrと比較する
 * targetStrがconvertedSearchStrの文字を含んだ場合はtrueを返す
 *
 * @param targetStr 検索対象文
 * @param convertedSearchStr 検索文
 */
CHK.hasSearchWord = function(targetStr, convertedSearchStr) {
	return CHK.kataToHira(CHK.fullwidthTohalfwidth(targetStr)).toLowerCase().indexOf(convertedSearchStr) != -1;
}

/**
 * 作業検索処理
 *
 */
CHK.searchTask = function() {
	CHK.updateTaskList($("#searchWord").val() ? $("#searchWord").val() : "");
}

/**
 * シーン名を取得
 *
 * @param sceneId シーンID
 */
CHK.getSceneName = function(sceneId) {
	var ret = "";
	if (sceneId == "0") {
		ret = getMsg("radarmap");
	} else {
		var sceneArray = krpano.get("scene").getArray();
		sceneArray.some(function(scene) {
			if (scene.name.substring(5) == sceneId) {
				ret = scene.title;
				return true;
			}
		});
	}
	return ret;
}

/**
 * 指摘No一覧のクリック処理
 *
 * @param name ホットスポット名
 * @param isHotspot true:ホットスポット false:レイヤー
 */
CHK.clickTaskList = function(sceneId, name, isHotspot) {
	if (CHK.operationType != CHK.OPERATION_TYPE.DRAWING && sceneId != "0" && CHK.getSceneId() != sceneId) {
		krpano.call("loadSceneAction(" + "scene" + sceneId + ", null, " + krpano.get("skin_settings.loadscene_flags") + ")");
		if (isHotspot && name) {
			CHK.lookHotspot = name;
		}
		else {
			CHK.lookHotspot = null;
		}
	}
	// シーン名項目クリック時の処理
	if (!name) {
		if ((sceneId != "0" && krpano.get("isOpen") == "1") || (sceneId == "0")) {
			// レーダーマップ項目クリック時の処理
			if (sceneId == "0" && krpano.get("isOpen") != "1" && !$("#0_values").is(':visible')) {
				$("#0_accordionBtn").click();
			}
			krpano.call("togglemap()");
		}
		return;
	}
	if ((isHotspot && krpano.get("isOpen") == "1") || (!isHotspot && krpano.get("isOpen") != "1")) {
		krpano.call("togglemap()");
	}
	if (isHotspot && CHK.operationType != CHK.OPERATION_TYPE.DRAWING) {
		krpano.call("hs_onclick_action(" + name + ", null, " + isHotspot + ")");
	} else {
		krpano.call("ly_onclick_action(" + name + ", null, " + isHotspot + ")");
	}
}

/**
 * 作業ホットスポットを取得
 *
 * @param name ホットスポット名
 * @param taskKey taskKey
 */
CHK.getTaskHotspot = function(name, taskKey) {
	if (!taskKey) taskKey = CHK.getTaskKeyByName(name);
	var ret;
	CHK.taskHotspot.hotspot.some(function(taskHotspot) {
		if (taskHotspot.taskKey == taskKey) {
			ret = taskHotspot;
			return true;
		}
	});
	return ret;
}

/**
 * taskIdを取得
 *
 * @param name ホットスポット名
 * @param taskKey taskKey
 */
CHK.getTaskId = function(name, taskKey) {
	if (!taskKey) taskKey = CHK.getTaskKeyByName(name);
	var ret = -1;
	CHK.taskHotspot.hotspot.some(function(hotspot) {
		if (hotspot.taskKey == taskKey) {
			ret = hotspot.taskId;
			return true;
		}
	});
	return ret;
}

/**
 * 指摘Noを取得
 *
 * @param taskReport 作業報告内容
 */
CHK.getPointNo = function(taskReport) {
	var ret = "";
	if (taskReport && taskReport.task) {
		for (var key in taskReport.task) {
			if (key.indexOf("q_1_") != -1) {
				ret = taskReport.task[key];
			}
		}
	}
	return ret;
}

/**
 * 作業名を取得
 *
 * @param taskReport 作業報告内容
 */
CHK.getTaskName = function(taskReport) {
	var ret = "";
	if (taskReport && taskReport.task) {
		for (var key in taskReport.task) {
			if (key.indexOf("q_2_") != -1) {
				ret = taskReport.task[key];
			}
		}
	}
	return ret;
}

/**
 * 作業報告情報を取得
 *
 * @param name ホットスポット名
 */
CHK.getTaskReport = function(name, taskKey, replyNo) {
	if (!taskKey) taskKey = CHK.getTaskKeyByName(name);
	if (!replyNo && replyNo != 0) replyNo = CHK.taskReplyNo? CHK.taskReplyNo : 0;
	var ret;
	if (!CHK.taskReport["taskReport_" + replyNo] || CHK.taskReport["taskReport_" + replyNo].length == 0) return ret;
	CHK.taskReport["taskReport_" + replyNo].some(function(taskReport) {
		if (taskReport.taskKey == taskKey) {
			ret = taskReport;
			return true;
		}
	});
	return ret;
}

/**
 * 作業の進捗を取得
 *
 */
CHK.getTaskProgress = function(name, taskKey) {
	var ret = "0";
	if (!taskKey) taskKey = CHK.getTaskKeyByName(name);
	var taskReport = CHK.getRecentVersionReport(taskKey);
	if (taskReport && taskReport.task) {
		for (var key in taskReport.task) {
			if (key.indexOf("q_3_") != -1) {
				ret = taskReport.task[key];
			}
		}
	}
	return ret;
}

/**
 * ホットスポットに設定するhtmlを取得
 *
 * @param name ホットスポット名
 * @param isHotspot true:ホットスポット false:レイヤー
 * @param value 表示する値
 */
CHK.getHotspotHtml = function(name, isHotspot, value) {
	//新規追加時
	if (!value) return "[img src=" + TARGET_IMAGE + " style='width:50px;height:50px;pointer-events:none;'][/img]";

	var color = CHK.getTextColor(name);
	if (isHotspot) {
		return "[font size='4' color='#ffffff' style='border-style:solid;border-width:1px;border-color:#ffffff;padding:5px 15px;background-color:" + color + ";'][b]" + value + "[/b][/font]";
	} else {
		if (CHK.operationType == CHK.OPERATION_TYPE.DRAWING) {
			return "[font color='#ffffff' style='border-style:solid;border-width:1px;border-color:#ffffff;padding:5px 15px;background-color:" + color + ";'][b]" + value + "[/b][/font]";
		} else {
			return "[font color='#ffffff' style='border-style:solid;border-width:1px;border-color:#ffffff;padding:5px 15px;background-color:" + color + ";'][b]" + value + "[/b][/font]";
		}
	}
}

/**
 * ホットスポットの文字色を取得
 *
 * @param name ホットスポット名
 */
CHK.getTextColor = function(name) {
	var ret = "#ff7700";
	//作業報告時は作業進捗によって文字色を判定
	var progress = CHK.getTaskProgress(name);
	if (progress == "999") ret = "#1b1bd2";
	return ret;
}

/**
 * ホットスポット名からtaskKeyを取得
 *
 * @param name ホットスポット名
 */
CHK.getTaskKeyByName = function(name) {
	if (name.indexOf("hs") != 0) return name; // PDFの場合、taskKeyをnameとして送る
	return name.substring(name.indexOf("-") + 1);
}

/**
 * seqIdを採番
 *
 */
CHK.getNextSeqId = function() {
	var seqId = 0;
	CHK.taskHotspot.hotspot.forEach(function(hotspot) {
		if (Number(hotspot.seqId) > seqId) {
			seqId = Number(hotspot.seqId);
		}
	});
	return seqId + 1;
}

/**
 * シーンIDを取得
 *
 */
CHK.getSceneId = function() {
	var scene = krpano.get("xml.scene");
	return scene.substring(5);
}

/**
 * 特定のホットスポットへ視点を移動
 *
 * @param name ホットスポット名
 */
CHK.lookToHotspot = function(name) {
	var fov = krpano.get("view.fov");
	krpano.call("looktohotspot(" + name + "," + fov + ")");
}

/**
 * UUIDを生成
 *
 */
CHK.generateUuid = function() {
	var chars = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".split("");
	for (var i = 0, len = chars.length; i < len; i++) {
		switch (chars[i]) {
			case "x":
				chars[i] = Math.floor(Math.random() * 16).toString(16);
				break;
			case "y":
				chars[i] = (Math.floor(Math.random() * 4) + 8).toString(16);
				break;
		}
	}
	return chars.join("");
}

/**
 * URLパラメータを取得
 *
 */
CHK.getUrlParameter = function() {
2179
	var ret = {};
Yujin Seo committed
2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628
	if (location.search) {
		var param = {};
		location.search.substring(1).split('&').forEach(function(val) {
			var kv = val.split('=');
			param[kv[0]] = kv[1];
		});
		ret = param;
	}
	console.log({ret: ret});
	return ret;
}

/**
 * get command of API or Action
 *
 * @param command name
 */
CHK.getCommand = function(cmd) {
	if(CHK.isWeb) {
		return CHK.actCmd[cmd];
	} else {
		return CHK.apiCmd[cmd];
	}
}

/**
 * get URL for CMS action
 * @param action
 */
CHK.getActionUrl = function(action) {
	return CHK.getShopUrl() + "taskVtour/" + action + "/" + operationId + "/";
}

/**
 * get shop URL
 */
CHK.getShopUrl = function() {
	return baseUrl + "/shop/";
}

/**
 * 作業報告初期処理、CMS
 *
 * @param callback コールバック
 */
CHK.cmsAjax = function(url, param, callback) {
	$.ajax({
		type: "POST",
		url: url,
		data: param,
		dataType:"json",
		cache: false,
		success: function(result) {
			if (result.status == "200") {
				if(callback) callback(result);
			} else {
				CHK.showDialog(result.message, null, null, true);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			CHK.showDialog(getMsg("errorOccurred"), null, null, true);
		}
	});
}

/**
 * ファイル情報のAPI送信処理
 *
 */
CHK.sendAttachedFile = function(taskKey, key, fileName, file, fileString, callback) {
	var url = CHK.getActionUrl(CHK.apiCmd.saveAttached);
	var formData = new FormData();

	formData.append('taskKey', taskKey);
	formData.append('attachedKey', key);
	formData.append('filename', fileName);
	// ファイル情報がstringかformか区別
	if (fileString) {
		formData.append('fileString', fileString);
	} else {
		formData.append('formFile', file, fileName);
	}

	CHK.sendEncodedFile(url, formData, callback);
}

/**
 * CMSでのOZDファイル編集後のTempファイル保存処理
 *
 * @param callback コールバック
 */
CHK.saveTempOzdForCms = function(type, taskKey, report, idx, callback) {
	var url = CHK.getActionUrl(CHK.apiCmd.saveAttached);
	var fileName = "taskReportOzd_" + idx;
	switch (type) {
		case CHK.REPORT_SAVE_TYPE.OZD:
			fileName += ".ozd";
			break;
		case CHK.REPORT_SAVE_TYPE.PDF:
			fileName += ".pdf";
			break;
		case CHK.REPORT_SAVE_TYPE.JPG:
			fileName += ".html";
			break;
	}
	var formData = new FormData();
	formData.append('taskKey', taskKey);
	formData.append('attachedKey', type);
	formData.append('filename', fileName);
	formData.append('ozdFileStr', report);
	formData.append('replyNo', CHK.taskReplyNo);

	CHK.sendEncodedFile(url, formData, callback);
}

/**
 * フォームデータのajaxでの送信処理
 *
 * @param callback コールバック
 */
CHK.sendEncodedFile = function(url, formData, callback) {
	jQuery.ajax({
		type: "POST",
		enctype: 'multipart/form-data',
		url: url,
		data: formData,
		processData: false,
		contentType: false,
		cache: false,
		timeout: 600000,
		success: function (result) {
			if (result.status == "200") {
				if (callback) {
					callback(result);
					if (callback.subCallback)
						callback.subCallback();
				}
			} else {
				CHK.showDialog(getMsg("errorOccurred") + "<br>" + result.message, null, null, true);
			}
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			CHK.showDialog(getMsg("errorOccurred"), null, null, true);
		}
	});
}

/**
 * OZDレポートビューワ表示
 *
 * @param taskKey 作業タスクキー
 */
CHK.showOzdReport = function(taskKey, isPreview, saveMessage, replyNo, taskReportId, reportStartDate) {
	if (CHK.debug || CHK.isWeb) {
		// CMSでのOZDビューア表示処理
		// 保存、クリアボタンタップ時の対応
		$(window).off('message');
		$(window).on('message', function(e) {
			var jsonData = JSON.parse(e.originalEvent.data);
			var ozdAction = jsonData.action;
			switch (ozdAction) {
				case CHK.ozdCmd.ozdSave: {
					// OZD形式のファイル保存
					// 保存処理が完了すると、PDF保存処理をする
					CHK.saveTempOzdForCms(CHK.REPORT_SAVE_TYPE.OZD, taskKey, jsonData.report, replyNo, function() {
						$("#report_dialog").dialog('close');
						$("#report_dialog").empty();
						$("#checkInput").find("iframe")[0].contentWindow.setOzdAttachedInfo("taskReportOzd", replyNo);
						$("#checkInput").find("iframe")[0].contentWindow.saveTaskForReport();
						CHK.closeLoading();
					});
					break;
				}
				case CHK.ozdCmd.ozdOpened: {
					CHK.closeLoading();
					break;
				}
				case CHK.ozdCmd.fixed: {
					// 変更がある場合、OZD保存処理をする
					CHK.showLoading(saveMessage);
					// ダイアログの表示を待つ
					setTimeout(function(){
						var message = {action: CHK.ozdCmd.ozdSave};
						$("#reportViewer")[0].contentWindow.postMessage(JSON.stringify(message), "*");
					}, 500);
					break;
				}
				case CHK.ozdCmd.unfixed: {
					// 変更がない場合、閉じる処理のみ実行
					$("#report_dialog").dialog('close');
					$("#report_dialog").empty();
					CHK.closeLoading();
					break;
				}
			}
		});

		var src = CHK.getShopUrl() + "ozdViewer"
		+ "?taskId=" + CHK.getTaskId(null, taskKey)
		+ "&taskKey=" + taskKey
		+ "&operationId=" + operationId
		+ "&reportIdx=" + CHK.taskReplyNo;
		if (taskReportId && reportStartDate) {
			var taskReportInfoId = 0;
			var targetTaskReportInfo = CHK.taskReport.taskReport.filter(function(obj) {
				return obj.reportStartDate == reportStartDate;
			})[0];
			if (targetTaskReportInfo) taskReportInfoId = targetTaskReportInfo.taskReportInfoId;
			src += "&taskReportInfoId=" + taskReportInfoId;
		}

		$("#report_dialog").empty();
		var buttons = {};
		buttons[getMsg("Close")] = function() {
			// 閉じるボタンが押されたことをOZDビューアに通知(変更があるかを確認)
			if (isPreview) {
				$("#report_dialog").dialog('close');
				$("#report_dialog").empty();
				return;
			}
		};

		// index.htmlのreport_dialogにビューアを挿入
		$("#report_dialog").prepend("<iframe id='reportViewer' width='100%' height='100%' src='" + src + "' style='margin-top:5px;border-width:0px;' >"
				+ "</iframe>");

		$("#report_dialog").dialog({
			dialogClass: 'noTitleDialog ui-dialog-titlebar dialogNoBorder',
			autoOpen: false,
			resizable: false,
			modal: true,
			width: "80%",
			height: window.innerHeight*0.9,
			title: '',
			// 画面中央へ表示
			position: {
				my: 'center', at: "center", of: window
			},
			buttons: buttons,
			open: function(e) {
				$(e.target).parent().css('background-color', 'rgba(128,128,128)');
				$(e.target).parent().children(".ui-dialog-buttonpane").css('background-color', 'rgba(128,128,128)').css('border', 'none');
			},
			close: function() {
			}
		});

		$("#report_dialog").dialog('open');
		CHK.showLoading(getMsg("Processing_w_dot"));

	} else {
		// アプリへOZD表示コマンドを送信
		var apiParam = {};
		if (taskReportId) {
			apiParam.taskReportId = taskReportId;
			apiParam.reportStartDate = CHK_I.getInspectIsoDate(new Date(reportStartDate));
		}
		// 連続作業の場合
		if (window.parent.CHK.reportType == window.parent.CHK.REPORT_TYPE.WORKFLOW) {
			apiParam.phaseNo = CHK_PR.selectedPhaseInfo.phaseNo;
			apiParam.processKey = CHK_PR.selectedProcessKey;
			apiParam.addReport = addReportFlg; // REVIEW 定期点検や報告(回答)も対応させる場合は要動作確認
		}
		if (isPreview) {
			apiParam.cmd = CHK.getCommand("previewReportOzd");
			apiParam.taskKey = taskKey;
			apiParam.fileName = "taskReport_" + CHK.taskReplyNo + ".ozd";
			apiParam.taskReportLevel = CHK.taskReplyNo;
			CHK.sendABookCheckApi(apiParam);
		} else {
			var fileType = $("#checkInput").find("iframe")[0].contentWindow.getOzdFileTypeForApp();
			apiParam.cmd = CHK.getCommand("showReportOzd");
			apiParam.taskKey = taskKey;
			apiParam.fileName = "taskReport_" + CHK.taskReplyNo + "." + fileType.toLowerCase();
			apiParam.localSave = localSaveFlg;
			apiParam.addReport = addReportFlg;
			apiParam.taskReportLevel = CHK.taskReplyNo;
			CHK.sendABookCheckApi(apiParam);
		}
	}
}

/**
 * encode string
 *
 * @param str
 */
CHK.encodeParam = function(str) {
	if (CHK.isWeb) {
		return str;
	} else {
		return encodeURIComponent(str);
	}
}

/**
 * 自画面を閉じる
 *
 */
CHK.close = function() {
	if (CHK.isCms) {
		if (window.opener) {
			window.opener.location.href = reloadUrl;
		}
		CHK.unloadAuth();
		$(window).unbind("unload");
	}
	window.close();
	window.open('','_self').close(); // for chrome
}

/**
 * beforeunload処理を登録
 *
 */
CHK.setBeforeunload = function() {
	if (CHK.isCms) {
		$(window).bind("unload", function(eventObject) {
			CHK.unloadAuth();
			if (window.opener) {
				window.opener.location.href = reloadUrl;
			}
		});
	}
}

/**
 * ロック解除を依頼
 *
 * @param callback コールバック
 */
CHK.unloadAuth = function(callback) {
	$.ajax({
		async: false,
		url: CHK.getShopUrl() + "vtour/unloadAuth/" + contentId + "/",
		cache: false,
		success: function(result) {
			if (callback) callback();
		}
	});
}

/**
 * 拡大、縮小ボタン処理
 *
 */
CHK.changeZoom = function(flg) {
	if (CHK.operationType == CHK.OPERATION_TYPE.VTOUR) {
		//360
		CHK_V.changeZoom(flg);
	} else if (CHK.operationType == CHK.OPERATION_TYPE.DRAWING) {
		//図面
		CHK_Z.changeZoom(flg);
	}
}

/**
 * GPS情報を取得
 *
 * @param gpsType 1:自動 2:手動
 */
CHK.getGpsInfo = function(gpsType) {
	if (CHK.isWeb) {
		if (gpsType == "1") {
			// 自動の場合、web版で何も処理を行わないで処理中のダイアログを非表示にする
			CHK.closeLoading();
		} else {
			// 手動
			navigator.geolocation.getCurrentPosition(
				function (pos) {
					var gps = {};
					var crd = pos.coords;
					if (crd.latitude && crd.longitude) {
						gps.latitude = crd.latitude;
						gps.longitude = crd.longitude;
						$("#checkInput").find("iframe")[0].contentWindow.getGpsInfoAfter(gps);
					}
				},
				function (err) {
					console.log(err.message);
					CHK.closeLoading();
				},
				{
					enableHighAccuracy: true,
					timeout : 5000
				}
			);
		}
	} else {
		var apiParam = {};
		apiParam.cmd = CHK.getCommand("getGpsInfo");
		apiParam.gpsType = gpsType;
		apiParam.taskReportLevel = CHK.taskReplyNo;
		CHK.sendABookCheckApi(apiParam);
	}
	//DEBUG
	if (CHK.debug == "1") {
		var gps = {};
		gps.latitude = 35.658;
		gps.longitude = 139.754;
		$("#checkInput").find("iframe")[0].contentWindow.getGpsInfoAfter(gps);
	}
}

/**
 * アプリのヘルプ用に表示状態の変更を通知
 *
 * @param displayStatus 表示状態
 */
CHK.sendDisplayStatus = function(displayStatus, taskKey) {
	if (CHK.isWeb || !addReportFlg) return; // Webの場合とaddReportFlgがfalseの場合、通知不要
	var apiParam = {};
	apiParam.cmd = CHK.getCommand("changeDisplayStatus");
	apiParam.statusCode = displayStatus;
	apiParam.addReport = addReportFlg; // アプリで値が変わる場合があるため、ここでもパラメータ生成する
	if (taskKey && CHK.operationType == CHK.OPERATION_TYPE.PDF) apiParam.taskKey = taskKey;
	console.log(apiParam);
	CHK.sendABookCheckApi(apiParam);
}

/**
 * 作業報告書が表示中かどうかを返す
 *
 */
CHK.isShowingForm = function() {
	return $("#checkInput iframe").is(":visible");
}

/**
 * 関連資料ボタンタップ通知
 */
CHK.showRelatedContent = function(urlPath, contentId, pageNum) {
	var apiParam = {};
	if (!pageNum) pageNum = 1;
	var key = "";
	if (CHK.isWeb) {
		var url = CHK.getShopUrl() + "checkWebContent/onetimekey/" + contentId + "/"
		CHK.getOneTimeKey(url, function(key) {
			window.open("/acms/webvw/checkview.html?urlPath=" + urlPath + "&pageNo=" + pageNum + "&key=" + key);
		});
	} else {
		apiParam.cmd = CHK.getCommand("showRelatedContent");
		apiParam.contentId = contentId;
		apiParam.pageNum = pageNum;
		console.log(apiParam);
		CHK.sendABookCheckApi(apiParam);
	}
}

Lee Munkyeong committed
2629

Yujin Seo committed
2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974
CHK.getOneTimeKey = function(url, callback) {
	$.ajax({
		type: "GET",
		url: url,
		cache: false,
		success: function(result) {
			if (callback) callback(result);
		},
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			CHK.showDialog(getMsg("errorOccurred"), null, null, true);
		}
	});
}

/**
 * 全ホットスポットの表示・非表示ボタン処理
 *
 * @showFlg 処理後のホットスポット表示状態 false:非表示 true:表示
 */
CHK.toggleHotspotVisible = function(showFlg) {
	for (var hotspotIdx in CHK.taskHotspot.hotspot) {
		var hotspot = CHK.taskHotspot.hotspot[hotspotIdx];
		if (CHK.operationType == CHK.OPERATION_TYPE.PDF) {
			if (showFlg) {
				$(".hotspot[name=" + hotspot.taskKey +  "]").show();
			} else {
				$(".hotspot[name=" + hotspot.taskKey +  "]").hide();
			}
		} else {
			var target = CHK.operationType == CHK.OPERATION_TYPE.DRAWING? "layer" : "hotspot";
			krpano.call("set(" + target + "[" + hotspot.name + "].visible, " + showFlg + ")");
		}
	}
}

/**
 * アプリOZReport保存処理対応
 *
 */
CHK.saveOzReport = function() {
	$("#checkInput").find("iframe")[0].contentWindow.setOzdAttachedInfo("taskReport", CHK.taskReplyNo);
	// 連続作業の場合シンプルフォームに戻るため保存は行わない
	if (window.parent.CHK.reportType != window.parent.CHK.REPORT_TYPE.WORKFLOW) {
		$("#checkInput").find("iframe")[0].contentWindow.saveTaskForReport();
	}
}

/**
 * アプリOZReport一時保存処理対応
 *
 */
CHK.localSaveOzReport = function() {
	$("#checkInput").find("iframe")[0].contentWindow.setOzdAttachedInfo("taskReport", CHK.taskReplyNo);
	// 連続作業の場合シンプルフォームに戻るため保存は行わない
	if (window.parent.CHK.reportType != window.parent.CHK.REPORT_TYPE.WORKFLOW) {
		$("#checkInput").find("iframe")[0].contentWindow.saveTaskForReport(true);
	}
}

/**
 * アプリOZReportキャンセル処理対応
 *
 */
CHK.cancelOzReport = function() {
	// 連続作業の場合シンプルフォームに戻るためスキップ
	if (window.parent.CHK.reportType != window.parent.CHK.REPORT_TYPE.WORKFLOW) {
		$("#checkInput").find("iframe")[0].contentWindow.taskClose();
	}
}

/**
 * アプリOZReport削除処理対応
 *
 */
CHK.deleteOzReport = function() {
	$("#checkInput").find("iframe")[0].contentWindow.deleteTask();
}

/**
 * タスクの回答情報リストを取得
 *
 * @param taskKey taskKey
 */
CHK.getTaskReplyReportList = function(taskKey) {
	var taskReplyReportList = [];
	Object.keys(CHK.taskReport).forEach(function(key) {
		if (key != "taskReport_0") {
			CHK.taskReport[key].forEach(function(taskReport) {
				if (taskReport.taskKey == taskKey && (taskReport.task || taskReport.hasAuthority == CHK.HAS_AUTHORITY.TRUE)) {
					taskReplyReportList.push(taskReport);
					return false;
				}
			})
		}
	});
	return taskReplyReportList;
}

/**
 * タスクフォームの報告・回答転換時、リダイレクトするかしないかを判断
 *
 * @param taskKey taskKey
 */
CHK.isRedirectForm = function(taskKey) {
	var ret = true;
	if  (CHK.isCms || CHK.getTaskReport(null, taskKey, 1) && CHK.getTaskReport(null, taskKey, 0).hasAuthority != CHK.getTaskReport(null, taskKey, 1).hasAuthority) ret = false;
	return ret;
}

/**
 * OZレポート表示の場合、checkInputエレメントを透明に設定する
 *
 */
CHK.setTransparentCheckInput = function() {
	$("#checkInput").css("visibility", "hidden");
}

/**
 * 一番最近のバージョン値を取得
 *
 */
CHK.getRecentVersionNum = function(taskKey) {
	var ret = 0;
	Object.keys(CHK.taskReport).forEach(function(key) {
		CHK.taskReport[key].forEach(function(taskReport) {
			if (taskReport.taskKey == taskKey && taskReport.task && taskReport.task.version && taskReport.task.version > ret) {
				ret = taskReport.task.version;
			}
		});
	});
	return ret;
}

/**
 * 一番最近のバージョンのレポートを取得
 *
 */
CHK.getRecentVersionReport = function(name, taskKey) {
	var level;
	if (!taskKey) taskKey = CHK.getTaskKeyByName(name);
	var recentVersion = CHK.getRecentVersionNum(taskKey);
	Object.keys(CHK.taskReport).forEach(function(key) {
		CHK.taskReport[key].forEach(function(taskReport) {
			if (taskReport.taskKey == taskKey && taskReport.task && taskReport.task.version && taskReport.task.version == recentVersion) {
				level = key.split("_")[1];
				return false;
			}
		});
		if (level || level == "0") return false;
	});
	if (!level) level = 0;
	return CHK.getTaskReport(null, taskKey, level);
}
//絞り検索
CHK.getSelectDataJson = function(setIndex, itemIndex) {
	if(!CHK.questionApertureList){
		return;
	}
	//返還するjsonリストを生成する
	var returnList = new Array();

	var enqueteApertureJson;

	enqueteApertureJson =CHK.getEnqueteApertureJson(setIndex);


	if ( enqueteApertureJson != null){
		//子グループリスト取得
		Object.keys(enqueteApertureJson).forEach(function (key) {
			if(enqueteApertureJson[key].parent_id == itemIndex && enqueteApertureJson[key].parent_id != 0)
			{
				var itemObject = new Object();
				itemObject.id = enqueteApertureJson[key].item_id;
				itemObject.value = enqueteApertureJson[key].item_name;
				returnList.push(itemObject);
			}
		});
	}
	// ID順にソートして返却
    returnList.sort(function(a,b) {
        return a.id - b.id;
    });

	return returnList;
}

CHK.getEnqueteApertureJson = function(setIndex){
	var enqueteApertureJson = new Object();
	var apertureList = CHK.questionApertureList;
	var enqueteKey = "set_" + setIndex;

    Object.keys(apertureList).forEach(function (key) {
		if(key == enqueteKey)
		{
			enqueteApertureJson = apertureList[key];
		}
	});

    return enqueteApertureJson;
}

/**
* setからitemIdと同じparent_idを持っているitemを探してListをreturnする
*/
CHK.getApertureSiblingList = function(setId, itemId) {

	var currentId = itemId;
	var itemDepth = -1;
	var returnList = new Array();

	var enqueteApertureJson = CHK.getEnqueteApertureJson(setId);
	var parent_id;
	if(currentId != "") {
		if(enqueteApertureJson != null) {
			Object.keys(enqueteApertureJson).forEach(function (key) {
				if(enqueteApertureJson[key].item_id == currentId)
				{
					itemDepth = enqueteApertureJson[key].depth;
					parent_id = enqueteApertureJson[key].parent_id;
				}
			});
		}
	}

	if(itemDepth != -1) {
		if(enqueteApertureJson != null){
			Object.keys(enqueteApertureJson).forEach(function (key){
				if(enqueteApertureJson[key].parent_id == parent_id && enqueteApertureJson[key].depth == itemDepth)
				{
					var itemObject = new Object();
					itemObject.id = enqueteApertureJson[key].item_id;
					itemObject.value = enqueteApertureJson[key].item_name;
					returnList.push(itemObject);
				}
			});
		}
	}
	// ID順にソートして返却
    returnList.sort(function(a,b) {
        return a.id - b.id;
    });

	return returnList;
}

/**
* 報告グループチェック時、報告グループ情報返還
* 絞り検索例外チェック処理追加
*/
CHK.getCheckResultGroupDataExist = function(setNo, itemId) {
	var result = new Object();
	result.saveFlag = false;
	result.group_id = 0;
	var enqueteApertureJson = CHK.getEnqueteApertureJson(setNo);

	if(CHK.workingGroup == null){
		return result;
	}

	Object.keys(enqueteApertureJson).forEach(function (key) {
 		if(enqueteApertureJson[key].item_id == itemId)
 		{
			if(enqueteApertureJson[key].group_flag)
			{
				if(Object.keys(CHK.workingGroup).length > 0)
				{
					Object.keys(CHK.workingGroup).forEach(function(taskGroup){
						var groupList = CHK.workingGroup[taskGroup];
						Object.keys(groupList).forEach(function(group){
							if(enqueteApertureJson[key].group_id == groupList[group].groupId)
							{
								result.group_id = groupList[group].groupId;
								result.saveFlag = true;
								result.groupName = groupList[group].groupName;
							}
						});
					});
				}
			}
 		}
 	});
	return result;
}

//#Bug 34466 関連対応
/**
 * Androidで修正したイメージのThumbnailを更新する。
 *
 * @param filename ファイル名
 * @param base64String base64ファイルデーター
 */
CHK.changeReportFormThumbnailImageForiOS = function(filename, base64String) {
	var targetContentwindow;
	if ($("#checkInput").find("iframe#reportForm0").length) {
		targetContentwindow = $("#checkInput").find("iframe#reportForm" + CHK.taskReplyNo)[0].contentWindow;
	} else {
		targetContentwindow = $("#checkInput").find("iframe")[0].contentWindow;
	}
	targetContentwindow.changeThumbnailTag(filename, base64String);
}

//#Bug 34466 関連対応
/**
 * Androidで修正したイメージのThumbnailを更新する。
 *
 * @param filePath ファイルパス
 * @param fileName ファイル名
 */
CHK.changeReportFormThumbnailImageForAnd = function(filename, filePath){
	var targetContentwindow;
	if ($("#checkInput").find("iframe#reportForm0").length) {
		targetContentwindow = $("#checkInput").find("iframe#reportForm" + CHK.taskReplyNo)[0].contentWindow;
	} else {
		targetContentwindow = $("#checkInput").find("iframe")[0].contentWindow;
	}
	targetContentwindow.changeThumbnailTagForAnd(filename, filePath);
}

/**
 * フォーム作成・切り替え時のフレーム表示処理
 * ロード終了時に非表示にする
 * フォームを閉じる時に削除
 *
 */
CHK.showWhiteFrame = function() {
	if (CHK.reportType == CHK.REPORT_TYPE.INSPECT) return;

	if ($("#whiteFrame").length == 0) {
		$("#checkInput").after($("<div/>", { id: "whiteFrame" }));
	}

	if (CHK.isWeb) {
		$("#whiteFrame").css("height", "calc(100% - 36px)");
		$("#whiteFrame").css("top", "36px");
	} else if (CHK.operationType == CHK.OPERATION_TYPE.PDF) {
		$("#whiteFrame").css("background-color", "#5c5c5c");
	}

	// リストではない場合フレームのサイズやオフセットを調整する
	if (CHK.operationType != CHK.OPERATION_TYPE.LIST) {
		$("#whiteFrame").width($("#checkInput").width());
		$("#whiteFrame").css("right", $("#checkInput").css("right"));
	}

	$("#whiteFrame").show();
2975 2976
}

2977 2978 2979 2980
/**
 * カテゴリー設定
 */
CHK.createCategory = function(operationGroupMasterList) {
2981

2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994
    $('.group-category-list').remove();
    $("#groupMasterPath").empty();
    if (typeof CHK.operationGroupMasterId == 'undefined' || CHK.operationGroupMasterId == 0) {
        $("#groupMasterPath").append('<li class="breadcrumb-item"><a href="#" class="text-decoration-none text-dark">' + getMsg("all") + '</a></li>');
    } else {
        var groupMaster = operationGroupMasterList.filter(it => it.operationGroupMasterId == CHK.operationGroupMasterId)[0];
        var groupMasterPathIdlist = groupMaster.treePath.split('/');
        groupMasterPathIdlist.forEach( function (parentId){
            var pathOperationGroupMaster = operationGroupMasterList.filter(it => it.operationGroupMasterId == parentId)[0];
            $("#groupMasterPath").append('<li class="breadcrumb-item"><a onclick="CHK.changeOperationGroupMaster('
            + pathOperationGroupMaster.operationGroupMasterId + ');" class="text-decoration-none text-dark">'
            + pathOperationGroupMaster.operationGroupMasterName + '</a></li>');
        });
2995
    }
2996

2997
	//サイドメニューカテゴリー構造作成
2998 2999 3000 3001 3002
	operationGroupMasterList.sort(function(a, b) {
		if (a.operationGroupMasterLevel < b.operationGroupMasterLevel) return -1;
		if (a.operationGroupMasterLevel > b.operationGroupMasterLevel) return 1;
		return 1;
	});
3003 3004
	var noCategory = $("<dl id='groupMasterId_0' class='group-category-list'><dt><a onclick='CHK.changeOperationGroupMaster(0);'>全て</a></dt></dl>");
	$('#category-menu').append(noCategory);
3005 3006
	//TODO operationGroupMasterId順番と深さの仕様確認要
	for (var i = 0; i < operationGroupMasterList.length; i++) {
3007 3008
	    if (operationGroupMasterList[i].operationGroupMasterLevel == 0 ){
	        var categoryParent = $("<dl id=groupMasterId_" + operationGroupMasterList[i].operationGroupMasterId
3009
	            + " class='group-category-list' style='overflow-x:auto;'><dt class='menu-ttl'><a onclick='CHK.changeOperationGroupMaster("
3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031
	            + operationGroupMasterList[i].operationGroupMasterId + ");'>" + operationGroupMasterList[i].operationGroupMasterName
	            + "</a></dt></dl>");
            $('#category-menu').append(categoryParent);
	    } else {
	        var groupParents = '#groupMasterId_' + operationGroupMasterList[i].parentOperationGroupMasterId;
            if ($('#groupMasterId_'+ operationGroupMasterList[i].parentOperationGroupMasterId + '>ul').length > 0){
                categoryChild = $("<li  id='groupMasterId_" + operationGroupMasterList[i].operationGroupMasterId
                    + "' class=''><p class='category-li group-level-" + operationGroupMasterList[i].operationGroupMasterLevel
                    + "'><a class='category-a' onclick='CHK.changeOperationGroupMaster("
                    + operationGroupMasterList[i].operationGroupMasterId + ");'>" + operationGroupMasterList[i].operationGroupMasterName
                    + "</a></p></li>");
                $('#groupMasterId_' + operationGroupMasterList[i].parentOperationGroupMasterId + ' >ul').append(categoryChild);
            } else {
                $(groupParents + " > p").addClass("sub-menu-ttl");
                categoryChild = $("<ul style='display:none;' class=''><li class='' id='groupMasterId_" + operationGroupMasterList[i].operationGroupMasterId
                + "' class=''><p class='category-li group-level-"
                + operationGroupMasterList[i].operationGroupMasterLevel
                + "'><a class='category-a' onclick='CHK.changeOperationGroupMaster(" + operationGroupMasterList[i].operationGroupMasterId
                + ");'>" + operationGroupMasterList[i].operationGroupMasterName + "</a></p></li></ul>");
                $('#groupMasterId_' + operationGroupMasterList[i].parentOperationGroupMasterId).append(categoryChild);
            }
	    }
3032
	}
3033
	acdMenu();
3034 3035 3036
};

/**
3037 3038 3039 3040 3041 3042 3043
 * 保存したsortTypeから作業一覧を描画
 */
 CHK.createOperationListBySavedSortType = function() {
	let sortIndex = CHK_CONSTANT.SORT_TYPE.START_DATE_ASC;
	if (CHK.isIOS) {
		sortIndex = CHK_iOS.getSortType();
	} else if (CHK.isAndroid) {
Yujin Seo committed
3044 3045 3046 3047 3048 3049 3050
        sortIndex = android.getSortType();
    } else if (CHK.isWindows) {
        if (CHK.sortIndex !== undefined) {
            console.log("CHK.sortIndex:" + CHK.sortIndex);
            sortIndex = CHK.sortIndex;
        }
    }
3051 3052 3053 3054 3055 3056
	let sortType = document.getElementsByClassName("sort-type")[sortIndex];
	CHK.changeSortType(sortType);
}

CHK.changeSortType = function(sortType) {
	$(".sort-type").removeClass("active");
3057 3058
    $(sortType).addClass("active");
    CHK.sortIndex = $(sortType).attr("data-sort");
3059 3060 3061 3062
	CHK.createOperationList(CHK.operation.operationList, true);
}

/**
3063 3064
 * 作業一覧描画
 */
Lee Munkyeong committed
3065
CHK.createOperationList = function(operationList, isSearched = false) {
3066
	//alert("hongnt CHK.createOperationList ");
3067 3068 3069 3070
    var searchKeyword = $("#searchTaskName").val();
    var searchStartDate = $("#searchStartDate").val();
    var searchEndDate = $("#searchEndDate").val();
    var operationGroupMasterId = CHK.operationGroupMasterId;
3071
    $('#operationTable').empty();
Lee Munkyeong committed
3072
    if (isSearched) {
3073 3074
        operationList = CHK.operation.searchOperationList;
    }
3075 3076 3077

    operationList = operationList.filter(function(operation) {
        var result = true;
3078
        if (searchKeyword && searchKeyword.length) {
3079 3080
            result = result * operation.operationName.includes(searchKeyword);
        }
3081
        if (searchStartDate && searchEndDate && searchStartDate.length && !searchEndDate.length) {
3082 3083
            result = result * (operation.operationStartDate >= searchStartDate);
        }
3084
        if (searchStartDate && searchEndDate && searchEndDate.length && !searchStartDate.length) {
3085 3086
            result = result * (operation.operationEndDate <= searchEndDate);
        }
3087
        if (searchStartDate && searchEndDate && searchStartDate.length && searchEndDate.length) {
3088 3089 3090
            result = result * ((operation.operationStartDate <= searchEndDate) && (operation.operationEndDate >= searchStartDate));
        }

3091
        if (CHK.operationGroupMasterRelation && operationGroupMasterId != 0) {
3092 3093 3094 3095 3096 3097 3098 3099 3100 3101
            var operationGroupMasterIdList = CHK.operationGroupMasterRelation.operationGroupMasterRelationList.filter(function(operationGroupMasterRelation) {
                return operationGroupMasterRelation.operationId == operation.operationId;
            })
            result = result * operationGroupMasterIdList.filter(function(operationGroupMaster){
                return operationGroupMaster.operationGroupMasterId == operationGroupMasterId;
            }).length;
        }
        return result;
    })

3102 3103
    if (operationList.length > 1) {
        var sortType = $(".sort-type.active").data("sort");
3104
		if (isSearched) {
Yujin Seo committed
3105 3106 3107 3108 3109 3110 3111 3112 3113
            if (CHK.isIOS) {
                webkit.messageHandlers.saveSortType.postMessage(sortType);
            } else if (CHK.isAndroid) {
                android.setSortType(sortType);
            } else {
                var param = {};
                param.cmd = CHK.getCommand("saveSortType");
                param.sortType = sortType;
                CHK.sendABookCheckApi(param);
3114 3115
			}
		}
3116 3117
        switch(sortType) {
            case CHK_CONSTANT.SORT_TYPE.NAME:
3118 3119 3120 3121 3122
				operationList.sort(function(a,b) {
					if (a.operationName > b.operationName) return 1;
					if (a.operationName < b.operationName) return -1;
					return 0;
				});
3123 3124
                break;
            case CHK_CONSTANT.SORT_TYPE.START_DATE_DESC:
3125 3126 3127 3128 3129
				operationList.sort(function(a,b) {
					if (setOperationDate(a.operationStartDate) < setOperationDate(b.operationStartDate)) return 1;
					if (setOperationDate(a.operationStartDate) > setOperationDate(b.operationStartDate)) return -1;
					return 0;
				});
3130 3131
                break;
            case CHK_CONSTANT.SORT_TYPE.START_DATE_ASC:
3132 3133 3134 3135 3136
				operationList.sort(function(a,b) {
					if (setOperationDate(a.operationStartDate) > setOperationDate(b.operationStartDate)) return 1;
					if (setOperationDate(a.operationStartDate) < setOperationDate(b.operationStartDate)) return -1;
					return 0;
				});
3137 3138
                break;
            case CHK_CONSTANT.SORT_TYPE.TYPE:
3139 3140 3141 3142 3143
				operationList.sort(function(a,b) {
					if (a.operationType < b.operationType) return 1;
					if (a.operationType > b.operationType) return -1;
					return 0;
				});
3144 3145
                break;
            case CHK_CONSTANT.SORT_TYPE.LAST_EDIT_DATE:
3146
				operationList.sort(function(a,b) {
3147 3148 3149 3150 3151 3152 3153 3154
				    if (!a.operationOpenDate) {
				        a.operationOpenDate = "1900-01-01 09:00:00";
				    }
				    if (!b.operationOpenDate) {
                        b.operationOpenDate = "1900-01-01 09:00:00";
                    }
					if (a.operationOpenDate < b.operationOpenDate) return 1;
					if (a.operationOpenDate > b.operationOpenDate) return -1;
3155 3156
					return 0;
				});
3157 3158 3159
                break;
        }
    }
3160
    for (var i = 0; i < operationList.length; i++) {
3161
		var operationTR;
3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174

		if (CHK.isIOS) {
			if (operationList[i].needSyncFlag == 1) {
				operationTR = $("<tr class= 'update'/>");
			} else {
				operationTR = $("<tr/>");
			}
		} else {
			if(operationList[i].needSyncFlg == 1){
				operationTR = $("<tr class= 'update'/>");
			} else{
				operationTR = $("<tr/>");
			}
3175
		}
3176

3177
		//TODO aタグlist.html 転移処理
Lee Munkyeong committed
3178 3179 3180 3181 3182 3183 3184 3185 3186 3187
		var operationNameTd;
		if (operationList[i].permitCodeRequiredFlg == 1) {
		     operationNameTd = $("<td class='operationId_" + operationList[i].operationId
            		    + "'><a href=\"javascript:CHK.displayAlert('onlyRfid');\" class='d-block text-black text-decoration-none mb-1'>" + operationList[i].operationName
            		    + "</a><div class='fa-sm mobile_operation_date'><i class='far fa-clock fa-blue' style='color:blue;margin-right:10px'></i>"
            		    + setOperationDate(operationList[i].operationStartDate) + " ~ "
            		    + setOperationDate(operationList[i].operationEndDate) +"</div></td>");
		} else {
             operationNameTd = $("<td class='operationId_" + operationList[i].operationId
                        + "'><a href=\"javascript:CHK_L.sendAppCommand('goOperation', '"
3188
                        + operationList[i].operationId + "', '" + operationList[i].contentId + " ', null ,'REPORT_LIST' ,'REPORT_LIST',null);\"  class='d-block text-black text-decoration-none mb-1'>" + operationList[i].operationName
Lee Munkyeong committed
3189 3190 3191 3192
                        + "</a><div class='fa-sm mobile_operation_date'><i class='far fa-clock fa-blue' style='color:blue;margin-right:10px'></i>"
                        + setOperationDate(operationList[i].operationStartDate) + " ~ "
                        + setOperationDate(operationList[i].operationEndDate) +"</div></td>");
		}
3193

3194 3195
		var operationStartDateTd = $("<td/>", {class: "operationStartDate"}).text(setOperationDate(operationList[i].operationStartDate));
		var operationEndDateTd = $("<td/>", {class: "operationEndDate"}).text(setOperationDate(operationList[i].operationEndDate));
3196

3197
        var iconTd = operationList[i].operationType == CHK.OPERATION_TYPE.VTOUR ? $("<td class='p-2'> <button class='btn btn-outline-primary fs-8 py-2' onclick=\"javascript:CHK_L.sendAppCommand('goPanoramaEdit', '" + operationList[i].operationId + "', '" + operationList[i].contentId + "');\">VR</button> </td>") : $("<td class='p-2 align-middle'>&nbsp;&emsp;-</td>");
3198 3199

		operationTR.append(operationNameTd);
3200 3201
        operationTR.append(operationStartDateTd);
        operationTR.append(operationEndDateTd);
3202 3203 3204
		operationTR.append(iconTd);

		$(".table tbody").append(operationTR);
3205

3206
	}
3207 3208 3209
	if(CHK.isAndroid) {
        android.hideLoading();
    }
3210 3211
};

3212
/**Oper
3213 3214 3215 3216 3217
 * Date表示(yyyy/MM/dd)hh以下省略
 */
function setOperationDate(date){
	var operationDate = date.replace(/-/g, "/").substring(0,10);
	return operationDate;
Lee Munkyeong committed
3218 3219 3220 3221 3222 3223 3224 3225 3226
};

/**
 * 作業一覧検索
 */
CHK.search = function() {
    var searchKeyword = $("#searchTaskName").val();
    var searchStartDate = $("#searchStartDate").val();
    var searchEndDate = $("#searchEndDate").val();
3227
    var operationGroupMasterId = CHK.operationGroupMasterId;
Lee Munkyeong committed
3228
    var searchResult;
3229

3230
	if((searchStartDate && searchEndDate) && (searchStartDate > searchEndDate)){
3231 3232 3233 3234
		CHK.displayAlert("dateError");
		return;
	}

3235 3236 3237 3238 3239
    searchResult = CHK.operation.operationList.filter(function(operation) {
        var result = true;
        if (searchKeyword.length) {
            result = result * operation.operationName.includes(searchKeyword);
        }
3240
        if (searchStartDate.length && !searchEndDate.length) {
3241
            result = result * (operation.operationStartDate >= searchStartDate);
3242
        }
3243
        if (searchEndDate.length && !searchStartDate.length) {
3244
            result = result * (operation.operationEndDate <= searchEndDate);
3245
        }
3246 3247 3248 3249
        if (searchStartDate.length && searchEndDate.length) {
            result = result * ((operation.operationStartDate <= searchEndDate) && (operation.operationEndDate >= searchStartDate));
        }

3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262
        if (operationGroupMasterId != 0) {
            var operationGroupMasterIdList = CHK.operationGroupMasterRelation.operationGroupMasterRelationList.filter(function(operationGroupMasterRelation) {
                return operationGroupMasterRelation.operationId == operation.operationId;
            })
            result = result * operationGroupMasterIdList.filter(function(operationGroupMaster){
                return operationGroupMaster.operationGroupMasterId == operationGroupMasterId;
            }).length;
        }
        return result;
    })
    CHK.isSearched = true;
    CHK.operation.searchOperationList = searchResult;
    CHK.createOperationList(searchResult, CHK.isSearched);
3263 3264
};

3265 3266 3267 3268 3269 3270 3271
/**
 * 検索条件をセット
 */
CHK.setSearchInfo = function(taskName, startDate, endDate) {
	$("#searchTaskName").val(taskName);
	$("#searchStartDate").val(startDate);
	$("#searchEndDate").val(endDate);
3272 3273 3274 3275 3276 3277 3278 3279 3280 3281
}

// カテゴリーのドロワーメニュー開閉
function acdMenu() {
    //デフォルトでアコーディオンの中身を非表示
    $(".drawer-menu dd").css("display", "none");
    $(".drawer-menu2 ul").css("display", "none");

    //第2階層のアコーディオン 
    $(".drawer-menu dt").on('click', function() {
3282
        $(".sub-menu-ttl").removeClass("openAcd").next().slideUp("fast");
3283 3284 3285 3286 3287
        $(".drawer-menu dt").not(this).removeClass("open").next().slideUp("fast");
        $(this).toggleClass("open").next().slideToggle("fast");
    });

    //第3階層のアコーディオン
3288 3289
    $(".sub-menu-ttl").on('click', function() {
        $(".sub-menu-ttl").not($(this)).not($(this).parents().siblings("p")).removeClass("openAcd").next().slideUp("fast");
3290 3291 3292 3293 3294
        $(this).toggleClass("openAcd").next().slideToggle("fast");
    });
}

CHK.changeOperationGroupMaster = function(operationGroupMasterId) {
3295 3296
    if ($("#category-menu").hasClass("open")) {
         $('#category-toggle-button').click();
3297
		 $("body").css("overflow", "visible");
3298
    }
3299 3300 3301
    CHK.operationGroupMasterId = operationGroupMasterId;
    CHK.createCategory(CHK.operationGroupMaster.operationGroupMasterList);
    CHK.search();
Lee Munkyeong committed
3302 3303 3304
}

CHK.startScan = function() {
Lee Munkyeong committed
3305 3306 3307
    try {
      if (CHK.isAndroid) {
        android.startScan();
3308
      } else if (CHK.isIOS) {
Kim Peace committed
3309 3310
        webkit.messageHandlers.startScan.postMessage({});
      }
Lee Munkyeong committed
3311 3312 3313
    } catch (e) {
      return;
    }
Lee Munkyeong committed
3314 3315
    $(".scan-overlay").removeClass("d-none");
    $(".scan-area").removeClass("d-none");
3316 3317

	var positionY = $(document).scrollTop() + screen.height/8;
3318
	var height = 200;
3319 3320 3321
	$(".scan-area").css("top", positionY);
	$(".scan-area").css("min-height", height);
	$("body").css("overflow", "hidden");
Lee Munkyeong committed
3322 3323 3324
}

CHK.scanClose = function() {
Lee Munkyeong committed
3325 3326 3327
    try {
      if (CHK.isAndroid) {
        android.stopScan();
3328
      } else if (CHK.isIOS) {
Kim Peace committed
3329 3330
        webkit.messageHandlers.stopScan.postMessage({});
      }
Lee Munkyeong committed
3331 3332 3333
    } catch (e) {
      return;
    }
Lee Munkyeong committed
3334 3335
    $(".scan-overlay").addClass("d-none");
    $(".scan-area").addClass("d-none");
3336
	$("body").css("overflow", "visible");
Lee Munkyeong committed
3337 3338
}

3339 3340
document.addEventListener('visibilitychange', () => {
	// バックグラウンド遷移時
3341
	if (document.visibilityState === 'hidden') {
3342 3343 3344 3345
		CHK.scanClose();
	}
});

Lee Munkyeong committed
3346
CHK.scanResult = function(scannedCode, scanType) {
3347 3348
	CHK.scanResultCode = scannedCode;
	CHK.scanType = scanType;
3349 3350 3351
    if (scannedCode == null || !(scannedCode.length)) {
        return;
    }
Lee Munkyeong committed
3352 3353 3354
    CHK.scanClose();
    var operationList = CHK.operation.searchOperationList;
    var scannedOperation = operationList.filter(function(operation) {
3355 3356 3357
        var resultCode =  scannedCode;
        if (scanType == 1)  {
            resultCode =  scannedCode.substring(4);
3358
			CHK.scanResultCode = resultCode;
3359 3360
        }
        return operation.permitCode == resultCode;
Lee Munkyeong committed
3361 3362
    })[0];
    if (scannedOperation != null) {
3363
        CHK.sendScanResult('goOperation', scannedOperation.operationId, scannedOperation.contentId, scanType ,'REPORT_LIST' ,'REPORT_LIST',null);
Lee Munkyeong committed
3364 3365 3366 3367 3368
    } else {
        CHK.displayAlert("notExistCode");
    }
}

Lee Munkyeong committed
3369 3370 3371 3372 3373 3374 3375 3376 3377 3378
CHK.sendScanResult = function (command, operationId, contentId, scanType) {
    var param = {};
    param.cmd = CHK.getCommand(command);
    param.operationId = operationId;
    param.contentId = contentId;
    param.scanType = scanType;
    CHK.sendABookCheckApi(param);
}


Lee Munkyeong committed
3379 3380 3381
CHK.alertClose = function() {
    $(".alert-overlay").addClass("d-none");
    $(".alert-area").addClass("d-none");
3382
	$("body").css("overflow", "visible");
Lee Munkyeong committed
3383 3384 3385
}

CHK.displayAlert = function(msgCode) {
3386
	// RFID(バーコード)関連は通常のアラート表示
3387 3388 3389
	if (msgCode == "notExistCode") {
		// scanResultCodeを代入するため別で処理
		setLangCode();
3390 3391 3392 3393 3394 3395
		var notExistCodeMessage = {ja:"読み込んだコードと一致しません。\n\n読み込んだコード: " + CHK.scanResultCode + "\n\nコードを確認してもう一度お願いします。", ko:"스캔된코드와 일치하는 작업이 존재하지않습니다.\n\n스캔 한 코드: " + CHK.scanResultCode + "\n\n코드를 확인하고 한번도 시도해주세요.", en:"No action exists that matches the scanned code.\n\nScanned code: " + CHK.scanResultCode + "\n\nPlease check the code and try it once."};
		if (CHK.scanType == 1) {
			// RFIDは24桁で1行に表示しきれないため改行を追加
			notExistCodeMessage = {ja:"読み込んだコードと一致しません。\n\n読み込んだコード:\n" + CHK.scanResultCode + "\n\nコードを確認してもう一度お願いします。", ko:"스캔된코드와 일치하는 작업이 존재하지않습니다.\n\n스캔 한 코드:\n" + CHK.scanResultCode + "\n\n코드를 확인하고 한번도 시도해주세요.", en:"No action exists that matches the scanned code.\n\nScanned code:\n" + CHK.scanResultCode + "\n\nPlease check the code and try it once."};
		}
		alert(notExistCodeMessage[lang]);
3396
	} else if (msgCode == "onlyRfid") {
3397
		alert(getMsg(msgCode));
3398 3399 3400 3401 3402 3403
	} else {
		$("#alertMsg").html(getMsg(msgCode));
		$(".alert-overlay").removeClass("d-none");
		$(".alert-area").removeClass("d-none");
		var positionY = $(document).scrollTop() + screen.height/8;
		var height = screen.height/4;
3404

3405
		$(".alert-overlay").css("height", screen.height);
3406 3407 3408 3409
		$(".alert-area").css("top", positionY);
		$(".alert-area").css("min-height", height);
		$("body").css("overflow", "hidden");
	}
3410 3411 3412 3413 3414 3415 3416
}

CHK.resetSearch = function() {
    $('#searchTaskName').val('');
    $('#searchStartDate').val('');
    $('#searchEndDate').val('');
    CHK.changeSortType($('#defaultSort'));
3417 3418
}

Yujin Seo committed
3419

3420 3421 3422 3423 3424 3425 3426
CHK.openCategory = function() {
	window.scrollTo(0,0);
    if ($("#category-menu").hasClass("open")) {
		$("body").css("overflow", "visible");
   	}else{
		$("body").css("overflow", "hidden");
	}
Yujin Seo committed
3427 3428
}

3429 3430 3431 3432 3433 3434 3435 3436 3437
//save, load json
CHK.saveJson = function(jsonFileName, jsonData) {
	var param = {};
	param.cmd = CHK.getCommand("saveJson");
	param.jsonName = jsonFileName;
	param.jsonData = JSON.stringify(jsonData);
	CHK.sendABookCheckApi(param);
}

3438 3439 3440 3441 3442 3443
CHK.sendAppCommand = function (command, param) {
    var apiParam = Object.assign({}, param);
    apiParam.cmd = CHK.getCommand(command);
    CHK.sendABookCheckApi(apiParam);
}

Yujin Seo committed
3444 3445
$(document).ready(function () {
    var urlParam = CHK.getUrlParameter();
NGUYEN HOANG SON committed
3446 3447
	if (typeof urlParam !== 'undefined' && typeof urlParam.lang !== 'undefined') {
		CHK.lang = urlParam.lang;
3448 3449 3450 3451 3452
	} else {
		CHK.loadSessionKey('lang');
	}
	if (typeof CHK.lang === 'undefined') {
		CHK.lang = 'ja';
NGUYEN HOANG SON committed
3453
	}
Yujin Seo committed
3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471
    console.log("CHK.lang:" + CHK.lang);

    $(".multi-lang").each(function () {
        var key = $(this).attr("data-msg");
        if (key) {
            if ($(this).prop("tagName").toLowerCase() == "input" && ($(this).attr("type") == "text" || $(this).attr("type") == "search")) {
                var attr = $(this).attr('placeholder');
                if (typeof attr !== 'undefined' && attr !== false) {
                    $(this).attr("placeholder", getMsg(key));
                } else {
                    $(this).val(getMsg(key));
                }
            } else {
                $(this).html(getMsg(key));
            }
        }
    });
});