Wires up the correct saving logic for media types + validation, refactors the logic so it can be reused everywhere.

This commit is contained in:
Shannon
2015-10-15 14:48:50 +02:00
parent 815d34f8a6
commit 33c206d820
9 changed files with 268 additions and 368 deletions

View File

@@ -3,7 +3,7 @@
* @name umbraco.resources.mediaTypeResource
* @description Loads in data for media types
**/
function mediaTypeResource($q, $http, umbRequestHelper) {
function mediaTypeResource($q, $http, umbRequestHelper, umbDataFormatter) {
return {
@@ -81,12 +81,10 @@ function mediaTypeResource($q, $http, umbRequestHelper) {
save: function (contentType) {
var saveModel = umbDataFormatter.formatContentTypePostData(contentType);
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"mediaTypeApiBaseUrl",
"PostSave"
), contentType),
$http.post(umbRequestHelper.getApiUrl("mediaTypeApiBaseUrl", "PostSave"), saveModel),
'Failed to save data for content type id ' + contentType.id);
},

View File

@@ -154,33 +154,12 @@
vm.contentType = contentTypeHelper.updateTemplatePlaceholder(vm.contentType);
}
//contentTypeResource.save(vm.contentType).then(function(dt){
// formHelper.resetForm({ scope: $scope, notifications: dt.notifications });
// contentEditingHelper.handleSuccessfulSave({
// scope: $scope,
// savedContent: dt,
// rebindCallback: function() {
// }
// });
// notificationsService.success("Document type save");
// //post save logic here -the saved doctype returns as a new object
// init(dt);
// syncTreeNode(vm.contentType, dt.path);
// vm.page.saveButtonState = "success";
//});
contentEditingHelper.contentEditorPerformSave({
statusMessage: "Saving...",
saveMethod: contentTypeResource.save,
scope: $scope,
content: vm.contentType,
//no-op for rebind callback... we don't really need to rebind for content types
//no-op for rebind callback... we don't really need to rebind for content types
rebindCallback: angular.noop
}).then(function (data) {
//success

View File

@@ -9,7 +9,7 @@
(function() {
"use strict";
function MediaTypesEditController($scope, $routeParams, mediaTypeResource, dataTypeResource, editorState, contentEditingHelper, formHelper, navigationService, iconHelper, contentTypeHelper, notificationsService, $filter) {
function MediaTypesEditController($scope, $routeParams, mediaTypeResource, dataTypeResource, editorState, contentEditingHelper, formHelper, navigationService, iconHelper, contentTypeHelper, notificationsService, $filter, $q) {
var vm = this;
@@ -125,49 +125,47 @@
function save() {
// validate form
if (formHelper.submitForm({ scope: $scope })) {
var deferred = $q.defer();
formHelper.resetForm({ scope: $scope });
vm.page.saveButtonState = "busy";
// if form validates - perform save
performSave();
// reformat allowed content types to array if id's
vm.contentType.allowedContentTypes = contentTypeHelper.createIdArray(vm.contentType.allowedContentTypes);
}
// update placeholder template information on new doc types
if (!$routeParams.notemplate && vm.contentType.id === 0) {
vm.contentType = contentTypeHelper.updateTemplatePlaceholder(vm.contentType);
}
contentEditingHelper.contentEditorPerformSave({
statusMessage: "Saving...",
saveMethod: mediaTypeResource.save,
scope: $scope,
content: vm.contentType,
//no-op for rebind callback... we don't really need to rebind for content types
rebindCallback: angular.noop
}).then(function (data) {
//success
syncTreeNode(vm.contentType, data.path);
vm.page.saveButtonState = "success";
deferred.resolve(data);
}, function (err) {
//error
if (err) {
editorState.set($scope.content);
}
vm.page.saveButtonState = "error";
deferred.reject(err);
});
return deferred.promise;
}
function performSave() {
vm.page.saveButtonState = "busy";
// reformat allowed content types to array if id's
vm.contentType.allowedContentTypes = contentTypeHelper.createIdArray(vm.contentType.allowedContentTypes);
mediaTypeResource.save(vm.contentType).then(function(dt){
formHelper.resetForm({ scope: $scope, notifications: dt.notifications });
contentEditingHelper.handleSuccessfulSave({
scope: $scope,
savedContent: dt,
rebindCallback: function() {
}
});
notificationsService.success("Media type saved");
//post save logic here -the saved doctype returns as a new object
init(dt);
syncTreeNode(vm.contentType, dt.path);
vm.page.saveButtonState = "success";
});
}
function init(contentType){
// set all tab to inactive