Changeset 57

Show
Ignore:
Timestamp:
06/02/08 13:56:30
Author:
nperriault
Message:

Application add form, styles - still work in progress

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/apps/main/modules/applications/actions/actions.class.php

    r56 r57  
    1111  public function executeAdd(sfWebRequest $request) 
    1212  { 
    13     $this->form = new ApplicationForm(); 
    14      
    15     if ($request->isMethod('post') && $this->form->bindAndSave($request->getParameter('application'))) 
    16     { 
    17       //$this->updateFromRequest(); 
    18       parent::purgeObjectRelatedCache($this->form->getObject()); 
    19       $this->getUser()->setFlash('notice', $this->__('Application added')); 
    20       $this->getUser()->setAttribute('from_app_creation', true, 'symfonians'); 
    21       $this->redirect('@application_connect_as_developer?slug='.$this->application->getSlug()); 
    22     } 
     13    $this->forward('applications', 'edit'); 
    2314  } 
    2415 
     
    3021  public function executeEdit(sfWebRequest $request) 
    3122  { 
    32     $this->application = $this->getFromSlug(); 
    33  
    34     if (!$this->getUser()->isAdmin() && $this->application->getSubmitterId() != $this->getUser()->getId()) 
     23    $creation = false; 
     24     
     25    if (!$application = $this->getFromSlug()) 
     26    { 
     27      $application = new Application(); 
     28      $creation = true; 
     29      $this->setTemplate('add'); 
     30    } 
     31     
     32    if (!$creation && !$this->getUser()->isAdmin() && $application->getSubmitterId() != $this->getUser()->getId()) 
    3533    { 
    3634      $this->getUser()->setFlash('warning', $this->__('You are not allowed to edit this record')); 
    37       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
    38     } 
    39  
     35      $this->redirect('@application_page?slug='.$application->getSlug()); 
     36    } 
     37     
     38    $this->form = new ApplicationForm($application); 
     39    $this->form->setDefault('tags', $application->getTagsString()); 
     40    $this->application = $application; 
     41     
    4042    if ($request->isMethod('post')) 
    4143    { 
    42       $this->updateFromRequest(); 
    43       parent::purgeObjectRelatedCache($this->application); 
    44       $this->getUser()->setFlash('notice', $this->__('Application updated')); 
    45       $this->getUser()->setAttribute('from_app_creation', true, 'symfonians'); 
    46       $this->redirect('@application_page?slug='.$this->application->getSlug()); 
     44      // Set the submitter id from the session 
     45      $params = array_merge($request->getParameter('application'),  
     46                            array('submitter_id' => $this->getUser()->getId())); 
     47      $this->form->bind($params, $request->getFiles('application')); 
     48       
     49      if (!$this->form->isValid() or !$this->form->save()) 
     50      { 
     51        return sfView::SUCCESS; 
     52      } 
     53       
     54      $application = $this->form->getObject(); 
     55       
     56      // Process uploaded image file 
     57      $this->processUploadedImage($this->form->getValue('screenshot_path'), $application); 
     58       
     59      parent::purgeObjectRelatedCache($application); 
     60       
     61      if (isset($creation) && true === $this->creation) 
     62      { 
     63        $message = $this->__('Application added'); 
     64        $redirect = '@application_connect_as_developer?slug='.$application->getSlug(); 
     65      } 
     66      else 
     67      { 
     68        $message = $this->__('Application updated'); 
     69        $redirect = '@application_page?slug='.$application->getSlug(); 
     70      } 
     71       
     72      $this->getUser()->setFlash('notice', $message); 
     73      $this->getUser()->setAttribute('from_app_creation', $creation, 'symfonians'); 
     74      $this->redirect($redirect); 
    4775    } 
    4876  } 
     
    182210    // User is submitter? 
    183211    $this->user_is_submitter = $this->application->getSubmitterId() === $this->getUser()->getId(); 
    184   } 
    185  
    186   protected function getFromSlug($peer_method = null) 
    187   { 
    188     $slug = $this->getRequestParameter('slug'); 
    189     $c = new Criteria; 
    190     $c->addJoin(ApplicationPeer::SUBMITTER_ID, sfGuardUserPeer::ID, Criteria::LEFT_JOIN); 
    191     $c->add(ApplicationPeer::SLUG, $slug); 
    192     $application = ApplicationPeer::doSelectOne($c); 
    193     $this->forward404Unless($application, sprintf('Unable to retrieve application "%s"',$slug)); 
    194     return $application; 
    195212  } 
    196213 
     
    269286    $this->tags = TagPeer::getPopulars($c); 
    270287  } 
    271  
    272   public function handleErrorAdd() 
    273   { 
    274     $this->application = new Application(); 
    275     return sfView::SUCCESS; 
     288   
     289  /** 
     290   * Retrieves an Application object from the "slug" parameter, if exists 
     291   * 
     292   * @param  Criteria|null  $c  Optional Propel Criteria  
     293   * @return Application|null 
     294   */ 
     295  protected function getFromSlug(Criteria $c = null) 
     296  { 
     297    if (!$this->getRequestParameter('slug')) 
     298    { 
     299      return null; 
     300    } 
     301     
     302    if (!$c instanceof Criteria) 
     303    { 
     304      $c = new Criteria(); 
     305    } 
     306     
     307    $c->addJoin(ApplicationPeer::SUBMITTER_ID, sfGuardUserPeer::ID, Criteria::LEFT_JOIN); 
     308    $c->add(ApplicationPeer::SLUG, $this->getRequestParameter('slug')); 
     309     
     310    return ApplicationPeer::doSelectOne($c); 
    276311  } 
    277312 
     
    304339    $this->setTemplate('connectAsDeveloper'); 
    305340    return sfView::SUCCESS; 
     341  } 
     342   
     343  /** 
     344   * Process uploaded image file and updates passed Application object with the 
     345   * thumb path field updated 
     346   * 
     347   * @param  sfValidatedFile|null  $file         The uploaded file 
     348   * @param  Application           $application  The Application object instance 
     349   */ 
     350  protected function processUploadedImage($file, Application &$application) 
     351  { 
     352    if (is_null($file)) 
     353    { 
     354      return null; 
     355    } 
     356     
     357    $thumb = ImagesTools::createThumb ( 
     358      $file, 
     359      sfConfig::get('sf_upload_dir').DIRECTORY_SEPARATOR.sfConfig::get('app_applications_upload_dir', 'applications'), 
     360      md5($application_data->getName()).'.jpg', 
     361      sfConfig::get('app_applications_screenshot_width', 200), 
     362      sfConfig::get('app_applications_screenshot_height', 140), 
     363      sfConfig::get('app_applications_screenshot_mime', 'image/jpeg'), 
     364      sfConfig::get('app_applications_screenshot_quality', 90) 
     365    ); 
     366     
     367    $application->setScreenshotPath($thumb); 
    306368  } 
    307369 
  • trunk/apps/main/modules/applications/templates/_form.php

    r56 r57  
    1414    <fieldset> 
    1515      <legend><?php echo __('Application informations') ?></legend> 
    16       <?php echo $form ?> 
    17       <?php /* 
    18       <div class="form-row required"> 
    19         <label for="name"><?php echo __('Application name') ?></label> 
    20         <?php echo object_input_tag($application, 'getName', 'name=application[name]', $sf_params->get('application[name]')) ?> 
    21         <?php echo form_error('application[name]') ?> 
    22       </div> 
    23       <div class="form-row"> 
    24         <label for="homepage"><?php echo __('Application homepage, if publicly available') ?></label> 
    25         <?php echo object_input_tag($application, 'getHomepage', 'name=application[homepage]', $sf_params->getRawValue()->get('application[homepage]', 'http://')) ?> 
    26         <?php echo form_error('application[homepage]') ?> 
    27       </div> 
    28       <div class="form-row"> 
    29         <label for="description"><?php echo __('Description') ?></label> 
    30         <?php echo object_textarea_tag($application, 'getDescription', 'name=application[description] rows=8', $sf_params->get('application[description]')) ?> 
    31         <?php echo form_error('application[description]') ?> 
    32       </div> 
    33       <div class="form-row"> 
    34         <label for="tags"><?php echo __('Tags (comma separated, eg: tag1, tag2, tag3)') ?></label> 
    35         <?php echo object_input_tag($application, 'getTagsString', 'name=application[tags]', $sf_params->get('application[tags]')) ?> 
    36         <?php echo form_error('application[tags]') ?> 
    37       </div> 
    38       */ ?> 
     16      <?php echo $form['name']->renderRow() ?> 
     17      <?php echo $form['homepage']->renderRow() ?> 
     18      <?php echo $form['description']->renderRow() ?> 
     19      <?php echo $form['tags']->renderRow() ?> 
    3920    </fieldset> 
    4021  </div> 
     
    4223    <fieldset> 
    4324      <legend><?php echo __('Other informations') ?></legend> 
    44       <?php /* 
     25      <?php echo $form['country']->renderRow() ?> 
     26      <?php echo $form['screenshot_path']->renderRow() ?> 
    4527      <div class="form-row"> 
    46         <label for="country"><?php echo __('Country') ?></label> 
    47         <?php echo object_select_country_tag($application, 'getCountry', 'name=application[country] include_custom='.__('Select a country'), $sf_params->getRawValue()->get('application[country]')) ?> 
    48         <?php echo form_error('application[country]') ?> 
     28        <?php echo $form['is_opensource'] ?> 
     29        <?php echo $form['is_opensource']->renderLabel(__('Is this application open source?'), array('class' => 'inline')) ?> 
    4930      </div> 
    50       <div class="form-row"> 
    51         <label for="screenshot_path"><?php echo __('Screenshot') ?></label> 
    52         <?php echo input_file_tag('application[screenshot_path]') ?> 
    53         <?php echo form_error('application[screenshot_path]') ?> 
     31      <?php echo $form['licence']->renderRow(array(), __('If application is open source, how is it licensed?')) ?> 
     32      <?php echo $form['feed_url']->renderRow() ?> 
     33      <div class="date_select"> 
     34        <?php echo $form['started_at']->renderRow() ?> 
     35        <?php echo $form['released_at']->renderRow() ?> 
    5436      </div> 
    55       <div class="form-row"> 
    56         <?php echo object_checkbox_tag($application, 'getIsOpensource', 'name=application[is_opensource]', $sf_params->get('application[is_opensource]')) ?> 
    57         <label for="is_opensource" class="inline"> 
    58           <?php echo __('Application is open source') ?> 
    59         </label> 
    60         <?php echo form_error('application[is_opensource]') ?> 
    61       </div> 
    62       <div class="form-row"> 
    63         <label for="licence"><?php echo __('Licence (if open source)') ?></label> 
    64         <?php echo object_input_tag($application, 'getLicence', 'name=application[licence]', $sf_params->get('application[licence]')) ?> 
    65         <?php echo form_error('application[licence]') ?> 
    66       </div> 
    67       <div class="form-row"> 
    68         <label for="feed_url"><?php echo __('Application development feed url') ?></label> 
    69         <?php echo object_input_tag($application, 'getFeedUrl', 'name=application[feed_url]', $sf_params->getRawValue()->get('application[feed_url]', 'http://')) ?> 
    70         <?php echo form_error('application[feed_url]') ?> 
    71       </div> 
    72       <div class="form-row"> 
    73         <label for="started_at"><?php echo __('Development start date (yyyy-mm-dd)') ?></label> 
    74         <?php echo object_input_date_tag($application, 'getStartedAt', 'name=application[started_at] format=Y-MM-dd rich=true class=date_select', $sf_params->get('application[started_at]')) ?> 
    75         <?php echo form_error('application[started_at]') ?> 
    76       </div> 
    77       <div class="form-row"> 
    78         <label for="released_at"><?php echo __('Release date (yyyy-mm-dd)') ?></label> 
    79         <?php echo object_input_date_tag($application, 'getReleasedAt', 'name=application[released_at] format=Y-MM-dd rich=true class=date_select', $sf_params->get('application[released_at]')) ?> 
    80         <?php echo form_error('application[released_at]') ?> 
    81       </div> 
    82       */ ?> 
    8337    </fieldset> 
    8438  </div> 
    8539  <div class="form-row" style="text-align:center;clear:left;"> 
    8640    <p> 
     41      <?php echo $form['_csrf_token'] ?> 
    8742      <input type="submit" value="<?php echo $submit_label ?>" /> 
    8843    </p> 
  • trunk/apps/main/modules/applications/templates/editSuccess.php

    r2 r57  
    11<?php slot('page_title') ?> 
    22  <?php $page_title = __('Update %name% application informations',  
    3                          array('%name%' => $application->getRawValue()->getName())) ?> 
     3                         array('%name%' => $form->getObject()->getName())) ?> 
    44  <?php echo $page_title ?> 
    55<?php end_slot() ?> 
    66 
    77<?php include_partial('applications/form', 
    8                       array('application'  => $application, 
     8                      array('application'  => $form->getObject(), 
     9                            'form'         => $form, 
    910                            'title'        => $page_title, 
    10                             'form_route'   => '@application_edit?slug='.$application->getSlug(), 
     11                            'form_route'   => '@application_edit?slug='.$form->getObject()->getSlug(), 
    1112                            'submit_label' => __('Update application informations'))) ?> 
  • trunk/lib/form/application/ApplicationForm.class.php

    r56 r57  
    1111  public function configure() 
    1212  { 
    13     unset($this['created_at'], $this['updated_at']); 
     13    $context = sfContext::getInstance(); 
     14    $culture = $context->getUser()->getCulture(); 
     15    sfLoader::loadHelpers('I18n'); 
     16     
     17    // Unset unused widgets 
     18    unset($this['created_at'],  
     19          $this['updated_at'], 
     20          $this['slug'],  
     21          $this['is_featured']); 
     22     
     23    // Overriding widgets 
     24    $this->widgetSchema['tags']               = new sfWidgetFormInput(); 
     25    $this->widgetSchema['screenshot_path']    = new sfWidgetFormInputFile(); 
     26    $this->widgetSchema['country']            = new sfWidgetFormI18nSelectCountry(array('culture' => $culture)); 
     27    $this->widgetSchema['started_at']         = new sfWidgetFormI18nDate(array('culture' => $culture)); 
     28    $this->widgetSchema['released_at']        = new sfWidgetFormI18nDate(array('culture' => $culture)); 
     29     
     30    // Overriding validators 
     31    $this->validatorSchema['tags']            = new sfValidatorRegex(array('pattern' => '/[0-9\w-_ ]/i', 'required' => false)); 
     32    $this->validatorSchema['screenshot_path'] = new sfValidatorFile(array('max_size' => 512000, 'required' => false));  
     33    $this->validatorSchema['country']         = new sfValidatorI18nChoiceCountry(array('culture' => $culture, 'required' => false)); 
     34    $this->validatorSchema['started_at']      = new sfValidatorDate(array('required' => false)); 
     35    $this->validatorSchema['ended_at']        = new sfValidatorDate(array('required' => false)); 
     36     
     37    // Redefined validators 
     38    $this->validatorSchema['homepage'] = new sfValidatorUrl(); 
     39    $this->validatorSchema['feed_url'] = new sfValidatorOr(array( 
     40      new sfValidatorUrl(), 
     41      new sfValidatorChoice(array('choices' => array('http://', ''))), 
     42    ), array('required' => false)); 
     43     
     44    // Defaults 
     45    $this->setDefaults(array('homepage'    => 'http://', 
     46                             'feed_url'    => 'http://', 
     47                             'released_at' => 'today', // thanks strtotime() 
     48                             'is_featured' => null)); 
    1449  } 
    1550} 
  • trunk/lib/model/Application.php

    r49 r57  
    163163    $c->add(ApplicationDeveloperPeer::DEVELOPER_ID, $user); 
    164164    return ($this->countApplicationDevelopers($c) > 0); 
    165   } 
    166  
    167   /** 
    168    * Sets is_featured field and update according relations 
    169    * 
    170    * @param  boolean $flag 
    171    */ 
    172   public function setIsFeatured($flag) 
    173   { 
    174     if ($flag && !$this->getIsFeatured()) 
    175     { 
    176       // Flag all apps as unfeatured 
    177       $c = new Criteria(); 
    178       $c->add(ApplicationPeer::IS_FEATURED, false); 
    179       ApplicationPeer::doUpdate($c); 
    180     } 
    181     parent::setIsFeatured($flag); 
    182   } 
    183  
    184   /** 
    185    * Sets app homepage url 
    186    * 
    187    * @param  string $v 
    188    */ 
    189   public function setHomepage($v) 
    190   { 
    191     if (trim(strtolower($v)) === 'http://') 
    192     { 
    193       $v = null; 
    194     } 
    195     parent::setHomepage($v); 
    196   } 
    197  
    198   /** 
    199    * Sets app feed url 
    200    * 
    201    * @param  string $v 
    202    */ 
    203   public function setFeedUrl($v) 
    204   { 
    205     if (trim(strtolower($v)) === 'http://') 
    206     { 
    207       $v = null; 
    208     } 
    209     parent::setFeedUrl($v); 
    210165  } 
    211166 
     
    280235    return $save; 
    281236  } 
     237   
     238  /** 
     239   * Sets the feed url value 
     240   * 
     241   * @param string $v 
     242   */ 
     243  public function setFeedUrl($v) 
     244  { 
     245    if ('http://' == trim(strtolower($v))) 
     246    { 
     247      $v = null; 
     248    } 
     249     
     250    return parent::setFeedUrl($v); 
     251  } 
     252   
     253  /** 
     254   * Sets the homepage url value 
     255   * 
     256   * @param string $v 
     257   */ 
     258  public function setHomepage($v) 
     259  { 
     260    if ('http://' == trim(strtolower($v))) 
     261    { 
     262      $v = null; 
     263    } 
     264     
     265    return parent::setHomepage($v); 
     266  } 
     267   
     268  /** 
     269   * Sets is_featured field and update according relations 
     270   * 
     271   * @param  boolean $flag 
     272   */ 
     273  public function setIsFeatured($flag) 
     274  { 
     275    if ($flag && !$this->getIsFeatured()) 
     276    { 
     277      // Flag all apps as unfeatured 
     278      $c = new Criteria(); 
     279      $c->add(ApplicationPeer::IS_FEATURED, false); 
     280      ApplicationPeer::doUpdate($c); 
     281    } 
     282    parent::setIsFeatured($flag); 
     283  } 
     284   
     285  /** 
     286   * Sets application tags, only if application has already been saved 
     287   * 
     288   * @param array|string $tags  Tags for the application 
     289   */ 
     290  public function setTags($tags) 
     291  { 
     292    if ($this->isNew()) 
     293    { 
     294      return; 
     295    } 
     296     
     297    $this->removeAllTags(); 
     298    $this->addTag($tags); 
     299  } 
    282300 
    283301} 
  • trunk/lib/symfonians/ImagesTools.class.php

    r48 r57  
    1010   * Creates a thumbnail from an uploaded image file 
    1111   *  
     12   * @param  sfValidatedFile  Validated uploaded file 
    1213   * @throws sfException   
    1314   */ 
    14   public static function createThumb($source_field_name,  
     15  public static function createThumb(sfValidatedFile $file,  
    1516                                     $destination_dir,  
    1617                                     $filename,  
     
    2122                                     $options = array()) 
    2223  { 
    23     $request = sfContext::getInstance()->getRequest(); 
    24      
    25     sfContext::getInstance()->getLogger()->info('{ImagesTools} Thumbnail creation parameters: '.var_export(func_get_args(), true)); 
    26      
    27     if (!$request->hasFiles()) 
    28     { 
    29       return null; 
    30     } 
    31      
    3224    if (!is_dir($destination_dir) && !@mkdir($destination_dir)) 
    3325    { 
     
    3628    } 
    3729     
    38     $screenshot = $request->getFile($source_field_name); 
    39     if (is_null($screenshot) or $screenshot == '') 
    40     { 
    41       return null; 
    42     } 
    43      
    44     $source_path = $request->getFilePath($source_field_name); 
    45     if (!$source_path) 
    46     { 
    47       return null; 
    48     } 
     30    $source_path = $file->getTempName(); 
    4931     
    5032    switch ($export_mime) 
     
    139121      } 
    140122    } 
    141     return $errors > 0
     123    return ($errors > 0)
    142124  } 
    143125 
  • trunk/web/css/style.css

    r52 r57  
    696696} 
    697697 
     698div.date_select select { 
     699  width: inherit; 
     700} 
     701 
    698702label { 
    699703  display: block;