Yii Eajaxupload和cJuiDialog

时间:2013-03-19 12:38:28

标签: ajax yii renderpartial cjuidialog

按钮Eajaxupload未在CjuiDialog中显示,但在标准格式下效果很好。

查看Entradas:

<?php

              $this->widget('ext.EAjaxUpload.EAjaxUpload', array(
                 'id'=>'image',
                 'config'=>array(
                 'action'=>Yii::app()->createUrl('/entradas/upload'),
                 'allowedExtensions'=>array("jpg", "jpeg", "png", "gif"),
                 'sizeLimit'=>8*1024*1024,// maximum file size in bytes
                 'onSubmit'=>"js:function(file, extension) { 
                                $('div.preview').addClass('loading');
                              }",
                 'onComplete'=>"js:function(file, response, responseJSON) {
                                  $('#thumb').load(function(){
                                    $('div.preview').removeClass('loading');
                                    $('#thumb').unbind();
                                    $('#Associazioni_logo').val(responseJSON['filename']);
                                  });
                                  $('#thumb').attr('src', '/../images/temp/'+responseJSON['filename']);
                                }",
            'messages'=>array(
                    'typeError'=>"{file} has invalid extension. Only {extensions} are allowed.",
                    'sizeError'=>"{file} is too large, maximum file size is {sizeLimit}.",
                    'emptyError'=>"{file} is empty, please select files again without it.",
                    'onLeave'=>"The files are being uploaded, if you leave now the upload will be cancelled."
                ),
              )
            ));     
            ?>

controller创建Entrada

public function actionCreate()
    {
        $model=new Entradas;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if(isset($_POST['Entradas']))
        {
            $model->attributes=$_POST['Entradas'];
            if($model->save()){
                    if (Yii::app()->request->isAjaxRequest)
                    {
                        echo CJSON::encode(array(
                            'status'=>'success', 
                            'div'=>"Tu creación fue exitosa."
                            ));
                        exit;               
                    }
                    else
                        $this->redirect('/site/index');
                    }
            }

    if (Yii::app()->request->isAjaxRequest)
    {
        echo CJSON::encode(array(
            'status'=>'failure', 
            'div'=>$this->renderPartial('_form', array('model'=>$model), true)));
        exit;               
    }
    else
        $this->render('create',array('model'=>$model,));
}

这不起作用

$this->renderPartial('_form', array('model'=>$model),false, true))); 

我进入调试器“请启用JavaScript以使用文件上传器。”

缺少一些参数,这是问题?¿¿¿


更多信息

链接crearEntrada

<li class="ope-add-ent" title="Crear Entradas" onclick="addEntrada(); $('#modal_dialog').dialog('open');"></li>

添加AJAX调用cjudialog函数的代码javascript addEntrada:

echo CHtml::ajax(array(
        'url'=>array('/entradas/create','t'=>'ENTRADA'),
        'data'=> "js:$(this).serialize()",
        'type'=>'post',
        'dataType'=>'json',
        'success'=>"function(data)
        {
            if (data.status == 'failure')
            {
                $('#modal_dialog div.divForForm').html(data.div);
                      // Here is the trick: on submit-> once again this function!
                $('#modal_dialog div.divForForm form').submit(addEntrada);
            }
            else
            {
                $('#modal_dialog div.divForForm').html(data.div);
                //setTimeout(\"$('#modal_dialog').dialog('close') \",3000);
                setTimeout(\"location.reload(true);\",3000);
            }

        } ",
        ))?>

和代码小部件cjuidialog:

$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // El dialog
'id'=>'modal_dialog',
'options'=>array(
    'title'=>'',
    'autoOpen'=>false,
    'modal'=>true,
    'width'=>550,
    'height'=>485,
),

));

0 个答案:

没有答案