Soooo, I’ve pretty much gotten MyNotes to a usable point in it’s development phase and am ready to start talking about it (and Ubiquity). It’s pretty difficult to figure out where to start. Well, let’s go with a brief description of ubiquity.
The best way I can think of to describe Ubiquity is, for all you Mac users, like Quicksilver for Firefox. A command line interface to control several different aspects of the web. A good video can be seen here.
Now, on to MyNotes.
I started working on MyNotes because the core of the MyNotes application has the basics for Ubiquity command line programming. My goals included:
- User account management
- Ajax data requests
- Data storage within Ubiquity
- Command hinting
- pseudo sub-cmmands
I was able to use AJAX post-get methods in php to accomplish #’s 1 and 2.
Code Snippet below:
register: function(key,val) {
//register
var url="http://colddish.gmtaz.com/ubiquity/"+
"mynotes/notes.php";
jQuery.post(url, {op:"register",u: key, p:val},
function(data){
if(data.registerResponse == key){
if (!Application.prefs.has(key)){
Application.prefs.setValue(key, val);
Application.prefs.setValue("mynotes_user", key);
displayMessage("New account created for ""+key+"".");
}
else{
var new_key = Application.prefs.get(key);
Application.prefs.setValue("mynotes_user", key);
new_key.value = val;
displayMessage("Password set for ""+key+"".");
}
}
else
displayMessage("Username is already in use."
+" Please try again.");
}, "json");
Basically, I’m perfoming an AJAX post with jquery, passing in JSON data (username and password), and then storing that data in the application.prefs. I overcame the issue of knowing which password/username combo to use by creating a generic “mynotes” perfs key storing the active username and password.
Application.prefs.setValue("mynotes_user", key);
Then I can just get the value of the mynotes pref key to get the password associated with that account. I could try to just store JSON data as the value for the key and run a function to pull the appropriate data…but for some reason, I’m having trouble converting the value string to a JSON object.
To get this to fully function, I needed to create a php file (notes.php), which serves out the JSON data to ubiquity based on parameters posted by the AJAX call.
I would love to hear your thoughts on how to optimize this script as I’m just starting to teach myself javascript and jquery, coming from an asp .net environment.
Here is a link to the script page for MyNotes