The content may contain violation information
branch: path: branch: path: 此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。 如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。".concat(htmlSafe(branch), "
").concat(htmlSafe(readonly_item), " Confirm the readonly flag of this path on the cancel branch?\n ");
gitGCModal.confirm("Cancel readonly", confirmString, function() {
var parentsReadonly = isParentsReadonly(readonly_item)
if (parentsReadonly) {
return gitGCModal.alert('Prompt', 'Readonly record does not exist, or parent directory is readonly',function () {
location.reload()
})
}
$.ajax({
url: "/NightFurySL2001/CJK-character-count/readonly",
type: 'DELETE',
data: {
branch: branch,
path: readonly_item
},
success: function(res) {
if (res.code !== 0) {
gitGCModal.alert("Prompt", res.msg, function() {
location.reload();
})
}else {
$parent.removeClass('readonly-item')
if (gon.readonlyItems) {
gon.readonlyItems.splice(gon.readonlyItems.indexOf(readonly_item), 1)
}
if (type === 'file') {
$icon.removeClass('icon-file-readonly readonly-icon')
$icon.addClass('icon-file')
} else {
$icon.removeClass('icon-folder-readonly readonly-icon')
$icon.addClass('icon-folders')
}
$icon.popup('destroy')
$item.removeAttr('data-readonly')
location.reload();
}
}
})
})
}
// 只读过滤
function isTreeItemReadonly(path, readonlyItems) {
var item = readonlyItems.find(function(item) {
if (item.slice(-1) === '/') {
return path.indexOf(item) === INDEX_BEGIN_WITH_READONLY_DIR
} else {
return path === item
}
})
return item !== undefined
}
function getItemPath(path) {
var path_type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'file';
return path_type === 'file' ? path : "".concat(path, "/");
}
// 启用异步只读差异化的次数
var is_can_readonly = false
// 异步对文件树进行只读差异化显示
function markTree() {
$.ajax({
url: "/NightFurySL2001/CJK-character-count/readonly",
method: 'get',
data: {
"branch": "master"
},
success:function(result) {
var readonlyItems = result.readonly_items
gon.readonlyItems = readonlyItems
$(".tree-list-item").each(function(){
$this = $(this)
var path = $this.attr('data-path')
var type = $this.attr('data-type')
var item_path = getItemPath(path, type)
var readonly = isTreeItemReadonly(item_path, readonlyItems)
$icon = $this.find('i')
$parent = $this.parent('.tree-item')
if (readonly) {
$parent.addClass('readonly-item')
$this.attr('data-readonly', '')
$icon.attr('class', "iconfont icon-".concat(type, "-readonly readonly-icon"));
$icon.attr('data-readonly', '')
$icon.popup({
content: "Readonly",
className : {
popup: 'ui popup dark',
},
position: 'top center'
})
} else {
var className = type === 'file' ? 'file' : 'folders'
$this.removeAttr('data-readonly')
$icon.attr('class', "iconfont icon-".concat(className));
$icon.removeAttr('data-readonly')
}
})
}
})
}
// 若已开启只读功能,对目录进行只读差异化标记
if (is_can_readonly) {
markTree()
}
// 添加只读标记
function addReadonlyMark(path, $item) {
var $icon = $($item.context.children[0])
var $parent = $item.parent('.tree-item')
var type = $parent.data('type')
var branch = $parent.data('branch')
var readonly_item = $item.data('path')
if (type !== 'file') {
readonly_item += "/"
}
var confirmString = "\n
".concat(htmlSafe(branch), "
").concat(htmlSafe(readonly_item), " Confirm that this path on the branch is marked as readonly?\n ");
gitGCModal.confirm("Mark readonly", confirmString,function (){
$.ajax({
url: "/NightFurySL2001/CJK-character-count/readonly",
type: 'POST',
data: {
branch: branch,
path: readonly_item,
},
success: function(res) {
if (res.code !== 0) {
gitGCModal.alert("Prompt", res.msg,function (){
location.reload();
})
} else {
// 之前未开启只读功能
if (!is_can_readonly) {
is_can_readonly = true
return markTree()
}
$parent.addClass('readonly-item')
var existReadonlyItems = gon.readonlyItems || []
existReadonlyItems.push(readonly_item)
gon.readonlyItems = existReadonlyItems
$icon.popup({
content: "Readonly",
className : {
popup: 'ui popup dark',
},
position: 'top center'
})
if (type === 'file') {
$icon.removeClass('icon-file')
$icon.addClass('icon-file-readonly readonly-icon')
} else {
$icon.removeClass('icon-folders')
$icon.addClass('icon-folder-readonly readonly-icon')
}
$item.attr('data-readonly', '')
location.reload();
}
}
})
})
}
function removeFile(path, file_name) {
var file_name = file_name || path
var content = "Are you sure to delete %{name} ?".replace('%{name}', htmlSafe(file_name));
gitGCModal.confirm("Remove", content, function() {
$.ajax({
type: "DELETE",
dataType: "JSON",
url: "/NightFurySL2001/CJK-character-count/delete/" + path,
success: function(res) {
if (res.status != 1) {
var alert_message = res.message || "Failed to delete"
return gitGCModal.alert("Prompt", alert_message)
}
if ($('.tree-item-file-name').length == 2) {
window.location.href = '/' + gon.user_project;
if(file_name.toUpperCase()==='LICENSE'){
window.location.reload();
}
} else {
window.location.href = window.location.pathname;
if(file_name.toUpperCase()==='LICENSE'){
window.location.reload();
}
}
}
});
})
}
// 删除子模块
function removeSubmodule(deleteUrl, $item) {
if (!deleteUrl) return
var file_name = $item.text().trim()
var content = "This operation can not be recovered, Are you sure to delete submodule %{name} ?".replace('%{name}', htmlSafe(file_name));
new GiteeModalHelper({
approveText: "Delete and submit push",
cancelText: "Cancel",
okText: "Delete and submit push",
}).confirm("Remove", content, function() {
$.ajax({
type: "DELETE",
dataType: "JSON",
url: deleteUrl,
success: function(res) {
if (res.status == 200) {
$item.closest('.row.tree-item').remove();
window.location.reload();
} else {
Flash.error(res.message, 5000)
}
},
error: function (err) {
err.responseJSON && Flash.error(err.responseJSON.message);
},
});
})
}
function rename(file_hex) {
$(".row.tree-item").show();
$(".tree-item-rename").hide();
if($("."+file_hex).is(':hidden') == true) return;
$("."+file_hex).hide();
var _t = $(".rename-"+file_hex);
src = _t.attr('src_text')
if(src==undefined){
newName = _t.find("[name='new_filename']").val()
_t.attr('src_text',newName)
}else{
_t.find("[name='new_filename']").val(_t.attr('src_text'))
}
$(".rename-"+file_hex).css("display","");
}
setTimeout(function(){
$(".popup-save").click(function(){
form = $(this).parents(".ui.form")
file_hex = $(this).parents(".row.tree-item").attr("file_hex");
new_filename = $.trim(form.find("[name='new_filename']").val())
overwrite = false
$('.tree-item-file-name').find('a').each(function(a){
title = $(this).attr('title');
if(title != undefined){
if (title.split('/')[0] == new_filename) {
overwrite = true;
}
}
});
if(overwrite){
form.find("[name='new_filename']").focus();
gitGCModal.alert("Prompt", "The same file name exists, please modify and try again")
return;
}
$.ajax({
type: 'POST',
url: "/NightFurySL2001/CJK-character-count/rename/"+ form.attr('path').replace(/\+/g, '%20'),
data:
{
new_filename: new_filename
},
success: function(o){
if(o.status == 1){
href = window.location.href.split('?')[0]
window.location.href = href;
}else {
var alert_message = o.message || "Rename failed"
gitGCModal.alert("Prompt", alert_message)
}
},
dataType: "json"
});
})
$(".popup-close").click(function(){
$(".row.tree-item").show();
$(".tree-item-rename").hide();
})
$('.tree-item-file-name, .tree-item-submodule-name').each(function() {
var $this = $(this);
if (typeof $this.parent().attr('file_hex') === 'undefined') {
return;
}
$this.on('contextmenu', function(event) {
event.preventDefault();
createContextMenu($this, event.pageX, event.pageY);
})
})
},1000)
})