Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

added: OC: Allow user to open next form when closing current form #392

Merged
merged 5 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/controllers/oc-api-v1-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ router
.post( '*', _setReturnQueryParam ) // is this actually used by OC?
.post( '*', _setGoTo )
.post( '*', _setParentWindow )
.post( '*', _setNextPrompt )
.post( /\/(survey|instance)\/(collect|edit|view|note|headless)/, _setEcid ) // excl preview
.post( /\/(survey|instance)\/(collect|edit|preview)(?!\/participant)/, _setJini ) // excl view, note, and participant
.post( /\/(survey|instance)\/(collect|edit|view|note)(?!\/participant)/, _setPid ) // excl preview, and participant
Expand Down Expand Up @@ -391,6 +392,15 @@ function _setParentWindow( req, res, next ) {
next();
}

function _setNextPrompt( req, res, next ) {
const nextPrompt = req.body.next_prompt;

if ( nextPrompt ) {
req.nextPromptParam = `next_prompt=${encodeURIComponent( nextPrompt )}`;
}
next();
}

function _setReturnQueryParam( req, res, next ) {
const returnUrl = req.body.return_url;

Expand Down Expand Up @@ -461,7 +471,7 @@ function _generateWebformUrls( id, req ) {
}
case 'single': {
const idToUse = dnClosePart ? idFsC : id;
const queryString = _generateQueryString( [ req.ecid, req.pid, req.defaultsQueryParam, req.returnQueryParam, req.parentWindowOriginParam, req.jini ] );
const queryString = _generateQueryString( [ req.ecid, req.pid, req.defaultsQueryParam, req.returnQueryParam, req.parentWindowOriginParam, req.jini, req.nextPromptParam ] );
url = `${BASEURL}single/${FSPATH}${dnClosePart}${IFRAMEPATH}${idToUse}${queryString}`;
break;
}
Expand Down
8 changes: 8 additions & 0 deletions app/controllers/survey-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ router
.get( '*/headless*', _setHeadless )
.get( '/preview*', _setJini )
.get( /\/(single|edit)\/fs(\/rfc)?(\/c)?\/i/, _setJini )
.get( /\/(single)\/fs(\/rfc)?(\/c)?\/i/, _setNextPrompt )
.get( /\/(edit|single)\/fs\/(?!(participant|rfc|dn|view))/, _setCompleteButton )
.get( '*', _setCloseButtonClass )
.get( `${config[ 'offline path' ]}/:enketo_id`, offlineWebform )
Expand Down Expand Up @@ -149,6 +150,12 @@ function _setJini( req, res, next ) {
next();
}

function _setNextPrompt( req, res, next ) {
req.nextPrompt = req.query.next_prompt ? req.query.next_prompt : null;
next();
}


function _setCompleteButton( req, res, next ) {
req.completeButton = true;
next();
Expand Down Expand Up @@ -179,6 +186,7 @@ function fieldSubmission( req, res, next ) {
participant: req.participant,
completeButton: req.completeButton,
closeButtonIdSuffix: req.closeButtonIdSuffix,
nextPrompt: req.nextPrompt,
headless: !!req.headless
};

Expand Down
6 changes: 4 additions & 2 deletions app/views/styles/component/_common-oc.scss
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ $secondary-color: #eeeeee;
}

#finish-form,
#close-form-participant {
#close-form-participant,
#next-prompt {
visibility: hidden;
}

Expand Down Expand Up @@ -363,7 +364,8 @@ $secondary-color: #eeeeee;
#finish-form,
#submit-form,
#close-form-participant,
#validate-form {
#validate-form,
#next-prompt {
visibility: visible;
}
}
Expand Down
56 changes: 56 additions & 0 deletions app/views/styles/component/_form_footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,62 @@
&__main-controls {
margin-bottom: 0;
margin-top: 0;

.next-prompt-container {
width: 100%;
margin-bottom: 10px;
text-align: center;

input[type=checkbox] {
vertical-align: -3px;
appearance: none;
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
display: inline-block;
width: 20px;
height: 20px;
margin-right: 10px;
margin-bottom: 0;
margin-top: 0;
border-width: 3px;
border-style: solid;
border-radius: 0;
background-color: transparent;
border-color: #666666;
margin: 4px 0 0;
line-height: normal;
border-width: 1px;

&:checked {
border-color: black;
background-image: url(data:image/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20stroke%3D%27transparent%27%20fill%3D%27black%27%20width%3D%2732%27%20height%3D%2732%27%20viewBox%3D%270%200%2032%2032%27%3E%3Cpath%20d%3D%27M25.1%2012.5l-3.4-3.3-8%208-2.9-3-3.4%203.4%206.3%206.3z%27%2F%3E%3C%2Fsvg%3E);
background-size: 20px 20px;
background-position: -3px;
background-position: -1px;

&:focus {
outline: 0;
-webkit-box-shadow: 0 0 0 1px #66afe9, 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: 0 0 0 1px #66afe9, 0 0 8px rgba(102, 175, 233, 0.6);
}
}

&:focus {
outline: 0;
-webkit-box-shadow: 0 0 0 1px #66afe9, 0 0 8px rgba(102, 175, 233, 0.6);
box-shadow: 0 0 0 1px #66afe9, 0 0 8px rgba(102, 175, 233, 0.6);
}
}


span {
font-family: 'OpenSans', Arial, sans-serif;
font-weight: normal;
font-size: 16px;
margin-left: 5px;
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions app/views/surveys/component/_form-footer.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ section.form-footer
i.icon.icon-check= ' '
span(data-i18n='formfooter.validate.btn')= t('formfooter.validate.btn')
else if type === 'fieldsubmission' || type === 'view'
if nextPrompt && completeButton
.next-prompt-container#next-prompt
input( type='checkbox' name='next-prompt' )
span #{nextPrompt}
button(id=`close-form-${closeButtonIdSuffix}`, class=`btn ${completeButton ? 'btn-default' : 'btn-primary'}`, data-i18n='alert.default.button')= t('alert.default.button')
if completeButton
button#finish-form.btn.btn-primary
Expand Down
4 changes: 3 additions & 1 deletion public/js/src/module/controller-webform.js
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,12 @@ function inIframe() {
* @param {Event} event - event
*/
function postEventAsMessageToParentWindow( event ) {
const nextPrompt = document.querySelector( 'input[name=next-prompt]' );
if ( event && event.type ) {
try {
window.parent.postMessage( JSON.stringify( {
enketoEvent: event.type
enketoEvent: event.type,
nextForm: nextPrompt && nextPrompt.checked ? true : false
} ), settings.parentWindowOrigin );
} catch ( error ) {
console.error( error );
Expand Down
2 changes: 2 additions & 0 deletions tutorials/oc-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Returns a URL that points to a regular fieldsubmission view to collect a new rec
- Has a **required** `ecid` parameter with string value.
- Has an optional `pid` parameter.
- Has an optional `jini` parameter with string value `"true"` or `"false"`. Defaults to `"false"`. Only works if jini was configured in config.json.
- Has an optional `next_prompt` parameter that will add a tickbox with the `next_prompt` value (URL-decoded) above close button (on last page only).

Otherwise, use exactly as [POST /survey/single/iframe](https://apidocs.enketo.org/v2#/post-survey-single-iframe)

Expand All @@ -51,6 +52,7 @@ Returns a URL that points to a regular fieldsubmission view to collect a new rec
- Has a **required** `ecid` parameter with string value.
- Has an optional `pid` parameter.
- Has an optional `jini` parameter with string value `"true"` or `"false"`. Defaults to `"false"`. Only works if jini was configured in config.json.
- Has an optional `next_prompt` parameter that will add a tickbox with the `next_prompt` value (URL-decoded) above close button (on last page only).

Otherwise, use exactly as POST /survey/collect.

Expand Down