| author | ymh <ymh.work@gmail.com> |
| Fri, 05 Apr 2013 13:59:23 +0200 | |
| changeset 141 | 64af5273ac5e |
| parent 128 | 93a1fbe6a848 |
| child 150 | 5b62100b8562 |
| permissions | -rw-r--r-- |
| 123 | 1 |
<!DOCTYPE html> |
2 |
<html xmlns="http://www.w3.org/1999/xhtml" |
|
3 |
xmlns:th="http://www.thymeleaf.org"> |
|
4 |
<head> |
|
| 127 | 5 |
<meta charset="utf-8"/> |
| 123 | 6 |
<title>Space form</title> |
7 |
</head> |
|
8 |
<body> |
|
| 127 | 9 |
<div id="spaceForm" th:fragment="spaceFormFragment" > |
10 |
<script type="text/javascript" th:inline="javascript"> |
|
11 |
//<![CDATA[ |
|
12 |
|
|
13 |
function showformErrors(errors) { |
|
14 |
$(".form-error").remove(); |
|
15 |
|
|
16 |
$.each(errors,function(k,v){ |
|
17 |
$("#"+k).after('<div class="form-error">'+v+'</div>'); |
|
18 |
}); |
|
19 |
$(".form-error").effect("highlight", {}, 1500); |
|
20 |
} |
|
21 |
|
|
22 |
function spaceFormSubmit() { |
|
|
128
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
23 |
|
| 127 | 24 |
var errors = {}; |
25 |
var valid = true; |
|
26 |
|
|
27 |
if(!$('#title').val()) { |
|
28 |
errors['title'] = /*[[#{renkan.error.title.empty}]]*/"renkan.error.title.empty"; |
|
29 |
valid = false; |
|
30 |
} |
|
31 |
|
|
|
128
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
32 |
if($('#binConfig').val()) { |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
33 |
|
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
34 |
var editor = ace.edit("binConfigDiv"); |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
35 |
var annotations = editor.getSession().getAnnotations(); |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
36 |
if(annotations.length>0) { |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
37 |
var error_message = /*[[#{renkan.error.bin_config.json}]]*/"renkan.error.bin_config.json"; |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
38 |
errors['binConfigDiv'] = error_message + ". "+ annotations[0].type + ": (" +(annotations[0].row+1)+","+annotations[0].column+") " + annotations[0].text; |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
39 |
valid = false; |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
40 |
} |
|
93a1fbe6a848
Correct add space and improve space form validation message
ymh <ymh.work@gmail.com>
parents:
127
diff
changeset
|
41 |
} |
| 127 | 42 |
|
43 |
showformErrors(errors); |
|
44 |
|
|
45 |
return valid; |
|
46 |
} |
|
47 |
|
|
| 141 | 48 |
function formatJson(jsonText, tabSize) { |
49 |
var obj = JSON.parse(jsonText); |
|
50 |
return JSON.stringify(obj, undefined, tabSize); |
|
51 |
} |
|
52 |
function compactJson(jsonText) { |
|
53 |
var obj = JSON.parse(jsonText); |
|
54 |
return JSON.stringify(obj); |
|
55 |
} |
|
56 |
|
|
57 |
function _setBinConfigStatus(editor) { |
|
58 |
var annotations = editor.getSession().getAnnotations(); |
|
59 |
if(annotations.length>0) { |
|
60 |
$('.binConfigButton').attr("disabled", "disabled"); |
|
61 |
} |
|
62 |
else { |
|
63 |
$('.binConfigButton').removeAttr("disabled"); |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
| 127 | 67 |
$(function(){ |
| 141 | 68 |
var tabSize = 2; |
| 127 | 69 |
var editor = ace.edit("binConfigDiv"); |
70 |
editor.setTheme("ace/theme/xcode"); |
|
71 |
editor.getSession().setMode("ace/mode/json"); |
|
| 141 | 72 |
editor.getSession().setTabSize(tabSize); |
73 |
editor.getSession().setUseSoftTabs(true); |
|
74 |
_setBinConfigStatus(editor); |
|
| 127 | 75 |
editor.getSession().on('change', function(e) { |
76 |
$('#binConfig').val(editor.getValue()); |
|
77 |
}); |
|
| 141 | 78 |
editor.getSession().on('changeAnnotation', function() { |
79 |
_setBinConfigStatus(editor); |
|
80 |
}); |
|
81 |
|
|
82 |
$('#binConfigFormatButton').click(function(){ |
|
83 |
var jsonText = editor.getValue(); |
|
84 |
try { |
|
85 |
editor.setValue(formatJson(jsonText, tabSize),0); |
|
86 |
editor.moveCursorTo(0,0); |
|
87 |
editor.clearSelection(); |
|
88 |
} catch (e) { |
|
89 |
//do nothing |
|
90 |
} |
|
91 |
}); |
|
92 |
|
|
93 |
$('#binConfigCompactButton').click(function(){ |
|
94 |
var jsonText = editor.getValue(); |
|
95 |
try { |
|
96 |
editor.setValue(compactJson(jsonText),0); |
|
97 |
editor.moveCursorTo(0,0); |
|
98 |
editor.clearSelection(); |
|
99 |
} catch (e) { |
|
100 |
//do nothing |
|
101 |
} |
|
102 |
}); |
|
| 127 | 103 |
|
104 |
$('#color').spectrum({ |
|
105 |
showInput: true, |
|
106 |
showAlpha: true, |
|
107 |
showPalette: true, |
|
108 |
showInitial: true |
|
109 |
}); |
|
110 |
}); |
|
111 |
//]]> |
|
112 |
</script> |
|
113 |
<form action="#" th:object="${space}" th:action="@{/admin/spaces/save}" method="post" onsubmit="return spaceFormSubmit()"> |
|
114 |
<fieldset class="form-fields"> |
|
115 |
<input type="hidden" th:field="*{id}" th:if="*{id}" /> |
|
116 |
<input type="hidden" th:field="*{binConfig}"/> |
|
117 |
<div> |
|
118 |
<label for="title" th:text="#{renkanAdmin.form.title}">Title: </label> |
|
119 |
<input type="text" th:field="*{title}" /> |
|
120 |
<div th:if="${#fields.hasErrors('title')}" th:errors="*{title}" class="form-error"></div> |
|
121 |
</div> |
|
122 |
<div> |
|
123 |
<label for="uri" th:text="#{renkanAdmin.form.uri}">Uri: </label> |
|
124 |
<input type="text" th:field="*{uri}" /> |
|
125 |
</div> |
|
126 |
<div> |
|
127 |
<label for="description" th:text="#{renkanAdmin.form.description}">Description: </label> |
|
128 |
<textarea th:field="*{description}"></textarea> |
|
129 |
</div> |
|
130 |
<div> |
|
131 |
<label for="color" th:text="#{renkanAdmin.form.color}">Color: </label> |
|
132 |
<input type="text" th:field="*{color}" /> |
|
133 |
</div> |
|
134 |
<div> |
|
| 141 | 135 |
<label for="binConfigContainer" th:text="#{renkanAdmin.form.space.bin_config}">Bin config: </label> |
136 |
<div id="binConfigContainer"> |
|
137 |
<div id="binConfigButtonsDiv"><button type="button" id="binConfigFormatButton" th:text="#{renkanAdmin.form.space.format}" class="binConfigButton">Format</button><button type="button" id="binConfigCompactButton" th:text="#{renkanAdmin.form.space.compact}" class="binConfigButton">Compact</button></div> |
|
138 |
<div id="binConfigDiv" th:text="*{binConfig}"></div> |
|
139 |
</div> |
|
| 127 | 140 |
<div th:if="${#fields.hasErrors('binConfig')}" th:errors="*{binConfig}" class="form-error"></div> |
141 |
</div> |
|
| 123 | 142 |
|
143 |
<div class="submit"> |
|
| 127 | 144 |
<button type="submit" name="save" th:text="#{renkanAdmin.form.space.submit}">Save</button> |
145 |
<!--button type="button" name="cancel" th:text="#{renkanAdmin.form.space.cancel}" th:onclick="location">Cancel</button--> |
|
| 123 | 146 |
</div> |
147 |
||
148 |
</fieldset> |
|
149 |
</form> |
|
150 |
</div> |
|
151 |
</body> |
|
152 |
</html> |