In the admin for space:
authorymh <ymh.work@gmail.com>
Fri, 05 Apr 2013 13:59:23 +0200
changeset 141 64af5273ac5e
parent 140 4ed1664b6087
child 142 4eaab4054132
In the admin for space: - Add a link to open a space - add two button to format (pretty print) or compact the json - use soft tab of size 2 for ace editor
server/src/main/webapp/WEB-INF/i18n/messages_en.properties
server/src/main/webapp/WEB-INF/i18n/messages_fr.properties
server/src/main/webapp/WEB-INF/templates/admin/spacesList.html
server/src/main/webapp/WEB-INF/templates/fragment/spaceForm.html
server/src/main/webapp/static/css/index.css
--- a/server/src/main/webapp/WEB-INF/i18n/messages_en.properties	Fri Apr 05 13:57:05 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/i18n/messages_en.properties	Fri Apr 05 13:59:23 2013 +0200
@@ -45,6 +45,7 @@
 renkanAdmin.space_add = Add space
 renkanAdmin.space_edit = Edit space
 renkanAdmin.space_delete = Delete space
+renkanIndex.space_url = Url
 renkanAdmin.space_confirm_delete = Do you want to delete the space entitled "{0}" ?
 
 renkanAdmin.object_name = Name
@@ -60,6 +61,8 @@
 renkanAdmin.form.space.bin_config = Bin config
 renkanAdmin.form.space.submit = Ok
 renkanAdmin.form.space.cancel = Cancel
+renkanAdmin.form.space.format = Format
+renkanAdmin.form.space.compact = Compact
 
 renkan.error.title.empty = Title must not be empty or null
 renkan.error.bin_config.json = bin config field must contain a valid json
--- a/server/src/main/webapp/WEB-INF/i18n/messages_fr.properties	Fri Apr 05 13:57:05 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/i18n/messages_fr.properties	Fri Apr 05 13:59:23 2013 +0200
@@ -43,6 +43,7 @@
 renkanAdmin.space_add = Nouvel espace
 renkanAdmin.space_edit = Edition espaces
 renkanAdmin.space_delete = Supression espace
+renkanIndex.space_url = Url
 renkanAdmin.space_confirm_delete = Confirmez-vous l'effacement de l'espace intitulé "{0}" ?
 
 renkanAdmin.object_name = Nom
@@ -58,6 +59,8 @@
 renkanAdmin.form.space.bin_config = Config chutier
 renkanAdmin.form.space.submit = Ok
 renkanAdmin.form.space.cancel = Annuler
+renkanAdmin.form.space.format = Formatter
+renkanAdmin.form.space.compact = Compacter
 
 renkan.error.title.empty = Le champ titre ne doit pas ĂȘtre vide
 renkan.error.bin_config.json = le champ bin config doit contenir un json valide
\ No newline at end of file
--- a/server/src/main/webapp/WEB-INF/templates/admin/spacesList.html	Fri Apr 05 13:57:05 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/templates/admin/spacesList.html	Fri Apr 05 13:59:23 2013 +0200
@@ -44,6 +44,7 @@
                 <th th:text="#{renkanAdmin.object_name}" class="spaces-table-title">Name</th>
                 <th th:text="#{renkanAdmin.object_name}" class="spaces-table-created">Created</th>
                 <th th:text="#{renkanIndex.space_proj_count}">Project count</th>
+                <th th:text="#{renkanIndex.space_url}">url</th>
                 <th th:text="#{renkanAdmin.object_edit}" class="spaces-table-actions">Edit</th>
                 <th th:text="#{renkanAdmin.object_delete}" class="spaces-table-actions">Delete</th>
               </tr>
@@ -53,6 +54,7 @@
                 <td th:text="${object.title}" class="spaces-table-title" >title</td>
                 <td th:text="${object.created}?${#dates.format(object.created, #messages.msg('date.format'))}:'n/a'" class="spaces-table-created">created</td>
                 <td th:text="${spaceProjCount}">nb. proj</td>
+                <td><a href="../renkanIndex.html" th:href="@{'/s/'+${object.id}}" th:text="#{renkanIndex.space_url}">url</a></td>
                 <td><a href="spaceEdit.html" th:href="@{'/admin/spaces/edit/'+${object.id}}" th:text="#{renkanAdmin.object_edit_link}" class="spaces-table-actions">Edit</a></td>
                 <td><a href="#" th:if="${spaceProjCount==0}" th:href="@{'/admin/spaces/delete/'+${object.id}}" th:text="#{renkanAdmin.object_delete_link}" class="spaces-table-actions">Delete</a><span th:if="${spaceProjCount>0}" class="spaces-table-actions spaces-table-actions-disabled" th:text="#{renkanAdmin.object_delete_link}">Delete</span></td>
               </tr>
--- a/server/src/main/webapp/WEB-INF/templates/fragment/spaceForm.html	Fri Apr 05 13:57:05 2013 +0200
+++ b/server/src/main/webapp/WEB-INF/templates/fragment/spaceForm.html	Fri Apr 05 13:59:23 2013 +0200
@@ -45,13 +45,61 @@
             return valid;
         }
         
+        function formatJson(jsonText, tabSize) {
+        	var obj = JSON.parse(jsonText);
+        	return JSON.stringify(obj, undefined, tabSize);
+        }
+        function compactJson(jsonText) {
+        	var obj = JSON.parse(jsonText);
+        	return JSON.stringify(obj);
+        }
+        
+        function _setBinConfigStatus(editor) {
+            var annotations = editor.getSession().getAnnotations();
+            if(annotations.length>0) {
+                $('.binConfigButton').attr("disabled", "disabled");                 
+            }
+            else {
+                $('.binConfigButton').removeAttr("disabled");
+            }        	
+        }
+        
         $(function(){
+        	var tabSize = 2;
             var editor = ace.edit("binConfigDiv");
             editor.setTheme("ace/theme/xcode");
             editor.getSession().setMode("ace/mode/json");
+            editor.getSession().setTabSize(tabSize);
+            editor.getSession().setUseSoftTabs(true);
+            _setBinConfigStatus(editor);
             editor.getSession().on('change', function(e) {
             	$('#binConfig').val(editor.getValue());
             });
+            editor.getSession().on('changeAnnotation', function() {
+                _setBinConfigStatus(editor);
+            });
+            
+            $('#binConfigFormatButton').click(function(){
+            	var jsonText = editor.getValue();
+            	try {
+					editor.setValue(formatJson(jsonText, tabSize),0);
+					editor.moveCursorTo(0,0);
+					editor.clearSelection();
+				} catch (e) {
+					//do nothing
+				}
+            });
+            
+            $('#binConfigCompactButton').click(function(){
+                var jsonText = editor.getValue();
+                try {
+                    editor.setValue(compactJson(jsonText),0);
+                    editor.moveCursorTo(0,0);
+                    editor.clearSelection();
+                } catch (e) {
+                    //do nothing
+                }
+            });
             
             $('#color').spectrum({
             	showInput: true,
@@ -84,8 +132,11 @@
          <input type="text" th:field="*{color}" /> 
        </div>
        <div>
-         <label for="binConfigDiv" th:text="#{renkanAdmin.form.space.bin_config}">Bin config: </label> 
-         <div id="binConfigDiv" th:text="*{binConfig}"></div>
+         <label for="binConfigContainer" th:text="#{renkanAdmin.form.space.bin_config}">Bin config: </label>
+         <div id="binConfigContainer">
+           <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>
+           <div id="binConfigDiv" th:text="*{binConfig}"></div>
+         </div>
          <div th:if="${#fields.hasErrors('binConfig')}" th:errors="*{binConfig}" class="form-error"></div>
        </div> 
 
--- a/server/src/main/webapp/static/css/index.css	Fri Apr 05 13:57:05 2013 +0200
+++ b/server/src/main/webapp/static/css/index.css	Fri Apr 05 13:59:23 2013 +0200
@@ -224,7 +224,7 @@
 	text-align: center;
 }
 
-.form-fields label, .form-fields input, .form-fields textarea, .form-fields #binConfigDiv {
+.form-fields label, .form-fields input, .form-fields textarea, .form-fields #binConfigContainer {
   display:inline-block;
 }
 
@@ -256,6 +256,13 @@
     height: 150px;
 }
 
+.binConfigButton {
+	font-weight: normal;
+}
+.binConfigButton[disabled] {
+    color: graytext;
+}
+
 #binConfigDiv div {
     margin-bottom: 0; 
 }