Skip to content

Notes on legal server integration

Quinten Steenhuis edited this page Oct 31, 2018 · 2 revisions

new e-sign script:

function esignFixValue(valueText){
  var theValue;
  valueText = valueText.replace(/<br ?\/?>/g, "\n").replace(/\<[^\>]+\>/g, '').replace(/(^ +| +$)/g, '').replace(/  +/g, ' ').replace(/ ?\[Edit\]/g, '').replace(/ *\n+ */g, ", ");
  if (valueText == 'Yes')
    theValue = true;
  else if (valueText == 'No')
    theValue = false;
  else if (valueText == 'N/A' || valueText == '')
    theValue = null;
  else
    theValue = valueText;
  return theValue;
}
function esignGetURL(event){
  var args = { id: jQuery("header.Main ul li h2").html().replace(/^.*\(/, '').replace(/\)$/, ''),
	       name: jQuery("header.Main hgroup h1").html(),
	       initiating_user: jQuery("li.user a strong").html(),
	       initiating_user_email_address: jQuery('input[name="bug_sender_email"]').val(),
	       sidebar_domestic_violence: null,
	       sidebar_unsafe_address: null
	     };
  jQuery("#sidebar table tr").each(function(){
    if (jQuery(this).find("td").length > 0){
      var labelText = 'sidebar_' + jQuery(this).find("th").text().toLowerCase().replace(/[^a-z]+/g, '_').replace(/(^_|_$)/g, '');
      if (labelText == 'sidebar_' && jQuery(this).find("th").next().length){
	var theMessage = jQuery(this).find("th").next().html();
	if (theMessage == 'Address Not Safe'){
	  args['sidebar_unsafe_address'] = true;
	}
      }
      if (labelText != 'sidebar_'){
	var valueText = jQuery(this).find("th").next().html();
	if (labelText == 'sidebar_disposition_case_status_date_open'){
	  var theVals = esignFixValue(valueText).split(", ");
	  args['sidebar_disposition'] = theVals[0];
	  args['sidebar_case_status'] = theVals[1];
	  args['sidebar_date_open'] = theVals[2];
	}
	else{
	  args[labelText] = esignFixValue(valueText);
	}
      }
    }
    else{
      var valueText = jQuery(this).find("th").text();
      if (valueText.indexOf('@') > -1){
	args['case_email'] = valueText;
      }
    }
  });
  jQuery("td.form_label label").each(function(){ 
    if (jQuery(this).attr('for')){
      var elem = document.getElementById(jQuery(this).attr('for'));
      if (elem.tagName != 'SELECT' && elem.tagName != 'INPUT'){
	var labelText = jQuery(this).text().toLowerCase().replace(/[^a-z]+/g, '_').replace(/(^_|_$)/g, '');
	var valueText = jQuery(elem).html();//.replace(/ *\[Edit\]/, '');
	args[labelText] = esignFixValue(valueText);
      }
    }
  });
  if (args['address']){
    if (args['address'].startsWith("(Safe)")){
      args['safe_address'] = true;
    }
    else if (args['address'].startsWith("(Not Safe)")){
      args['safe_address'] = false;
    }
    args['address'] = args['address'].replace(/^\((Safe|Not Safe)\) */, '');
  }

Instruction block:

<a target="_blank" href="#" id="jhpLink">Click me</a>
<script type="text/javascript">
function JHPFindCaseId(){
  for(var els = document.getElementsByClassName('dropdown clearfix'), i = els.length; i--;){
    for(var child = els[i].firstChild; child != null; child = child.nextSibling){
      if (child.tagName == 'LI'){
        for(var grandchild = child.firstChild; grandchild != null; grandchild = grandchild.nextSibling){
          if (grandchild.tagName == 'H2'){
            if (grandchild.innerHTML && grandchild.innerHTML.substring(0, 7) == "Case No"){
              var regExp = /\(([^)]+)\)/;
              var matches = regExp.exec(grandchild.innerHTML);
              if (matches[1]){
                return(matches[1]);
              }
            }
          }
        }
      }
    }
  }
}

function myOnLoad(event){
  var theValues = jQuery("form.formtable").first().serializeArray();
  jQuery(".form_element_static_value").each(function(){
    theValues.push({'name': jQuery('label[for="' + jQuery(this).attr('id') + '"]').html(), 'value': jQuery(this).html()});
  });
  theValues.push({'name': 'identification_number', 'value': JHPFindCaseId()});
  jQuery("#jhpLink").attr("href", "https://demo.docassemble.org/?i=playground1%3Alstest.yml&args=" + btoa(JSON.stringify(theValues)));
}

if(window.attachEvent) {
    window.attachEvent('onload', myOnLoad);
} else {
    if(window.onload) {
        var curronload = window.onload;
        var newonload = function(evt) {
            curronload(evt);
            myOnLoad(evt);
        };
        window.onload = newonload;
    } else {
        window.onload = myOnLoad;
    }
}
</script>

Interview:

metadata:
  title: Legal Server Test
  short title: LS Test
---
modules:
  - docassemble.base.legal
---
objects:
  - client: Individual
---
include:
  - signature-questions.yml
---
mandatory: true
code: |
  multi_user = True
  user = client
  role = 'client'
---
initial: true
code: |
  update_info(user, role, current_info)
---
code: |
  welcome_screen_shown = True
  force_ask(welcome_screen)
---
sets: welcome_screen
question: |
  Welcome, ${ arguments['matter:first'] } ${ arguments['matter:last'] }
subquestion: |
  Press Continue, or resume this interview on your mobile device by
  taking a picture of this QR code.
  
  ${ interview_url_as_qr() }
buttons:
  - Continue: continue
---
code: |
  ls_args = from_b64_json(url_args.get('args', None))
  if ls_args is not None:
      arguments = dict()
      for arg in ls_args:
          arguments[arg['name']] = arg['value']
---
code: |
  client.name.first = arguments['matter:first']
  client.name.last = arguments['matter:last']
  client.ssn = arguments['matter:ssn']
  client.phone = arguments['matter:phone_home']
  organization = "Philadelphia Legal Assistance"
---
sets: all_done
question: |
  All done
subquestion: |
  Your signed agreement is below.
attachments:
  - name: "Agreement with ${ organization }"
    filename: agreement
    valid formats:
      - pdf
    metadata:
      SingleSpacing: true
    content: |
      [BOLDCENTER] Agreement between ${ user } and ${ organization }
      
      I, ${ client }, promise to be good.
      
      ${ client.signature.show(width='2in') }
      
      | Date: ${ today() }
      | SSN: ${ client.ssn }
      | Phone number: ${ client.phone }
---
yesno: client_agrees_to_sign
question: |
  Do you agree to be good?
---
sets: client_told_goodbye
question: Goodbye
subquestion: |
  We are sad that you have not agreed to be good.
buttons:
  - Exit: exit
---
mandatory: true
code: |
  need(welcome_screen_shown)
  if not client_agrees_to_sign:
    need(client_told_goodbye)
  need(all_done)
Clone this wiki locally