Skip to content
This repository was archived by the owner on Feb 10, 2024. It is now read-only.

Commit e55c6c4

Browse files
authored
Merge pull request #176 from tompipe/property-validation
Enables both client and server side validation
2 parents 1bdd3e3 + f48ad3a commit e55c6c4

File tree

2 files changed

+78
-38
lines changed

2 files changed

+78
-38
lines changed

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Js/doctypegrideditor.controllers.js

Lines changed: 76 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -93,49 +93,54 @@
9393
id: $scope.control.value.id
9494
};
9595
overlayOptions.close = function () {
96+
// ensure an empty doctype is not persisted
97+
if($scope.control.$initializing){
98+
$scope.removeControl($scope.area, $scope.control.$index -1);
99+
}
100+
96101
editorService.close();
97102
}
98103
overlayOptions.submit = function (newModel) {
99104

100-
// Copy property values to scope model value
101-
if (newModel.node) {
102-
var value = {
103-
name: newModel.editorName
104-
};
105-
106-
for (var v = 0; v < newModel.node.variants.length; v++) {
107-
var variant = newModel.node.variants[v];
108-
for (var t = 0; t < variant.tabs.length; t++) {
109-
var tab = variant.tabs[t];
110-
for (var p = 0; p < tab.properties.length; p++) {
111-
var prop = tab.properties[p];
112-
if (typeof prop.value !== "function") {
113-
value[prop.alias] = prop.value;
105+
// Copy property values to scope model value
106+
if (newModel.node) {
107+
var value = {
108+
name: newModel.editorName
109+
};
110+
111+
for (var v = 0; v < newModel.node.variants.length; v++) {
112+
var variant = newModel.node.variants[v];
113+
for (var t = 0; t < variant.tabs.length; t++) {
114+
var tab = variant.tabs[t];
115+
for (var p = 0; p < tab.properties.length; p++) {
116+
var prop = tab.properties[p];
117+
if (typeof prop.value !== "function") {
118+
value[prop.alias] = prop.value;
119+
}
120+
}
114121
}
115122
}
116-
}
117-
}
118123

119-
if (newModel.nameExp) {
120-
var newName = newModel.nameExp(value); // Run it against the stored dictionary value, NOT the node object
121-
if (newName && (newName = $.trim(newName))) {
122-
value.name = newName;
123-
}
124-
}
124+
if (newModel.nameExp) {
125+
var newName = newModel.nameExp(value); // Run it against the stored dictionary value, NOT the node object
126+
if (newName && (newName = $.trim(newName))) {
127+
value.name = newName;
128+
}
129+
}
125130

126-
newModel.dialogData.value = value;
127-
} else {
128-
newModel.dialogData.value = null;
131+
newModel.dialogData.value = value;
132+
} else {
133+
newModel.dialogData.value = null;
129134

130-
}
135+
}
131136

132-
$scope.setValue({
133-
dtgeContentTypeAlias: newModel.dialogData.docTypeAlias,
134-
value: newModel.dialogData.value,
135-
id: newModel.dialogData.id
136-
});
137-
$scope.setPreview($scope.control.value);
138-
editorService.close();
137+
$scope.setValue({
138+
dtgeContentTypeAlias: newModel.dialogData.docTypeAlias,
139+
value: newModel.dialogData.value,
140+
id: newModel.dialogData.id
141+
});
142+
$scope.setPreview($scope.control.value);
143+
editorService.close();
139144
};
140145

141146
editorService.open(overlayOptions);
@@ -227,19 +232,52 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
227232
"Our.Umbraco.DocTypeGridEditor.Resources.DocTypeGridEditorResources",
228233
"Our.Umbraco.DocTypeGridEditor.Services.DocTypeGridEditorUtilityService",
229234
"blueprintConfig",
235+
"contentEditingHelper",
236+
"serverValidationManager",
230237

231-
function ($scope, $interpolate, formHelper, contentResource, dtgeResources, dtgeUtilityService, blueprintConfig) {
238+
function ($scope, $interpolate, formHelper, contentResource, dtgeResources, dtgeUtilityService, blueprintConfig, contentEditingHelper, serverValidationManager) {
232239

233240
var vm = this;
234241
vm.submit = submit;
235242
vm.close = close;
236243
vm.loading = true;
237244
vm.blueprintConfig = blueprintConfig;
238245

246+
function cleanup() {
247+
if ($scope.model.node.id > 0){
248+
// delete any temporary blueprints used for validation
249+
contentResource.deleteBlueprint($scope.model.node.id);
250+
}
251+
252+
//clear server validation messages when this editor is destroyed
253+
serverValidationManager.clear();
254+
}
255+
256+
$scope.$on('$destroy', cleanup);
257+
239258
function submit() {
240259
if ($scope.model.submit) {
241-
$scope.$broadcast('formSubmitting', { scope: $scope });
242-
$scope.model.submit($scope.model);
260+
$scope.model.node.name = "Dtge Temp: " + $scope.model.node.key;
261+
$scope.model.node.variants[0].name = $scope.model.node.name
262+
$scope.model.node.variants[0].save = true;
263+
264+
// save the content as a blueprint, to trigger validation
265+
var args = {
266+
saveMethod: contentResource.saveBlueprint,
267+
scope: $scope,
268+
content: $scope.model.node,
269+
create: true,
270+
action: "save",
271+
showNotifications: true,
272+
softRedirect: true
273+
}
274+
275+
contentEditingHelper.contentEditorPerformSave(args).then(function (data) {
276+
$scope.model.submit($scope.model);
277+
},
278+
function (err) {
279+
280+
});
243281
}
244282
}
245283
function close() {
@@ -282,7 +320,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
282320
};
283321

284322
function createFromBlueprint(blueprintId) {
285-
contentResource.getBlueprintScaffold(-20, blueprintId).then(function (data) {
323+
contentResource.getBlueprintScaffold(-1, blueprintId).then(function (data) {
286324
// Assign the model to scope
287325
$scope.nodeContext = $scope.model.node = data;
288326
$scope.dialogMode = "edit";
@@ -297,7 +335,7 @@ angular.module("umbraco").controller("Our.Umbraco.DocTypeGridEditor.Dialogs.DocT
297335

298336
function loadNode() {
299337
vm.loading = true;
300-
contentResource.getScaffold(-20, $scope.model.dialogData.docTypeAlias).then(function (data) {
338+
contentResource.getScaffold(-1, $scope.model.dialogData.docTypeAlias).then(function (data) {
301339

302340
// Merge current value
303341
if ($scope.model.dialogData.value) {

src/Our.Umbraco.DocTypeGridEditor/Web/UI/App_Plugins/DocTypeGridEditor/Views/doctypegrideditor.dialog.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<div class="dtge-dialog" ng-controller="Our.Umbraco.DocTypeGridEditor.Dialogs.DocTypeGridEditorDialog as vm">
22

3+
<form name="dtgeForm" val-form-manager>
34
<umb-editor-view>
45
<umb-editor-header name="dialogMode == 'selectDocType' ? model.titles.selectContentType : dialogMode == 'selectBlueprint' ? model.titles.selectBlueprint : dialogMode == 'edit' ? model.titles.editItem : model.titles.insertItem"
56
name-locked="true"
@@ -114,4 +115,5 @@
114115
</umb-editor-footer-content-right>
115116
</umb-editor-footer>
116117
</umb-editor-view>
118+
</form>
117119
</div>

0 commit comments

Comments
 (0)