flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject [1/2] git commit: [flex-asjs] [refs/heads/develop] - Fix to allow the selection for the DateChooser to be set and visible (show's date as selected).
Date Tue, 13 Dec 2016 22:14:55 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop c51282f03 -> d55991594


Fix to allow the selection for the DateChooser to be set and visible (show's date as selected).


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/79378574
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/79378574
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/79378574

Branch: refs/heads/develop
Commit: 79378574854ed2953df441c7f7a86f33f74c224f
Parents: c51282f
Author: Peter Ent <pent@apache.org>
Authored: Tue Dec 13 17:13:32 2016 -0500
Committer: Peter Ent <pent@apache.org>
Committed: Tue Dec 13 17:13:32 2016 -0500

----------------------------------------------------------------------
 .../flex/org/apache/flex/html/DateChooser.as    |   3 +
 .../apache/flex/html/beads/DateChooserView.as   |  74 ++-----------
 .../controllers/DateChooserMouseController.as   |   4 +
 .../controllers/DateFieldMouseController.as     |  72 +++++++++++-
 .../flex/html/beads/models/DateChooserModel.as  | 110 ++++++++++++++++++-
 5 files changed, 192 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/79378574/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/DateChooser.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/DateChooser.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/DateChooser.as
index ff5ef28..7e88d9c 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/DateChooser.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/DateChooser.as
@@ -51,6 +51,9 @@ package org.apache.flex.html
 			// fix the DateChooser's size
 			width = 280;
 			height = 240;
+			
+			// default to today
+			selectedDate = new Date();
 		}
 
 		/**

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/79378574/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DateChooserView.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DateChooserView.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DateChooserView.as
index c8a9ad4..b2eaaa0 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DateChooserView.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/DateChooserView.as
@@ -84,9 +84,6 @@ package org.apache.flex.html.beads
 		private var dayNamesContainer:DateChooserHeader;
 		private var daysContainer:DateChooserList;
 		
-		private var _dayNames:Array;
-		private var _days:Array;
-		
 		/**
 		 *  The button that causes the previous month to be displayed by the DateChooser.
 		 *
@@ -152,17 +149,10 @@ package org.apache.flex.html.beads
 			
 			daysContainer = new DateChooserList();
 			UIBase(_strand).addElement(daysContainer, false);
-						
-			_dayNames = new Array();
-			
-			// the calendar has 7 columns with 6 rows, the first row are the day names
-			for(var i:int=0; i < 7; i++) {
-				_dayNames.push(model.dayNames[i]);
-			}
 			
 			IEventDispatcher(daysContainer).dispatchEvent( new Event("itemsCreated") );
 			
-			updateCalendar();
+			model.addEventListener("selectedDateChanged", selectionChangeHandler);
 		}
 		
 		private function layoutContents():void
@@ -179,20 +169,22 @@ package org.apache.flex.html.beads
 			monthLabel.x = _prevMonthButton.x + _prevMonthButton.width;
 			monthLabel.y = 0;
 			monthLabel.width = sw - _prevMonthButton.width - _nextMonthButton.width;
+			monthLabel.text = model.monthNames[model.displayedMonth] + " " +
+				String(model.displayedYear);
 			
 			dayNamesContainer.x = 0;
 			dayNamesContainer.y = monthLabel.y + monthLabel.height;
 			dayNamesContainer.width = sw;
 			dayNamesContainer.height = monthLabel.height;
 			
-			dayNamesContainer.dataProvider = _dayNames;
+			dayNamesContainer.dataProvider = model.dayNames;
 			
 			daysContainer.x = 0;
 			daysContainer.y = dayNamesContainer.y + dayNamesContainer.height;
 			daysContainer.width = sw;
 			daysContainer.height = sh - monthLabel.height - dayNamesContainer.height;
 			
-			daysContainer.dataProvider = _days;
+			daysContainer.dataProvider = model.days;
 			
 			IEventDispatcher(_strand).dispatchEvent( new Event("layoutNeeded") );
 			IEventDispatcher(daysContainer).dispatchEvent( new Event("layoutNeeded") );
@@ -201,58 +193,12 @@ package org.apache.flex.html.beads
 		/**
 		 * @private
 		 */
-		private function updateCalendar():void
+		private function selectionChangeHandler(event:Event):void
 		{
-			monthLabel.text = model.monthNames[model.displayedMonth] + " " +
-				String(model.displayedYear);
-			
-			var firstDay:Date = new Date(model.displayedYear,model.displayedMonth,1);
-			
-			_days = new Array(42);
-			
-			// blank out the labels for the first firstDay.day-1 entries.
-			for(var i:int=0; i < firstDay.getDay(); i++) {
-				_days[i] = null;
-			}
-			
-			// renumber to the last day of the month
-			var dayNumber:int = 1;
-			var numDays:Number = numberOfDaysInMonth(model.displayedMonth, model.displayedYear);
-			
-			for(; i < _days.length && dayNumber <= numDays; i++) {
-				_days[i] = new Date(model.displayedYear, model.displayedMonth, dayNumber++);
-			}
-			
-			// blank out the rest
-			for(; i < _days.length; i++) {
-				_days[i] = null;
-			}
-			
-			daysContainer.dataProvider = _days;
-		}
-		
-		/**
-		 * @private
-		 */
-		private function numberOfDaysInMonth(month:Number, year:Number):Number
-		{
-			var n:int;
-			
-			if (month == 1) // Feb
-			{
-				if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) // leap year
-					n = 29;
-				else
-					n = 28;
-			}
-				
-			else if (month == 3 || month == 5 || month == 8 || month == 10)
-				n = 30;
-				
-			else
-				n = 31;
+			layoutContents();
 			
-			return n;
+			var index:Number = model.getIndexForSelectedDate();
+			daysContainer.selectedIndex = index;
 		}
 		
 		/**
@@ -260,7 +206,7 @@ package org.apache.flex.html.beads
 		 */
 		private function handleModelChange(event:Event):void
 		{
-			updateCalendar();
+			layoutContents();
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/79378574/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as
index a43ca7a..f5d7e34 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateChooserMouseController.as
@@ -81,6 +81,8 @@ package org.apache.flex.html.beads.controllers
 		 */
 		private function prevMonthClickHandler(event:MouseEvent):void
 		{
+			event.preventDefault();
+			
 			var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel;
 			
 			var month:Number = model.displayedMonth - 1;
@@ -98,6 +100,8 @@ package org.apache.flex.html.beads.controllers
 		 */
 		private function nextMonthClickHandler(event:MouseEvent):void
 		{
+			event.preventDefault();
+			
 			var model:DateChooserModel = _strand.getBeadByType(IBeadModel) as DateChooserModel;
 			
 			var month:Number = model.displayedMonth + 1;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/79378574/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as
index c4f130a..2b8ea51 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/DateFieldMouseController.as
@@ -21,11 +21,14 @@ package org.apache.flex.html.beads.controllers
 	import org.apache.flex.core.IBeadController;
 	import org.apache.flex.core.IDateChooserModel;
 	import org.apache.flex.core.IStrand;
+	import org.apache.flex.core.IUIBase;
 	import org.apache.flex.core.UIBase;
 	import org.apache.flex.events.Event;
-	import org.apache.flex.events.MouseEvent;
 	import org.apache.flex.events.IEventDispatcher;
+	import org.apache.flex.events.MouseEvent;
 	import org.apache.flex.html.beads.DateFieldView;
+	import org.apache.flex.utils.Timer;
+	import org.apache.flex.utils.UIUtils;
 	
 	/**
 	 * The DateFieldMouseController class is responsible for monitoring
@@ -74,9 +77,41 @@ package org.apache.flex.html.beads.controllers
 		 */
 		private function clickHandler(event:MouseEvent):void
 		{
+			event.stopImmediatePropagation();
+			
 			var viewBead:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView;
 			viewBead.popUpVisible = true;
 			IEventDispatcher(viewBead.popUp).addEventListener("change", changeHandler);
+			
+			removeDismissHandler();
+			
+			// use a timer to delay the installation of the event handler, otherwise
+			// the event handler is called immediately and will dismiss the popup.
+			var t:Timer = new Timer(0.25,1);
+			t.addEventListener("timer",addDismissHandler);
+			t.start();
+		}
+		
+		/**
+		 * @private
+		 */
+		private function addDismissHandler(event:Event):void
+		{
+			var host:UIBase = UIUtils.findPopUpHost(_strand as UIBase) as UIBase;
+			if (host) {
+				host.addEventListener("click", dismissHandler);
+			}
+		}
+		
+		/**
+		 * @private
+		 */
+		private function removeDismissHandler():void
+		{
+			var host:UIBase = UIUtils.findPopUpHost(_strand as UIBase) as UIBase;
+			if (host) {
+				host.removeEventListener("click", dismissHandler);
+			}
 		}
 		
 		/**
@@ -84,6 +119,8 @@ package org.apache.flex.html.beads.controllers
 		 */
 		private function changeHandler(event:Event):void
 		{
+			event.stopImmediatePropagation();
+			
 			var viewBead:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView;
 			
 			var model:IDateChooserModel = _strand.getBeadByType(IDateChooserModel) as IDateChooserModel;
@@ -91,6 +128,39 @@ package org.apache.flex.html.beads.controllers
 
 			viewBead.popUpVisible = false;
 			IEventDispatcher(_strand).dispatchEvent(new Event("change"));
+			
+			removeDismissHandler();
+		}
+		
+		/**
+		 * @private
+		 */
+		private function dismissHandler(event:MouseEvent):void
+		{
+			var viewBead:DateFieldView = _strand.getBeadByType(DateFieldView) as DateFieldView;
+			var popup:IUIBase = IUIBase(viewBead.popUp);
+			
+			COMPILE::SWF {
+				var before:IUIBase = event.targetBeforeBubbling["flexjs_wrapper"] as IUIBase;
+				if (before) {
+					while (before != null) {
+						if (before == popup) return;
+						before = before.parent as IUIBase;
+					}
+				}
+			}
+			COMPILE::JS {
+				var before:IUIBase = event.target as IUIBase;
+				if (before) {
+					while (before != null) {
+						if (before == popup) return;
+						before = before.parent as IUIBase;
+					}
+				}
+			}
+			
+			viewBead.popUpVisible = false;
+			removeDismissHandler();
 		}
 	}
 }

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/79378574/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/DateChooserModel.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/DateChooserModel.as
b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/DateChooserModel.as
index 2132cc7..a24ca90 100644
--- a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/DateChooserModel.as
+++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/models/DateChooserModel.as
@@ -38,9 +38,9 @@ package org.apache.flex.html.beads.models
 		public function DateChooserModel()
 		{
 			// default displayed year and month to "today"
-			var today:Date = new Date();
-			displayedYear = today.getFullYear();
-			displayedMonth = today.getMonth();
+//			var today:Date = new Date();
+//			displayedYear = today.getFullYear();
+//			displayedMonth = today.getMonth();
 		}
 		
 		private var _strand:IStrand;
@@ -60,6 +60,7 @@ package org.apache.flex.html.beads.models
 		
 		private var _dayNames:Array   = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
 		private var _monthNames:Array = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
+		private var _days:Array;
 		private var _displayedYear:Number;
 		private var _displayedMonth:Number;
 		private var _firstDayOfWeek:Number = 0;
@@ -119,6 +120,7 @@ package org.apache.flex.html.beads.models
 		{
 			if (value != _displayedYear) {
 				_displayedYear = value;
+				updateCalendar();
 				dispatchEvent( new Event("displayedYearChanged") );
 			}
 		}
@@ -139,6 +141,7 @@ package org.apache.flex.html.beads.models
 		{
 			if (_displayedMonth != value) {
 				_displayedMonth = value;
+				updateCalendar();
 				dispatchEvent( new Event("displayedMonthChanged") );
 			}
 		}
@@ -163,6 +166,18 @@ package org.apache.flex.html.beads.models
 			}
 		}
 		
+		public function get days():Array
+		{
+			return _days;
+		}
+		public function set days(value:Array):void
+		{
+			if (value != _days) {
+				_days = value;
+				dispatchEvent( new Event("daysChanged") );
+			}
+		}
+		
 		/**
 		 *  The currently selected date or null if no date has been selected.
 		 *  
@@ -179,13 +194,96 @@ package org.apache.flex.html.beads.models
 		{
 			if (value != _selectedDate) {
 				_selectedDate = value;
-				dispatchEvent( new Event("selectedDateChanged") );
 				
 				if (value != null) {
-					displayedMonth = value.getMonth();
-					displayedYear  = value.getFullYear();
+					var needsUpdate:Boolean = false;
+					if (value.getMonth() != _displayedMonth) {
+						needsUpdate = true;
+						_displayedMonth = value.getMonth();
+					}
+					if (value.getFullYear() != _displayedYear) {
+						needsUpdate = true;
+						_displayedYear  = value.getFullYear();
+					}
+					if (needsUpdate) updateCalendar();
+				}
+				
+				dispatchEvent( new Event("selectedDateChanged") );
+			}
+		}
+		
+		// Utilities
+		
+		
+		/**
+		 * @private
+		 */
+		private function updateCalendar():void
+		{	
+			var firstDay:Date = new Date(displayedYear,displayedMonth,1);
+			
+			_days = new Array(42);
+			
+			// blank out the labels for the first firstDay.day-1 entries.
+			for(var i:int=0; i < firstDay.getDay(); i++) {
+				_days[i] = null;
+			}
+			
+			// renumber to the last day of the month
+			var dayNumber:int = 1;
+			var numDays:Number = numberOfDaysInMonth(displayedMonth, displayedYear);
+			
+			for(; i < _days.length && dayNumber <= numDays; i++) {
+				_days[i] = new Date(displayedYear, displayedMonth, dayNumber++);
+			}
+			
+			// blank out the rest
+			for(; i < _days.length; i++) {
+				_days[i] = null;
+			}
+		}
+		
+		/**
+		 * @private
+		 */
+		private function numberOfDaysInMonth(month:Number, year:Number):Number
+		{
+			var n:int;
+			
+			if (month == 1) // Feb
+			{
+				if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) // leap year
+					n = 29;
+				else
+					n = 28;
+			}
+				
+			else if (month == 3 || month == 5 || month == 8 || month == 10)
+				n = 30;
+				
+			else
+				n = 31;
+			
+			return n;
+		}
+		
+		/**
+		 * @private
+		 */
+		public function getIndexForSelectedDate():Number
+		{
+			var d:Date = _selectedDate;
+			if (d == null) return -1;
+			
+			for(var i:int=0; i < _days.length; i++) {
+				var test:Date = _days[i] as Date;
+				if (test != null) {
+					if (test.getMonth() == d.getMonth() && test.getDate() == d.getDate() &&
test.getFullYear() == d.getFullYear()) {
+						return i;
+					}
 				}
 			}
+			return -1;
 		}
 	}
 }


Mime
View raw message