From 5a770ae43b2598a132c952040afe7c70bb0e391e Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 3 Jun 2012 18:46:20 +0200 Subject: [PATCH] Edit Ads and Company data with nice forms. --- apps/companyfront/modules/ad/templates/_form.php | 93 +++++++++++++++++++--- .../modules/company/templates/_form.php | 11 ++- lib/form/doctrine/AdDescriptionForm.class.php | 3 + lib/form/doctrine/AdForm.class.php | 26 ++++-- web/css/inadminpanel/style.css | 15 +++- 5 files changed, 128 insertions(+), 20 deletions(-) diff --git a/apps/companyfront/modules/ad/templates/_form.php b/apps/companyfront/modules/ad/templates/_form.php index 6ef22b0..a073d6a 100644 --- a/apps/companyfront/modules/ad/templates/_form.php +++ b/apps/companyfront/modules/ad/templates/_form.php @@ -5,19 +5,90 @@ getObject()->isNew()): ?> +
+ - - - - - - renderGlobalErrors() ?> - + renderRow(array('class' => 'validate-selection')) ?> + renderError() ?> + renderRow(array('class' => 'required')) ?> + renderRow(array('class' => 'required')) ?> + renderError() ?> + renderRow(array('class' => 'required')) ?> + renderError() ?>
- renderHiddenFields(false) ?> -   - -
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ render(array('class' => 'validate-selection')) ?> + renderError() ?> + + render(array('class' => 'required')) ?> + renderError() ?> + render(array('class' => 'required')) ?> + renderError() ?> + render(array('class' => 'required')) ?> + renderError() ?> + + renderError() ?> +
+ render(array('class' => 'validate-selection')) ?> + renderError() ?> + + render(array('class' => 'required')) ?> + renderError() ?> + render(array('class' => 'required')) ?> + renderError() ?> + render(array('class' => 'required')) ?> + renderError() ?> + + + renderError() ?> + + renderError() ?> +
+ renderHiddenFields(false) ?> +
+   + + + + + + + +
+ + + +
diff --git a/apps/companyfront/modules/company/templates/_form.php b/apps/companyfront/modules/company/templates/_form.php index 66cb305..d8d1419 100644 --- a/apps/companyfront/modules/company/templates/_form.php +++ b/apps/companyfront/modules/company/templates/_form.php @@ -10,11 +10,13 @@ renderRow(array('class' => 'required')) ?> + renderError() ?> renderRow(array('class' => 'required')) ?> + renderError() ?>
- + @@ -30,10 +32,13 @@ @@ -44,13 +49,17 @@ diff --git a/lib/form/doctrine/AdDescriptionForm.class.php b/lib/form/doctrine/AdDescriptionForm.class.php index 612913c..f8de80f 100644 --- a/lib/form/doctrine/AdDescriptionForm.class.php +++ b/lib/form/doctrine/AdDescriptionForm.class.php @@ -13,6 +13,9 @@ class AdDescriptionForm extends BaseAdDescriptionForm public function configure() { unset($this['ad_id']); + unset($this['ad_description']); + + $this->widgetSchema['ad_link'] = new sfWidgetFormInputText(); if ($this->object->exists()) { diff --git a/lib/form/doctrine/AdForm.class.php b/lib/form/doctrine/AdForm.class.php index 5d8879c..22ba8d1 100644 --- a/lib/form/doctrine/AdForm.class.php +++ b/lib/form/doctrine/AdForm.class.php @@ -94,10 +94,13 @@ class AdForm extends BaseAdForm protected function doBind(array $values) { - if ('' === trim($values['new']['ad_description']) && '' === trim($values['new']['ad_mobile_text']) - && '' === trim($values['new']['ad_name']) && '' === trim($values['new']['ad_link'])) + if (isset($values['new'])) { - unset($values['new'], $this['new']); + if ('' === trim($values['new']['ad_mobile_text']) && '' === trim($values['new']['ad_name']) && + '' === trim($values['new']['ad_link'])) + { + unset($values['new'], $this['new']); + } } if (isset($values['AdDescription'])) @@ -202,10 +205,19 @@ class AdForm extends BaseAdForm if ($field == 'latitude') $latitude = $value; } + //Catch id element. We will use this id to insert the PostGIS value in the right row. - $arrowId = $this->getObject()->getId(); - //Update PostGIS - //This connection will throw exception in case of error. - Doctrine_Manager::connection()->execute("UPDATE ad SET ad_gps=ST_GeographyFromText('SRID=4326;POINT($longitude $latitude)') WHERE id=$arrowId"); + $rowId = $this->getObject()->getId(); + //They are not required fields, so they could be null values. + if ((isset($longitude)) && (isset($latitude))) + { + //Update PostGIS with the chosen coordinates. + //This connection will throw exception in case of error. + Doctrine_Manager::connection()->execute("UPDATE ad SET ad_gps=ST_GeographyFromText('SRID=4326;POINT($longitude $latitude)') WHERE id=$rowId"); + } + else { + //Update PostGIS with null value (no GPS coordinates) + Doctrine_Manager::connection()->execute("UPDATE ad SET ad_gps=null WHERE id=$rowId"); + } } } diff --git a/web/css/inadminpanel/style.css b/web/css/inadminpanel/style.css index e254b8e..ba02799 100644 --- a/web/css/inadminpanel/style.css +++ b/web/css/inadminpanel/style.css @@ -516,7 +516,7 @@ border-color: #95E0EF; border-style: solid; border-width: 1px 1px 1px 2px; float: left; -height: 28px; +height: 22px; padding: 5px 0 0 2px; width: 300px; } @@ -539,3 +539,16 @@ background-color: #0FCDF6; color: #FFFFFF; padding: 2px 5px; } +legend.optional{ +color:#FFFFFF; +background-color:#50c150; +padding:2px 5px 2px 5px; +} +textarea.required{ +width:300px; +height:75px; +float:left; +border: 1px solid #95E0EF; +background-color:#f3fcfe; +border-left-width:2px; +} -- 2.1.4
render(array('class' => 'validate-selection')) ?> + renderError() ?> render(array('class' => 'required')) ?> + renderError() ?> + renderError() ?> render(array('class' => 'validate-selection')) ?> + renderError() ?> render(array('class' => 'required')) ?> + renderError() ?> + renderError() ?> + renderError() ?>