<%@ include file="/project/include.jsp" %>	

<script type="text/javascript">
	function onChangeTranscodeId() {
		var transcodeCombo = document.getElementById('id_transcode');
		var transcodeId = transcodeCombo.options[transcodeCombo.selectedIndex].value;
		
		loadStandardSelectOptionsAndFill('id_type', 
				'it.cedaf.icare.configurazioni.control.binding.requestbean.valuesetproviders.TipoEntryValueSetProvider(transcodeId)', 
				'transcodeId=' + transcodeId, '');
	}

	function showImportTranscodeEntriesDialog() {
		var rec = getClientAreaRectangle().resize(500, 200, HORIZONTAL_CENTER | VERTICAL_CENTER);
		var buttons = [
   			{ 'img'		: juiceGetResource('shell', 'img/misc/confirm-small.gif'),
   			  'text'	: 'Importa',
   			  'onclick'	: 
   			  	function() { 
   					importTranscodeEntries();
   				}
   			}
   		];
   		showDivModal('idImportTranscode', 'Importa transcode entries', rec, true, false, buttons);		
	}

	function importTranscodeEntries(warningConfirmed) {
		var transcodeId = document.getElementById('id_import_transcodeId').value;		
		if (!transcodeId) {
			alert('Inserire un transcode id per effettuare l\'import.');
			return;			
		}
		var nomeExcel = document.getElementById('id_nome_excel').value;		
		if (!nomeExcel) {
			alert('Selezionare un file excel da importare.');
			return;			
		}
		var params = 'transcodeId=' + transcodeId;
		if (warningConfirmed) {
			params += '&warn=true';
		}
		jsLoadString('it.cedaf.icare.configurazioni.control.action.ImportTranscodeEntryExecutor', params, 'importTranscodeEntriesHandler');
	}

	function importTranscodeEntriesHandler(value){
		if (value == 'OK') {	
			hideModal('idImportTranscode');	
			buiView();		
		} else if (value == 'WARN_ID_ESISTENTE') {
			if (confirm('Attenzione! Il transcode id specificato � gi� presente nel sistema, importandolo nuovamente si andranno a sovrascrivere i types specificati. Si � sicuri di voler continuare?')) {
				importTranscodeEntries(true);
			}
		} else if (value == 'ERROR') {
			alert('Si � verificato un errore nell\'importazione del file specificato.');
		}
	}

	function caricaFile() {				
		shellFileUploadDialog(
			'it.cedaf.icare.configurazioni.control.action.TranscodeEntriesFileUploadExecutor', 
			'Scegliere il file...', 
			"Seleziona l'Excel che si intende importare:");	
	}

	function onUploadFile(fileName) {
		document.getElementById('id_nome_excel').value = fileName;
		if (fileName != null) {
			var transcodeId = fileName;
			var index = transcodeId.lastIndexOf('.');
			if (index != -1)
				transcodeId = transcodeId.substring(0, index);
			if (transcodeId != 'transcodeEntries')
				document.getElementById('id_import_transcodeId').value = transcodeId;
		}
    }

	function showCreateTranscodeEntriesDialog() {
		var rec = getClientAreaRectangle().resize(500, 200, HORIZONTAL_CENTER | VERTICAL_CENTER);
		var buttons = [
   			{ 'img'		: juiceGetResource('shell', 'img/misc/confirm-small.gif'),
   			  'text'	: 'Crea',
   			  'onclick'	: 
   			  	function() { 
   					createTranscodeEntries();
   				}
   			}
   		];
   		showDivModal('idCreateTranscode', 'Crea', rec, true, false, buttons);		
	}

	function createTranscodeEntries() {
		var transcodeId = document.getElementById('id_create_transcodeId').value;		
		if (!transcodeId) {
			alert('Inserire un transcode id per procedere alla creazione di nuove transcode entries.');
			return;			
		}
		var params = 'transcodeId=' + transcodeId;
		var transcodeType = document.getElementById('id_create_transcodeType').value;		
		if (transcodeType) {
			params += '&transcodeType=' + transcodeType;			
		}
		var event = 'configurazioni.createTranscodeEntries?' + params;
		juiceChangeLocation(event);
	}
</script>
	
<shell:fieldset title="Informazioni generali">
	<table border="0" cellpadding="0" cellspacing="3" width="100%">	   		
        <tr>
        	<td class="form-label">
				<shell:label prop="transcodeId" />
			</td>
        	<td class="form-values">
				<j:bind prop="transcodeId">
					<j:select class="form-input" id="id_transcode" emptyOptionDescr=" " onChange="javascript:onChangeTranscodeId();"/>
					<shell:error />
				</j:bind>
			</td>
		</tr>
		<tr>
        	<td class="form-label">
				<shell:label prop="type" />
			</td>
        	<td class="form-values">
				<j:bind prop="type">
					<j:select class="form-input" id="id_type" emptyOptionDescr=" "/>
					<shell:error />
				</j:bind>
			</td>
		</tr>
    </table>
</shell:fieldset>

<div id="idImportTranscode" class="modalElement">
	<table width="100%" style="padding: 4px 4px 4px 4px;">
		<tr>
			<td class="form-label">
				${j:bundle('LBL_configurazioni_transcodeEntry_transcodeId')}
			</td>
			<td class="form-values">
				<input type="text" id="id_import_transcodeId" class="form-normal-text">
			</td>
		</tr>
		<tr>
			<td class="form-label">
				${j:bundle('LBL_configurazioni_transcodeEntry_file')}
			</td>
			<td class="form-values">
				<input type="text" id="id_nome_excel" class="form-normal-text" readonly>
				<shell:button img="documentiallegati.browse" text="Seleziona..." title="Seleziona il file a partire dal computer locale" href="javascript:caricaFile();" />
			</td>
		</tr>
	</table>
</div>

<div id="idCreateTranscode" class="modalElement">
	<table width="100%" style="padding: 4px 4px 4px 4px;">
		<tr>
			<td class="form-label">
				${j:bundle('LBL_configurazioni_transcodeEntry_transcodeId')}
			</td>
			<td class="form-values">
				<input type="text" id="id_create_transcodeId" class="form-normal-text">
			</td>
		</tr>
		<tr>
			<td class="form-label">
				${j:bundle('LBL_configurazioni_transcodeEntry_type')}
			</td>
			<td class="form-values">
				<input type="text" id="id_create_transcodeType" class="form-normal-text">
			</td>
		</tr>
	</table>
</div>