contentview_Memo.js 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316

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

CONTENTVIEW_MEMO.createMemoDialog = function(){
	CONTENTVIEW_MEMO.targetDiv.show();
	CONTENTVIEW_MEMO.targetDiv.html('');
	CONTENTVIEW_MEMO.targetDiv.append(
	'<aside id="memoWrapper" class="MemoIndexBox">'
	+ '	<h1 class="indexBoxHd">' + I18N.i18nText('txtMemo')
	+'		<a id="memoClosing2" class="delete"></a>'
	+'	</h1>'
	+'	<div id="memoArea" class="indexBoxBody_on">'
	+'		<textarea id="txaMemoContent" style="resize: none; height: 302px; width: 452px; margin-bottom: 10px"></textarea>'
	+'		<div style="width: 450px;">'
	+ '			<a id="Memo_btnCancel" style="float:right" class="lang cancelbtn" lang="dspCancel">' + I18N.i18nText('dspCancel') + '</a>'
	+ '			<a id="Memo_btnDel" style="float:right" class="lang cancelbtn" lang="dspDelete">' + I18N.i18nText('dspDelete') + '</a>'
	+ '			<a id="Memo_btnSave" style="float:right" class="lang cancelbtn" lang="dspSave">' + I18N.i18nText('dspSave') + '</a>'
	+'		</div>'
	+'	</div>'
	+'</aside>');
	
	$('#txaMemoContent').focus();
	
	CONTENTVIEW_MEMO.handleMemoEventFunction();
};

CONTENTVIEW_MEMO.handleMemoEventFunction = function(){
	$('#Memo_btnSave').click(CONTENTVIEW_MEMO.buttonSaveFunction);
	$('#Memo_btnDel').click(CONTENTVIEW_MEMO.MemoDelFunction);
	$('#Memo_btnCancel').click(CONTENTVIEW_MEMO.MemoCancelFunction);
	//$('.delete').click(CONTENTVIEW_MEMO.MemoCancelFunction);
	$("#memoClosing2").on({
		'click touchend': function(ev){
			CONTENTVIEW_MEMO.MemoCancelFunction(ev);
			return false;
		},
		'touchstart touchmove': function(){
			//これを入れないと次にダイアログを開くと表示位置が大きくズレる
			return false;
		}
	});
	
};

CONTENTVIEW_MEMO.memoSaveFunction = function(){

	var tempArr = [];	
	
	var memoObj = new MemoEntity();
	memoObj.pageNo = CONTENTVIEW_MEMO.pageid;
	memoObj.contentid = CONTENTVIEW_MEMO.conid;
	memoObj.Text = $('#txaMemoContent').val();
	var imagePt = CONTENTVIEW.screenToImage(CONTENTVIEW_MEMO.targetX, CONTENTVIEW_MEMO.targetY);
	
    //#11478 逆に縮める対応
    var canvasWidth = $('#offscreen').width();
    var canvasHeight = $('#offscreen').height();
    //var tempRatioWidth = canvasWidth / CONTENTVIEW_GENERAL.widthEachPageApi;
    var tempRatioWidth = CONTENTVIEW_GENERAL.widthEachPageApi / canvasWidth;
    if( tempRatioWidth > 1 ){
        tempRatioWidth = 1;
    }
    var tempRatioHeight = CONTENTVIEW_GENERAL.heightEachPageApi / canvasHeight;
    if( tempRatioHeight > 1 ){
        tempRatioHeight = 1;
    }
    memoObj.posX = Math.round(imagePt.x * tempRatioWidth);
    memoObj.posY = Math.round(imagePt.y * tempRatioHeight);
    //memoObj.posX = imagePt.x;
    //memoObj.posY = imagePt.y;
    
	//=== Start Function : No.17    Editor : Long   Date: 07/30/2013   Summary : Set UTC time and UUID when create new memo.
	memoObj.memoid = COMMON.getUUID();
	memoObj.registerDate = new Date();
	//=== End Function : No.17    Editor : Long   Date: 07/30/2013   Summary : Set UTC time and UUID when create new memo.
	tempArr = ClientData.MemoData();	
	tempArr.push(memoObj);	
	ClientData.MemoData(tempArr);
	
	if(CONTENTVIEW_MEMO.memoCallbackFunc){
		CONTENTVIEW_MEMO.memoCallbackFunc();
	}
};

CONTENTVIEW_MEMO.MemoDelFunction = function(){
	if(CONTENTVIEW_MEMO.saveMode == 'Copy'){
		//CONTENTVIEW_MEMO.targetDiv.dialog('close');
		CONTENTVIEW_MEMO.targetDiv.fadeOut('medium', function(){
			
		});
		
		CONTENTVIEW_GENERAL.isCopyMemo = false;
	}
	else{
		
		var resultArr = ClientData.MemoData();
		resultArr.splice(CONTENTVIEW_MEMO.EditIndex, 1);
		
		ClientData.MemoData(resultArr);
	
		//CONTENTVIEW_MEMO.targetDiv.dialog('close');	
		//if(CONTENTVIEW_MEMO.memoCallbackFunc){
		//	CONTENTVIEW_MEMO.memoCallbackFunc();
		//}
		
	}
	$("#overlay").hide();
	CONTENTVIEW_MEMO.targetDiv.children().remove();
	CONTENTVIEW_MEMO.targetDiv.hide();
	
	$("#pop_up_memo").hide();
	
	/* draw again */
	CONTENTVIEW.drawCanvas();	
	//START TRB00054 - EDITOR : Long - Date : 09/19/2013 - Summary : Fix for remove loading icon when del memo 
	CONTENTVIEW.drawCanvas(1);
	//END TRB00054 - EDITOR : Long - Date : 09/19/2013 - Summary : Fix for remove loading icon when del memo
	
	/* enable controls after finish copy */
	CONTENTVIEW.enableControlsCopyMemo();
	
};

CONTENTVIEW_MEMO.MemoCancelFunction = function(){
	//CONTENTVIEW_MEMO.targetDiv.dialog('close');
	$("#overlay").hide();	
	CONTENTVIEW_MEMO.targetDiv.children().remove();
	CONTENTVIEW_MEMO.targetDiv.hide();
	
	CONTENTVIEW_GENERAL.isCopyMemo = false;
	$("#pop_up_memo").hide();
	
	/* enable controls after finish copy */
	CONTENTVIEW.enableControlsCopyMemo();
	
	if(ClientData.IsAddingMemo() == true){	
		ClientData.IsAddingMemo(false); 	
		
	    //change class
        $('#imgaddmemo').removeClass();
        $('#imgaddmemo').addClass('memoAdd');	
	}	
};

CONTENTVIEW_MEMO.AddMemo = function(contentId,pageNo,targetId, posX, posY, callback) {
	CONTENTVIEW_MEMO.conid = contentId;
	CONTENTVIEW_MEMO.pageid = pageNo;
	CONTENTVIEW_MEMO.targetDiv = targetId;
	CONTENTVIEW_MEMO.targetX = posX;
	CONTENTVIEW_MEMO.targetY = posY;
	CONTENTVIEW_MEMO.memoCallbackFunc = callback;
	
	CONTENTVIEW_MEMO.createMemoDialog();
	CONTENTVIEW_MEMO.saveMode = 'New';
	$('#Memo_btnDel').css('display','none');
	
	//CONTENTVIEW_MEMO.targetDiv.dialog({width: 466, height: 390, modal: true, position: [CONTENTVIEW_MEMO.targetX, CONTENTVIEW_MEMO.targetY], resizable: false});	
	//CONTENTVIEW_MEMO.targetDiv.parent().removeClass('ui-draggable');
	$("#overlay").show();
	CONTENTVIEW.disableControlsCopyMemo();
	CONTENTVIEW_MEMO.targetDiv.css('z-index','1005');
	
	//START TRB00097
	if(CONTENTVIEW_MEMO.targetY >= $('#wrapper').height()/2){
		CONTENTVIEW_MEMO.targetDiv.css('top', $('#wrapper').height()/3);
		CONTENTVIEW_MEMO.targetDiv.css('left',CONTENTVIEW_MEMO.targetX - ($('#memoWrapper').width() /2 ));
	    
	}
	else{
		CONTENTVIEW_MEMO.targetDiv.css('top',CONTENTVIEW_MEMO.targetY);
		CONTENTVIEW_MEMO.targetDiv.css('left',CONTENTVIEW_MEMO.targetX - ($('#memoWrapper').width() /2 ));
	}
	//END TRB00097
	
	
	
	CONTENTVIEW_MEMO.targetDiv.draggable({ handle: "h1" });
	//CONTENTVIEW_MEMO.editJqueryUIDialog();
};

CONTENTVIEW_MEMO.EditMemo = function(index, posXPlus, posYPlus, targetId, callback){
	CONTENTVIEW_MEMO.targetDiv = targetId;
	CONTENTVIEW_MEMO.targetX = ClientData.MemoData()[index].posX + posXPlus;
	CONTENTVIEW_MEMO.targetY = ClientData.MemoData()[index].posY + posYPlus;
	
	CONTENTVIEW_MEMO.EditIndex = index;
	CONTENTVIEW_MEMO.memoCallbackFunc = callback;
	
	CONTENTVIEW_MEMO.createMemoDialog();
	CONTENTVIEW_MEMO.getMemoForEdit();
	CONTENTVIEW_MEMO.saveMode = 'Edit';
	$('#Memo_btnDel').css('display','block');
	
	//CONTENTVIEW_MEMO.targetDiv.dialog({width: 466, height: 390, modal: true, position: [CONTENTVIEW_MEMO.targetX, CONTENTVIEW_MEMO.targetY], resizable: false});
	//CONTENTVIEW_MEMO.targetDiv.parent().removeClass('ui-draggable');
	$("#overlay").show();
	CONTENTVIEW.disableControlsCopyMemo();
	CONTENTVIEW_MEMO.targetDiv.css('z-index','1005');
		
	var pt = CONTENTVIEW.imageToScreen(CONTENTVIEW_MEMO.targetX, CONTENTVIEW_MEMO.targetY);	
	
   //START TRB00097
    if(pt.y >= $('#wrapper').height()/2){
    	CONTENTVIEW_MEMO.targetDiv.css('top', $('#wrapper').height()/3);
    	CONTENTVIEW_MEMO.targetDiv.css('left',pt.x - ($('#memoWrapper').width() /2 ));       
    }
    else{
    	CONTENTVIEW_MEMO.targetDiv.css('top',pt.y);
    	CONTENTVIEW_MEMO.targetDiv.css('left',pt.x - ($('#memoWrapper').width() /2 ));
    }
    //END TRB00097
	
    CONTENTVIEW_MEMO.targetDiv.draggable({ handle: "h1" });
	//CONTENTVIEW_MEMO.editJqueryUIDialog();
};

CONTENTVIEW_MEMO.CopyMemo = function(index,contentId,pageNo,targetId, posX, posY, callback){
	CONTENTVIEW_MEMO.conid = contentId;
	CONTENTVIEW_MEMO.pageid = pageNo;
	CONTENTVIEW_MEMO.targetDiv = targetId;
	CONTENTVIEW_MEMO.targetX = posX;
	CONTENTVIEW_MEMO.targetY = posY;
	CONTENTVIEW_MEMO.EditIndex = index;
	CONTENTVIEW_MEMO.memoCallbackFunc = callback;
	
	CONTENTVIEW_MEMO.createMemoDialog();
	//CONTENTVIEW_MEMO.getMemoForEdit();
	$('#txaMemoContent').val(index);
	CONTENTVIEW_MEMO.saveMode = 'Copy';
	$('#Memo_btnDel').css('display','none');
	//CONTENTVIEW_MEMO.targetDiv.dialog({width: 466, height: 390, modal: true, position: [CONTENTVIEW_MEMO.targetX, CONTENTVIEW_MEMO.targetY], resizable: false});
	//CONTENTVIEW_MEMO.targetDiv.parent().removeClass('ui-draggable');
	$("#overlay").show();
	CONTENTVIEW.disableControlsCopyMemo();
	CONTENTVIEW_MEMO.targetDiv.css('z-index','1005');
	CONTENTVIEW_MEMO.targetDiv.css('top',CONTENTVIEW_MEMO.targetY);
	CONTENTVIEW_MEMO.targetDiv.css('left',CONTENTVIEW_MEMO.targetX - ($('#memoWrapper').width() /2 ));
	
	CONTENTVIEW_MEMO.targetDiv.draggable({ handle: "h1" });
	//CONTENTVIEW_MEMO.editJqueryUIDialog();
};

CONTENTVIEW_MEMO.getMemoForEdit = function(){
	var arrTemp = ClientData.MemoData();
	var tempEntity = arrTemp[CONTENTVIEW_MEMO.EditIndex];
	$('#txaMemoContent').val(tempEntity.Text);
};

CONTENTVIEW_MEMO.editMemoFunction = function(){
	var arrTemp = ClientData.MemoData();
	var tempEntity = arrTemp[CONTENTVIEW_MEMO.EditIndex];

	var editContent = $('#txaMemoContent').val();
	
	tempEntity.Text = editContent;	
	//=== Start Function : No.17    Editor : Long   Date: 07/30/2013   Summary : Set UTC time when edit memo.
	tempEntity.registerDate = new Date();	
	//=== End Function : No.17    Editor : Long   Date: 07/30/2013   Summary : Set UTC time when edit memo.
	arrTemp[CONTENTVIEW_MEMO.EditIndex] = tempEntity;
	ClientData.MemoData(arrTemp);
	
	if(CONTENTVIEW_MEMO.memoCallbackFunc){
		CONTENTVIEW_MEMO.memoCallbackFunc();
	}	
	
	/*refresh memo*/																	
	//CONTENTVIEW.drawCanvas();	
};

CONTENTVIEW_MEMO.buttonSaveFunction = function(){
	
	if(CONTENTVIEW_MEMO.saveMode == 'Edit'){
		CONTENTVIEW_MEMO.editMemoFunction();
	}
	else if(CONTENTVIEW_MEMO.saveMode == 'New'){
		CONTENTVIEW_MEMO.memoSaveFunction();
	}else if(CONTENTVIEW_MEMO.saveMode == 'Copy'){
		CONTENTVIEW_MEMO.memoSaveFunction();
	}
	//CONTENTVIEW_MEMO.targetDiv.dialog('close');
	$("#overlay").hide();
	CONTENTVIEW_MEMO.targetDiv.children().remove();
	CONTENTVIEW_MEMO.targetDiv.hide();
	
	CONTENTVIEW_GENERAL.isCopyMemo = false;
	$("#pop_up_memo").hide();
	
	/* enable controls after finish copy */
	CONTENTVIEW.enableControlsCopyMemo();	
};

//未使用
CONTENTVIEW_MEMO.editJqueryUIDialog = function(){
	$('.ui-dialog-titlebar').hide();
	CONTENTVIEW_MEMO.targetDiv.addClass('memoDialogImportantCss');
	CONTENTVIEW_MEMO.targetDiv.parent().addClass('parentMemoDialogImportantCss');
};

$(function () {
	//CONTENTVIEW_MEMO.ready();
});

CONTENTVIEW_MEMO.ready = function(){
	
	CONTENTVIEW_MEMO.targetDiv = undefined;
	CONTENTVIEW_MEMO.targetX = undefined;
	CONTENTVIEW_MEMO.targetY = undefined;
	CONTENTVIEW_MEMO.EditIndex = undefined;
	CONTENTVIEW_MEMO.saveMode = undefined;
	CONTENTVIEW_MEMO.memoCallbackFunc = undefined;
	CONTENTVIEW_MEMO.conid = undefined;
	CONTENTVIEW_MEMO.pageid = undefined;
	
};