stepValidation.php 8.92 KB
Newer Older
Clément Damiens's avatar
 
Clément Damiens committed
1
<?php 
Raph El's avatar
Raph El committed
2
if( $mode != "pdf" ){
3 4
	//if( Form::canFormAccess( ['roles'=>["Financeur"] ], @$parentForm["parent"])  ){
	if( !empty($canAdminAnswer) && $canAdminAnswer === true ){
Raph El's avatar
Raph El committed
5 6
		if( isset($form['id']) )
		{ 
Tibor Katelbach's avatar
Tibor Katelbach committed
7
			$editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$parentForm["_id"]."' data-collection='".Form::COLLECTION."' data-path='params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
Tibor Katelbach's avatar
Tibor Katelbach committed
8

Raph El's avatar
Raph El committed
9 10 11
			$paramsData = [ 
				"limitRoles" =>["Financeur"]
			];
Tibor Katelbach's avatar
Tibor Katelbach committed
12

13 14 15
			if( isset($parentForm["params"][$kunik]) ) {
				if( isset($parentForm["params"][$kunik]["limitRoles"]) ) 
					$paramsData["financersList"] =  $parentForm["params"][$kunik]["limitRoles"];
Raph El's avatar
Raph El committed
16
			}
Tibor Katelbach's avatar
Tibor Katelbach committed
17

Raph El's avatar
Raph El committed
18
			?>
Clément Damiens's avatar
 
Clément Damiens committed
19

20
			<div id="copyEquilibreBudgetaire"></div>
Clément Damiens's avatar
 
Clément Damiens committed
21

22 23 24 25 26 27 28
			<table class="table table-bordered table-hover  directoryTable" >
				<tbody class="directoryLines">	
				
					<tr>
						<td colspan='2' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>">Validation</h4>
						</td>
					</tr>
Raph El's avatar
Raph El committed
29
				<?php 
30 31 32 33 34 35 36 37 38 39
				if( isset( $answer["validation"][ $form['id'] ] ) ){ ?>
					<tr>
						<td colspan='2' align="center">
							<button id="generateCopil2" class="generateCopil btn btn-primary" data-id="<?php echo (string)$answer["_id"] ?>" data-date="<?php echo date("Y-m-d") ?>" data-title="Compte Rendu de la réunion de finalisation" data-key="copilReunionFinalisation">Générer le dossier validé</button>
					<?php $pdf=Document::getListDocumentsWhere([ "id"=>(string)$answer["_id"], "type"=>Form::ANSWER_COLLECTION, "doctype"=>"file", "subKey"=>"pdf".$form['id'] ] ,"file");
						 ?>
						</td>
					</tr>
				<?php   
				}
Raph El's avatar
Raph El committed
40 41


42
				if(isset($answer["validation"][$form['id']])){ 
Raph El's avatar
Raph El committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
					$color = "danger";
					$lbl = "Non validé";
					if(isset($answer["validation"][$form['id']]["valid"])){
						if( $answer["validation"][$form['id']]["valid"] == "valid" ){
							$color = "success";
							$lbl = "Validé sans réserves";
						} else if( $answer["validation"][$form['id']]["valid"] == "validReserve" ){
							$color = "warning";
							$lbl = "Validé avec réserves";
						}
					}

					$editState = ( isset( $answer["validation"][$form['id']] ) ) ? "" : " <a href='javascript:;' data-type='".$form['id']."' class='validEdit btn btn-default btn-xs'><i class='fa fa-pencil'></i></a>";
					?>
					<tr>
						<td>Avis</td>
						<td><h4 class="label label-<?php echo $color?>"><?php echo $lbl?></h4> <?php echo $editState ?></td>
					</tr>
					<tr>
						<td>Commentaire global</td>
						<td><?php if( isset($answer["validation"][$form['id']]["description"] ) ) echo $answer["validation"][$form['id']]["description"]; ?></td>
					</tr>
					<tr>
						<td>Date</td>
						<td><?php if( isset($answer["validation"][$form['id']]["date"] ) ) echo $answer["validation"][$form['id']]["date"]; ?></td>
					</tr>
					<?php 
70 71 72 73 74 75 76 77 78 79 80 81
					if(!empty($ficheAction)){ 
						//$ficheAction = array_splice($ficheAction, count($ficheAction)-1);
						$histo = 0;
						foreach($ficheAction as $k => $v){ 
							if($histo < 1){?>
							<tr>
								<td>Fiche Action Finale</td>
								<td><a href='<?php echo $v["docPath"] ?>' target='_blank' class="link-files"><i class="fa fa-file-pdf-o text-red"></i> <?php echo $v["name"] ?></a></td>
							</tr>
						<?php	$histo++; }
						} 
					} ?>
Raph El's avatar
Raph El committed
82

83 84 85 86 87 88 89 90 91
				<?php 
				}  ?>
					<tr>
						<td colspan='2' class="text-center" >
							<a href="javascript:;" data-type="<?php echo $form['id'] ?>" class="validEdit btn btn-primary">Valider cette action</a>				
						</td>
					</tr>
				</tbody>
			</table>
Raph El's avatar
Raph El committed
92 93 94 95
		 

		
	<?php 
96
		} ?>
Raph El's avatar
Raph El committed
97 98 99 100 101 102 103 104 105 106




	<script type="text/javascript">

	sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;

	$(document).ready(function() { 

107
	    mylog.log("render","/modules/survey/views/tpls/forms/cplx/stepValidation.php");
Raph El's avatar
Raph El committed
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

	    sectionDyf.<?php echo $kunik ?>Params = {
			"jsonSchema" : {	
		        "title" : "<?php echo $kunik ?> config",
		        "icon" : "fa-cog",
		        "properties" : {
		            limitRoles : {
		                inputType : "array",
		                label : "Liste des roles qui pourront valider cette étape",
		                values :  sectionDyf.<?php echo $kunik ?>ParamsData.limitRoles
		            }
		        },
		        save : function () {  
		            tplCtx.value = {};
		            $.each( sectionDyf.<?php echo $kunik ?>Params.jsonSchema.properties , function(k,val) { 
		        		if(val.inputType == "array")
		        		 	tplCtx.value[k] = getArray('.'+k+val.inputType);
		        		else if(val.inputType == "properties")
		        		 	tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
		        		else
		        		 	tplCtx.value[k] = $("#"+k).val();
		        	 });
		            mylog.log("save tplCtx",tplCtx);
		            
		            if(typeof tplCtx.value == "undefined")
		            	toastr.error('value cannot be empty!');
		            else {
		                dataHelper.path2Value( tplCtx, function(params) { 
		                    urlCtrl.loadByHash(location.hash);
		                } );
		            }

		    	}
Tibor Katelbach's avatar
Tibor Katelbach committed
141
		    }
Raph El's avatar
Raph El committed
142 143
		};

Clément Damiens's avatar
 
Clément Damiens committed
144

Raph El's avatar
Raph El committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
	   $(".edit<?php echo $kunik ?>Params").off().on("click",function() {  
	        tplCtx.id = $(this).data("id");
	        tplCtx.collection = $(this).data("collection");
	        tplCtx.path = $(this).data("path");
	        //if no params config on the element.costum.form.params.<?php echo $kunik ?>
	        //then we load default values available in forms.inputs.<?php echo $kunik ?>xxx.params
	        //mylog.log(".editParams",sectionDyf.<?php echo $kunik ?>Params,calData);
	        dyFObj.openForm( sectionDyf.<?php echo $kunik ?>Params,null, sectionDyf.<?php echo $kunik ?>ParamsData);
	    });

	    //documentManager.bindEvents();

	    typeObj.validation<?php echo $form['id'] ?> = {
		    jsonSchema : {
			    title : "Validation",
			    icon : "gavel",
			    onLoads : {
			    	sub : function(){
		    		 	dyFInputs.setSub("bg-red");
		    		},
			    },
			    save : function() { 	    	
			   
					var formData = $("#ajaxFormModal").serializeFormJSON();
					var today = new Date();
					today = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();
171

Raph El's avatar
Raph El committed
172
			    	ctxTpl = {
Clément Damiens's avatar
Clément Damiens committed
173
			    		id : "<?php echo (string)$answer['_id'] ?>",
Raph El's avatar
Raph El committed
174 175 176 177 178 179 180 181 182 183
			    		collection : "answers",
			    		path : "validation."+formData.form,
	            		value : {
	            			//who : formData.who,
	            			valid : formData.valid,
	            			description : formData.description,
	            			date : today , 
	            			user : userId
	            		}
			    	};
Clément Damiens's avatar
Clément Damiens committed
184
			    	if(form.subForms.length == $.inArray( "<?php echo $form['id'] ?>", form.subForms )+1 && formData.valid == "valid")
185
						ctxTpl.value.finished = true;
Raph El's avatar
Raph El committed
186 187 188 189 190 191 192 193
			    	
			    	mylog.log("validation save",ctxTpl);

			  	 	dataHelper.path2Value( ctxTpl, function(params) { 
			  	 		dyFObj.closeForm();
			  	 		//only increment step form to next step if step valid
			  	 		if( ctxTpl.value.valid == "valid" || ctxTpl.value.valid == "validReserve" ){
				  	 		step = 0;
Clément Damiens's avatar
Clément Damiens committed
194
				  	 		if(form.subForms.length == $.inArray( "<?php echo $form['id'] ?>", form.subForms )+1)
Raph El's avatar
Raph El committed
195 196
				  	 			step = "all";
				  	 		else 
Clément Damiens's avatar
Clément Damiens committed
197
				  	 			step = form.subForms[$.inArray( "<?php echo $form['id'] ?>", form.subForms )+1];
Raph El's avatar
Raph El committed
198 199

				  	 		ctxTpl = {
Clément Damiens's avatar
Clément Damiens committed
200
					    		id    : "<?php echo (string)$answer['_id'] ?>",
Raph El's avatar
Raph El committed
201 202 203 204 205 206 207 208 209 210 211 212 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 245 246 247 248 249 250 251 252
					    		collection : "answers",
					    		path  : "step",
					    		value : step
					    	};
					    	mylog.log("save step save",ctxTpl);
					  	 	dataHelper.path2Value( ctxTpl, function(params) { 
					  	 		urlCtrl.loadByHash(location.hash);
					  	 	} );
					  	 } else 
					  	 	urlCtrl.loadByHash(location.hash);
			  	 	} );

						
			    },
			    properties : {
			    	info : {
		                inputType : "custom",
		                html:"<p></p>",
		            },
		            valid : {
	                    "label" : "Valider",
	                    "inputType" : "select",
	                    "placeholder" : "---- Selectionner Valider ----",
	                    "options" : {
	                    	"notValid":"Non validé",
	                        "validReserve" : "Validé avec réserves",
	                        "valid" : "Validé sans réserve"
	                    }
	                },
		            description : dyFInputs.textarea( tradDynForm["description"], "..." ),
		      		//  date : {
				    // 	inputType : "date",
				    // 	label : "Date",
				    // 	placeholder : "Date de Validation",
				    // 	rules : { 
				    // 		required : true,
				    // 		greaterThanNow : ["DD/MM/YYYY"]
				    // 	}
				    // },
		            form : dyFInputs.inputHidden()
			    }
			}
		};
	    $('.validEdit').off().on("click", function() {
	    	var setVal = { form : $(this).data("type")};
			dyFObj.openForm( typeObj[ 'validation'+setVal.form ], null, setVal );
		});

		
	    
	});
	</script>
253 254
	<?php 
	} else { ?>
Raph El's avatar
Raph El committed
255 256 257 258 259 260
		<div class="col-xs-12">
			Seuls les référents du territoire, le porteur de l’action et l’équipe nationale ont accès à cette étape.
		</div>
	<?php } 
}
?>