1+ Ext4 . define ( 'SequenceBasedGenotyping.window.ChangeReadsetStatusWindow' , {
2+ extend : 'Ext.window.Window' ,
3+
4+ statics : {
5+ buttonHandlerForAnalyses : function ( dataRegionName ) {
6+ var dr = LABKEY . DataRegions [ dataRegionName ] ;
7+ LDK . Assert . assertNotEmpty ( 'Unable to find dataregion in ChangeReadsetStatusWindow' , dr ) ;
8+
9+ var checked = dr . getChecked ( ) ;
10+ if ( ! checked . length ) {
11+ Ext4 . Msg . alert ( 'Error' , 'No rows selected' ) ;
12+ return ;
13+ }
14+
15+ Ext4 . create ( 'SequenceBasedGenotyping.window.ChangeReadsetStatusWindow' , {
16+ targetQuery : 'sequence_analyses' ,
17+ targetColumns : 'readset/rowid,readset/container' ,
18+ readsetField : 'readset/rowid' ,
19+ containerField : 'readset/container' ,
20+ dataRegionName : dataRegionName ,
21+ checked : checked
22+ } ) . show ( ) ;
23+ } ,
24+
25+ buttonHandlerForReadsets : function ( dataRegionName ) {
26+ var dr = LABKEY . DataRegions [ dataRegionName ] ;
27+ LDK . Assert . assertNotEmpty ( 'Unable to find dataregion in ChangeReadsetStatusWindow' , dr ) ;
28+
29+ var checked = dr . getChecked ( ) ;
30+ if ( ! checked . length ) {
31+ Ext4 . Msg . alert ( 'Error' , 'No rows selected' ) ;
32+ return ;
33+ }
34+
35+ Ext4 . create ( 'SequenceBasedGenotyping.window.ChangeReadsetStatusWindow' , {
36+ targetQuery : 'sequence_readsets' ,
37+ targetColumns : 'rowid,container' ,
38+ readsetField : 'rowid' ,
39+ containerField : 'container' ,
40+ dataRegionName : dataRegionName ,
41+ checked : checked
42+ } ) . show ( ) ;
43+ }
44+ } ,
45+
46+ initComponent : function ( ) {
47+ Ext4 . apply ( this , {
48+ modal : true ,
49+ title : 'Change Readset Status' ,
50+ bodyStyle : 'padding: 5px;' ,
51+ closeAction : 'destroy' ,
52+ width : 500 ,
53+ defaults : {
54+ border : false
55+ } ,
56+ items : [ {
57+ html : 'This will update the status for the readsets associated with the ' + this . checked . length + ' selected rows.' ,
58+ style : 'padding-bottom: 10px;'
59+ } , {
60+ xtype : 'labkey-combo' ,
61+ itemId : 'statusField' ,
62+ forceSelection : true ,
63+ width : 400 ,
64+ fieldLabel : 'Status' ,
65+ displayField : 'status' ,
66+ valueField : 'status' ,
67+ queryMode : 'local' ,
68+ store : {
69+ type : 'labkey-store' ,
70+ containerPath : Laboratory . Utils . getQueryContainerPath ( ) ,
71+ schemaName : 'sequenceanalysis' ,
72+ queryName : 'readset_status' ,
73+ autoLoad : true
74+ }
75+ } ] ,
76+ buttons : [ {
77+ text : 'Submit' ,
78+ scope : this ,
79+ handler : this . onSubmit
80+ } , {
81+ text : 'Cancel' ,
82+ handler : function ( btn ) {
83+ btn . up ( 'window' ) . close ( ) ;
84+ }
85+ } ]
86+ } ) ;
87+
88+ this . callParent ( arguments ) ;
89+ } ,
90+
91+ onSubmit : function ( ) {
92+ var rowIds = this . checked ;
93+ var status = this . down ( '#statusField' ) . getValue ( ) ;
94+ //NOTE: allow a blank value
95+ //if (!status){
96+ //
97+ //}
98+
99+ Ext4 . Msg . wait ( 'Loading...' ) ;
100+
101+ LABKEY . Query . selectRows ( {
102+ method : 'POST' ,
103+ schemaName : 'sequenceanalysis' ,
104+ queryName : this . targetQuery ,
105+ columns : this . targetColumns ,
106+ filterArray : [ LABKEY . Filter . create ( 'rowid' , rowIds . join ( ';' ) , LABKEY . Filter . Types . IN ) ] ,
107+ scope : this ,
108+ failure : LDK . Utils . getErrorCallback ( ) ,
109+ success : function ( results ) {
110+ if ( ! results || ! results . rows ) {
111+ Ext4 . Msg . hide ( ) ;
112+ Ext4 . Msg . alert ( 'Error' , 'Unable to find matching rows' ) ;
113+ return ;
114+ }
115+
116+ var readsetIds = [ ] ;
117+ Ext4 . Array . forEach ( results . rows , function ( row ) {
118+ if ( row [ this . readsetField ] ) {
119+ readsetIds . push ( row [ this . readsetField ] + '<>' + row [ this . containerField ] ) ;
120+ }
121+ } , this ) ;
122+
123+ readsetIds = Ext4 . unique ( readsetIds ) ;
124+
125+ var toUpdate = [ ] ;
126+ Ext4 . Array . forEach ( readsetIds , function ( r ) {
127+ var tokens = r . split ( '<>' ) ;
128+ toUpdate . push ( {
129+ rowid : tokens [ 0 ] ,
130+ container : tokens [ 1 ] ,
131+ status : status || null
132+ } ) ;
133+ } , this ) ;
134+
135+ if ( toUpdate . length ) {
136+ LABKEY . Query . updateRows ( {
137+ method : 'POST' ,
138+ schemaName : 'sequenceanalysis' ,
139+ queryName : 'sequence_readsets' ,
140+ rows : toUpdate ,
141+ scope : this ,
142+ failure : LDK . Utils . getErrorCallback ( ) ,
143+ success : function ( results ) {
144+ Ext4 . Msg . hide ( ) ;
145+
146+ if ( this . dataRegionName ) {
147+ LABKEY . DataRegions [ this . dataRegionName ] . clearSelected ( ) ;
148+ }
149+
150+ Ext4 . Msg . alert ( 'Success' , 'Readsets updated' , function ( ) {
151+ LABKEY . DataRegions [ this . dataRegionName ] . refresh ( ) ;
152+ } , this ) ;
153+ }
154+ } ) ;
155+ }
156+ else {
157+ Ext4 . Msg . hide ( ) ;
158+ Ext4 . Msg . alert ( 'Error' , 'No matching readsets found for the selected rows' ) ;
159+ }
160+ }
161+ } ) ;
162+ }
163+ } ) ;
0 commit comments