comparison js/modules/app.js @ 89:ee0a4597c067

Added a really basic error log that gets populated when the wrong username/pass is entered. Also, the username/password prompt for login now emphasizes the fact that it is a bugzilla login.
author Atul Varma <avarma@mozilla.com>
date Mon, 26 Apr 2010 17:45:02 -0700
parents 03bf0a1b85da
children d48599d7a9ae
comparison
equal deleted inserted replaced
88:392fd25a6e21 89:ee0a4597c067
52 52
53 callbacks.forEach(function(cb) { cb(info); }); 53 callbacks.forEach(function(cb) { cb(info); });
54 }; 54 };
55 }; 55 };
56 56
57 Require.modules["errors"] = function(exports, require) {
58 var $ = require("jQuery");
59
60 var errors = $("#errors");
61 var messages = $("#templates .errors");
62 var lastError = null;
63
64 exports.log = function log(name) {
65 var message = messages.find("." + name);
66 if (!message.length) {
67 exports.log("unknown-error");
68 return;
69 }
70 if (lastError == message.get(0))
71 return;
72 lastError = message.get(0);
73
74 message = message.clone();
75 errors.append(message);
76 if (errors.children().length == 1)
77 errors.fadeIn();
78 else
79 message.fadeIn();
80 };
81 };
82
57 Require.modules["app/bugzilla-auth"] = function(exports, require) { 83 Require.modules["app/bugzilla-auth"] = function(exports, require) {
84 function onLoad(event) {
85 var xhr = event.target;
86 console.log("load", xhr);
87 }
88
89 function onError(event) {
90 var xhr = event.target;
91 require("errors").log("bugzilla-api-error");
92 }
93
58 exports.create = function(Bugzilla) { 94 exports.create = function(Bugzilla) {
59 function AuthenticatedBugzilla() { 95 function AuthenticatedBugzilla() {
60 this.ajax = function ajax(options) { 96 this.ajax = function ajax(options) {
61 var user = require("app/login").get(); 97 var user = require("app/login").get();
62 98
65 options.data = {}; 101 options.data = {};
66 options.data.username = user.username; 102 options.data.username = user.username;
67 options.data.password = user.password; 103 options.data.password = user.password;
68 } 104 }
69 105
70 return Bugzilla.ajax.call(this, options); 106 var xhr = Bugzilla.ajax.call(this, options);
107
108 xhr.addEventListener("load", onLoad, false);
109 xhr.addEventListener("error", onError, false);
110
111 return xhr;
71 }; 112 };
72 } 113 }
73 114
74 AuthenticatedBugzilla.prototype = Bugzilla; 115 AuthenticatedBugzilla.prototype = Bugzilla;
75 116