From: Gustavo Martin Morcuende Date: Mon, 10 Dec 2012 23:27:22 +0000 (+0100) Subject: Better user experience while editing offices. X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=85c42230eee71d9e039d9d34b3f5ce610462449a;p=mobi%2F.git Better user experience while editing offices. --- diff --git a/apps/companyfront/modules/office/templates/_formCustomOffice.php b/apps/companyfront/modules/office/templates/_formCustomOffice.php index b5793b3..93a283c 100644 --- a/apps/companyfront/modules/office/templates/_formCustomOffice.php +++ b/apps/companyfront/modules/office/templates/_formCustomOffice.php @@ -2,33 +2,44 @@ - diff --git a/lib/form/doctrine/CityForm.class.php b/lib/form/doctrine/CityForm.class.php index 4bb45a2..978824e 100644 --- a/lib/form/doctrine/CityForm.class.php +++ b/lib/form/doctrine/CityForm.class.php @@ -17,7 +17,10 @@ class CityForm extends BaseCityForm $this->widgetSchema['region_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Region'), 'add_empty' => true)); - $this->widgetSchema['region_id']->setAttribute('disabled', 'disabled'); + if($this->isNew()) + { + $this->widgetSchema['region_id']->setAttribute('disabled', 'disabled'); + } $this->embedRelation('Region'); } diff --git a/lib/form/doctrine/OfficeForm.class.php b/lib/form/doctrine/OfficeForm.class.php index 4bc21a3..5e94bce 100644 --- a/lib/form/doctrine/OfficeForm.class.php +++ b/lib/form/doctrine/OfficeForm.class.php @@ -14,27 +14,20 @@ class OfficeForm extends BaseOfficeForm { $this->useFields(array('city_id', 'office_street_address', 'office_zip')); - $query = null; - if($this->isNew()) - { - $country = CountryTable::getInstance()->findOnebyCountryName(sfConfig::get('app_default_country')); - $region = RegionTable::getInstance()->findOneByCountryId($country->getId()); - $query = CityTable::getInstance()->getCitiesByRegionIdQuery($region->getId()); - } - $this->widgetSchema['longitude'] = new sfWidgetFormInputFloat(); $this->widgetSchema['latitude'] = new sfWidgetFormInputFloat(); $this->widgetSchema['city_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('City'), - 'add_empty' => true, - 'query' => $query)); + 'add_empty' => true)); $this->validatorSchema['city_id'] = new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('City'), 'required' => true)); - - $this->widgetSchema['city_id']->setAttribute('disabled', 'disabled'); + if($this->isNew()) + { + $this->widgetSchema['city_id']->setAttribute('disabled', 'disabled'); + } @@ -148,4 +141,21 @@ class OfficeForm extends BaseOfficeForm $this->setDefault('longitude', $this->getObject()->getLongitude()); $this->setDefault('latitude', $this->getObject()->getLatitude()); } + + protected function doBind(array $values) + { + if($this->getObject()->isNew()) + { + if (!empty($values['City']['region_id'])) + { + $this->widgetSchema['City']['region_id']->setAttribute('disabled', ''); + $this->widgetSchema['city_id']->setAttribute('disabled', ''); + } + if (!empty($values['City']['Region']['country_id'])) + { + $this->widgetSchema['City']['region_id']->setAttribute('disabled', ''); + } + } + parent::doBind($values); + } } diff --git a/lib/form/doctrine/RegionForm.class.php b/lib/form/doctrine/RegionForm.class.php index b10071e..2c40053 100644 --- a/lib/form/doctrine/RegionForm.class.php +++ b/lib/form/doctrine/RegionForm.class.php @@ -17,6 +17,5 @@ class RegionForm extends BaseRegionForm $this->widgetSchema['country_id'] = new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Country'), 'add_empty' => true)); - $this->embedRelation('Country'); } }