1 /* This file is part of NIT ( http://www.nitlanguage.org ).
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
17 * LoginBox allows user to login and logoff from GitHub API
23 $
.widget("nitdoc.loginbox", {
25 icon
: "resources/icons/github-icon.png",
26 iconActive
: "resources/icons/github-icon-green.png",
28 signedinTxt
: "Signed in Github",
29 signedoutTxt
: "Sign in Github",
31 upstreamTxt
: "Upstream branch",
33 signoffTxt
: "Sign Off",
34 usernameTxt
: "Username",
35 passwordTxt
: "Password",
36 repoTxt
: "Repository",
47 src
: this.options
.icon
,
48 alt
: this.options
.iconAlt
50 .addClass("nitdoc-github-li-img")
52 .click($
.proxy(this.toggle
, this))
55 this.content
= $
("<div/>");
56 this.loginBox
= $
("<div/>")
57 .attr("id", "nitdoc-github-loginbox")
58 .css("display", "none")
60 $
(document
.createElement("div"))
61 .addClass("nitdoc-github-loginbox-arrow")
64 .append(this.content
);
65 this.element
.append(this.loginBox
);
70 displayLogout
: function(origin
, user
) {
73 $
("<h3/>").text(this.options
.signedinTxt
)
79 .append(this.options
.welcomeTxt
+ " ")
82 .attr("href", "https://github.com/" + user
.login
)
88 .text("Upstream Branch")
92 .text(origin
.user
+ ":" + origin
.repo
+ ":" + origin
.branch
)
93 .addClass("nitdoc-github-loginbox-githublink")
95 title
: "Open branch in GitHub",
96 href
: "https://github.com/" + origin
.user
+ "/" + origin
.repo
+ "/tree/" + origin
.branch
101 .attr("for", "github-base")
102 .append("Your branch")
106 .text(user
.login
+ ":" + user
.repo
+ ":" + user
.branch
)
107 .addClass("nitdoc-github-loginbox-githublink")
109 title
: "Open branch in GitHub",
110 href
: "https://github.com/" + user
.login
+ "/" + user
.repo
+ "/tree/" + user
.branch
115 .addClass("nitdoc-github-button")
116 .addClass("nitdoc-github-cancel")
119 .attr("src", this.options
.icon
)
120 ).text(this.options
.signoffTxt
)
121 .click($
.proxy(this._doClickLogoff
, this))
124 $
(".nitdoc-github-li-img").attr("src", this.options
.iconActive
);
127 displayLogin
: function() {
128 this.content
.empty();
130 $
("<h3/>").text(this.options
.signedoutTxt
)
134 .keyup($
.proxy(this._doFormChange
, this))
137 .attr("for", "nitdoc-github-login-field")
138 .append(this.options
.usernameTxt
)
143 id
: "nitdoc-github-login-field",
149 .attr("for", "nitdoc-github-password-field")
150 .append(this.options
.passwordTxt
)
155 id
: "nitdoc-github-password-field",
161 .attr("for", "nitdoc-github-repo-field")
162 .append(this.options
.repoTxt
)
167 id
: "nitdoc-github-repo-field",
173 .attr("for", "nitdoc-github-branch-field")
174 .append(this.options
.branchTxt
)
179 id
: "nitdoc-github-branch-field",
185 .addClass("nitdoc-github-button")
186 .attr("disabled", "disabled")
189 .attr("src", this.options
.icon
)
190 ).text(this.options
.signinTxt
)
191 .click($
.proxy(this._doClickLogin
, this))
194 $
(".nitdoc-github-li-img").attr("src", this.options
.icon
);
198 if(this.loginBox
.is(':hidden')) {
199 this.loginBox
.show();
200 if ($
('#nitdoc-github-login-field').is(':visible')) { $
('#nitdoc-github-login-field').focus(); }
202 this.loginBox
.hide();
208 _doClickLogoff
: function(event
) {
209 this._trigger("_logoff", event
);
212 _doClickLogin
: function(event
) {
213 this._trigger("_login", event
, {
214 login
: $
('#nitdoc-github-login-field').val(),
215 password
: $
('#nitdoc-github-password-field').val(),
216 repo
: $
('#nitdoc-github-repo-field').val(),
217 branch
: $
('#nitdoc-github-branch-field').val()
222 _doFormChange
: function(event
) {
223 login
= $
('#nitdoc-github-login-field').val();
224 password
= $
('#nitdoc-github-password-field').val();
225 repo
= $
('#nitdoc-github-repo-field').val();
226 branch
= $
('#nitdoc-github-branch-field').val();
227 if(login
&& password
&& repo
&& branch
) {
228 this.loginBox
.find("form .nitdoc-github-button").removeAttr("disabled");
230 this.loginBox
.find("form .nitdoc-github-button").attr("disabled", "disabled");