{extends file=$smarty.const.SMARTY_LAYOUT_MAIN_GENERAL_PAGINATED_LISTING}

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

{block name="js" append}
	<script type="text/javascript">
		MVC.scheduleOnLoad(function(){
			
			MVC.listing.prototype.resetModuleSettings = function() {
				this.backend_callUpdateOperation('reset', { });
			}
			
			MVC.listing.prototype.resetWithConfirmation = function(button) {
				MVC.callbackWithConfirmation(
					"{$lang['reset']['title']}",
					"{$lang['reset']['confirmation']}",
					this.resetModuleSettings.bind(this)
				);
			}
			
			MVC.listing.prototype.saveModuleSettings = function() {
				this.backend_callUpdateOperation('save', { });
			}
			
			
			MVC.listing.prototype.saveWithConfirmation = function(element) {
				MVC.callbackWithConfirmation(
					"{$lang['save']['title']}",
					"{$lang['save']['confirmation']}",
					this.saveModuleSettings.bind(this)
				);
			}
			
			MVC.listing.prototype.unsetFieldsSelected= function(button){
				this.backend_callUpdateOperation('unsetFields', null, button);
			}
			
			MVC.listing.prototype.unsetFieldsCurrentItem= function(element){
				this.backend_callUpdateOperation('unsetFields', {
					'listing[selection][add][]':	this.getItemId(element),
					'listing[selection][clear]' :	'all'
				});
			}
			
			MVC.listing.installedHandlers.listing.elements.table.on('change', function(evt, elm) {
				var productField = elm.up('td').readAttribute('data-productField');
				var serviceId = elm.up('tr').readAttribute('data-id');
				var serviceName = elm.up('tr').readAttribute('data-serviceName');
				var value = $F(elm);
				MVC.listing.installedHandlers.listing.AJAXManaged('changeOption', 'changeOption', { 'serviceId' : serviceId, 'serviceName' : serviceName, 'field' : productField, 'value' : value });
			});
		}, {
			delay: .1,
		});
	</script>
{/block}
