<commit_before><?php
namespace Mabs\JQueryAjaxBundle\Twig;

/**
 *
 * @author <NAME> <<EMAIL>>
 *        
 */
class JqueryAjaxExtension extends \Twig_Extension
{

    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction('ja_request', $this->remoteCall(), array(
                'is_safe' => array(
                    'html'
                )
            )),
            new \Twig_SimpleFunction('ja_submit', $this->submitTag(), array(
                'is_safe' => array(
                    'html'
                )
            )),
            new \Twig_SimpleFunction('ja_link', $this->linkTag(), array(
                'is_safe' => array(
                    'html'
                )
            ))
        );
    }

    /**
     * Generate Js function to send ajax request.
     *
     * @param array $options            
     */
    public function remoteCall($options = array())
    {
        return function ($options) {
            $type = isset($options['type']) ? $options['type'] : "POST";
            $dataType = isset($options['dataType']) ? $options['dataType'] : "html";
            $js = "$.ajax({
							url: '" . $options['url'] . "',
							type: '" . $type . "',
							dataType: '" . $dataType . "',";
            
            if (isset($options['before'])) {
                $before = str_replace('"', "'", $options['before']);
                $js .= "beforeSend: function(){" . $before . "},";
            }
            
            $js .= "success: function( data ){ $('" . $options['update'] . "').html(data);";
            
            if (isset($options['after'])) {
                $after = str_replace('"', "'", $options['after']);
                $js .= $after;
            }
            
            $js .= "}";
            
            if (isset($options['complete'])) {
                $complete = str_replace('"', "'", $options['complete']);
                $js .= ",complete: function(){" . $complete . "},";
            }
            
            $js .= "});";
            
            return $js;
        };
    }
    
     /**
     * Generate Js function to send ajax form data.
     *
     * @param array $options            
     */
    public function submitCall($options = array())
    {
    	return function ($options) {
    		$type = isset($options['type']) ? $options['type'] : "POST";
    		$dataType = isset($options['dataType']) ? $options['dataType'] : "html";
    		$js = "$.ajax({
		    		url: '" . $options['url'] . "',
		    		type: '" . $type . "',
		    		data: $(this.form.elements).serializeArray(),
		    		dataType: '" . $dataType . "',";
    		if (isset($options['before'])) {
    			$before = str_replace('"', "'", $options['before']);
    			$js .= "beforeSend: function(){" . $before . "},";
    		}
    		$js .= "success: function( data ){";
    		if (isset($options['success'])) {
    			$success = str_replace('"', "'", $options['success']);
    			$js .= $success ;
    		}
    		if (isset($options['after'])) {
    			$after = str_replace('"', "'", $options['after']);
    			$js .= $after;
    		}
    
    		$js .= "}});";
    
    		return $js;
    	};
    }

    /**
     * Generate link tag with js function to send ajax request
     *
     * @param array $options            
     */
    public function linkTag($options = array())
    {
        $jsRequest = $this->remoteCall();
        
        return function ($options) use($jsRequest)
        {
            $confirm = '';
            if (isset($options['confirm']) && $options['confirm'] == true) {
                
                $msg = "Are you sure you want to perform this action?";
                if(isset($options['confirm_msg'])) {
                    $msg = htmlentities(str_replace("'", '"', $options['confirm_msg']), ENT_QUOTES);                  
                }
            	$confirm .= "if(confirm('".$msg."'))" ;
            }
            $html = '<a class="' . (isset($options['class']) ? $options['class'] : "") . '"
    		 		 id="' . (isset($options['id']) ? $options['id'] : "") . '"
    		 		 href="' . $options['url'] . '"
    				 onclick="' .$confirm. call_user_func($jsRequest, $options) . 'return false;">';
            $html .= $options['text'];
            $html .= '</a>';
            
            return $html;
        };
    }
    
     /**
     * Generate submit button tag with js function to send ajax form
     *
     * @param array $options
     */
    public function submitTag($options = array())
    {
    	$jsSubmit = $this->submitCall();
    
    	return function ($options) use($jsSubmit)
    	{
    		$confirm = '';
    		if (isset($options['confirm']) && $options['confirm'] == true) {
    
    			$msg = "Are you sure you want to perform this action?";
    			if(isset($options['confirm_msg'])) {
    				$msg = htmlentities(str_replace("'", '"', $options['confirm_msg']), ENT_QUOTES);
    			}
    			$confirm .= "if(confirm('".$msg."'))" ;
    		}
    		$html = '<button class="' . (isset($options['class']) ? $options['class'] : "") . '"
    		id="' . (isset($options['id']) ? $options['id'] : "") . '"
    		onclick="' .$confirm. call_user_func($jsSubmit, $options) . 'return false;">';
    		$html .= $options['text'];
    		$html .= '</button>';
    
    		return $html;
    	};
    }

    /**
     * Returns the name of the extension.
     *
     * @return string The extension name
     */
    public function getName()
    {
        return 'mabs_jquery_ajax';
    }
}
<commit_msg>Update JqueryAjaxExtension.php<commit_after><?php
namespace Mabs\JQueryAjaxBundle\Twig;

/**
 *
 * @author <NAME> <<EMAIL>>
 *        
 */
class JqueryAjaxExtension extends \Twig_Extension
{

    public function getFunctions()
    {
        return array(
            new \Twig_SimpleFunction('ja_request', $this->remoteCall(), array(
                'is_safe' => array(
                    'html'
                )
            )),
            new \Twig_SimpleFunction('ja_submit', $this->submitTag(), array(
                'is_safe' => array(
                    'html'
                )
            )),
            new \Twig_SimpleFunction('ja_link', $this->linkTag(), array(
                'is_safe' => array(
                    'html'
                )
            ))
        );
    }

    /**
     * Generate Js function to send ajax request.
     *
     * @param array $options            
     */
    public function remoteCall($options = array())
    {
        return function ($options) {
            $type = isset($options['type']) ? $options['type'] : "POST";
            $dataType = isset($options['dataType']) ? $options['dataType'] : "html";
            $js = "$.ajax({
							url: '" . $options['url'] . "',
							type: '" . $type . "',
							dataType: '" . $dataType . "',";
            
            if (isset($options['before'])) {
                $before = str_replace('"', "'", $options['before']);
                $js .= "beforeSend: function(){" . $before . "},";
            }
            
            $js .= "success: function( data ){ $('" . $options['update'] . "').html(data);";
            
            if (isset($options['after'])) {
                $after = str_replace('"', "'", $options['after']);
                $js .= $after;
            }
            
            $js .= "}";
            
            if (isset($options['complete'])) {
                $complete = str_replace('"', "'", $options['complete']);
                $js .= ",complete: function(){" . $complete . "},";
            }
            
            $js .= "});";
            
            return $js;
        };
    }
    
     /**
     * Generate Js function to send ajax form data.
     *
     * @param array $options            
     */
    public function submitCall($options = array())
    {
    	return function ($options) {
    		$type = isset($options['type']) ? $options['type'] : "POST";
    		$dataType = isset($options['dataType']) ? $options['dataType'] : "html";
    		$js = "$.ajax({
		    		url: '" . $options['url'] . "',
		    		type: '" . $type . "',
		    		data: $(this.form.elements).serializeArray(),
		    		dataType: '" . $dataType . "',";
    		if (isset($options['before'])) {
    			$before = str_replace('"', "'", $options['before']);
    			$js .= "beforeSend: function(){" . $before . "},";
    		}
    		$js .= "success: function( data ){";
    		if (isset($options['success'])) {
    			$success = str_replace('"', "'", $options['success']);
    			$js .= $success ;
    		}
    		if (isset($options['after'])) {
    			$after = str_replace('"', "'", $options['after']);
    			$js .= $after;
    		}
    
    		$js .= "}});";
    
    		return $js;
    	};
    }

    /**
     * Generate link tag with js function to send ajax request
     *
     * @param array $options            
     */
    public function linkTag($options = array())
    {
        $jsRequest = $this->remoteCall();
        
        return function ($options) use($jsRequest)
        {
            $confirm = '';
            if (isset($options['confirm']) && $options['confirm'] === true) {
                
                $msg = "Are you sure you want to perform this action?";
                if(isset($options['confirm_msg'])) {
                    $msg = htmlentities(str_replace("'", '"', $options['confirm_msg']), ENT_QUOTES);                  
                }
            	$confirm .= "if(confirm('".$msg."'))" ;
            }
            $html = '<a class="' . (isset($options['class']) ? $options['class'] : "") . '"
    		 		 id="' . (isset($options['id']) ? $options['id'] : "") . '"
    		 		 href="' . $options['url'] . '"
    				 onclick="' .$confirm. call_user_func($jsRequest, $options) . 'return false;">';
            $html .= $options['text'];
            $html .= '</a>';
            
            return $html;
        };
    }
    
     /**
     * Generate submit button tag with js function to send ajax form
     *
     * @param array $options
     */
    public function submitTag($options = array())
    {
    	$jsSubmit = $this->submitCall();
    
    	return function ($options) use($jsSubmit)
    	{
    		$confirm = '';
    		if (isset($options['confirm']) && $options['confirm'] === true) {
    
    			$msg = "Are you sure you want to perform this action?";
    			if(isset($options['confirm_msg'])) {
    				$msg = htmlentities(str_replace("'", '"', $options['confirm_msg']), ENT_QUOTES);
    			}
    			$confirm .= "if(confirm('".$msg."'))" ;
    		}
    		$html = '<button class="' . (isset($options['class']) ? $options['class'] : "") . '"
    		id="' . (isset($options['id']) ? $options['id'] : "") . '"
    		onclick="' .$confirm. call_user_func($jsSubmit, $options) . 'return false;">';
    		$html .= $options['text'];
    		$html .= '</button>';
    
    		return $html;
    	};
    }

    /**
     * Returns the name of the extension.
     *
     * @return string The extension name
     */
    public function getName()
    {
        return 'mabs_jquery_ajax';
    }
}


{'fraction_non_alphanumeric': 0.1940014498006524, 'fraction_numerical': 0.0, 'mean_word_length': 1.634128878281623, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7560715', 'n_tokens_mistral': 3459, 'n_tokens_neox': 3305, 'n_words': 639}