
Project: improve validations for new project form
@d37c4bbac556628cd946a612c014be75394561de
--- app/assets/stylesheets/less/_page.less
+++ app/assets/stylesheets/less/_page.less
... | ... | @@ -1405,6 +1405,7 @@ |
1405 | 1405 |
//-- new project |
1406 | 1406 |
.form-wrap { |
1407 | 1407 |
&.new-project { |
1408 |
+ position:relative; |
|
1408 | 1409 |
width:700px; |
1409 | 1410 |
margin: 30px auto; |
1410 | 1411 |
|
... | ... | @@ -1439,6 +1440,10 @@ |
1439 | 1440 |
background:#fafafa; |
1440 | 1441 |
.border-radius(10px); |
1441 | 1442 |
} |
1443 |
+ |
|
1444 |
+ .popover { |
|
1445 |
+ max-width:144px; |
|
1446 |
+ } |
|
1442 | 1447 |
} |
1443 | 1448 |
} |
1444 | 1449 |
|
--- app/assets/stylesheets/less/_yobiUI.less
+++ app/assets/stylesheets/less/_yobiUI.less
... | ... | @@ -50,6 +50,10 @@ |
50 | 50 |
.border-radius(2px); |
51 | 51 |
.box-shadow(-2px 2px 1px rgba(0,0,0,0.1)); |
52 | 52 |
} |
53 |
+.popover-content { |
|
54 |
+ padding:9px 10px; |
|
55 |
+ line-height:120%; |
|
56 |
+} |
|
53 | 57 |
|
54 | 58 |
/** yobi.ui.Dropdown **/ |
55 | 59 |
.dropdown-toggle { |
--- app/views/project/create.scala.html
+++ app/views/project/create.scala.html
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 |
<div class="page-wrap-outer"> |
29 | 29 |
<div class="project-page-wrap"> |
30 | 30 |
<div class="form-wrap new-project"> |
31 |
- <form action="@routes.ProjectApp.newProject()" method="post" name="newproject" class="frm-wrap"> |
|
31 |
+ <form id="newProjectForm" action="@routes.ProjectApp.newProject()" method="post" class="frm-wrap"> |
|
32 | 32 |
<legend> |
33 | 33 |
@Messages("title.newProject") |
34 | 34 |
<span> |
... | ... | @@ -64,11 +64,9 @@ |
64 | 64 |
</option> |
65 | 65 |
} |
66 | 66 |
</select> |
67 |
- <div class="n-alert" data-errType="owner"> |
|
68 |
- <div class="orange-txt"> |
|
69 |
- @if(newProjectForm.error("owner") != null) { <span class="warning">@Messages(newProjectForm.error("owner").message())</span> } |
|
70 |
- </div> |
|
71 |
- </div> |
|
67 |
+ @if(newProjectForm.error("owner") != null) { |
|
68 |
+ <span class="orange-text">@Messages(newProjectForm.error("owner").message())</span> |
|
69 |
+ } |
|
72 | 70 |
</dd> |
73 | 71 |
<!-- // --> |
74 | 72 |
|
... | ... | @@ -81,13 +79,7 @@ |
81 | 79 |
</dt> |
82 | 80 |
<dd> |
83 | 81 |
<input id="project-name" type="text" name="name" class="text" maxlength="250" pattern="[a-zA-Z0-9-]+" |
84 |
- value="@newProjectForm.field("name").value" placeholder="@Messages("project.name.alert")" > |
|
85 |
- <div class="n-alert" data-errType="name"> |
|
86 |
- <div class="orange-txt"> |
|
87 |
- @if(newProjectForm.error("name") != null) { <span class="warning">@Messages(newProjectForm.error("name").message())</span> } |
|
88 |
- <span class="msg wrongName" style="display: none;"></span> |
|
89 |
- </div> |
|
90 |
- </div> |
|
82 |
+ value="@newProjectForm.field("name").value" placeholder="@Messages("project.name.placeholder")" > |
|
91 | 83 |
</dd> |
92 | 84 |
<!-- // --> |
93 | 85 |
|
... | ... | @@ -187,9 +179,10 @@ |
187 | 179 |
|
188 | 180 |
@common.select2() |
189 | 181 |
<script type="text/javascript"> |
190 |
- $(document).ready(function() { |
|
182 |
+ $(function() { |
|
191 | 183 |
$yobi.loadModule("project.New", { |
192 |
- "sFormName" : "newproject" |
|
184 |
+ "sFormId": "#newProjectForm", |
|
185 |
+ "htError": @Html(newProjectForm.errorsAsJson.toString) |
|
193 | 186 |
}); |
194 | 187 |
}); |
195 | 188 |
</script> |
--- app/views/project/importing.scala.html
+++ app/views/project/importing.scala.html
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 |
<div class="page-wrap-outer"> |
28 | 28 |
<div class="project-page-wrap"> |
29 | 29 |
<div class="form-wrap new-project"> |
30 |
- <form id="importGit" action="@routes.ImportApp.newProject()" method="post" name="newproject" class="frm-wrap"> |
|
30 |
+ <form id="importGit" action="@routes.ImportApp.newProject()" method="post" class="frm-wrap"> |
|
31 | 31 |
<legend> |
32 | 32 |
@Messages("project.import.from.git") |
33 | 33 |
<span> |
... | ... | @@ -48,11 +48,6 @@ |
48 | 48 |
</dt> |
49 | 49 |
<dd> |
50 | 50 |
<input id="url" type="text" name="url" class="text" placeholder="@Messages("project.git.url.alert")" value="@newProjectForm.field("url").value"> |
51 |
- <div class="n-alert" data-errType="url"> |
|
52 |
- <div class="orange-txt"> |
|
53 |
- @if(newProjectForm.error("url") != null) { <span class="warning">@Messages(newProjectForm.error("url").message())</span> } |
|
54 |
- </div> |
|
55 |
- </div> |
|
56 | 51 |
</dd> |
57 | 52 |
<!-- // --> |
58 | 53 |
<!-- ProjectOwner --> |
... | ... | @@ -79,11 +74,9 @@ |
79 | 74 |
</option> |
80 | 75 |
} |
81 | 76 |
</select> |
82 |
- <div class="n-alert" data-errType="owner"> |
|
83 |
- <div class="orange-txt"> |
|
84 |
- @if(newProjectForm.error("owner") != null) { <span class="warning">@Messages(newProjectForm.error("owner").message())</span> } |
|
85 |
- </div> |
|
86 |
- </div> |
|
77 |
+ @if(newProjectForm.error("owner") != null) { |
|
78 |
+ <span class="orange-text">@Messages(newProjectForm.error("owner").message())</span> |
|
79 |
+ } |
|
87 | 80 |
</dd> |
88 | 81 |
<!-- // --> |
89 | 82 |
|
... | ... | @@ -97,12 +90,6 @@ |
97 | 90 |
<dd> |
98 | 91 |
<input id="project-name" type="text" name="name" class="text" maxlength="250" pattern="[a-zA-Z0-9-]+" |
99 | 92 |
value="@newProjectForm.field("name").value" placeholder="@Messages("project.name.alert")" > |
100 |
- <div class="n-alert" data-errType="name"> |
|
101 |
- <div class="orange-txt"> |
|
102 |
- @if(newProjectForm.error("name") != null) { <span class="warning">@Messages(newProjectForm.error("name").message())</span> } |
|
103 |
- <span class="msg wrongName" style="display: none;"></span> |
|
104 |
- </div> |
|
105 |
- </div> |
|
106 | 93 |
</dd> |
107 | 94 |
<!-- // --> |
108 | 95 |
|
... | ... | @@ -188,9 +175,10 @@ |
188 | 175 |
|
189 | 176 |
@common.select2() |
190 | 177 |
<script type="text/javascript"> |
191 |
- $(document).ready(function(){ |
|
178 |
+ $(function() { |
|
192 | 179 |
$yobi.loadModule("project.New", { |
193 |
- "sFormName": "newproject" |
|
180 |
+ "sFormId": "#importGit", |
|
181 |
+ "htError": @Html(newProjectForm.errorsAsJson.toString) |
|
194 | 182 |
}); |
195 | 183 |
}); |
196 | 184 |
</script> |
--- conf/messages
+++ conf/messages
... | ... | @@ -470,9 +470,9 @@ |
470 | 470 |
project.members = Project members |
471 | 471 |
project.members.addMember = Add new member ID. |
472 | 472 |
project.name = Project name |
473 |
-project.name.alert = Characters that can be used in URL are allowed |
|
473 |
+project.name.alert = Enter name in alphabet, number or hyphen |
|
474 | 474 |
project.name.duplicate = Same project name already exists. |
475 |
-project.name.placeholder = Enter project name |
|
475 |
+project.name.placeholder = Enter project name in alphabet, number or hyphen |
|
476 | 476 |
project.name.reserved.alert = You can''t use reserved names. |
477 | 477 |
project.name.rule = Naming rules |
478 | 478 |
project.new.agreement = I have read this user agreement and agree to all of its provisions. |
--- conf/messages.ja
+++ conf/messages.ja
... | ... | @@ -361,10 +361,10 @@ |
361 | 361 |
project.members = メンバー |
362 | 362 |
project.members.addMember = 追加するメンバーのIDを入力してください |
363 | 363 |
project.name = プロジェクト名 |
364 |
-project.name.alert = プロジェクト名はURLで使える文字(半角ローマ字,数字,-'ハイフン')だけ使えます |
|
364 |
+project.name.alert = 半角英数字,ハイフン(-)だけにしてください |
|
365 | 365 |
project.name.duplicate = すでに同じな名前のプロジェクトがあります |
366 |
-project.name.placeholder = プロジェクト名を入力してください |
|
367 |
-project.name.reserved.alert = Name is reserved |
|
366 |
+project.name.placeholder = プロジェクト名には半角英数字,ハイフン(-)のみ使用できます |
|
367 |
+project.name.reserved.alert = 予約語は使用できません |
|
368 | 368 |
project.name.rule = 名前規則 |
369 | 369 |
project.new.agreement = 利用契約に同意する |
370 | 370 |
project.new.vcsType.git = Git |
... | ... | @@ -373,9 +373,12 @@ |
373 | 373 |
project.onwatching = <strong>{0}</strong> |
374 | 374 |
project.owner = 作成者名 |
375 | 375 |
project.private = 非公開 |
376 |
-project.private.notice = 非公開プロジェクトもプロジェクト名、説明、ロゴなどは誰にでも見えます。 |
|
376 |
+project.private.notice = プロジェクトメンバーだけに接近を許します。ただし、プロジェクト名、説明、ロゴなどは一般に公開されます |
|
377 | 377 |
project.projects = プロジェクト |
378 |
+project.protected = グループ内公開 |
|
379 |
+project.protected.notice = 同じグループ内の人々とプロジェクトメンバーだけに接近を許します |
|
378 | 380 |
project.public = 公開 |
381 |
+project.public.notice = 誰もこのプロジェクトに接近できます |
|
379 | 382 |
project.readme = プロジェクトに関する説明をREADME.mdファイルで作成してリポジトリールートに追加したらここに表示されます |
380 | 383 |
project.searchPlaceholder = このプロジェクトで検索 |
381 | 384 |
project.setting = 設定 |
--- conf/messages.ko
+++ conf/messages.ko
... | ... | @@ -468,10 +468,10 @@ |
468 | 468 |
project.members = 프로젝트 멤버 |
469 | 469 |
project.members.addMember = 새로운 멤버의 아이디를 입력하세요 |
470 | 470 |
project.name = 프로젝트 이름 |
471 |
-project.name.alert = 프로젝트 이름은 URL로 사용할 수 있는 글자(영문자,숫자,-'하이픈')만 허용합니다 |
|
471 |
+project.name.alert = 영문, 숫자, 하이픈(-)만 입력해주세요 |
|
472 | 472 |
project.name.duplicate = 이미 같은 이름의 프로젝트가 있습니다 |
473 |
-project.name.placeholder = 프로젝트 이름을 입력해주세요. |
|
474 |
-project.name.reserved.alert = 예약된 이름으로 사용할 수 없습니다. |
|
473 |
+project.name.placeholder = 프로젝트 이름은 영문, 숫자, 하이픈(-)만 사용할 수 있습니다 |
|
474 |
+project.name.reserved.alert = 예약된 이름으로 사용할 수 없습니다 |
|
475 | 475 |
project.name.rule = 이름 규칙 |
476 | 476 |
project.new.agreement = 본인은 약관에 대한 안내를 읽었으며 이에 동의합니다 |
477 | 477 |
project.new.vcsType.git = Git |
--- public/javascripts/service/yobi.project.New.js
+++ public/javascripts/service/yobi.project.New.js
... | ... | @@ -27,20 +27,18 @@ |
27 | 27 |
var htElement = {}; |
28 | 28 |
|
29 | 29 |
function _init(htOptions){ |
30 |
- _initVar(htOptions); |
|
31 |
- _initElement(); |
|
30 |
+ _initVar(); |
|
31 |
+ _initElement(htOptions); |
|
32 | 32 |
_attachEvent(); |
33 |
+ _focusOnFirstField(); |
|
33 | 34 |
|
34 |
- _initFormValidator(); |
|
35 |
- |
|
36 |
- htElement.welInputProjectName.focus(); |
|
35 |
+ _showErrors(htOptions.htError); |
|
37 | 36 |
} |
38 | 37 |
|
39 | 38 |
/** |
40 | 39 |
* initialize variables |
41 | 40 |
*/ |
42 |
- function _initVar(htOptions){ |
|
43 |
- htVar.sFormName = htOptions.sFormName || "newproject"; |
|
41 |
+ function _initVar(){ |
|
44 | 42 |
htVar.rxPrjName = /^[0-9A-Za-z-_\.]+$/; |
45 | 43 |
htVar.aReservedWords = [".", "..", ".git"]; |
46 | 44 |
} |
... | ... | @@ -48,11 +46,14 @@ |
48 | 46 |
/** |
49 | 47 |
* initialize element |
50 | 48 |
*/ |
51 |
- function _initElement(){ |
|
52 |
- htElement.vcsSelect = $("#vcs"); |
|
53 |
- htElement.svnWarning = $("#svn"); |
|
49 |
+ function _initElement(htOptions){ |
|
50 |
+ htElement.welForm = $(htOptions.sFormId); |
|
54 | 51 |
htElement.welInputProjectName = $("#project-name"); |
55 | 52 |
htElement.welInputProjectOwner = $("#project-owner"); |
53 |
+ htElement.welInputGitRepoURL = $("#url"); |
|
54 |
+ |
|
55 |
+ htElement.vcsSelect = $("#vcs"); |
|
56 |
+ htElement.svnWarning = $("#svn"); |
|
56 | 57 |
htElement.welProtected = $("#opt-protected"); |
57 | 58 |
} |
58 | 59 |
|
... | ... | @@ -62,6 +63,7 @@ |
62 | 63 |
function _attachEvent(){ |
63 | 64 |
htElement.vcsSelect.on("change", _onChangeVCSItem); |
64 | 65 |
htElement.welInputProjectOwner.on("change", _onChangeProjectOwner); |
66 |
+ htElement.welForm.on("submit", _validateForm); |
|
65 | 67 |
} |
66 | 68 |
|
67 | 69 |
function _onChangeVCSItem(evt){ |
... | ... | @@ -74,6 +76,7 @@ |
74 | 76 |
|
75 | 77 |
function _onChangeProjectOwner() { |
76 | 78 |
var sType = $("#project-owner option:selected").data("type"); |
79 |
+ |
|
77 | 80 |
if (sType == "user") { |
78 | 81 |
if ($("#protected").is(":checked")) { |
79 | 82 |
$("#public").prop("checked", true); |
... | ... | @@ -84,63 +87,76 @@ |
84 | 87 |
} |
85 | 88 |
} |
86 | 89 |
|
87 |
- /** |
|
88 |
- * initialize formValidator |
|
89 |
- * @require validate.js |
|
90 |
- */ |
|
91 |
- function _initFormValidator(){ |
|
92 |
- // name : name of input element |
|
93 |
- // rules: rules to apply to the input element. |
|
94 |
- var aRules = []; |
|
95 |
- |
|
96 |
- htVar.oValidator = new FormValidator(htVar.sFormName, aRules, function(aErrors){ |
|
97 |
- var oForm = $(document.forms[htVar.sFormName]); |
|
98 |
- var oElement = oForm.find("input[name=name]"); |
|
99 |
- var sPrjName = oElement.val(); |
|
100 |
- if(!htVar.rxPrjName.test(sPrjName)){ |
|
101 |
- aErrors.push({ |
|
102 |
- id: oElement.attr("id"), |
|
103 |
- name: oElement.attr("name"), |
|
104 |
- message: Messages("project.name.alert") |
|
105 |
- }); |
|
106 |
- } |
|
107 |
- if(htVar.aReservedWords.indexOf(sPrjName) >= 0){ |
|
108 |
- aErrors.push({ |
|
109 |
- id: oElement.attr("id"), |
|
110 |
- name: oElement.attr("name"), |
|
111 |
- message: Messages("project.name.reserved.alert") |
|
112 |
- }); |
|
113 |
- } |
|
114 |
- _onFormValidate(aErrors); |
|
115 |
- }); |
|
90 |
+ function _focusOnFirstField(){ |
|
91 |
+ if(htElement.welInputGitRepoURL.length > 0){ |
|
92 |
+ htElement.welInputGitRepoURL.focus(); |
|
93 |
+ } else { |
|
94 |
+ htElement.welInputProjectName.focus(); |
|
95 |
+ } |
|
116 | 96 |
} |
117 | 97 |
|
118 | 98 |
/** |
119 |
- * handler for validation errors. |
|
99 |
+ * Validate form on submit |
|
100 |
+ * |
|
101 |
+ * @private |
|
120 | 102 |
*/ |
121 |
- function _onFormValidate(aErrors){ |
|
122 |
- if(aErrors.length > 0){ |
|
123 |
- $('span.warning').hide(); |
|
124 |
- $('span.msg').html(aErrors[0].message).show(); |
|
125 |
- } else { |
|
126 |
- new Spinner({ |
|
127 |
- lines: 13, // The number of lines to draw |
|
128 |
- length: 10, // The length of each line |
|
129 |
- width: 5, // The line thickness |
|
130 |
- radius: 10, // The radius of the inner circle |
|
131 |
- corners: 1, // Corner roundness (0..1) |
|
132 |
- rotate: 0, // The rotation offset |
|
133 |
- direction: 1, // 1: clockwise, -1: counterclockwise |
|
134 |
- color: '#000', // #rgb or #rrggbb |
|
135 |
- speed: 1, // Rounds per second |
|
136 |
- trail: 60, // Afterglow percentage |
|
137 |
- shadow: false, // Whether to render a shadow |
|
138 |
- hwaccel: false, // Whether to use hardware acceleration |
|
139 |
- className: 'spinner', // The CSS class to assign to the spinner |
|
140 |
- zIndex: 2e9, // The z-index (defaults to 2000000000) |
|
141 |
- top: 'auto', // Top position relative to parent in px |
|
142 |
- left: 'auto' // Left position relative to parent in px |
|
143 |
- }).spin(document.forms[htVar.sFormName]); |
|
103 |
+ function _validateForm(evt){ |
|
104 |
+ var error = {}; |
|
105 |
+ var projectName = htElement.welInputProjectName.val(); |
|
106 |
+ |
|
107 |
+ if(projectName.length === 0){ |
|
108 |
+ error.name = error.name || []; |
|
109 |
+ error.name.push(Messages("project.name.alert")); |
|
110 |
+ } |
|
111 |
+ |
|
112 |
+ if(!htVar.rxPrjName.test(projectName)){ |
|
113 |
+ error.name = error.name || []; |
|
114 |
+ error.name.push(Messages("project.name.alert")); |
|
115 |
+ } |
|
116 |
+ |
|
117 |
+ if(htVar.aReservedWords.indexOf(projectName) > -1){ |
|
118 |
+ error.name = error.name || []; |
|
119 |
+ error.name.push(Messages("project.name.reserved.alert")); |
|
120 |
+ } |
|
121 |
+ |
|
122 |
+ if(htElement.welInputGitRepoURL.length > 0 && |
|
123 |
+ htElement.welInputGitRepoURL.val().trim().length === 0 ){ |
|
124 |
+ error.url = error.url || []; |
|
125 |
+ error.url.push(Messages("project.import.error.empty.url")); |
|
126 |
+ } |
|
127 |
+ |
|
128 |
+ if(!$.isEmptyObject(error)){ |
|
129 |
+ _showErrors(error); |
|
130 |
+ evt.preventDefault(); |
|
131 |
+ return false; |
|
132 |
+ } |
|
133 |
+ |
|
134 |
+ yobi.ui.Spinner.show(); |
|
135 |
+ } |
|
136 |
+ |
|
137 |
+ /** |
|
138 |
+ * Show error message on target element with $.popover |
|
139 |
+ * |
|
140 |
+ * @param error |
|
141 |
+ * @private |
|
142 |
+ */ |
|
143 |
+ function _showErrors(error){ |
|
144 |
+ if(!error){ |
|
145 |
+ return; |
|
146 |
+ } |
|
147 |
+ |
|
148 |
+ var targetElement; |
|
149 |
+ |
|
150 |
+ for(var target in error){ |
|
151 |
+ targetElement = htElement.welForm.find("[name=" + target + "]"); |
|
152 |
+ |
|
153 |
+ if(targetElement.length > 0) { |
|
154 |
+ targetElement.popover({ |
|
155 |
+ "trigger" : "manual", |
|
156 |
+ "placement": "left", |
|
157 |
+ "content" : error[target].shift() |
|
158 |
+ }).popover("show"); |
|
159 |
+ } |
|
144 | 160 |
} |
145 | 161 |
} |
146 | 162 |
|
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?