@@ -54,6 +54,9 @@ public partial class ContentTypeControlNew : UmbracoUserControl
54
54
// "Structure" tab
55
55
protected DualSelectbox DualAllowedContentTypes = new DualSelectbox ( ) ;
56
56
57
+ // "Structure" tab - Compositions
58
+ protected DualSelectbox DualContentTypeCompositions = new DualSelectbox ( ) ;
59
+
57
60
// "Info" tab
58
61
public uicontrols . TabPage InfoTabPage ;
59
62
@@ -88,6 +91,7 @@ override protected void OnInit(EventArgs e)
88
91
else
89
92
{
90
93
SetupStructurePane ( ) ;
94
+ SetupCompositionsPane ( ) ;
91
95
}
92
96
93
97
SetupGenericPropertiesPane ( ) ;
@@ -105,7 +109,7 @@ protected void Page_Load(object sender, EventArgs e)
105
109
pp_alias . Text = ui . Text ( "alias" , Security . CurrentUser ) ;
106
110
pp_name . Text = ui . Text ( "name" , Security . CurrentUser ) ;
107
111
pp_allowedChildren . Text = ui . Text ( "allowedchildnodetypes" , Security . CurrentUser ) ;
108
-
112
+ pp_compositions . Text = ui . Text ( "contenttypecompositions" , Security . CurrentUser ) ;
109
113
pp_description . Text = ui . Text ( "editcontenttype" , "description" , Security . CurrentUser ) ;
110
114
pp_icon . Text = ui . Text ( "icon" , Security . CurrentUser ) ;
111
115
@@ -291,20 +295,62 @@ protected void save_click(object sender, EventArgs e)
291
295
Trace . Write ( "ContentTypeControlNew" , "executing task" ) ;
292
296
293
297
//we need to re-set the UmbracoContext since it will be nulled and our cache handlers need it
294
- global ::Umbraco . Web . UmbracoContext . Current = asyncState . UmbracoContext ;
298
+ // global::Umbraco.Web.UmbracoContext.Current = asyncState.UmbracoContext;
295
299
296
300
_contentType . ContentTypeItem . Name = txtName . Text ;
297
301
_contentType . ContentTypeItem . Alias = txtAlias . Text ; // raw, contentType.Alias takes care of it
298
302
_contentType . ContentTypeItem . Icon = tb_icon . Value ;
299
303
_contentType . ContentTypeItem . Description = description . Text ;
300
- //_contentType.ContentTypeItem.Thumbnail = ddlThumbnails.SelectedValue;
304
+ //_contentType.ContentTypeItem.Thumbnail = ddlThumbnails.SelectedValue;
301
305
_contentType . ContentTypeItem . AllowedAsRoot = allowAtRoot . Checked ;
302
306
_contentType . ContentTypeItem . IsContainer = cb_isContainer . Checked ;
303
307
304
308
int i = 0 ;
305
309
var ids = SaveAllowedChildTypes ( ) ;
306
310
_contentType . ContentTypeItem . AllowedContentTypes = ids . Select ( x => new ContentTypeSort { Id = new Lazy < int > ( ( ) => x ) , SortOrder = i ++ } ) ;
307
311
312
+ //Saving ContentType Compositions
313
+ var compositionIds = SaveCompositionContentTypes ( ) ;
314
+ var existingCompsitionIds = _contentType . ContentTypeItem . CompositionIds ( ) . ToList ( ) ;
315
+ if ( compositionIds . Any ( ) )
316
+ {
317
+ //Iterate ContentType Ids from the save-collection
318
+ foreach ( var compositionId in compositionIds )
319
+ {
320
+ //If the compositionId is the Id of the current ContentType we skip it
321
+ if ( _contentType . Id . Equals ( compositionId ) ) continue ;
322
+
323
+ //If the Id already exists we'll just skip it
324
+ if ( existingCompsitionIds . Any ( x => x . Equals ( compositionId ) ) ) continue ;
325
+
326
+ //New Ids will get added to the collection
327
+ var compositionType = Services . ContentTypeService . GetContentType ( compositionId ) ;
328
+ var added = _contentType . ContentTypeItem . AddContentType ( compositionType ) ;
329
+ //TODO if added=false then return error message
330
+ }
331
+
332
+ //Iterate the set except of existing and new Ids
333
+ var removeIds = existingCompsitionIds . Except ( compositionIds ) ;
334
+ foreach ( var removeId in removeIds )
335
+ {
336
+ //Remove ContentTypes that was deselected in the list
337
+ var compositionType = Services . ContentTypeService . GetContentType ( removeId ) ;
338
+ var removed = _contentType . ContentTypeItem . RemoveContentType ( compositionType . Alias ) ;
339
+ }
340
+ }
341
+ else if ( existingCompsitionIds . Any ( ) )
342
+ {
343
+ //Iterate the set except of existing and new Ids
344
+ var removeIds = existingCompsitionIds . Except ( compositionIds ) ;
345
+ foreach ( var removeId in removeIds )
346
+ {
347
+ //Remove ContentTypes that was deselected in the list
348
+ var compositionType = Services . ContentTypeService . GetContentType ( removeId ) ;
349
+ var removed = _contentType . ContentTypeItem . RemoveContentType ( compositionType . Alias ) ;
350
+ }
351
+ }
352
+
353
+
308
354
var tabs = SaveTabs ( ) ;
309
355
foreach ( var tab in tabs )
310
356
{
@@ -319,6 +365,7 @@ protected void save_click(object sender, EventArgs e)
319
365
}
320
366
321
367
SavePropertyType ( asyncState . SaveArgs , _contentType . ContentTypeItem ) ;
368
+ //SavePropertyType(state.SaveArgs, _contentType.ContentTypeItem);
322
369
UpdatePropertyTypes ( _contentType . ContentTypeItem ) ;
323
370
324
371
if ( DocumentTypeCallback != null )
@@ -342,8 +389,10 @@ protected void save_click(object sender, EventArgs e)
342
389
catch ( DuplicateNameException ex )
343
390
{
344
391
DuplicateAliasValidator . IsValid = false ;
345
- asyncState . SaveArgs . IconType = BasePage . speechBubbleIcon . error ;
346
- asyncState . SaveArgs . Message = ex . Message ;
392
+ //asyncState.SaveArgs.IconType = BasePage.speechBubbleIcon.error;
393
+ state . SaveArgs . IconType = BasePage . speechBubbleIcon . error ;
394
+ //asyncState.SaveArgs.Message = ex.Message;
395
+ state . SaveArgs . Message = ex . Message ;
347
396
return ;
348
397
}
349
398
@@ -580,6 +629,56 @@ private int[] SaveAllowedChildTypes()
580
629
581
630
#endregion
582
631
632
+ #region Compositions Pane
633
+
634
+ private void SetupCompositionsPane ( )
635
+ {
636
+ DualContentTypeCompositions . ID = "compositionContentTypes" ;
637
+ DualContentTypeCompositions . Width = 175 ;
638
+
639
+ int [ ] compositionIds = _contentType . ContentTypeItem . CompositionIds ( ) . ToArray ( ) ;
640
+ if ( ! Page . IsPostBack )
641
+ {
642
+ string chosenContentTypeIDs = "" ;
643
+ ContentType [ ] contentTypes = _contentType . GetAll ( ) ;
644
+ foreach ( ContentType ct in contentTypes . OrderBy ( x => x . Text ) )
645
+ {
646
+ ListItem li = new ListItem ( ct . Text , ct . Id . ToString ( ) ) ;
647
+ if ( ct . Id == _contentType . Id )
648
+ li . Enabled = false ;
649
+
650
+ DualContentTypeCompositions . Items . Add ( li ) ;
651
+ lstContentTypeCompositions . Items . Add ( li ) ;
652
+
653
+ foreach ( int i in compositionIds )
654
+ {
655
+ if ( i == ct . Id )
656
+ {
657
+ li . Selected = true ;
658
+ chosenContentTypeIDs += ct . Id + "," ;
659
+ }
660
+ }
661
+ }
662
+ DualContentTypeCompositions . Value = chosenContentTypeIDs ;
663
+ }
664
+ }
665
+
666
+ private int [ ] SaveCompositionContentTypes ( )
667
+ {
668
+ var tmp = new ArrayList ( ) ;
669
+ foreach ( ListItem li in lstContentTypeCompositions . Items )
670
+ {
671
+ if ( li . Selected )
672
+ tmp . Add ( int . Parse ( li . Value ) ) ;
673
+ }
674
+ var ids = new int [ tmp . Count ] ;
675
+ for ( int i = 0 ; i < tmp . Count ; i ++ ) ids [ i ] = ( int ) tmp [ i ] ;
676
+
677
+ return ids ;
678
+ }
679
+
680
+ #endregion
681
+
583
682
#region "Generic properties" Pane
584
683
585
684
private void SetupGenericPropertiesPane ( )
@@ -1625,5 +1724,41 @@ protected void dgTabs_itemdatabound(object sender, DataGridItemEventArgs e)
1625
1724
/// To modify move field declaration from designer file to code-behind file.
1626
1725
/// </remarks>
1627
1726
protected global ::System . Web . UI . WebControls . CustomValidator DuplicateAliasValidator ;
1727
+
1728
+ /// <summary>
1729
+ /// Pane9 control.
1730
+ /// </summary>
1731
+ /// <remarks>
1732
+ /// Auto-generated field.
1733
+ /// To modify move field declaration from designer file to code-behind file.
1734
+ /// </remarks>
1735
+ protected global ::umbraco . uicontrols . Pane Pane9 ;
1736
+
1737
+ /// <summary>
1738
+ /// pp_compositions control.
1739
+ /// </summary>
1740
+ /// <remarks>
1741
+ /// Auto-generated field.
1742
+ /// To modify move field declaration from designer file to code-behind file.
1743
+ /// </remarks>
1744
+ protected global ::umbraco . uicontrols . PropertyPanel pp_compositions ;
1745
+
1746
+ /// <summary>
1747
+ /// lstContentTypeCompositions control.
1748
+ /// </summary>
1749
+ /// <remarks>
1750
+ /// Auto-generated field.
1751
+ /// To modify move field declaration from designer file to code-behind file.
1752
+ /// </remarks>
1753
+ protected global ::System . Web . UI . WebControls . CheckBoxList lstContentTypeCompositions ;
1754
+
1755
+ /// <summary>
1756
+ /// PlaceHolderContentTypeCompositions control.
1757
+ /// </summary>
1758
+ /// <remarks>
1759
+ /// Auto-generated field.
1760
+ /// To modify move field declaration from designer file to code-behind file.
1761
+ /// </remarks>
1762
+ protected global ::System . Web . UI . WebControls . PlaceHolder PlaceHolderContentTypeCompositions ;
1628
1763
}
1629
1764
}
0 commit comments