Explorar o código

Alpha 2.3.0 fixes :
- Multiple request templates on portal
- SelectField interface stabilization
- UI fixes on portal
- Forms updates on lifecycle

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

glajarige %!s(int64=9) %!d(string=hai) anos
pai
achega
8e079c7750

+ 2 - 2
core/attributedef.class.inc.php

@@ -6036,7 +6036,7 @@ class AttributeFriendlyName extends AttributeComputedFieldVoid
 		return '\\Combodo\\iTop\\Form\\Field\\StringField';
 	}
 
-	public function GetFormField(DBObject $oObject, $oFormField = null)
+	public function MakeFormField(DBObject $oObject, $oFormField = null)
 	{
 		if ($oFormField === null)
 		{
@@ -6044,7 +6044,7 @@ class AttributeFriendlyName extends AttributeComputedFieldVoid
 			$oFormField = new $sFormFieldClass($this->GetCode());
 		}
 		$oFormField->SetReadOnly(true);
-		parent::GetFormField($oObject, $oFormField);
+		parent::MakeFormField($oObject, $oFormField);
 
 		return $oFormField;
 	}

+ 11 - 4
js/form_field.js

@@ -84,10 +84,17 @@ $(function()
 				}
 				else if($(oElem).is('select'))
 				{
-					value = [];
-					$(oElem).find('option:selected').each(function(){
-						value.push($(this).val());
-					});
+					if($(oElem).is('select[multiple]'))
+					{
+						value = [];
+						$(oElem).find('option:selected').each(function(){
+							value.push($(this).val());
+						});
+					}
+					else
+					{
+						value = $(oElem).val();
+					}
 				}
 				else if($(oElem).is(':checkbox') || $(oElem).is(':radio'))
 				{

+ 1 - 0
sources/autoload.php

@@ -31,6 +31,7 @@ require_once APPROOT . 'sources/form/field/stringfield.class.inc.php';
 require_once APPROOT . 'sources/form/field/textareafield.class.inc.php';
 require_once APPROOT . 'sources/form/field/multiplechoicesfield.class.inc.php';
 require_once APPROOT . 'sources/form/field/selectfield.class.inc.php';
+require_once APPROOT . 'sources/form/field/multipleselectfield.class.inc.php';
 require_once APPROOT . 'sources/form/field/selectobjectfield.class.inc.php';
 require_once APPROOT . 'sources/form/field/checkboxfield.class.inc.php';
 require_once APPROOT . 'sources/form/field/radiofield.class.inc.php';

+ 35 - 0
sources/form/field/multipleselectfield.class.inc.php

@@ -0,0 +1,35 @@
+<?php
+
+// Copyright (C) 2010-2016 Combodo SARL
+//
+//   This file is part of iTop.
+//
+//   iTop is free software; you can redistribute it and/or modify	
+//   it under the terms of the GNU Affero General Public License as published by
+//   the Free Software Foundation, either version 3 of the License, or
+//   (at your option) any later version.
+//
+//   iTop is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//   GNU Affero General Public License for more details.
+//
+//   You should have received a copy of the GNU Affero General Public License
+//   along with iTop. If not, see <http://www.gnu.org/licenses/>
+
+namespace Combodo\iTop\Form\Field;
+
+use \Closure;
+use \Dict;
+use \Combodo\iTop\Form\Field\SelectField;
+
+/**
+ * Description of MultipleSelectField
+ *
+ * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
+ */
+class MultipleSelectField extends SelectField
+{
+	const DEFAULT_MULTIPLE_VALUES_ENABLED = true;
+
+}

+ 13 - 0
sources/form/field/selectfield.class.inc.php

@@ -30,6 +30,7 @@ use \Combodo\iTop\Form\Field\MultipleChoicesField;
  */
 class SelectField extends MultipleChoicesField
 {
+	const DEFAULT_MULTIPLE_VALUES_ENABLED = false;
 	const DEFAULT_NULL_CHOICE_LABEL = 'UI:SelectOne';
 	const DEFAULT_STARTS_WITH_NULL_CHOICE = true;
 
@@ -75,4 +76,16 @@ class SelectField extends MultipleChoicesField
 		return $aChoices;
 	}
 
+	/**
+	 * Overloads the method to prevent changing this property.
+	 *
+	 * @param boolean $bMultipleValuesEnabled
+	 * @return \Combodo\iTop\Form\Field\SelectField
+	 */
+	public function SetMultipleValuesEnabled($bMultipleValuesEnabled)
+	{
+		// We don't allow changing this value
+		return $this;
+	}
+
 }

+ 2 - 0
sources/renderer/bootstrap/bsformrenderer.class.inc.php

@@ -44,9 +44,11 @@ class BsFormRenderer extends FormRenderer
 		$this->AddSupportedField('StringField', 'BsSimpleFieldRenderer');
 		$this->AddSupportedField('TextAreaField', 'BsSimpleFieldRenderer');
 		$this->AddSupportedField('SelectField', 'BsSimpleFieldRenderer');
+		$this->AddSupportedField('MultipleSelectField', 'BsSimpleFieldRenderer');
 		$this->AddSupportedField('RadioField', 'BsSimpleFieldRenderer');
 		$this->AddSupportedField('CheckboxField', 'BsSimpleFieldRenderer');
 		$this->AddSupportedField('SubFormField', 'BsSubFormFieldRenderer');
+		$this->AddSupportedField('SelectObjectField', 'BsSimpleFieldRenderer');
 	}
 
 }

+ 8 - 1
sources/renderer/bootstrap/fieldrenderer/bssimplefieldrenderer.class.inc.php

@@ -92,6 +92,7 @@ EOF
 					break;
 
 				case 'Combodo\\iTop\\Form\\Field\\SelectField':
+				case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
 					$oOutput->AddHtml('<div class="form-group ' . $sFieldMandatoryClass . '">');
 					if ($this->oField->GetLabel() !== '')
 					{
@@ -187,7 +188,9 @@ EOF
 						break;
 
 					case 'Combodo\\iTop\\Form\\Field\\RadioField':
-					case 'Combodo\\iTop\\Form\\Field\\SelectField': // TODO : This should be check for external key, as we would display it differently
+					case 'Combodo\\iTop\\Form\\Field\\SelectField':
+					case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
+					case 'Combodo\\iTop\\Form\\Field\\SelectObjectField': // TODO : This should be check for external key, as we would display it differently
 						$aFieldChoices = $this->oField->GetChoices();
 						$sFieldValue = (isset($aFieldChoices[$this->oField->GetCurrentValue()])) ? $aFieldChoices[$this->oField->GetCurrentValue()] : Dict::S('UI:UndefinedObject');
 
@@ -214,6 +217,8 @@ EOF
 			case 'Combodo\\iTop\\Form\\Field\\StringField':
 			case 'Combodo\\iTop\\Form\\Field\\TextAreaField':
 			case 'Combodo\\iTop\\Form\\Field\\SelectField':
+			case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
+			case 'Combodo\\iTop\\Form\\Field\\SelectObjectField':
 			case 'Combodo\\iTop\\Form\\Field\\HiddenField':
 				$oOutput->AddJs(
 <<<EOF
@@ -266,6 +271,8 @@ EOF
 		{
 			case 'Combodo\\iTop\\Form\\Field\\StringField':
 			case 'Combodo\\iTop\\Form\\Field\\SelectField':
+			case 'Combodo\\iTop\\Form\\Field\\MultipleSelectField':
+			case 'Combodo\\iTop\\Form\\Field\\SelectObjectField':
 			case 'Combodo\\iTop\\Form\\Field\\HiddenField':
 			case 'Combodo\\iTop\\Form\\Field\\RadioField':
 			case 'Combodo\\iTop\\Form\\Field\\CheckboxField':

+ 1 - 0
sources/renderer/bootstrap/fieldrenderer/bssubformfieldrenderer.class.inc.php

@@ -48,6 +48,7 @@ class BsSubFormFieldRenderer extends FieldRenderer
 			'fields_impacts' => $this->oField->GetForm()->GetFieldsImpacts(),
 			'form_path' => $this->oField->GetForm()->GetId()
 		);
+		
 		$sFieldSetOptions = json_encode($aFieldSetOptions);
 		$oOutput->AddJs(
 <<<EOF