Selaa lähdekoodia

- 'Add...' butotn is now grayed when there is nothing to Add
- Better handling of AllowedValues, supporting autocompletes
- Cleanup unused code in wizard.utils.js

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@151 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 15 vuotta sitten
vanhempi
commit
ffe1ed1fc4

+ 10 - 5
application/ui.linkswidget.class.inc.php

@@ -75,14 +75,15 @@ class UILinksWidget
 			$sHTMLValue .= "</script>\n";
 			$sHTMLValue .= $this->GetObjectPickerDialog($oPage, $sTargetClass, 'oLinkWidget'.$this->m_iInputId.'.OnOk');
 			$sHTMLValue .= $this->GetLinkObjectDialog($oPage, $this->m_iInputId);
-			$sHTMLValue .= "<input type=\"text\" id=\"ac_{$this->m_iInputId}\" size=\"35\" name=\"\" value=\"\" title=\"Type the first 3 characters\" />";
-			$sHTMLValue .= "<input type=\"button\" value=\" Add... \"  class=\"action\" onClick=\"oLinkWidget{$this->m_iInputId}.AddObject();\"/>";
+			$sHTMLValue .= "<input type=\"text\" id=\"ac_{$this->m_iInputId}\" size=\"35\" name=\"\" value=\"\" title=\"Type the first 3 characters\"/>";
+			$sHTMLValue .= "<input type=\"button\" id=\"ac_add_{$this->m_iInputId}\" value=\" Add... \"  class=\"action\" onClick=\"oLinkWidget{$this->m_iInputId}.AddObject();\"/>";
 			$sHTMLValue .= "&nbsp;<input type=\"button\" value=\"Browse...\"  class=\"action\" onClick=\"return ManageObjects('$sTitle', '$sTargetClass', '$this->m_iInputId', '$sExtKeyToRemote');\"/>";
 			// another hidden input to store & pass the object's Id
-			$sHTMLValue .= "<input type=\"hidden\" id=\"id_ac_{$this->m_iInputId}\"/>\n";
+			$sHTMLValue .= "<input type=\"hidden\" id=\"id_ac_{$this->m_iInputId}\" onChange=\"EnableAddButton('{$this->m_iInputId}');\"/>\n";
 			$sHTMLValue .= "<input type=\"hidden\" id=\"{$this->m_iInputId}\" name=\"attr_{$this->m_sAttCode}{$this->m_sNameSuffix}\" value=\"\"/>\n";
 			$oPage->add_ready_script("\$('#{$this->m_iInputId}').val('$sJSON');\noLinkWidget{$this->m_iInputId}.Init();\n\$('#ac_{$this->m_iInputId}').autocomplete('./ajax.render.php', { minChars:3, onItemSelect:selectItem, onFindValue:findValue, formatItem:formatItem, autoFill:true, keyHolder:'#id_ac_{$this->m_iInputId}', extraParams:{operation:'ui.linkswidget', sclass:'{$this->m_sClass}', attCode:'{$this->m_sAttCode}', max:30}});");
-			$oPage->add_ready_script("\$('#ac_{$this->m_iInputId}').result( function(event, data, formatted) { if (data) { $('#id_ac_{$this->m_iInputId}').val(data[1]); } } );");
+			$oPage->add_ready_script("\$('#ac_add_{$this->m_iInputId}').attr('disabled', 'disabled');");
+			$oPage->add_ready_script("\$('#ac_{$this->m_iInputId}').result( function(event, data, formatted) { if (data) { $('#id_ac_{$this->m_iInputId}').val(data[1]); $('#ac_add_{$this->m_iInputId}').attr('disabled', ''); } else { $('#ac_add_{$this->m_iInputId}').attr('disabled', 'disabled'); } } );");
 		}
 		else
 		{
@@ -221,6 +222,7 @@ class UILinksWidget
 	{
 		$sHTML = <<< EOF
 		<div class="jqmWindow" id="ManageObjectsDlg_{$this->m_iInputId}">
+		<div class="wizContainer">
 		<div class="page_header"><h1 id="Manage_DlgTitle_{$this->m_iInputId}">Selected Objects</h1></div>
 		<table width="100%">
 			<tr>
@@ -248,6 +250,7 @@ class UILinksWidget
 			</tr>
 		</table>
 		</div>
+		</div>
 EOF;
 		$oPage->add_ready_script("$('#ManageObjectsDlg_$this->m_iInputId').jqm({overlay:70, modal:true, toTop:true});"); // jqModal Window
 		//$oPage->add_ready_script("UpdateObjectList('$sClass');");
@@ -265,6 +268,7 @@ EOF;
 		$sExtKeyToRemote = $oAttDef->GetExtKeyToRemote();
 		
 		$sHTML = "<div class=\"jqmWindow\" id=\"LinkDlg_$sId\">\n";
+		$sHTML .= "<div class=\"wizContainer\">\n";
 		$sHTML .= "<div class=\"page_header\"><h1 id=\"LinkObject_DlgTitle\">$sLinkedClass attributes</h1></div>\n";
 		$sHTML .= "<form>\n";
 		$index = 0;
@@ -306,9 +310,10 @@ EOF;
 			}
 		}
 		$sHTML .= $oPage->GetDetails($aDetails);
-		$sHTML .= "<button type=\"button\" class=\"jqmClose\" onClick=\"oLinkWidget$sId.OnLinkOk()\"> Ok </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type=\"button\" class=\"jqmClose\"  onClick=\"LinkWidget$sId.OnLinkCancel()\"> Cancel</button>\n";
+		$sHTML .= "<button type=\"button\" class=\"jqmClose\" onClick=\"oLinkWidget$sId.OnLinkOk()\"> Ok </button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type=\"button\" class=\"jqmClose\"  onClick=\"oLinkWidget$sId.OnLinkCancel()\"> Cancel</button>\n";
 		$sHTML .= "</form>\n";
 		$sHTML .= "</div>\n";
+		$sHTML .= "</div>\n";
 		$oPage->add_ready_script("$('#LinkDlg_$sId').jqm({overlay:70, modal:true, toTop:true});"); // jqModal Window
 		//$oPage->add_ready_script("UpdateObjectList('$sClass');");
 		return $sHTML;

+ 6 - 5
css/jqModal.css

@@ -11,11 +11,12 @@
     display: none;
     
     position: fixed;
-    top: 10%;
-    left: 20%;
+    top: 25px;
+    left: 25px;
     
-    margin-left: -100px;
-    width: 800px;
+    nomargin-left: 25px;
+    nomargin-right: 25px;
+    nowidth: 800px;
     
     background-color: #FFF;
     color: #333;
@@ -37,4 +38,4 @@
 * removed.html .jqmWindow {
      position: absolute;
      top: expression((document.documentElement.scrollTop || document.body.scrollTop) + Math.round(17 * (document.documentElement.offsetHeight || document.body.clientHeight) / 100) + 'px');
-}
+}

+ 4 - 0
js/linkswidget.js

@@ -74,12 +74,16 @@ function LinksWidget(id, sLinkedClass, sExtKeyToMe, sExtKeyToRemote, aAttributes
 			this.aLinks.push(oLink);
 		}
 		this.Refresh();
+		// Grey out the 'Add...' button
+		$('#ac_add_'+this.id).attr('disabled', 'disabled');
 	}
 	
 	this.OnLinkCancel = function()
 	{
 		// Restore the links to their previous value (just in case)
 		this.aLinks = this.aPreviousLinks;
+		// Grey out the 'Add...' button
+		$('#ac_add_'+this.id).attr('disabled', 'disabled');
 	}
 	
 	this.RemoveLink = function(index)

+ 0 - 17
js/wizard.utils.js

@@ -24,22 +24,6 @@ function AddObject(sClass, sId, sExtKeyToRemote)
 	// Display the additional dialog
 	$('#LinkDlg_'+sId).jqmShow();
 	return;
-	
-	// TO BE REWRITTEN
-	var sRelatedObjectIds = new String($('#related_object_ids_'+sId).val());
-	if (sRelatedObjectIds.length > 0)
-	{
-		aRelatedObjectIds = sRelatedObjectIds.split(' ');
-	}
-	else
-	{
-		aRelatedObjectIds = new Array();
-	}
-	// To do: check if the ID is not already in the list...
-	aRelatedObjectIds[aRelatedObjectIds.length] = sCurrentObjectId;
-	// Update the form & reload the list
-	$('#related_object_ids').val(aRelatedObjectIds.join(' '));
-	UpdateObjectList(sClass, sExtKeyToRemote);
 }
 
 function ManageObjects(sTitle, sClass, sId, sExtKeyToRemote)
@@ -158,6 +142,5 @@ function GetObjectIds(sInputId, sExtKeyToRemote)
 		}
 	}
 	return aLinkedIds;
-	
 }
 

+ 1 - 1
js/wizardhelper.js

@@ -104,7 +104,7 @@ function WizardHelper(sClass)
 		   { operation: 'wizard_helper' },
 			function(json_data){
 				//console.log('data received:', json_data);
-				oWizardHelper.FromJSON(json_data);
+				//oWizardHelper.FromJSON(json_data);
 				oWizardHelper.UpdateFields();
 				//console.log(oWizardHelper);
 				$('#wizStep'+ G_iCurrentStep).unblock( {fadeOut: 0} );

+ 1 - 1
pages/ajax.render.php

@@ -94,7 +94,7 @@ switch($operation)
 
 		$oWizardHelper->SetAllowedValuesHtml($sAttCode, $sHTMLValue);
 	}
-	$oPage->add($oWizardHelper->ToJSON());
+	$oPage->add("<script>oWizardHelper.FromJSON(".$oWizardHelper->ToJSON().")</script>\n");
 	break;
 		
 	case 'ajax':