Edit Ads and Company data with nice forms.
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 3 Jun 2012 16:46:20 +0000 (18:46 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 3 Jun 2012 16:46:20 +0000 (18:46 +0200)
apps/companyfront/modules/ad/templates/_form.php
apps/companyfront/modules/company/templates/_form.php
lib/form/doctrine/AdDescriptionForm.class.php
lib/form/doctrine/AdForm.class.php
web/css/inadminpanel/style.css

index 6ef22b0..a073d6a 100644 (file)
@@ -5,19 +5,90 @@
 <?php if (!$form->getObject()->isNew()): ?>
 <input type="hidden" name="sf_method" value="put" />
 <?php endif; ?>
+  <fieldset>
+  <legend><?php echo __('PICTURE, GPS COORDINATES AND CATEGORY') ?></legend>
   <table>
-    <tfoot>
-      <tr>
-        <td colspan="2">
-          <?php echo $form->renderHiddenFields(false) ?>
-          &nbsp;<a href="<?php echo url_for('ad/index?page='.$page) ?>"><?php echo __('Back to list') ?></a>
-          <input type="submit" value="Update" />
-        </td>
-      </tr>
-    </tfoot>
     <tbody>
-      <?php echo $form->renderGlobalErrors() ?>
-      <?php echo $form ?>
+            <?php echo $form['company_categ_id']->renderRow(array('class' => 'validate-selection')) ?>
+            <?php echo $form['company_categ_id']->renderError() ?>
+            <?php echo $form['ad_mobile_image_link']->renderRow(array('class' => 'required')) ?>
+            <?php echo $form['longitude']->renderRow(array('class' => 'required')) ?>
+            <?php echo $form['longitude']->renderError() ?>
+            <?php echo $form['latitude']->renderRow(array('class' => 'required')) ?>
+            <?php echo $form['latitude']->renderError() ?>
     </tbody>
   </table>
+  </fieldset>
+  <fieldset>
+  <legend class="optional"><?php echo __('INTERNATIONALIZATION') ?></legend>
+  <table id="rounded-cornergus">
+  <thead>
+    <tr>
+        <th> </th>
+        <th scope="col" class="rounded-companygus"><?php echo __('Language') ?></th>
+        <th scope="col" class="rounded-companygus"><?php echo __('Ad Name, Mobile Text and Link HTTP') ?></th>
+        <th scope="col" class="rounded-q4gus"><?php echo __('Remove') ?></th>
+    </tr>
+  </thead>
+  <tbody>
+  <?php if (isset($form['new'])): ?>
+     <tr>
+    <td><?php echo __('New Entry:') ?></td>
+    <td>
+        <?php echo $form['new']['language_id']->render(array('class' => 'validate-selection')) ?>
+        <?php echo $form['new']['language_id']->renderError() ?>
+    </td>
+    <td>
+        <?php echo $form['new']['ad_name']->render(array('class' => 'required')) ?>
+        <?php echo $form['new']['ad_name']->renderError() ?>
+        <?php echo $form['new']['ad_mobile_text']->render(array('class' => 'required')) ?>
+        <?php echo $form['new']['ad_mobile_text']->renderError() ?>
+        <?php echo $form['new']['ad_link']->render(array('class' => 'required')) ?>
+        <?php echo $form['new']['ad_link']->renderError() ?>
+        <?php echo $form['new']['id'] ?>
+        <?php echo $form['new']['id']->renderError() ?>
+    </td>
+    <td></td>
+    </tr>
+  <?php endif; ?>
+  <?php foreach ($form['AdDescription'] as $adDescription): ?>
+    <tr>
+    <td><?php echo __('Current Entry:') ?></td>
+    <td>
+        <?php echo $adDescription['language_id']->render(array('class' => 'validate-selection')) ?>
+        <?php echo $adDescription['language_id']->renderError() ?>
+    </td>
+    <td>
+        <?php echo $adDescription['ad_name']->render(array('class' => 'required')) ?>
+        <?php echo $adDescription['ad_name']->renderError() ?>
+        <?php echo $adDescription['ad_mobile_text']->render(array('class' => 'required')) ?>
+        <?php echo $adDescription['ad_mobile_text']->renderError() ?>
+        <?php echo $adDescription['ad_link']->render(array('class' => 'required')) ?>
+        <?php echo $adDescription['ad_link']->renderError() ?>
+    </td>
+    <td>
+        <?php echo $adDescription['delete'] ?>
+        <?php echo $adDescription['delete']->renderError() ?>
+        <?php echo $adDescription['id'] ?>
+        <?php echo $adDescription['id']->renderError() ?>
+    </td>
+    </tr> 
+  <?php endforeach; ?>
+  </tbody>
+  </table>
+  <?php echo $form->renderHiddenFields(false) ?>
+  </fieldset>
+  &nbsp;
+  <table align="right">
+        <tbody>
+            <tr>
+            <td>
+                <a href="<?php echo url_for('ad/index?page='.$page) ?>" class="bt_red"><strong><?php echo __('Back to list') ?></strong></a>
+            </td>
+            <td>
+                <input type="submit" value="<?php echo __('Update') ?>" class="NFButton">
+            </td>
+            </tr>
+        </tbody>
+   </table>
 </form>
index 66cb305..d8d1419 100644 (file)
   <table>
     <tbody>
             <?php echo $form['company_logo']->renderRow(array('class' => 'required')) ?>
+            <?php echo $form['company_logo']->renderError() ?>
             <?php echo $form['company_cif']->renderRow(array('class' => 'required')) ?>
+            <?php echo $form['company_cif']->renderError() ?>
     </tbody>
   </table>
   <fieldset>
-  <legend><?php echo __('INTERNATIONALIZATION') ?></legend>
+  <legend class="optional"><?php echo __('INTERNATIONALIZATION') ?></legend>
   <table id="rounded-cornergus">
   <thead>
     <tr>
     <td><?php echo __('New Entry:') ?></td>
     <td>
         <?php echo $form['new']['language_id']->render(array('class' => 'validate-selection')) ?>
+        <?php echo $form['new']['language_id']->renderError() ?>
     </td>
     <td>
         <?php echo $form['new']['company_name']->render(array('class' => 'required')) ?>
+        <?php echo $form['new']['company_name']->renderError() ?>
         <?php echo $form['new']['id'] ?>
+        <?php echo $form['new']['id']->renderError() ?>
     </td>
     <td>
     </td>
     <td><?php echo __('Current Entry:') ?></td>
     <td>
         <?php echo $companyDescription['language_id']->render(array('class' => 'validate-selection')) ?>
+        <?php echo $companyDescription['language_id']->renderError() ?>
     </td>
     <td>
         <?php echo $companyDescription['company_name']->render(array('class' => 'required')) ?>
+        <?php echo $companyDescription['company_name']->renderError() ?>
     </td>
     <td>
         <?php echo $companyDescription['delete'] ?>
+        <?php echo $companyDescription['delete']->renderError() ?>
         <?php echo $companyDescription['id'] ?>
+        <?php echo $companyDescription['id']->renderError() ?>
     </td>
     </tr>
     <?php endforeach; ?>
index 612913c..f8de80f 100644 (file)
@@ -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())
     {
index 5d8879c..22ba8d1 100644 (file)
@@ -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");
+    }   
   }
 }
index e254b8e..ba02799 100644 (file)
@@ -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;
+}