Action

TEST: wizard - checklist

Posted by felix@42sol.eu, Last update about 2 months ago - Unlisted

Use the opened draft to start a review or checking process and deliver it as a JSON object

(Proof of concept)

Steps

  • script

     
    
    function prompt_item(p_title, p_id, p_task, p_data) {
      var r_data = p_data;
    
      var p = Prompt.create();
      p.isCancellable = false;
    
      p.title = p_title + "_" + p_id;
      p.message = p_task.replace(/-\s+\[[ xo\-]\]\s+/i, "");
    
      p.addTextView("comment", "comment", "",{ "height": 25});
    
      p.addButton("Yes");
      p.addButton("No");
    
      var did_select = p.show();
      var comment = p.fieldValues["comment"];
      var selection = "Cancel";
      if(did_select) 
      {
        selection = p.buttonPressed;
      }
      
      
      r_data["#"+p_id] = {
              "question": p_task,
              "answer": selection,
              "comment": comment,
              "topic": p_title};
              
      return r_data;
    }
    
    function alert_json( p_json ) {
      alert(JSON.stringify(p_json));
      return p_json["answer"];
    }
    
  • script

    
    function process(p_input) {
    var r_data = p_input;
    var lines = draft.content.split("\n");
    var test = true;
    
    var topic = "";
    var count_question = 1;
    
    for( line of lines ) {
    
      if(line.match(/#+\s+/g) != null) 
      {
        topic = line.split(" ")[1];
        count_question = 1;
      }
      else if(topic != "" && line.match(/-\s\[\s\]\s/g) != null)
      {
        r_data = prompt_item(topic, count_question, line, r_data);
           count_question += 1;
      }
      else
      {
        //alert(line);
      }
      
     
    }//for
    
      alert_json(r_data);
      return r_data;
    }//function
    
  • script

    let data = process({})
    
    app.setClipboard(JSON.stringify(data));

Options

  • After Success Nothing
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.