1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
(function() {
var projectNameInput = document.getElementById('project_name');
var nameValidTimeout = null;
if (!projectNameInput) return;
function setProjectNameBorder(valid) {
projectNameInput.classList.remove('border', 'border-success', 'border-danger');
projectNameInput.classList.add('border');
if (valid === true) {
projectNameInput.classList.add('border-success');
} else if (valid === false) {
projectNameInput.classList.add('border-danger');
} else {
projectNameInput.classList.remove('border');
}
}
function checkProjectName() {
var name = (projectNameInput.value || '').trim();
if (!name) {
setProjectNameBorder(null);
return;
}
var url = '/projectnamevalid?name=' + encodeURIComponent(name);
fetch(url, { credentials: 'same-origin' })
.then(function(res) {
setProjectNameBorder(res.ok);
})
.catch(function() {
setProjectNameBorder(null);
});
}
projectNameInput.addEventListener('blur', function() {
checkProjectName();
});
projectNameInput.addEventListener('input', function() {
clearTimeout(nameValidTimeout);
var name = (projectNameInput.value || '').trim();
if (!name) {
setProjectNameBorder(null);
return;
}
nameValidTimeout = setTimeout(checkProjectName, 400);
});
})();
(function() {
var sourceRadios = Array.prototype.slice.call(document.querySelectorAll('input[name="project_source_type"]'));
var emptyTab = document.getElementById('tab-empty-repo');
var zipTab = document.getElementById('tab-upload-zip');
var remoteInput = document.getElementById('pull_from_remote');
var zipInput = document.getElementById('repo_zip');
if (!emptyTab || !zipTab || !remoteInput || !zipInput) return;
function getSelectedSource() {
for (var i = 0; i < sourceRadios.length; i++) {
if (sourceRadios[i].checked) {
return sourceRadios[i].value;
}
}
return 'empty';
}
function updateSourceTabs() {
var selected = getSelectedSource();
var isZip = selected === 'zip';
emptyTab.classList.toggle('d-none', isZip);
zipTab.classList.toggle('d-none', !isZip);
if (isZip) {
remoteInput.value = '';
} else {
zipInput.value = '';
zipInput.dispatchEvent(new Event('change'));
}
}
sourceRadios.forEach(function(radio) {
radio.addEventListener('change', updateSourceTabs);
});
updateSourceTabs();
})();
(function() {
var dropzone = document.getElementById('dropzone');
var input = document.getElementById('repo_zip');
if (!dropzone || !input) return;
var placeholder = dropzone.querySelector('[data-dropzone-placeholder]');
var filenameEl = dropzone.querySelector('[data-dropzone-filename]');
if (!placeholder || !filenameEl) return;
function showFile(name) {
if (name) {
placeholder.classList.add('d-none');
filenameEl.classList.remove('d-none');
filenameEl.textContent = 'Selected: ' + name;
} else {
placeholder.classList.remove('d-none');
filenameEl.classList.add('d-none');
filenameEl.textContent = '';
}
}
dropzone.addEventListener('click', function() { input.click(); });
dropzone.addEventListener('dragover', function(e) { e.preventDefault(); dropzone.classList.add('border-primary'); });
dropzone.addEventListener('dragleave', function() { dropzone.classList.remove('border-primary'); });
dropzone.addEventListener('drop', function(e) {
e.preventDefault();
dropzone.classList.remove('border-primary');
var files = e.dataTransfer.files;
if (files.length && files[0].name.toLowerCase().endsWith('.zip')) {
input.files = files;
showFile(files[0].name);
}
});
input.addEventListener('change', function() {
showFile(input.files.length ? input.files[0].name : null);
});
})();