emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jeff Kowalski <jeff.kowalski@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Add TODO from external app?
Date: Wed, 2 Apr 2014 03:07:40 +0000 (UTC)	[thread overview]
Message-ID: <loom.20140402T045853-8@post.gmane.org> (raw)
In-Reply-To: CAFAhFSVJyTieu5m0kFShOmQa=7LTSpkbvFrPW9hfYaPghob+9A@mail.gmail.com

I use org-etml to serve pages from within emacs and use a custom capture 
handler, like this:

####
(defun jeff/capture-handler (request)
  "Handle REQUEST objects meant for 'org-capture'.
GET header should contain a path in form '/capture/KEY/LINK/TITLE/BODY'."
  (with-slots (process headers) request
    (let ((path (cdr (assoc :GET headers))))
      (if (string-match "/capture:?/\\(.*\\)" path)
          (progn
            (org-protocol-capture (match-string 1 path))
            (ws-response-header process 200))
        (ws-send-404 process)))))

(setq jeff/org-ehtml-handler
  '(((:GET  . "/capture") . jeff/capture-handler)
    ((:GET  . ".*") . org-ehtml-file-handler)
    ((:POST . ".*") . org-ehtml-edit-handler)))

(when t
  (mapc (lambda (server)
          (if (= 3333 (port server))
              (ws-stop server)))
        ws-servers)
  (ws-start jeff/org-ehtml-handler 3333))
####

And the relevant org-capture looks like

####
("b" "entry.html" entry (file+headline (concat org-directory "toodledo.org") 
"TASKS")
               "* TODO [#C] %:description\nSCHEDULED: %t\n%:initial\n"
               :immediate-finish t)

####

Then, I post from a hosted form served as entry.html via org-ehtml, like 
this:

###
<!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<head>
<title>Org Entry</title>
</head>
<html>

  <style>
    input[type=text] {
    -webkit-appearance: none; -moz-appearance: none;
    display: block;
    margin: 0;
    width: 100%; height: 40px;
    line-height: 40px; font-size: 17px;
    border: 1px solid #bbb;
    }
    input[type=submit],select {
    -webkit-appearance: none; -moz-appearance: none;
    display: block;
    margin: 0;
    height: 40px;
    line-height: 40px; font-size: 17px;
    border: 1px solid #bbb;
    }
  </style>

  <script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

  <form id="target" action="/capture/b">
    <input id="title" width="100%" type="text" name="title" />
    <br>
    <select id="context" name="context">
      <option value="@agendas">@agendas</option>
      <option value="@calls"  >@calls  </option>
      <option value="@errands">@errands</option>
      <option value="@home"   >@home   </option>
      <option value="@quicken">@quicken</option>
      <option value="@view"   >@view   </option>
      <option value="@waiting">@waiting</option>
      <option value="@work"   >@work   </option>
    </select>
    <br>
    <input type="submit" value="Submit" name="submit">
  </form>
  <span></span>

  <script type="text/javascript">
    $("#target").submit (function (event) {
        event.preventDefault();

        var link  = encodeURIComponent("LINK");
        var title = encodeURIComponent($("#title").val() + "  :" + 
$("#context").val() + ":");
        var body  = encodeURIComponent("");
        var xurl   = "/capture/b" + "/" + link + "/" + title + "/" + body;

        $.ajax({
            url: xurl
        }).success(function() {
            $("span").text("captured "+xurl).show().fadeOut(1000);
            $("#title").val("");
            $("#context").val("@agendas");
        }).fail(function(jqXHR, textStatus) {
            $("span").text("failed " + xurl + "<br>" + textStatus).show(); 
//.fadeOut(1000);
        });
    });
  </script>

</html>
####


Forwarding ports from my machine running org-ehtml on emacs means I can 
access the page anywhere to add new tasks even from my cell phone.

You could easily call this emacs-webservice from a PHP page, but it's just 
as easy to simply serve the page from emacs itself.  Take a look at org-
ehtml and the companion webserver that Schulte wrote.

  parent reply	other threads:[~2014-04-03 13:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-01 15:41 Add TODO from external app? Lawrence Bottorff
2014-04-01 17:08 ` Anthony Lander
2014-04-02  3:07 ` Jeff Kowalski [this message]
2014-04-16 16:31 ` Bastien
2014-04-16 18:15   ` Tim Visher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20140402T045853-8@post.gmane.org \
    --to=jeff.kowalski@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).