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 * CommitBox allows user to add a message and sign its commit
23 $
.widget("nitdoc.commitbox", {
26 title
: "Commit changes"
30 this._fade
= this._buildFade();
31 $
("body").append(this._fade
);
32 this._commitBox
= $
("<div/>")
34 .attr("id", "nitdoc-github-commitBox")
35 .addClass("nitdoc-github-modal")
38 .addClass("nitdoc-github-close")
39 .attr("title", "Close")
41 .click($
.proxy(this.close
, this))
43 .append("<h3>" + this.options
.title
+ "</h3>")
48 .attr("for", "nitdoc-github-commit-message")
53 .attr("id", "nitdoc-github-commit-message")
59 id
: "nitdoc-github-commit-signedoff",
62 .change($
.proxy(this._doSignedChange
, this))
67 "id": "nitdoc-github-commit-signedoff-label",
68 "for": "nitdoc-github-commit-signedoff"
73 .addClass("nitdoc-github-buttons")
77 id
: "nitdoc-github-commit-button",
80 .addClass("nitdoc-github-button")
82 $
(document
.createElement("img"))
83 .attr("src", "resources/icons/github-icon.png")
86 .click($
.proxy(this._doCommitClick
, this))
89 $
("body").append(this._commitBox
);
92 open
: function(namespace, user
, isNew
) {
93 var message
= "doc: " + (isNew ?
"added" : "modified") + " comment for " + namespace;
94 this._setMessage(message
);
95 this._setSignedOff(user
.signedOff
);
97 this._commitBox
.show();
100 marginTop
: -(this._commitBox
.outerHeight() / 2) + "px",
102 marginLeft
: -(this._commitBox
.outerWidth() / 2) + "px"
104 .find("#nitdoc-github-commit-message").focus();
108 this._commitBox
.hide();
114 _buildFade
: function() {
117 .attr("id", "nitdoc-github-commitBox-fade")
118 .addClass("nitdoc-github-fade")
121 _getMessage
: function() {
122 return $
("#nitdoc-github-commit-message").val();
125 _setMessage
: function(message
) {
126 $
("#nitdoc-github-commit-message").val(message
);
129 _getSignedOff
: function() {
130 return $
("#nitdoc-github-commit-message").val();
133 _setSignedOff
: function(signedoff
) {
134 $
("#nitdoc-github-commit-signedoff").val(signedoff
);
135 $
("#nitdoc-github-commit-signedoff-label").text(signedoff
);
140 _doSignedChange
: function(event
) {
141 if ($
(event
.currentTarget
).is(':checked')) {
142 $
("#nitdoc-github-commit-button").removeAttr("disabled");
144 $
("#nitdoc-github-commit-button").attr("disabled", "disabled");
148 _doCommitClick
: function(event
) {
149 $
(event
.target
).text("Commiting...");
150 $
(event
.target
).attr("disabled", "disabled");
151 this._trigger("_commit", event
, {
152 message
: this._getMessage(),
153 signedoff
: this._getSignedOff()
157 _doCancelClick
: function(event
) {
158 this._trigger("_cancel", event
);