<div class="ibox-content">
	<span class=""><a href="javascript:void(0)" onclick="$('.attachment').slideToggle(300);"><i
				class="fa fa-paperclip"></i> <span id="attachment-count">0</span> attachments</a> </span>
	<div class="attachment">
		<div id="list-attachment"></div>
		<div id="attachment-action" style="display:none">
			<button type="button" onclick="showModalAttachment()" class="btn btn-xs"><i class="fa fa-cloud-upload"></i>&nbsp;Upload Attachment</button>
			<button type="button" onclick="showQrAttachment()" class="btn btn-xs hidden"><i class="fa fa-qrcode"></i>&nbsp;Upload via mobile</button>
		</div>
	</div>
</div>
<script>
	var attachment_timer;
	$(document).ready(function () {
		// refreshAttachment();
		listAttachment();
    // if (!attachment_timer) {
		// 	attachment_timer = setInterval(function(){listAttachment();}, 10000); 
    // }
		var is_edit_detail = $('#is_edit_detail').val();
		if(is_edit_detail)
		$('#attachment-action').show();
	});

	function showModalAttachment() {
		var pk_data = $('.pk_data').val();
		if (pk_data == '')
			alert('Upload attachment belum di setting');
		pk_data = encode(pk_data);
		modalView({
			url: 'main/upload/modal?key=' + pk_data + '&ism=1&',
			title: 'add attachment',
			subtitle: 'upload file'
		});
	}

	function showQrAttachment() {
		var pk_data = $('.pk_data').val();
		if (pk_data == '')
			alert('Upload attachment belum di setting');
		pk_data = encode(pk_data);
		token = encode('<?=date('h:i:s A', time()+3600)?>');
		modalView({
			url: 'main/upload/qr_scan?key=' + pk_data + '&t=' + token,
			title: 'SCAN QR CODE',
			subtitle: 'Scan untuk upload dari mobile'
		});
	}

	function listAttachment()
	{
		var pk_data = $('.pk_data').val();
		pk_data = encode(pk_data);
		$.ajax({
			type: 'POST',
			url: site_url + "main/attachment/attachment_list",
			dataType: 'html',
			data: {
				transnum_ref: pk_data
			},
			success: function(result) {
				$('#list-attachment').html(result);
			}
		});
	}
</script>
<div class="row">
	<div id="attachment-data"></div>
</div>