Changeset 740

Show
Ignore:
Timestamp:
08/24/08 10:46:59 (3 months ago)
Author:
camper
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/AjaxFileUploader.php

    r737 r740  
    44 * There is the only way I've found to do this: through IFrames. 
    55 * The example I used as a basement is on the http://web-tec.info/2007/09/09/ajax_fundamentals_iframe/ 
    6  *  
     6 * 
    77 * Usage: 
    88 * 1) Form which would upload file through Ajax should NOT be submitted by submitForm(), 
    99 *    use Ajax::uploadFile() instead: 
    10  *     
     10 * 
    1111 *    $form->addButton('Submit')->uploadFile($form,$form->getElement('file')->name); 
    1212 * 2) AjaxFileUploader class will be created and used to handle file upload. You can configure 
    1313 *    directory where uploaded files will be stored in config file 
    14  *  
     14 * 
    1515 *    $config['ajax_uploads_dir']='/uploads'; 
    1616 *    uploads/ dir in project root will be used by default. 
    1717 * 3) You can reach uploaded file by calling: 
    18  *  
     18 * 
    1919 *    $file=$this->api->getElement('uploader')->getFile(); 
    2020 *    $file_path=$this->api->getElement('uploader')->getFilePath(); 
    2121 * 4) Form is submitted from upload JS code after file is uploaded 
    22  *  
     22 * 
    2323 * Ajax uploads use JS script functions from the ajax.js: 
    2424 * createIFrame() 
    2525 * submitUpload() 
    2626 * sendComplete() 
    27  *  
     27 * 
    2828 * If no file specified in the form, nothing done and form is simply submitted 
    29  *  
     29 * 
    3030 * You may upgrade and improve this class on your own, probably it is not the best implementation. 
    31  *  
     31 * 
    3232 * Created on 21.06.2008 by *Camper* (camper@adevel.com) 
    3333 */ 
     
    3535        protected $file_path=''; 
    3636        protected $mime_type=null; 
    37          
     37 
    3838        function init(){ 
    3939                parent::init(); 
     
    4848        } 
    4949        function getFilePath(){ 
    50                 return $this->file_path; 
     50                if(!$this->file_path)return ''; 
     51                return (defined('BASEDIR')?BASEDIR.'/':'').$this->file_path; 
    5152        } 
    5253        function setFilePath($path){ 
  • trunk/lib/Form/Field.php

    r736 r740  
    142142        $this->template->trySet('field_caption',$this->caption?($this->caption.$this->separator):''); 
    143143        $this->template->trySet('field_name',$this->name); 
    144         $this->template->trySet('field_comment',$this->comment);              
    145         $this->template->set('field_input',$this->field_prepend.$this->getInput().$this->field_append);    
     144        $this->template->trySet('field_comment',$this->comment); 
     145        $this->template->set('field_input',$this->field_prepend.$this->getInput().$this->field_append); 
    146146        $this->template->trySet('field_error', 
    147147                             isset($this->owner->errors[$this->short_name])? 
     
    217217         * --> <a href="foo.html"><b>click here</b></a> 
    218218         */ 
    219           
     219 
    220220        if(is_string($attr)){ 
    221221            $value=$attr; 
     
    302302        $this->setNoSave(); 
    303303    } 
    304      
     304 
    305305    function getInput($attr=array()){ 
    306306        if (isset($this->value_list)){ 
     
    313313        $this->value_list = $list; 
    314314    } 
    315      
     315 
    316316} 
    317317class Form_Field_File extends Form_Field { 
     
    326326                $this->name=$this->short_name='MAX_FILE_SIZE'; 
    327327                parent::init(); 
     328                $this->no_save=true; 
    328329        } 
    329330} 
    330331class Form_Field_Time extends Form_Field { 
    331332        function getInput($attr=array()){ 
    332         return parent::getInput(array_merge(array('type'=>'text',  
     333        return parent::getInput(array_merge(array('type'=>'text', 
    333334                        'value'=>format_time($this->value)),$attr)); 
    334335        } 
     
    337338        private $sep = '-'; 
    338339        private $is_valid = false; 
    339          
     340 
    340341        /*function getInput($attr=array()){ 
    341         return parent::getInput(array_merge(array('type'=>'text',  
     342        return parent::getInput(array_merge(array('type'=>'text', 
    342343                        'value'=>($this->is_valid ? date('Y-m-d', $this->value) : $this->value)),$attr)); 
    343344        }*/ 
     
    357358                        $c = split($this->sep, $this->value); 
    358359                        //day must go first, month should be second and a year should be last 
    359                         if(strlen($c[0]) != 4 ||  
    360                                 $c[1] <= 0 || $c[1] > 12 ||  
     360                        if(strlen($c[0]) != 4 || 
     361                                $c[1] <= 0 || $c[1] > 12 || 
    361362                                $c[2] <= 0 || $c[2] > 31) 
    362363                        { 
     
    381382    } 
    382383    function getInput($attr=array()){ 
    383          
     384 
    384385        // Disable the deny edit here < 
    385386        if (is_null($this->onkeypress)) { 
    386387            $this->onKeyPress(); 
    387388        } 
    388          
    389         return  
     389 
     390        return 
    390391            parent::getInput(array_merge(array(''=>'textarea'),$attr)). 
    391392            htmlspecialchars(stripslashes($this->value)). 
     
    399400} 
    400401 
    401 // The following clases operates with predefined value lists.  
     402// The following clases operates with predefined value lists. 
    402403// User is picking one or several options 
    403404class Form_Field_ValueList extends Form_Field { 
     
    426427        } else { 
    427428            if(isset($_POST[$this->name]))$this->set($data); 
    428         }  
     429        } 
    429430    } 
    430431} 
     
    512513        return $output; 
    513514    } 
    514      
     515 
    515516    function loadPOST(){ 
    516517        $data=$_POST[$this->name]; 
    517518        if(is_array($data)) 
    518519           $data=join(',',$data); 
    519         else  
     520        else 
    520521           $data=''; 
    521522 
     
    525526        } else { 
    526527            $this->set($data); 
    527         }  
    528     }     
     528        } 
     529    } 
    529530} 
    530531