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",
44 .addClass("glyphicon glyphicon-off")
45 //.click($.proxy(this.toggle, this))
47 "data-container": "body",
48 "data-toggle": "popover",
49 "data-placement": "bottom",
50 "data-content": "bottom",
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 .addClass("form-group")
140 .attr("for", "nitdoc-github-login-field")
141 .append(this.options
.usernameTxt
)
143 .addClass("form-group")
147 id
: "nitdoc-github-login-field",
149 "class": "form-control"
155 .addClass("form-group")
158 .attr("for", "nitdoc-github-password-field")
159 .append(this.options
.passwordTxt
)
164 id
: "nitdoc-github-password-field",
166 "class": "form-control"
172 .addClass("form-group")
175 .attr("for", "nitdoc-github-repo-field")
176 .append(this.options
.repoTxt
)
181 id
: "nitdoc-github-repo-field",
183 "class": "form-control"
189 .addClass("form-group")
192 .attr("for", "nitdoc-github-branch-field")
193 .append(this.options
.branchTxt
)
198 id
: "nitdoc-github-branch-field",
200 "class": "form-control"
206 .addClass("nitdoc-github-button btn btn-primary btn-lg pull-right")
207 .attr("disabled", "disabled")
210 .attr("src", this.options
.icon
)
211 ).text(this.options
.signinTxt
)
212 .click($
.proxy(this._doClickLogin
, this))
215 $
(".nitdoc-github-li-img").attr("src", this.options
.icon
);
219 if(this.loginBox
.is(':hidden')) {
220 this.loginBox
.show();
221 if ($
('#nitdoc-github-login-field').is(':visible')) { $
('#nitdoc-github-login-field').focus(); }
223 this.loginBox
.hide();
229 _doClickLogoff
: function(event
) {
230 this._trigger("_logoff", event
);
233 _doClickLogin
: function(event
) {
234 this._trigger("_login", event
, {
235 login
: $
('#nitdoc-github-login-field').val(),
236 password
: $
('#nitdoc-github-password-field').val(),
237 repo
: $
('#nitdoc-github-repo-field').val(),
238 branch
: $
('#nitdoc-github-branch-field').val()
243 _doFormChange
: function(event
) {
244 login
= $
('#nitdoc-github-login-field').val();
245 password
= $
('#nitdoc-github-password-field').val();
246 repo
= $
('#nitdoc-github-repo-field').val();
247 branch
= $
('#nitdoc-github-branch-field').val();
248 if(login
&& password
&& repo
&& branch
) {
249 this.loginBox
.find("form .nitdoc-github-button").removeAttr("disabled");
251 this.loginBox
.find("form .nitdoc-github-button").attr("disabled", "disabled");