[Anouncement] I am back

Misc October 31st, 2007

I joined Microsoft Canada Develop Center recently. And according to the contract, Microsoft is solely, exclusively intellectual property owner of Employee Work. I just contacted with LCA team of Microsoft and clarify the ownership of contribution to dojox.gfx, PyAWS and this blog.

I received the reply yesterday, as long as I don’t use any resource of Microsoft, including the device, network connection and the topic does not conflicts with Microsoft’s interest, it is totally OK to keep programming for the open source community and blogging as my will.

So I am back.

Learning Django by Example(8): To DnD or Not to DnD

Web October 23rd, 2007

This is really a dilemma, it is quite painful to drop such a cool feature, but after carefully consideration, I decided to take the move for the sake of simplicity:

Using steps


Using navigation



Now the users can either upload the file locally or select the file in the incoming director remotely(N/A); use Prev | Next to navigate, click the image to select the meta data, add tags by clicking(N/A). I consider that click need less effort for user to operate than DnD. And the Step statements directs the users but not enforce the order like wizard does.

It may be worthy to wrap the file browser as a dojo dijit, and that is also a good candidate for comet. The server may register handlers for file system events(check System.IO.FileSystemWatcher, inotify in Linux) , then push the status change to the client. That is quite a little work, so I would rather leave the placeholder here and implement some other features first.

This is r41, the save functionality is still broken, I would squeeze time to fix it ASAP.

Learning Django by Example(7): Act like a desktop application: Dnd

Web October 6th, 2007

After some tests, I found the add-by-search has a big design flaw, I took the wrong direction: the focus of eBook management ultimately is the file, not the meta data. Current implementation is too meta-data centric, it adds the complexity since all dynamic features are created dynamically, and it looks like a little desperate to put so many controls in one page.

So in r37, a brand new UI is developed inspired by WordPress’s dashboard.

Dnd Overview



The user may drag the thumbnail from the search result and drop it in the left dropbox, attach a local file, then click Save, done. Here is another screen shot of drag-n-drop in action:

Dnd in action


Unlike the canonical Dnd example, our dropbox only accept no more than one item at any time, the newly added item would replace the old one. So we need to subscribe the /dnd/drop event:

dojo.subscribe("/dnd/drop", function(source, nodes, iscopy) {
        var t = dojo.dnd.manager().target;
        if(t == dropbox) {
            t.selectAll();
            t.deleteSelectedNodes();
            t.clearItems();
        }
        var jsnode = source.getItem(nodes[0].id);
        t.insertNodes(false, [jsnode.data]);

    });

The first action is to remove all the items, then we extract the data, and reconstruct the nodes by calling insertNodes. The rest part is quite the same.

An advanced version is in the blueprint: how about a file manager on FTP’s incoming directory? But I am lazy to copy-n-paste the code, I would rather grill myself to figure it out how to put the two options in one page more intuitively. If you have any suggestion or mock up, please just drop you comment here. Thanks.

Learning Django by Example(6): AJAX File Upload

Python, Web October 4th, 2007

In the last post, I just added the entities in the database, but did not bind the meta data with eBook files. This post will demonstrate how to upload the file in AJAX flavor:

The idea is inspired by this tutorial , using dojo.io.iframe, we could submit a form with file upload asynchronously. In client side, a hidden field meta is added to store the marshaled JSON string. dojo.io.iframe.send shares the same defer concept as dojo.xhrPost:

var meta = dojo.query("input[@name=meta]", form)[0];
    meta.value = dojo.toJson(cache[i]);

    // submit the form
    dojo.io.iframe.send({
        url: form.action,
        method: "post",
        handleAs: "json",
        form: form,
    }).addCallback(function(ret) {
    … …

NOTE: the handleAs is json, so the argument ret is JavaScript object.

In server side, the JSON string needs to be wrapped by textarea, this is the hard requirement of dojo.iframe.send.

return HttpResponse("<textarea>%s</textarea>" % simplejson.dumps(retset) , mimetype=‘text/html’);

Conceptually, add-by-search will issue INSERT operation to the database, the result may fall in the following categories:

  • Success
  • FileAlreadyExist: the eBook file exists, so the uploaded file is discarded
  • UnexpectedError: an 500 error happens in server side for unknown reason.

Check r34 for the implementation.

Proud to be a Dojo committer

Web October 3rd, 2007

After the development of dojox.gfx and dojox.gfx3d, and continuous efforts on dojox.charting, I was granted the commit privilege eventually. This is quite a honor to acknowledge the contribution and it is an approval from the community of my Web development skills.

Hmm, still a long way to go anyway.