Преглед изворни кода

Typespecial fix labels - always show id

Piotr Labudda пре 10 година
родитељ
комит
82346b23a3
1 измењених фајлова са 22 додато и 6 уклоњено
  1. 22 6
      SE/se-lib/Typespecial.php

+ 22 - 6
SE/se-lib/Typespecial.php

@@ -662,12 +662,23 @@ jQuery('#typeahead-{$fName}').typeahead({
 		$out .= '<div class="typepsecial">';
 		$out .= '<select id="ts-' . $fName . '">';
 			if (!empty($selValue)) {
-				$tsVal = (!empty($tsValue))? $tsValue : $selValue;
-				//$out .= '<option value="' . $selValue . '" selected="selected" typespecial="'.$tsVal.'">' . $tsVal . '</option>';
-				$out .= '<option value="' . $selValue . '" selected="selected">' . $tsVal . '</option>';
+				$tsSelectedItemLabel = (!empty($tsValue))? $tsValue : $selValue;
+				//$out .= '<option value="' . $selValue . '" selected="selected" typespecial="'.$tsSelectedItemLabel.'">' . $tsSelectedItemLabel . '</option>';
+				{// fix prefix
+					$prefix = "{$selValue}";
+					$prefixLen = strlen($prefix);
+					if (strlen($tsSelectedItemLabel) > $prefixLen && $prefix != substr($tsSelectedItemLabel, 0, $prefixLen)) {
+						if (' ' == substr($tsSelectedItemLabel, 0, 1)) {
+							$tsSelectedItemLabel = "{$prefix}{$tsSelectedItemLabel}";
+						} else {
+							$tsSelectedItemLabel = "{$prefix}: {$tsSelectedItemLabel}";
+						}
+					}
+				}
+				$out .= '<option value="' . $selValue . '" selected="selected">' . $tsSelectedItemLabel . '</option>';
 				$optionsJson = new stdClass();
 				$optionsJson->id = $selValue;
-				$optionsJson->name = $tsValue;
+				$optionsJson->name = $tsSelectedItemLabel;
 				$optionsJson = array($optionsJson);
 				$optionsJson = json_encode($optionsJson);
 			}
@@ -774,8 +785,13 @@ jQuery('#typeahead-{$fName}').typeahead({
 					callback();
 				},
 				success: function(res) {
-					for (var i in res) {
-						res[i].name = res[i].id + ': ' + res[i].name;
+					var i, prefix, prefixLen;
+					for (i in res) {
+						prefix = '' + res[i].id;
+						prefixLen = prefix.length;
+						if (prefixLen > 0 && prefix !== res[i].name.substr(0, prefixLen)) {
+							res[i].name = res[i].id + ': ' + res[i].name;
+						}
 					}
 					callback(res);
 				}