collaboration.php 17.4 KB
Newer Older
Tibor Katelbach's avatar
Tibor Katelbach committed
1 2 3
<?php if($answer){
    ?>
    <div class="form-group">
Anatole Rakotoson's avatar
Anatole Rakotoson committed
4
       
Tibor Katelbach's avatar
Tibor Katelbach committed
5 6

            <?php
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
7

Anatole Rakotoson's avatar
Anatole Rakotoson committed
8 9
            $editBtnL = ($canEdit and $mode != "r" and $mode != "pdf") ? " <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>" : "";
        $editParamsBtn = ($canEditForm and $mode != "r" || $mode != "pdf") ? " <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
10 11 12

            $paramsData = [
                "nature" => [
Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
13 14 15
                    "accord" => "Accord",
                    "convention" => "Convention",
                    "reseau" => "Réseau"
Tibor Katelbach's avatar
Tibor Katelbach committed
16 17
                ],
                "type" => [
Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
18 19
                    "regionale" => "Régional",
                    "intergouv" => "Intér-gouvernemental"
Tibor Katelbach's avatar
Tibor Katelbach committed
20 21 22 23 24 25 26 27 28 29 30 31 32 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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
                ]
                ];


                   $a=[];

            if(isset($answer["answers"]["sommomForm1"])){
                foreach ($answer["answers"]["sommomForm1"] as $k => $v) {
                    if(is_array($v)){
                        foreach ($v as $key => $value) {
                            if(isset($value["intitule"])) {
                                $a += array($value["intitule"] => $value["intitule"]);
                            }
                        }
                    }
                }
            }
                 if( isset($parentForm["params"][$kunik]["nature"]) )
                $paramsData["nature"] =  $parentForm["params"][$kunik]["nature"];
                 if( isset($parentForm["params"][$kunik]["type"]) )
                $paramsData["type"] =  $parentForm["params"][$kunik]["type"];

            
            $properties = [
                "nom" => [
                    "label" => "Nom du dispositif de collaboration",
                    "placeholder" => "Intitulé",
                    "inputType" => "text",
                    "rules" => [ "required" => true ]
                ],
                "nature" => [
                    "label" => "Nature",
                    "placeholder" => "Nature",
                    "inputType" => "select",
                    "noOrder" => true,
                    "options" => $paramsData["nature"],
                    "rules" => [ "required" => true ]
                ],
                "type" => [
                    "label" => "type",
                    "placeholder" => "type",
                    "inputType" => "select",
                    "noOrder" => true,
                    "options" => $paramsData["type"],
                    "rules" => [ "required" => true ]
                ],
                "date" => [
                    "label" => "Année de création",
                    "placeholder" => "Date de création",
                    "inputType" => "text",
                    "rules" => [ "required" => true ]
                ],
                "object" => [
                    "label" => "Objet",
                    "placeholder" => "Objet",
                    "inputType" => "text",
                    "rules" => [ "required" => true ]
                ],
                "Gestion" => [
                    "label" => "Organisme associé",
                    "placeholder" => "Organisme associé",
                    "inputType" => "selectMultiple",
                    "options" => $a,
                    "rules" => [ "required" => true ]
                ],
                "site" => [
                    "label" => "Site internet de référence",
                    "placeholder" => "Site internet de référence",
                    "inputType" => "text",
                    "rules" => [ "required" => false ]
                ],
            ];

            $propertiesParams = [
                "labels"=>[],
                "placeholders"=>[],
            ];

            foreach ($properties as $k => $v) {
                if( isset($v["label"])){
                    if( isset($parentForm["params"][$kunik]["labels"][$k]) )
                        $properties[$k]["label"] = $parentForm["params"][$kunik]["labels"][$k];
                    $propertiesParams["labels"][$k] = $properties[$k]["label"];
                }

                if( isset($v["placeholder"])){
                    if(isset($parentForm["params"][$kunik]["placeholders"][$k]) )
                       $properties[$k]["placeholder"] = $parentForm["params"][$kunik]["placeholders"][$k];
                    $propertiesParams["placeholders"][$k] = $properties[$k]["placeholder"];
                }
            }

            ?>

Anatole Rakotoson's avatar
Anatole Rakotoson committed
114 115
            <?php if(  $mode != "pdf" ){ ?>

Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
116
            <table class="table table-bordered table-hover  directoryTable" id="<?php echo $kunik?>" style="overflow-x: auto">
Tibor Katelbach's avatar
Tibor Katelbach committed
117 118
            <thead>
            <tr>
Anatole Rakotoson's avatar
Anatole Rakotoson committed
119
                <td colspan="<?php  if( $mode != "r"){ echo count( $properties)+2 ; } else { echo count( $properties) ;} ?>" ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
Tibor Katelbach's avatar
Tibor Katelbach committed
120 121 122 123 124 125 126 127 128 129 130 131 132
                    <?php echo $info ?>
                </td>
            </tr>
            <?php

            if( count($answers)>0 ){ ?>
                <tr>
                    </th>
                    <?php

                    foreach ($properties as $i => $inp) {
                        echo "<th>".$inp["placeholder"]."</th>";
                    } ?>
Anatole Rakotoson's avatar
Anatole Rakotoson committed
133 134 135
                   <?php if(  $mode != "r" ){ ?>
                            <th></th>
                        <?php } ?>
Tibor Katelbach's avatar
Tibor Katelbach committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
                </tr>
                <tr></tr>
            <?php } ?>
            </thead>
            <tbody class="directoryLines">
            <?php
            $ct = 0;

            if(isset($answers)){
                foreach ($answers as $q => $a) {

                    echo "<tr id='".$kunik.$q."' class='".$kunik."Line'>";
                    foreach ($properties as $i => $inp) {
                        echo "<td>";
                        if(isset($a[$i])) {
                            if(is_array($a[$i])){
Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
152
                                echo implode(",", $a[$i]);
Tibor Katelbach's avatar
Tibor Katelbach committed
153 154 155 156
                            } else {
                                if($i == "site") {
                                    echo "<a href='".$a[$i]."'>".$a[$i]."</a>";
                                }
Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
157 158 159 160 161 162 163 164
                                else if($i == "type" && isset($paramsData[$i][$a[$i]])){

                                        echo $paramsData[$i][$a[$i]];
                                    }
                                    else if($i == "nature" && isset($paramsData[$i][$a[$i]])){

                                        echo $paramsData[$i][$a[$i]];
                                    }
Tibor Katelbach's avatar
Tibor Katelbach committed
165 166 167 168 169 170 171 172
                                else {
                                    echo $a[$i];
                                }
                            }
                        }
                        echo "</td>";
                    }
                    ?>
Anatole Rakotoson's avatar
Anatole Rakotoson committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
                     <?php  if( $mode != "r"){?>
                            <td style="white-space: normal;">
                                <?php
                                $this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
                                    "canEdit"=>($canEdit),
                                    "id" => $answer["_id"],
                                    "collection" => Form::ANSWER_COLLECTION,
                                    "q" => $q,
                                    "path" => $answerPath.$q,
                                    "keyTpl"=>$kunik
                                ] ); ?>

                                <a href="javascript:;" class="btn btn-xs btn-primary openAnswersComment" onclick="commentObj.openPreview('answers','<?php echo $answer["_id"]?>','<?php echo $answer["_id"].$key.$q ?>', '<?php echo @$a['step'] ?>')"><?php echo PHDB::count(Comment::COLLECTION, array("contextId"=>$answer["_id"],"contextType"=>"answers", "path"=>$answer["_id"].$key.$q))?> <i class='fa fa-commenting'></i></a>
                            </td>
                            <?php } ?>
Tibor Katelbach's avatar
Tibor Katelbach committed
188 189 190 191 192 193 194 195 196
                    <?php
                    $ct++;
                    echo "</tr>";
                }
            }

            ?>
            </tbody>
        </table>
Anatole Rakotoson's avatar
Anatole Rakotoson committed
197 198 199 200 201 202 203 204 205 206 207

        <?php
            } else {
            ?>
            <div>
                <label>
                    <h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
                                <?php echo $info ?>
                </label>
            </div>

Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
208
            <table class="table table-bordered table-hover  directoryTable" id="<?php echo $kunik?>" style="overflow-x: auto">
Anatole Rakotoson's avatar
Anatole Rakotoson committed
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 263 264 265 266 267 268 269
            <thead>
            
            <?php

            if( count($answers)>0 ){ ?>
                <tr>
                    <?php

                    foreach ($properties as $i => $inp) {
                        echo "<th>".$inp["placeholder"]."</th>";
                    } ?>
                </tr>
            <?php } ?>
            </thead>
            <tbody class="directoryLines">
            <?php
            $ct = 0;

            if(isset($answers)){
                foreach ($answers as $q => $a) {

                    echo "<tr id='".$kunik.$q."' class='".$kunik."Line'>";
                    foreach ($properties as $i => $inp) {
                        echo "<td>";
                        if(isset($a[$i])) {
                            if(is_array($a[$i])){
                                echo implode(",", $a[$i]);
                            } else {
                                if($i == "site") {
                                    echo "<a href='".$a[$i]."'>".$a[$i]."</a>";
                                }
                                else if($i == "type" && isset($paramsData[$i][$a[$i]])){

                                        echo $paramsData[$i][$a[$i]];
                                    }
                                    else if($i == "nature" && isset($paramsData[$i][$a[$i]])){

                                        echo $paramsData[$i][$a[$i]];
                                    }
                                else {
                                    echo $a[$i];
                                }
                            }
                        }
                        echo "</td>";
                    }
                    echo "</tr>";
                }
            }

            ?>
            </tbody>
        </table>

           


    <?php } ?>



Tibor Katelbach's avatar
Tibor Katelbach committed
270
    </div>
Anatole Rakotoson's avatar
Anatole Rakotoson committed
271
    <?php  if( $mode != "pdf"){?>
Tibor Katelbach's avatar
Tibor Katelbach committed
272 273 274 275 276 277 278 279 280 281
    <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 ); ?>;
        sectionDyf.<?php echo $kunik ?>ParamsProperty = {
            labels : <?php echo json_encode( $propertiesParams["labels"] ); ?>,
            placeholders : <?php echo json_encode( $propertiesParams["placeholders"] ); ?>
        };


Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
        var max<?php echo $kunik ?> = 0;
        var nextValuekey<?php echo $kunik ?> = 0;

        if(notNull(<?php echo $kunik ?>Data)){
            $.each(<?php echo $kunik ?>Data, function(ind, val){
                if(parseInt(ind) > max<?php echo $kunik ?>){
                    max<?php echo $kunik ?> = parseInt(ind);
                }
            });

            nextValuekey<?php echo $kunik ?> = max<?php echo $kunik ?> + 1;

        }


Tibor Katelbach's avatar
Tibor Katelbach committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 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
        $(document).ready(function() {

            sectionDyf.<?php echo $kunik ?> = {
                "jsonSchema" : {
                    "title" : "Les collaborations régionales et intergouvernementales",
                    "icon" : "fa-globe",
                    "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 ); ?>,
                    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');
                                location.reload();
                            } );
                        }

                    }
                }
            };

            sectionDyf.<?php echo $kunik ?>Params = {
                "jsonSchema" : {
                    "title" : "<?php echo $kunik ?> config",
                    "description" : "Liste de question possible",
                    "icon" : "fa-cog",
                    "properties" : {
                        labels : {
                            inputType : "properties",
                            labelKey : "Clef",
                            labelValue : "Libellé du champs",
                            label : "Modifier les libélés des Questions",
                            values :  sectionDyf.<?php echo $kunik ?>ParamsProperty.labels
                        },
                        placeholders : {
                            inputType : "properties",
                            labelKey : "Clef",
                            labelValue : "Texte dans le champs",
                            label : "Modifier les textes à l'interieur du champs de saisie",
                            values :  sectionDyf.<?php echo $kunik ?>ParamsProperty.placeholders
                        },
                        nature : {
                            inputType : "array",
                            label : "Liste des natures",
                            values :  sectionDyf.<?php echo $kunik ?>ParamsData.nature
                        },
                        type : {
                            inputType : "array",
                            label : "Liste des natures",
                            values :  sectionDyf.<?php echo $kunik ?>ParamsData.type
                        }
                    },
                    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) {
Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
374 375 376 377 378
 

$("#ajax-modal").modal('hide');
		urlCtrl.loadByHash( location.hash );

Tibor Katelbach's avatar
Tibor Katelbach committed
379 380 381 382 383 384 385 386 387 388 389 390 391 392
                            } );
                        }

                    }
                }
            };


            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");
Anatole Rakotoson's avatar
sommom  
Anatole Rakotoson committed
393
                tplCtx.path = $(this).data("path")+nextValuekey<?php echo $kunik ?>;
Tibor Katelbach's avatar
Tibor Katelbach committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
                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");
                //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);
            });


        });
    </script>
Anatole Rakotoson's avatar
Anatole Rakotoson committed
417
<?php } } ?>