|
| Re: sfPropelAdmin generator and ajax [message #33544 is a reply to message #32787 ] |
Fri, 17 August 2007 01:06   |
 |
lvanderree Messages: 652 Registered: June 2007 Location: Netherlands |
Faithful Member |
|
|
One way to solve this is by manually copy the _edit_form.php template from your cache to your module/template folder and then alter it.
Another and nicer way is to fix this directly in your theme. I saw the default-theme currently does not anticipate in this, but I want this too, so I will alter the theme tomorrow and post it here, so you can activate it from your generator.yml.
[Updated on: Fri, 17 August 2007 01:06] Leon
|
|
|
| Re: sfPropelAdmin generator and ajax [message #33586 is a reply to message #32787 ] |
Fri, 17 August 2007 21:00   |
sfxpt Messages: 339 Registered: January 2007 Location: Canada |
Faithful Member |
|
|
| wiseman wrote on Thu, 02 August 2007 16:56 | ... i want this part of my app to be totally ajax'ed... so now i have to manually edit all generated templates. It works normally...
|
Interesting.
wiseman, could you share with us what's the benefit of using link_to_remote & form_remote_tag instead of link_to, button_to, etc. Looking at the API doc didn't give me much idea what's they're for, what's the advantages, etc. Please help.
Further, I'm planning to redo what you've done to my forms and see how it works/feels, on seeing this is an interesting idea. Could you tell me what have you changed to make Admin gen totally ajax'ed?
thx a lot!!!
http://xpt.sourceforge.net/techdocs/
http://xpt.sourceforge.net/tools/
|
|
|
| Re: sfPropelAdmin generator and ajax [message #33587 is a reply to message #33586 ] |
Fri, 17 August 2007 21:39   |
 |
lvanderree Messages: 652 Registered: June 2007 Location: Netherlands |
Faithful Member |
|
|
I don't think wiseman did anything to the templates yet. He said he had to manually alter every template.
I said I wanted to alter the theme to make it possible from the generator. But at the moment I am still looking at what I actually want to AJAX-ise 
I have a very simple example:
I've got countries (id, name, abbreviation), and per country I have some cities (id, country_id, name). (I don't want to use the country-select-helper, because I don't need all countries.)
In the city module, when adding a city without AJAX you get a drop-down-list from where you can select a country. But if the country is not in the database yet, you first have to add it with a country module.
With AJAX you can generate a city module where you have 2 text fields, one for the city-name and one which uses autocomplete to set the countryname. If the country exists, autocompletion can be used to select the country and set the country_id in a hidden-input-box. The interesting thing is If the country does not exists, then you can freely enter the country name, and when submitting, the form already knows the country does not exists, and immediately can ask for the country abbreviation, so it can add the country to the database and then add the city with the foreign key to the newly added country.
---
At the moment I have figured out how to create an autocomplete which sets a hidden inputfield if the country exists. I can easily change my theme so this can be generated by the admin generator.
Currently a problem has been introduced, because if you press enter when selecting the country with the keyboard, you submit the form. So I have to replace the submit buttons by javascript powered ones.
After that I want to add a popup which asks for the missing fields (the country abbreviation), so a new country can be added.
When I figured these last two things out I will post my alter theme for the generator
Leon
|
|
|
| Re: sfPropelAdmin generator and ajax [message #33634 is a reply to message #33587 ] |
Sun, 19 August 2007 02:52   |
wiseman Messages: 9 Registered: August 2007 Location: Russia |
Junior Member |
|
|
hi, all.
Thanks for responces, i was playing around generator.yml and tried to explore all it's powers.
there is no big workaround there - just change all link_to, button_to tags to remote_link_to and remote_button_to tags and define there id of <div> you need to update. But i don't like to manually edit generated templates, i was thinking that adding some params in generator.yml could change the way of generating all stuff, something like:
generator:
class: sfPropelAdminGenerator
param:
xhr: true
update: div_id
and by modifying two functions in sfAdminGenerator.class.php ( getLinkToAction, getButtonToAction ) extend them, so if not defined xhr parameter, the generate all links and buttons in non-ajaxed way, otherwise generate ajaxed stuff.
But for now i don't have the time to dig into it more, so it's just an idea for now.
|
|
|
|
| Re: sfPropelAdmin generator and ajax [message #34775 is a reply to message #33638 ] |
Mon, 03 September 2007 00:19  |
DrCore Messages: 59 Registered: August 2007 |
Member |
|
|
Instead of changing the admin generated form, I have chosen to use a session parameter to track the linked main form. Basically all forms are kept as they are, only a couple of action elements are added to the subforms and one component is added to the mainform.
For example, the main form contains a module/actions/components.class.php with the following content:
class vendorComponents extends sfComponents
{
protected $mainidparam = 'vendor_id';
protected $mainmodule = 'vendor';
public function executeVendorMenu()
{
// Check if vendor id was set before
if ($this->getUser()->hasAttribute($this->mainidparam))
$this->mainid = $this->getUser()->getAttribute($this->mainidparam);
// Check if a request for an ID was done within the vendor module
if (sfContext::getInstance()->getModuleName() == $this->mainmodule and $this->hasRequestParameter('id'))
$this->mainid = $this->getRequestParameter('id');
// Check if a request was done for a vendor id
if ($this->hasRequestParameter($this->mainidparam))
$this->mainid = $this->getRequestParameter($this->mainidparam);
// If vendor id is set
if ($this->mainid)
{
// Check if vendor id exists
$c = new Criteria();
$c->add(vendorPeer::ID, $this->mainid);
$this->mainselect = vendorPeer::doSelect($c);
if (count($this->mainselect) == 1)
{
// Store the vendor id in the session
$this->getUser()->setAttribute($this->mainidparam, $this->mainid);
}
else
{
// Remove vendor id session if vendor is not found
unset($this->vendor);
unset($this->mainid);
$this->getUser()->getAttributeHolder()->remove($this->mainidparam);
}
}
// Get current module name for menu
$this->module = sfContext::getInstance()->getModuleName();
}
}
In this case vendor_id is going to be a user session parameter which is going to be picked up in the subforms.
In the subform /module/actions/actions.class.php you find:
class vendorcontactActions extends autovendorcontactActions
{
// Apply the subview for vendors
protected function processFilters()
{
// This initiates all of the other filters you might have
parent::processFilters();
// Get the normal filters
$filters = $this->getUser()->getAttributeHolder()->getAll('sf_admin/vendor_contact/filters');
// Check for vendormenu_id
if ($this->getUser()->hasAttribute('vendor_id'))
{
$filters['vendor_id'] = $this->getUser()->getAttribute('vendor_id');
}
// Put the modified filters back where the belong
$this->getUser()->getAttributeHolder()->removeNamespace('sf_admin/vendor_contact/filters');
$this->getUser()->getAttributeHolder()->add($filters, 'sf_admin/vendor_contact/filters');
}
protected function addFiltersCriteria($c)
{
if (isset($this->filters['vendor_id']))
{
$criterion = $c->getNewCriterion(vendor_contactPeer::VENDOR_ID,
$this->filters['vendor_id']);
$c->add($criterion);
}
parent::addFiltersCriteria($c);
}
// Reset the list from vendor selection
public function executeListreset()
{
// Get user session
$this->getUser()->getAttributeHolder()->remove('vendor_id');
$this->forward('vendorcontact', 'list');
}
}
Basically a filter gets automatically added to the list to show only the subitems of the mainform. To break this link call the 'listreset' action. This means all links within the forms stay as they are. The session parameter will remember the link.
This is probably not the best looking code, but at least it seems to work.
Andre
|
|
|