{extends file=$smarty.const.SMARTY_LAYOUT_MAIN_POPUP_LISTING}

{block name="css" append}
	{$CSS->load("{asset path="_css/listing-table.css"}")}
{/block}

{block name="template-head" append}
	{$JS->loadGroup("effects")}
{/block}


{block name="button_close"}
	<button type="button" style="float:left" onclick="window.close();">{$_LANG['close']}</button>
{/block}

{block name="js" append}
	<script type="text/javascript">
		MVC.scheduleOnLoad(function() {
			$('listingContainer').observe('listing:initialize', function(evt) {
				var listing = evt.memo.listing;
				listing.selection.saveSelection = function(params) {
					params = (params?params:{ });
					{if $idOrder}
						params['idOrder'] = {$idOrder};
					{/if}
					MVC.selection.prototype.saveSelection.call(this, params);
				};
			});
	
	
			MVC.listing.prototype.filterByOfferExternalSystemReservationId = function(element) {
				var offerExternalSystemReservationId = this.getItemData(element).get('offerExternalSystemReservationId');
				if (offerExternalSystemReservationId) {
				
					var params = {
						'listing[reset]' : 1,
						'filters[idUser][id]' : false,
						'filters[offerExternalSystemReservationId]' : offerExternalSystemReservationId
					};
					
					{if $idOrder}
						params['idOrder'] = {$idOrder};
					{/if}
				
					window.location = MVC.appUrl('Orders/ImportedOrders/ProcessServicesList', 'index', params);
				}
			};
	
			MVC.listing.prototype.importService = function(element) {
				var params = {
					'parent': 'importOrderServicesList'
				};
	
				{if $idOrder}
					params['idOrder'] = {$idOrder};
				{/if}
	
	
				if (this.getItemData(element).get('isPackage') == '1') {
					params['idPackageService'] = this.getItemId(element);
				}
				else {
					params['idImportedServicesList'] = this.getItemId(element);
				}
	
				window.location = MVC.appUrl('Orders/Services', 'insert', params);
			};
	
			MVC.listing.prototype.autoImportService = function(element) {
				var params = {
					'parent': 'importOrderServicesList',
					'autoSubmit' : 1,
					'importedPassengerInsertTypeDefault' : 'selectIfOneOrAutoInsert'
				};
	
				{if $idOrder}
					params['idOrder'] = {$idOrder};
				{/if}
	
	
				if (this.getItemData(element).get('isPackage') == '1') {
					params['idPackageService'] = this.getItemId(element);
				}
				else {
					params['idImportedServicesList'] = this.getItemId(element);
				}
	
				window.location = MVC.appUrl('Orders/Services', 'insert', params);
			};
	
			MVC.listing.prototype.importServices = function(element) {
				var params = {
					'parent': 'importOrderServicesList'
				};
	
				{if $idOrder}
					params['idOrder'] = {$idOrder};
				{/if}
	
	
				if (this.getSelectedData(element).first().get('isPackage') == '1') {
					params['idPackageService'] = this.getSelectedIds(element).first();
				}
				else {
					params['idImportedServicesList'] = this.getSelectedIds(element);
				}
	
				window.location = MVC.appUrl('Orders/Services', 'insert', params);
			};
	
			MVC.listing.prototype.autoImportServices = function(element) {
				var params = {
					'parent': 'importOrderServicesList',
					'autoSubmit' : 1,
					'importedPassengerInsertTypeDefault' : 'selectIfOneOrAutoInsert'
				};
	
				{if $idOrder}
					params['idOrder'] = {$idOrder};
				{/if}
	
	
					if (this.getSelectedData(element).first().get('isPackage') == '1') {
					params['idPackageService'] = this.getSelectedIds(element).first();
				}
				else {
					params['idImportedServicesList'] = this.getSelectedIds(element);
				}
	
				window.location = MVC.appUrl('Orders/Services', 'insert', params);
			};
	
			MVC.listing.prototype.quickProcess = function(element) {
				var params = {
					'parent': 'importOrderServicesList',
					'autoSubmit' : 1
				};
	
				{if $idOrder}
					params['idOrder'] = {$idOrder};
				{/if}
	
	
				if (this.getItemData(element).get('isPackage') == '1') {
					params['idPackageService'] = this.getItemId(element);
				}
				else {
					params['idImportedServicesList'] = [this.getItemId(element)];
				}
	
				window.location = MVC.appUrl('Orders/Services/ProcessBulk', 'index', params);
			};
	
			MVC.listing.prototype.quickProcessBulk = function(element) {
				var params = {
					'parent': 'importOrderServicesList',
					'autoSubmit' : 1
				};
	
				{if $idOrder}
					params['idOrder'] = {$idOrder};
				{/if}
	
	
				if (this.getSelectedData(element).first().get('isPackage') == '1') {
					params['idPackageService'] = this.getSelectedIds(element).first();
				}
				else {
					params['idImportedServicesList'] = this.getSelectedIds(element);
				}
	
				window.location = MVC.appUrl('Orders/Services/ProcessBulk', 'index', params);
			};
		});
	</script>
{/block}