developer.jelix.org is not used any more and exists only for history. Post new tickets on the Github account.
developer.jelix.org n'est plus utilisée, et existe uniquement pour son historique. Postez les nouveaux tickets sur le compte github.

Ticket #1433: upload-crud.diff

File upload-crud.diff, 10.8 KB (added by lhapaipai, 8 years ago)
  • .gitignore

    diff --git a/.gitignore b/.gitignore
    index e57d9a2..e129a1a 100644
    a b _dev/ 
    55*.komodoproject
    66.komodotools
    77*.kdev4
     8/nbproject/private/
     9 No newline at end of file
  • build/manifests/testapp.mn

    diff --git a/build/manifests/testapp.mn b/build/manifests/testapp.mn
    index 6cf304f..088fda6 100644
    a b cd testapp/modules/jelix_tests/install 
    153153  install.pgsql.sql
    154154  upgrade_to_1.3RC1.2079_productdate.php
    155155  upgrade_to_1.3RC2.2100_jacl2db.php
     156  upgrade_to_1.6.0a1pre.2969_productpicture.php
    156157cd testapp/modules/jelix_tests/locales/
    157158  test_A.properties
    158159  test_B.properties
  • lib/jelix/core-modules/jelix/locales/en_EN/jforms.UTF-8.properties

    diff --git a/lib/jelix/core-modules/jelix/locales/en_EN/jforms.UTF-8.properties b/lib/jelix/core-modules/jelix/locales/en_EN/jforms.UTF-8.properties
    index 07be2a3..3dda29c 100644
    a b date.day.label = Day 
    44
    55time.hour.label = Hour
    66time.minutes.label = Minutes
    7 time.seconds.label = Seconds
    8  No newline at end of file
     7time.seconds.label = Seconds
     8
     9upload.file.label = File
     10upload.delete.label = Delete
     11 No newline at end of file
  • lib/jelix/core-modules/jelix/locales/en_GB/jforms.UTF-8.properties

    diff --git a/lib/jelix/core-modules/jelix/locales/en_GB/jforms.UTF-8.properties b/lib/jelix/core-modules/jelix/locales/en_GB/jforms.UTF-8.properties
    index 0907fda..c51aa59 100644
    a b date.day.label = Day 
    77
    88time.hour.label = Hour
    99time.minutes.label = Minutes
    10 time.seconds.label = Seconds
    11  No newline at end of file
     10time.seconds.label = Seconds
     11
     12upload.file.label = File
     13upload.delete.label = Delete
     14 No newline at end of file
  • lib/jelix/core-modules/jelix/locales/en_US/jforms.UTF-8.properties

    diff --git a/lib/jelix/core-modules/jelix/locales/en_US/jforms.UTF-8.properties b/lib/jelix/core-modules/jelix/locales/en_US/jforms.UTF-8.properties
    index 0907fda..c51aa59 100644
    a b date.day.label = Day 
    77
    88time.hour.label = Hour
    99time.minutes.label = Minutes
    10 time.seconds.label = Seconds
    11  No newline at end of file
     10time.seconds.label = Seconds
     11
     12upload.file.label = File
     13upload.delete.label = Delete
     14 No newline at end of file
  • lib/jelix/core-modules/jelix/locales/fr_FR/jforms.UTF-8.properties

    diff --git a/lib/jelix/core-modules/jelix/locales/fr_FR/jforms.UTF-8.properties b/lib/jelix/core-modules/jelix/locales/fr_FR/jforms.UTF-8.properties
    index 071a20b..d4419bc 100644
    a b date.day.label = Jour 
    77
    88time.hour.label = Heure
    99time.minutes.label = Minutes
    10 time.seconds.label = Secondes
    11  No newline at end of file
     10time.seconds.label = Secondes
     11
     12upload.file.label = Fichier
     13upload.delete.label = Supprimer
     14 No newline at end of file
  • lib/jelix/forms/controls/jFormsControlUpload.class.php

    diff --git a/lib/jelix/forms/controls/jFormsControlUpload.class.php b/lib/jelix/forms/controls/jFormsControlUpload.class.php
    index 0c92827..0740e11 100644
    a b  
    33* @package     jelix
    44* @subpackage  forms
    55* @author      Laurent Jouanneau
    6 * @contributor Julien Issler
     6* @contributor Julien Issler, Hugues Tavernier
    77* @copyright   2006-2008 Laurent Jouanneau
    8 * @copyright   2009 Julien Issler
     8* @copyright   2009 Julien Issler, 2013 Hugues Tavernier
    99* @link        http://www.jelix.org
    1010* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
    1111*/
    class jFormsControlUpload extends jFormsControl { 
    2929            $this->fileInfo = array('name'=>'','type'=>'','size'=>0,'tmp_name'=>'', 'error'=>UPLOAD_ERR_NO_FILE);
    3030
    3131        if($this->fileInfo['error'] == UPLOAD_ERR_NO_FILE) {
    32             if($this->required)
     32            if($this->required && $this->container->data[$this->ref] == '')
    3333                return $this->container->errors[$this->ref] = jForms::ERRDATA_REQUIRED;
    3434        }else{
    3535            if($this->fileInfo['error'] == UPLOAD_ERR_NO_TMP_DIR
    class jFormsControlUpload extends jFormsControl { 
    6060    }
    6161
    6262    function setValueFromRequest($request) {
    63         if(isset($_FILES[$this->ref])){
    64             $this->setData($_FILES[$this->ref]['name']);
    65         }else{
     63        $params = $request->getParam($this->ref, array('delete' => false));
     64        if (isset($_FILES[$this->ref])) {
     65            // do not overwrite the previous value until the upload has succeeded
     66            if ($_FILES[$this->ref]['error'] == UPLOAD_ERR_OK || $this->container->data[$this->ref] == '') {
     67                $this->setData($_FILES[$this->ref]['name']);
     68            } else if ($params['delete'] == true) {
     69                $this->setData('');
     70            }
     71        } else {
    6672            $this->setData('');
    6773        }
    6874    }
  • lib/jelix/plugins/formwidget/upload_html/upload_html.formwidget.php

    diff --git a/lib/jelix/plugins/formwidget/upload_html/upload_html.formwidget.php b/lib/jelix/plugins/formwidget/upload_html/upload_html.formwidget.php
    index b20b5a0..fff3500 100644
    a b  
    33* @package     jelix
    44* @subpackage  formwidgets
    55* @author      Claudio Bernardes
    6 * @contributor Laurent Jouanneau, Julien Issler, Dominique Papin
     6* @contributor Laurent Jouanneau, Julien Issler, Dominique Papin, Hugues Tavernier
    77* @copyright   2012 Claudio Bernardes
    8 * @copyright   2006-2012 Laurent Jouanneau, 2008-2011 Julien Issler, 2008 Dominique Papin
     8* @copyright   2006-2012 Laurent Jouanneau, 2008-2011 Julien Issler, 2008 Dominique Papin, 2013 Hugues Tavernier
    99* @link        http://www.jelix.org
    1010* @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
    1111*/
    class upload_htmlFormWidget extends \jelix\forms\HtmlWidget\WidgetBase { 
    2121    protected function outputJs() {
    2222        $ctrl = $this->ctrl;
    2323        $jFormsJsVarName = $this->builder->getjFormsJsVarName();
     24
     25        if ($this->getValue($this->ctrl)) {
     26            $this->ctrl->required = false;
     27        }
    2428       
    2529        $this->parentWidget->addJs("c = new ".$jFormsJsVarName."ControlString('".$ctrl->ref."', ".$this->escJsStr($ctrl->label).");\n");
    2630        $this->commonJs();
    class upload_htmlFormWidget extends \jelix\forms\HtmlWidget\WidgetBase { 
    3236        /*if($this->ctrl->maxsize){
    3337            echo '<input type="hidden" name="MAX_FILE_SIZE" value="',$this->ctrl->maxsize,'"','/>';
    3438        }*/
     39        $this->_outputUploadControlUploader($attr);
     40        if ($previousFileName = $this->getValue($this->ctrl)) {
     41            echo '<span>'.jLocale::get('jelix~jforms.upload.file.label').' : '.$previousFileName.'</span>';
     42            if (!$this->ctrl->required)
     43                $this->_outputUploadControlDelete($attr, $previousFileName);
     44        }
     45        $this->outputJs();
     46    }
     47   
     48    protected function _outputUploadControlUploader($attr) {
    3549        $attr['type'] = 'file';
    3650        $attr['value'] = '';
    3751        echo '<input';
    3852        $this->_outputAttr($attr);
    3953        echo "/>\n";
    40         $this->outputJs();
     54    }
     55   
     56    protected function _outputUploadControlDelete($attr) {
     57        $attr['type'] = 'checkbox';
     58        $attr['id'] .= '_delete';
     59        $attr['name'] .= '[delete]';
     60        echo '<input';
     61        $this->_outputAttr($attr);
     62        echo '/>';
     63       
     64        echo '<label for="'.$attr['id'].'">'.jLocale::get('jelix~jforms.upload.delete.label')."</label>\n";
    4165    }
    4266}
  • testapp/modules/jelix_tests/install/install.mysql.sql

    diff --git a/testapp/modules/jelix_tests/install/install.mysql.sql b/testapp/modules/jelix_tests/install/install.mysql.sql
    index 3b9ba9e..ed1a911 100644
    a b CREATE TABLE IF NOT EXISTS `products` ( 
    3838`name` VARCHAR( 150 ) NOT NULL ,
    3939`price` FLOAT   default '0',
    4040`promo` BOOL NOT NULL,
    41 `publish_date` DATE NOT NULL
     41`publish_date` DATE NOT NULL,
     42`picture` varchar(150) DEFAULT NULL
    4243) ENGINE = MYISAM ;
    4344
    4445
  • testapp/modules/jelix_tests/install/install.pgsql.sql

    diff --git a/testapp/modules/jelix_tests/install/install.pgsql.sql b/testapp/modules/jelix_tests/install/install.pgsql.sql
    index 02b6597..93009ee 100644
    a b CREATE TABLE products ( 
    4646    id serial NOT NULL,
    4747    name character varying(150) NOT NULL,
    4848    price real DEFAULT 0,
    49     promo boolean NOT NULL
     49    promo boolean NOT NULL,
     50    picture character varying(150) DEFAULT NULL
    5051);
    5152
    5253SELECT pg_catalog.setval(pg_catalog.pg_get_serial_sequence('products', 'id'), 1, false);
  • testapp/modules/jelix_tests/install/upgrade_to_1.6.0a1pre.2969_productpicture.php

    diff --git a/testapp/modules/jelix_tests/install/upgrade_to_1.6.0a1pre.2969_productpicture.php b/testapp/modules/jelix_tests/install/upgrade_to_1.6.0a1pre.2969_productpicture.php
    index ab2e6ee..7f1d44e 100644
    a b  
    11<?php
    22
    3 
    4 class jelix_testsModuleUpgrader_productdate extends jInstallerModule {
     3class jelix_testsModuleUpgrader_productpicture extends jInstallerModule {
    54
    65    function install() {
    76        if (!$this->firstDbExec()) {
    87            return;
    98        }
    109        $db = $this->dbConnection();
    11         $db->exec("ALTER TABLE ".$db->prefixTable('products')." ADD `publish_date` DATE NOT NULL");
     10        $db->exec("ALTER TABLE ".$db->prefixTable('products')." ADD `picture` VARCHAR( 150 ) NULL");
    1211    }
    1312}
     13 No newline at end of file
  • testapp/modules/testapp/daos/products.dao.xml

    diff --git a/testapp/modules/testapp/daos/products.dao.xml b/testapp/modules/testapp/daos/products.dao.xml
    index 47ca0b1..25500be 100644
    a b  
    99      <property name="price" fieldname="price" datatype="float"/>
    1010      <property name="promo" fieldname="promo" datatype="boolean"/>
    1111      <property name="publish_date" datatype="date" />
     12      <property name="picture" fieldname="picture" datatype="string"/>
    1213   </record>
    1314</dao>
    1415
  • testapp/modules/testapp/forms/products.form.xml

    diff --git a/testapp/modules/testapp/forms/products.form.xml b/testapp/modules/testapp/forms/products.form.xml
    index 04c572d..ecfe363 100644
    a b  
    1616     <label>Une date</label>
    1717   </date>
    1818
     19  <upload ref="picture" mimetype="image/gif;image/png;" maxsize="50000">
     20     <label>Product photo (gif/png &lt; 50ko)</label>
     21     <alert>The file should be a gif or png image, under 50000 octets</alert>
     22  </upload>
     23 
    1924  <submit ref="valid">
    2025    <label>Save</label>
    2126  </submit>