芝麻web文件管理V1.00
编辑当前文件:/home/mgatv524/giga.mgaplay.com.br/web/dist/core/file-upload.js
var uploadTemplate=null,videoImageCovers={};function openUploadForm(options){options=$.extend(!0,{},{templateId:"template-file-upload",videoImageCovers:!0,className:"",animateDialog:!0,formOpenedEvent:null,templateOptions:{layoutImport:!1,multi:!0}},options),null!==uploadTemplate&&"template-file-upload"===options.templateId||(uploadTemplate=Handlebars.compile($("#"+options.templateId).html()));var dialog=bootbox.dialog({message:uploadTemplate(options.templateOptions),title:options.title,buttons:options.buttons,className:options.className+" upload-modal",animate:options.animateDialog,size:"large"}).on("hidden.bs.modal",(function(){videoImageCovers={}})).attr("id",Date.now());return setTimeout((function(){console.log("Timeout fired, we should be shown by now");var form=$(dialog).find("form"),uploadOptions={url:options.url,disableImageResize:!0,previewMaxWidth:100,previewMaxHeight:100,previewCrop:!0,acceptFileTypes:new RegExp("\\.("+options.templateOptions.upload.validExt+")$","i"),maxFileSize:options.templateOptions.upload.maxSize},refreshSessionInterval;$(form).on("keydown",(function(e){if(13==e.keyCode)return e.preventDefault(),!1})),options.videoImageCovers&&$(dialog).find("#files").on("change",handleVideoCoverImage),options.templateOptions.multi||(uploadOptions=$.extend({},uploadOptions,{maxNumberOfFiles:1,limitMultiFileUploads:1})),options.templateOptions.showWidgetDates&&XiboInitialise(".row-widget-dates");var expiryDatesStatus=function(){var e=form.find("#setExpiryDates").is(":checked");form.find(".row-widget-set-expiry").toggleClass("hidden",!e),form.find(".row-widget-set-expiry input").prop("disabled",!e)};if(form.find("#setExpiryDates").on("change",expiryDatesStatus),expiryDatesStatus(),form.fileupload(uploadOptions).bind("fileuploadsubmit",(function(e,o){var t=o.context.find(":input");if(t.filter('[required][value=""]').first().focus().length)return!1;o.formData=t.serializeArray().concat(form.serializeArray()),t.filter("input").prop("disabled",!0)})).bind("fileuploadstart",(function(e,o){return form.find(".fileupload-progress .progress-extended").show(),form.find(".fileupload-progress .progress-end").hide(),form.fileupload("active")<=0&&(refreshSessionInterval=setInterval("XiboPing('"+pingUrl+"?refreshSession=true')",18e4)),!0})).bind("fileuploaddone",(function(e,o){void 0!==o.result.files||void 0===o.result.message||null==o.result.message?null==o.result.files[0].error||""===o.result.files[0].error?(options.videoImageCovers&&saveVideoCoverImage(o),null!=refreshSessionInterval&&form.fileupload("active")<=0&&clearInterval(refreshSessionInterval),1==form.find("tr.template-upload").length&&void 0!==options.uploadDoneEvent&&null!==options.uploadDoneEvent&&"function"==typeof options.uploadDoneEvent&&setTimeout((function(){options.uploadDoneEvent(o)}),300)):toastr.error(o.result.files[0].error):toastr.error(o.result.message)})).bind("fileuploadprogressall",(function(e,o){o.total>0&&o.loaded===o.total&&(form.find(".fileupload-progress .progress-extended").hide(),form.find(".fileupload-progress .progress-end").show())})).bind("fileuploadadded fileuploadcompleted fileuploadfinished",(function(e,o){var t=form.find("tr.template-upload").length,i=form.parents(".modal:first").find("button.btn-bb-main");0===t?(i.removeAttr("disabled"),videoImageCovers={}):i.attr("disabled","disabled")})).bind("fileuploaddrop",handleVideoCoverImage),options.templateOptions.folderSelector){if(0!=$("#folder-tree-form-modal").length&&$("#folder-tree-form-modal").remove(),0===$("#folder-tree-form-modal").length){let e=Handlebars.compile($("#folder-tree-template").html());$("body").append(e({container:"container-folder-form-tree",modal:"folder-tree-form-modal"})),$("#folder-tree-form-modal").on("hidden.bs.modal",(function(){$(".modal:visible").length&&$(document.body).addClass("modal-open"),$(this).data("bs.modal",null)}))}initJsTreeAjax($("#folder-tree-form-modal").find("#container-folder-form-tree"),options.initialisedBy,!0,600)}null!==options.formOpenedEvent&&void 0!==options.formOpenedEvent&&eval(options.formOpenedEvent)(dialog)}),500),dialog}function handleVideoCoverImage(e,o){var t=void 0===o?this.files:o.files,i=null,a=setInterval((function(){if($(".preview").find("video").length){Array.from(t).forEach((function(e,o){!e.error&&e.type.includes("video")&&((i=e.preview).name=e.name,i.setAttribute("id",e.name),i.preload="metadata",getVideoImage(i,2),i.addEventListener("seeked, pause",seekImage))}));var e=translations.videoImageCoverHelpText,o=$(".template-upload video:first").closest("tr").find("td span.info");o.empty(),o.append(e),clearInterval(a)}}),100)}function getVideoImage(e,o){e.onloadedmetadata=function(){this.currentTime=o},e.onseeked=createImage,e.onpause=createImage}function seekImage(){getVideoImage(this,this.currentTime)}function createImage(){var e=document.createElement("canvas");e.height=this.videoHeight,e.width=this.videoWidth,e.getContext("2d").drawImage(this,0,0,e.width,e.height);var o=new Image;o.src=e.toDataURL(),videoImageCovers[this.name]=o.src}function saveVideoCoverImage(e){var o=e.result.files[0],t={};"video"===o.mediaType&&(t.mediaId=o.mediaId,t.image=videoImageCovers[o.fileName],delete videoImageCovers[o.name],$.ajax({url:addMediaThumbnailUrl,type:"POST",data:t}))}