From: <svn...@pl...> - 2004-10-25 12:06:48
|
Author: shh42 Date: Mon Oct 25 07:23:30 2004 New Revision: 5706 Modified: CMFPlone/branches/Plone-2_0-branch/skins/plone_ecmascript/plone_javascripts.js CMFPlone/branches/Plone-2_0-branch/skins/plone_scripts/date_components_support.py CMFPlone/branches/Plone-2_0-branch/tests/testDateComponentsSupport.py Log: Make the am/pm dropdown behave just like the rest by adding a '----' default entry. Modified: CMFPlone/branches/Plone-2_0-branch/skins/plone_ecmascript/plone_javascripts.js ============================================================================== --- CMFPlone/branches/Plone-2_0-branch/skins/plone_ecmascript/plone_javascripts.js (original) +++ CMFPlone/branches/Plone-2_0-branch/skins/plone_ecmascript/plone_javascripts.js Mon Oct 25 07:23:30 2004 @@ -687,7 +687,7 @@ var minute = document.getElementById(minute) var ampm = document.getElementById(ampm) - if (year.value > 0) + if (0 < year.value) { // Return ISO date string // Note: This relies heavily on what date_components_support.py puts into the form. @@ -703,6 +703,8 @@ day.options[0].selected = 1 hour.options[0].selected = 1 minute.options[0].selected = 1 + if (ampm.options) + ampm.options[0].selected = 1 // Return empty string field.value = '' } Modified: CMFPlone/branches/Plone-2_0-branch/skins/plone_scripts/date_components_support.py ============================================================================== --- CMFPlone/branches/Plone-2_0-branch/skins/plone_scripts/date_components_support.py (original) +++ CMFPlone/branches/Plone-2_0-branch/skins/plone_scripts/date_components_support.py Mon Oct 25 07:23:30 2004 @@ -132,6 +132,11 @@ if use_ampm: p=date.strftime('%p') + if default: + ampm.append({'id': '----', 'value': 'AM', 'selected': 1}) + else: + ampm.append({'id': '----', 'value': 'AM', 'selected': None}) + for x in ('AM', 'PM'): d={'id': x, 'value': x, 'selected': None} if x==p and not default: Modified: CMFPlone/branches/Plone-2_0-branch/tests/testDateComponentsSupport.py ============================================================================== --- CMFPlone/branches/Plone-2_0-branch/tests/testDateComponentsSupport.py (original) +++ CMFPlone/branches/Plone-2_0-branch/tests/testDateComponentsSupport.py Mon Oct 25 07:23:30 2004 @@ -162,7 +162,12 @@ for i in range(13): self.assertEqual(minutes[i], data[i]) - def testAMPM(self): + def testAM(self): + d = DateTime(2002, 8, 1, 3, 0, 0) + d = self.portal.date_components_support(d) + self.assertEqual(d.get('ampm'), []) + + def testPM(self): ampm = self.d.get('ampm') self.assertEqual(ampm, []) @@ -347,10 +352,25 @@ for i in range(13): self.assertEqual(hours[i], data[i]) - def testAMPM(self): + def testAM(self): + d = DateTime(2002, 8, 1, 3, 0, 0) + d = self.portal.date_components_support(d, use_ampm=1) + data = [ - {'selected': None, 'id': 'AM', 'value': 'AM'}, - {'selected': 1, 'id': 'PM', 'value': 'PM'}, + {'selected': None, 'id': '----', 'value': 'AM'}, + {'selected': 1, 'id': 'AM', 'value': 'AM'}, + {'selected': None, 'id': 'PM', 'value': 'PM'}, + ] + + ampm = d.get('ampm') + for i in range(2): + self.assertEqual(ampm[i], data[i]) + + def testPM(self): + data = [ + {'selected': None, 'id': '----', 'value': 'AM'}, + {'selected': None, 'id': 'AM', 'value': 'AM'}, + {'selected': 1, 'id': 'PM', 'value': 'PM'}, ] ampm = self.d.get('ampm') @@ -390,8 +410,9 @@ def testAMPM(self): data = [ - {'selected': None, 'id': 'AM', 'value': 'AM'}, - {'selected': None, 'id': 'PM', 'value': 'PM'}, + {'selected': 1, 'id': '----', 'value': 'AM'}, + {'selected': None, 'id': 'AM', 'value': 'AM'}, + {'selected': None, 'id': 'PM', 'value': 'PM'}, ] ampm = self.d.get('ampm') @@ -399,6 +420,21 @@ self.assertEqual(ampm[i], data[i]) +class TestSpecialCases(PloneTestCase.PloneTestCase): + + def testNoneUsesDefault(self): + d = self.portal.date_components_support(None) + hours = d.get('hours') + # default == 1 + self.failUnless(hours[0]['selected']) + + def testEmptyStringUsesDefault(self): + d = self.portal.date_components_support('') + hours = d.get('hours') + # default == 1 + self.failUnless(hours[0]['selected']) + + def test_suite(): from unittest import TestSuite, makeSuite suite = TestSuite() @@ -406,6 +442,7 @@ suite.addTest(makeSuite(TestDateComponentsSupportDefault)) suite.addTest(makeSuite(TestDateComponentsSupportAMPM)) suite.addTest(makeSuite(TestDateComponentsSupportAMPMDefault)) + suite.addTest(makeSuite(TestSpecialCases)) return suite if __name__ == '__main__': |