1+ Ext4 . define ( 'Laboratory.panel.StudiesFilterType' , {
2+ extend : 'LDK.panel.AbstractFilterType' ,
3+ alias : 'widget.studies-filtertype' ,
4+
5+ statics : {
6+ filterName : 'study' ,
7+ label : 'Studies'
8+ } ,
9+
10+ initComponent : function ( ) {
11+ this . items = this . getItems ( ) ;
12+
13+ this . callParent ( ) ;
14+ } ,
15+
16+ getItems : function ( ) {
17+ var ctx = this . filterContext ;
18+ var toAdd = [ ] ;
19+
20+ toAdd . push ( {
21+ width : 200 ,
22+ html : 'Choose Study:' ,
23+ style : 'margin-bottom:10px'
24+ } ) ;
25+
26+ toAdd . push ( {
27+ xtype : 'panel' ,
28+ items : [ {
29+ xtype : 'combo' ,
30+ width : 265 ,
31+ itemId : 'studyField' ,
32+ displayField : 'studyName' ,
33+ valueField : 'studyName' ,
34+ multiSelect : false ,
35+ store : {
36+ type : 'labkey-store' ,
37+ schemaName : 'studies' ,
38+ queryName : 'studies' ,
39+ autoLoad : true
40+ } ,
41+ value : Ext4 . isArray ( ctx . studies ) ? ctx . studies . join ( ';' ) : ctx . studies
42+ } ]
43+ } ) ;
44+
45+ return toAdd ;
46+ } ,
47+
48+ getFilters : function ( ) {
49+ return {
50+ studies : this . getStudies ( )
51+ }
52+ } ,
53+
54+ getFilterArray : function ( tab ) {
55+ var filterArray = {
56+ removable : [ ] ,
57+ nonRemovable : [ ]
58+ } ;
59+
60+ if ( this . reportQCStates ?. length ) {
61+ filterArray . nonRemovable . push ( LABKEY . Filter . create ( 'qcstate/label' , this . reportQCStates , LABKEY . Filter . Types . EQUALS_ONE_OF ) ) ;
62+ }
63+
64+ var filters = this . getFilters ( ) ;
65+ var report = tab . report ;
66+ var studyFieldName = report . additionalFieldKeys ?. studyAssignmentFieldKey ;
67+ if ( ! studyFieldName ) {
68+ LDK . Utils . logToServer ( {
69+ message : 'A TabbedReport is attempting to load a study filter when it should have been stopped upstream' ,
70+ level : 'ERROR' ,
71+ includeContext : true
72+ } ) ;
73+
74+ return filterArray ;
75+ }
76+
77+ var studyName = filters . studies [ 0 ] ;
78+ filterArray . nonRemovable . push ( LABKEY . Filter . create ( studyFieldName , studyName , LABKEY . Filter . Types . CONTAINS ) ) ;
79+
80+ return filterArray ;
81+ } ,
82+
83+ isValid : function ( ) {
84+ var val = this . down ( '#studyField' ) . getValue ( ) ;
85+ if ( ! val || ! val . length ) {
86+ return false ;
87+ }
88+
89+ return true ;
90+ } ,
91+
92+ getFilterInvalidMessage : function ( ) {
93+ return 'Error: Must choose a study' ;
94+ } ,
95+
96+ validateReportForFilterType : function ( report ) {
97+ if ( ! report . additionalFieldKeys ?. studyAssignmentFieldKey ) {
98+ return 'This report cannot be used with the selected filter type, because the report does not contain a field with study assignment information' ;
99+ }
100+
101+ return null ;
102+ } ,
103+
104+ getTitle : function ( ) {
105+ var studies = this . getStudies ( ) ;
106+
107+ if ( studies && studies . length ) {
108+ return studies . join ( ', ' ) ;
109+ }
110+
111+ return '' ;
112+ } ,
113+
114+ getStudies : function ( ) {
115+ var projectArray = this . down ( '#studyField' ) . getValue ( ) ;
116+ if ( projectArray && ! Ext4 . isArray ( projectArray ) ) {
117+ projectArray = [ projectArray ] ;
118+ }
119+
120+ if ( projectArray && projectArray . length > 0 ) {
121+ projectArray = Ext4 . unique ( projectArray ) ;
122+ projectArray . sort ( ) ;
123+ }
124+
125+ return projectArray ;
126+ }
127+ } ) ;
0 commit comments