Commits

bsiri  committed c991c87

[Issue 1427] reworking the renaming system.

  • Participants
  • Parent commits afe87f4

Comments (0)

Files changed (6)

File tm/tm.web/src/main/webapp/WEB-INF/tags/layout/workspace-page-layout.tag

 <layout:tree-page-layout titleKey="squashtm" highlightedWorkspace="${ resourceName }" linkable="${linkable}">
 	<jsp:attribute name="head">
 		<comp:rich-jeditable-header />
-		<script type="text/javascript">
-			
-			function renameSelectedNreeNode(name){
-				var node = $('#tree').jstree("get_selected");
-				$('#tree').jstree("set_text",node,name); //we don't want rename-node() since we use our own renaming interface
-			}
-			//update the selected node name attribute
-			function updateSelectedNodeName(newName){
-				var node = $('#tree').jstree("get_selected");
-				node.attr('name', newName);
-			}
-
-	
-			//success handler for a renaming operation
-			function rename_from_tree_sucess(data) {
-				//change the node name attribute
-				updateSelectedNodeName(data.newName);
-				//get the node
-				var node = $('#tree').jstree("get_selected");
-				//check if there's a prefix to the name
-				var checkedName = getRealNodeName(data.newName, node);
-				//performed if the node is displayed  in the contextual content
-				updateFragmentPageData(data.newName, checkedName);
-				
-				//rename the node in the tree
-				renameSelectedNreeNode(checkedName);
-
-				//close the pop-up
-				$('#rename-node-dialog' ).dialog( 'close' );
-			}
-			
-	
-			
-			function rename_from_tree_failed(xhr){
-				$('#rename-node-dialog .popup-label-error')
-				.html(xhr.statusText);								
-			}
-
-			
-			<c:choose>
-				<c:when test="${ resourceName eq 'campaign' }">
-					function getRealNodeName(name, node){
-						var toReturn = name;
-						//check if there's an index
-						if(node.attr('iterationIndex') != null){
-							toReturn = node.attr('iterationIndex') + " - " + name;
-						}
-						return toReturn;
-					}
-					//external calls ie fragment js functions
-					function updateFragmentPageData(rawName, completeName){
-						//declare a hook to rename the label
-						if (typeof nodeSetname == 'function'){
-							nodeSetname(rawName);
-						}
-					}
-					//only for campaign : get the iteration index
-					function getSelectedNodeIndex(){
-						return $('#tree').jstree("get_selected").attr('iterationIndex');
-					}
-				</c:when>
-				<c:when test="${ (resourceName eq 'requirement') or (resourceName eq 'test-case') }">
-					function getRealNodeName(name, node){
-						var toReturn = name;
-						//check if there's a reference
-						if(node.attr('reference') != null){
-							toReturn = node.attr('reference') + " - " + name;
-						}
-						return toReturn;
-					}
-					function updateFragmentPageData(rawName, completeName){
-						if (typeof nodeSetname == 'function'){
-							nodeSetname(completeName);
-						}
-						if (typeof updateRawNameHiddenField == 'function'){
-							updateRawNameHiddenField(rawName);
-						}
-					}
-				</c:when>
-				<c:otherwise>
-					function getRealNodeName(name, node){
-						return name;
-					}
-					function updateFragmentPageData(rawName, completeName){
-						if (typeof nodeSetname == 'function'){
-							nodeSetname(rawName);
-						}
-					}
-				</c:otherwise>
-			</c:choose>
-		</script>		
+		
 		
 		<jsp:invoke fragment="head" />
 	</jsp:attribute>
 		<treepopup:add-nameable-node-dialog resourceName="folder" treeNodeButton="squashtm.treemenu.create.buttons['create-folder']"/>
 		<treepopup:add-nameable-node-dialog resourceName="${ resourceName }"  treeNodeButton="squashtm.treemenu.create.buttons['create-file']"/>
 	
-		<treepopup:rename-node-dialog treeSelector="#tree" successCallback="rename_from_tree_sucess" treeNodeButton="squashtm.treeButtons['rename']"/>
+		<treepopup:rename-node-dialog treeSelector="#tree" treeNodeButton="squashtm.treeButtons['rename']"/>
 		<treepopup:delete-node-dialog treeSelector="#tree" resourceName="${resourceName}" treeNodeButton="squashtm.treeButtons['delete']"/>
 
 		<treepopup:copy-paste-node treeSelector="#tree" resourceName="${resourceName}" 

File tm/tm.web/src/main/webapp/WEB-INF/tags/treepopups/rename-node-dialog.tag

 
 
 <%@ attribute name="treeSelector" description="jQuerySelector for the tree."%>
-<%@ attribute name="successCallback" description="javascript callback in case of success."%>
 <%@ attribute name="treeNodeButton" required="true" description="the javascript button that will open the dialog" %>
 
 		
 		<f:message var="label" key="dialog.rename.confirm.label" />	
 		"${ label }": function() {
 			
-			var url = $('${treeSelector}').jstree('get_selected').getResourceUrl();
+			var node = $('${treeSelector}').jstree('get_selected');
+			var url = node.getResourceUrl();
+
 			var name = $('#rename-tree-node-text').val();
 			
 			$.ajax({
 				data : { 'newName' : name },
 				dataType : 'json'		
 			})
-			.success(${successCallback});
+			.success(function(){
+				var event = new EventRename(
+					new SquashEventObject(node.getResId(), node.getResType()),
+					name
+				);
+				squashtm.contextualContent.fire(null, event);
+			});
 	
 		},
 	<pop:cancel-button />

File tm/tm.web/src/main/webapp/scripts/squashtest/classes/Event.js

 	this.obj_id = id;
 	this.obj_restype = restype;
 }
+
 function SquashEvent(name) {
 	this.evt_name = name;
 }
+
+//'paste' event, inheriting base event
 function EventPaste(destination) {
 	this.base = SquashEvent;
 	this.base("paste");
 }
 EventPaste.prototype = new SquashEvent;
 
+
+//'duplicate' event, inheriting paste
 function EventDuplicate(destination, duplicate, source) {
 	this.base = EventPaste;
 	this.base(destination);
 	this.evt_duplicate = duplicate;
 	this.evt_source = source;
 }
-EventDuplicate.prototype = new EventPaste;
+EventDuplicate.prototype = new EventPaste;
+
+
+//'rename' event, inheriting base event
+function EventRename(target, newName){
+	this.base = SquashEvent;
+	this.base('rename');
+	this.evt_target = target;
+	this.evt_newname = newName;
+}
+
+EventRename.prototype = new SquashEvent;
+
+//'update reference', inheriting base event
+function EventUpdateReference(target, newReference){
+	this.base = SquashEvent;
+	this.base('update-reference');
+	this.evt_target = target;
+	this.evt_newref = newReference;
+}
+
+EventUpdateReference.prototype = new SquashEvent;

File tm/tm.web/src/main/webapp/scripts/squashtest/classes/TreeEventHandler.js

 		// todo : make something smarter
 		switch(event.evt_name){
 			case "paste" : updateEventPaste(event, this.tree); break;
+			case "rename" : updateEventRename(event, this.tree); break;
+			case "update-reference" : updateEventUpdateReference(event, this.tree); break;
 			default : this.tree.refresh_selected(); break;
 		}
  	}
  		}	
  	});
 
+ }
+ 
+ 
+ function updateEventRename(event, tree){
+	 
+	 var target = tree.findNodes({
+		 restype : event.evt_target.obj_restype,
+		 resid : event.evt_target.obj_id
+	 });
+	 
+	 if (target.length===0) return;
+	 
+	 target.setName(event.evt_newname);
+	 
+ }
+ 
+ function updateEventUpdateReference(event, tree){
+	 var target = tree.findNodes({
+		 restype : event.evt_target.obj_restype,
+		 resid : event.evt_target.obj_id
+	 });
+	 
+	 if (target.length===0) return;
+	 
+	 target.setReference(event.evt_newref);
  }

File tm/tm.web/src/main/webapp/scripts/squashtest/jquery.squashtm.contextual-content.js

 			_cleanPopups();
 			this.empty();
 			this.listeners = [];
-			if (this.onCleanContent != null) {
+			if (this.onCleanContent !== null) {
 				this.onCleanContent();
 				this.onCleanContent = null;
 			}

File tm/tm.web/src/main/webapp/scripts/squashtest/jquery.squashtm.jstree-node.js

 			}
 		}
 	}
+	
+	
+	var buildRefreshLabel = function(treeNode){
+		
+		switch(treeNode.getResType()){
+		case "requirements" :
+		case "test-cases" :
+			return function(){
+				var name = this.getName();
+				var reference = this.getReference() || "";
+				if (reference.length>0){
+					reference+=" - ";
+				}
+				this.getTree().set_text(this, reference+name);
+			};
+			break;
+			
+		case "iterations" :
+			return function(){
+				var name = this.getName();
+				var index = this.getIndex() || "";
+				if (index.length>0){
+					index+=" - ";
+				};
+				this.getTree().set_text(this, index+name);
+			};
+			break;
+			
+		default :
+			return function(){
+				var name = this.getName();
+				this.getTree().set_text(this, name);
+			}
+			break;
+		}
+		
+	}
 
 	$.fn.treeNode = function () {
 
 		this.getName = function () {
 			return this.reference.attr('name');
 		};
+		
+		this.getReference = function(){
+			return this.reference.attr('reference');
+		};
+		
+		this.getIndex = function(){
+			return this.reference.attr('iterationIndex');			
+		};
 
 		this.getPath = function() {
 			return this.getAncestors().all('getName').join().replace(/,/g, '/');
 		this.getProjectId = function(){
 			return this.getLibrary().attr('project');
 		};
+		
+		// ************ some setters **************
+		
+		this.setName = function(name){
+			this.reference.attr('name', name);
+			this.refreshLabel();
+		};
+		
+		this.setReference = function(reference){
+			this.reference.attr('reference', reference);
+			this.refreshLabel();
+		}
 
 		// ************ relationships getters
 
 		};
 
 		this.getContentUrl = buildGetContent(this);
+		this.refreshLabel = buildRefreshLabel(this);
+		
 
 		this.getCopyUrl = function () {
 			switch (this.getDomType()) {