blob: 9bcb447a8e8b6b3b910c081b31b2f6ea2f7169e0 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001[define category_css]css/ph_detail.css[end]
2[include "../framework/header.ezt" "hidetabs"]
3
4<h2>Create a new project</h2>
5
6[if-any read_only][include "../framework/read-only-rejection.ezt"]
7[else]
8
9<form action="createProject.do" method="POST" id="create_project_form"
10 style="margin:1em" enctype="multipart/form-data">
11 <input type="hidden" name="token" value="[form_token]">
12
13
14 Project name:<br>
15 <input size="30" type="text" id="projectname" name="projectname" autocomplete="off"
16 value="[initial_name]">
17 <span class="graytext">Example: my-project-name</span>
18 <div class="fielderror">&nbsp;
19 <span id="projectnamefeedback">
20 [if-any errors.projectname][errors.projectname][end]
21 </span>
22 </div>
23
24 [include "../framework/project-descriptive-fields.ezt"]
25 <br>
26
27 Viewable by:
28 [include "../framework/project-access-part.ezt" "checksubmit"]
29 <br>
30
31 <input type="submit" id="submit_btn" name="btn" value="Create project">
32</form>
33
34
35<script type="text/javascript" nonce="[nonce]">
36runOnLoad(function() {
37 [# TODO(jrobbins): move this to compiled Javascript. ]
38 var submit = document.getElementById('submit_btn');
39 submit.disabled = 'disabled';
40 var projectname = document.getElementById('projectname');
41 var access = document.getElementById('access');
42 var summary = document.getElementById('summary');
43 var description = document.getElementById('description');
44 var cg = document.getElementById('cg');
45 var oldName = '';
46 projectname.focus();
47 var solelyDigits = /^[[]-0-9]+$/
48 var hasUppercase = /[[]A-Z]/
49 var projectRE = /^[[]a-z0-9][[]-a-z0-9]*$/
50
51 function checkprojectname() {
52 name = projectname.value;
53 if (name != oldName) {
54 oldName = name;
55 feedback = document.getElementById('projectnamefeedback');
56 submit.disabled='disabled';
57 if (name == '') {
58 feedback.textContent = '';
59 } else if (hasUppercase.test(name)) {
60 feedback.textContent = 'Must be all lowercase';
61 } else if (solelyDigits.test(name)) {
62 feedback.textContent = 'Must include a lowercase letter';
63 } else if (!projectRE.test(name)) {
64 feedback.textContent = 'Invalid project name';
65 } else if (name.length > [max_project_name_length]) {
66 feedback.textContent = 'Project name is too long';
67 } else if(name[[]name.length - 1] == '-') {
68 feedback.textContent = "Project name cannot end with a '-'";
69 } else {
70 feedback.textContent = '';
71 checkname();
72 checksubmit();
73 }
74 }
75 }
76
77 var checkname = debounce(function() {
78 _CP_checkProjectName(projectname.value);
79 });
80
81 function checkempty(elemId) {
82 var elem = document.getElementById(elemId);
83 feedback = document.getElementById(elemId + 'feedback');
84 if (elem.value.length == 0) {
85 feedback.textContent = 'Please enter a ' + elemId;
86 } else {
87 feedback.textContent = ' ';
88 }
89 checksubmit();
90 }
91
92 function checksubmit() {
93 feedback = document.getElementById('projectnamefeedback');
94 submit.disabled='disabled';
95 if (projectname.value.length > 0 &&
96 summary.value.length > 0 &&
97 description.value.length > 0 &&
98 (cg == undefined || cg.value.length > 1) &&
99 feedback.textContent == '') {
100 submit.disabled='';
101 }
102 }
103 setInterval(checkprojectname, 700); [# catch changes that were not keystrokes.]
104 $("projectname").addEventListener("keyup", checkprojectname);
105 $("summary").addEventListener("keyup", function() { checkempty("summary"); });
106 $("description").addEventListener("keyup", function() { checkempty("description"); });
107 $("create_project_form").addEventListener("submit", function () {
108 $("submit_btn").value = "Creating project...";
109 $("submit_btn").disabled = "disabled";
110 });
111
112});
113</script>
114
115[end][# not read-only]
116
117[include "../framework/footer.ezt"]