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.
15 Documentation generator for the nit language.
16 Generate API documentation in HTML format from nit source code.
22 "plugins/github/modalbox",
23 ], function($
, UI
, ModalBox
) {
25 init
: function(containerSelector
) {
26 this.loginBoxLi
= $
(document
.createElement("li"))
27 .attr("id", "nitdoc-github-li")
29 $
(document
.createElement("a"))
31 $
(document
.createElement("img"))
33 src
: "resources/icons/github-icon.png",
36 .addClass("nitdoc-github-li-img")
38 .click(function() { LoginBox
.toggle() })
41 this.loginBoxContent
= $
(document
.createElement("div"));
42 this.loginBox
= $
(document
.createElement("div"))
43 .attr("id", "nitdoc-github-loginbox")
44 .css("display", "none")
46 $
(document
.createElement("div"))
47 .addClass("nitdoc-github-loginbox-arrow")
51 $
(document
.createElement("h3"))
52 .append("Github Sign In")
54 .append(this.loginBoxContent
);
56 this.loginBoxLi
.append(this.loginBox
);
57 $
(containerSelector
).append(this.loginBoxLi
);
60 // Panel of login box to display when the user is logged in
61 displayLogout
: function(origin
, user
) {
62 var panel
= $
(document
.createElement("div"))
64 $
(document
.createElement("h4"))
67 $
(document
.createElement("a"))
68 .attr("href", "https://github.com/" + user
.login
)
73 $
(document
.createElement("label"))
74 .attr("for", "github-origin")
78 $
(document
.createElement("input"))
83 value
: origin
.user
+ ":" + origin
.repo
+ ":" + origin
.branch
87 $
(document
.createElement("label"))
88 .attr("for", "github-base")
92 $
(document
.createElement("input"))
97 value
: user
.login
+ ":" + user
.repo
+ ":" + user
.branch
101 $
(document
.createElement("button"))
102 .addClass("nitdoc-github-button")
103 .addClass("nitdoc-github-cancel")
105 $
(document
.createElement("img"))
106 .attr("src", "resources/icons/github-icon.png")
108 .click(function() { // log out user
113 $
(".nitdoc-github-li-img").attr("src", "resources/icons/github-icon-green.png");
114 this.loginBoxContent
.empty()
115 this.loginBoxContent
.append(panel
);
118 // Panel of login box to display when the user is logged out
119 displayLogin
: function() {
120 var panel
= $
(document
.createElement("form"))
122 $
(document
.createElement("label"))
123 .attr("for", "nitdoc-github-login-field")
127 $
(document
.createElement("input"))
129 id
: "nitdoc-github-login-field",
134 $
(document
.createElement("label"))
135 .attr("for", "nitdoc-github-password-field")
139 $
(document
.createElement("input"))
141 id
: "nitdoc-github-password-field",
146 $
(document
.createElement("label"))
147 .attr("for", "nitdoc-github-repo-field")
148 .append("Repository")
151 $
(document
.createElement("input"))
153 id
: "nitdoc-github-repo-field",
158 $
(document
.createElement("label"))
159 .attr("for", "nitdoc-github-branch-field")
163 $
(document
.createElement("input"))
165 id
: "nitdoc-github-branch-field",
170 $
(document
.createElement("button"))
171 .addClass("nitdoc-github-button")
173 $
(document
.createElement("img"))
174 .attr("src", "resources/icons/github-icon.png")
177 var login
= $
('#nitdoc-github-login-field').val();
178 var password
= $
('#nitdoc-github-password-field').val();
179 var repo
= $
('#nitdoc-github-repo-field').val();
180 var branch
= $
('#nitdoc-github-branch-field').val();
181 if(!login ||
!password ||
!repo ||
!branch
) {
182 ModalBox
.open("Sign in error", "Please enter your GitHub username, password, repository and branch.", true);
184 var user
= UI
.tryLogin(login
, password
, repo
, branch
);
185 if(user
== "error:login") {
186 ModalBox
.open("Sign in error", "The username, password, repo or branch you entered is incorrect.", true);
187 } else if(user
== "error:sha") {
188 ModalBox
.open("Base commit not found", "The provided GitHub repository must contains the base commit '" + UI
.origin
.sha
+ "'", true);
189 } else if(user
== "error:profile") {
190 ModalBox
.open("Incomplete GitHub profile", "Please set your public name and email in your <a href='https://github.com/settings/profile'>GitHub profile</a>.<br/><br/>Your public profile informations are used to sign-off your commits.", true);
193 LoginBox
.displayLogout(UI
.origin
, user
);
199 $
(".nitdoc-github-li-img").attr("src", "resources/icons/github-icon.png");
200 this.loginBoxContent
.empty()
201 this.loginBoxContent
.append(panel
);
205 if(this.loginBox
.is(':hidden')) {
206 this.loginBox
.show();
207 if (!$
('#loginGit').is(':hidden')) { $
('#loginGit').focus(); }
209 this.loginBox
.hide();