@@ -19,6 +19,7 @@ class ManiphestAuxiliaryFieldDefaultSpecification
1919 const TYPE_STRING = 'string ' ;
2020 const TYPE_INT = 'int ' ;
2121 const TYPE_BOOL = 'bool ' ;
22+ const TYPE_DATE = 'date ' ;
2223
2324 public function getFieldType () {
2425 return $ this ->fieldType ;
@@ -92,22 +93,36 @@ public function renderControl() {
9293 case self ::TYPE_BOOL :
9394 $ control = new AphrontFormCheckboxControl ();
9495 break ;
96+ case self ::TYPE_DATE :
97+ $ control = new AphrontFormDateControl ();
98+ $ control ->setUser ($ this ->getUser ());
99+ $ control ->setValue (time ());
100+ break ;
95101 default :
96102 $ label = $ this ->getLabel ();
97103 throw new ManiphestAuxiliaryFieldTypeException (
98104 "Field type ' {$ type }' is not a valid type (for field ' {$ label }'). " );
99105 break ;
100106 }
101107
102- if ($ type == self ::TYPE_BOOL ) {
103- $ control ->addCheckbox (
104- 'auxiliary[ ' .$ this ->getAuxiliaryKey ().'] ' ,
105- 1 ,
106- $ this ->getCheckboxLabel (),
107- (bool )$ this ->getValue ());
108- } else {
109- $ control ->setValue ($ this ->getValue ());
110- $ control ->setName ('auxiliary[ ' .$ this ->getAuxiliaryKey ().'] ' );
108+ switch ($ type ) {
109+ case self ::TYPE_BOOL :
110+ $ control ->addCheckbox (
111+ 'auxiliary[ ' .$ this ->getAuxiliaryKey ().'] ' ,
112+ 1 ,
113+ $ this ->getCheckboxLabel (),
114+ (bool )$ this ->getValue ());
115+ break ;
116+ case self ::TYPE_DATE :
117+ if ($ this ->getValue ()) {
118+ $ control ->setValue ($ this ->getValue ());
119+ }
120+ $ control ->setName ('auxiliary_date_ ' .$ this ->getAuxiliaryKey ());
121+ break ;
122+ default :
123+ $ control ->setValue ($ this ->getValue ());
124+ $ control ->setName ('auxiliary[ ' .$ this ->getAuxiliaryKey ().'] ' );
125+ break ;
111126 }
112127
113128 $ control ->setLabel ($ this ->getLabel ());
@@ -117,9 +132,18 @@ public function renderControl() {
117132 return $ control ;
118133 }
119134
120- public function setValueFromRequest ($ request ) {
121- $ aux_post_values = $ request ->getArr ('auxiliary ' );
122- return $ this ->setValue (idx ($ aux_post_values , $ this ->getAuxiliaryKey (), '' ));
135+ public function setValueFromRequest (AphrontRequest $ request ) {
136+ switch ($ this ->getFieldType ()) {
137+ case self ::TYPE_DATE :
138+ $ control = $ this ->renderControl ();
139+ $ value = $ control ->readValueFromRequest ($ request );
140+ break ;
141+ default :
142+ $ aux_post_values = $ request ->getArr ('auxiliary ' );
143+ $ value = idx ($ aux_post_values , $ this ->getAuxiliaryKey (), '' );
144+ break ;
145+ }
146+ return $ this ->setValue ($ value );
123147 }
124148
125149 public function getValueForStorage () {
@@ -135,8 +159,9 @@ public function validate() {
135159 case self ::TYPE_INT :
136160 if (!is_numeric ($ this ->getValue ())) {
137161 throw new ManiphestAuxiliaryFieldValidationException (
138- $ this ->getLabel ().' must be an integer value. '
139- );
162+ pht (
163+ '%s must be an integer value. ' ,
164+ $ this ->getLabel ()));
140165 }
141166 break ;
142167 case self ::TYPE_BOOL :
@@ -145,6 +170,14 @@ public function validate() {
145170 return true ;
146171 case self ::TYPE_SELECT :
147172 return true ;
173+ case self ::TYPE_DATE :
174+ if ($ this ->getValue () <= 0 ) {
175+ throw new ManiphestAuxiliaryFieldValidationException (
176+ pht (
177+ '%s must be a valid date. ' ,
178+ $ this ->getLabel ()));
179+ }
180+ break ;
148181 }
149182 }
150183
@@ -159,11 +192,13 @@ public function renderForDetailView() {
159192 case self ::TYPE_SELECT :
160193 $ display = idx ($ this ->getSelectOptions (), $ this ->getValue ());
161194 return $ display ;
195+ case self ::TYPE_DATE :
196+ $ display = phabricator_datetime ($ this ->getValue (), $ this ->getUser ());
197+ return $ display ;
162198 }
163199 return parent ::renderForDetailView ();
164200 }
165201
166-
167202 public function renderTransactionDescription (
168203 ManiphestTransaction $ transaction ,
169204 $ target ) {
@@ -190,6 +225,16 @@ public function renderTransactionDescription(
190225 "from ' {$ old_display }' to ' {$ new_display }' " ;
191226 }
192227 break ;
228+ case self ::TYPE_DATE :
229+ $ new_display = phabricator_datetime ($ new , $ this ->getUser ());
230+ if ($ old === null ) {
231+ $ desc = "set field ' {$ label }' to ' {$ new_display }' " ;
232+ } else {
233+ $ old_display = phabricator_datetime ($ old , $ this ->getUser ());
234+ $ desc = "changed field ' {$ label }' " .
235+ "from ' {$ old_display }' to ' {$ new_display }' " ;
236+ }
237+ break ;
193238 default :
194239 if (!strlen ($ old )) {
195240 if (!strlen ($ new )) {
0 commit comments