Jump to content

Module MVC 1.5.1 - Problème ajax (doublon a supprimer).


Recommended Posts

Bonjour,

 

Je suis en train de convertir un module 1.4 en 1.5 et je me retrouve bloquée sur la partie ajax.

 

controllers\admin\AdminMyModuleController.php contient les fonctions ci-dessous en plus de la fonction renderForm et renderList

 

public function ajaxProcess()
{
 if (Tools::isSubmit('customerFilter'))
 {
  $search_query = trim(Tools::getValue('q'));
  $customers = Db::getInstance()->executeS('
  SELECT `id_customer`, `email`, CONCAT(`firstname`, \' \', `lastname`) as cname
  FROM `'._DB_PREFIX_.'customer`
  WHERE `deleted` = 0 AND is_guest = 0 AND active = 1
  AND (
`id_customer` = '.(int)$search_query.'
OR `email` LIKE "%'.pSQL($search_query).'%"
OR `firstname` LIKE "%'.pSQL($search_query).'%"
OR `lastname` LIKE "%'.pSQL($search_query).'%"
  )
  ORDER BY `firstname`, `lastname` ASC
  LIMIT 50');
  die(Tools::jsonEncode($customers));
 }
}

public function setMedia()
{
 parent::setMedia();
 $this->addJqueryUI('ui.datepicker');
 if ($this->tabAccess['edit'] == 1)
 {
  $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
 }
}

public function renderForm()
{
.......
'input' => array(
array(
 'type' => 'hidden',
 'name' => 'id_customer',
 'value' => 0
),
array(
 'type' => 'text',
 'label' => $this->l('Customer:'),
 'name' => 'customerFilter',
 'size' => 40,
 'required' => true,
 'class' => 'ac_input',
 'autocomplete' => false
),
.......
}

 

views\templates\admin\MyModule_data\helpers\form qui contient

{extends file="helpers/form/form.tpl"}
er
{block name="input"}
 {$smarty.block.parent}
{/block}
{block name="script"}
$(document).ready(function() {
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
 return "";
  else
 return results[1];
}
var currentToken = gup( 'token' );

$('#customerFilter')
.autocomplete(
  'ajax-tab.php', {
  minChars: 2,
  max: 50,
  width: 500,
  selectFirst: false,
  scroll: false,
  dataType: 'json',
  formatItem: function(data, i, max, value, term) {
return value;
  },
  parse: function(data) {
var mytab = new Array();
for (var i = 0; i < data.length; i++)
 mytab[mytab.length] = { data: data[i], value: data[i].cname + ' (' + data[i].email + ')' };
return mytab;
  },
  extraParams: {
controller: 'AdminMyModule',
token: currentToken,
customerFilter: 1
  }
 }
)
.result(function(event, data, formatted) {
 $('#id_customer').val(data.id_customer);
 $('#customerFilter').val(data.cname + ' (' + data.email + ')');
});

});
{/block}

 

Le problème, ajax me retourne une valeur vide

 

Je voudrais reproduire le même fonctionnement que AdminCartRulesController mais dans un module sans passer par ajax.php mais ajax-tab.php.

 

Merci de votre aide

Edited by erotikat (see edit history)
Link to comment
Share on other sites

  • 4 weeks later...
  • 5 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...