diff --git a/backend/logic/file/FileManager.php b/backend/logic/file/FileManager.php index 7b7ff2e..da311a8 100644 --- a/backend/logic/file/FileManager.php +++ b/backend/logic/file/FileManager.php @@ -26,28 +26,18 @@ class FileManager /** * @param $array * @param $value - * @param int $key * @return int * 查看$extension数组中是否存在文件类型,不存在则返回-1 */ - public function searchType($array,$value, $key=-1){ - foreach($array as $k=>$row){ - if(!is_array($row)){ - if($row == $value){ - if($key != -1) { - return $key; - }else{ - return -1; - } - } - }else{ - $r = self::searchType($row,$value, $k); - if($r != -1){ - return $r; + public function searchType($array, $keyword, $key=-1){ + foreach($array as $key => $value){ + foreach ($value as $k => $v) { + if($v == $keyword){ + return $key; } } } - return -1; + return false; } /** diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index 728c569..9dbc2a7 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -104,6 +104,7 @@ class GoodsController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); + $model->imageId = $model->image; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('index'); @@ -183,7 +184,7 @@ class GoodsController extends Controller $model->name = $file_name; $file_manager = new \backend\logic\file\FileManager(); $type = $file_manager->searchType(\backend\logic\file\FileManager::$extension, pathinfo($data['path'])['extension']); - if ($type != -1) { + if ($type) { $model->type = $type; } $model->alias = $data['alias']; @@ -200,18 +201,49 @@ class GoodsController extends Controller public function actionImgIdDel() { //判断该类是否存在 - if(!class_exists('\common\models\ars\TemFile')){ + if(!class_exists('\common\models\ars\TemFile') || !class_exists('\common\models\ars\File')){ return ''; } - $alias = Yii::$app->request->get('data')['alias']; $img_id = Yii::$app->request->get('imgid'); $img_id_arr = explode(',', $img_id); - $tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); - if ($tem_file) { - $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + if(isset(Yii::$app->request->get('data')['alias'])) { + $alias = Yii::$app->request->get('data')['alias']; + $tem_file = \common\models\ars\TemFile::findOne(['alias' => $alias]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + }else{ + foreach (Yii::$app->request->get() as $key => $value) { + $tem_file = \common\models\ars\File::findOne(['alias' => $value]); + if ($tem_file) { + $img_id_arr = array_diff($img_id_arr, [$tem_file->id]); + } + } } $img_id_str = implode(',', $img_id_arr); return $img_id_str; } + + public function actionImageFile() + { + //判断该类是否存在 + if(!class_exists('\common\models\ars\File')){ + return false; + } + + $file_id_str = Yii::$app->request->get('fileidstr'); + $file_id_arr = explode(',', $file_id_str); + $data = \common\models\ars\File::find()->where(['id' => $file_id_arr])->all(); + if($data) { + $res = array(); + $i = 0; + foreach ($data as $key => $value) { + $res[$i]['name'] = $value->alias; + $res[$i]['path'] = Yii::$app->request->hostInfo . '/' . $value->path; + $res[$i]['size'] = filesize($value->path); + } + } + return json_encode($res); + } } diff --git a/vendor/antgoods/goods/src/logic/goods/GoodsManager.php b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php index d5514f6..b1410d8 100644 --- a/vendor/antgoods/goods/src/logic/goods/GoodsManager.php +++ b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php @@ -15,6 +15,7 @@ class GoodsManager */ public function saveFile($fileIdStr, $goodsModel, $filetype = 1) { + //判断类名是否存在 if(!class_exists('\backend\logic\file\FileManager') || !class_exists('\common\models\ars\File')) { return false; } diff --git a/vendor/antgoods/goods/src/views/goods/_form.php b/vendor/antgoods/goods/src/views/goods/_form.php index 18bfe40..4a30336 100644 --- a/vendor/antgoods/goods/src/views/goods/_form.php +++ b/vendor/antgoods/goods/src/views/goods/_form.php @@ -68,7 +68,7 @@ use antgoods\goods\models\ars\Supplier; field($model, 'express_template')->textInput() ?> - field($model, 'imageId')->hiddenInput()->label('') ?> + field($model, 'imageId')->textInput()->label('') ?> field($model, 'imagePath')->widget(\iron\widgets\Upload::className(), [ 'url' => 'upload', 'deleteUrl' => 'imageDel', @@ -87,15 +87,20 @@ use antgoods\goods\models\ars\Supplier; } ", 'deleteScript' => " + console.log(data); $.ajax({ url: 'img-id-del', data: {data: data, imgid: $('#goods-imageid').val()}, success: function(data) { + console.log(data); $('#goods-imageid').val(data); }, }); ", + 'previewConfig' => [ + 'url' => 'image-file?fileidstr='.$model->imageId, + ], ])->label('图片') ?>
diff --git a/vendor/iron/assets/upload/js/jquery-file-upload.min.js b/vendor/iron/assets/upload/js/jquery-file-upload.min.js index 6788a62..3f525b1 100644 --- a/vendor/iron/assets/upload/js/jquery-file-upload.min.js +++ b/vendor/iron/assets/upload/js/jquery-file-upload.min.js @@ -1 +1 @@ -(function($){if($.fn.ajaxForm==undefined){$.getScript(("https:"==document.location.protocol?"https://":"http://")+"malsup.github.io/jquery.form.js")}var feature={};feature.fileapi=$("").get(0).files!==undefined;feature.formdata=window.FormData!==undefined;$.fn.uploadFile=function(options){var s=$.extend({url:"",method:"POST",enctype:"multipart/form-data",returnType:null,allowDuplicates:true,duplicateStrict:false,allowedTypes:"*",acceptFiles:"*",fileName:"file",formData:false,dynamicFormData:false,maxFileSize:-1,maxFileCount:-1,multiple:true,dragDrop:true,autoSubmit:true,showCancel:true,showAbort:true,showDone:false,showDelete:false,showError:true,showStatusAfterSuccess:true,showStatusAfterError:true,showFileCounter:true,fileCounterStyle:"). ",showFileSize:true,showProgress:false,nestedForms:true,showDownload:false,onLoad:function(obj){},onSelect:function(files){return true},onSubmit:function(files,xhr){},onSuccess:function(files,response,xhr,pd){},onError:function(files,status,message,pd){},onCancel:function(files,pd){},onAbort:function(files,pd){},downloadCallback:false,deleteCallback:false,afterUploadAll:false,serialize:true,sequential:false,sequentialCount:2,customProgressBar:false,abortButtonClass:"ajax-file-upload-abort",cancelButtonClass:"ajax-file-upload-cancel",dragDropContainerClass:"ajax-upload-dragdrop",dragDropHoverClass:"state-hover",errorClass:"ajax-file-upload-error",uploadButtonClass:"ajax-file-upload",dragDropStr:"Drag & Drop Files",uploadStr:"Upload",abortStr:"Abort",cancelStr:"Cancel",deleteStr:"Delete",doneStr:"Done",multiDragErrorStr:"Multiple File Drag & Drop is not allowed.",extErrorStr:"is not allowed. Allowed extensions: ",duplicateErrorStr:"is not allowed. File already exists.",sizeErrorStr:"is not allowed. Allowed Max size: ",uploadErrorStr:"Upload is not allowed",maxFileCountErrorStr:" is not allowed. Maximum allowed files are:",downloadStr:"Download",customErrorKeyStr:"jquery-upload-file-error",showQueueDiv:false,statusBarWidth:400,dragdropWidth:400,showPreview:false,previewHeight:"auto",previewWidth:"100%",extraHTML:false,uploadQueueOrder:"top",headers:{}},options);this.fileCounter=1;this.selectedFiles=0;var formGroup="ajax-file-upload-"+(new Date).getTime();this.formGroup=formGroup;this.errorLog=$("
");this.responses=[];this.existingFileNames=[];if(!feature.formdata){s.dragDrop=false}if(!feature.formdata||s.maxFileCount===1){s.multiple=false}$(this).html("");var obj=this;var uploadLabel=$("
"+s.uploadStr+"
");$(uploadLabel).addClass(s.uploadButtonClass);(function checkAjaxFormLoaded(){if($.fn.ajaxForm){if(s.dragDrop){var dragDrop=$('
').width(s.dragdropWidth);$(obj).append(dragDrop);$(dragDrop).append(uploadLabel);$(dragDrop).append($(s.dragDropStr));setDragDropHandlers(obj,s,dragDrop)}else{$(obj).append(uploadLabel)}$(obj).append(obj.errorLog);if(s.showQueueDiv)obj.container=$("#"+s.showQueueDiv);else obj.container=$("
").insertAfter($(obj));s.onLoad.call(this,obj);createCustomInputFile(obj,formGroup,s,uploadLabel)}else window.setTimeout(checkAjaxFormLoaded,10)})();this.startUpload=function(){$("form").each(function(i,items){if($(this).hasClass(obj.formGroup)){mainQ.push($(this))}});if(mainQ.length>=1)submitPendingUploads()};this.getFileCount=function(){return obj.selectedFiles};this.stopUpload=function(){$("."+s.abortButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()});$("."+s.cancelButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()})};this.cancelAll=function(){$("."+s.cancelButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()})};this.update=function(settings){s=$.extend(s,settings);if(settings.hasOwnProperty("url")){$("form").each(function(i,items){$(this).attr("action",settings["url"])})}};this.enqueueFile=function(file){if(!(file instanceof File))return;var files=[file];serializeAndUploadFiles(s,obj,files)};this.reset=function(removeStatusBars){obj.fileCounter=1;obj.selectedFiles=0;obj.errorLog.html("");if(removeStatusBars!=false){obj.container.html("")}};this.remove=function(){obj.container.html("");$(obj).remove()};this.createProgress=function(filename,filepath,filesize){var pd=new createProgressDiv(this,s);pd.progressDiv.show();pd.progressbar.width("100%");var fileNameStr="";if(s.showFileCounter)fileNameStr=obj.fileCounter+s.fileCounterStyle+filename;else fileNameStr=filename;if(s.showFileSize)fileNameStr+=" ("+getSizeStr(filesize)+")";pd.filename.html(fileNameStr);obj.fileCounter++;obj.selectedFiles++;if(s.showPreview){pd.preview.attr("src",filepath);pd.preview.show()}if(s.showDownload){pd.download.show();pd.download.click(function(){if(s.downloadCallback)s.downloadCallback.call(obj,[filename],pd)})}if(s.showDelete){pd.del.show();pd.del.click(function(){pd.statusbar.hide().remove();var arr=[filename];if(s.deleteCallback)s.deleteCallback.call(this,arr,pd);obj.selectedFiles-=1;updateFileCounter(s,obj)})}return pd};this.getResponses=function(){return this.responses};var mainQ=[];var progressQ=[];var running=false;function submitPendingUploads(){if(running)return;running=true;(function checkPendingForms(){if(!s.sequential)s.sequentialCount=99999;if(mainQ.length==0&&progressQ.length==0){if(s.afterUploadAll)s.afterUploadAll(obj);running=false}else{if(progressQ.length1){if(s.showError)$("
"+s.multiDragErrorStr+"
").appendTo(obj.errorLog);return}if(s.onSelect(files)==false)return;serializeAndUploadFiles(s,obj,files)});ddObj.on("dragleave",function(e){$(this).removeClass(s.dragDropHoverClass)});$(document).on("dragenter",function(e){e.stopPropagation();e.preventDefault()});$(document).on("dragover",function(e){e.stopPropagation();e.preventDefault();var that=$(this);if(!that.hasClass(s.dragDropContainerClass)){that.removeClass(s.dragDropHoverClass)}});$(document).on("drop",function(e){e.stopPropagation();e.preventDefault();$(this).removeClass(s.dragDropHoverClass)})}function getSizeStr(size){var sizeStr="";var sizeKB=size/1024;if(parseInt(sizeKB)>1024){var sizeMB=sizeKB/1024;sizeStr=sizeMB.toFixed(2)+" MB"}else{sizeStr=sizeKB.toFixed(2)+" KB"}return sizeStr}function serializeData(extraData){var serialized=[];if(jQuery.type(extraData)=="string"){serialized=extraData.split("&")}else{serialized=$.param(extraData).split("&")}var len=serialized.length;var result=[];var i,part;for(i=0;i"+files[i].name+" "+s.extErrorStr+s.allowedTypes+"
").appendTo(obj.errorLog);continue}if(s.maxFileSize!=-1&&files[i].size>s.maxFileSize){if(s.showError)$("
"+files[i].name+" "+s.sizeErrorStr+getSizeStr(s.maxFileSize)+"
").appendTo(obj.errorLog);continue}fd.append(fileName+"[]",files[i]);fileArray.push(files[i].name);fileListStr+=obj.fileCounter+"). "+files[i].name+"
";obj.fileCounter++}if(fileArray.length==0)return;var extraData=s.formData;if(extraData){var sData=serializeData(extraData);for(var j=0;j");form.appendTo("body");ajaxFormSubmit(form,ts,pd,fileArray,obj)}function serializeAndUploadFiles(s,obj,files){for(var i=0;i"+files[i].name+" "+s.extErrorStr+s.allowedTypes+"").appendTo(obj.errorLog);continue}if(!s.allowDuplicates&&isFileDuplicate(obj,files[i].name)){if(s.showError)$("
"+files[i].name+" "+s.duplicateErrorStr+"
").appendTo(obj.errorLog);continue}if(s.maxFileSize!=-1&&files[i].size>s.maxFileSize){if(s.showError)$("
"+files[i].name+" "+s.sizeErrorStr+getSizeStr(s.maxFileSize)+"
").appendTo(obj.errorLog);continue}if(s.maxFileCount!=-1&&obj.selectedFiles>=s.maxFileCount){if(s.showError)$("
"+files[i].name+" "+s.maxFileCountErrorStr+s.maxFileCount+"
").appendTo(obj.errorLog);continue}obj.selectedFiles++;obj.existingFileNames.push(files[i].name);var ts=$.extend({},s);var fd=new FormData;var fileName=s.fileName.replace("[]","");fd.append(fileName,files[i]);var extraData=s.formData;if(extraData){var sData=serializeData(extraData);for(var j=0;j");form.appendTo("body");var fileArray=[];fileArray.push(files[i].name);ajaxFormSubmit(form,ts,pd,fileArray,obj,files[i]);obj.fileCounter++}}function isFileTypeAllowed(obj,s,fileName){var fileExtensions=s.allowedTypes.toLowerCase().split(/[\s,]+/g);var ext=fileName.split(".").pop().toLowerCase();if(s.allowedTypes!="*"&&jQuery.inArray(ext,fileExtensions)<0){return false}return true}function isFileDuplicate(obj,filename){var duplicate=false;if(obj.existingFileNames.length){for(var x=0;x");var fileInputStr="";if(s.multiple){if(s.fileName.indexOf("[]")!=s.fileName.length-2){s.fileName+="[]"}fileInputStr=""}var fileInput=$(fileInputStr).appendTo(form);fileInput.change(function(){obj.errorLog.html("");var fileExtensions=s.allowedTypes.toLowerCase().split(",");var fileArray=[];if(this.files){for(i=0;i"+filenameStr+" "+s.extErrorStr+s.allowedTypes+"").appendTo(obj.errorLog);return}flist.push({name:filenameStr,size:"NA"});if(s.onSelect(flist)==false)return}updateFileCounter(s,obj);uploadLabel.unbind("click");form.hide();createCustomInputFile(obj,group,s,uploadLabel);form.addClass(group);if(s.serialize&&feature.fileapi&&feature.formdata){form.removeClass(group);var files=this.files;form.remove();serializeAndUploadFiles(s,obj,files)}else{var fileList="";for(var i=0;i";else fileList+=fileArray[i]+"
";obj.fileCounter++}if(s.maxFileCount!=-1&&obj.selectedFiles+fileArray.length>s.maxFileCount){if(s.showError)$("
"+fileList+" "+s.maxFileCountErrorStr+s.maxFileCount+"
").appendTo(obj.errorLog);return}obj.selectedFiles+=fileArray.length;var pd=new createProgressDiv(obj,s);pd.filename.html(fileList);ajaxFormSubmit(form,s,pd,fileArray,obj,null)}});if(s.nestedForms){form.css({margin:0,padding:0});uploadLabel.css({position:"relative",overflow:"hidden",cursor:"default"});fileInput.css({position:"absolute",cursor:"pointer",top:"0px",width:"100%",height:"100%",left:"0px","z-index":"100",opacity:"0.0",filter:"alpha(opacity=0)","-ms-filter":"alpha(opacity=0)","-khtml-opacity":"0.0","-moz-opacity":"0.0"});form.appendTo(uploadLabel)}else{form.appendTo($("body"));form.css({margin:0,padding:0,display:"block",position:"absolute",left:"-250px"});if(navigator.appVersion.indexOf("MSIE ")!=-1){uploadLabel.attr("for",fileUploadId)}else{uploadLabel.click(function(){fileInput.click()})}}}function defaultProgressBar(obj,s){this.statusbar=$("
").width(s.statusBarWidth);this.preview=$("").width(s.previewWidth).height(s.previewHeight).appendTo(this.statusbar).hide();this.filename=$("
").appendTo(this.statusbar);this.progressDiv=$("
").appendTo(this.statusbar).hide();this.progressbar=$("
").appendTo(this.progressDiv);this.abort=$("
"+s.abortStr+"
").appendTo(this.statusbar).hide();this.cancel=$("
"+s.cancelStr+"
").appendTo(this.statusbar).hide();this.done=$("
"+s.doneStr+"
").appendTo(this.statusbar).hide();this.download=$("
"+s.downloadStr+"
").appendTo(this.statusbar).hide();this.del=$("
"+s.deleteStr+"
").appendTo(this.statusbar).hide();this.abort.addClass("ajax-file-upload-red");this.done.addClass("ajax-file-upload-green");this.download.addClass("ajax-file-upload-green");this.cancel.addClass("ajax-file-upload-red");this.del.addClass("ajax-file-upload-red");return this}function createProgressDiv(obj,s){var bar=null;if(s.customProgressBar)bar=new s.customProgressBar(obj,s);else bar=new defaultProgressBar(obj,s);bar.abort.addClass(obj.formGroup);bar.abort.addClass(s.abortButtonClass);bar.cancel.addClass(obj.formGroup);bar.cancel.addClass(s.cancelButtonClass);if(s.extraHTML)bar.extraHTML=$("
"+s.extraHTML()+"
").insertAfter(bar.filename);if(s.uploadQueueOrder=="bottom")$(obj.container).append(bar.statusbar);else $(obj.container).prepend(bar.statusbar);return bar}function ajaxFormSubmit(form,s,pd,fileArray,obj,file){var currentXHR=null;var options={cache:false,contentType:false,processData:false,forceSync:false,type:s.method,data:s.formData,formData:s.fileData,dataType:s.returnType,headers:s.headers,beforeSubmit:function(formData,$form,options){if(s.onSubmit.call(this,fileArray)!=false){if(s.dynamicFormData){var sData=serializeData(s.dynamicFormData());if(sData){for(var j=0;j"+s.uploadErrorStr+"
");pd.cancel.show();form.remove();pd.cancel.click(function(){mainQ.splice(mainQ.indexOf(form),1);removeExistingFileName(obj,fileArray);pd.statusbar.remove();s.onCancel.call(obj,fileArray,pd);obj.selectedFiles-=fileArray.length;updateFileCounter(s,obj)});return false},beforeSend:function(xhr,o){for(var key in o.headers){xhr.setRequestHeader(key,o.headers[key])}pd.progressDiv.show();pd.cancel.hide();pd.done.hide();if(s.showAbort){pd.abort.show();pd.abort.click(function(){removeExistingFileName(obj,fileArray);xhr.abort();obj.selectedFiles-=fileArray.length;s.onAbort.call(obj,fileArray,pd)})}if(!feature.formdata){pd.progressbar.width("5%")}else pd.progressbar.width("1%")},uploadProgress:function(event,position,total,percentComplete){if(percentComplete>98)percentComplete=98;var percentVal=percentComplete+"%";if(percentComplete>1)pd.progressbar.width(percentVal);if(s.showProgress){pd.progressbar.html(percentVal);pd.progressbar.css("text-align","center")}},success:function(data,message,xhr){pd.cancel.remove();progressQ.pop();if(s.returnType=="json"&&$.type(data)=="object"&&data.hasOwnProperty(s.customErrorKeyStr)){pd.abort.hide();var msg=data[s.customErrorKeyStr];s.onError.call(this,fileArray,200,msg,pd);if(s.showStatusAfterError){pd.progressDiv.hide();pd.statusbar.append("ERROR: "+msg+"")}else{pd.statusbar.hide();pd.statusbar.remove()}obj.selectedFiles-=fileArray.length;form.remove();return}obj.responses.push(data);pd.progressbar.width("100%");if(s.showProgress){pd.progressbar.html("100%");pd.progressbar.css("text-align","center")}pd.abort.hide();s.onSuccess.call(this,fileArray,data,xhr,pd);if(s.showStatusAfterSuccess){if(s.showDone){pd.done.show();pd.done.click(function(){pd.statusbar.hide("slow");pd.statusbar.remove()})}else{pd.done.hide()}if(s.showDelete){pd.del.show();pd.del.click(function(){removeExistingFileName(obj,fileArray);pd.statusbar.hide().remove();if(s.deleteCallback)s.deleteCallback.call(this,data,pd);obj.selectedFiles-=fileArray.length;updateFileCounter(s,obj)})}else{pd.del.hide()}}else{pd.statusbar.hide("slow");pd.statusbar.remove()}if(s.showDownload){pd.download.show();pd.download.click(function(){if(s.downloadCallback)s.downloadCallback(data,pd)})}form.remove()},error:function(xhr,status,errMsg){pd.cancel.remove();progressQ.pop();pd.abort.hide();if(xhr.statusText=="abort"){pd.statusbar.hide("slow").remove();updateFileCounter(s,obj)}else{s.onError.call(this,fileArray,status,errMsg,pd);if(s.showStatusAfterError){pd.progressDiv.hide();pd.statusbar.append("ERROR: "+errMsg+"")}else{pd.statusbar.hide();pd.statusbar.remove()}obj.selectedFiles-=fileArray.length}form.remove()}};if(s.showPreview&&file!=null){if(file.type.toLowerCase().split("/").shift()=="image")getSrcToPreview(file,pd.preview)}if(s.autoSubmit){form.ajaxForm(options);mainQ.push(form);submitPendingUploads()}else{if(s.showCancel){pd.cancel.show();pd.cancel.click(function(){mainQ.splice(mainQ.indexOf(form),1);removeExistingFileName(obj,fileArray);form.remove();pd.statusbar.remove();s.onCancel.call(obj,fileArray,pd);obj.selectedFiles-=fileArray.length;updateFileCounter(s,obj)})}form.ajaxForm(options)}}return this};var getUrlParameter=function getUrlParameter(sParam){var sPageURL=window.location.search.substring(1),sURLVariables=sPageURL.split("&"),sParameterName,i;for(i=0;i").get(0).files!==undefined;feature.formdata=window.FormData!==undefined;$.fn.uploadFile=function(options){var s=$.extend({url:"",method:"POST",enctype:"multipart/form-data",returnType:null,allowDuplicates:true,duplicateStrict:false,allowedTypes:"*",acceptFiles:"*",fileName:"file",formData:false,dynamicFormData:false,maxFileSize:-1,maxFileCount:-1,multiple:true,dragDrop:true,autoSubmit:true,showCancel:true,showAbort:true,showDone:false,showDelete:false,showError:true,showStatusAfterSuccess:true,showStatusAfterError:true,showFileCounter:true,fileCounterStyle:"). ",showFileSize:true,showProgress:false,nestedForms:true,showDownload:false,onLoad:function(obj){},onSelect:function(files){return true},onSubmit:function(files,xhr){},onSuccess:function(files,response,xhr,pd){},onError:function(files,status,message,pd){},onCancel:function(files,pd){},onAbort:function(files,pd){},downloadCallback:false,deleteCallback:false,afterUploadAll:false,serialize:true,sequential:false,sequentialCount:2,customProgressBar:false,abortButtonClass:"ajax-file-upload-abort",cancelButtonClass:"ajax-file-upload-cancel",dragDropContainerClass:"ajax-upload-dragdrop",dragDropHoverClass:"state-hover",errorClass:"ajax-file-upload-error",uploadButtonClass:"ajax-file-upload",dragDropStr:"Drag & Drop Files",uploadStr:"Upload",abortStr:"Abort",cancelStr:"Cancel",deleteStr:"Delete",doneStr:"Done",multiDragErrorStr:"Multiple File Drag & Drop is not allowed.",extErrorStr:"is not allowed. Allowed extensions: ",duplicateErrorStr:"is not allowed. File already exists.",sizeErrorStr:"is not allowed. Allowed Max size: ",uploadErrorStr:"Upload is not allowed",maxFileCountErrorStr:" is not allowed. Maximum allowed files are:",downloadStr:"Download",customErrorKeyStr:"jquery-upload-file-error",showQueueDiv:false,statusBarWidth:400,dragdropWidth:400,showPreview:false,previewHeight:"auto",previewWidth:"100%",extraHTML:false,uploadQueueOrder:"top",headers:{}},options);this.fileCounter=1;this.selectedFiles=0;var formGroup="ajax-file-upload-"+(new Date).getTime();this.formGroup=formGroup;this.errorLog=$("
");this.responses=[];this.existingFileNames=[];if(!feature.formdata){s.dragDrop=false}if(!feature.formdata||s.maxFileCount===1){s.multiple=false}$(this).html("");var obj=this;var uploadLabel=$("
"+s.uploadStr+"
");$(uploadLabel).addClass(s.uploadButtonClass);(function checkAjaxFormLoaded(){if($.fn.ajaxForm){if(s.dragDrop){var dragDrop=$('
').width(s.dragdropWidth);$(obj).append(dragDrop);$(dragDrop).append(uploadLabel);$(dragDrop).append($(s.dragDropStr));setDragDropHandlers(obj,s,dragDrop)}else{$(obj).append(uploadLabel)}$(obj).append(obj.errorLog);if(s.showQueueDiv)obj.container=$("#"+s.showQueueDiv);else obj.container=$("
").insertAfter($(obj));s.onLoad.call(this,obj);createCustomInputFile(obj,formGroup,s,uploadLabel)}else window.setTimeout(checkAjaxFormLoaded,10)})();this.startUpload=function(){$("form").each(function(i,items){if($(this).hasClass(obj.formGroup)){mainQ.push($(this))}});if(mainQ.length>=1)submitPendingUploads()};this.getFileCount=function(){return obj.selectedFiles};this.stopUpload=function(){$("."+s.abortButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()});$("."+s.cancelButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()})};this.cancelAll=function(){$("."+s.cancelButtonClass).each(function(i,items){if($(this).hasClass(obj.formGroup))$(this).click()})};this.update=function(settings){s=$.extend(s,settings);if(settings.hasOwnProperty("url")){$("form").each(function(i,items){$(this).attr("action",settings["url"])})}};this.enqueueFile=function(file){if(!(file instanceof File))return;var files=[file];serializeAndUploadFiles(s,obj,files)};this.reset=function(removeStatusBars){obj.fileCounter=1;obj.selectedFiles=0;obj.errorLog.html("");if(removeStatusBars!=false){obj.container.html("")}};this.remove=function(){obj.container.html("");$(obj).remove()};this.createProgress=function(filename,filepath,filesize){var pd=new createProgressDiv(this,s);pd.progressDiv.show();pd.progressbar.width("100%");var fileNameStr="";if(s.showFileCounter)fileNameStr=obj.fileCounter+s.fileCounterStyle+filename;else fileNameStr=filename;if(s.showFileSize)fileNameStr+=" ("+getSizeStr(filesize)+")";pd.filename.html(fileNameStr);obj.fileCounter++;obj.selectedFiles++;if(s.showPreview){pd.preview.attr("src",filepath);pd.preview.show()}if(s.showDownload){pd.download.show();pd.download.click(function(){if(s.downloadCallback)s.downloadCallback.call(obj,[filename],pd)})}if(s.showDelete){pd.del.show();pd.del.click(function(){pd.statusbar.hide().remove();var arr=[filename];if(s.deleteCallback)s.deleteCallback.call(this,arr,pd);obj.selectedFiles-=1;updateFileCounter(s,obj)})}return pd};this.getResponses=function(){return this.responses};var mainQ=[];var progressQ=[];var running=false;function submitPendingUploads(){if(running)return;running=true;(function checkPendingForms(){if(!s.sequential)s.sequentialCount=99999;if(mainQ.length==0&&progressQ.length==0){if(s.afterUploadAll)s.afterUploadAll(obj);running=false}else{if(progressQ.length1){if(s.showError)$("
"+s.multiDragErrorStr+"
").appendTo(obj.errorLog);return}if(s.onSelect(files)==false)return;serializeAndUploadFiles(s,obj,files)});ddObj.on("dragleave",function(e){$(this).removeClass(s.dragDropHoverClass)});$(document).on("dragenter",function(e){e.stopPropagation();e.preventDefault()});$(document).on("dragover",function(e){e.stopPropagation();e.preventDefault();var that=$(this);if(!that.hasClass(s.dragDropContainerClass)){that.removeClass(s.dragDropHoverClass)}});$(document).on("drop",function(e){e.stopPropagation();e.preventDefault();$(this).removeClass(s.dragDropHoverClass)})}function getSizeStr(size){var sizeStr="";var sizeKB=size/1024;if(parseInt(sizeKB)>1024){var sizeMB=sizeKB/1024;sizeStr=sizeMB.toFixed(2)+" MB"}else{sizeStr=sizeKB.toFixed(2)+" KB"}return sizeStr}function serializeData(extraData){var serialized=[];if(jQuery.type(extraData)=="string"){serialized=extraData.split("&")}else{serialized=$.param(extraData).split("&")}var len=serialized.length;var result=[];var i,part;for(i=0;i"+files[i].name+" "+s.extErrorStr+s.allowedTypes+"").appendTo(obj.errorLog);continue}if(s.maxFileSize!=-1&&files[i].size>s.maxFileSize){if(s.showError)$("
"+files[i].name+" "+s.sizeErrorStr+getSizeStr(s.maxFileSize)+"
").appendTo(obj.errorLog);continue}fd.append(fileName+"[]",files[i]);fileArray.push(files[i].name);fileListStr+=obj.fileCounter+"). "+files[i].name+"
";obj.fileCounter++}if(fileArray.length==0)return;var extraData=s.formData;if(extraData){var sData=serializeData(extraData);for(var j=0;j");form.appendTo("body");ajaxFormSubmit(form,ts,pd,fileArray,obj)}function serializeAndUploadFiles(s,obj,files){for(var i=0;i"+files[i].name+" "+s.extErrorStr+s.allowedTypes+"").appendTo(obj.errorLog);continue}if(!s.allowDuplicates&&isFileDuplicate(obj,files[i].name)){if(s.showError)$("
"+files[i].name+" "+s.duplicateErrorStr+"
").appendTo(obj.errorLog);continue}if(s.maxFileSize!=-1&&files[i].size>s.maxFileSize){if(s.showError)$("
"+files[i].name+" "+s.sizeErrorStr+getSizeStr(s.maxFileSize)+"
").appendTo(obj.errorLog);continue}if(s.maxFileCount!=-1&&obj.selectedFiles>=s.maxFileCount){if(s.showError)$("
"+files[i].name+" "+s.maxFileCountErrorStr+s.maxFileCount+"
").appendTo(obj.errorLog);continue}obj.selectedFiles++;obj.existingFileNames.push(files[i].name);var ts=$.extend({},s);var fd=new FormData;var fileName=s.fileName.replace("[]","");fd.append(fileName,files[i]);var extraData=s.formData;if(extraData){var sData=serializeData(extraData);for(var j=0;j");form.appendTo("body");var fileArray=[];fileArray.push(files[i].name);ajaxFormSubmit(form,ts,pd,fileArray,obj,files[i]);obj.fileCounter++}}function isFileTypeAllowed(obj,s,fileName){var fileExtensions=s.allowedTypes.toLowerCase().split(/[\s,]+/g);var ext=fileName.split(".").pop().toLowerCase();if(s.allowedTypes!="*"&&jQuery.inArray(ext,fileExtensions)<0){return false}return true}function isFileDuplicate(obj,filename){var duplicate=false;if(obj.existingFileNames.length){for(var x=0;x");var fileInputStr="";if(s.multiple){if(s.fileName.indexOf("[]")!=s.fileName.length-2){s.fileName+="[]"}fileInputStr=""}var fileInput=$(fileInputStr).appendTo(form);fileInput.change(function(){obj.errorLog.html("");var fileExtensions=s.allowedTypes.toLowerCase().split(",");var fileArray=[];if(this.files){for(i=0;i"+filenameStr+" "+s.extErrorStr+s.allowedTypes+"").appendTo(obj.errorLog);return}flist.push({name:filenameStr,size:"NA"});if(s.onSelect(flist)==false)return}updateFileCounter(s,obj);uploadLabel.unbind("click");form.hide();createCustomInputFile(obj,group,s,uploadLabel);form.addClass(group);if(s.serialize&&feature.fileapi&&feature.formdata){form.removeClass(group);var files=this.files;form.remove();serializeAndUploadFiles(s,obj,files)}else{var fileList="";for(var i=0;i";else fileList+=fileArray[i]+"
";obj.fileCounter++}if(s.maxFileCount!=-1&&obj.selectedFiles+fileArray.length>s.maxFileCount){if(s.showError)$("
"+fileList+" "+s.maxFileCountErrorStr+s.maxFileCount+"
").appendTo(obj.errorLog);return}obj.selectedFiles+=fileArray.length;var pd=new createProgressDiv(obj,s);pd.filename.html(fileList);ajaxFormSubmit(form,s,pd,fileArray,obj,null)}});if(s.nestedForms){form.css({margin:0,padding:0});uploadLabel.css({position:"relative",overflow:"hidden",cursor:"default"});fileInput.css({position:"absolute",cursor:"pointer",top:"0px",width:"100%",height:"100%",left:"0px","z-index":"100",opacity:"0.0",filter:"alpha(opacity=0)","-ms-filter":"alpha(opacity=0)","-khtml-opacity":"0.0","-moz-opacity":"0.0"});form.appendTo(uploadLabel)}else{form.appendTo($("body"));form.css({margin:0,padding:0,display:"block",position:"absolute",left:"-250px"});if(navigator.appVersion.indexOf("MSIE ")!=-1){uploadLabel.attr("for",fileUploadId)}else{uploadLabel.click(function(){fileInput.click()})}}}function defaultProgressBar(obj,s){this.statusbar=$("
").width(s.statusBarWidth);this.preview=$("").width(s.previewWidth).height(s.previewHeight).appendTo(this.statusbar).hide();this.filename=$("
").appendTo(this.statusbar);this.progressDiv=$("
").appendTo(this.statusbar).hide();this.progressbar=$("
").appendTo(this.progressDiv);this.abort=$("
"+s.abortStr+"
").appendTo(this.statusbar).hide();this.cancel=$("
"+s.cancelStr+"
").appendTo(this.statusbar).hide();this.done=$("
"+s.doneStr+"
").appendTo(this.statusbar).hide();this.download=$("
"+s.downloadStr+"
").appendTo(this.statusbar).hide();this.del=$("
"+s.deleteStr+"
").appendTo(this.statusbar).hide();this.abort.addClass("ajax-file-upload-red");this.done.addClass("ajax-file-upload-green");this.download.addClass("ajax-file-upload-green");this.cancel.addClass("ajax-file-upload-red");this.del.addClass("ajax-file-upload-red");return this}function createProgressDiv(obj,s){var bar=null;if(s.customProgressBar)bar=new s.customProgressBar(obj,s);else bar=new defaultProgressBar(obj,s);bar.abort.addClass(obj.formGroup);bar.abort.addClass(s.abortButtonClass);bar.cancel.addClass(obj.formGroup);bar.cancel.addClass(s.cancelButtonClass);if(s.extraHTML)bar.extraHTML=$("
"+s.extraHTML()+"
").insertAfter(bar.filename);if(s.uploadQueueOrder=="bottom")$(obj.container).append(bar.statusbar);else $(obj.container).prepend(bar.statusbar);return bar}function ajaxFormSubmit(form,s,pd,fileArray,obj,file){var currentXHR=null;var options={cache:false,contentType:false,processData:false,forceSync:false,type:s.method,data:s.formData,formData:s.fileData,dataType:s.returnType,headers:s.headers,beforeSubmit:function(formData,$form,options){if(s.onSubmit.call(this,fileArray)!=false){if(s.dynamicFormData){var sData=serializeData(s.dynamicFormData());if(sData){for(var j=0;j"+s.uploadErrorStr+"
");pd.cancel.show();form.remove();pd.cancel.click(function(){mainQ.splice(mainQ.indexOf(form),1);removeExistingFileName(obj,fileArray);pd.statusbar.remove();s.onCancel.call(obj,fileArray,pd);obj.selectedFiles-=fileArray.length;updateFileCounter(s,obj)});return false},beforeSend:function(xhr,o){for(var key in o.headers){xhr.setRequestHeader(key,o.headers[key])}pd.progressDiv.show();pd.cancel.hide();pd.done.hide();if(s.showAbort){pd.abort.show();pd.abort.click(function(){removeExistingFileName(obj,fileArray);xhr.abort();obj.selectedFiles-=fileArray.length;s.onAbort.call(obj,fileArray,pd)})}if(!feature.formdata){pd.progressbar.width("5%")}else pd.progressbar.width("1%")},uploadProgress:function(event,position,total,percentComplete){if(percentComplete>98)percentComplete=98;var percentVal=percentComplete+"%";if(percentComplete>1)pd.progressbar.width(percentVal);if(s.showProgress){pd.progressbar.html(percentVal);pd.progressbar.css("text-align","center")}},success:function(data,message,xhr){pd.cancel.remove();progressQ.pop();if(s.returnType=="json"&&$.type(data)=="object"&&data.hasOwnProperty(s.customErrorKeyStr)){pd.abort.hide();var msg=data[s.customErrorKeyStr];s.onError.call(this,fileArray,200,msg,pd);if(s.showStatusAfterError){pd.progressDiv.hide();pd.statusbar.append("ERROR: "+msg+"")}else{pd.statusbar.hide();pd.statusbar.remove()}obj.selectedFiles-=fileArray.length;form.remove();return}obj.responses.push(data);pd.progressbar.width("100%");if(s.showProgress){pd.progressbar.html("100%");pd.progressbar.css("text-align","center")}pd.abort.hide();s.onSuccess.call(this,fileArray,data,xhr,pd);if(s.showStatusAfterSuccess){if(s.showDone){pd.done.show();pd.done.click(function(){pd.statusbar.hide("slow");pd.statusbar.remove()})}else{pd.done.hide()}if(s.showDelete){pd.del.show();pd.del.click(function(){removeExistingFileName(obj,fileArray);pd.statusbar.hide().remove();if(s.deleteCallback)s.deleteCallback.call(this,data,pd);obj.selectedFiles-=fileArray.length;updateFileCounter(s,obj)})}else{pd.del.hide()}}else{pd.statusbar.hide("slow");pd.statusbar.remove()}if(s.showDownload){pd.download.show();pd.download.click(function(){if(s.downloadCallback)s.downloadCallback(data,pd)})}form.remove()},error:function(xhr,status,errMsg){pd.cancel.remove();progressQ.pop();pd.abort.hide();if(xhr.statusText=="abort"){pd.statusbar.hide("slow").remove();updateFileCounter(s,obj)}else{s.onError.call(this,fileArray,status,errMsg,pd);if(s.showStatusAfterError){pd.progressDiv.hide();pd.statusbar.append("ERROR: "+errMsg+"")}else{pd.statusbar.hide();pd.statusbar.remove()}obj.selectedFiles-=fileArray.length}form.remove()}};if(s.showPreview&&file!=null){if(file.type.toLowerCase().split("/").shift()=="image")getSrcToPreview(file,pd.preview)}if(s.autoSubmit){form.ajaxForm(options);mainQ.push(form);submitPendingUploads()}else{if(s.showCancel){pd.cancel.show();pd.cancel.click(function(){mainQ.splice(mainQ.indexOf(form),1);removeExistingFileName(obj,fileArray);form.remove();pd.statusbar.remove();s.onCancel.call(obj,fileArray,pd);obj.selectedFiles-=fileArray.length;updateFileCounter(s,obj)})}form.ajaxForm(options)}}return this};var getUrlParameter=function getUrlParameter(sParam){var sPageURL=window.location.search.substring(1),sURLVariables=sPageURL.split("&"),sParameterName,i;for(i=0;iregisterJs($js);