Skip to content
This repository was archived by the owner on Dec 13, 2021. It is now read-only.

Commit 2439c12

Browse files
committed
Switched the DTD to reference the GUID instead of the INT
It's one less thing to worry about for Courier deployments
1 parent 3bce45a commit 2439c12

File tree

2 files changed

+69
-27
lines changed

2 files changed

+69
-27
lines changed

src/Our.Umbraco.PropertyList/Web/UI/App_Plugins/PropertyList/js/propertylist.controllers.js

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.RepeatableDataTypeController",
2-
function ($scope, contentTypeResource, umbPropEditorHelper) {
1+
angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.PropertyListController", [
2+
"$scope",
3+
"contentTypeResource",
4+
"Our.Umbraco.PropertyList.Resources.PropertyListResources",
5+
"umbPropEditorHelper",
6+
function ($scope, contentTypeResource, propertyListResource, umbPropEditorHelper) {
37

48
//console.debug("pl", $scope.model.config.dataType, $scope.model.value);
59

6-
var dataTypeId = $scope.model.config.dataType;
7-
var minItems = $scope.model.config.minItems || 0;
8-
var maxItems = $scope.model.config.maxItems || 0;
10+
var dataTypeGuid = $scope.model.config.dataType;
11+
var minItems = $scope.model.config.minItems || 0;
12+
var maxItems = $scope.model.config.maxItems || 0;
913

10-
$scope.isConfigured = dataTypeId != null;
14+
$scope.isConfigured = dataTypeGuid != null;
1115

1216
if ($scope.isConfigured) {
1317

1418
if (!angular.isObject($scope.model.value))
1519
$scope.model.value = undefined;
1620

1721
$scope.model.value = $scope.model.value || {
18-
dtdId: dataTypeId,
22+
dtd: dataTypeGuid,
1923
values: []
2024
};
2125

2226
$scope.prompts = {};
2327

24-
contentTypeResource.getPropertyTypeScaffold(dataTypeId).then(function (propertyType) {
28+
propertyListResource.getPropertyTypeScaffoldByKey(dataTypeGuid).then(function (propertyType) {
2529

2630
$scope.propertyType = propertyType;
2731

@@ -76,10 +80,12 @@
7680
};
7781

7882
$scope.model.controls.splice(idx, 0, control);
83+
$scope.setDirty();
7984
}
8085

8186
$scope.deleteContent = function (evt, idx) {
8287
$scope.model.controls.splice(idx, 1);
88+
$scope.setDirty();
8389
}
8490

8591
$scope.sortableOptions = {
@@ -92,11 +98,15 @@
9298
cursorAt: {
9399
top: 0
94100
},
95-
//update: function (e, ui) {
96-
// _.each($scope.model.controls, function (itm, idx) {
97-
// console.debug("sorted", itm, idx)
98-
// });
99-
//}
101+
update: function (e, ui) {
102+
$scope.setDirty();
103+
}
104+
};
105+
106+
$scope.setDirty = function () {
107+
if ($scope.propertyForm) {
108+
$scope.propertyForm.$setDirty();
109+
}
100110
};
101111

102112
var unsubscribe = $scope.$on("formSubmitting", function (ev, args) {
@@ -106,32 +116,38 @@
106116
tmpValues[idx] = control.value;
107117
});
108118

109-
$scope.model.value.values = !_.isEmpty(tmpValues) ? tmpValues : [];
110-
$scope.model.value.dtdId = dataTypeId;
119+
$scope.model.value = {
120+
dtd: dataTypeGuid,
121+
values: !_.isEmpty(tmpValues) ? tmpValues : []
122+
};
111123
});
112124

113125
$scope.$on('$destroy', function () {
114126
unsubscribe();
115127
});
116128

117-
});
129+
}]);
118130

119-
angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataTypePickerController",
120-
function ($scope, contentTypeResource, dataTypeResource, dataTypeHelper) {
131+
angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataTypePickerController", [
132+
"$scope",
133+
"contentTypeResource",
134+
"dataTypeHelper",
135+
"dataTypeResource",
136+
"entityResource",
137+
"Our.Umbraco.PropertyList.Resources.PropertyListResources",
138+
function ($scope, contentTypeResource, dataTypeHelper, dataTypeResource, entityResource, propertyListResource) {
121139

122140
if (!$scope.model.property) {
123141

124142
$scope.model.property = {};
125143

126144
if ($scope.model.value) {
127-
dataTypeResource.getById($scope.model.value).then(function (dataType) {
128-
145+
propertyListResource.getDataTypeByKey($scope.model.value).then(function (dataType) {
129146
// update editor
130147
$scope.model.property.editor = dataType.selectedEditor;
131148
$scope.model.property.dataTypeId = dataType.id;
132149
$scope.model.property.dataTypeIcon = dataType.icon;
133150
$scope.model.property.dataTypeName = dataType.name;
134-
135151
});
136152
}
137153
}
@@ -141,8 +157,10 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
141157
vm.openEditorPickerOverlay = openEditorPickerOverlay;
142158
vm.openEditorSettingsOverlay = openEditorSettingsOverlay;
143159

144-
function setDataTypeId(dataTypeId) {
145-
$scope.model.value = dataTypeId;
160+
function setModelValue(dataTypeId) {
161+
entityResource.getById(dataTypeId, "DataType").then(function (entity) {
162+
$scope.model.value = entity.key;
163+
});
146164
};
147165

148166
function openEditorPickerOverlay(property) {
@@ -154,7 +172,7 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
154172

155173
vm.editorPickerOverlay.submit = function (model) {
156174

157-
setDataTypeId(model.property.dataTypeId);
175+
setModelValue(model.property.dataTypeId);
158176

159177
vm.editorPickerOverlay.show = false;
160178
vm.editorPickerOverlay = null;
@@ -186,7 +204,7 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
186204

187205
contentTypeResource.getPropertyTypeScaffold(newDataType.id).then(function (propertyType) {
188206

189-
setDataTypeId(newDataType.id);
207+
setModelValue(newDataType.id);
190208

191209
// update editor
192210
property.config = propertyType.config;
@@ -214,5 +232,4 @@ angular.module("umbraco").controller("Our.Umbraco.PropertyList.Controllers.DataT
214232

215233
}
216234

217-
});
218-
235+
}]);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
angular.module("umbraco.resources").factory("Our.Umbraco.PropertyList.Resources.PropertyListResources",
2+
function ($q, $http, umbRequestHelper) {
3+
return {
4+
getDataTypeByKey: function (key) {
5+
return umbRequestHelper.resourcePromise(
6+
$http({
7+
url: "/umbraco/backoffice/PropertyList/PropertyListApi/GetDataTypeByKey",
8+
method: "GET",
9+
params: { key: key }
10+
}),
11+
"Failed to retrieve datatype by key"
12+
);
13+
},
14+
getPropertyTypeScaffoldByKey: function (key) {
15+
return umbRequestHelper.resourcePromise(
16+
$http({
17+
url: "/umbraco/backoffice/PropertyList/PropertyListApi/GetPropertyTypeScaffoldByKey",
18+
method: "GET",
19+
params: { key: key }
20+
}),
21+
"Failed to retrieve property type scaffold by key"
22+
);
23+
}
24+
};
25+
});

0 commit comments

Comments
 (0)