Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Commit

Permalink
Rename type to method in Ajax
Browse files Browse the repository at this point in the history
Rename type to method
  • Loading branch information
stephanvierkant authored May 7, 2019
2 parents 42ef873 + ab1213a commit 5e4bf48
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
40 changes: 30 additions & 10 deletions Datatable/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Ajax
*
* @var string
*/
protected $type;
protected $method;

/**
* Data to be sent.
Expand Down Expand Up @@ -90,17 +90,17 @@ public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'url' => null,
'type' => 'GET',
'method' => 'GET',
'data' => null,
'pipeline' => 0,
));

$resolver->setAllowedTypes('url', array('null', 'string'));
$resolver->setAllowedTypes('type', 'string');
$resolver->setAllowedTypes('method', 'string');
$resolver->setAllowedTypes('data', array('null', 'array'));
$resolver->setAllowedTypes('pipeline', 'int');

$resolver->setAllowedValues('type', array('GET', 'POST'));
$resolver->setAllowedValues('method', array('GET', 'POST'));

return $this;
}
Expand Down Expand Up @@ -134,29 +134,49 @@ public function setUrl($url)
}

/**
* Get type.
* Get method.
*
* @return string
*/
public function getMethod()
{
return $this->method;
}

/**
* @return string
* @deprecated Use getMethod() instead
*/
public function getType()
{
return $this->type;
return $this->getMethod();
}

/**
* Set type.
* Set method.
*
* @param string $type
* @param string $method
*
* @return $this
*/
public function setType($type)
public function setMethod($method)
{
$this->type = $type;
$this->method = $method;

return $this;
}

/**
* @param $method
*
* @return \Sg\DatatablesBundle\Datatable\Ajax
* @deprecated Use setMethod() instead
*/
public function setType($method)
{
return $this->setMethod($method);
}

/**
* Get data.
*
Expand Down
4 changes: 2 additions & 2 deletions Resources/public/js/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $.fn.dataTable.pipeline = function ( opts ) {
url: '', // script url
data: null, // function or object with parameters to send to the server
// matching how `ajax.data` works in DataTables
method: 'GET' // Ajax HTTP method
method: opts.method // Ajax HTTP method
}, opts );

// Private variables for storing the cache
Expand Down Expand Up @@ -73,7 +73,7 @@ $.fn.dataTable.pipeline = function ( opts ) {
}

settings.jqXHR = $.ajax( {
"type": conf.method,
"method": conf.method,
"url": conf.url,
"data": request,
"dataType": "json",
Expand Down
5 changes: 1 addition & 4 deletions Resources/views/datatable/ajax.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% if sg_datatables_view.ajax.url is not same as(null) %}
"url": "{{ sg_datatables_view.ajax.url|raw }}",
{% endif %}
"type": "{{ sg_datatables_view.ajax.type }}",
"method": "{{ sg_datatables_view.ajax.method }}",
{% if sg_datatables_view.ajax.data is not same as(null) %}
"data": {{ sg_datatables_view.ajax.data|raw }},
{% endif %}
Expand All @@ -27,6 +27,3 @@
{{ ajax_vars }}
},
{% endif %}



2 changes: 1 addition & 1 deletion Resources/views/datatable/multiselect_actions.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ $(".sg-datatables-{{ datatable_name }}-multiselect-action").on("click", function
if (url != null) {
$.ajax({
url: url,
type: "POST",
method: "POST",
cache: false,
data: {
'data': items,
Expand Down
2 changes: 1 addition & 1 deletion Response/DatatableResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ private function createDatatableQueryBuilder()
private function getRequestParams()
{
$parameterBag = null;
$type = $this->datatable->getAjax()->getType();
$type = $this->datatable->getAjax()->getMethod();

if ('GET' === strtoupper($type)) {
$parameterBag = $this->request->query;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Datatables/PostDatatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function buildDatatable(array $options = array())
{
$this->ajax->set(array(
'url' => '',
'type' => 'GET',
'method' => 'GET',
));

$this->options->set(array(
Expand Down

0 comments on commit 5e4bf48

Please sign in to comment.