2014-03-06 20:25:32 +05:30
|
|
|
var Gogits = {
|
|
|
|
"PageIsSignup": false
|
|
|
|
};
|
2014-03-02 19:17:55 +05:30
|
|
|
|
2014-03-06 20:25:32 +05:30
|
|
|
(function ($) {
|
2014-03-10 14:24:52 +05:30
|
|
|
|
2014-03-02 19:17:55 +05:30
|
|
|
Gogits.showTab = function (selector, index) {
|
|
|
|
if (!index) {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
$(selector).tab("show");
|
|
|
|
$(selector).find("li:eq(" + index + ") a").tab("show");
|
2014-03-06 20:25:32 +05:30
|
|
|
};
|
|
|
|
Gogits.validateForm = function (selector, options) {
|
|
|
|
var $form = $(selector);
|
|
|
|
options = options || {};
|
|
|
|
options.showErrors = function (map, list) {
|
|
|
|
var $error = $form.find('.form-error').addClass('hidden');
|
|
|
|
$('.has-error').removeClass("has-error");
|
|
|
|
$error.text(list[0].message).show().removeClass("hidden");
|
|
|
|
$(list[0].element).parents(".form-group").addClass("has-error");
|
|
|
|
};
|
|
|
|
$form.validate(options);
|
|
|
|
};
|
2014-03-10 14:24:52 +05:30
|
|
|
|
|
|
|
// ----- init elements
|
|
|
|
Gogits.initModals = function () {
|
|
|
|
var modals = $("[data-toggle=modal]");
|
|
|
|
if (modals.length < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$.each(modals, function (i, item) {
|
2014-03-10 18:42:49 +05:30
|
|
|
var hide = $(item).data('modal');
|
|
|
|
$(item).modal(hide ? hide : "hide");
|
2014-03-10 14:24:52 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
Gogits.initTooltips = function () {
|
|
|
|
$("body").tooltip({
|
|
|
|
selector: "[data-toggle=tooltip]"
|
|
|
|
//container: "body"
|
|
|
|
});
|
|
|
|
};
|
2014-03-10 18:42:49 +05:30
|
|
|
Gogits.initTabs = function () {
|
2014-03-13 11:38:49 +05:30
|
|
|
var $tabs = $('[data-init=tabs]');
|
|
|
|
$tabs.find("li:eq(0) a").tab("show");
|
2014-03-10 18:42:49 +05:30
|
|
|
}
|
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
// ajax utils
|
|
|
|
(function ($) {
|
|
|
|
Gogits.ajaxDelete = function (url, data, success) {
|
|
|
|
data = data || {};
|
|
|
|
data._method = "DELETE";
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
method: "POST",
|
|
|
|
dataType: "json",
|
|
|
|
success: function (json) {
|
|
|
|
if (success) {
|
|
|
|
success(json);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2014-03-03 20:10:22 +05:30
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|
2014-03-06 20:25:32 +05:30
|
|
|
function initCore() {
|
2014-03-10 14:24:52 +05:30
|
|
|
Gogits.initTooltips();
|
2014-03-13 11:38:49 +05:30
|
|
|
Gogits.initTabs();
|
2014-03-10 14:24:52 +05:30
|
|
|
Gogits.initModals();
|
2014-03-06 20:25:32 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function initRegister() {
|
|
|
|
$.getScript("/js/jquery.validate.min.js", function () {
|
|
|
|
Gogits.validateForm("#gogs-login-card", {
|
|
|
|
rules: {
|
|
|
|
"username": {
|
|
|
|
required: true,
|
|
|
|
maxlength: 30
|
|
|
|
},
|
|
|
|
"email": {
|
|
|
|
required: true,
|
|
|
|
email: true
|
|
|
|
},
|
|
|
|
"passwd": {
|
|
|
|
required: true,
|
|
|
|
minlength: 6,
|
|
|
|
maxlength: 30
|
|
|
|
},
|
|
|
|
"re-passwd": {
|
|
|
|
required: true,
|
|
|
|
equalTo: "input[name=passwd]"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2014-03-10 18:42:49 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
function initUserSetting(){
|
2014-03-16 18:37:50 +05:30
|
|
|
$('#gogs-ssh-keys .delete').confirmation({
|
|
|
|
singleton: true,
|
|
|
|
onConfirm: function(e, $this){
|
|
|
|
Gogits.ajaxDelete("",{"id":$this.data("del")},function(json){
|
|
|
|
if(json.ok){
|
|
|
|
window.location.reload();
|
|
|
|
}else{
|
|
|
|
alert(json.err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-03-10 18:42:49 +05:30
|
|
|
});
|
2014-03-03 20:10:22 +05:30
|
|
|
}
|