Author: david
Date: Thu Sep 3 14:02:28 2009
New Revision: 3161
Log:
Swap non-preferred term for preferred term for broad term autocomplete (fixes
issue #884). Remove ability to translate broad terms and link broad terms by id
(fixes issue #883).
Modified:
trunk/apps/qubit/modules/term/actions/editAction.class.php
trunk/apps/qubit/modules/term/templates/_termNameAutoComplete.php
trunk/apps/qubit/modules/term/templates/editSuccess.php
Modified: trunk/apps/qubit/modules/term/actions/editAction.class.php
==============================================================================
--- trunk/apps/qubit/modules/term/actions/editAction.class.php Thu Sep 3
00:03:12 2009 (r3160)
+++ trunk/apps/qubit/modules/term/actions/editAction.class.php Thu Sep 3
14:02:28 2009 (r3161)
@@ -235,37 +235,16 @@
public function updateParent()
{
// If broad term field is empty
- if (0 == strlen(trim($this->getRequestParameter('broad_term'))))
+ if (null == $this->getRequestParameter('parentId') && 0 ==
strlen(trim($this->getRequestParameter('broadTerm'))))
{
- // Don't orphan term if it has a parent in the source culture
- if ($this->getUser()->getCulture() == $this->term->sourceCulture)
- {
- // then make term a child of the root term
- $this->term->parentId = QubitTerm::ROOT_ID;
- }
-
- return $this;
+ // then make term a child of the root term
+ $this->term->parentId = QubitTerm::ROOT_ID;
}
-
- // search for term in current taxonomy
- $criteria = new Criteria;
- $criteria->addJoin(QubitTerm::ID, QubitTermI18n::ID, Criteria::INNER_JOIN);
- $criteria->add(QubitTermI18n::NAME,
$this->getRequestParameter('broad_term'), Criteria::EQUAL);
- $criteria->add(QubitTermI18n::CULTURE, $this->getUser()->getCulture(),
Criteria::EQUAL);
- $criteria->add(QubitTerm::TAXONOMY_ID, $this->term->getTaxonomyId(),
Criteria::EQUAL);
-
- // If the term doesn't already exist, create a new term
- if (null === ($parentTerm = QubitTerm::getOne($criteria)))
- {
- $parentTerm = new QubitTerm;
- $parentTerm->setName($this->getRequestParameter('broad_term'));
- $parentTerm->setParentId(QubitTerm::ROOT_ID);
- $parentTerm->setTaxonomyId($this->term->getTaxonomyId());
- $parentTerm->save();
+ else if (null !== ($parentTerm =
QubitTerm::getById($this->getRequestParameter('parentId'))))
+ {
+ $this->term->parentId = $parentTerm->id;
}
- $this->term->parentId = $parentTerm->id;
-
return $this;
}
Modified: trunk/apps/qubit/modules/term/templates/_termNameAutoComplete.php
==============================================================================
--- trunk/apps/qubit/modules/term/templates/_termNameAutoComplete.php Thu Sep
3 00:03:12 2009 (r3160)
+++ trunk/apps/qubit/modules/term/templates/_termNameAutoComplete.php Thu Sep
3 14:02:28 2009 (r3161)
@@ -18,15 +18,30 @@
<script language="javascript">
//<!CDATA[
var termRelationOptions = new Array('use for', 'use', 'related term');
+ var preferredTermFormat = ' (<?php echo __('use') ?>: %s)';
- // Setup data source
+ function formatTermResults(oResultData, sQuery, sResultMatch) {
+ var sMarkup = "";
+ if (sResultMatch)
+ {
+ sMarkup = sResultMatch;
+ if (undefined != (preferredName = oResultData.preferredName))
+ {
+ sMarkup += preferredTermFormat.replace('%s', preferredName);
+ }
+ }
+
+ return sMarkup;
+ };
+
+ // Setup data source
var termDatasource = new YAHOO.util.XHRDataSource('<?php echo
url_for(array('module' => 'term', 'action' => 'list')) ?>');
termDatasource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
termDatasource.responseSchema = {
resultsList : "Results",
- fields : ["name", "id"]
+ fields : ["name", "id", "preferredName", "preferredId"]
}
-
+
// Create query handler
var queryHandler = function(sQuery)
{
@@ -44,12 +59,13 @@
var acInputName = acName + "Input" + acIndex;
var acListName = acName + "List" + acIndex;
-
+
var newAc = new YAHOO.widget.AutoComplete(acInputName, acListName,
termDatasource);
- newAc.generateRequest = queryHandler;
+ newAc.generateRequest = queryHandler;
newAc.animVert = true;
newAc.maxResultsDisplayed = 10;
newAc.useIFrame = true;
+ newAc.resultTypeList = false;
return newAc;
}
@@ -65,14 +81,14 @@
acRowHtml += '<input id="relatedTermAcInput' + newRtCount + '"
type="text" name="new_related_term[' + newRtCount + ']" />';
acRowHtml += '<div id="relatedTermAcList' + newRtCount + '"></div>';
acRowHtml += '</div>';
- acRowHtml += '</td>';
- acRowHtml += '<td>';
+ acRowHtml += '</td>';
+ acRowHtml += '<td>';
acRowHtml += '<select name="related_term_type[new' + newRtCount + ']">';
for (var i=0; i < termRelationOptions.length; i++)
{
acRowHtml += '<option value="' + termRelationOptions[i] + '">' +
termRelationOptions[i] + '</option>';
- };
+ };
acRowHtml += '</select>';
acRowHtml += '</td>';
@@ -85,13 +101,13 @@
newAcRow.find('td').wrapInner('<div class="animateNicely" style="display:
none"></div>');
$('tr#addRtRowLink').before(newAcRow);
newTermAcField('relatedTermAc', newRtCount);
-
+
// Show animation
newAcRow.find('div.animateNicely').show('normal', function(i) {
// After show animation completes, remove "animateNicely" divs
$(this).replaceWith($(this).children());
});
-
+
newRtCount++;
}
@@ -108,8 +124,43 @@
Drupal.behaviors.broadTermAutoComplete = {
attach: function(context)
{
- // Build broad & related term auto-complete widgets
+ var parentIdField = YAHOO.util.Dom.get("parentId");
+
+ // Build broad term auto-complete widget
var btAutoComplete = newTermAcField('broadTermAc');
+
+ // Add " (use: preferred term)" suffix when listing a non-preferred term
+ btAutoComplete.formatResult = formatTermResults;
+
+ // Actions when a term is selected from the auto-complete list
+ var broadTermHandler = function(sType, aArgs) {
+ var oData = aArgs[2]; // object literal of selected item's result data
+
+ // update hidden form field with the selected item's ID
+ parentIdField.value = oData.preferredId;
+
+ // Swap in preferred term name for a non-preferred term
+ if (undefined != oData.preferredName)
+ {
+ YAHOO.util.Dom.get('broadTermAcInput').value = oData.preferredName;
+ }
+ };
+ btAutoComplete.itemSelectEvent.subscribe(broadTermHandler);
+
+ // Clear the parentId field when user types in the autocomplete field
+ btAutoComplete.textboxKeyEvent.subscribe(function() {
+ if (undefined != parentIdField.value)
+ {
+ parentIdField.value = null;
+ }
+ });
+ }
+ }
+
+ Drupal.behaviours.relatedTermAutoComplete = {
+ attach: function(context)
+ {
+ // Build related term auto-complete widgets
var rtAutoComplete = newTermAcField('relatedTermAc');
// Add an id to override the "overflow: auto" style used by default for
Modified: trunk/apps/qubit/modules/term/templates/editSuccess.php
==============================================================================
--- trunk/apps/qubit/modules/term/templates/editSuccess.php Thu Sep 3
00:03:12 2009 (r3160)
+++ trunk/apps/qubit/modules/term/templates/editSuccess.php Thu Sep 3
14:02:28 2009 (r3161)
@@ -86,11 +86,9 @@
<div class="form-item">
<label for="display note"><?php echo __('broad term'); ?></label>
- <?php if (strlen($sourceCultureValue =
$parent->getName(array('sourceCulture' => true))) > 0 && $sf_user->getCulture()
!= $term->getSourceCulture()): ?>
- <div class="default-translation"><?php echo nl2br($sourceCultureValue)
?></div>
- <?php endif; ?>
<div id="broadTermAutoComplete" style="padding-bottom:2em; width:95%">
- <input id="broadTermAcInput" type="text" name="broad_term"
value="<?php echo $parent->getName() ?>" />
+ <input id="parentId" type="hidden" name="parentId" value="<?php echo
$term->parentId ?>" />
+ <input id="broadTermAcInput" type="text" name="broadTerm" value="<?php
echo $parent->getName(array('cultureFallback' => true)) ?>" />
<div id="broadTermAcList"></div>
</div>
</div>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---