Skip to content

Commit 213d8c0

Browse files
ronaldbarendsenul800sebastiaan
authored andcommitted
Remove inherited property group id/key when local properties are added (#11231)
* Remove inherited property group id/key when local properties are added * Rebind saved content type values * Remove inherited from save group (cherry picked from commit 20b9db8)
1 parent 11ad3fc commit 213d8c0

File tree

5 files changed

+73
-116
lines changed

5 files changed

+73
-116
lines changed

src/Umbraco.Web.UI.Client/src/common/services/contenttypehelper.service.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,45 @@ function contentTypeHelper(contentTypeResource, dataTypeResource, $filter, $inje
439439

440440
array.push(placeholder);
441441

442+
},
443+
444+
rebindSavedContentType: function (contentType, savedContentType) {
445+
// The saved content type might have updated values (eg. new IDs/keys), so make sure the view model is updated
446+
contentType.ModelState = savedContentType.ModelState;
447+
contentType.id = savedContentType.id;
448+
contentType.groups.forEach(function (group) {
449+
if (!group.alias) return;
450+
451+
var k = 0;
452+
while (k < savedContentType.groups.length && savedContentType.groups[k].alias != group.alias)
453+
k++;
454+
455+
if (k == savedContentType.groups.length) {
456+
group.id = 0;
457+
return;
458+
}
459+
460+
var savedGroup = savedContentType.groups[k];
461+
group.id = savedGroup.id;
462+
group.key = savedGroup.key;
463+
group.contentTypeId = savedGroup.contentTypeId;
464+
465+
group.properties.forEach(function (property) {
466+
if (property.id || !property.alias) return;
467+
468+
k = 0;
469+
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
470+
k++;
471+
472+
if (k == savedGroup.properties.length) {
473+
property.id = 0;
474+
return;
475+
}
476+
477+
var savedProperty = savedGroup.properties[k];
478+
property.id = savedProperty.id;
479+
});
480+
});
442481
}
443482

444483
};

src/Umbraco.Web.UI.Client/src/common/services/umbdataformatter.service.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
return {
3939

40-
formatChangePasswordModel: function(model) {
40+
formatChangePasswordModel: function (model) {
4141
if (!model) {
4242
return null;
4343
}
@@ -59,26 +59,23 @@
5959
},
6060

6161
formatContentTypePostData: function (displayModel, action) {
62-
63-
//create the save model from the display model
62+
// Create the save model from the display model
6463
var saveModel = _.pick(displayModel,
6564
'compositeContentTypes', 'isContainer', 'allowAsRoot', 'allowedTemplates', 'allowedContentTypes',
6665
'alias', 'description', 'thumbnail', 'name', 'id', 'icon', 'trashed',
6766
'key', 'parentId', 'alias', 'path', 'allowCultureVariant', 'allowSegmentVariant', 'isElement');
6867

69-
// TODO: Map these
7068
saveModel.allowedTemplates = _.map(displayModel.allowedTemplates, function (t) { return t.alias; });
7169
saveModel.defaultTemplate = displayModel.defaultTemplate ? displayModel.defaultTemplate.alias : null;
7270
var realGroups = _.reject(displayModel.groups, function (g) {
73-
//do not include these tabs
71+
// Do not include groups with init state
7472
return g.tabState === "init";
7573
});
7674
saveModel.groups = _.map(realGroups, function (g) {
77-
78-
var saveGroup = _.pick(g, 'inherited', 'id', 'sortOrder', 'name', 'key', 'alias', 'type');
75+
var saveGroup = _.pick(g, 'id', 'sortOrder', 'name', 'key', 'alias', 'type');
7976

8077
var realProperties = _.reject(g.properties, function (p) {
81-
//do not include these properties
78+
// Do not include properties with init state or inherited from a composition
8279
return p.propertyState === "init" || p.inherited === true;
8380
});
8481

@@ -89,16 +86,21 @@
8986

9087
saveGroup.properties = saveProperties;
9188

92-
//if this is an inherited group and there are not non-inherited properties on it, then don't send up the data
93-
if (saveGroup.inherited === true && saveProperties.length === 0) {
94-
return null;
89+
if (g.inherited === true) {
90+
if (saveProperties.length === 0) {
91+
// All properties are inherited from the compositions, no need to save this group
92+
return null;
93+
} else if (g.contentTypeId != saveModel.id) {
94+
// We have local properties, but the group id is not local, ensure a new id/key is generated on save
95+
saveGroup = _.omit(saveGroup, 'id', 'key');
96+
}
9597
}
9698

9799
return saveGroup;
98100
});
99101

100-
//we don't want any null groups
101102
saveModel.groups = _.reject(saveModel.groups, function (g) {
103+
// Do not include empty/null groups
102104
return !g;
103105
});
104106

@@ -127,17 +129,17 @@
127129
},
128130

129131
/** formats the display model used to display the dictionary to the model used to save the dictionary */
130-
formatDictionaryPostData : function(dictionary, nameIsDirty) {
132+
formatDictionaryPostData: function (dictionary, nameIsDirty) {
131133
var saveModel = {
132134
parentId: dictionary.parentId,
133135
id: dictionary.id,
134136
name: dictionary.name,
135137
nameIsDirty: nameIsDirty,
136138
translations: [],
137-
key : dictionary.key
139+
key: dictionary.key
138140
};
139141

140-
for(var i = 0; i < dictionary.translations.length; i++) {
142+
for (var i = 0; i < dictionary.translations.length; i++) {
141143
saveModel.translations.push({
142144
isoCode: dictionary.translations[i].isoCode,
143145
languageId: dictionary.translations[i].languageId,
@@ -362,7 +364,7 @@
362364
parentId: displayModel.parentId,
363365
//set the action on the save model
364366
action: action,
365-
variants: _.map(displayModel.variants, function(v) {
367+
variants: _.map(displayModel.variants, function (v) {
366368
return {
367369
name: v.name || "", //if its null/empty,we must pass up an empty string else we get json converter errors
368370
properties: getContentProperties(v.tabs),
@@ -392,7 +394,7 @@
392394
* @param {} displayModel
393395
* @returns {}
394396
*/
395-
formatContentGetData: function(displayModel) {
397+
formatContentGetData: function (displayModel) {
396398

397399
// We need to check for invariant properties among the variant variants,
398400
// as the value of an invariant property is shared between different variants.
@@ -458,12 +460,12 @@
458460
* Formats the display model used to display the relation type to a model used to save the relation type.
459461
* @param {Object} relationType
460462
*/
461-
formatRelationTypePostData : function(relationType) {
463+
formatRelationTypePostData: function (relationType) {
462464
var saveModel = {
463465
id: relationType.id,
464466
name: relationType.name,
465467
alias: relationType.alias,
466-
key : relationType.key,
468+
key: relationType.key,
467469
isBidirectional: relationType.isBidirectional,
468470
parentObjectType: relationType.parentObjectType,
469471
childObjectType: relationType.childObjectType

src/Umbraco.Web.UI.Client/src/views/documenttypes/edit.controller.js

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -324,35 +324,9 @@
324324
scope: $scope,
325325
content: vm.contentType,
326326
infiniteMode: infiniteMode,
327-
// we need to rebind... the IDs that have been created!
328-
rebindCallback: function (origContentType, savedContentType) {
329-
vm.contentType.ModelState = savedContentType.ModelState;
330-
vm.contentType.id = savedContentType.id;
331-
vm.contentType.groups.forEach(function (group) {
332-
if (!group.name) return;
333-
var k = 0;
334-
while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name)
335-
k++;
336-
if (k == savedContentType.groups.length) {
337-
group.id = 0;
338-
return;
339-
}
340-
var savedGroup = savedContentType.groups[k];
341-
if (!group.id) group.id = savedGroup.id;
342-
343-
group.properties.forEach(function (property) {
344-
if (property.id || !property.alias) return;
345-
k = 0;
346-
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
347-
k++;
348-
if (k == savedGroup.properties.length) {
349-
property.id = 0;
350-
return;
351-
}
352-
var savedProperty = savedGroup.properties[k];
353-
property.id = savedProperty.id;
354-
});
355-
});
327+
rebindCallback: function (_, savedContentType) {
328+
// we need to rebind... the IDs that have been created!
329+
contentTypeHelper.rebindSavedContentType(vm.contentType, savedContentType);
356330
}
357331
}).then(function (data) {
358332
// allow UI to access server validation state

src/Umbraco.Web.UI.Client/src/views/mediatypes/edit.controller.js

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -295,38 +295,9 @@
295295
saveMethod: mediaTypeResource.save,
296296
scope: $scope,
297297
content: vm.contentType,
298-
// we need to rebind... the IDs that have been created!
299-
rebindCallback: function (origContentType, savedContentType) {
300-
vm.contentType.id = savedContentType.id;
301-
vm.contentType.groups.forEach(function (group) {
302-
if (!group.name) return;
303-
304-
var k = 0;
305-
while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name)
306-
k++;
307-
if (k == savedContentType.groups.length) {
308-
group.id = 0;
309-
return;
310-
}
311-
312-
var savedGroup = savedContentType.groups[k];
313-
if (!group.id) group.id = savedGroup.id;
314-
315-
group.properties.forEach(function (property) {
316-
if (property.id || !property.alias) return;
317-
318-
k = 0;
319-
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
320-
k++;
321-
if (k == savedGroup.properties.length) {
322-
property.id = 0;
323-
return;
324-
}
325-
326-
var savedProperty = savedGroup.properties[k];
327-
property.id = savedProperty.id;
328-
});
329-
});
298+
rebindCallback: function (_, savedContentType) {
299+
// we need to rebind... the IDs that have been created!
300+
contentTypeHelper.rebindSavedContentType(vm.contentType, savedContentType);
330301
}
331302
}).then(function (data) {
332303
//success

src/Umbraco.Web.UI.Client/src/views/membertypes/edit.controller.js

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@
175175

176176
//we are creating so get an empty data type item
177177
memberTypeResource.getScaffold(memberTypeId)
178-
.then(function (dt) {
179-
init(dt);
178+
.then(function (dt) {
179+
init(dt);
180180

181-
vm.page.loading = false;
182-
});
181+
vm.page.loading = false;
182+
});
183183
}
184184
else {
185185
loadMemberType();
@@ -215,38 +215,9 @@
215215
saveMethod: memberTypeResource.save,
216216
scope: $scope,
217217
content: vm.contentType,
218-
// we need to rebind... the IDs that have been created!
219-
rebindCallback: function (origContentType, savedContentType) {
220-
vm.contentType.id = savedContentType.id;
221-
vm.contentType.groups.forEach(function (group) {
222-
if (!group.name) return;
223-
224-
var k = 0;
225-
while (k < savedContentType.groups.length && savedContentType.groups[k].name != group.name)
226-
k++;
227-
if (k == savedContentType.groups.length) {
228-
group.id = 0;
229-
return;
230-
}
231-
232-
var savedGroup = savedContentType.groups[k];
233-
if (!group.id) group.id = savedGroup.id;
234-
235-
group.properties.forEach(function (property) {
236-
if (property.id || !property.alias) return;
237-
238-
k = 0;
239-
while (k < savedGroup.properties.length && savedGroup.properties[k].alias != property.alias)
240-
k++;
241-
if (k == savedGroup.properties.length) {
242-
property.id = 0;
243-
return;
244-
}
245-
246-
var savedProperty = savedGroup.properties[k];
247-
property.id = savedProperty.id;
248-
});
249-
});
218+
rebindCallback: function (_, savedContentType) {
219+
// we need to rebind... the IDs that have been created!
220+
contentTypeHelper.rebindSavedContentType(vm.contentType, savedContentType);
250221
}
251222
}).then(function (data) {
252223
//success

0 commit comments

Comments
 (0)