/
application.cf.editFiche.js
executable file
·2053 lines (1978 loc) · 95.8 KB
/
application.cf.editFiche.js
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
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @class application.cf.editFiche
* Singleton to build the editFiche viewport
*
* @singleton
*/
Ext.namespace("application.cf");
application.cf.editFiche = function() {
// private variables
/**
* Property: map
* {OpenLayers.Map}
*/
map = null;
/**
* Property: toolbar
* {mapfish.widgets.ToolBar}
*/
var toolbar = null;
/**
* Property: toolbarInitializedOnce
* {Boolean} toolbar has already been initialized
*/
var toolbarInitializedOnce = false;
/**
* Property: vectorLayer
* {OpenLayers.Layer.Vector}
*/
vectorLayer = null;
/**
* Property: dragPanControl
*/
var dragPanControl = null;
/**
* Property: dragPointControl
*/
var dragPointControl = null;
/**
* Property: store
* {Ext.data.Store} The ap store (should contain only one record)
*/
var store = null;
/**
* Property: protocol
* {mapfish.Protocol.MapFish}
*/
var protocol = null
/**
* Property: eventProtocol
* {mapfish.Protocol.TriggerEventDecorator}
*/
var eventProtocol = null;
/**
* Property: filterProtocol
* {mapfish.Protocol.MergeFilterDecorator}
*/
var filterProtocol = null;
/**
* Property: format
* {<OpenLayers.Format.WKT>}
*/
var format = new OpenLayers.Format.WKT();
/**
* APIProperty: id_cf
* The id of fiche to update (if applies), null in case of a creating a new fiche
*/
var id_cf = null;
/**
* APIProperty: old_cd_nom
* The old cd_nom of the taxon to update
*/
var old_taxon = null;
/**
* Property: layerTreeTip
* {Ext.Tip} The layerTreeTip created with the factory
*/
var layerTreeTip = null;
/**
* Property: firstGeometryLoad
* {Boolean} is the geometry has been load once only
*/
var firstGeometryLoad = true;
/**
* Property: myProxyTaxons
* {Ext.data.HttpProxy} Url pour charger une liste de taxon fonction de l'unité ???
*/
var myProxyReleves = null;
/**
* Property: myProxyReleves
* {Ext.data.HttpProxy} Url pour charger une liste des releves de la fiche ???
*/
var myProxyTaxons = null;
/**
* Property: maProjection
* {Openlayers.Projection} définie ici sinon temps de retard lors de la création du point gps ???
*/
var maProjection = null;
/**
* Property: blankRecord
* {Ext.data.Record} record vide pour la grid-taxons
*/
var blankRecord = null;
/**
* Property: errorMsg
* {string} message to display if taxon form is invalid or not complete
*/
var errorMsg = '';
// private functions
/**
* Method: initViewport
*/
var initViewport = function() {
return new Ext.Viewport({
layout: 'border'
,defaults: {
border: false
}
,items: [
getViewportCenterItem()
,getViewportEastItem()
,getViewportSouthItem()
]
,listeners: {
show: initToolbarItems
,beforedestroy:function(){window.location.href = host_uri+'/'+app_uri;}
,afterlayout: function(){
map.baseLayer.redraw();
}
}
});
};
/**
* Method: getViewportSouthItem
*/
var getViewportSouthItem = function() {
return {
region:"south"
,layout:'fit'
,height:45
,bbar: new Ext.Toolbar({
items: ['© Parc National des Ecrins 2012', '->',
application.cf.user.nom+' ('+application.cf.user.status+')',
{
text: 'Déconnexion'
,iconCls: 'logout'
,handler: function() {
window.location.href = 'deconnexion'
}
},{
text: 'Accueil'
,iconCls: 'home_mini'
,handler: function() {
window.location.href = '/'+app_uri
}
}]
})
}
};
/**
* Method: getViewportEastItem
*/
var getViewportEastItem = function() {
return {
region: 'east'
,width: 600
,split: true
,autoScroll: true
,defaults: {
border: false
}
,items: [{
id: 'edit-fiche-form'
,xtype: 'form'
,bodyStyle: 'padding: 5px'
,disabled: true
,defaults: {
xtype: 'numberfield'
,labelWidth: 90
,width: 180
,anchor:'-15'
}
,monitorValid:true
,items: [getFormItems(),getFormTaxons()]
//pour version Extjs 3.4
,buttons:[{
text: 'Annuler'
,xtype: 'button'
,handler: function() {
Ext.Msg.confirm('Attention'
,'Cette action va réinitialiser totalement le formulaire.<br>Si vous avez des données non enregistrées elles seront perdues.<br>Souhaitez poursuivre ?'
,function(btn) {
if (btn == 'yes') {
resetViewport();
Ext.ux.Toast.msg('Information !', 'Aucune données n\'a été enregistrée, le formulaire a été réinitialisé.');
}
else{Ext.ux.Toast.msg('Action annulée', '');}
}
,this // scope
);
}
,scope: this
},{
text: 'Enregistrer'
,xtype: 'button'
,id: 'ficheSaveButton'
,iconCls: 'action-save'
,handler:function(){submitForm();}
}]
}]
}
};
/**
* Method: getViewportCenterItem
*/
var getViewportCenterItem = function() {
createMap();
toolbar = new mapfish.widgets.toolbar.Toolbar({
map: map,
configurable: false
});
return {
region: 'center'
,id: 'edit-fiche-mapcomponent'
,xtype: 'mapcomponent'
,map: map
,tbar: toolbar
};
};
/**
* Method: getFormItems
* Creates the form items
*/
var getFormItems = function() {
var comboObservateurs = new Ext.ux.form.SuperBoxSelect({
id:'combo-fiche-observateurs'
,xtype:'superboxselect'
,fieldLabel: 'Observateur(s) '
,name: 'lesobservateurs'
,store: application.cf.storeObservateursCfAdd
,displayField: 'auteur'
,valueField: 'id_role'
,allowBlank: false
,resizable: true
,forceSelection : true
,selectOnFocus:true
,resizable: true
,mode: 'local'
,value: application.cf.user.id_utilisateur
,listeners:{
afterrender :function(combo){
combo.setValue(application.cf.user.id_utilisateur);
Ext.getCmp('edit-fiche-form').getForm().findField('ids_observateurs').setValue(combo.getValue());
}
,change:function(combo,newValue){
Ext.getCmp('edit-fiche-form').getForm().findField('ids_observateurs').setValue(newValue);
Ext.getCmp('edit-fiche-form').getForm().findField('ids_observateurs').setValue(newValue);
}
,render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Le ou les auteurs de l\'observation.'
});
}
}
});
var todayButton = new Ext.Button({
id:'bt-today'
,text: 'aujourd\'hui'
,handler: function() {
var d = new Date();
Ext.getCmp('datefield-fiche-date').setValue(d);
}
,scope: this
});
var yesterdayButton = new Ext.Button({
id:'bt-yesterday'
,text: 'hier'
,handler: function() {
var d = new Date();
d.setDate(d.getDate() - 1);
Ext.getCmp('datefield-fiche-date').setValue(d);
}
,scope: this
});
return [{
id:'hidden-idfiche'
,xtype:'hidden'
,name: 'id_cf'
},{
xtype:'hidden'
,name: 'monaction'
},{
xtype: 'hidden'
,name: 'geometry'
},{
xtype:'hidden'
,name: 'ids_observateurs'
},{
// Fieldset
xtype:'fieldset'
,id:'fieldset-1-fiche'
,columnWidth: 1
,title: 'Renseignements concernant le pointage'
,collapsible: true
,autoHeight:true
,anchor:'98%'
,items :[comboObservateurs
,{
xtype: 'compositefield'
,labelWidth: 80
,items: [
{
id:'datefield-fiche-date'
,fieldLabel: 'Date '
,name: 'dateobs'
,xtype:'datefield'
,maxValue: new Date()
,format: 'd/m/Y'
,altFormats:'Y-m-d'
,allowBlank: false
,blankText:'La date de l\'observation est obligatoire'
,listeners: {
render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Date de réalisation de l\'observation. Elle ne peut donc être postérieure à la date de saisie.'
});
}
}
}
,todayButton
,yesterdayButton
,{
xtype: 'displayfield',
value: ' Altitude :'
},{
id: 'fieldfiche-altitude'
,xtype:'numberfield'
,allowDecimals :false
,allowNegative: false
,name: 'altitude_saisie'
,anchor: '40%'
,listeners: {
render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'L\'altitude est calculée automatiquement, vous pouvez donc laisser ce champ vide. Si vous le souhaitez, vous pouvez toutefois saisir une altitude c\'est celle que vous fournissez qui sera retenue.'
});
}
}
}]
},{
id:'fieldlabel-commune'
,xtype: 'displayfield'
,value: 'Commune : inconnue'
}
]
} //fin du groupe 1
] //fin du return
};
/**
* Method: getFormTaxons
*
* Dans ce formulaire, les données saisies à droite sont enregistrées dans le store
* de la grille de gauche en temps réel (sur keyup ou sur select pour les combo).
* Une fonction invoquée sur chaque modification des champs obligatoires vérifie
* si l'ensemble du formulaire est valid ou non.
* si oui on active le bouton enregister, sinon l'enregistrement est impossible.
*/
var getFormTaxons = function(){
var relevesStoreFields = [
{name: 'id_releve_cf', type: 'integer'}
,{name: 'id_taxon', type: 'integer'}
,{name: 'nom_francais', type: 'string',sortType: Ext.data.SortTypes.asAccentuatedString}
,{name: 'nom_latin', type: 'string'}
,{name: 'nom_taxon_saisi', type: 'string'}
,{name: 'id_critere_cf', type: 'integer'}
,{name: 'am', type: 'integer'}
,{name: 'af', type: 'integer'}
,{name: 'ai', type: 'integer'}
,{name: 'na', type: 'integer'}
,{name: 'jeune', type: 'integer'}
,{name: 'yearling', type: 'integer'}
,{name: 'sai', type: 'integer'}
,{name: 'commentaire', type: 'string'}
,{name: 'cd_ref_origine', type: 'integer'}
,{name: 'denombrement', type: 'integer'}
,{name: 'id_classe', type: 'integer'}
,{name: 'patrimonial'}
];
myProxyReleves = new Ext.data.HttpProxy({
id:'store-releve-proxy'
,url: 'cf/listreleves'
,method: 'GET'
});
var relevesStore = new Ext.data.JsonStore({
url: myProxyReleves
,sortInfo: {
field: 'nom_francais'
,direction: 'ASC'
}
,fields: relevesStoreFields
,listeners: {
load: function(store, records) {
Ext.getCmp('grid-taxons').getSelectionModel().selectRow(0);
}
}
});
//record vide pour le bouton ajouter un taxon
blankRecord = Ext.data.Record.create(relevesStoreFields);
var manageDenombrementFields = function(n,reset){
if(n==5){
Ext.getCmp('fieldfiche-jeune').hideItem();
Ext.getCmp('fieldfiche-yearling').hideItem();
Ext.getCmp('fieldfiche-na').showItem();
}
if(n==6){
Ext.getCmp('fieldfiche-jeune').showItem();
Ext.getCmp('fieldfiche-yearling').showItem();
Ext.getCmp('fieldfiche-na').hideItem();
}
if(reset){
Ext.getCmp('fieldfiche-jeune').setValue(0);
Ext.getCmp('fieldfiche-yearling').setValue(0);
Ext.getCmp('fieldfiche-na').setValue(0);
}
}
function isPatri(val){
if(val){
return '<span style="font-weigt:bold;">' + val + '</span>';
}
return val;
}
var colModel = new Ext.grid.ColumnModel([
{header: "Id", width: 55, sortable: true, dataIndex: 'id_taxon',hidden:true}
,{id:'taxonfr',header: "Taxons déjà saisis", width: 160, sortable: true, locked:false, dataIndex: 'nom_francais',hidden:true}
,{id:'taxonssc',header: "Taxons déjà saisis", width: 160, sortable: true, locked:false, dataIndex: 'nom_latin',hidden:true}
,{header: "Critère", width: 55, sortable: true, dataIndex: 'id_critere_cf',hidden:true}
,{header: "Mâle", width: 35, sortable: true, dataIndex: 'am',hidden:true}
,{header: "Femelle", width: 35, sortable: true, dataIndex: 'af',hidden:true}
,{header: "Indéterminé", width: 35, sortable: true, dataIndex: 'ai',hidden:true}
,{header: "Non Adulte", width: 35, sortable: true, dataIndex: 'na',hidden:true}
,{header: "Sexe & Age Indéterminé", width: 35, sortable: true, dataIndex: 'sai',hidden:true}
,{header: "Jeune", width: 35, sortable: true, dataIndex: 'jeune',hidden:true}
,{header: "Yearling", width: 35, sortable: true, dataIndex: 'yearling',hidden:true}
,{header: "Commentaire", width: 135, sortable: true, dataIndex: 'commentaire',hidden:true}
,{header: "id_classe", width: 135, sortable: true, dataIndex: 'id_classe',hidden:true}
,{id:'taxonsaisi',header: "Taxons saisis", width: 160, sortable: true, dataIndex: 'nom_taxon_saisi'}
,{header: "cd_ref", width: 135, sortable: true, dataIndex: 'cd_ref_origine',hidden:true}
,{header: "Patrimoniale", width: 50, sortable: true, renderer:isPatri,dataIndex: 'patrimonial',hidden:true}
,{
xtype : 'actioncolumn'
,sortable : false
,hideable : false
,menuDisabled : true
,width:20
,items : [{
tooltip : 'Supprimer ce taxon du pointage'
,getClass : function(v, meta, record, rowIndex, colIdx, store) {
return 'action-remove';
}
,scope : this
,handler : function(grid, rowIndex, colIndex) {
var record = grid.getStore().getAt(rowIndex);
if(!record.data.id_taxon){
grid.getStore().remove(record);
if(Ext.getCmp('grid-taxons').getStore().getCount()==0){
this.addNewTaxon();
Ext.ux.Toast.msg('Information !', 'Vous avez supprimé tous les taxons de ce pointage.');
}
else{
Ext.getCmp('grid-taxons').getSelectionModel().selectRow(0);
Ext.ux.Toast.msg('Annulation !', 'La saisie d\'un nouveau taxon a été annulée.');
}
}
else{
Ext.Msg.confirm('Attention'
,'Etes-vous certain de vouloir supprimer le taxon "'+record.data.nom_francais+'" ?'
,function(btn) {
if (btn == 'yes') {
grid.getStore().remove(record);
if(Ext.getCmp('grid-taxons').getStore().getCount()==0){
this.addNewTaxon();
Ext.ux.Toast.msg('Suppression !', 'Le taxon "'+record.data.nom_francais+'" a été supprimé de ce pointage. Vous avez supprimé tous les taxons de ce pointage.');
}
else{
Ext.getCmp('grid-taxons').getSelectionModel().selectRow(0);
Ext.ux.Toast.msg('Suppression !', 'Le taxon "'+record.data.nom_francais+'" a été supprimé de ce pointage.');
}
}
}
,this // scope
);
}
Ext.getCmp('combo-fiche-critere').setWidth(200);//debug sinon le combo apparait avec une largeur ridicule
Ext.getCmp('combo-fiche-critere').syncSize();//debug sinon le combo apparait avec une largeur ridicule
}
}]
}
]);
var myProxyCriteres = new Ext.data.HttpProxy({
id:'store-critere-proxy'
,url: 'bibs/criterescf'
,method: 'GET'
});
var storeCriteresAdapte = function(id_classe) {
if(id_classe){
myProxyCriteres.url = 'bibs/criterescf?id_classe='+id_classe;
criteresStore.reload();
}
else{criteresStore.removeAll();}
};
var criteresStore = new Ext.data.JsonStore({
url: myProxyCriteres
,sortInfo: {
field: 'tri_cf'
,direction: 'ASC'
}
,fields: [
'id_critere_cf'
,'nom_critere_cf'
,'id_classe'
,'tri_cf'
]
,autoLoad: true
,synchronous: true
,listeners: {
load: function(store, records) {
if(Ext.getCmp('grid-taxons').getSelectionModel().getSelected()){
Ext.getCmp('combo-fiche-critere').setValue(Ext.getCmp('grid-taxons').getSelectionModel().getSelected().data.id_critere_cf);
}
}
}
});
myProxyTaxons = new Ext.data.HttpProxy({
id:'store-taxon-proxy'
,url: 'bibs/taxonscf'
,method: 'GET'
});
var comboTaxonsFiltre = function(){
var orange = Ext.getCmp('cb-orange-cf').getValue();
var red = Ext.getCmp('cb-red-cf').getValue();
var gray = Ext.getCmp('cb-gray-cf').getValue();
var patri = Ext.getCmp('cb-patri-cf').getValue();
Ext.getCmp('combo-fiche-taxon').getStore().filterBy(function(record,id){
var recColor = record.data.couleur;
var statutPatri = record.data.patrimonial;
var id_classe = record.data.id_classe;
if(!patri){
if(recColor == 'orange' && orange && comboTaxonsFiltreClasse(id_classe)){return true;}
if(recColor == 'red' && red && comboTaxonsFiltreClasse(id_classe)){return true;}
if(recColor == 'gray' && gray && comboTaxonsFiltreClasse(id_classe)){return true;}
}
if(patri){
if(recColor == 'orange' && orange && statutPatri && comboTaxonsFiltreClasse(id_classe)){return true;}
if(recColor == 'red' && red && statutPatri && comboTaxonsFiltreClasse(id_classe)){return true;}
if(recColor == 'gray' && gray && statutPatri && comboTaxonsFiltreClasse(id_classe)){return true;}
}
return false;
});
};
var comboTaxonsFiltreClasse = function(classe){
var amphibiens = Ext.getCmp('cb-amphibiens-cf').getValue();
var mammiferes = Ext.getCmp('cb-mammiferes-cf').getValue();
var oiseaux = Ext.getCmp('cb-oiseaux-cf').getValue();
var poissons = Ext.getCmp('cb-poissons-cf').getValue();
var reptiles = Ext.getCmp('cb-reptiles-cf').getValue();
if((!amphibiens&&!mammiferes&&!oiseaux&&!poissons&&!reptiles)==true){return true;}
if(oiseaux && classe==12){return true;}
if(mammiferes && classe==11){return true;}
if(amphibiens && classe==1){return true;}
if(reptiles && classe==14){return true;}
if(poissons && classe==13){return true;}
return false;
};
/*** SOLUTION ATOL ***/
var comboTaxonsTemplate = function(langue) {
var dataIndex = (langue == 'latin'?'nom_latin':'nom_francais');
var comboFicheTaxon = Ext.getCmp('combo-fiche-taxon');
comboFicheTaxon.getStore().sort(dataIndex);
var monTpl = new Ext.XTemplate(
'<tpl for=".">'+
' <div class="x-combo-list-item" style="color:{couleur};">'+
' <tpl if="patrimonial">'+
' <img src="images/logo_pne.gif" width="10" height="10">'+
' </tpl>'+
' {'+dataIndex+'}({nb_obs}) - {derniere_date}'+
' </div>'+
'</tpl>');
if(Ext.isDefined(comboFicheTaxon.view)){
comboFicheTaxon.view.tpl = monTpl;
comboFicheTaxon.view.refresh();
}
};
var sommeDenombrement = function(){
var a = Ext.getCmp('edit-fiche-form').getForm().findField('fieldfiche-male').getValue();
var b = Ext.getCmp('edit-fiche-form').getForm().findField('fieldfiche-femelle').getValue();
var c = Ext.getCmp('edit-fiche-form').getForm().findField('fieldfiche-indetermine').getValue();
var d = Ext.getCmp('edit-fiche-form').getForm().findField('fieldfiche-na').getValue();
var e = Ext.getCmp('edit-fiche-form').getForm().findField('fieldfiche-jeune').getValue();
var f = Ext.getCmp('edit-fiche-form').getForm().findField('fieldfiche-yearling').getValue();
var g = Ext.getCmp('edit-fiche-form').getForm().findField('fieldfiche-sai').getValue();
return a+b+c+d+e+f+g;
};
var isValidForm = function(){
var isValid = true;
Ext.getCmp('grid-taxons').getStore().each(function(r){
if(r.data.id_taxon==0 || r.data.id_taxon==null){isValid = false;return false;}
if(r.data.nom_taxon_saisi=='Saisie en cours'){isValid = false;return false;}
if(r.data.id_critere_cf==0 || r.data.id_critere_cf==null){isValid = false;return false;}
if((r.data.am+r.data.af+r.data.ai+r.data.na+r.data.jeune+r.data.yearling+r.data.sai) == 0){isValid = false;return false;}
return true;
});
return isValid;
};
var isValidTaxon = function(r){
var isValid = true;
errorMsg = '';
if(r.data.id_taxon==0 || r.data.id_taxon==null){isValid = false;errorMsg='Veuillez choisir un taxon';return false;}
if(r.data.id_critere_cf==0 || r.data.id_critere_cf==null){isValid = false;errorMsg='Veuillez choisir un critère pour ce taxon';return false;}
if((r.data.am+r.data.af+r.data.ai+r.data.na+r.data.jeune+r.data.yearling+r.data.sai) == 0){isValid = false;errorMsg='Veuillez choisir une valeur de dénombrement pour au moins une classe d\'âge';return false;}
return true;
return isValid;
};
var manageValidationTaxon = function(isValid){
if(isValid){
Ext.getCmp('grid-taxons').enable();
Ext.getCmp('bt-validtaxon').enable();
Ext.getCmp('bt-validtaxon').setIconClass('validate');
Ext.getCmp('bt-validtaxon').setText('Valider "' + returnTaxonSaisi() +'"');
}
else{
if(!Ext.getCmp('grid-taxons').getSelectionModel().hasNext() && Ext.getCmp('grid-taxons').getSelectionModel().getSelected().data.id_taxon==null){
Ext.getCmp('grid-taxons').enable();
}
else{Ext.getCmp('grid-taxons').disable();}
Ext.getCmp('bt-validtaxon').disable();
Ext.getCmp('bt-validtaxon').setIconClass('unvalidate');
Ext.getCmp('bt-validtaxon').setText('Terminer la saisie pour valider');
Ext.getCmp('grid-taxons').getSelectionModel().getSelected().set('nom_taxon_saisi','Saisie en cours');
}
Ext.getCmp('error-message').setText(errorMsg);
manageValidationForm(isValidForm())
};
var manageValidationForm = function(isValid){
if(isValid){
Ext.getCmp('ficheSaveButton').enable();
Ext.getCmp('bt-addtaxon').enable();
}
else{
Ext.getCmp('ficheSaveButton').disable();
Ext.getCmp('bt-addtaxon').disable();
}
};
this.addNewTaxon = function(){
Ext.getCmp('edit-fiche-form').getForm().findField('monactiontaxon').setValue('add');
relevesStore.add(new blankRecord({
//attention l'ordre des champs est important
id_releve_cf:null
,id_taxon:null
,nom_francais:''
,nom_latin:''
,nom_taxon_saisi:'Saisie en cours'
,id_critere_cf:null
,am:0
,af:0
,ai:0
,na:0
,jeune:0
,yearling:0
,sai:0
,commentaire:''
,cd_ref_origine:null
,denombrement:5
,id_classe:null
,patrimonial:false
}));
Ext.getCmp('fieldset-critere').collapse();
Ext.getCmp('fieldset-denombrement').collapse();
Ext.getCmp('fieldset-commentaire').collapse();
Ext.getCmp('grid-taxons').getSelectionModel().selectLastRow(false);
manageValidationTaxon(false);
};
var returnTaxonSaisi = function(){
var r = null;
if(Ext.getCmp('combo-fiche-taxon').findRecord('id_taxon',Ext.getCmp('combo-fiche-taxon').getValue())){r = Ext.getCmp('combo-fiche-taxon').findRecord('id_taxon',Ext.getCmp('combo-fiche-taxon').getValue())};
if(Ext.getCmp('radiogroup-langue-cf').getValue().inputValue=='fr'){
if(r){return r.data.nom_francais;}
else{return 'en cours';}
}
if(Ext.getCmp('radiogroup-langue-cf').getValue().inputValue=='latin'){
if(r){return r.data.nom_latin;}
else{return 'en cours';}
}
};
if(application.cf.user.statuscode >= 2){
var validTaxonButton = new Ext.Button({
id:'bt-validtaxon'
,iconCls: 'unvalidate'
,text: 'Terminer la saisie pour valider'
,disabled: true
,handler: function() {
Ext.getCmp('grid-taxons').getSelectionModel().getSelected().set('nom_taxon_saisi',returnTaxonSaisi());
manageValidationForm(isValidForm());
}
,scope: this
});
}
if(application.cf.user.statuscode >= 2){
var addTaxonButton = new Ext.Button({
id:'bt-addtaxon'
,iconCls: 'add'
,text: 'Ajouter un taxon sur ce pointage'
,disabled: true
,handler: function() {
this.addNewTaxon();
Ext.getCmp('combo-fiche-taxon').focus();
}
,scope: this
});
}
storeTaxonsCf = new Ext.data.JsonStore({
url: myProxyTaxons
,fields: [
'id_taxon'
,'cd_ref'
,'nom_latin'
,{name:'nom_francais',sortType: Ext.data.SortTypes.asAccentuatedString}
,'id_classe'
,'denombrement'
,'patrimonial'
,'message'
,'couleur'
,'nb_obs'
,'derniere_date'
]
,sortInfo: {
field: 'nom_francais'
,direction: 'ASC'
}
,autoLoad:true
,listeners: {
load: function(store, records) {
if(Ext.getCmp('grid-taxons').getSelectionModel().getSelected()){
Ext.getCmp('combo-fiche-taxon').setValue(Ext.getCmp('grid-taxons').getSelectionModel().getSelected().data.id_taxon);
}
comboTaxonsFiltre();
}
}
});
/*
* création du formulaire taxon
*/
var gridForm = new Ext.Panel({
id: 'taxons-form'
,frame: true
,labelAlign: 'left'
,title: 'Listes des taxons observés'
,bodyStyle:'padding:5px'
,width: 600
,layout: 'column' // Specifies that the items will now be arranged in columns
,items: [{
columnWidth: 0.6
,xtype: 'panel'
,labelWidth: 80
,defaults: {
width: 305
,border:false
,allowDecimals :false
,allowNegative: false
}
,defaultType: 'numberfield'
,autoHeight: true
,bodyStyle: Ext.isIE ? 'padding:0 0 5px 5px;' : 'padding:5px 5px;'
,border: false
,style: {
"margin-left": "5px", // when you add custom margin in IE 6...
"margin-right": Ext.isIE6 ? (Ext.isStrict ? "-10px" : "-13px") : "0" // you have to adjust for it somewhere else
}
,items: [
{
xtype:'fieldset'
,id:'fieldset-taxons'
,columnWidth: 1
,title: 'Choix du taxon observé'
,collapsible: true
,autoHeight:true
,anchor:'100%'
,items :[
{
id:'radiogroup-langue-cf'
,xtype: 'radiogroup'
,fieldLabel: 'Langue'
,defaultType: 'radio'
,cls:'graytext'
,itemCls:'graytext'
,items: [{
boxLabel: 'français'
,name: 'langue'
,itemCls:'graytext'
,inputValue: 'fr'
,checked: true
,listeners: {
check: function(checkbox,checked) {
if(checked){
comboTaxonsTemplate('fr');
Ext.getCmp('combo-fiche-taxon').displayField = 'nom_francais';
Ext.getCmp('combo-fiche-taxon').setValue(Ext.getCmp('combo-fiche-taxon').getValue());//pas trouvé mieux pour rafraichier en live le taxon déjà affiché dans le combo
}
}
}
},{
boxLabel: 'latin'
,name: 'langue'
,itemCls:'graytext'
,inputValue: 'latin'
,listeners: {
check: function(checkbox,checked) {
if(checked){comboTaxonsTemplate('latin');
Ext.getCmp('combo-fiche-taxon').displayField = 'nom_latin'
Ext.getCmp('combo-fiche-taxon').setValue(Ext.getCmp('combo-fiche-taxon').getValue());//pas trouvé mieux pour rafraichier en live le taxon déjà affiché dans le combo
}
}
}
}
]
},{
id:'checkboxgroup-classe-cf'
,xtype: 'checkboxgroup'
,fieldLabel: 'Groupe taxonomique'
,cls:'graytext'
,itemCls:'graytext'
,columns: 2
,items: [{
id:'cb-mammiferes-cf'
,boxLabel: 'Mammifères'
,name: 'cb-mammiferes'
,itemCls:'graytext'
,checked: false
,listeners: {
check: function(checkbox,checked){
if(checked){
Ext.getCmp('cb-oiseaux-cf').setValue(false);
Ext.getCmp('cb-reptiles-cf').setValue(false);
Ext.getCmp('cb-amphibiens-cf').setValue(false);
Ext.getCmp('cb-poissons-cf').setValue(false);
}
if(Ext.getCmp('combo-fiche-taxon')){Ext.getCmp('combo-fiche-taxon').clearValue();}
comboTaxonsFiltre();
}
,render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Affiche les mammifères dans la liste si la case est cochée.'
});
}
}
},{
id:'cb-oiseaux-cf'
,boxLabel: 'Oiseaux'
,name: 'cb-oiseaux'
,itemCls:'graytext'
,checked: false
,listeners: {
check: function(checkbox,checked) {
if(checked){
Ext.getCmp('cb-mammiferes-cf').setValue(false);
Ext.getCmp('cb-reptiles-cf').setValue(false);
Ext.getCmp('cb-amphibiens-cf').setValue(false);
Ext.getCmp('cb-poissons-cf').setValue(false);
}
if(Ext.getCmp('combo-fiche-taxon')){Ext.getCmp('combo-fiche-taxon').clearValue();}
comboTaxonsFiltre();
}
,render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Affiche les oiseaux dans la liste si la case est cochée.'
});
}
}
},{
id:'cb-reptiles-cf'
,boxLabel: 'Reptiles'
,name: 'cb-reptiles'
,itemCls:'graytext'
,checked: false
,listeners: {
check: function(checkbox,checked) {
if(checked){
Ext.getCmp('cb-mammiferes-cf').setValue(false);
Ext.getCmp('cb-oiseaux-cf').setValue(false);
Ext.getCmp('cb-amphibiens-cf').setValue(false);
Ext.getCmp('cb-poissons-cf').setValue(false);
}
if(Ext.getCmp('combo-fiche-taxon')){Ext.getCmp('combo-fiche-taxon').clearValue();}
comboTaxonsFiltre();
}
,render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Affiche les reptiles dans la liste si la case est cochée.'
});
}
}
},{
id:'cb-amphibiens-cf'
,boxLabel: 'Amphibiens'
,name: 'cb-amphibiens'
,itemCls:'graytext'
,checked: false
,listeners: {
check: function(checkbox,checked) {
if(checked){
Ext.getCmp('cb-mammiferes-cf').setValue(false);
Ext.getCmp('cb-oiseaux-cf').setValue(false);
Ext.getCmp('cb-reptiles-cf').setValue(false);
Ext.getCmp('cb-poissons-cf').setValue(false);
}
if(Ext.getCmp('combo-fiche-taxon')){Ext.getCmp('combo-fiche-taxon').clearValue();}
comboTaxonsFiltre();
}
,render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Affiche les amphibiens dans la liste si la case est cochée.'
});
}
}
},{
id:'cb-poissons-cf'
,boxLabel: 'Poissons'
,name: 'cb-poissons'
,itemCls:'graytext'
,checked: false
,listeners: {
check: function(checkbox,checked) {
if(checked){
Ext.getCmp('cb-mammiferes-cf').setValue(false);
Ext.getCmp('cb-oiseaux-cf').setValue(false);
Ext.getCmp('cb-reptiles-cf').setValue(false);
Ext.getCmp('cb-amphibiens-cf').setValue(false);
}
if(Ext.getCmp('combo-fiche-taxon')){Ext.getCmp('combo-fiche-taxon').clearValue();}
comboTaxonsFiltre();
}
,render: function(c) {
Ext.QuickTips.register({
target: c.getEl(),
text: 'Affiche uniquement les poissons dans la liste si la case est cochée.'
});
}
}
}
]
},{