uploader.php 17.3 KB
Newer Older
Clément Damiens's avatar
 
Clément Damiens committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php //var_dump($form["inputs"][$key]);var_dump($key);var_dump($form["id"]);var_dump(@$answer);var_dump(@$form); 
$domUploader=$form["id"]."_".$key."_uploader";
$inputsObj=$form["inputs"][$key];
$uploaderObj=$form["inputs"][$key]["uploader"];
$uploaderObj["contextId"]=(string)$answer["_id"];
$uploaderObj["dom"]=$domUploader;
$uploaderObj["contextType"]=Form::ANSWER_COLLECTION;
$uploaderObj["formats"]=(isset($uploaderObj["formats"])) ? $uploaderObj["formats"] : ['jpeg', "pdf", 'jpg', 'gif', 'png'];
$uploaderObj["params"]=array("subKey"=>$form["id"].".".$key);
if(isset($uploaderObj["cryptage"]))
	$uploaderObj["params"]["cryptage"]=true;
if(isset($uploaderObj["restricted"]))
	$uploaderObj["params"]["restricted"]=true;
$initAnswerFiles=Document::getListDocumentsWhere(array(
		  			"id"=>$uploaderObj["contextId"], 
		  			"type"=>$uploaderObj["contextType"],
		  			"subKey"=>$uploaderObj["params"]["subKey"]), "file");
?>

<style type="text/css">
	.uploader_container{
		white-space: normal;
	}
</style>
<div class="uploader_container col-xs-12 no-padding margin-bottom-20">
26 27 28 29 30 31 32 33 34 35
	<br/>
	<label for="<?php echo $kunik ?>">
		<h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn ?>
		</h4>
	</label><!--<h4><?php echo @$inputsObj["label"] ?></h4>-->
	<?php if(isset($inputsObj["info"])){ ?> 
		<span class="italic">
			<?php echo $inputsObj["info"] ?>
		</span>
	<?php } 
Raph El's avatar
Raph El committed
36
	if($mode=="r" || $mode=="pdf"){ 
37 38 39 40 41 42 43
        echo $this->renderPartial("co2.views.pod.docsList",array("edit"=>false, "documents"=>$initAnswerFiles,"docType"=>@$uploaderObj["docType"]) ); 
	} else{ 
		if(!isset($uploaderObj["paste"]) || $uploaderObj["paste"]){ ?> 
			<input type="text" name="upload" id="<?php echo $domUploader ?>_paste" placeholder="coller une image de votre navigateur ici" class="form-control text-center qq-paste-input"/>
		<?php } ?>
		<div class="col-xs-12 fine-uploader-manual-trigger no-padding"  id="<?php echo $domUploader; ?>" data-type="" data-id=""></div>
	    	<?php if(isset($uploaderObj["docType"]) && $uploaderObj["docType"]=="image"){ ?>
Clément Damiens's avatar
Clément Damiens committed
44
				<script type="text/template" id="qq-template-gallery<?php echo $domUploader ?>">
Clément Damiens's avatar
 
Clément Damiens committed
45
			<?php }else{ ?>
Clément Damiens's avatar
Clément Damiens committed
46 47
				<script type="text/template" id="qq-template-manual-trigger<?php echo $domUploader ?>">
			<?php  }  ?>
Clément Damiens's avatar
 
Clément Damiens committed
48 49

			<div class="qq-uploader-selector qq-uploader qq-upload-drop-area-active<?php if(isset($fieldObj["docType"]) && $fieldObj["docType"]=="image"){ echo " qq-gallery"; } ?>" qq-drop-area-text="drop files" style="<?php if(!isset($uploaderObj["paste"]) || $uploaderObj["paste"]){ ?>border-radius:0px 0px 10px 10px;<?php } ?>">
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
				<div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container">
					<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div>
				</div>
				<!--<div class="qq-paste-element-triger"><input type="text" value="" placeholder="paste a link"/></div>qq-hide-dropzone-->
				<div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone>
					<span class="qq-upload-drop-area-text-selector"></span>
				</div>
				<div class="col-xs-12 margin-bottom-10 text-center">
					<div class="qq-upload-button-selector btn btn-primary">
						<div>Selectionner un document</div>
					</div>	
				</div>
				<button type="button" id="trigger-upload" class="btn btn-danger hide">
        	        <i class="icon-upload icon-white"></i> <?php echo Yii::t("common", "Save") ?>
                </button>
				<span class="qq-drop-processing-selector qq-drop-processing">
					<span>En cours de progression...</span>
					<span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span>
				</span>
				<?php if(isset($uploaderObj["docType"]) && $uploaderObj["docType"]=="image"){ ?>
					<ul class="qq-upload-list-selector qq-upload-list" role="region" aria-live="polite" aria-relevant="additions removals">
						<li>
							<span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
							<div class="qq-progress-bar-container-selector qq-progress-bar-container">
Clément Damiens's avatar
 
Clément Damiens committed
74
								<div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
75 76 77
							</div>
							<span class="qq-upload-spinner-selector qq-upload-spinner"></span>
							<div class="qq-thumbnail-wrapper">
Clément Damiens's avatar
 
Clément Damiens committed
78
								<img class="qq-thumbnail-selector" qq-max-size="120" qq-server-scale>
79 80 81
							</div>
							<button type="button" class="qq-upload-cancel-selector qq-upload-cancel">X</button>
							<button type="button" class="qq-upload-retry-selector qq-upload-retry">
Clément Damiens's avatar
 
Clément Damiens committed
82 83
								<span class="qq-btn qq-retry-icon" aria-label="Retry"></span>
								Retry
84 85
							</button>
							<div class="qq-file-info">
Clément Damiens's avatar
 
Clément Damiens committed
86 87 88 89 90 91
								<div class="qq-file-name">
								<span class="qq-upload-file-selector qq-upload-file"></span>
								</div>
								<input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
								<span class="qq-upload-size-selector qq-upload-size"></span>
								<button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">
92
									<?php echo Yii::t("common", "Delete") ?>
Clément Damiens's avatar
 
Clément Damiens committed
93 94 95 96 97 98 99 100
								</button>
								<button type="button" class="qq-btn qq-upload-pause-selector qq-upload-pause">
								<span class="qq-btn qq-pause-icon" aria-label="Pause"></span>
								</button>
								<button type="button" class="qq-btn qq-upload-continue-selector qq-upload-continue">
								<span class="qq-btn qq-continue-icon" aria-label="Continue"></span>
								</button>
							</div>
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
							<button type="button" class="view-btn hide btn">View</button>
						</li>
					</ul>
				<?php }else{ ?>
					<ul class="qq-upload-list-selector qq-upload-list" aria-live="polite" aria-relevant="additions removals">
				        <li>
		                    <div class="qq-progress-bar-container-selector">
		                        <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div>
		                    </div>
				             <span class="qq-upload-spinner-selector qq-upload-spinner"></span>
		                    <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale>
		                    <a href="" target="_blank" class="qq-upload-link">
		                    	<span class="qq-upload-file-selector qq-upload-file"></span>
			                    <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text">
			                    <span class="qq-upload-size-selector qq-upload-size"></span>
		                    </a>
				            <button type="button" class="qq-btn qq-upload-cancel-selector qq-upload-cancel"><?php echo Yii::t("common", "Cancel") ?></button>
		                    <button type="button" class="qq-btn qq-upload-retry-selector qq-upload-retry"><?php echo Yii::t("common", "Retry") ?></button>
		                    <button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete"><?php echo Yii::t("common", "Delete") ?></button>
							<button type="button" class="view-btn hide btn">View</button>
				            <span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span>
		                </li>
		            </ul>
				<?php } ?>
				<dialog class="qq-alert-dialog-selector">
					<div class="qq-dialog-message-selector"></div>
						<div class="qq-dialog-buttons">
						<button type="button" class="qq-cancel-button-selector">Close</button>
					</div>
				</dialog>
				<dialog class="qq-confirm-dialog-selector">
					<div class="qq-dialog-message-selector"></div>
					<div class="qq-dialog-buttons">
						<button type="button" class="qq-cancel-button-selector">No</button>
						<button type="button" class="qq-ok-button-selector">Yes</button>
					</div>
				</dialog>
				<dialog class="qq-prompt-dialog-selector">
					<div class="qq-dialog-message-selector"></div>
					<input type="text">
					<div class="qq-dialog-buttons">
						<button type="button" class="qq-cancel-button-selector">Cancel</button>
						<button type="button" class="qq-ok-button-selector">Ok</button>
					</div>
				</dialog>
Clément Damiens's avatar
 
Clément Damiens committed
146 147
				<div class="col-xs-12 text-center fineUploaderOpenFormSubmit" style="display: none;">
					<a href="javascript:;" class="btn btn-success margin-top-10 col-sm-6 col-sm-offset-3 fineUploader_submit" data-dom-uploader="<?php echo $domUploader ?>" id="<?php echo $domUploader ?>_submit"><?php echo Yii::t("common","Save") ?></a>
148 149 150
				</div>
			</div>
		</script>
Clément Damiens's avatar
 
Clément Damiens committed
151
	<!---->
152 153
	</div>
<?php } ?>
Clément Damiens's avatar
Clément Damiens committed
154
</div>
Raph El's avatar
Raph El committed
155
<?php if($mode != "pdf"){ ?>
Clément Damiens's avatar
 
Clément Damiens committed
156 157 158 159 160 161 162 163
<script type="text/javascript">
	//var domUploader="<?php echo $domUploader ?>";
	var uploadAnswerObj=<?php echo json_encode($uploaderObj); ?>;
	uploadAnswerObj["path"]=uploadObj.get(uploadAnswerObj.contextType,uploadAnswerObj.contextId, uploadAnswerObj.docType, null, null, uploadAnswerObj.extraPath);
	var initListUploader=<?php echo json_encode(@$initAnswerFiles); ?>;
	jQuery(document).ready(function() {
		$("#"+uploadAnswerObj.dom).off();
		$("#"+uploadAnswerObj.dom).fineUploader({
Clément Damiens's avatar
Clément Damiens committed
164
            template: ((uploadAnswerObj.docType=="image") ? 'qq-template-gallery'+uploadAnswerObj.dom : 'qq-template-manual-trigger'+uploadAnswerObj.dom),
Clément Damiens's avatar
 
Clément Damiens committed
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
            paste: {
		        defaultName: 'pasted_image',
		       //promptForName:true,
		        targetElement: $("#"+uploadAnswerObj.dom+"_paste")
		    },
		    classes : {
		    	dropActive : true
		    },
            request: {
                endpoint: uploadAnswerObj.path,
                params : uploadAnswerObj.params
            },
            validation: {
                allowedExtensions: uploadAnswerObj.formats,
                sizeLimit: ((typeof uploadAnswerObj.sizeLimit != "undefined") ? uploadAnswerObj.sizeLimit : 5000000),
                itemLimit: ((typeof uploadAnswerObj.itemLimit != "undefined") ? uploadAnswerObj.itemLimit : 3)
            },
            messages: {
		        sizeError : '{file} '+tradDynForm.istooheavy+'! '+tradDynForm.limitmax+' : {sizeLimit}.',
		        typeError : '{file} '+tradDynForm.invalidextension+'. '+tradDynForm.extensionacceptable+': {extensions}.'
		    },
		    session:{
		    	endpoint:null
		    },
		    deleteFile: {
		        enabled: true//,
		       // endpoint: baseUrl+'/'+moduleId+'/document/delete/id/server/file'
		    },
            callbacks: {
            	//when a img is selected
Clément Damiens's avatar
 
Clément Damiens committed
195
			    /*onSubmit: function(id, fileName) {
Clément Damiens's avatar
 
Clément Damiens committed
196 197
			    	//if(typeof v.endPoint == "undefined")
			    	//	$(domElement).fineUploader('setEndpoint',uploadObj.path);
Clément Damiens's avatar
 
Clément Damiens committed
198 199
			    	console.log("coucou",id,this);
			    	alert(uploadAnswerObj.dom);
Clément Damiens's avatar
 
Clément Damiens committed
200 201 202 203 204 205 206 207 208 209 210 211
			    	listObject=$("#"+uploadAnswerObj.dom).fineUploader('getUploads');
					showBtnUpload=false;
					if(listObject.length > 0){
			    		$.each(listObject, function(e,v){
			    			if(v.status == "submitting")
			    				showBtnUpload=true;
			    		});
			    	}
					if( showBtnUpload ){
			    		$("#"+uploadAnswerObj.dom+"_submit").parent().show();//.fineUploader('uploadStoredFiles');
			    	}
				    
Clément Damiens's avatar
 
Clément Damiens committed
212
			    },*/
Clément Damiens's avatar
 
Clément Damiens committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
			   /* onCancel: function(id) {
			    	if(($("ul.qq-upload-list > li").length-1)<=0)
			    		$('#trigger-upload').addClass("hide");
    			},*/
    			onPasteReceived: function(blob) {
    			},
    			onSubmitDelete: function(id) {
    				//alert("id"); 
    				//mylog.log(this.getName(id));
        			//this.setDeleteFileParams({ids: [this.getName(id)]}, id);
    			},
			    //launches request endpoint
			    //onUpload: function(id, fileName) {
			      //alert(" > upload : "+id+fileName+contextData.type+contextData.id);
			      //alert(" > request : "+ uploadObj.id +" :: "+ uploadObj.type);
			      //mylog.log('onUpload uplaodObj',uploadObj);
			      //var ex = $('.fine-uploader-manual-trigger').fineUploader('getEndpoint');
			      //mylog.log('onUpload getEndpoint',ex);
			    //},
			    //launched on upload
			    //onProgress: function(id, fileName, uploadedBytes,totalBytes) {
			    	/*mylog.log('onProgress uplaodObj',uploadObj);
			    	var ex = $('.fine-uploader-manual-trigger').fineUploader('getEndpoint');
			    	mylog.log('onProgress getEndpoint',ex);
			    	mylog.log('getInProgress',$('.fine-uploader-manual-trigger').fineUploader('getInProgress'));*/
			      //alert("progress > "+" :: "+ uploadObj.id +" :: "+ uploadObj.type);
			    //},
			    //when every img finish upload process whatever the status
			    onComplete: function(id, fileName,responseJSON,xhr) {
			    	mylog.log("onCompleate", id, fileName, responseJSON);
			    	setFiles={};
			    	setFiles[responseJSON.id.$id]=responseJSON;
Clément Damiens's avatar
 
Clément Damiens committed
245
			    	
Clément Damiens's avatar
 
Clément Damiens committed
246
			            var serverPathToFile = responseJSON.docPath,
Clément Damiens's avatar
 
Clément Damiens committed
247 248 249 250 251 252 253 254 255
				       	fileItem = this.getItemByFileId(id);
				        var viewTnh = qq(fileItem).getByClass("qq-upload-link")[0];
				        if(typeof viewTnh != "undefined")
                    		viewTnh.setAttribute("href", serverPathToFile);
				    	//  $fileItem.find(".qq-upload-link")
				        //    .attr("href", serverPathToFile)
				        //  .removeClass("hide");
				        this.setDeleteFileEndpoint(baseUrl+"/"+moduleId+"/document/deletedocumentbyid/id/"+responseJSON.id.$id, id);
				   
Clément Damiens's avatar
 
Clément Damiens committed
256 257 258 259 260 261 262 263 264 265 266 267
			    	if(!responseJSON.result){
			    		toastr.error(trad.somethingwentwrong+" : "+responseJSON.msg );		
			    		mylog.error(trad.somethingwentwrong , responseJSON.msg)
			    	}
			    },
			    onStatusChange : function(id, oldStatus, newStatus) {
			    	
				},
                   
			    onSessionRequestComplete:function(response, success, xhrOrXdr){
			    },
			    //when all upload is complete whatever the result
Clément Damiens's avatar
 
Clément Damiens committed
268
			   /* onAllComplete: function(succeeded, failed) {
Clément Damiens's avatar
 
Clément Damiens committed
269
			    	mylog.log("ooooooooooooo",succeeded,failed);
Clément Damiens's avatar
 
Clément Damiens committed
270
			    	$("#"+uploadAnswerObj.dom+"_submit").parent().fadeOut();
Clément Damiens's avatar
 
Clément Damiens committed
271
			    },*/
Clément Damiens's avatar
 
Clément Damiens committed
272 273 274 275 276 277 278 279 280 281 282
			    onError: function(id) {
			      toastr.info(trad.somethingwentwrong);
			    }
			},
            thumbnails: {
                placeholders: {
                    waitingPath: baseUrl+'/plugins/fine-uploader/jquery.fine-uploader/processing.gif',
                    notAvailablePath: baseUrl+'/plugins/fine-uploader/jquery.fine-uploader/retry.gif'
                }
            },
            autoUpload: false
Clément Damiens's avatar
 
Clément Damiens committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
        }).on("submit", function(event,id, fileName) {
	    	//if(typeof v.endPoint == "undefined")
	    	//	$(domElement).fineUploader('setEndpoint',uploadObj.path);
	    	listObject=$(this).fineUploader('getUploads');
			showBtnUpload=false;
			if(listObject.length > 0){
	    		$.each(listObject, function(e,v){
	    			if(v.status == "submitting")
	    				showBtnUpload=true;
	    		});
	    	}
			if( showBtnUpload ){
	    		$(this).find(".fineUploaderOpenFormSubmit").show();//.fineUploader('uploadStoredFiles');
	    	}
		    
	    })/*.on("complete", function(event, id, fileName,responseJSON,xhr){
	    	mylog.log("onCompleate", id, fileName, responseJSON);
	    	setFiles={};
	    	setFiles[responseJSON.id.$id]=responseJSON;
    	    var serverPathToFile = responseJSON.docPath,
	       	fileItem = this.getItemByFileId(id);
	        var viewTnh = qq(fileItem).getByClass("qq-upload-link")[0];
	        if(typeof viewTnh != "undefined")
        		viewTnh.setAttribute("href", serverPathToFile);
	    	//  $fileItem.find(".qq-upload-link")
	        //    .attr("href", serverPathToFile)
	        //  .removeClass("hide");
	        this.setDeleteFileEndpoint(baseUrl+"/"+moduleId+"/document/deletedocumentbyid/id/"+responseJSON.id.$id, id);
	   
	    	if(!responseJSON.result){
	    		toastr.error(trad.somethingwentwrong+" : "+responseJSON.msg );		
	    		mylog.error(trad.somethingwentwrong , responseJSON.msg)
	    	}
    	})*/.on("allComplete", function(event, succeeded, failed) {
	    	mylog.log("ooooooooooooo",succeeded,failed);
	    	$(this).find(".fineUploaderOpenFormSubmit").fadeOut();
	    });
Clément Damiens's avatar
 
Clément Damiens committed
320 321 322 323 324 325 326 327 328 329 330
		if(typeof initListUploader != "undefined" && Object.keys(initListUploader).length > 0){
			//objectListFiles=uploadObj.prepareInit(initFiles);
        	//console.log(objectListFiles,"bloublou");
			$("#"+uploadAnswerObj.dom).fineUploader("addInitialFiles",prepFileForFormsUploader(initListUploader));
			$i=0;
			$.each(initListUploader, function(e,v){
				$("#"+uploadAnswerObj.dom).find(".qq-file-id-"+$i+" .qq-upload-link").attr("href", v.docPath);
				$i++;
			});
		}
					
Clément Damiens's avatar
 
Clément Damiens committed
331 332 333
		$(".fineUploader_submit").off().on("click",function(){
			idUploader=$(this).data("dom-uploader");
			listObject=$("#"+idUploader).fineUploader('getUploads');
Clément Damiens's avatar
 
Clément Damiens committed
334
			goToUpload=false;
Clément Damiens's avatar
Clément Damiens committed
335 336
			alert(idUploader);
			mylog.log(listObject);
Clément Damiens's avatar
 
Clément Damiens committed
337 338 339 340 341 342
			if(listObject.length > 0){
	    		$.each(listObject, function(e,v){
	    			if(v.status == "submitted")
	    				goToUpload=true;
	    		});
	    	}
Clément Damiens's avatar
Clément Damiens committed
343
	    	alert(goToUpload);
Clément Damiens's avatar
 
Clément Damiens committed
344 345
			if( goToUpload ){
				insideCallBMulti=true;
Clément Damiens's avatar
 
Clément Damiens committed
346
	    		$("#"+idUploader).fineUploader('uploadStoredFiles');
Clément Damiens's avatar
 
Clément Damiens committed
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
		    	//principalement pour les surveys
		    	//if(typeof callB == "function")
	    		//	callB();
	    	}
		});
});
function prepFileForFormsUploader(data){
		arrayList=[];
		$i=0;
		$.each(data, function(e, v){
			item=new Object;
			item.size=v.size,
			item.uuid=e,
			item.name=v.name,
			item.deleteFileEndpoint=baseUrl+"/"+moduleId+"/document/deletedocumentbyid/id";
			item.deleteFileParams={ids:e};
			if(typeof v.imageThumbPath != "undefined"){
				item.thumbnailUrl=v.imageThumbPath;
				item.pathUrl=v.docPath;
			}if(typeof v.docPath != "undefined"){
				item.thumbnailUrl=v.docPath;
				item.pathUrl=v.docPath;
			}
			//initListUploader[e].uuid=$i;
			$i++;
			arrayList.push(item);
		} );
		return arrayList;
	}
Raph El's avatar
Raph El committed
376 377
</script>
<?php } ?>