trotter (owner)

Revisions

gist: 9056 Download_button fork
public
Public Clone URL: git://gist.github.com/9056.git
Embed All Files: show embed
mbox-commands.ubiquity-command.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
CmdUtils.CreateCommand({
    name: "mbox-login",
    homepage: "http://www.motionbox.com",
    author: {name: "Trotter Cashion", email: "trotter.cashion@motionbox.com"},
    license: "MIT",
    description: "Quick and easy login to motionbox",
    help: "Will log you into Motionbox and open a new tab with your profile page",
    
    takes: {login: noun_arb_text},
    modifiers: {"/": noun_arb_text, host: noun_arb_text},
    
    _host: function(host) {
       return host || "www.motionbox.com";
    },
 
    _login_url: function(host) {
        return "http://" + this._host(host) + "/user/login";
    },
 
    preview: function(pblock, login, mods) {
        var template = "Login to ${url} using ${login} / ${password}";
        var subs = {url: this._login_url(mods.host.text), login: login.text, password: mods["/"].text};
        pblock.innerHTML = CmdUtils.renderTemplate(template, subs);
    },
 
    execute: function(login, mods) {
        var url = this._login_url(mods.host.text);
        var params = {"user[login]": login.text, "user[password]": mods["/"].text};
        var redirect_url = "http://" + this._host(mods.host.text);
        jQuery.post(url, params, function(response) {
            Utils.openUrlInBrowser(redirect_url);
        });
    }
});