contentview_Memo.js 5.98 KB
Newer Older
Motohisa Nakano committed
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
var targetDiv;
var targetX;
var targetY;
var targetMemoId;
var EditIndex;
var saveMode;
var memoCallbackFunc;
var conid;
var pageid;

function createMemoDialog(){
	targetDiv.show();
	targetDiv.html('');
	targetDiv.append(
	'<aside id="memoWrapper" class="MemoIndexBox">'
	+ '	<h1 class="indexBoxHd">' + i18nText('txtMemo')
	+'		<a 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">' + i18nText('dspCancel') + '</a>'
	+ '			<a id="Memo_btnDel" style="float:right" class="lang cancelbtn" lang="dspDelete">' + i18nText('dspDelete') + '</a>'
	+ '			<a id="Memo_btnSave" style="float:right" class="lang cancelbtn" lang="dspSave">' + i18nText('dspSave') + '</a>'
	+'		</div>'
	+'	</div>'
	+'</aside>');
	
	$('#txaMemoContent').focus();
	
	handleMemoEventFunction();
};

function handleMemoEventFunction(){
	$('#Memo_btnSave').click(buttonSaveFunction);
	$('#Memo_btnDel').click(MemoDelFunction);
	$('#Memo_btnCancel').click(MemoCancelFunction);
	$('.delete').click(MemoCancelFunction);
};

function memoSaveFunction(){

	var tempArr = [];	
	
	var memoObj = new MemoEntity();
	memoObj.pageNo = pageid;
	memoObj.contentid = conid;
	memoObj.Text = $('#txaMemoContent').val();
	var imagePt = screenToImage(targetX, targetY);
	memoObj.posX = imagePt.x;
	memoObj.posY = imagePt.y;
	
	tempArr = ClientData.MemoData();	
	tempArr.push(memoObj);	
	ClientData.MemoData(tempArr);
	
	if(memoCallbackFunc){
		memoCallbackFunc();
	}
};

function MemoDelFunction(){	
	if(saveMode == 'Copy'){
		//targetDiv.dialog('close');
		targetDiv.fadeOut('medium', function(){
			
		});
		
		isCopyMemo = false;
	}
	else{
		var resultArr = ClientData.MemoData();
		resultArr.splice(EditIndex, 1);
		
		ClientData.MemoData(resultArr);
	
		//targetDiv.dialog('close');	
		if(memoCallbackFunc){				
			memoCallbackFunc();
		}
	}
	$("#overlay").hide();
	targetDiv.children().remove();
	targetDiv.hide();
	
	$("#pop_up_memo").hide();
	
	/* draw again */
	drawCanvas();	
	
	/* enable controls after finish copy */
	enableControlsCopyMemo();	
};

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

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

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

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

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

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

	var editContent = $('#txaMemoContent').val();
	
	tempEntity.Text = editContent;	
	
	arrTemp[EditIndex] = tempEntity;
	ClientData.MemoData(arrTemp);
	
	if(memoCallbackFunc){
		memoCallbackFunc();
	}	
	
	/*refresh memo*/																	
	//drawCanvas();	
};

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

function editJqueryUIDialog(){
	$('.ui-dialog-titlebar').hide();
	targetDiv.addClass('memoDialogImportantCss');
	targetDiv.parent().addClass('parentMemoDialogImportantCss');
};