在file-uploader中的addInitialFiles之后调用的一些事件

时间:2017-01-07 03:45:32

标签: fine-uploader

我需要在精细上传器中添加一个href到缩略图并使用addInitialFiles函数。我的问题是,在添加每个文件后,我没有任何事件处理程序可以调用,对吗?

            callbacks:{
                onValidate: function(dados, buttonContainer) {
                    alert('onValidate');
                },
                onSessionRequestComplete: function(arr, response, success) {
                    alert('onSessionRequestComplete');
                },
                onComplete: function(id, name, response) {
                    alert('onComplete');
                    if (response.success) {
                        var serverPathToFile = response.url+'/'+response.uuid+'/'+response.name, fileItem = this.getItemByFileId(id);
                        var viewTnh = qq(fileItem).getByClass("qq-thumbnail-link")[0];
                        viewTnh.setAttribute("href", serverPathToFile);
                    }
                }
            },

...

            var numFiles = 0;
            var prova = cVs['6'][p][a]['provas']['prova'];
            $.each(cVs['30'][p], function(a){
                galleryUploader.addInitialFiles({
                    numFiles:{
                        "name":cVs['30'][p][a]["imagens_provas"]['ficheiro'],
                        "uuid":cVs['30'][p][a]["imagens_provas"]['uuid'],
                        "size":'111',
                        "thumbnailUrl":"uploads/Provas/users/Admin/"+prova+"/respostas/"+cVs['30'][p][a]["imagens_provas"]['uuid']+"/thumb_"+cVs['30'][p][a]["imagens_provas"]['ficheiro'],
                        "fileUrl":"uploads/Provas/users/Admin/"+prova+"/respostas/"+cVs['30'][p][a]["imagens_provas"]['uuid']+"/"+cVs['30'][p][a]["imagens_provas"]['ficheiro'],
                        "numero":"115"
                    }
                });
                numFiles++;
            });

1 个答案:

答案 0 :(得分:0)

结果:

http://prntscr.com/dtvmob

        var galleryUploader = new qq.FineUploader({
            element: document.getElementById("fine-uploader-gallery"),
            template: 'qq-template-gallery',
            request: {
                endpoint: 'modules.php?name=Logos_9&opt=30_put&prova='+cVs['6'][p][a]['provas']['prova']
            },
            session: {
                endpoint: 'modules.php?name=Logos_9&opt=30a_get&prova='+cVs['6'][p][a]['provas']['prova'],
                refreshOnReset: true
            },
            thumbnails: {
                placeholders: {
                    waitingPath: 'includes/FineUploader/placeholders/waiting-generic.png',
                    notAvailablePath: 'includes/FineUploader/placeholders/not_available-generic.png'
                }
            },
            validation: {
                allowedExtensions: ['jpeg', 'jpg', 'gif', 'png']
            },
            chunking: {
                enabled: true,
                partSize: 200000,
                concurrent: {
                    enabled: true
                },
                success: {
                    endpoint: 'modules.php?name=Logos_9&done&opt=30_put&prova='+cVs['6'][p][a]['provas']['prova']
                }
            },
            deleteFile: {
                //not yet
            },
            scaling: {
                sendOriginal: false,
                sizes: [
                    //{name: "small", maxSize: 100},
                    {name: "", maxSize: 1684}
                ]
            },
            callbacks:{
                onSessionRequestComplete: function(response, success) {
                    if (success) {
                        $.each(response, function(a, obj) {
                            //response[a] ex.
                            //{
                            //  "id":"12",
                            //  "name":"PROV02.jpg",
                            //  "uuid":"aa60f02e-29a4-4826-96d3-39709b39a664",
                            //  "size":"?",
                            //  "aluno_id":1,
                            //  "estado":"2",
                            //  "thumbnailUrl":"uploads/Provas/users/User_n/1/respostas/aa60f02e-29a4-4826-96d3-39709b39a664/thumb_PROV02.jpg",
                            //  "fileUrl":"uploads/Provas/users/User_n/1/respostas/aa60f02e-29a4-4826-96d3-39709b39a664/test_PROV02.jpg"
                            //}

                            var serverPathToFile = obj.fileUrl;
                            var viewTnh = document.getElementsByClassName('qq-file-id-'+a)[0].getElementsByClassName('qq-thumbnail-wrapper')[0].getElementsByClassName('qq-thumbnail-link')[0];
                            viewTnh.setAttribute("href", serverPathToFile);

                            var number = obj.aluno_id;
                            var viewNum = document.getElementsByClassName('qq-file-id-'+a)[0].getElementsByClassName('qq-file-info')[0].getElementsByClassName('qq-numero')[0];
                            viewNum.innerHTML = number;

                            if(obj.estado == "1") {
                                var corEstado = "background-color: #50FF00;";
                                obj.estado = "2";
                            }
                            else if(obj.estado == "2") {
                                var corEstado = "background-color: #FFFF00;";
                                obj.estado = "3";
                            }
                            else if(obj.estado == "3") {
                                var corEstado = "background-color: #FF0000;";
                                obj.estado = "1";
                            }
                            var viewTnh = document.getElementsByClassName('qq-file-id-'+a)[0];
                            viewTnh.setAttribute("style", corEstado);
                        });
                    }
                },
                onComplete: function(id, name, response) {
                    if (response.success) {

                        //response ex.
                        //{
                        //) "success":true,
                        //  "uuid":"23d1612b-7d32-49ab-8157-dae3bf19be7a",
                        //  "name":"PROV08.jpg",
                        //  "url":"uploads/Provas/users/Admin/1/respostas",
                        //  "student_id":7,
                        //  "estado":"2"
                        //}

                        //PLACE LINK IN THUMBNAIL
                        var serverPathToFile = response.url+'/'+response.uuid+'/'+response.name, fileItem = this.getItemByFileId(id);
                        var viewTnh = qq(fileItem).getByClass("qq-thumbnail-link")[0];
                        viewTnh.setAttribute("href", serverPathToFile);

                        //REDEFINE THE NEW THUMBNAIL IMAGEM
                        var serverPathToFile = response.url+'/'+response.uuid+'/thumb_'+response.name, fileItem = this.getItemByFileId(id);
                        var viewTnh = qq(fileItem).getByClass("qq-thumbnail-link")[0].getElementsByClassName('qq-thumbnail-selector')[0];
                        viewTnh.src = serverPathToFile;

                        //SHOW STUDENT NUMBER IN THUMBNAIL
                        var number = response.student_id;
                        if(number <= 0) number = '???';
                        var viewNum = qq(fileItem).getByClass('qq-file-info')[0].getElementsByClassName('qq-numero')[0];
                        viewNum.innerHTML = number;

                        //CHANGE COLOR IN THUMBAIL
                        if(response.estado == "1") {
                            var corEstado = "background-color: #50FF00;";
                        }
                        else if(response.estado == "2") {
                            var corEstado = "background-color: #FFFF00;";
                        }
                        else if(response.estado == "3") {
                            var corEstado = "background-color: #FF0000;";
                        }
                        var viewTnh = fileItem.getElementsByClassName('qq-thumbnail-wrapper')[0].parentNode;
                        viewTnh.setAttribute("style", corEstado);

                    }
                }
            },
            messages:{
                'onLeave':'Os ficheiros estão a ser carregados para o servidor, se sair agora o carregamento vai ser cancelado.',
                'sizeError':'Free account are limited to: 29.297 GB, please login for more options',
                'emptyError':'O ficheiro {file} está vazio'
            }
        });