11<?php
22
3- final class PHUIObjectBoxView extends AphrontView {
3+ final class PHUIObjectBoxView extends AphrontTagView {
44
55 private $ headerText ;
66 private $ color ;
@@ -12,9 +12,6 @@ final class PHUIObjectBoxView extends AphrontView {
1212 private $ validationException ;
1313 private $ header ;
1414 private $ flush ;
15- private $ id ;
16- private $ sigils = array ();
17- private $ metadata ;
1815 private $ actionListID ;
1916 private $ objectList ;
2017 private $ table ;
@@ -28,22 +25,18 @@ final class PHUIObjectBoxView extends AphrontView {
2825 private $ showHideOpen ;
2926
3027 private $ tabs = array ();
28+ private $ tabMap = null ;
29+ private $ tabLists = array ();
3130 private $ propertyLists = array ();
31+ private $ propertyList = null ;
3232
3333 const COLOR_RED = 'red ' ;
3434 const COLOR_BLUE = 'blue ' ;
3535 const COLOR_GREEN = 'green ' ;
3636 const COLOR_YELLOW = 'yellow ' ;
3737
38- public function addSigil ($ sigil ) {
39- $ this ->sigils [] = $ sigil ;
40- return $ this ;
41- }
42-
43- public function setMetadata (array $ metadata ) {
44- $ this ->metadata = $ metadata ;
45- return $ this ;
46- }
38+ const BLUE = 'phui-box-blue ' ;
39+ const GREY = 'phui-box-grey ' ;
4740
4841 public function addPropertyList (
4942 PHUIPropertyListView $ property_list ,
@@ -144,11 +137,6 @@ public function setForm($form) {
144137 return $ this ;
145138 }
146139
147- public function setID ($ id ) {
148- $ this ->id = $ id ;
149- return $ this ;
150- }
151-
152140 public function setHeader ($ header ) {
153141 $ this ->header = $ header ;
154142 return $ this ;
@@ -195,7 +183,109 @@ public function setValidationException(
195183 return $ this ;
196184 }
197185
198- public function render () {
186+ public function willRender () {
187+ $ tab_lists = array ();
188+ $ property_lists = array ();
189+ $ tab_map = array ();
190+
191+ $ default_key = 'tab.default ' ;
192+
193+ // Find the selected tab, or select the first tab if none are selected.
194+ if ($ this ->tabs ) {
195+ $ selected_tab = null ;
196+ foreach ($ this ->tabs as $ key => $ tab ) {
197+ if ($ tab ->getSelected ()) {
198+ $ selected_tab = $ key ;
199+ break ;
200+ }
201+ }
202+ if ($ selected_tab === null ) {
203+ head ($ this ->tabs )->setSelected (true );
204+ $ selected_tab = head_key ($ this ->tabs );
205+ }
206+ }
207+
208+ foreach ($ this ->propertyLists as $ key => $ list ) {
209+ $ group = new PHUIPropertyGroupView ();
210+ $ i = 0 ;
211+ foreach ($ list as $ item ) {
212+ $ group ->addPropertyList ($ item );
213+ if ($ i > 0 ) {
214+ $ item ->addClass ('phui-property-list-section-noninitial ' );
215+ }
216+ $ i ++;
217+ }
218+
219+ if ($ this ->tabs && $ key != $ default_key ) {
220+ $ tab_id = celerity_generate_unique_node_id ();
221+ $ tab_map [$ key ] = $ tab_id ;
222+
223+ if ($ key === $ selected_tab ) {
224+ $ style = null ;
225+ } else {
226+ $ style = 'display: none ' ;
227+ }
228+
229+ $ tab_lists [] = phutil_tag (
230+ 'div ' ,
231+ array (
232+ 'style ' => $ style ,
233+ 'id ' => $ tab_id ,
234+ ),
235+ $ group );
236+ } else {
237+ if ($ this ->tabs ) {
238+ $ group ->addClass ('phui-property-group-noninitial ' );
239+ }
240+ $ property_lists [] = $ group ;
241+ }
242+ $ this ->propertyList = $ property_lists ;
243+ $ this ->tabMap = $ tab_map ;
244+ $ this ->tabLists = $ tab_lists ;
245+ }
246+ }
247+
248+ protected function getTagAttributes () {
249+ $ classes = array ();
250+ $ classes [] = 'phui-box ' ;
251+ $ classes [] = 'phui-box-border ' ;
252+ $ classes [] = 'phui-object-box ' ;
253+ $ classes [] = 'mlt mll mlr ' ;
254+
255+ if ($ this ->color ) {
256+ $ classes [] = 'phui-object-box- ' .$ this ->color ;
257+ }
258+
259+ if ($ this ->collapsed ) {
260+ $ classes [] = 'phui-object-box-collapsed ' ;
261+ }
262+
263+ if ($ this ->flush ) {
264+ $ classes [] = 'phui-object-box-flush ' ;
265+ }
266+
267+ if ($ this ->background ) {
268+ $ classes [] = $ this ->background ;
269+ }
270+
271+ $ sigil = null ;
272+ $ metadata = null ;
273+ if ($ this ->tabs ) {
274+ $ sigil = 'phui-object-box ' ;
275+ $ metadata = array (
276+ 'tabMap ' => $ this ->tabMap ,
277+ );
278+ }
279+
280+ return array (
281+ 'class ' => implode (' ' , $ classes ),
282+ 'sigil ' => $ sigil ,
283+ 'meta ' => $ metadata ,
284+ );
285+ }
286+
287+ protected function getTagContent () {
288+ require_celerity_resource ('phui-box-css ' );
199289 require_celerity_resource ('phui-object-box-css ' );
200290
201291 $ header = $ this ->header ;
@@ -296,133 +386,35 @@ public function render() {
296386 }
297387 }
298388
299- $ tab_lists = array ();
300- $ property_lists = array ();
301- $ tab_map = array ();
302-
303- $ default_key = 'tab.default ' ;
304-
305- // Find the selected tab, or select the first tab if none are selected.
306- if ($ this ->tabs ) {
307- $ selected_tab = null ;
308- foreach ($ this ->tabs as $ key => $ tab ) {
309- if ($ tab ->getSelected ()) {
310- $ selected_tab = $ key ;
311- break ;
312- }
313- }
314- if ($ selected_tab === null ) {
315- head ($ this ->tabs )->setSelected (true );
316- $ selected_tab = head_key ($ this ->tabs );
317- }
318- }
319-
320- foreach ($ this ->propertyLists as $ key => $ list ) {
321- $ group = new PHUIPropertyGroupView ();
322- $ i = 0 ;
323- foreach ($ list as $ item ) {
324- $ group ->addPropertyList ($ item );
325- if ($ i > 0 ) {
326- $ item ->addClass ('phui-property-list-section-noninitial ' );
327- }
328- $ i ++;
329- }
330-
331- if ($ this ->tabs && $ key != $ default_key ) {
332- $ tab_id = celerity_generate_unique_node_id ();
333- $ tab_map [$ key ] = $ tab_id ;
334-
335- if ($ key === $ selected_tab ) {
336- $ style = null ;
337- } else {
338- $ style = 'display: none ' ;
339- }
340-
341- $ tab_lists [] = phutil_tag (
342- 'div ' ,
343- array (
344- 'style ' => $ style ,
345- 'id ' => $ tab_id ,
346- ),
347- $ group );
348- } else {
349- if ($ this ->tabs ) {
350- $ group ->addClass ('phui-property-group-noninitial ' );
351- }
352- $ property_lists [] = $ group ;
353- }
354- }
355-
356389 $ tabs = null ;
357390 if ($ this ->tabs ) {
358391 $ tabs = id (new PHUIListView ())
359392 ->setType (PHUIListView::NAVBAR_LIST );
360393 foreach ($ this ->tabs as $ tab ) {
361394 $ tabs ->addMenuItem ($ tab );
362395 }
363-
364396 Javelin::initBehavior ('phui-object-box-tabs ' );
365397 }
366398
367- $ content = id (new PHUIBoxView ())
368- ->appendChild (
369- array (
370- ($ this ->showHideOpen == false ? $ this ->anchor : null ),
371- $ header ,
372- $ this ->infoView ,
373- $ this ->formErrors ,
374- $ this ->formSaved ,
375- $ exception_errors ,
376- $ this ->form ,
377- $ tabs ,
378- $ tab_lists ,
379- $ showhide ,
380- ($ this ->showHideOpen == true ? $ this ->anchor : null ),
381- $ property_lists ,
382- $ this ->table ,
383- $ this ->renderChildren (),
384- ))
385- ->setBorder (true )
386- ->setID ($ this ->id )
387- ->addMargin (PHUI ::MARGIN_LARGE_TOP )
388- ->addMargin (PHUI ::MARGIN_LARGE_LEFT )
389- ->addMargin (PHUI ::MARGIN_LARGE_RIGHT )
390- ->addClass ('phui-object-box ' );
391-
392- if ($ this ->color ) {
393- $ content ->addClass ('phui-object-box- ' .$ this ->color );
394- }
395-
396- if ($ this ->background ) {
397- $ content ->setColor ($ this ->background );
398- }
399-
400- if ($ this ->collapsed ) {
401- $ content ->addClass ('phui-object-box-collapsed ' );
402- }
403-
404- if ($ this ->tabs ) {
405- $ content ->addSigil ('phui-object-box ' );
406- $ content ->setMetadata (
407- array (
408- 'tabMap ' => $ tab_map ,
409- ));
410- }
411-
412- if ($ this ->flush ) {
413- $ content ->addClass ('phui-object-box-flush ' );
414- }
415-
416- foreach ($ this ->sigils as $ sigil ) {
417- $ content ->addSigil ($ sigil );
418- }
419-
420- if ($ this ->metadata !== null ) {
421- $ content ->setMetadata ($ this ->metadata );
422- }
399+ $ content = array (
400+ ($ this ->showHideOpen == false ? $ this ->anchor : null ),
401+ $ header ,
402+ $ this ->infoView ,
403+ $ this ->formErrors ,
404+ $ this ->formSaved ,
405+ $ exception_errors ,
406+ $ this ->form ,
407+ $ tabs ,
408+ $ this ->tabLists ,
409+ $ showhide ,
410+ ($ this ->showHideOpen == true ? $ this ->anchor : null ),
411+ $ this ->propertyList ,
412+ $ this ->table ,
413+ $ this ->renderChildren (),
414+ );
423415
424416 if ($ this ->objectList ) {
425- $ content-> appendChild ( $ this ->objectList ) ;
417+ $ content[] = $ this ->objectList ;
426418 }
427419
428420 return $ content ;
0 commit comments