@@ -97,52 +97,19 @@ jt.setFormDefaults = function() {
97
97
}
98
98
99
99
if (
100
- $ ( this ) . attr ( 'action' ) === undefined &&
100
+ form . attr ( 'action' ) === undefined &&
101
101
(
102
102
this . $listeners == null ||
103
103
this . $listeners . click == null
104
104
)
105
105
) {
106
106
try {
107
- $ ( this ) . off ( 'submit' ) ;
108
- $ ( this ) . submit ( function ( event ) {
107
+ form . off ( 'submit' ) ;
108
+ form . submit ( function ( event ) {
109
109
event . preventDefault ( ) ;
110
110
event . stopPropagation ( ) ;
111
- var values = { } ;
112
- var stageName = jt . data . player . stage . id ;
113
- values . fnName = stageName ;
114
- values . playerRoomId = jt . data . player . roomId ;
115
-
116
- // INPUTS (includes input, select and checkboxes, but not buttons)
117
- // https://stackoverflow.com/questions/11855781/jquery-getting-data-from-form
118
- var $inputs = $ ( this ) . find ( ':input:not(:button)' ) ;
119
- $inputs . each ( function ( ) {
120
- // Skip blank inputs.
121
- var fieldName = $ ( this ) . attr ( 'name' ) ;
122
- if ( fieldName !== '' && fieldName !== undefined ) {
123
- if ( this . type === 'checkbox' ) {
124
- if ( this . checked === true ) {
125
- if ( values [ fieldName ] === undefined ) {
126
- values [ fieldName ] = [ ] ;
127
- }
128
- values [ fieldName ] . push ( this . value ) ;
129
- }
130
- } else if ( this . type === 'radio' ) {
131
- if ( this . checked ) {
132
- values [ fieldName ] = this . value ;
133
- }
134
- } else {
135
- values [ fieldName ] = this . value ;
136
- }
137
- }
138
- } ) ;
139
-
140
- console . log ( 'submitting form with values ' + JSON . stringify ( values ) ) ;
141
-
142
- jt . sendMessage ( stageName , values ) ;
143
-
144
- $ ( form ) . find ( '[jtautogenerated=true]' ) . remove ( ) ;
145
-
111
+ jt . submitForm ( form ) ;
112
+ form . find ( '[jtautogenerated=true]' ) . remove ( ) ;
146
113
} ) ;
147
114
} catch ( err ) {
148
115
console . log ( 'error assigning submit button action' ) ;
@@ -153,6 +120,49 @@ jt.setFormDefaults = function() {
153
120
154
121
}
155
122
123
+ jt . submitForm = function ( formEl ) {
124
+ var values = { } ;
125
+
126
+ // INPUTS (includes input, select and checkboxes, but not buttons)
127
+ // https://stackoverflow.com/questions/11855781/jquery-getting-data-from-form
128
+ var $inputs = $ ( formEl ) . find ( ':input:not(:button)' ) ;
129
+ $inputs . each ( function ( ) {
130
+ // Skip blank inputs.
131
+ var fieldName = $ ( this ) . attr ( 'name' ) ;
132
+ if ( fieldName !== '' && fieldName !== undefined ) {
133
+ if ( this . type === 'checkbox' ) {
134
+ if ( this . checked === true ) {
135
+ if ( values [ fieldName ] === undefined ) {
136
+ values [ fieldName ] = [ ] ;
137
+ }
138
+ values [ fieldName ] . push ( this . value ) ;
139
+ }
140
+ } else if ( this . type === 'radio' ) {
141
+ if ( this . checked ) {
142
+ values [ fieldName ] = this . value ;
143
+ }
144
+ } else {
145
+ values [ fieldName ] = this . value ;
146
+ }
147
+ }
148
+ } ) ;
149
+ jt . submitFormData ( values ) ;
150
+ }
151
+
152
+ jt . submitFormData = function ( values ) {
153
+ var stageName = jt . data . player . stage . id ;
154
+ values . fnName = stageName ;
155
+ values . playerRoomId = jt . data . player . roomId ;
156
+ console . log ( 'submitting form with values ' + JSON . stringify ( values ) ) ;
157
+ try {
158
+ jt . vue . app . onSubmit ( ) ;
159
+ } catch ( err ) {
160
+
161
+ }
162
+ $ ( '#jtree' ) . addClass ( 'hidden' ) ;
163
+ jt . sendMessage ( stageName , values ) ;
164
+ }
165
+
156
166
jt . vueMounted = false ;
157
167
jt . vueMethods = { } ;
158
168
@@ -253,6 +263,21 @@ jt.getVueModels = function(player) {
253
263
timeElapsed : 0 ,
254
264
timeElapsedClient : 0 ,
255
265
}
266
+
267
+ let app = vueModel . app ;
268
+ let funcPrefix = '__func_' ;
269
+ for ( let i in app ) {
270
+ let isFunc = false ;
271
+ let name = i ;
272
+ if ( name . startsWith ( funcPrefix ) ) {
273
+ name = name . substring ( funcPrefix . length ) ;
274
+ isFunc = true ;
275
+ }
276
+ if ( isFunc ) {
277
+ eval ( 'app[name] = ' + app [ i ] ) ;
278
+ }
279
+ }
280
+
256
281
if ( vueModel . group . players == null ) {
257
282
vueModel . group . players = [ ] ;
258
283
}
@@ -353,6 +378,9 @@ jt.updatePlayer = function(player, updateVue) {
353
378
return ;
354
379
}
355
380
381
+ $ ( '#jtree' ) . removeClass ( 'hidden' ) ;
382
+ $ ( '.alert-box' ) . remove ( ) ;
383
+
356
384
if ( ! jt . vueMounted ) {
357
385
jt . mountVue ( player ) ;
358
386
$ ( 'body' ) . addClass ( 'show' ) ;
@@ -632,13 +660,11 @@ jt.endStage = function(player) {
632
660
let forms = $ ( 'form' ) . filter ( ':visible' ) ;
633
661
if ( forms != null && forms . length > 0 ) {
634
662
forms . each ( function ( ) {
635
- $ ( this ) . submit ( ) ;
663
+ jt . submitForm ( this ) ;
636
664
} ) ;
637
665
} else {
638
666
var values = { } ;
639
- var stageName = jt . data . player . stage . id ;
640
- values . fnName = stageName ;
641
- jt . sendMessage ( stageName , values ) ;
667
+ jt . submitFormData ( values ) ;
642
668
}
643
669
}
644
670
}
0 commit comments