forro

Forro is a end-to-end encrypted contract form based on PGP.
git clone git://git.defalsify.org/forro.git
Info | Log | Files | Refs | README | LICENSE

help.js (2268B)


      1 const HELPSTATE = {
      2 	INTRO: 1 << 1,
      3 	WRITEMSG: 1 << 2,
      4 };
      5 
      6 function checkHelpSkip(helpstate, content, skip_state) {
      7 	let r = {
      8 		state: helpstate,
      9 		content: [],
     10 	};
     11 	if (!skip_state) {
     12 		skip_state = 0;
     13 	}
     14 	if ((helpstate & skip_state) > 0) {
     15 		return r;
     16 	}
     17 	r.state |= skip_state;
     18 	r.content = content;
     19 	return r;
     20 }
     21 
     22 function help_welcome(helpstate) {
     23 	const content = [
     24 		"This is an encrypted contact form.",
     25 		"A secret key is needed to read messages you send here.",
     26 	];
     27 	return checkHelpSkip(helpstate, content, HELPSTATE.INTRO);
     28 }
     29 
     30 function help_writemsg(helpstate) {
     31 	const content = [
     32 		"The contents of the message will be signed by you and encrypted for the recipient before it is sent.",
     33 		"Once it is sent, a link to where the message is stored will appear in the 'receipt' field above.",
     34 		"The message cannot be read by anyone but the recipient. <em>That includes you, too</em>. If you want a copy, then make one manually",
     35 	];
     36 	//return checkHelpSkip(helpstate, content, HELPSTATE.WRITEMSG);
     37 	return checkHelpSkip(helpstate, content);
     38 }
     39 
     40 function help_identify(helpstate) {
     41 	const content = [
     42 		"Identifying yourself means that the name and email you give will be added to your signature key.",
     43 		"You may write any name and email you want.",
     44 		"Any identifying information will be encrypted, and cannot be read by anyone except the recipient.",
     45 	];
     46 	return checkHelpSkip(helpstate, content);
     47 }
     48 
     49 
     50 async function helpFor(helpstate, state, k) {
     51 	let help = []
     52 
     53 	let fn = window['help_' + k];
     54 	if (fn === undefined) {
     55 		console.warn("no help found for '" + k + "'");
     56 	} else {
     57 		let r = fn.call(null, helpstate);
     58 		helpstate = r.state;
     59 		while (r.content.length > 0) {
     60 			help.push(r.content.shift());
     61 		}
     62 	}
     63 
     64 	if (state > 0) {
     65 		let state_cpy = state;
     66 		let i = 0;
     67 		while (state_cpy > 0) {
     68 			if ((state_cpy & 1) == 1) {
     69 				let sk = STATE_KEYS[i]	
     70 				fn = window['help_' + k + '_' + sk.toLowerCase() ];
     71 				if (fn !== undefined) {
     72 					console.debug('supplemental help found for ' + k + " with state " + sk);
     73 					let r = fn.call(null, helpstate);
     74 					helpstate = r.state;
     75 					while (r.content.length > 0) {
     76 						help.push(r.content.shift());
     77 					}
     78 				}
     79 			}
     80 			i += 1;
     81 			state_cpy >>= 1;
     82 		}
     83 	}
     84 
     85 	return {
     86 		state: helpstate,
     87 		v: help,
     88 	};
     89 }