Bonjour,
J'ai un petit soucis avec un script Ajax qui sert à filtrer des projets à l'aide de différents champs, pour le moment juste un select avec dedans une liste de statuts et je dois récupérer les éléments qui ont uniquement ce statut, j'arrive à récupérer les données filtrées mais au moment de les re-passer à ma vue, euh PAAN ! vous pouvez voir le site web à cette url : http://bb-on-air.com/website/projects, PS : J'ai laissé un debug et mis des console.log() ça peut aider
- j'utilise cakephp
- j'ai donc des Modèles Vues et Controllers
Mon Modèle : Model/Project.php
Mon Contrôleur : Controller/ProjectsController.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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 <?php class Project extends AppModel{ var $name='Project'; var $actsAs=array( 'Containable' ); // =============== LIAISONS ===============-> public $belongsTo = array( 'Customer', 'CommissionType', 'ProjectType', 'ProjectAttributionType', 'ProjectStatusType', 'ProjectPriorityType' ); public $hasMany = array( 'ProjectSteps' ); function compareDateWish() { $dateStartWish=$this->data['Project']['project_date_start_wish']; $dateEndWish=$this->data['Project']['project_date_end_wish']; return dateDiff2($dateStartWish,$dateEndWish); } function compareDateReal() { $dateStartWish=$this->data['Project']['project_date_start_wish']; $dateEndWish=$this->data['Project']['project_date_end_wish']; $return = dateDiff2($dateStartWish,$dateEndWish); if (!empty($this->data['Project']['project_date_end_real'])) { $dateStartReal=$this->data['Project']['project_date_start_real']; $dateEndReal=$this->data['Project']['project_date_end_real']; if (empty($dateStartReal)) { $return = false; } else { $return = dateDiff2($dateStartReal,$dateEndReal); } } return $return; } // =============== VALIDATIONS ===============-> public $validate = array( 'project_name' => array( 'rule' => '/^[a-z0-9A-Zéèàùç@ôûüëêâ"\' ]{3,}$/i', 'message' => 'Les données pour ce champ ne doivent contenir que lettres et chiffres !' ) // etc ); } ?>
Ma vue : View/Projects/index.ctp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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
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
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
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
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
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
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
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464 <?php class ProjectsController extends AppController { var $name="Projects"; var $components=array('RequestHandler'); var $helpers = array( 'Form', 'Js', 'Ajax', 'Html', 'Session', 'Paginator' ); var $paginate = array( 'limit' => 5, 'order' => array( 'Project.id' => 'desc' ) ); function beforeFilter() { if($this->RequestHandler->isAjax()){ //debug($this->RequestHandler); $this->layout='ajax'; } } // ===================== DOWN PRIORITE d'un PROJET ================================-> public function downgrade($id=null) { if($this->RequestHandler->isAjax()){ $this->autoRender = false; $this->Project->id = $id; if($this->Project->saveField('project_priority_type_id',$this->Project->field('project_priority_type_id')+1)){ //$this->Session->setFlash('Priorité du projet : "'.$this->Project->field('project_name').'" modifiée<br /><br />'); $newValue = $this->Project->findById($id); return $newValue['Project']['project_priority_type_id']; $this->redirect(array('action' => 'index')); exit; } } else { echo 'isAjax(downgrade) Failed ! vérifiez votre connexion internet (accès aux scripts distants)';} } // ===================== UP PRIORITE d'un PROJET ================================-> public function upgrade($id=null) { if($this->RequestHandler->isAjax()){ $this->autoRender = false; $this->Project->id = $id; if($this->Project->saveField('project_priority_type_id',$this->Project->field('project_priority_type_id')-1)){ //$this->Session->setFlash('Priorité du projet : "'.$this->Project->field('project_name').'" modifiée<br /><br />'); $newValue = $this->Project->findById($id); return $newValue['Project']['project_priority_type_id']; $this->redirect(array('action' => 'index')); exit; } } else { echo 'isAjax(upgrade) Filed ! vérifiez votre connexion internet (accès aux scripts distants)';} } // ===================== ACTIVATION/DESACTIVATION d'un PROJET ================================-> public function activation($id=null) { if($this->RequestHandler->isAjax()){ $this->autoRender = false; $this->Project->id = $id; $projectActivation = $this->Project->field('project_activation'); if(!empty($projectActivation)){ $newStatus = false; } else { $newStatus = true; } if($this->Project->saveField('project_activation',$newStatus)){ $newValue = $this->Project->findById($id); return $newStatus; $this->redirect(array('action' => 'index')); exit; } } else { echo 'isAjax(activation) Failed ! vérifiez votre connexion internet (accès aux scripts distants)';} } // ===================== RECHERCHE d'un PROJET ================================-> public function search() { if($this->RequestHandler->isAjax()){ $this->autoRender = false; $this->Project->recursive = 0; $this->paginate = array( 'order' => array('Project.id' => 'desc'), 'recursive' => -1, "limit" => 5 ); if (isset($_POST['status'])) { $conditions['Project.project_status_type_id'] = $_POST['status']; } elseif (isset($_GET['status'])) { $conditions['Project.project_status_type_id'] = $_GET['status']; } $projects = $this->paginate("Project", $conditions); $this->set('Projects',compact("Projects")); if (isset($_POST['status'])) { return $_POST['status']; } if (isset($_GET['status'])) { debug($projects); $this->render('index'); } //$this->redirect(array('action' => 'index')); } else { echo 'isAjax(upgrade) Filed ! vérifiez votre connexion internet (accès aux scripts distants)';} } // ===================== AFFICHAGE des PROJETS ================================-> public function index() { function switchdate2($var) { //print_r($var['Project']['project_date_end_wish']); $tab = explode("-",$var); $datechangee = $tab[2]."/".$tab[1]."/".$tab[0]; return $datechangee ; } // ___________ fonction changer icone statut projet ________ function iconStatusClass($statusTypeId, $late='medium') { if($statusTypeId==1) { $iconShape = 'icon-play'; } elseif($statusTypeId==3) { $iconShape = 'icon-stop'; } elseif($statusTypeId==2) { $iconShape = 'icon-ban-circle'; } if($late=='low'){ $iconColor='icon-green'; } elseif($late=='medium'){ $iconColor='icon-orange'; } else { $iconColor='icon-red'; } return ($iconColor.' '.$iconShape); } // ___________ fonction changer icone priorité projet ________ function iconPriorityClass($priorityTypeId){ if ($priorityTypeId==1){ $iconShape='icon-warning'; } elseif ($priorityTypeId==2){ $iconShape='icon-clock'; } elseif ($priorityTypeId==3){ $iconShape='icon-busy'; } return ($iconShape); } // =============== LIAISONS pour FORMULAIRE de RECHERCHE ===============-> $projectStatusTypes = $this->Project->ProjectStatusType->find('list', array('fields' => 'project_status_type_name')); $this->set(compact('projectStatusTypes')); // =============== INFOS du PROJET ===============-> //$projects = $this->Project->find('all'); //$projects = $this->paginate('Project'); $projects = $this->Paginate('Project'); $this->set('Projects',$projects); // test search /*$conditions['Project.project_status_type_id'] = 1; $projects = $this->paginate("Project", $conditions); $this->set('Projects',$projects);*/ // ___________ fonction écoulement ________ function dateDiff($dateStart, $dateEnd) { // date récupérée // date récupérée formatée $dateStartClean = date("Y-m-d",strtotime($dateStart)); //D d H:i:s O Y $dateStartCleanDay = date("d",strtotime($dateStart)); $dateStartCleanMonth = date("m",strtotime($dateStart)); $dateStartCleanYear = date("Y",strtotime($dateStart)); //date catuelle formatée $dateEndClean = date("Y-m-d",strtotime($dateEnd)); $dateEndCleanDay = date("d",strtotime($dateEnd)); $dateEndCleanMonth = date("m",strtotime($dateEnd)); $dateEndCleanYear = date("Y",strtotime($dateEnd)); // difference entre les deux dates $diff = mktime(0, 0, 0, $dateEndCleanMonth, $dateEndCleanDay, $dateEndCleanYear) - mktime(0, 0, 0, $dateStartCleanMonth, $dateStartCleanDay, $dateStartCleanYear); // années ecoulées $years = $dateEndCleanYear-$dateStartCleanYear; // mois ecoulées $months = $diff/(60*60*24*30); // jours ecoulées $days = $diff/(60*60*24); // écoulement if ($days<365) { if ($days>60) { $lapse = round($months).' mois';//.' mois'; } else { $lapse = round($days).' jours'; } } else { $lapse = $years.' ans'; } return $lapse; } } // ===================== AJOUT d'un PROJET================================-> public function add() { function switchdate($var) { //echo ' before format => '.$var; $tab = explode("/",$var); $datechangee = $tab[2]."-".$tab[1]."-".$tab[0]; //echo ' new format => '.$datechangee; return $datechangee ; } function dateDiff2($dateStart, $dateEnd) { $dateStart = explode("-", $dateStart); $dateEnd = explode("-", $dateEnd); $diff = mktime(0, 0, 0, $dateEnd[1], $dateEnd[2], $dateEnd[0]) - mktime(0, 0, 0, $dateStart[1], $dateStart[2], $dateStart[0]); $diffDate=($diff / 86400); if ($diffDate>=0){ return true; } else { return false; } } // =============== LIAISONS pour FORMULAIRE ===============-> $customers = $this->Project->Customer->find('list', array('fields' => 'customer_name')); $this->set(compact('customers')); $projectStatusTypes = $this->Project->ProjectStatusType->find('list', array('fields' => 'project_status_type_name')); $this->set(compact('projectStatusTypes')); $commissionTypes = $this->Project->CommissionType->find('list', array('fields' => 'commission_type_name')); $this->set(compact('commissionTypes')); $projectTypes = $this->Project->ProjectType->find('list', array('fields' => 'project_type_name')); $this->set(compact('projectTypes')); $projectAttributionTypes = $this->Project->ProjectAttributionType->find('list', array('fields' => 'project_attribution_type_name')); $this->set(compact('projectAttributionTypes')); $projectTypes = $this->Project->ProjectType->find('list', array('fields' => 'project_type_name')); $this->set(compact('projectTypes')); $projectStatusTypes = $this->Project->ProjectStatusType->find('list', array('fields' => 'project_status_type_name')); $this->set(compact('projectStatusTypes')); $projectPriorityTypes = $this->Project->ProjectPriorityType->find('list', array('fields' => 'project_priority_type_name')); $this->set(compact('projectPriorityTypes')); $commissionTypes = $this->Project->CommissionType->find('list', array('fields' => 'commission_type_name')); $this->set(compact('commissionTypes')); // =============== LIAISONS pour FORMULAIRE ===============-> // =============== ENVOI FORMULAIRE ===============-> if ($this->request->is('Post')) { // formatage des dates pour l'enregistrement $this->request->data['Project']['project_date_start_wish'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_start_wish']))); if ($this->request->data['Project']['project_date_start_real']!='') { $this->request->data['Project']['project_date_start_real'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_start_real']))); } $this->request->data['Project']['project_date_end_wish'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_end_wish']))); if($this->request->data['Project']['project_date_end_real']!='') { $this->request->data['Project']['project_date_end_real'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_end_real']))); } // enregistrement $this->Project->create(); if ($this->Project->save($this->request->data)) { $this->Session->setFlash('Nouveau projet sauvegardé.<br /><br />'); $this->redirect(array('action' => 'index')); } else { $this->Session->setFlash('Impossible de créer ce projet.<br /><br />'); } } //debug($this->request->data); } public function edit($id = null) { function switchdate($var) { //echo ' before format => '.$var; $tab = explode("/",$var); $datechangee = $tab[2]."-".$tab[1]."-".$tab[0]; //echo ' new format => '.$datechangee; return $datechangee ; } function switchdate2($var) { //print_r($var['Project']['project_date_end_wish']); $tab = explode("-",$var); $datechangee = $tab[1]."/".$tab[2]."/".$tab[0]; return $datechangee ; } function dateDiff2($dateStart, $dateEnd) { $dateStart = explode("-", $dateStart); $dateEnd = explode("-", $dateEnd); $diff = mktime(0, 0, 0, $dateEnd[1], $dateEnd[2], $dateEnd[0]) - mktime(0, 0, 0, $dateStart[1], $dateStart[2], $dateStart[0]); $diffDate=($diff / 86400); if ($diffDate>=0){ return true; } else { return false; } } // PROJET ACTUEL $this->Project->id = $id; // =============== LIAISONS pour FORMULAIRE ===============-> $customers = $this->Project->Customer->find('list', array('fields' => 'customer_name')); $this->set(compact('customers')); $projectStatusTypes = $this->Project->ProjectStatusType->find('list', array('fields' => 'project_status_type_name')); $this->set(compact('projectStatusTypes')); $commissionTypes = $this->Project->CommissionType->find('list', array('fields' => 'commission_type_name')); $this->set(compact('commissionTypes')); $projectTypes = $this->Project->ProjectType->find('list', array('fields' => 'project_type_name')); $this->set(compact('projectTypes')); $projectAttributionTypes = $this->Project->ProjectAttributionType->find('list', array('fields' => 'project_attribution_type_name')); $this->set(compact('projectAttributionTypes')); $projectTypes = $this->Project->ProjectType->find('list', array('fields' => 'project_type_name')); $this->set(compact('projectTypes')); $projectStatusTypes = $this->Project->ProjectStatusType->find('list', array('fields' => 'project_status_type_name')); $this->set(compact('projectStatusTypes')); $projectPriorityTypes = $this->Project->ProjectPriorityType->find('list', array('fields' => 'project_priority_type_name')); $this->set(compact('projectPriorityTypes')); $commissionTypes = $this->Project->CommissionType->find('list', array('fields' => 'commission_type_name')); $this->set(compact('commissionTypes')); // =============== LIAISONS pour FORMULAIRE ===============-> // =============== POST du FORMULAIRE ===============-> if ($this->request->is('post')) { // formatage des dates pour l'enregistrement $this->request->data['Project']['project_date_start_wish'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_start_wish']))); if ($this->request->data['Project']['project_date_start_real']!='') { $this->request->data['Project']['project_date_start_real'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_start_real']))); } $this->request->data['Project']['project_date_end_wish'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_end_wish']))); if($this->request->data['Project']['project_date_end_real']!='') { $this->request->data['Project']['project_date_end_real'] = date('Y-m-d', strtotime(switchdate($this->request->data['Project']['project_date_end_real']))); } if ($this->Project->save($this->request->data)) { $this->Session->setFlash('Votre projet a été mis à jour.<br /><br />'); // redirection vers index $this->redirect(array('action' => 'index')); } else { //debug($this->Recipe->validationErrors); $this->Session->setFlash('Impossible de mettre à jour votre projet.<br /><br />'); }; } // =============== POST du FORMULAIRE ===============-> // =============== FORMATAGE des DATES pour PRE-REMPLIR le FORMULAIRE ===============-> //___________ Date début souhaitée ________ $dateStartWish = $this->Project->field('project_date_start_wish'); $dateStartWish = switchdate2($dateStartWish); // envoi à la vue des champs formatés $this->set('projectDateStartWish', $dateStartWish); //___________ Date début réelle ________ $dateStartReal = $this->Project->field('project_date_start_real'); if ($dateStartReal!='') { $dateStartReal = switchdate2($dateStartReal); // envoi à la vue des champs formatés $this->set('projectDateStartReal', $dateStartReal); } //___________ Date fin souhaitée ________ $dateEndWish = $this->Project->field('project_date_end_wish'); $dateEndWish = switchdate2($dateEndWish); // envoi à la vue des champs formatés $this->set('projectDateEndWish', $dateEndWish); //___________ Date fin réelle ________ $dateEndReal = $this->Project->field('project_date_end_real'); if ($dateEndReal!='') { $dateEndReal = switchdate2($dateEndReal); // envoi à la vue des champs formatés $this->set('projectDateEndReal', $dateEndReal); } // debug resultat de la conversions => //echo 'Début souhaité : '.$dateStartWish.' ; fin souhaitée : '.$dateEndWish; //echo '<br />Début souhaité : '.$this->Project->field('project_date_start_wish').' ; fin souhaitée : '.$this->Project->field('project_date_end_wish'); // =============== FORMATAGE des DATES pour PRE-REMPLIR le FORMULAIRE ===============-> // =============== INFOS PROJET pour PRE-REMPLIR le FORMULAIRE ===============-> $this->set('project', $this->Project->findById($id)); } } ?>
et enfin,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
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
114
115
116
117
118
119
120
121 <?php //print_r($Projects); //echo '<br /><br />'; ?> <?php echo $this->Html->link(($this->Html->tag('i','', array('class' => 'icon-white icon-plus-sign'))).' Ajouter un projet', array('controller' => 'projects', 'action' => 'add'), array('class' => 'btn btn-success', 'escape'=>false)) ?> <br /><br /> <table width="910" border="0" cellspacing="0" cellpadding="0" class="bordered hovered"> <thead> <tr> <td width="86px"> <?php echo 'Statut '.$this->Paginator->sort('project_status_type_id', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?> <div class="input-control select"> <?php echo $this->Form->create( 'Project', array('controller' => 'projects', 'action' => 'search', 'type' => 'POST', 'class' => 'ajax-search' ) ); // Champ select avec la liste des auteurs echo $this->Form->input( 'project_status_type_id', array( 'label' => 'Selectionnez un statut', 'type' => 'select', //'options' => $projectStatusTypeList, //'selected' => isset($this->params['Project']['project_status_type_id']) ? $this->params['Project']['project_status_type_id'] : null, 'empty' => 'Selectionnez un statut', 'class' => 'ajax-search-status' ) ); //echo $this->Form->Submit('Lancer la recherche', array('controller' => 'projects', 'action' => 'search'), array('escape'=>false)); ?> </div> </td> <td width="86px;"> <?php echo 'Priorité '.$this->Paginator->sort('project_priority_type_id', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?> <div class="input-control select"> <select style="width: 72px; cursor: pointer; margin-bottom: 0px; margin-top: 7px; text-align:center;"> <option>Haute</option> <option>Moyenne</option> <option>Basse</option> </select> </div> </td> <td width="170px"> <?php echo 'Projet '.$this->Paginator->sort('project_name', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?> <input type="text" placeholder="rechercher un projet" style="width: 150px; height: 28px; margin-right: 6px; margin-bottom: 0px; margin-top: 7px;"> </td> <td><?php echo 'Budget '.$this->Paginator->sort('project_budjet', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?></td> <td><?php echo 'Début '.$this->Paginator->sort('project_date_start_wish', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?></td> <td><?php echo 'Fin '.$this->Paginator->sort('project_date_end_wish', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?></td> <td><?php echo 'Durée réelle '//.$this->Paginator->sort('id', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?></td> <td><?php echo 'Durée estimé '//.$this->Paginator->sort('id', $this->Html->tag('i','', array('class' => 'icon-menu')), array('escape'=> false)); ?></td> </tr> </thead> <tbody> <?php foreach($Projects as $p) { ?> <tr align="center" <?php if ($p['Project']['project_activation']==false) { echo 'class="locked"';} ?>> <td> <?php echo $this->Html->link($this->Html->tag('i','', array('class' => iconStatusClass($p['Project']['project_status_type_id']))), array('controller' => 'projects', 'action' => 'activation', $p['Project']['id']), array('class' => 'ajax-activation-project', 'escape'=>false))?> </td> <td> <?php echo $this->Html->tag('span',($this->Html->tag('i','', array('class' => iconPriorityClass($p['Project']['project_priority_type_id']), 'style' => 'cursor: default;', 'title' => $p['ProjectPriorityType']['project_priority_type_name']))), array('style' => 'float:left; margin-top:7px; margin-left:8px')); if ($p['Project']['project_priority_type_id']==1) { echo $this->Html->tag('span',($this->Html->link($this->Html->tag('i','', array('class' => 'icon-grey icon-plus')), array('controller' => 'projects', 'action' => 'upgrade', $p['Project']['id']), array('title' => 'Augmenter la priorité', 'class'=>'ajax-priority-project', 'style' => 'display: none;', 'escape' => false)).'<br style="display: none;" />'.$this->Html->link(($this->Html->tag('i','', array('class' => 'icon-grey icon-minus', 'style' => 'margin-bottom: 9px; margin-top: 9px;'))), array('controller' => 'projects', 'action' => 'downgrade', $p['Project']['id']), array('title' => 'Réduire la priorité', 'class'=>'ajax-priority-project', 'escape' => false))), array('style' => 'display: block; float: right;')); } elseif ($p['Project']['project_priority_type_id']==2) { echo $this->Html->tag('span',($this->Html->link($this->Html->tag('i','', array('class' => 'icon-grey icon-plus')), array('controller' => 'projects', 'action' => 'upgrade', $p['Project']['id']), array('title' => 'Augmenter la priorité', 'class'=>'ajax-priority-project', 'escape' => false)).'<br />'.$this->Html->link(($this->Html->tag('i','', array('class' => 'icon-grey icon-minus'))), array('controller' => 'projects', 'action' => 'downgrade', $p['Project']['id']), array('title' => 'Réduire la priorité', 'class'=>'ajax-priority-project', 'escape' => false))), array('style' => 'display: block; float: right;')); } else { echo $this->Html->tag('span',($this->Html->link($this->Html->tag('i','', array('class' => 'icon-grey icon-plus', 'style' => 'margin-bottom: 9px; margin-top: 9px;')), array('controller' => 'projects', 'action' => 'upgrade', $p['Project']['id']), array('title' => 'Augmenter la priorité', 'class'=>'ajax-priority-project', 'escape' => false)).'<br style="display: none;" />'.$this->Html->link(($this->Html->tag('i','', array('class' => 'icon-grey icon-minus'))), array('controller' => 'projects', 'action' => 'downgrade', $p['Project']['id']), array('title' => 'Réduire la priorité', 'class'=>'ajax-priority-project', 'style' => 'display: none;', 'escape' => false))), array('style' => 'display: block; float: right;')); } ?> </td> <td><?php echo $this->Html->link($p['Project']['project_name'], array('controller' => 'projects', 'action' => 'edit', $p['Project']['id']), array('class' => 'navigation-text')) ?></td> <td><?php if(!empty($p['Project']['project_budget'])){echo number_format($p['Project']['project_budget'], 0, ',', ' ').' €';} else { echo '-';} ?></td> <td><?php if(!empty($p['Project']['project_date_start_real'])){echo switchdate2($p['Project']['project_date_start_real']);} else { echo switchdate2($p['Project']['project_date_start_wish']);} ?></td> <td><?php if(!empty($p['Project']['project_date_end_real'])){echo switchdate2($p['Project']['project_date_end_real']);} else { echo switchdate2($p['Project']['project_date_end_wish']);} ?></td> <td><?php echo dateDiff(($p['Project']['project_date_start_wish']),($p['Project']['project_date_end_wish'])); ?></td> <td><?php if(!empty($p['Project']['project_date_end_real'])){ echo dateDiff(($p['Project']['project_date_start_real']),($p['Project']['project_date_end_real']));} else { echo '-';} ?></td> </tr> <?php } ?> </tbody> <?php if ($this->Paginator->counter('{:pages}')>1) { ?> <tfoot> <tr> <td colspan="9"> <div class="btn-toolbar" style="margin-top:0px;"> <span>Pages :</span> <div class="btn-group"> <?php echo $this->paginator->prev(($this->Html->tag('i','', array('class' => 'icon icon-arrow-left', 'style' => 'margin-top:4px;'))).' Précédente', array('escape' => false), null, array('class'=>'disabled')); echo $this->Paginator->numbers(array('modulus' => 4, 'separator' => '', 'class' => 'btn', 'currentClass' => 'btn active', 'escape' => false)); echo $this->paginator->next('Suivante '.($this->Html->tag('i','', array('class' => 'icon icon-arrow-right', 'style' => 'margin-top:4px;'))), array('escape' => false), null, array('class'=>'disabled')); ?> </div> </div> </td> </tr> </tfoot> <?php }; ?> </table> <?php echo $this->Js->writeBuffer(); ?>
Mon script : webroot/js/Ajax_Project_search.js
et une capture des deux tables projects et project_status_types si nécessaire :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
26
27
28
29
30
31
32
33
34
35 // JavaScript Document $(document).ready( console.log('Document JS pêt'), $(document).on("change", '.ajax-search-status',function(e){ alert('recherche'); objet = this; $.ajax({ type:"POST", url:'projects/search/', data:'status='+this.value, success:function(response){ //console.log(response) // ok objet if(response) { var url = $(this).attr("href"); console.log(url); console.log(response); // raffraichier le content de l page et rechrger le script on click $.get('projects/search/',{ "status":response },function(data){ //console.log(data); $('#content').empty().append(data); }); alert('Recherche exécutée !'); } else { console.log('no response'); alert('erreur !'); $('#flashMessage').html( "<p id='flashMessage' class='flash_bad'>An unexpected error has occured, please refresh and try again</p>" ).show(); } } }); return false; }) );
Partager