CmdUtils.CreateCommand({ 
  name: "deadline-add",
  icon: "http://deadlineapp.com/favicon.ico",
  homepage: "http://deadlineapp.com/",
  author: { name: "Alex Young", email: "alex@helicoid.net"},
  license: "GPL",
  description: "Add an event to Deadline",
  help: "Type in some text containing a date.  You must be signed in to Deadline for this command to work.  This plugin requires you to check 'Accept third-party plugins' in Firefox Preferences, Privacy to work.",
  takes: {"deadline": noun_arb_text},
  preview: function(pblock, input) {
    var baseUrl = "http://deadlineapp.com/deadlines";
    jQuery.get(baseUrl, {}, function(data, status) {
      if (status != 'success') {
        pblock.innerHTML = "You must login to Deadline to use this command";
      } else {
        pblock.innerHTML = "Type in a Deadline and press return to add it";
      }
    })
  },
  execute: function(input) {
    jQuery.ajax({
      type: 'POST',
      url: "http://deadlineapp.com/deadlines",
      data: 'deadline[description]=' + input.text,
      dataType: 'json',
      success: function(data, status) {
        if (status == 'success') {
          displayMessage('Deadline added');
        } else {
          displayMessage('Deadline could not be addeed');
        }
      }
    })
  }
});

CmdUtils.CreateCommand({ 
  name: "deadline-search",
  icon: "http://deadlineapp.com/favicon.ico",
  homepage: "http://deadlineapp.com/",
  author: { name: "Alex Young", email: "alex@helicoid.net"},
  license: "GPL",
  description: "Search Deadline",
  help: "Search your deadlines.  You must be signed in to Deadline for this command to work.  This plugin requires you to check 'Accept third-party plugins' in Firefox Preferences, Privacy to work.",
  takes: {"deadline": noun_arb_text},
  preview: function(pblock, input) {
    jQuery.ajax({
      type: 'POST',
      url: "http://deadlineapp.com/deadlines/search",
      data: 'deadline[search]=' + input.text,
      dataType: 'json',
      success: function(data, status) {
        if (status != 'success') {
          pblock.innerHTML = "You must login to Deadline to use this command";
        } else {
          pblock.innerHTML = '<style>.deadlines .deadline .date_container { padding-right: 1em }</style><div style="width: 100%" id="deadlines_container">' + data + '</div>'
        }
      }
    })
  },
  execute: function(input) {
  }
});