Skip to content

Commit 14ad5d8

Browse files
committed
submit stage
1 parent a20f747 commit 14ad5d8

File tree

2 files changed

+87
-61
lines changed

2 files changed

+87
-61
lines changed

client/internal/clients/participant/defaultClient.js

Lines changed: 68 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -97,52 +97,19 @@ jt.setFormDefaults = function() {
9797
}
9898

9999
if (
100-
$(this).attr('action')===undefined &&
100+
form.attr('action')===undefined &&
101101
(
102102
this.$listeners == null ||
103103
this.$listeners.click == null
104104
)
105105
) {
106106
try {
107-
$(this).off('submit');
108-
$(this).submit(function(event) {
107+
form.off('submit');
108+
form.submit(function(event) {
109109
event.preventDefault();
110110
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();
146113
});
147114
} catch (err) {
148115
console.log('error assigning submit button action');
@@ -153,6 +120,49 @@ jt.setFormDefaults = function() {
153120

154121
}
155122

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+
156166
jt.vueMounted = false;
157167
jt.vueMethods = {};
158168

@@ -253,6 +263,21 @@ jt.getVueModels = function(player) {
253263
timeElapsed: 0,
254264
timeElapsedClient: 0,
255265
}
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+
256281
if (vueModel.group.players == null) {
257282
vueModel.group.players = [];
258283
}
@@ -353,6 +378,9 @@ jt.updatePlayer = function(player, updateVue) {
353378
return;
354379
}
355380

381+
$('#jtree').removeClass('hidden');
382+
$('.alert-box').remove();
383+
356384
if (!jt.vueMounted) {
357385
jt.mountVue(player);
358386
$('body').addClass('show');
@@ -632,13 +660,11 @@ jt.endStage = function(player) {
632660
let forms = $('form').filter(':visible');
633661
if (forms != null && forms.length > 0) {
634662
forms.each(function() {
635-
$(this).submit();
663+
jt.submitForm(this);
636664
});
637665
} else {
638666
var values = {};
639-
var stageName = jt.data.player.stage.id;
640-
values.fnName = stageName;
641-
jt.sendMessage(stageName, values);
667+
jt.submitFormData(values);
642668
}
643669
}
644670
}

server/source/App.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class App {
6666
this.shortId = id;
6767

6868

69+
this.onSubmit = function() {
70+
jt.popupMessage('Submitting...');
71+
};
72+
6973
/**
7074
* @type {jt}
7175
*/
@@ -1630,6 +1634,18 @@ class App {
16301634
}
16311635
}
16321636

1637+
copyFieldsTo(obj) {
1638+
var fields = this.outputFields();
1639+
for (var f in fields) {
1640+
var field = fields[f];
1641+
if (Utils.isFunction(this[field])) {
1642+
obj['__func_' + field] = this[field].toString();
1643+
} else {
1644+
obj[field] = this[field];
1645+
}
1646+
}
1647+
}
1648+
16331649
/**
16341650
* A shell of this object. Excludes parent, includes child shells.
16351651
*
@@ -1640,15 +1656,7 @@ class App {
16401656
*/
16411657
shellWithChildren() {
16421658
var out = {};
1643-
var fields = this.outputFields();
1644-
for (var f in fields) {
1645-
var field = fields[f];
1646-
if (Utils.isFunction(this[field])) {
1647-
out['__func_' + field] = this[field].toString();
1648-
} else {
1649-
out[field] = this[field];
1650-
}
1651-
}
1659+
this.copyFieldsTo(out);
16521660
out.indexInSession = this.indexInSession();
16531661
out.periods = [];
16541662
for (var i in this.periods) {
@@ -1669,11 +1677,7 @@ class App {
16691677
*/
16701678
shellWithParent() {
16711679
var out = {};
1672-
var fields = this.outputFields();
1673-
for (var f in fields) {
1674-
var field = fields[f];
1675-
out[field] = this[field];
1676-
}
1680+
this.copyFieldsTo(out);
16771681
out.session = this.session.shell();
16781682
out.numStages = this.stages.length;
16791683
out.vueComputedText = {};
@@ -1702,11 +1706,7 @@ class App {
17021706
*/
17031707
shell() {
17041708
var out = {};
1705-
var fields = this.outputFields();
1706-
for (var f in fields) {
1707-
var field = fields[f];
1708-
out[field] = this[field];
1709-
}
1709+
this.copyFieldsTo(out);
17101710
out.sessionIndex = this.indexInSession();
17111711
return out;
17121712
}

0 commit comments

Comments
 (0)