Ajax handle in component, how to pass changed entity to template

Notice: This thread is very old.
SvvimX
Member | 65
+
0
-

Hi,
I have component with form, where I need to edit entity, which has picture.

class StoreItemForm extends BaseFormControl {

	public function render () {
		$id = $this -> presenter -> getParameter("id");
		$this -> template -> entity = $this -> itemFacade -> getOneById( $id );
	}

	public function setDefaultsFromEntity ( BaseEntity $entity) {
		$this ['form'] -> setDefaults ( array ( ... ) );
	}

	public function handleDeleteImage ( ) {
		$id = $this -> presenter -> getParameter("id");
		$entity = $this -> itemFacade -> getOneById( $id );
		$this -> imageFacade -> deleteEntity( $entity -> thumb ); // this delete image, and also set thumb column of item to NULL, via annotation onDelete="SET NULL"
		/** @fixme HOW TO PASS NEW ENTITY TO TEMPLATE */
		$this -> template -> entity = $this -> itemFacade -> getOneById( $id );

		$this -> redrawControl( "image" );
	}

	protected function createComponentForm ( $name = NULL ) {
		$form = new BaseForm ( $this -> translator );
		$form -> addUpload( 'image', "Image" );
		...
	}
}

So my question is in code: how to pass changed entity to template, cause now returning json for snippet is with old one – thumb is still there, when I reload page, new entity load correctly and no thumb is present

May be I miss something how ajax handle is done, like: does it call render on component, so why the new entity isn't load from database?

Thanks for help, and sorry for my english

Last edited by SvvimX (2014-05-03 23:52)