/************************************************************* * motivation.js.php * * Shows motivation inquiry form and processes response. * * Author: LITW Core Team * Last Modified: August 16, 2016 * * © Copyright 2016 LabintheWild * For questions about this file and permission to use * the code, contact us at info@labinthewild.org *************************************************************/ var litw_locale = "en"; var MOTIVATION = { participant_id: 0, study_name: "", show_where: "", show_next: null, likert_labels_5: ["Not at all", "", "", "", "Very much"], likert_labels_7: ["Not at all true", "", "", "Somewhat true", "", "", "Very true"], data: {}, timestamp_1: null, timestamp_2: null } function motivation_show(show_where, show_next, participant_id, study_name, args) { args = args || {}; MOTIVATION.participant_id = participant_id; MOTIVATION.study_name = study_name; MOTIVATION.show_next = show_next; MOTIVATION.show_where = show_where; MOTIVATION.next_btn_msg = args.next_btn_msg; var likert_items = motivation_shuffle([ "

" + "I want to help science" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "", "

" + "For fun" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "", "

" + "I want to learn about myself" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "", "

" + "I want to compare myself to others" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "", "

" + "I am bored" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" ]); var html = "
" + "

" + "Before we get started, we have a quick question for you:" + "

" + "

" + "To what extent are you participating in an experiment on LabintheWild for the following reasons?" + "

"; likert_items.forEach(function(item) { html += item; }); html += "
"; $("#" + MOTIVATION.show_where).html(html); $("#.option-set-header:first").css("margin-top", "0"); showSlide(show_where); showNextButton(function() { motivation_process(); }, MOTIVATION.next_btn_msg); disableKeyboard(); $('body, html').scrollTop(0); } function motivation_comments_show(show_where, participant_id, study_name) { MOTIVATION.participant_id = participant_id; MOTIVATION.study_name = study_name; MOTIVATION.show_where = show_where; var likert_items = motivation_shuffle([ "

" + "This task was fun to do" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
", "

" + "I thought this was a boring task" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
", "

" + "I would describe this task as very interesting" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
", "

" + "I thought this task was quite enjoyable" + "

" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
" ]); var html = "
" + "

" + "Also, one more question:" + "

" + "

" + "For each of the following statements, please indicate how true it is for you:" + "

"; likert_items.forEach(function(item) { html += item; }); html += "
"; $("#" + MOTIVATION.show_where).append(html); $("#.option-set-header:first").css("margin-top", "0"); showSlide(show_where); $('body, html').scrollTop(0); } function motivation_process() { MOTIVATION.timestamp_1 = new Date().getTime(); $("#" + MOTIVATION.show_where).css("opacity", "0.5"); $("#ajax_working").css("display", "block"); // get form responses, ignoring blank text boxes // NOTE: in future studies, we may not want to ignore blank responses, // in order to make analysis easier $("#motivation_form :input[value!='']").serializeArray().forEach(function(resp) { MOTIVATION.data[resp.name] = resp.value; }); motivation_submit(); } function motivation_comments_process() { MOTIVATION.timestamp_2 = new Date().getTime(); $("#" + MOTIVATION.show_where).css("opacity", "0.5"); $("#ajax_working").css("display", "block"); // get form responses, ignoring blank text boxes $("#motivation_comments_form :input[value!='']").serializeArray().forEach(function(resp) { MOTIVATION.data[resp.name] = resp.value; }); motivation_comments_submit(); } function motivation_submit() { // We are shifting towards saving data in a json field as used below, // but I am also keeping previous columns for backwards compatibility var motivation_data = MOTIVATION.data; if (Object.keys(MOTIVATION.data).length > 0) { motivation_data['timestamp'] = MOTIVATION.timestamp_1; motivation_data['participant_id'] = MOTIVATION.participant_id; motivation_data['locale'] = MOTIVATION.locale; motivation_data['study_name'] = MOTIVATION.study_name; $.ajax({ type: 'POST', url: '../motivation_inquiry/include/motivation.php', data: { participant_id: MOTIVATION.participant_id, study_name: MOTIVATION.study_name, locale: litw_locale, timestamp_1: MOTIVATION.timestamp_1, data: JSON.stringify(motivation_data), } }).done(function(response) { motivation_proceed(); }); } else { motivation_proceed(); } } function motivation_comments_submit() { if (Object.keys(MOTIVATION.data).length > 0) { $.ajax({ type: 'POST', url: '../motivation_inquiry/include/motivationComments.php', data: { participant_id: MOTIVATION.participant_id, study_name: MOTIVATION.study_name, locale: litw_locale, timestamp_1: MOTIVATION.timestamp_1, timestamp_2: MOTIVATION.timestamp_2, data: JSON.stringify(MOTIVATION.data), } }).done(function(response) { // nothing--study advancement is handled by the comments page already }); } } function motivation_proceed() { setTimeout(function() { $("#ajax_working").css("display", "none"); MOTIVATION.show_next(); }, 1000); } // Fisher-Yates array shuffle algorithm function motivation_shuffle(array) { var m = array.length, t, i; while (m) { i = Math.floor(Math.random() * m--); t = array[m]; array[m] = array[i]; array[i] = t; } return array; }