<%@ include file="/project/include.jsp" %>	
<script type="text/javascript">
	function prepareToCreateTranscode() {
		var dataRif = document.getElementById('dataInizioCLD').value;
		var tipo = getComboValueById('selectTipo');
		
		if (dataRif == '') {
			alert('Inserire la data di riferimento.');
			return;
		}
		dataRif = completeDateString(dataRif);				
		if (dataRif == null) {
			alert('Inserire una data nel formato: gg/mm/aaaa.');
			return;			
		}
		if (tipo == '') {
			alert('Scegliere il tipo di nomenclatore.');
			return;
		}
		
		params = 'dataRif=' + dataRif + '&tipo=' + tipo;
		buiPrepareToCreate(-1, params);
	}
	
	function exportTranscodeIass() {
		juiceDownload('it.cedaf.icare.iass.etc.ExportTranscodeIassFileContentProvider');
	}
	
	function exportConfigurazioneIass() {
		juiceDownload('it.cedaf.icare.iass.etc.ExportConfigurationIassFileContentProvider');
	}
	
	function importConfigurazioneIass() {
		if(confirm('Attenzione. Importando una nuova configurazione, la precedente verr� completamente eliminata.\nContinuare?')) {
			shellFileUploadDialog(
				'it.cedaf.icare.iass.control.action.ImportConfigurazioneFileUploadExecutor', 
				'Scegliere il file...', 
				"Seleziona il file xml che si intende importare:", 
				'importaConfigurazione');
		}
	
		
	}
	
	function importaConfigurazione() {
    	jsLoadMap('it.cedaf.icare.iass.control.action.ImportConfigurazioniExecutor', null, 'importConfigurazioniHandler', JS_SYNC);
    }
    
    function importConfigurazioniHandler(map){
		var result = map.get('result');
		var log = "";
		if (result == 'OK') {
			document.getElementById('idTrOk').style.display = '';
			document.getElementById('idTrErrore').style.display = 'none';
			var nrImport = map.get('nrImport');
			log = 'Importati ' + nrImport + ' records.';
			document.getElementById('txtLog').value = log;
		} else {
			document.getElementById('msgErrore').innerHTML = result;
			document.getElementById('idTrOk').style.display = 'none';
			document.getElementById('idTrErrore').style.display = '';
			log = 'Elenco problemi: \n';
			var nrLine = map.get('nrLine');
			if (nrLine > 0) {
				for (var i = 0; i < nrLine; i++ ) {
					log += ' - ' + map.get('line_' + i) + '\n';
				}
				document.getElementById('txtLog').value = log;
			} else {
				document.getElementById('txtLog').value = '';
			}
		}
				
		var rec = getClientAreaRectangle().resize(500, 350, HORIZONTAL_CENTER | VERTICAL_CENTER);
		var buttons = [
   			{ 'img'		: juiceGetResource('shell', 'img/misc/confirm-small.gif'),
   			  'text'	: 'Chiudi',
   			  'onclick'	: 
   			  	function() { 
   					hideModal('idImportConfigurazioniResult');
   				}
   			}
   		];
   		showDivModal('idImportConfigurazioniResult', 'Importazione configurazione', rec, true, false, buttons);		
	}
	
	function verifyIassTranscode() {
		shellDownload('it.cedaf.icare.iass.etc.ControlloTranscodeFileContentProvider');
	}
	
</script>

<div id="idImportConfigurazioniResult" class="modalElement">
	<table width="100%" style="padding: 4px 4px 4px 4px;">
		<tr id="idTrErrore" style="display:none;">
			<td class="form-label">
				<span id="msgErrore"/>
			</td>			
		</tr>
		<tr id="idTrOk" style="display:none;">
			<td class="form-label">
				Importazione terminata correttamente.
			</td>
		</tr>
		<tr>
			<td class="form-values">
				<textarea id="txtLog" rows="12" cols="60" readonly>
				</textarea>
			</td>
		</tr>		
	</table>
</div>

<shell:fieldset title="Parametri di ricerca">
	<table border="0" cellpadding="0" cellspacing="3">
		<tr>
			<td class="form-label">
				<shell:label prop="dataValidita" />
			</td>
			<td class="form-values">
				<j:bind prop="dataValidita">
					<j:text class="form-date" id="dataInizioCLD" />
					<shell:calendar inputId="dataInizioCLD" />
					<shell:error />
				</j:bind>	
			</td>
		</tr>
		<tr>
			<td class="form-label">
				<shell:label prop="tipo" />
			</td>
			<td class="form-values">
				<j:bind prop="tipo">
					<j:select id="selectTipo" class="form-input" emptyOptionDescr=" " />
					<shell:error />
				</j:bind>	
			</td>
		</tr>
	</table>
</shell:fieldset>