718 |
def __init__(self, *args, **params): |
def __init__(self, *args, **params): |
719 |
FieldDisplayHandler.__init__(self, *args, **params) |
FieldDisplayHandler.__init__(self, *args, **params) |
720 |
|
|
|
# My events... |
|
|
self.subevents.registerEventListeners( { |
|
|
'requestREPLACEVALUE' : self.replaceText } ) |
|
|
|
|
721 |
def beginEdit(self, event): |
def beginEdit(self, event): |
722 |
|
pass |
|
if not self._loadedAllowedValues and not hasattr(self.entry,'_allowedValues'): |
|
|
self.entry.allowedValues() |
|
|
self._loadedAllowedValues = 1 |
|
|
|
|
|
self.editing = 1 |
|
|
self.modified = 0 |
|
|
|
|
|
# TODO: Replace with formatter |
|
|
self.setValue(self.entry.getValue()) |
|
|
|
|
|
if self.value == None: |
|
|
self.work = "" |
|
|
else: |
|
|
try: |
|
|
self.work = self.entry._allowedValues[str(self.value)] |
|
|
except KeyError: |
|
|
self.work = "" |
|
|
event.__error__ = 1 |
|
|
event.__errortext__ = _("Invalid value '%s' for keyed pull-down field") % self.value |
|
|
|
|
|
self._buildDisplay() |
|
|
|
|
|
self.cursor = len(self.display) |
|
|
|
|
723 |
|
|
724 |
# TODO: Replace with format mask |
# TODO: Replace with format mask |
725 |
def _buildDisplayHelper(self, value, editing): |
def _buildDisplayHelper(self, value, editing): |
|
self._dropdownIndex = 0 |
|
726 |
if value in (None,""): |
if value in (None,""): |
727 |
return "" |
return "" |
728 |
|
descr = "" |
729 |
|
if hasattr(self.entry,'datasource'): |
730 |
|
if hasattr(self.entry,'foreign_key'): |
731 |
|
foreignKeyContent = string.split(self.entry.foreign_key,'.') |
732 |
|
if len(foreignKeyContent) > 2: |
733 |
|
tmpFieldName = foreignKeyContent[1]+'.'+foreignKeyContent[2] |
734 |
|
else: |
735 |
|
tmpFieldName = foreignKeyContent[1] |
736 |
|
|
737 |
|
lResultSet = self.entry.datasource.createResultSet({tmpFieldName:value}) |
738 |
|
if (lResultSet.firstRecord()): |
739 |
|
if hasattr(self.entry,'foreign_key_description'): |
740 |
|
descr = "%s" % lResultSet.current.getField(self.entry.foreign_key_description) |
741 |
|
|
742 |
if editing: |
return descr |
|
i = 0 |
|
|
val = string.lower(value) |
|
|
#print "editing .. _allowedValuesDescr ",self.entry._allowedValuesDescr |
|
|
for disp in self.entry._allowedValuesDescr: |
|
|
if disp[:len(val)] == val: |
|
|
display = self.entry._allowedValues[self.entry._allowedValuesReverse[disp]] |
|
|
self._dropdownIndex = i |
|
|
return str(display) |
|
|
|
|
|
return str(value) |
|
|
else: |
|
|
#print "no editing ... value ", str(value) |
|
|
#print "_allowedValues ", self.entry._allowedValues |
|
|
return self.entry._allowedValues[str(value)] |
|
743 |
|
|
744 |
def _buildDisplay(self): |
def _buildDisplay(self): |
745 |
if self.editing: |
self.display = self._buildDisplayHelper(self.value, 0) |
|
self.display = self._buildDisplayHelper(self.work, 1) |
|
|
if self.cursor > len(self.work): |
|
|
self.work = self.display |
|
|
else: |
|
|
self.display = self._buildDisplayHelper(self.value, 0) |
|
|
|
|
|
|
|
|
def replaceText(self, event): |
|
|
self.selection1 = 0 |
|
|
self.selection2 = len(self.display) |
|
|
self.addText(event) |
|
|
|
|
|
|
|
|
def _buildValue(self): |
|
|
if self.work == "": |
|
|
self.value = '' # None |
|
|
else: |
|
|
try: |
|
|
self.value = self.entry._allowedValuesReverse[string.lower(self.display)] |
|
|
except KeyError: |
|
|
return 0 |
|
|
return 1 |
|
746 |
|
|
747 |
|
def endEdit(self,event): |
748 |
|
pass |
749 |
|
|
750 |
############################################################################# |
############################################################################# |
751 |
# |
# |