@@ -72,6 +72,9 @@ var trelloGithub = (function($, Trello) {
72
72
}
73
73
74
74
var createIssue = exports . createIssue = function ( event ) {
75
+ if ( ! [ '#github-repo' , '#issue-title' ] . map ( function ( e ) { return validate ( e ) ; } ) . reduce ( function ( p , c , i , a ) { return p && c ; } , true ) )
76
+ return ;
77
+
75
78
var pathparts = location . pathname . split ( '/' ) ;
76
79
var boardId = pathparts [ pathparts . length - 2 ] ;
77
80
var cardShortId = pathparts [ pathparts . length - 1 ] ;
@@ -85,7 +88,8 @@ var trelloGithub = (function($, Trello) {
85
88
86
89
Trello . post ( '/checklists/' + checklist . id + '/checkItems' , { name :issue . html_url } , function ( ) {
87
90
//hooray! we've completed everything.
88
- window . location . reload ( ) ;
91
+ $ ( '#github-popover' ) . hide ( ) ;
92
+ //window.location.reload();
89
93
} , function ( ) {
90
94
alert ( 'trello api error' ) ;
91
95
} ) ;
@@ -151,9 +155,39 @@ var trelloGithub = (function($, Trello) {
151
155
}
152
156
} ) ;
153
157
$ ( '.js-create-github-issue' ) . click ( createIssue ) ;
158
+
159
+ //validation
160
+ $ ( '#issue-title' ) . blur ( function ( e ) {
161
+ validate ( '#issue-title' ) ;
162
+ } ) ;
163
+
164
+ $ ( '#github-repo' ) . blur ( function ( e ) {
165
+ validate ( '#github-repo' )
166
+ } ) ;
154
167
} ) ;
155
168
}
156
169
170
+ var validators = {
171
+ '#github-repo' :function ( ) {
172
+ var good = ( / ^ [ ^ \s \/ ] + \/ [ ^ \s \/ ] + $ / . test ( $ ( '#github-repo' ) . val ( ) ) ) ;
173
+ $ ( '#github-repo' ) . toggleClass ( 'input-error' , ! good ) ;
174
+ return good ;
175
+ } ,
176
+ '#issue-title' :function ( ) {
177
+ var good = $ ( '#issue-title' ) . val ( ) . length > 0 ;
178
+ $ ( '#issue-title' ) . toggleClass ( 'input-error' , ! good ) ;
179
+ return good ;
180
+ }
181
+ } ;
182
+
183
+ var validate = exports . validate = function ( id ) {
184
+ var validator = validators [ id ] ;
185
+ if ( typeof validator !== 'function' )
186
+ return null ;
187
+
188
+ return validator ( ) ;
189
+ }
190
+
157
191
setupPopover ( ) ;
158
192
githubAuth ( ) ;
159
193
0 commit comments