Content Garden

export function tabClick(event, $w) {
	//Make all children of the boxBtnGrp have the background #DBE7D1, then assign the button that was clicked background #4F7C8F
	//Change infoBox based on the first word of the button label

	let labelWord = event.target.label.replace(" ", "");
	

	$w('#boxBtnGrp').children.forEach(button => {
		$w(`#${button.id}`).style.backgroundColor = '#4F7C8F'
		$w(`#${button.id}`).style.color = '#DBE7D1'
	})

	$w(`#${event.target.id}`).style.backgroundColor = '#DBE7D1';
	$w(`#${event.target.id}`).style.color = '#4F7C8F';

	$w('#InfoBox').changeState(labelWord)

}
export function checkOff(event, type) {
	console.log('[checkOff] starting function with', event, type)
	return wixData.get(type, event.context.itemId)
	.then(lesson => {
		lesson.done = event.target.checked
		lesson.dateCompleted = new Date()
		
		wixData.update(type, lesson)
		.then(updated => {
			return updated
		}).catch(e => {console.log('could not update checked item', e)})
	}).catch(e => {console.log('Could not get checked item', e)})

}
export function documentation(event, type, lesson, sticky) {
	let $item = $w.at(event.context)
	let data = {
		type: type,
		id: event.context.itemId,
		lesson: lesson,
		sticky: sticky
	}

	console.log('[todo-helper.js documentation] data is', data)

	if (event.target.checked === true) {
		console.log('[todo-helper.js documentation] event.target.checked is true')
		wixWindow.openLightbox('Submit Activities', data)
		.then(result => {
			console.log('[todo-helper.js documentation] returning from lightbox', result)
			if (result.checkOriginal === true) {
				checkOff(event, type)
				.then(() => {
					wixLocation.to('/current-quests')
				})
				
			}
		})
	} else {
		checkOff(event, type)
	}
	
	
}
export function fieldsUpdate(group) {
    let update = {}

	console.log('fieldsUpdate group is', group.children)

		group.children.forEach(field => {
		if (field.value !== null) {
			if (field.inputType === 'number') {
				update[field.id] = Number(field.value)
			} else if (field.fileType !== undefined) {
				field.value = null
			} else if(field.type === '$w.Checkbox') {
				update[field.id] = field.checked
			} else {
				update[field.id] = field.value
			}	
		}
		})

    return update
}
export function uploadHelper(field, dataset, dbField) {
	if (field.value.length > 0) {  // visitor chose a file
      console.log("[uploadHelper] Uploading " + field.value[0].name + "- Please wait.");
      field.startUpload()
        .then( (uploadedFile) => {
          console.log("[uploadHelper] Upload successful. File is available here:");
          console.log(uploadedFile.url);
		  console.log('[uploadHelper] Setting field value', dbField, uploadedFile.url)
		  dataset.setFieldValue(dbField, uploadedFile.url)
        } )
        .catch( (uploadError) => {
          console.log("[uploadHelper] File upload error: " + uploadError.errorCode);
          console.log(uploadError.errorDescription);
        } );
  }
  else {    // site visitor clicked button but didn't choose a file
    console.log("[uploadHelper] Please choose a file to upload.")
  }
}

Similiar Collections