diff --git a/application/forms.class.inc.php b/application/forms.class.inc.php index 283965be9..908c00f1b 100644 --- a/application/forms.class.inc.php +++ b/application/forms.class.inc.php @@ -395,6 +395,7 @@ EOF { foreach($aFields as $oField) { + /** @var \DesignerFormField $oField */ $oField->ReadParam($aValues); } } @@ -679,18 +680,34 @@ class DesignerTabularForm extends DesignerForm class DesignerFormField { + /** @var string $sLabel */ protected $sLabel; + /** @var string $sCode */ protected $sCode; + /** @var mixed $defaultValue */ protected $defaultValue; /** @var \DesignerForm $oForm */ protected $oForm; + /** @var bool $bMandatory */ protected $bMandatory; + /** @var bool $bReadOnly */ protected $bReadOnly; + /** @var bool $bAutoApply */ protected $bAutoApply; + /** @var array $aCSSClasses */ protected $aCSSClasses; + /** @var bool $bDisplayed */ protected $bDisplayed; + /** @var array $aWidgetExtraParams */ protected $aWidgetExtraParams; - + + /** + * DesignerFormField constructor. + * + * @param string $sCode + * @param string $sLabel + * @param mixed $defaultValue + */ public function __construct($sCode, $sLabel, $defaultValue) { $this->sLabel = $sLabel; @@ -703,7 +720,10 @@ class DesignerFormField $this->bDisplayed = true; $this->aWidgetExtraParams = array(); } - + + /** + * @return string + */ public function GetCode() { return $this->sCode; @@ -712,69 +732,108 @@ class DesignerFormField /** * @param \DesignerForm $oForm */ - public function SetForm(\DesignerForm $oForm) + public function SetForm(DesignerForm $oForm) { $this->oForm = $oForm; } - + /** + * @param bool $bMandatory + */ public function SetMandatory($bMandatory = true) { $this->bMandatory = $bMandatory; } + /** + * @param bool $bReadOnly + */ public function SetReadOnly($bReadOnly = true) { $this->bReadOnly = $bReadOnly; } - + + /** + * @return bool + */ public function IsReadOnly() { return ($this->oForm->IsReadOnly() || $this->bReadOnly); } + /** + * @param bool $bAutoApply + */ public function SetAutoApply($bAutoApply) { $this->bAutoApply = $bAutoApply; } + /** + * @return bool + */ public function IsAutoApply() { return $this->bAutoApply; } + /** + * @param bool $bDisplayed + */ public function SetDisplayed($bDisplayed) { $this->bDisplayed = $bDisplayed; } + /** + * @return bool + */ public function IsDisplayed() { return $this->bDisplayed; } + /** + * @return string + */ public function GetFieldId() { return $this->oForm->GetFieldId($this->sCode); } - + + /** + * @return string + */ public function GetWidgetClass() { return 'property_field'; } - + + /** + * @return array + */ public function GetWidgetExtraParams() { return $this->aWidgetExtraParams; } - + + /** + * @param \WebPage $oP + * @param string $sFormId + * @param string $sRenderMode + * + * @return array + */ public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog') { $sId = $this->oForm->GetFieldId($this->sCode); $sName = $this->oForm->GetFieldName($this->sCode); return array('label' => $this->sLabel, 'value' => "defaultValue, ENT_QUOTES, 'UTF-8')."\">"); } - + + /** + * @param array $aValues + */ public function ReadParam(&$aValues) { if ($this->IsReadOnly()) @@ -801,12 +860,18 @@ class DesignerFormField } } } - + + /** + * @return bool + */ public function IsVisible() { return true; } - + + /** + * @param string $sCSSClass + */ public function AddCSSClass($sCSSClass) { $this->aCSSClasses[] = $sCSSClass; @@ -814,6 +879,8 @@ class DesignerFormField /** * A way to set/change the default value after constructing the field + * + * @param array $aAllDefaultValue */ public function SetDefaultValueFrom($aAllDefaultValue) { @@ -822,7 +889,12 @@ class DesignerFormField $this->defaultValue = $aAllDefaultValue[$this->GetCode()]; } } - + + /** + * @param $sFieldCode + * + * @return \DesignerFormField|false + */ public function FindField($sFieldCode) { if ($this->sCode == $sFieldCode) @@ -832,11 +904,17 @@ class DesignerFormField return false; } + /** + * @return string + */ public function GetHandlerEquals() { return 'null'; } + /** + * @return string + */ public function GetHandlerGetValue() { return 'null'; @@ -845,25 +923,43 @@ class DesignerFormField class DesignerLabelField extends DesignerFormField { + /** @var int $iCount A counter to automatically make the field code */ + protected static $iCount = 0; + /** @var string $sDescription */ protected $sDescription; - + + /** + * @inheritdoc + */ public function __construct($sLabel, $sDescription) { - parent::__construct('', $sLabel, ''); + // Increase counter + static::$iCount++; + + parent::__construct('label_number_' . static::$iCount, $sLabel, ''); $this->sDescription = $sDescription; } - + + /** + * @inheritdoc + */ public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog') { $sId = $this->oForm->GetFieldId($this->sCode); $sName = $this->oForm->GetFieldName($this->sCode); return array('label' => $this->sLabel, 'value' => $this->sDescription); } - + + /** + * @inheritdoc + */ public function ReadParam(&$aValues) { } - + + /** + * @inheritdoc + */ public function IsVisible() { return true; @@ -1334,7 +1430,8 @@ class DesignerIconSelectionField extends DesignerFormField $sPostUploadTo = ($this->sUploadUrl == null) ? 'null' : "'{$this->sUploadUrl}'"; if (!$this->IsReadOnly()) { - $sValue = "defaultValue}\"/>"; + $sDefaultValue = ($this->defaultValue !== '') ? : $this->aAllowedValues[$idx]['value']; + $sValue = ""; $oP->add_ready_script( <<= 1024) { $sReturn = 'K'; $value = $value / 1024; + $iPrecision = 1; } // Megabytes if ($value >= 1024) @@ -621,7 +623,7 @@ class utils $value = $value / 1024; } - $value = round($value, 1); + $value = round($value, $iPrecision); return $value . '' . $sReturn . 'B'; } diff --git a/css/light-grey.css b/css/light-grey.css index 9751985df..dfae4fec1 100644 --- a/css/light-grey.css +++ b/css/light-grey.css @@ -2411,6 +2411,12 @@ a.summary, a.summary:hover { background: url(../images/ok.png?v=v2.7.0-dev) 1em 1em no-repeat #cfc; padding-left: 3em; } +.message_warning { + border: 1px solid #ec9800; + background: url(../images/error.png?v=v2.6.1) 1em 1em no-repeat #ffd78d; + color: #000; + padding-left: 3em; +} .message_error { border: 1px solid #933; background: url(../images/error.png?v=v2.7.0-dev) 1em 1em no-repeat #fcc; @@ -2943,6 +2949,17 @@ table.listResults .originColor { .menu-icon-select > .ui-menu-item { padding: 0.3em 3%; } +.menu-icon-select > .ui-menu-item > * { + width: 100%; + white-space: nowrap; + overflow-x: hidden; + text-overflow: ellipsis; +} +.menu-icon-select > .ui-menu-item > * > img { + max-width: 80px; + max-height: 45px; + margin-right: 10px; +} .attribute.attribute-set .attribute-set-item::after { content: ","; margin-right: 0.5em; diff --git a/css/light-grey.scss b/css/light-grey.scss index 63e37f0ad..54bbb862d 100644 --- a/css/light-grey.scss +++ b/css/light-grey.scss @@ -2791,6 +2791,12 @@ a.summary, a.summary:hover { background: url(../images/ok.png?v=#{$version}) 1em 1em no-repeat #cfc; padding-left: 3em; } +.message_warning { + border: 1px solid #ec9800; + background: url(../images/error.png?v=#{$version}) 1em 1em no-repeat #ffd78d; + color: #000; + padding-left: 3em; +} .message_error { border: 1px solid #933; background: url(../images/error.png?v=#{$version}) 1em 1em no-repeat #fcc; @@ -3392,6 +3398,19 @@ table.listResults .originColor{ } .menu-icon-select > .ui-menu-item{ padding: .3em 3%; + + > *{ + width: 100%; + white-space: nowrap; + overflow-x: hidden; + text-overflow: ellipsis; + + > img{ + max-width: 80px; + max-height: 45px; + margin-right: 10px; + } + } } ////////////////////// diff --git a/js/property_field.js b/js/property_field.js index 2b07818fa..c02c5ef20 100644 --- a/js/property_field.js +++ b/js/property_field.js @@ -256,14 +256,14 @@ $(function() if (oWidget && oWidget._is_visible()) { var oVal = oWidget._get_committed_value(); - oData[oVal.name] = oVal.value; + oData[oVal.name] = me._get_value_for_post(oVal.value); } }); - oPostedData = this.options.submit_parameters; + var oPostedData = this.options.submit_parameters; oPostedData.params = oData; oPostedData.params.updated = [ $('#'+this.options.field_id, this.element).attr('name') ]; // only one field updated in this case oPostedData.params.previous_values = {}; - oPostedData.params.previous_values[oPostedData.params.updated] = this.previous_value; // pass also the previous value(s) + oPostedData.params.previous_values[$('#'+this.options.field_id, this.element).attr('name')] = me._get_value_for_post(this.previous_value); // pass also the previous value(s) $.post(this.options.submit_to, oPostedData, function(data) { $('#prop_submit_result').html(data); @@ -293,6 +293,14 @@ $(function() oWidget = element.data('itopSelector_property_field'); } return oWidget; + }, + _get_value_for_post: function(value) + { + if ((typeof value == "object") && (Object.keys(value).length === 0)) + { + return ""; + } + return value; } }); }); diff --git a/setup/modelfactory.class.inc.php b/setup/modelfactory.class.inc.php index c31b78537..e50569a7e 100644 --- a/setup/modelfactory.class.inc.php +++ b/setup/modelfactory.class.inc.php @@ -615,8 +615,8 @@ class ModelFactory if (!$oTargetParentNode) { - echo "Dumping target doc - looking for '$sParentId'
\n"; - $this->oDOMDocument->firstChild->Dump(); + // echo "Dumping target doc - looking for '$sParentId'
\n"; + // $this->oDOMDocument->firstChild->Dump(); $sPath = MFDocument::GetItopNodePath($oSourceNode); $iLine = $oSourceNode->getLineNo(); throw new MFException($sPath.' at line '.$iLine.": parent class '$sParentId' could not be found", MFException::PARENT_NOT_FOUND, $iLine, $sPath, $sParentId); @@ -633,8 +633,8 @@ class ModelFactory } else { - echo "Dumping target doc - looking for '".$oSourceNode->getAttribute('id')."'
\n"; - $this->oDOMDocument->firstChild->Dump(); + // echo "Dumping target doc - looking for '".$oSourceNode->getAttribute('id')."'
\n"; + // $this->oDOMDocument->firstChild->Dump(); $sPath = MFDocument::GetItopNodePath($oSourceNode); $iLine = $oSourceNode->getLineNo(); throw new MFException($sPath.' at line '.$iLine.": could not be found", MFException::NOT_FOUND, $iLine, $sPath); @@ -1078,13 +1078,17 @@ class ModelFactory /** * Check if the class specified by the given name already exists in the loaded DOM + * * @param string $sClassName The node corresponding to the class to load - * @throws Exception + * @param bool $bIncludeMetas Look for $sClassName also in meta declaration (PHP classes) if not found in XML classes + * + * @throws \Exception + * * @return bool True if the class exists, false otherwise */ - protected function ClassNameExists($sClassName) + protected function ClassNameExists($sClassName, $bIncludeMetas = false) { - return !is_null($this->GetClass($sClassName)); + return !is_null($this->GetClass($sClassName, $bIncludeMetas)); } /** @@ -1190,14 +1194,22 @@ EOF { return $this->GetNodes("/itop_design/classes//class[@id][@_created_in='$sModuleName']"); } - + /** * List all classes from the DOM - * @throws Exception + * + * @param bool $bIncludeMetas Also look for meta declaration (PHP classes) in addition to XML classes + * + * @return \DOMNodeList */ - public function ListAllClasses() + public function ListAllClasses($bIncludeMetas = false) { - return $this->GetNodes("/itop_design/classes//class[@id]"); + $sXPath = "/itop_design/classes//class[@id]"; + if($bIncludeMetas === true) + { + $sXPath .= "|/itop_design/meta/classes/class[@id]"; + } + return $this->GetNodes($sXPath); } /** @@ -1210,13 +1222,22 @@ EOF } /** - * @param $sClassName + * @param string $sClassName + * @param bool $bIncludeMetas Look for $sClassName also in meta declaration (PHP classes) if not found in XML classes * - * @return \DOMElement + * @return null|\DOMElement */ - public function GetClass($sClassName) + public function GetClass($sClassName, $bIncludeMetas = false) { + // Check if class among XML classes $oClassNode = $this->GetNodes("/itop_design/classes//class[@id='$sClassName']")->item(0); + + // If not, check if class among exposed meta classes (PHP classes) + if(is_null($oClassNode) && ($bIncludeMetas === true)) + { + $oClassNode = $this->GetNodes("/itop_design/meta/classes/class[@id='$sClassName']")->item(0); + } + return $oClassNode; } @@ -1764,6 +1785,7 @@ EOF; /** * MFElement: helper to read/change the DOM * @package ModelFactory + * @property \MFDocument $ownerDocument This is only here for type hinting as iTop replaces \DOMDocument with \MFDocument */ class MFElement extends Combodo\iTop\DesignElement { @@ -2286,8 +2308,8 @@ class MFElement extends Combodo\iTop\DesignElement { if ($bMustExist) { - echo "Dumping parent node
\n"; - $oContainer->Dump(); + //echo "Dumping parent node
\n"; + //$oContainer->Dump(); throw new Exception(MFDocument::GetItopNodePath($this).' at line '.$this->getLineNo().": could not be found"); } if (!$bIfExists) @@ -2358,6 +2380,7 @@ class MFElement extends Combodo\iTop\DesignElement case 'added': case 'replaced': case 'needed': + case 'forced': // marked as added or modified, just reset the flag $oNode->removeAttribute('_alteration'); break;