You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by sb...@apache.org on 2015/04/01 14:28:37 UTC

svn commit: r1670624 - in /sling/trunk/contrib/explorers/resourceeditor/src: main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js test/javascript/e2e/spec/e2e_spec.js

Author: sboehme
Date: Wed Apr  1 12:28:37 2015
New Revision: 1670624

URL: http://svn.apache.org/r1670624
Log:
fixed SLING-4559 Resource Editor :: add node dialog :: use the entered but not yet selected values of the node name and the resource type

Modified:
    sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js
    sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js

Modified: sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js?rev=1670624&r1=1670623&r2=1670624&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/main/resources/SLING-INF/libs/sling/resource-editor-static-content/js/tree/AddNodeController.js Wed Apr  1 12:28:37 2015
@@ -38,6 +38,8 @@ org.apache.sling.reseditor.AddNodeContro
 		this.showAllNodeTypes = false;
 		this.nodeTypeObjects = [];
 		this.nodeType="";
+		this.latestEnteredNodeName="";
+		this.latestEnteredResType="";
 		
 		var thatAddNodeController = this;
 		$(document).ready(function() {
@@ -63,7 +65,7 @@ org.apache.sling.reseditor.AddNodeContro
 			$("body").on('keydown', function (e) {
 		    	// see http://www.javascripter.net/faq/keycodes.htm
 				var aKey = 65;
-		    	if (e.ctrlKey && aKey==e.which) {
+		    	if (e.ctrlKey && aKey==e.which) { /*ctrl-a*/
 		    		if (thatAddNodeController.dialogShown){
 		    			thatAddNodeController.addNode();
 		    		}
@@ -74,10 +76,9 @@ org.apache.sling.reseditor.AddNodeContro
 
 	AddNodeController.prototype.addNode = function() {
 		var thatAddNodeController = this;
-		var nodeName = $("#nodeName").val().trim();
+		var nodeName = this.latestEnteredNodeName.trim();
 		var nodeType = $("#nodeType").val();
-		var resourceTypeData = $("#resourceType").select2('data');
-		var resourceType = resourceTypeData != null ? resourceTypeData.text.trim() : "";
+		var resourceType = (this.latestEnteredResType != null && this.latestEnteredResType != "") ? this.latestEnteredResType.trim() : "";
 		
 		var data = {"_charset_": "utf-8"};
 		if ("" != nodeType){
@@ -204,12 +205,20 @@ org.apache.sling.reseditor.AddNodeContro
 		$("#nodeName").select2({
 			placeholder: "Enter or select a node name",
 			allowClear: true, 
+			selectOnBlur: true,
 			data: nodeNameObjects,
 			createSearchChoice: function(searchTerm){
 				return {id:searchTerm, text:searchTerm};
 			}
 		});
-
+		$("#nodeName").on("select2-highlight", function(e) { 
+			/* In Select2 there is currently no way of getting
+			 * the highlighted (newly entered but not yet selected) text.
+			 * But there is this event. Thats why I use this one. 
+			 */ 
+			thatAddNodeController.latestEnteredNodeName=e.val;
+		})
+		
 		var nodeNameList = Object.keys(appliCnTypesByNodeName);
 		nodeNameList.sort();
 		thatAddNodeController.nodeTypeObjects = getNodeTypesByDependenyState.call(thatAddNodeController, nodeNameList, appliCnTypesByNodeName, thatAddNodeController.nodeTypeObjects);
@@ -234,6 +243,7 @@ org.apache.sling.reseditor.AddNodeContro
 		$("#nodeType").select2({
 			placeholder: "Select a node type",
 			allowClear: true,  
+			selectOnBlur: true,
 			data: function() { 
 			      return { results: thatAddNodeController.nodeTypeObjects } ; // Use the global variable to populate the list
 		    }
@@ -257,11 +267,19 @@ org.apache.sling.reseditor.AddNodeContro
 			var select2 = $("#resourceType").select2({
 				placeholder: "Enter or select a resource type",
 				allowClear: true, 
+				selectOnBlur: true,
 				data: data,
 				createSearchChoice: function(searchTerm){
 					return {id:searchTerm, text:searchTerm};
 				}
 			}).data("select2");
+			$("#resourceType").on("select2-highlight", function(e) {
+				/* In Select2 there is currently no way of getting
+				 * the highlighted (newly entered but not yet selected) text.
+				 * But there is this event. Thats why I use this one. 
+				 */ 
+				thatAddNodeController.latestEnteredResType=e.val;
+			})
 		});
 	}
 	

Modified: sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js?rev=1670624&r1=1670623&r2=1670624&view=diff
==============================================================================
--- sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js (original)
+++ sling/trunk/contrib/explorers/resourceeditor/src/test/javascript/e2e/spec/e2e_spec.js Wed Apr  1 12:28:37 2015
@@ -3,9 +3,12 @@
 var assert = require('assert');
 
 describe('The Apache Sling Resource Editor', function() {
+	browser = browser.url('http://localhost:8080/reseditor/.html');
+	// Find a way to specify the host and the port via grunt. See 
+	// http://stackoverflow.com/questions/29370075/how-to-pass-parameters-from-the-gruntfile-js-to-the-webdriverio-spec
+	
 	  it('should have a title', function(done) {
 		  browser
-	      .url('http://localhost:8080/reseditor/.html')
 	      .getTitle(function(err,title) {
 	          assert(title.indexOf('Apache Sling Resource Editor') !== -1);
 	      })