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

<script type="text/javascript">	
	function scaricaFile(slave) {
		var idDocumento;
		if (slave) {
			idDocumento = cpGetSlaveColumnValueOfCurrentRow(slave, 'id');
		} else {
			idDocumento = cpGetMasterColumnValueOfCurrentRow('id');
		}		
		if (idDocumento != '') {
			downloadDocAllegato(idDocumento);
		}
	}
	
	function allegaFile() {				
		shellFileUploadDialog(
			'it.cedaf.icare.documentiallegati.control.action.AllegaDocumentoExecutor', 
			$BundleHandler.getBundle('LBL_documentiallegati_documentoAllegato_selFileTitle', null), 
			$BundleHandler.getBundle('LBL_documentiallegati_documentoAllegato_selFileLabel', null));		
	}
	
	function onUploadFile(fileName) {
		document.getElementById('idNomeAllegato').value = fileName;	
		shellSetBuiFormAsChanged();	
    }	
    
    function gestioneDocumento(newDoc, noSogg) {   	
    	var event = "documentiallegati.vaiAGestioneDocumenti?newDoc=" + newDoc + shellGetSelectedRowParam() + shellGetSelectedTabParam();
    	if (noSogg) {
    		event = event + "&noSogg=true";
    	}
		juiceChangeLocation(event);		
    }
    
    function gestioneDocumentoNucleo() {  
    	var idNucleo = cpGetMasterColumnValueOfCurrentRow('id');	
    	var event = "documentiallegati.vaiAGestioneDocumentiNucleo?idNucleo=" + idNucleo + shellGetSelectedRowParam() + shellGetSelectedTabParam();
		juiceChangeLocation(event);		
    }
    
    function eformat_cpmt_nomeAllegato(element, value, name) {
    	var button = document.getElementById('idButtonDownload');
    	if(button) button.style.display= (value == '' ? 'none' : 'inline');
		element.innerHTML = value;			
	}
	
	function eformat_cpst_${_slave}_nomeAllegato(element, value, name) {
		var button = document.getElementById('idButtonDownload');
    	if(button) button.style.display= (value == '' ? 'none' : 'inline');
		element.innerHTML = value;
	}
    
	function importAllegati() {
		var event = 'documentiallegati.prepareSearchProtocollo';
		var rec = getClientAreaRectangle().resize(980, 620, HORIZONTAL_CENTER | VERTICAL_CENTER);
		showIFrameModalByEvent('importAllegati', $BundleHandler.getBundle('LBL_importAllegatiDialogTitle', null), event, rec, true, false, null);	
	}
	
	function closeImportAllegatiDialog() {
		hideModal('importAllegati');
	}
	
</script>

<c:if test="${!empty _slave}">
	<bui:out modes="view">
		<j:tile slave="${_slave}" name="shell.slaveToolbar" />
	</bui:out>
	
	<shell:grid description="dataCollocazione,20%; oggetto,40%; autore,40%" slave="${_slave}" />
</c:if>

<c:if test="${empty _slave}">
	<bui:out modes="view">
		<script type="text/javascript">	
			function eformat_cpmt_nominativoSoggetto(element, value, name) {
				linkToSoggetto('idSoggetto', element, value);			
			}
		</script>
	</bui:out>	
	<c:choose>
		<c:when test="${empty dto_soggetto_lock && empty dto_nucleo_lock && empty dto_no_sogg}">
			<shell:fieldset title="${j:bundle('LBL_documentiallegati_documentoAllegato_infoSogg_SET')}">
				<table border="0" cellpadding="0" cellspacing="3" width="100%">   		
			        <tr>
						<td class="form-label">
							<shell:label prop="idSoggetto" />
						</td>
						<td class="form-values">	
							<c:choose>
								<c:when test="${bui:isMode(null, 'record_created')}">
									<j:bind prop="nominativoSoggetto">
										<j:text class="form-normal-text" readonly="true" id="nominativo_documentoLookup" />
									</j:bind>
								  	<j:bind prop="idSoggetto">
										<j:hidden id="id_documentoLookup"/>
										<shell:error />
									</j:bind>
									<c:if test="${empty nascondiLookup || nascondiLookup == 'false'}">
										<shell:lookup lookupId="documentoLookup" identifier="anagrafiche.soggetto" 
											init="it.cedaf.icare.anagrafiche.model.datamanagement.SoggettoLookupInitializer" 
											params="onlySearch=true&disableComplete=true&importNucleo=false" 
											noCommitOnCreate="id=-1" />
									</c:if>
								</c:when>
								<c:otherwise>
									<j:tile name="shell.plaintext" prop="nominativoSoggetto" />
								</c:otherwise>
							</c:choose>						
						</td>
					</tr>
					<tr>
						<td class="form-label">
							<shell:label prop="cartella" />
						</td>
						<td class="form-values">
							<j:tile name="shell.plaintext" prop="cartella" />
						</td>
					</tr>
				</table>
			</shell:fieldset>		
		</c:when>
		<c:otherwise>
			<c:if test="${bui:isMode(null, 'record_created')}">
				<j:bind prop="idSoggetto">
					<j:hidden id="id_documentoLookup"/>
				</j:bind>
			</c:if>		
		</c:otherwise>
	</c:choose>
	
</c:if>

<shell:fieldset title="${j:bundle('LBL_documentiallegati_documentoAllegato_infoPrinc_SET')}">
	<table>
		<tr>   
      		<td class="form-label">
    			<shell:label prop="icaroCode" />
    		</td>
    		<td class="form-values">
				<j:tile slave="${_slave}" name="shell.plaintext" prop="icaroCode" />
			</td> 
	  	</tr>
		<tr>   
      		<td class="form-label">
    			<shell:label prop="dataCollocazione" />
    		</td>
    		<bui:out modes="view">   
		  		<td class="form-values">
					<j:tile slave="${_slave}" name="shell.plaintext" prop="dataCollocazione" />
				</td>
			</bui:out>
			<bui:out slave="${_slave}" modes="update,create">
			    <j:bind prop="dataCollocazione">						
					<td class="form-values">
						<j:text class="form-date" id="dataCollocazioneCLD" onChange="getOperatoriRiferimento();" />
						<shell:calendar inputId="dataCollocazioneCLD" />	
						<shell:error />
					</td>
				</j:bind>
		   	</bui:out> 
	  	</tr>
	  	<tr>   
	      	<td class="form-label">
	    		<shell:label prop="autore" />
    		</td>
    		<bui:out modes="view">   
		  		<td class="form-values">
					<j:tile slave="${_slave}" name="shell.plaintext" prop="autore" />
				</td>
			</bui:out>
			<bui:out slave="${_slave}" modes="update,create">
			    <j:bind prop="autore">
					<td class="form-values">
						<j:text class="form-long-text"/>
					    <shell:error />
					</td>
				</j:bind>
		   	</bui:out> 
	  	</tr>	
	  	<tr>   
	      	<td class="form-label">
	    		<shell:label prop="oggetto" />
    		</td>
    		<bui:out modes="view">   
		  		<td class="form-values">
					<j:tile slave="${_slave}" name="shell.plaintext" prop="oggetto" />
				</td>
			</bui:out>
			<bui:out slave="${_slave}" modes="update,create">
			    <j:bind prop="oggetto">
					<td class="form-values">
						<j:text class="form-long-text"/>
					    <shell:error />
					</td>
				</j:bind>
		   	</bui:out> 
	  	</tr>
	    <tr>   
	      	<td class="form-label">
	    		<shell:label prop="nomeAllegato" />
    		</td>
    		<bui:out modes="view">   
		  		<td class="form-values">
					<j:tile slave="${_slave}" name="shell.plaintext" prop="nomeAllegato" />&nbsp;&nbsp;
					<c:if test="${bui_tableInfos.numRows > 0}"><shell:button id="idButtonDownload" img="documentiallegati.download" text="${j:bundle('LBL_documentiallegati_documentoAllegato_download_BUTTON')}" href="javascript:scaricaFile('${_slave}');" /></c:if>													
				</td>
			</bui:out>
			<bui:out slave="${_slave}" modes="update,create">
			    <j:bind prop="nomeAllegato">
					<td class="form-values">
						<j:text class="form-normal-text" id="idNomeAllegato" readonly="true"/>
					    <shell:error />
					    <shell:button img="documentiallegati.browse" text="${j:bundle('LBL_selezionaDocumento_BUTTON')}" title="${j:bundle('LBL_selezionaDocumento_TOOLTIP')}" href="javascript:allegaFile();" />
					</td>
				</j:bind>
		   	</bui:out> 
	  	</tr>	
	  	<bui:out modes="view">
	  		<tr>
	  			<td class="form-label">
	  				<shell:label prop="dimensione" />
	  			</td>
	  			<td class="form-values">
	  				<j:tile slave="${_slave}" name="shell.plaintext" prop="dimensione" />
	  			</td>
	  		</tr>
	  	</bui:out>  	
	</table>
</shell:fieldset>	
		
<table border="0" cellpadding="0" cellspacing="3" width="100%">
	<tr>
		<td valign="top" width="50%">	        	       	
			<shell:fieldset title="${j:bundle('LBL_documentiallegati_documentoAllegato_infoDoc_SET')}">
				<table border="0" cellpadding="0" cellspacing="3">			  		
				  	<tr>   
				      	<td class="form-label">
			    			<shell:label prop="tipoDocumento" />
			    		</td>
			    		<bui:out modes="view">   
						  	<td class="form-values">
								<j:tile slave="${_slave}" name="shell.plaintext" prop="tipoDocumento" />
							</td>
						</bui:out>
						<bui:out slave="${_slave}" modes="update,create">
						    <j:bind prop="tipoDocumento">
								<td class="form-values">
									<j:select class="form-input" emptyOptionDescr=" "/> 
								    <shell:error />
								</td>
							</j:bind>
					   	</bui:out> 
					</tr>
					<tr>   
				      	<td class="form-label">
				    		<shell:label prop="numero" />
			    		</td>
			    		<bui:out modes="view">   
					  		<td class="form-values">
								<j:tile slave="${_slave}" name="shell.plaintext" prop="numero" />
							</td>
						</bui:out>
						<bui:out slave="${_slave}" modes="update,create">
						    <j:bind prop="numero">
								<td class="form-values">
									<j:text class="form-normal-text" maxlength="100"/>
								    <shell:error />
								</td>
							</j:bind>
					   	</bui:out> 
				  	</tr>	
				  	<c:if test="${empty dto_buono_attivazione}">
				  	<tr>   
				      	<td class="form-label">
				    		<shell:label prop="visibilita" />
			    		</td>
			    		<bui:out modes="view">   
					  		<td class="form-values">
								<j:tile slave="${_slave}" name="shell.plaintext" prop="visibilita" />
							</td>
						</bui:out>
						<bui:out slave="${_slave}" modes="update,create">
						    <j:bind prop="visibilita">
								<td class="form-values">
									<j:valueSetIterator>
										<j:radio /> ${j:getValueSetItem().description}<br/>
									</j:valueSetIterator>
								    <shell:error />
								</td>
							</j:bind>
					   	</bui:out> 
				  	</tr>	  	
				  	</c:if>	
				</table>
			</shell:fieldset>
		</td>
		<c:if test="${empty dto_ente_logged || dto_ente_logged == 'false'}">
			<c:if test="${empty _slave}">
			<td valign="top" width="50%">
				<shell:fieldset title="${j:bundle('LBL_documentiallegati_documentoAllegato_infoOper_SET')}">
					<table border="0" cellpadding="0" cellspacing="3">
						<j:tile name="commons.opRifNonStoricizzato"/>
						<j:tile name="commons.opAbilitato" objectName="DocumentoAllegato" idField="id"/>
					</table>
				</shell:fieldset>
			</td>
			</c:if>
		</c:if>
	</tr>
</table>

<shell:fieldset title="${j:bundle('LBL_documentiallegati_documentoAllegato_infoProt_SET')}">		
	<c:choose>
		<c:when test="${!empty _slave || (!empty protocolloNonModificabile && protocolloNonModificabile == 'true') || (!empty dto_buono_attivazione)}">
			<table border="0" cellpadding="0" cellspacing="3" width="100%">
				 <tr>
					<td class="form-label">
						<shell:label prop="numeroProtocollo" />
					</td>
					<td class="form-values">
						<j:tile slave="${_slave}" name="shell.plaintext" prop="numeroProtocollo" />
					</td>
				</tr>
				<tr>
					<td class="form-label">
						<shell:label prop="dataProtocollo" />
					</td>
					<td class="form-values">
						<j:tile slave="${_slave}" name="shell.plaintext" prop="dataProtocollo" />
					</td>
				</tr>
			</table>
			</td><td valign="top">
			<table border="0" cellpadding="0" cellspacing="3" width="100%">
				 <tr>
					<td class="form-label">
						<shell:label prop="classificaProtocollo" />
					</td>
					<td class="form-values">
						<j:tile slave="${_slave}" name="shell.plaintext" prop="classificaProtocollo" />
					</td>
				</tr>
				<tr>
					<td class="form-label">
						<shell:label prop="fascicoloProtocollo" />
					</td>
					<td class="form-values">
						<j:tile slave="${_slave}" name="shell.plaintext" prop="fascicoloProtocollo" />
					</td>
				</tr>
			</table>
		</c:when>
		<c:otherwise>
			<table border="0" cellpadding="0" cellspacing="3" width="100%">
				<tr>
					<td class="form-label">
						<shell:label prop="numeroProtocollo" />
					</td>
					<td class="form-values">
						<bui:out modes="view">
							<j:tile name="shell.plaintext" prop="numeroProtocollo" />
						</bui:out>
						<bui:out modes="create, update">
							<j:bind prop="numeroProtocollo">
								<j:text class="form-normal-text" />
								<shell:error />
							</j:bind>
						</bui:out>
					</td>						
				</tr>
				<tr>
					<td class="form-label">
						<shell:label prop="dataProtocollo" />
					</td>
					<td class="form-values">
						<bui:out modes="view">
							<j:tile name="shell.plaintext" prop="dataProtocollo" />
						</bui:out>
						<bui:out modes="create, update">
							<j:bind prop="dataProtocollo">
								<j:text class="form-date" id="dataProtocolloCLD" />
								<shell:calendar inputId="dataProtocolloCLD" />
								<shell:error />
							</j:bind>
						</bui:out>
					</td>						
				</tr>
				<tr>
					<td>
						&nbsp;
					</td>
					<td class="form-values">
						<j:tile name="commons.protocollazione" protContext="DO_A" />
					</td>					
				</tr>
			</table>
			</td><td valign="top">
			<table border="0" cellpadding="0" cellspacing="3" width="100%">
				<tr>
					<td class="form-label">
						<shell:label prop="classificaProtocollo" />
					</td>
					<td class="form-values">
						<bui:out modes="view">
							<j:tile name="shell.plaintext" prop="classificaProtocollo" />
						</bui:out>
						<bui:out modes="create, update">
							<j:bind prop="classificaProtocollo">
								<j:text class="form-normal-text" />
								<shell:error />
							</j:bind>
						</bui:out>
					</td>						
				</tr>
				<tr>
					<td class="form-label">
						<shell:label prop="fascicoloProtocollo" />
					</td>
					<td class="form-values">
						<bui:out modes="view">
							<j:tile name="shell.plaintext" prop="fascicoloProtocollo" />
						</bui:out>
						<bui:out modes="create, update">
							<j:bind prop="fascicoloProtocollo">
								<j:text class="form-normal-text" />
								<shell:error />
							</j:bind>
						</bui:out>
					</td>						
				</tr>
			</table>
		</c:otherwise>		
	</c:choose>	
</shell:fieldset>
			

<c:if test="${empty dto_buono_attivazione}">
<shell:fieldset title="${j:bundle('LBL_documentiallegati_documentoAllegato_infoAgg_SET')}">
	<table>
	<c:choose>
		<c:when test="${empty dto_ente_logged || dto_ente_logged == 'false'}">	
			<icare:ifOptional prop="Periodo di riferimento [p]">
				<tr>
					<td class="form-label">
						<shell:label prop="periodoRiferimento" />
					</td>
					<bui:out modes="view">   
				 	<td class="form-values">
						${j:bundle('LBL_ricercaDa')}<j:tile slave="${_slave}" name="shell.plaintext" prop="periodoRiferimentoDa" />
						a:<j:tile slave="${_slave}" name="shell.plaintext" prop="periodoRiferimentoA" />
					</td>
					</bui:out>
					<bui:out slave="${_slave}" modes="update,create">
					<td class="form-values">
						${j:bundle('LBL_ricercaDa')} 
						<j:bind prop="periodoRiferimentoDa">
							<j:text class="form-date" id="periodoRiferimentoDaCLD" />
							<shell:calendar inputId="periodoRiferimentoDaCLD" />				
							<shell:error />
						</j:bind>					
						a:
						<j:bind prop="periodoRiferimentoA">
							<j:text class="form-date" id="periodoRiferimentoACLD" />
							<shell:calendar inputId="periodoRiferimentoACLD" />					
							<shell:error />
						</j:bind>
					</td>
					</bui:out>
				</tr>
			</icare:ifOptional>	
		</c:when>
		<c:otherwise>
			<tr>
				<td class="form-label">
					<shell:label prop="periodoRiferimento" />
				</td>
				<bui:out modes="view">   
			 	<td class="form-values">
					${j:bundle('LBL_ricercaDa')}<j:tile slave="${_slave}" name="shell.plaintext" prop="periodoRiferimentoDa" />
					a:<j:tile slave="${_slave}" name="shell.plaintext" prop="periodoRiferimentoA" />
				</td>
				</bui:out>
				<bui:out slave="${_slave}" modes="update,create">
				<td class="form-values">
					${j:bundle('LBL_ricercaDa')} 
					<j:bind prop="periodoRiferimentoDa">
						<j:text class="form-date" id="periodoRiferimentoDaCLD" />
						<shell:calendar inputId="periodoRiferimentoDaCLD" />				
						<shell:error />
					</j:bind>					
					a:
					<j:bind prop="periodoRiferimentoA">
						<j:text class="form-date" id="periodoRiferimentoACLD" />
						<shell:calendar inputId="periodoRiferimentoACLD" />					
						<shell:error />
					</j:bind>
				</td>
				</bui:out>
			</tr>
		</c:otherwise>
	</c:choose>
	<c:if test="${empty dto_ente_logged || dto_ente_logged == 'false'}">
		<tr>   
	  		<td class="form-label">
				<shell:label prop="note" />
	    	</td>
		    <bui:out modes="view">   
			 	<td class="form-values">
					<j:tile slave="${_slave}" name="shell.plaintext" prop="note" />
				</td>
			</bui:out>
			<bui:out slave="${_slave}" modes="update,create">
			    <j:bind prop="note">
					<td class="form-values">
						<j:textarea class="form-long-textarea" />
						<shell:error />
					</td>
				</j:bind>
			</bui:out> 
		</tr>
		</c:if>
	</table>
</shell:fieldset>
</c:if>