formdedie.php 13.2 KB
Newer Older
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
1
2
3
4
5
6
<?php if($answer){
    ?>
    <div class="form-group">
        <table class="table table-bordered table-hover  directoryTable" id="<?php echo $kunik?>">

            <?php
Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
7
            $editBtnL = ($canAnswer) ? " <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>  <a href='javascript:;' data-id='".Yii::app()->request->getQuery("answer")."' data-collection='answers' data-path='answers.sommomForm1.sommomForm122.' class='addorganismesommomForm122 btn btn-default'><i class='fa fa-plus'></i> Ajouter un organisme </a>" : "";
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
8
9
10
11
12

            $editParamsBtn = ($canEdit) ? " <a href='javascript:;' data-id='".$el["_id"]."' data-collection='".Yii::app()->session["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>" : "";

            $paramsData = [];

Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
13
14
15
16
17
18
19
20
21
              $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"]);
                            }
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
22
23
24
25
26
27
28
29
30
                        }
                    }
                }
            }
            

            if( isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["ocean"]) )
                $paramsData["ocean"] =  Yii::app()->session["costum"]["form"]["params"][$kunik]["ocean"];
                
Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
31

Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
32
33
34
35
36
37
38
            $properties = [
                "intitule" => [
                    "label" => "Intitulé de la formation",
                    "placeholder" => "Intitulé de la formation",
                    "inputType" => "text",
                    "rules" => [ "required" => true ]
                ],
Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
39
                 "organisme" => [
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
40
41
42
43
                    "label" => "Organisme référent ",
                    "placeholder" => "Organisme référent ",
                    "inputType" => "selectMultiple",
                    "options" => $a,
Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
44
                    "rules" => [ "required" => false ]
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
                ],
                "publCle" => [
                    "label" => "Public ciblé",
                    "placeholder" => "Public ciblé",
                    "inputType" => "text",
                    "rules" => [ "required" => true ]
                ],
                "duree" => [
                    "label" => "Durée",
                    "placeholder" => "Durée",
                    "inputType" => "text",
                    "rules" => [ "required" => true ]
                ],
                "cout" => [
                    "label" => "Coût par personne ",
                    "placeholder" => "Coût par personne ",
                    "inputType" => "text",
                    "rules" => [ "required" => true ]
                ],
                "lien" => [
                    "label" => "Site internet de référence",
                    "placeholder" => "Site internet de référence",
                    "inputType" => "text",
Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
68
                    "rules" => [ "required" => false ]
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
69
70
71
                ],
            ];

Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
            $propertiesParams = [
                "labels"=>[],
                "placeholders"=>[],
            ];

            foreach ($properties as $k => $v) {
                if( isset($v["label"])){
                    if( isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["labels"][$k]) )
                        $properties[$k]["label"] = Yii::app()->session["costum"]["form"]["params"][$kunik]["labels"][$k];
                    $propertiesParams["labels"][$k] = $properties[$k]["label"];
                }

                if( isset($v["placeholder"])){
                    if(isset(Yii::app()->session["costum"]["form"]["params"][$kunik]["placeholders"][$k]) )
                       $properties[$k]["placeholder"] = Yii::app()->session["costum"]["form"]["params"][$kunik]["placeholders"][$k];
                    $propertiesParams["placeholders"][$k] = $properties[$k]["placeholder"];
                }
            }

Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
91
92
93
94
95
96
97
98
99
100
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
            ?>

            <thead>
            <tr>
                <td colspan='<?php echo count( $properties)+2?>' ><h4 style="color:<?php echo ($titleColor) ? $titleColor : "black"; ?>"><?php echo $label.$editQuestionBtn.$editParamsBtn.$editBtnL?></h4>
                    <?php echo $info ?>
                </td>
            </tr>
            <?php

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

                    foreach ($properties as $i => $inp) {
                        echo "<th>".$inp["placeholder"]."</th>";
                    } ?>
                    <th></th>
                </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
126
                                echo implode(",", $a[$i]);
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
                        }
                                else {

                            
                            if($i == "lien")
                            {
                                echo "<a href='".$a[$i]."'>".$a[$i]."</a>";
                            }
                                else
                                {
                                echo $a[$i];
                                }
                        }
                    }
                        echo "</td>";
                    }
                    ?>
                     <td style="white-space: normal;">
                        <?php
                        $this->renderPartial( "survey.views.tpls.forms.cplx.editDeleteLineBtn" , [
147
                            "canEdit"=>($canEdit || $canAnswer),
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
148
149
150
                            "id" => $answer["_id"],
                            "collection" => Form::ANSWER_COLLECTION,
                            "q" => $q,
Tibor Katelbach's avatar
Tibor Katelbach committed
151
                            "path" => $answerPath.$q,
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
                            "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
                    $ct++;
                    echo "</tr>";
                }
            }

            ?>
            </tbody>
        </table>
    </div>
    <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 ); ?>;
Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
171
172
173
174
175
        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
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
203
204
205
206
207
208
209
210
211

        $(document).ready(function() {

            sectionDyf.<?php echo $kunik ?> = {
                "jsonSchema" : {
                    "title" : "Formations dédiées à l’activité d’observation",
                    "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" : {
Anatole Rakotoson's avatar
sommom    
Anatole Rakotoson committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
                        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
                        },
Anatole Rakotoson's avatar
Sommom  
Anatole Rakotoson committed
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
                        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) {
                                $("#ajax-modal").html("<div class='text-center'><i class='fa fa-spin fa-spinner'></i></div>");
                                location.reload();
                            } );
                        }

                    }
                }
            };


            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");
                //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>
<?php } else {
    //echo "<h4 class='text-red'>CALENDAR works with existing answers</h4>";
} ?>