Handling Files

Allikas: Juhised

Explanation[muuda]

The most complex file handling process takes place using the editor.

1. Loading the editor[muuda]

tennis24_insertingFile_editor_sequence.png

The editor can be loaded anywhere. First, we have to put a placeholder into the template and replace the placeholder by the content provided by the method buildWrapperForUpload in View. This method uses the template file upload.tpl and the part wrapper-for-uploading in it.

Inside the form for image, there is an iframe for the file browsing. The content of that iframe will be loaded by calling buildFormForUploading in the main controller. The actual content will be created by buildFormForUploading in View using upload.tpl and form-for-uploading in it.

2. Choosing a file to upload[muuda]

tennis24_uploadingFile_sequence.png When we have chosen a file for upload, the Javascript function upload is called that switches the progress indicator on and submits the file upload form.

The content of the form will be submitted using uploadFile in the main controller. The actual upload takes place in uploadForPreview in FileHandler. It removes all the files and folders in final and original previews' folder, checks for the correct file and puts the file into the original previews' folder. Subsequently, the upload form is reloaded into iframe. Now, a real preview is needed and therefore, buildPreview from View uses the block preview from file.tpl for creation of a preview. setUploadFile loads the file into the preview block using the named buildPreview function. As a result, we see the uploaded file. If it is an image we see a thumbnail, otherwise a file icon.

3. Putting the uploaded file into the text[muuda]

tennis24_insertingFileIntoText_sequence.png There is a small icon for putting the file link or image into the text. A click on it calls insertFile in the main controller which calls insertInEditor in FileHandler to create another preview for the text. insertInEditor checks whether the file is there and the alternative text is set. buildFileInEditor creates the new preview file and puts it with the help of file-in-text in upload.tpl into the text according to whether it is an image or not.

4. Putting the files into final places[muuda]

tennis24_saveUploadedFilesIntoContentInEditor_sequence.png The form fields of the editor will be submitted using handleObj which is a Javascript function available in sport.js. Parameters urlBeginning and typeOObj and typeOAction are the base to create the knowledge what the appropriate controller shall do as next. The controller calls the appropriate function that must do something with the object. That function calls saveFilesFromEditor from FileHandler that takes care of files and modifies the URL-s in the content returning the modified content that can be entered into the database.