Scarab commit: svn commit: r10786 - trunk/src: java/org/tigris/scarab/om webapp/WEB-INF/templates/layouts webapp/WEB-INF/templates/macros webapp/scripts webapp/skins

Hussayn Dabbous <[email protected]>
Newsgroups gmane.comp.java.scarab.cvs
Message-ID <[email protected]>
Author: dabbous
Date: 2009-07-12 01:04:23-0700
New Revision: 10786

Modified:
   trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java
   trunk/src/webapp/WEB-INF/templates/layouts/Default.vm
   trunk/src/webapp/WEB-INF/templates/macros/GlobalMacros.vm
   trunk/src/webapp/scripts/sstree.js
   trunk/src/webapp/skins/classic.css
   trunk/src/webapp/skins/custom.css

Log:
SCB2979: 

fixed: Problem with conditional workflow. The new treeview did not check for canMakeTransition. The whole processing has been moved from velocity to AbstractScarabModule.java for now (will be moved to the notification framework later).

improved the style of the popup treeview.

Modified: trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java?view=diff&pathrev=10786&r1=10785&r2=10786
==============================================================================
--- trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java	(original)
+++ trunk/src/java/org/tigris/scarab/om/AbstractScarabModule.java	2009-07-12 01:04:23-0700
@@ -57,6 +57,7 @@
 import java.util.Map;
 import java.util.Vector;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.fulcrum.localization.Localization;
 import org.apache.fulcrum.security.entity.Group;
 import org.apache.regexp.RECompiler;
@@ -69,10 +70,14 @@
 import org.apache.torque.om.ComboKey;
 import org.apache.torque.om.SimpleKey;
 import org.apache.torque.util.Criteria;
+import org.apache.turbine.RunData;
+import org.apache.turbine.TemplateContext;
 import org.apache.turbine.Turbine;
 import org.tigris.scarab.reports.ReportBridge;
 import org.tigris.scarab.services.cache.ScarabCache;
 import org.tigris.scarab.services.security.ScarabSecurity;
+import org.tigris.scarab.tools.ScarabGlobalTool;
+import org.tigris.scarab.tools.ScarabRequestTool;
 import org.tigris.scarab.tools.localization.L10NKey;
 import org.tigris.scarab.tools.localization.L10NKeySet;
 import org.tigris.scarab.tools.localization.L10NMessage;
@@ -1533,22 +1538,29 @@
         return moduleOptions;
     }
 
-    public String getOptionsTreeAsJSON(Attribute attribute, IssueType issueType, boolean activeOnly) throws TorqueException {
-    	List<RModuleOption> moduleOptions = (List<RModuleOption>) getRModuleOptions(attribute, issueType, activeOnly);
+    public String getOptionsTreeAsJSON(RunData data, String fromValue, Attribute attribute, Issue issue, boolean activeOnly) throws TorqueException {    
+    	System.out.println(attribute.getName());
+    	
+    	List<RModuleOption> moduleOptions = (List<RModuleOption>) getRModuleOptions(attribute, issue.getIssueType(), activeOnly);
     		if (moduleOptions == null) {
     			return null;
     		}    	
     	    		
-    		StringBuffer json = new StringBuffer("{ 'optionId' : 0, 'displayValue' : 'root', '_children': [");
+    		StringBuffer json = new StringBuffer("{ 'attributeId' : ");    		
+    		json.append(attribute.getAttributeId());
+    		json.append(", 'name' : '");
+    		json.append(attribute.getName());
+    		json.append("', '_children': [");
     		
 			boolean first = true;
 			
     		for (RModuleOption moduleOption : moduleOptions) {    			
+        		if (!AbstractScarabModule.canMakeTransitionForOption(data, fromValue, moduleOption, issue, false)) continue;
     			if (moduleOption.getAttributeOption().getAncestors().size() == 1) {
     				if (!first) {
     					json.append(", ");
     				}
-					json.append(this.getModuleOptionAsJSON(moduleOption));
+					json.append(this.getModuleOptionAsJSON(data, fromValue, attribute, issue, moduleOption));
     				first = false;
     			}
     		}
@@ -1558,7 +1570,7 @@
     		return json.toString();
     }
     
-    private String getModuleOptionAsJSON(RModuleOption moduleOption) throws TorqueException {
+    private String getModuleOptionAsJSON(RunData data, String fromValue, Attribute attribute, Issue issue, RModuleOption moduleOption) throws TorqueException {
     	StringBuffer json = new StringBuffer("{ 'optionId': ");
     	json.append(moduleOption.getOptionId());
     	json.append(", 'displayValue': '");
@@ -1568,10 +1580,11 @@
 		boolean first = true;
 
     	for (RModuleOption rmo : (List<RModuleOption>) moduleOption.getDescendants(moduleOption.getIssueType())) {
+    		if (!AbstractScarabModule.canMakeTransitionForOption(data, fromValue, rmo, issue, false)) continue;
 			if (!first) {
 				json.append(", ");
 			}
-			json.append(this.getModuleOptionAsJSON(rmo));
+			json.append(this.getModuleOptionAsJSON(data, fromValue, attribute, issue, rmo));
 			first = false;
     	}
 
@@ -1579,6 +1592,45 @@
     	
     	return json.toString();
     }
+        
+    /**
+     * Implements CanMakeTransitionForOption from GlobalMacros.vm
+     * 
+     * @param fromValue
+     * @param option
+     * @param issue
+     * @param multiple
+     * @return
+     */
+    private static boolean canMakeTransitionForOption(RunData data, String fromValue, RModuleOption option, Issue issue, boolean multiple) {
+    	TemplateContext context = org.apache.turbine.modules.Module.getTemplateContext(data);
+        ScarabRequestTool scarabR = (ScarabRequestTool) context.get(ScarabConstants.SCARAB_REQUEST_TOOL);
+    	
+    	boolean selected = false;
+    	boolean canMakeTransition = true;
+    	
+		try {
+	    	if (StringUtils.isNotEmpty(fromValue)) {
+	    		if (!multiple) {
+	    			if (issue.isTemplate()) {
+						canMakeTransition = ScarabGlobalTool.getWorkflow().canMakeTransition((ScarabUser) data.getUser(), scarabR.getAttributeOption("0"), option.getAttributeOption(), issue);
+	    			}
+	    			else {
+						canMakeTransition = ScarabGlobalTool.getWorkflow().canMakeTransition((ScarabUser) data.getUser(), scarabR.getAttributeOption(issue.isNew() ? "0" : fromValue), option.getAttributeOption(), issue);	    				
+	    			}
+	    		}
+	    	}
+	    	else {
+				canMakeTransition = ScarabGlobalTool.getWorkflow().canMakeTransition((ScarabUser) data.getUser(), scarabR.getAttributeOption("0"), option.getAttributeOption(), issue);	    		
+	    	}
+		}
+		catch (Exception e) {
+			e.printStackTrace();
+			return false;
+		}
+    			
+    	return canMakeTransition;
+    }
     
     
     /** 

Modified: trunk/src/webapp/WEB-INF/templates/layouts/Default.vm
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/webapp/WEB-INF/templates/layouts/Default.vm?view=diff&pathrev=10786&r1=10785&r2=10786
==============================================================================
--- trunk/src/webapp/WEB-INF/templates/layouts/Default.vm	(original)
+++ trunk/src/webapp/WEB-INF/templates/layouts/Default.vm	2009-07-12 01:04:23-0700
@@ -314,7 +314,7 @@
 
  ## render the popup used to display selection trees
  #foreach ($attributeTreePopup in $attributeTreePopupHelper)
-  <script type="text/javascript">renderJSONTreePopup('$attributeTreePopup.get(0)', '$attributeTreePopup.get(1)', $attributeTreePopup.get(2));</script>
+  <script type="text/javascript">renderJSONTreePopup('$attributeTreePopup.get(0)', '$attributeTreePopup.get(1)', $attributeTreePopup.get(2), '$staticLink.setPath("/images")');</script>
  #end
  
 </body>

Modified: trunk/src/webapp/WEB-INF/templates/macros/GlobalMacros.vm
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/webapp/WEB-INF/templates/macros/GlobalMacros.vm?view=diff&pathrev=10786&r1=10785&r2=10786
==============================================================================
--- trunk/src/webapp/WEB-INF/templates/macros/GlobalMacros.vm	(original)
+++ trunk/src/webapp/WEB-INF/templates/macros/GlobalMacros.vm	2009-07-12 01:04:23-0700
@@ -99,7 +99,7 @@
   #set ($attributeTreePopup = [])
   #set ($dummy = $attributeTreePopup.add($attrInput.get($optionFieldName).Key) )
   #set ($dummy = $attributeTreePopup.add($newValues) )
-  #set ($dummy = $attributeTreePopup.add($module.getOptionsTreeAsJSON($attr, $attrValue.Issue.IssueType, false)) )
+  #set ($dummy = $attributeTreePopup.add($module.getOptionsTreeAsJSON($data, $newValues.toString(), $attr, $attrValue.Issue, false)) )
   
   #set ($dummy = $attributeTreePopupHelper.add($attributeTreePopup) )
 

Modified: trunk/src/webapp/scripts/sstree.js
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/webapp/scripts/sstree.js?view=diff&pathrev=10786&r1=10785&r2=10786
==============================================================================
--- trunk/src/webapp/scripts/sstree.js	(original)
+++ trunk/src/webapp/scripts/sstree.js	2009-07-12 01:04:23-0700
@@ -72,31 +72,31 @@
 }
 
 
-function renderJSONTreePopup(key, value, root) {
+function renderJSONTreePopup(key, value, root, imgpath) {
 	document.writeln('<div id="' + key + ':Popup" class="tree_popup"><ol class="treeview root">');		
 	for (var i = 0; i < root._children.length; i++) {			
-		renderJSONTree(key, value, root._children[i]);						
+		renderJSONTree(root.attributeId, key, value, root._children[i], imgpath);						
 	}
 	document.writeln('</ol></div>');	
 }
 
-function renderJSONTree(key, value, root) {
+function renderJSONTree(attributeId, key, value, root, imgpath) {
 	if (root.optionId == value) {
 		document.getElementById(key + ':Display').value = root.displayValue;	
 	}	
 	
-	document.writeln('<li>');
-
 	if (root._children.length > 0) {
-		document.writeln('<a class="folder" onclick="toggle(this,\'/scarab/images\');"></a><a href="javascript:clickTree(\'' + key + '\', \'' + root.optionId + '\', \'' + root.displayValue + '\');">' + root.displayValue + '</a>');
+		document.writeln('<li>');
+		document.writeln('<a class="folder" onclick="toggle(this,\''+imgpath+'\');"></a><a href="javascript:clickTree(' + attributeId + ', \'' + key + '\', \'' + root.optionId + '\', \'' + root.displayValue + '\');">' + root.displayValue + '</a>');
 		document.writeln('<ol class="treeview">');			
 		for (var i = 0; i < root._children.length; i++) {			
-			renderJSONTree(key, value, root._children[i]);						
+			renderJSONTree(attributeId, key, value, root._children[i],imgpath);						
 		}
 		document.writeln('</ol>');	
 	}
 	else {
-		document.writeln('<a href="javascript:clickTree(\'' + key + '\', \'' + root.optionId + '\', \'' + root.displayValue + '\');">' + root.displayValue + '</a>');
+		document.writeln('<li class="leaf">');
+		document.writeln('<a href="javascript:clickTree(' + attributeId + ', \'' + key + '\', \'' + root.optionId + '\', \'' + root.displayValue + '\');">' + root.displayValue + '</a>');
 	}
 	
 	document.writeln('</li>');
@@ -138,7 +138,8 @@
 	}
 }
 
-function clickTree(key, value, display) {
+function clickTree(attributeId, key, value, display) {
+	//alert(attributeId);
 	document.getElementById(key).value = value;
 	document.getElementById(key + ':Display').value = display;
 	document.getElementById(key + ':Popup').style.display = 'none';				

Modified: trunk/src/webapp/skins/classic.css
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/webapp/skins/classic.css?view=diff&pathrev=10786&r1=10785&r2=10786
==============================================================================
--- trunk/src/webapp/skins/classic.css	(original)
+++ trunk/src/webapp/skins/classic.css	2009-07-12 01:04:23-0700
@@ -252,6 +252,25 @@
 }
 
 
+/* ============================================================== */
+/* Issue editor                                                   */
+/* ============================================================== */
+
+#properties div.header{
+}
+#properties div.header div.group {
+	float:left;
+	display:inline;
+	padding-bottom:10px;
+}
+#properties div.header div.group th {
+	background-color: #E9F1F9;
+}
+#properties div.header div.group td {
+	font-size:0.9em;
+}
+
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 /* ==== From here on downwards the refactoring must still take place. ==== */
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Modified: trunk/src/webapp/skins/custom.css
Url: http://scarab.tigris.org/source/browse/scarab/trunk/src/webapp/skins/custom.css?view=diff&pathrev=10786&r1=10785&r2=10786
==============================================================================
--- trunk/src/webapp/skins/custom.css	(original)
+++ trunk/src/webapp/skins/custom.css	2009-07-12 01:04:23-0700
@@ -62,13 +62,16 @@
 
 
 div.tree_popup {
-	background-color: white;
+	background-color: #ffffe8;
 	display: none;	
 	max-height: 200px;
 	overflow-x: hidden;
 	overflow-y: auto;
 	position: absolute;
-	width: 300px;
+	width: 200px;
+	border-style:dotted;
+	border-width:1px;
+	border-color:#92b9d8;
 }
 
 div.tree_popup ol.treeview {
@@ -77,11 +80,21 @@
 	margin: 0px;
 }
 
+div.tree_popup ol.treeview li a.folder {
+	padding-left:0px;
+}
+
 div.tree_popup ol.treeview li {
 	font-size: x-small;
 	margin-bottom: 1px;
 	margin-top: 3px;
-	padding-left: 40px;
+	padding-left: 15px;
+}
+
+div.tree_popup ol.treeview li a {
+	color:#000;
+	font-weight:bold;
+	text-decoration:none;
 }
 
 .asterisk {

------------------------------------------------------
http://scarab.tigris.org/ds/viewMessage.do?dsForumId=3577&dsMessageId=2370735
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.