EasyUI Forum
May 19, 2024, 06:31:36 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Browse for file in inline edit field of edatagrid...  (Read 8762 times)
bwwelle
Newbie
*
Posts: 8


View Profile Email
« on: December 06, 2013, 01:00:05 PM »

Hello,
I have a edatagrid in which the field, when the user clicks on it, needs to have a window that pops up to that they can browse for a file on the local machine, and then when they press ok on the window, the path of the file is entered into the field thumbnailfilename.  Can this be done with easyui functionality?  If so what would the code look like?  Thanks.

The html code:
Code:
<table id="videodg" title="Videos" style="width:700px;height:250px" toolbar="#videotoolbar" pagination="true" idfield="id"
    rownumbers="true" fitcolumns="true" singleselect="true">
      <thead>
        <tr>
          <th field="videoname" width="50" editor="{type:'validatebox',options:{required:true}}">Video Name</th>
 <th field="videocode" width="50" editor="{type:'validatebox',options:{required:true}}">Video Code</th>
 <th field="thumbnailfilename" width="50" class="easyui-validatebox" editor="{type:'file',options:{required:true}}">Thumbnail File Name</th>
        </tr>
      </thead>
    </table>
    <div id="videotoolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true"
    onclick="javascript:$('#videodg').edatagrid('addRow')">New</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true"
    onclick="javascript:$('#videodg').edatagrid('destroyRow')">Destroy</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-save" plain="true"
    onclick="javascript:$('#videodg').edatagrid('saveRow')">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-undo" plain="true"
    onclick="javascript:$('#videodg').edatagrid('cancelRow')">Cancel</a></div>
    <script type="text/javascript">
                $(function(){
                        $('#videodg').edatagrid({
                                url: 'get_videos.php',
                                saveUrl: 'save_video.php',
                                updateUrl: 'update_video.php',
                                destroyUrl: 'destroy_video.php'
                        });
                });
        
</script>
Logged
finzaiko
Newbie
*
Posts: 44


View Profile
« Reply #1 on: December 06, 2013, 08:05:16 PM »

I've made similar before, first create an inline crud as usual using edatagrid and then make an upload + image resize (kohana image class) function and update the file name to the database.
may like screenshot like this

i use yii :
Code:
class AttachController extends Controller {

    function actionIndex() {
        $dir = 'uploads';
        $uploaded = false;

        $model = new Attach();

        if (isset($_POST['Attach'])) {
            $model->attributes = $_POST['Attach'];
            $this->deleteFile($model->id);
           
            $file = CUploadedFile::getInstance($model, 'file');
            $initFile = date('YmdHis');
            if ($model->validate()) {
                $item = $this->loadItemModel($model->id);
                $item->file_path = $initFile;
                $item->save(false);
                $imgFile = strtolower('img'.$initFile.'.'.$file->extensionName);
                $imgPath = $dir . '/' . $imgFile;
                $thmFile = strtolower('thm'.$initFile.'.'.$file->extensionName);
                $thmPath = $dir . '/' . $thmFile;
                $uploaded = $file->saveAs($imgPath);
                $this->resizeImg($imgPath,$thmPath);
                echo CJSON::encode(array('success' => true));
            }else{
                echo CJSON::encode(array('msg' => 'Failed upload file.'));
            }
        }
    }
   
    function resizeImg($path,$newPath) {
        $img = Yii::app()->image->load($path);
        $img->resize(150,150);
        $img->save($newPath);
    }
....
... other function
.......




May it help
Logged
bwwelle
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: December 07, 2013, 04:56:41 PM »

Thank you so much for the response.  So I'm a confused on how to integrated the class you provided into the html code that I displayed in my original post, specifically on the "thumbnailfilname" field line.  Can you point me in the right direction?  Thanks again!
Logged
finzaiko
Newbie
*
Posts: 44


View Profile
« Reply #3 on: December 08, 2013, 06:39:43 PM »

That class if you're using Yii Framework, I haven't use pure php yet,
please refer to this http://hayageek.com/ajax-file-upload-jquery/
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!