[TYPO3-mvc] extjs itemselector and extbase: map a comma separated list of values to Tx_Extbase_Persistence_ObjectStorage

Dmitri Pisarev dimaip at gmail.com
Fri Mar 12 14:38:46 CET 2010


Thanks for your help Jochen and Dennis!
For some reason my previous reply didn't get through and was lost:(
In short: I went more the Jochen's way, and not Dennis', because I write 
ext's code by hand, and not with help of viewhelpers.
Here's how I did it:
	/**
	 * Updates invoice.
	 *
	 * @param Tx_Alex_Domain_Model_Invoice $invoice
	 * @param string $subprojects
	 * @return string The rendered view
	 * @dontverifyrequesthash
	 */
	public function updateAction($invoice,$subprojects = NULL) {
  		$invoice->removeAllSubprojects();
		if($subprojects){
			$subprojects_arr = explode(',',$subprojects);
			foreach($subprojects_arr as $subproject_uid){
				$subproject_uid = (int)$subproject_uid;
				$subproject = $this->subprojectRepository->findByUid($subproject_uid);
				$invoice->addSubproject($subproject);
			}
		}
		$this->invoiceRepository->update($invoice);
		$this->flashMessages->add('Your invoice was updated.');
		echo '{success:true}';
	}

Cheers,
Dmitri.
11.03.2010 11:31, dennis ahrens пишет:
> Hi Dmitri,
>
> i've integrated the extjs ItemSelector in mvc_extjs. I've patched the
> js files to handle json objects instead of csv lists and have written
> a set of ViewHelpers to generate extjs classes based on your domain
> models. Have a look at:
>
> the JS Files:
> http://forge.typo3.org/repositories/browse/extension-mvc_extjs/branches/view/Resources/Public/JavaScript
>
> and the ViewHelpers:
> http://forge.typo3.org/repositories/browse/extension-mvc_extjs/branches/view/Classes/ViewHelpers/JsCode
>
> To get a working ItemSelectorField in your extjs gui you may combine
> the ItemSelectorViewHelper, MultiSelectViewHelper and
> ArrayStoreViewHelper.
>
> It should look like this in your template:
>
> <ext:jsCode.itemSelectorField
> 		domainModel="Fakultaet"
> 		extensionName="FhhOrgaobjects"
> 		fromMultiSelect="new FhhForschungsprojekte.Module.FakultaetFromMultiSelect"
> 		toMultiSelect="new FhhForschungsprojekte.Module.FakultaetToMultiSelect"
> 		minSelections="1">
> 		<ext:jsCode.multiSelectField
> 			domainModel="Fakultaet"
> 			extensionName="FhhOrgaobjects"
> 			name="FakultaetFromMultiSelect"
> 			store="new FhhForschungsprojekte.Module.FakultaetMultiSelectFromStore"
> 			displayField="name"
> 			valueField="uid"
> 			legend="Verfügbar">
> 			<ext:jsCode.arrayStore
> 				domainModel="Fakultaet"
> 				name="FakultaetMultiSelectFromStore"
> 				extensionName="FhhOrgaobjects"
> 				data="FhhForschungsprojekte.Module.FakultaetArrayData">
> 				<ext:jsCode.arrayStoreData
> 					domainModel="Fakultaet"
> 					extensionName="FhhOrgaobjects"
> 					data="{fakultaeten}" />
> 			</ext:jsCode.arrayStore>
> 		</ext:jsCode.multiSelectField>
> 		<ext:jsCode.multiSelectField
> 			domainModel="Fakultaet"
> 			extensionName="FhhOrgaobjects"
> 			name="FakultaetToMultiSelect"
> 			store="new FhhForschungsprojekte.Module.FakultaetMultiSelectToStore"
> 			displayField="name"
> 			valueField="uid"
> 			legend="Ausgewählt">
> 			<ext:jsCode.arrayStore
> 				domainModel="Fakultaet"
> 				name="FakultaetMultiSelectToStore"
> 				extensionName="FhhOrgaobjects">
> 			</ext:jsCode.arrayStore>
> 		</ext:jsCode.multiSelectField>
> 	</ext:jsCode.itemSelectorField>
>
> Not really handy at first sight - i know. But if u have a closer look
> the ViewHelpers are nothing more than extjs object configurations in
> xml sytnax...
>
> regards
> Dennis
>
> 2010/3/11 Jochen Rau<jochen.rau at typoplanet.de>:
>> Hi Dimitry,
>>
>> have a look at the OfferController and the according templates of
>>
>> http://forge.typo3.org/repositories/show/extension-sjr_offers
>>
>> how multivalues can be handeled.
>>
>> Regards
>> Jochen
>>
>> On 11.03.10 08:51, Dmitri Pisarev wrote:
>>>
>>> As my first question gets no reply, I'll try to put it the other way
>>> around:
>>> May be it's best attach and remove subprojects to invoice one by one, as
>>> a separate ajax calls, when user clicks on add and remove buttons of
>>> itemSelector?
>>> Here's the link to the sample of itemselector:
>>> http://www.extjs.com/deploy/dev/examples/multiselect/multiselect-demo.html
>>>
>>> Didn't anyone ever integrate multiselect with extbase?
>>>
>>> Cheers,
>>> Dmitri.
>>>
>>> On 09.03.2010 12:41, Dmitri Pisarev wrote:
>>>>
>>>> Hey guys! I'm trying to screw in the Ext's ItemSelector to my extbase
>>>> plugin. It lets me select multiple items and then submits a
>>>> comma-separated list of uid's. In my model I have a foreign key type of
>>>> relationship between Invoice and Suproject, so I can add multiple
>>>> subprojects to one invoice, and one subproject can belong to only one
>>>> invoice.
>>>> If I submit subprojects list as
>>>> Tx_Alex_Domain_Model_Invoice_Subprojects, nothing happens, it just maps
>>>> it to an empty
>>>> Tx_Extbase_Persistence_ObjectStorage<Tx_Alex_Domain_Model_Subproject>.
>>>> I can get that subprojects list as a string to the controller, manually
>>>> explode it, then manually deal with it, but isn't it possible to do it
>>>> automatically?
>>>>
>>>> Thanks in advance,
>>>> Dmitri.
>>>
>>
>> _______________________________________________
>> TYPO3-project-typo3v4mvc mailing list
>> TYPO3-project-typo3v4mvc at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>>



More information about the TYPO3-project-typo3v4mvc mailing list