Jump to content
yakyak

AddRow detail, delete, edit dans une liste d'un Tab

Recommended Posts

Salut,

 

Je souhaite afficher une liste de d'information enregistrée dans ma BDD dans un Tab.

 

Dans ce Tab, je veux pouvoir supprimer, editer, voir le détail d'un devis dans ma liste.

J'ai ajouter plusieurs AddRow() mais il manque le code pour effectuer les actions.

 

Voici le code de mon controller:

class AdminGestionDevisController extends ModuleAdminController
{
	public function __construct()
	{
        $this->table = 'devis_data';
        $this->className = 'DevisData';
		$this->deleted = true;
        $this->colorOnBackground = false;
        $this->context = Context::getContext();
		
        $this->bootstrap = true;
		
        parent::__construct();
	}
	
	public function renderList()
	{
		$this->addRowAction('details');
        $this->addRowAction('delete');
		$this->addRowAction('edit');

		$this->fields_list = array(
			'id_devis_data' => array(
				'title' => $this->l('Identifiant'),
				'width' => 140,
				'type' => 'text',
			),
			'name' => array(
				'title' => $this->l('Nom'),
				'width' => 140,
				'type' => 'text',
			),
		);
		
        $lists = parent::renderList();

        parent::initToolbar();

        return $lists;
	}

	public function renderForm()
    {
        $this->fields_form = array(
            'tinymce' => true,
            'legend' => array(
                'title' => $this->l('Modifier un devis'),
                'image' => '../img/admin/cog.gif'
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('Nom:'),
                    'name' => 'name'
                ),
            ),
            'submit' => array(
                'title' => $this->l('Save'),
                'class' => 'button'
            )
        );
		
        if (!($obj = $this->loadObject(true))) {
            return;
        }
		
        return parent::renderForm();
    }
	
    public function postProcess()
    {
		
        if (Tools::isSubmit('submitAdd'.$this->table)) 
		{
            $languages = Language::getLanguages(false);			
            foreach ($languages as $language) {
                $varFname = Tools::getValue('name_'.$language['id_lang']);
            }

			$sql = "INSERT INTO `ps_devis_data` (`name`) VALUES('{$varFname}')";			
			if (!Db::getInstance()->execute($sql)) 
			{
					$this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
			} 
			else 
			{
				Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
			}
        }		
		else if (Tools::isSubmit('delete'.$this->table))
		{
			$idDevis = Tools::getValue('id_devis_data');
			
			$sql = "UPDATE `ps_devis_data` SET deleted = 1 WHERE id_devis_data = '{$idDevis}'";
			if (!Db::getInstance()->execute($sql)) 
			{
					$this->errors[] = Tools::displayError('An error has occurred: Can\'t save the current object');
			} 
			else 
			{
				Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
			}
		}
    }
}

Mes questions sont les suivantes:

 

Est-ce que la suppression se fait bien dans la méthode postProccess() comme je l'ai fait ?

 

Quelles méthodes je dois ajouter pour détailler et éditer un élément de la liste lorsque je clique sur AddRow(edit) ou AddRow(detail) ?

Share this post


Link to post
Share on other sites

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More