{extends file=$smarty.const.SMARTY_REMOTEHTMLVIEW}

{block name="css" append}
<style>
	span.documentType {
		padding-right: 25px;
	}

</style>
{/block}


{block name="content" append}
	{$sectionName='chooseDocument'}

	<div class="content">

		<center>
			<button
				onClick="MVC.documents.documentsManagement('{$idPivot}', '{$pivot}');"

			>{$lang['index']['buttons']['documentsManagement']}</button>
		</center>


			<table class="quickLaunchDocs">
				<thead></thead>
				<tbody>
					{foreach $documentTypesDetails as $documentType => $documentDetails}
						<tr>
							<td><span class="documentType">
								<a class="link" href="#;" {if $documentDetails['issues']['final']['id']}style="font-weight:bold;"{/if}
									onClick="MVC.documents.generate.addDocument({
										'pivot': 			'{$pivot}',
										'idPivot': 			'{$idPivot}',
										'documentType': 	'{$documentType}'
									});"

									tooltip="{$lang['index']['buttons']['linkTooltip']}"
								>{\App\Config\IssueDocuments::getInstance()->getDocTypeName($documentType)}</a>

								{if $documentDetails['issues']['final']['id']}
									<var class="icons icon-info"
										tooltip="
											<div><b>{$lang['index']['tooltips']['issueUser']}</b>: {userLabel ref=$documentDetails['issues']['final']['idAddUser'] hideLink="1"}</div>
											<div><b>{$lang['index']['tooltips']['issueTime']}</b>: {$documentDetails['issues']['final']['issueDateTime']|dateTimeFormat}</div>
										"
									></var>
								{/if}
							</span></td>
							<td class="optionsBox sectionRow">

								<ul class="submenu submenu-depth-0 Simple ">

									{****************** ADD/GENERATE/VIEW *************************************}
									{if $documentDetails['issues']['final']['id']}
										<li class="menuItem"
											onClick="MVC.documents.generate.viewInWindow('{$documentDetails['issues']['final']['id']}', {});"
											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['view']}.</div></div>"{/strip}
										>
											<var class="icon-view"></var>
										</li>
									{else}
										<li class="menuItem"
											onClick="MVC.documents.generate.addDocument({
												'pivot': 			'{$pivot}',
												'idPivot': 			'{$idPivot}',
												'documentType': 	'{$documentType}',
												'postAction':		'generate'
											})";

											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['generate']}.</div></div>"{/strip}
										>
											<var class="icon-add"></var>
										</li>
									{/if}


									{*** PREVIEW/DOWNLOAD/VIEW ***********************************}
									{if $documentDetails['issues']['final']['id']}
										<li class="menuItem"
											onClick="MVC.documents.generate.downloadInWindow('{$documentDetails['issues']['final']['id']}', {});"
											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['downloadAlreadyGenerated']}.</div></div>"{/strip}
										>
											<var class="icon-export"></var>
										</li>

									{elseif $documentDetails['issues']['preview']['id']}
										<li class="menuItem"
											onClick="MVC.documents.generate.viewInWindow('{$documentDetails['issues']['preview']['id']}', {});"
											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['preview']}.</div></div>"{/strip}
										>
											<var class="icon-view"></var>
										</li>
									{else}
										<li class="menuItem"
											onClick="MVC.documents.generate.addDocument({
												'pivot' : 			'{$pivot}',
												'idPivot': 			'{$idPivot}',
												'documentType' : 	'{$documentType}',
												'postAction': 		'preview'
											});"
											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['generatePreview']}.</div></div>"{/strip}
										>
											<var class="icon-preview"></var>
										</li>
									{/if}

									{***************************** PRINT ***************************************************}
									{if $documentDetails['issues']['final']['id']}
										<li class="menuItem"
											onClick="MVC.documents.generate.printInWindow('{$documentDetails['issues']['final']['id']}', {
												docFormat: '{$documentDetails['issues']['final']['fileFormat']}'
											});"

											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['print']}.</div></div>"{/strip}
										>
											<var class="icon-print"></var>
										</li>
									{else}
										<li class="menuItem"
											onClick="MVC.documents.generate.addDocument({
												'pivot' : 			'{$pivot}',
												'idPivot': 			'{$idPivot}',
												'documentType' : 	'{$documentType}',
												'postAction': 		'print'
											});"
											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['printAndGenerate']}.</div></div>"{/strip}
										>
											<var class="icon-print"></var>
										</li>
									{/if}

									{*** EMAIL ***************************************************}
									{if $documentDetails['issues']['final']['id']}
										<li class="menuItem"
											onClick="MVC.documents.generate.sendEmailInWindow('{$documentDetails['issues']['final']['id']}', {
												operation: 'sendEmail'
											});"

											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['sendEmail']}.</div></div>"{/strip}
										>
											<var class="icon-email"></var>

										</li>
									{else}
										<li class="menuItem"
											onClick="MVC.documents.generate.addDocument({
												'pivot' : 			'{$pivot}',
												'idPivot': 			'{$idPivot}',
												'documentType' : 	'{$documentType}',
												'postAction': 		'generate'
											});"

											tooltip={strip}"<div class=' has-description'><div class='description'>{$lang['index']['tooltips']['sendEmailAndGenerate']}.</div></div>"{/strip}
										>
											<var class="icon-email"></var>
										</li>
									{/if}

								</ul>

							</td>
					{/foreach}
				</tbody>
			</table>
		</center>
	</div>

{/block}

{block name="js" append}


	<script type="text/javascript">

		MVC.documents = { };

		/********** DOCUMENTS MANAGEMENT OPTIONS ********/
		MVC.documents.documentsManagement = function(idPivot, pivot)
		{
			Popup2
				.create()
				.setId('Documents/Generate/GenerateDocument')
				.setUrl(MVC.appUrl('Documents/Generate', 'index', { 'pivot': pivot, 'idPivot': idPivot} ))
				.setDimensions(800, 500)
				.show();
		}

		/******************* GENERATE DOCUMENTS **************/
		MVC.documents.generate = { };

		/************ ADD NEW DOCUMENT ***************/
		MVC.documents.generate.addDocument = function(params)
		{
			Popup2
				.create()
				.setId('Documents/Generate/GenerateDocument')
				.setUrl(MVC.appUrl('Documents/Generate/GenerateDocument', 'index', params))
				.setDimensions(800, 500)
				.show();
		}

		/***************** VIEW DOCUMENT ********************************/
		MVC.documents.generate.viewInWindow = function(idDocument, params)
		{
			params = (params?params:{ });
			MVC.documents.generate._openInWindow('view', idDocument, params);
		}

		/****************** DOWNLOAD DOCUMENT ***************************/
		MVC.documents.generate.downloadInWindow = function(idDocument, params)
		{
			params = (params?params:{ });
			MVC.documents.generate._openInWindow('download', idDocument, params);
		}

		/****************** PRINT DOCUMENT *******************************/
		MVC.documents.generate.printInWindow = function(idDocument, params)
		{
			MVC.documents.generate._openInWindow('print', idDocument, params);
		}

		/*********************** SEND DOCUMENT VIA EMAIL ***************************/
		MVC.documents.generate.sendEmailInWindow = function(idDocument)
		{
			Popup2.create().setId('Documents/Generate/Email/SendEmail').setUrl(MVC.appUrl('Documents/Generate/Email/SendEmail', 'index', { 'idDocument': idDocument} )).setDimensions(800, 500).show();
		}


		/*** HELPER METHOD IN ORDER TO OPEN POPUP FOR MANAGING OPEN DOCUMENT ***/
		MVC.documents.generate._openInWindow = function(action, idDocument, params)
		{
			Popup2
				.create()
				.setId('Documents/Generate/OpenDocument/action_'+action+'/idDocument_'+idDocument)
				.setUrl(MVC.documents.generate.getOpenDocumentUrl(idDocument, action, params))
				.setDimensions(800, 500)
				.show();
		}

		/*** Get url for module OpenDocument ****/
		MVC.documents.generate.getOpenDocumentUrl = function(idDocument, action, params)
		{
			params.idDocument = idDocument;

			return MVC.appUrl('Documents/Generate/OpenDocument', action, params);
		}
	</script>

{/block}
