budget.php 12 KB
Newer Older
Clément Damiens's avatar
 
Clément Damiens committed
1 2 3 4
<?php if($answer){ 
$debug = false;
$editBtnL = (Yii::app()->session["userId"] == $answer["user"]) ? " <a href='javascript:;' data-id='".$answer["_id"]."' data-collection='".Form::ANSWER_COLLECTION."' data-path='".$answerPath."' class='add".$kunik." btn btn-default'><i class='fa fa-plus'></i> Ajouter une ligne </a>" : "";

5
$editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$el["_id"]."' data-collection='".$this->costum["contextType"]."' data-path='costum.form.params.".$kunik."' class='previewTpl edit".$kunik."Params btn btn-xs btn-danger'><i class='fa fa-cog'></i> </a>" : "";
Clément Damiens's avatar
 
Clément Damiens committed
6 7 8 9 10 11 12

$paramsData = [ 
	"group" => [ 
		"Feature", 
		"Costum", 
		"Chef de Projet", 
		"Data", 
Raph El's avatar
Raph El committed
13 14
		"Mantenance" 
	],
Clément Damiens's avatar
 
Clément Damiens committed
15
	"nature" => [
Raph El's avatar
Raph El committed
16 17 18 19 20 21 22 23
		"investissement" => "Investissement",
		"fonctionnement" => "Fonctionnement"
	],
	"amounts" => [
		"price" => "Price"
	],
	"estimate" => false 
];
Clément Damiens's avatar
 
Clément Damiens committed
24

25 26 27 28 29 30 31 32
if( isset($this->costum["form"]["params"][$kunik]["group"]) ) 
	$paramsData["group"] =  $this->costum["form"]["params"][$kunik]["group"];
if( isset($this->costum["form"]["params"][$kunik]["nature"]) ) 
	$paramsData["nature"] =  $this->costum["form"]["params"][$kunik]["nature"];
if( isset($this->costum["form"]["params"][$kunik]["amounts"]) ) 
	$paramsData["amounts"] =  $this->costum["form"]["params"][$kunik]["amounts"];
if( isset($this->costum["form"]["params"][$kunik]["estimate"]) ) 
	$paramsData["estimate"] =  $this->costum["form"]["params"][$kunik]["estimate"];
Clément Damiens's avatar
 
Clément Damiens committed
33 34 35 36 37 38 39 40 41 42 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 70 71 72 73

// if(isset($answers)){
// 	foreach ($answers as $q => $a) {
// 		if(isset($a["group"]))
// 			$paramsData["group"][] = $a["group"];
// 	}
// }


$properties = [
		"group" => [
            "placeholder" => "Groupé",
            "inputType" => "select",
            "options" => $paramsData["group"],
            "rules" => [ "required" => true ]
        ],
        "nature" => [
            "placeholder" => "Nature de l’action",
            "inputType" => "select",
            "options" => $paramsData["nature"],
            "rules" => [ "required" => true ]
        ],
        "poste" => [
            "inputType" => "text",
            "label" => "Poste de dépense",
            "placeholder" => "Poste de dépense",
            "rules" => [ "required" => true  ]
        ]
    ];
    foreach ($paramsData["amounts"] as $k => $l) {
    	$properties[$k] = [ "inputType" => "text",
				            "label" => $l,
				            "propType" =>"amount",
				            "placeholder" => $l,
				            //"rules" => [ "required" => true, "number" => true ]
				        ];
    }
    if($debug)var_dump($answers);
    if($debug)var_dump($paramsData);
?>	

Raph El's avatar
Raph El committed
74
<?php
Raph El's avatar
Raph El committed
75
echo $this->renderPartial("survey.views.tpls.forms.cplx.budgetTable",
Raph El's avatar
Raph El committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
	                      [ 
	                        "form" => $form,
	                        "wizard" => true, 
	                        "answers"=>$answers,
	                        "answer"=>$answer,
                            "mode" => $mode,
                            "kunik" => $kunik,
                            "key" => $key,
                            "titleColor" => $titleColor,
                            "properties" => $properties,


                            "label" => $label,
                            "editQuestionBtn" => $editQuestionBtn,
                            "editParamsBtn" => $editParamsBtn,
                            "editBtnL" => $editBtnL,
                            "info" => $info,
	                        //"showForm" => $showForm,
	                        "paramsData" => $paramsData,
	                        "canEdit" => $canEdit,  
	                        //"el" => $el 
	                    ] ,true );
Clément Damiens's avatar
 
Clément Damiens committed
98 99 100 101 102 103 104 105 106 107

?>

<?php if( $paramsData["estimate"] ) {  ?>
<div class="form-estimate" style="display:none;">
  	Proposition de prix : <br/>
	<input type="text" id="priceEstimate" name="priceEstimate" style="width:100%;">
	Durée : <br/>
	<input type="text" id="daysEstimate" name="daysEstimate" style="width:100%;">
</div>
Raph El's avatar
Raph El committed
108 109 110 111 112
<?php } 


if($mode != "r"){
?>
Clément Damiens's avatar
 
Clément Damiens committed
113 114 115 116 117 118 119 120 121

<script type="text/javascript">

var <?php echo $kunik ?>Data = <?php echo json_encode( (isset($answers)) ? $answers : null ); ?>;
sectionDyf.<?php echo $kunik ?>ParamsData = <?php echo json_encode( $paramsData ); ?>;

$(document).ready(function() { 
	
	sectionDyf.<?php echo $kunik ?> = {
122 123 124 125 126
		jsonSchema : {	
	        title : "Budget prévisionnel",
            icon : "fa-money",
            text : "Décrire ici les principaux postes de dépenses : à quoi correspondent les coûts ? <br/>Préciser ce qui relève des dépenses de fonctionnement et des dépenses d’investissement.<br/>Les coûts doivent être en <b>hors taxe</b>.",
	        properties : <?php echo json_encode( $properties ); ?>,
Clément Damiens's avatar
 
Clément Damiens committed
127 128 129 130 131 132 133 134 135 136 137 138 139
	        save : function () {  
	        	var today = new Date();
	            tplCtx.value = { date : today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear() };
	            $.each( sectionDyf.<?php echo $kunik ?>.jsonSchema.properties , function(k,val) { 
	        		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) { 
	                    $("#ajax-modal").html("<div class='text-center'><i class='fa fa-spin fa-spinner'></i></div>");//$("#ajax-modal").modal('hide');
140
	                    urlCtrl.loadByHash(location.hash);
Clément Damiens's avatar
 
Clément Damiens committed
141 142 143 144 145 146 147
	                } );
	            }
	    	}
	    }
	};

	sectionDyf.<?php echo $kunik ?>Params = {
148 149 150 151 152
		jsonSchema : {	
	        title : "<?php echo $kunik ?> config",
	        description : "Liste de question possible",
	        icon : "fa-cog",
	        properties : {
Clément Damiens's avatar
 
Clément Damiens committed
153 154 155 156 157 158 159 160 161 162 163 164 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 195 196 197 198 199 200 201 202
	            group : {
	                inputType : "array",
	                label : "Liste des groups",
	                values :  sectionDyf.<?php echo $kunik ?>ParamsData.group
	            },
	            nature : {
	                inputType : "properties",
	                labelKey : "Clef",
	                labelValue : "Label affiché",
	                label : "Liste des natures possibles",
	                values :  sectionDyf.<?php echo $kunik ?>ParamsData.nature
	            },
	            amounts : {
	                inputType : "properties",
	                labelKey : "Clef",
	                labelValue : "Label affiché",
	                label : "Liste des prix(ex:par année)",
	                values :  sectionDyf.<?php echo $kunik ?>ParamsData.amounts
	            },
	            estimate : {
	                inputType : "checkboxSimple",
                    label : "estimate Prices",
                    params : {
                        onText : "Oui",
                        offText : "Non",
                        onLabel : "Oui",
                        offLabel : "Non",
                        labelText : "estimate Prices"
                    },
                    checked : sectionDyf.<?php echo $kunik ?>ParamsData.estimate
	            }
	        },
	        save : function () {  
	            tplCtx.value = {};
	            $.each( sectionDyf.<?php echo $kunik ?>Params.jsonSchema.properties , function(k,val) { 
	        		if(val.inputType == "properties")
	        		 	tplCtx.value[k] = getPairsObj('.'+k+val.inputType);
	        		else if(val.inputType == "array")
	        		 	tplCtx.value[k] = getArray('.'+k+val.inputType);
	        		else
	        		 	tplCtx.value[k] = $("#"+k).val();
	        		 mylog.log("value",'.'+k+val.inputType,tplCtx.value[k]);
	        	 });
	            mylog.log("save tplCtx",tplCtx);
	            
	            if(typeof tplCtx.value == "undefined")
	            	toastr.error('value cannot be empty!');
	            else {
	                dataHelper.path2Value( tplCtx, function(params) { 
	                    $("#ajax-modal").html("<div class='text-center'><i class='fa fa-spin fa-spinner'></i></div>");
203
	                    //urlCtrl.loadByHash(location.hash);
Clément Damiens's avatar
 
Clément Damiens committed
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 253 254 255 256 257 258 259 260 261 262
	                } );
	            }

	    	}
	    }
	};


    mylog.log("render","/modules/costum/views/tpls/forms/<?php echo $kunik ?>.php");

    //adds a line into answer
    $(".add<?php echo $kunik ?>").off().on("click",function() {  
        tplCtx.id = $(this).data("id");
        tplCtx.collection = $(this).data("collection");            
        tplCtx.path = $(this).data("path")+((notNull(<?php echo $kunik ?>Data) ? <?php echo $kunik ?>Data.length : "0"));
        dyFObj.openForm( sectionDyf.<?php echo $kunik ?> );
    });

    $(".edit<?php echo $kunik ?>").off().on("click",function() {  
        tplCtx.id = $(this).data("id");
        tplCtx.collection = $(this).data("collection"); 
        tplCtx.path = $(this).data("path");
        dyFObj.openForm( sectionDyf.<?php echo $kunik ?>,null, <?php echo $kunik ?>Data[$(this).data("key")]);
    });

    $(".edit<?php echo $kunik ?>Params").off().on("click",function() {  
        tplCtx.id = $(this).data("id");
        tplCtx.collection = $(this).data("collection");
        tplCtx.path = $(this).data("path");
        dyFObj.openForm( sectionDyf.<?php echo $kunik ?>Params,null, sectionDyf.<?php echo $kunik ?>ParamsData);
    });


<?php if( $paramsData["estimate"] ) {  ?>
	
	$('.btnEstimateSelected').off().click(function() { 
		tplCtx.pos = $(this).data("pos");
		tplCtx.collection = "answers";
		tplCtx.id = $(this).data("id");
		tplCtx.key = $(this).data("key");
		tplCtx.form = $(this).data("form");
		tplCtx.price = $(this).data("price");
		$(this).removeClass('btn-default').addClass("btn-success");

		tplCtx.pathBase = "answers";
    	if( notNull(formInputs [tplCtx.form]) )
    		tplCtx.pathBase = "answers."+tplCtx.form;    

    	tplCtx.path = tplCtx.pathBase+"."+tplCtx.key+"."+tplCtx.pos+".estimates."+$(this).data("uid")+".selected"; 	
        tplCtx.value = true;

		mylog.log("btnEstimateSelected save",tplCtx);
  	 	dataHelper.path2Value( tplCtx, function(){
  	 		tplCtx.path = tplCtx.pathBase+"."+tplCtx.key+"."+tplCtx.pos+".price"; 	
	        tplCtx.value = tplCtx.price;

			mylog.log("btnEstimateSelected save",tplCtx);
	  	 	dataHelper.path2Value( tplCtx, function(){
	  	 		$("#price"+tplCtx.pos).html( tplCtx.price+"" );
263
	  	 		saveLinks(answerObj._id.$id,"intentValidated",userId);
Clément Damiens's avatar
 
Clément Damiens committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
	  	 	 } );
  	 	} );

  	 	

		
	});

    $('.btnEstimate').off().click(function() { 
		tplCtx.pos = $(this).data("pos");
		tplCtx.collection = "answers";
		tplCtx.id = $(this).data("id");
		tplCtx.key = $(this).data("key");
		tplCtx.form = $(this).data("form");
		prioModal = bootbox.dialog({
	        message: $(".form-estimate").html(),
	        title: "Voter pour partie",
	        show: false,
	        buttons: {
                success: {
                    label: trad.save,
                    className: "btn-primary",
                    callback: function () {

                    	tplCtx.path = "answers";
			        	if( notNull(formInputs [tplCtx.form]) )
			        		tplCtx.path = "answers."+tplCtx.form;    

			        	tplCtx.path = tplCtx.path+"."+tplCtx.key+"."+tplCtx.pos+".estimates."+userId; 

			        	var today = new Date();
						today = today.getDate() + '/' + (today.getMonth()+1) + '/' + today.getFullYear();	
			            tplCtx.value = {
			            	price : $(".bootbox #priceEstimate").val(),
			            	days : $(".bootbox #daysEstimate").val(),
			            	name :  userConnected.name,
			            	date : today
			            };

				    	mylog.log("btnEstimate save",tplCtx);
304 305 306 307
				  	 	dataHelper.path2Value( tplCtx, function(){
				  	 		saveLinks(answerObj._id.$id,"estimated",userId);
				  	 		closePrioModalRel();
				  	 	} );
Clément Damiens's avatar
 
Clément Damiens committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
			        }		
                },
                cancel: {
                  label: trad.cancel,
                  className: "btn-secondary",
                  callback: closePrioModal
                }
              },
		        onEscape: closePrioModal
	    });
	    prioModal.modal("show");
	});
<?php } ?>


});
324 325 326 327 328 329 330
function closePrioModal(){
	prioModal.modal('hide');
}
function closePrioModalRel(){
	closePrioModal();
	urlCtrl.loadByHash(location.hash);
}
Clément Damiens's avatar
 
Clément Damiens committed
331 332 333
</script>
<?php } else {
	//echo "<h4 class='text-red'>CALENDAR works with existing answers</h4>";
Raph El's avatar
Raph El committed
334 335 336 337 338 339
} 


}

?>