got data type editor dynamically loading pre-vals when the drop down changes, got the mock services to save the data.

This commit is contained in:
Shannon
2013-08-19 12:37:04 +10:00
parent bcf49c440a
commit 024511a605
9 changed files with 172 additions and 51 deletions

View File

@@ -7,6 +7,48 @@ angular.module('umbraco.mocks').
return {
getMockDataType: function(id, selectedId) {
var dataType = {
id: id,
name: "Simple editor " + id,
selectedEditor: selectedId,
availableEditors: [
{ name: "Simple editor 1", editorId: String.CreateGuid() },
{ name: "Simple editor 2", editorId: String.CreateGuid() },
{ name: "Simple editor " + id, editorId: selectedId },
{ name: "Simple editor 4", editorId: String.CreateGuid() },
{ name: "Simple editor 5", editorId: String.CreateGuid() },
{ name: "Simple editor 6", editorId: String.CreateGuid() }
],
preValues: [
{
label: "Custom pre value 1 for editor " + selectedId,
description: "Enter a value for this pre-value",
key: "myPreVal",
view: "requiredfield",
validation: [
{
type: "Required"
}
]
},
{
label: "Custom pre value 2 for editor " + selectedId,
description: "Enter a value for this pre-value",
key: "myPreVal",
view: "requiredfield",
validation: [
{
type: "Required"
}
]
}
]
};
return dataType;
},
/** Creats a mock content object */
getMockContent: function(id) {
var node = {

View File

@@ -119,9 +119,22 @@ angular.module('umbraco.mocks').
return [200, null, null];
}
function returnSave(status, data, headers) {
if (!mocksUtils.checkAuth()) {
return [401, null, null];
}
return [200, null, null];
}
return {
register: function () {
$httpBackend
.whenPOST(mocksUtils.urlRegex('/umbraco/UmbracoApi/Content/PostSave'))
.respond(returnSave);
$httpBackend
.whenPOST(mocksUtils.urlRegex('/umbraco/UmbracoApi/Content/PostSort'))
.respond(returnSort);

View File

@@ -12,44 +12,8 @@ angular.module('umbraco.mocks').
var selectedId = String.CreateGuid();
var dataType = {
id: id,
name: "Simple editor " + id,
selectedEditor: selectedId,
availableEditors: [
{ name: "Simple editor 1", editorId: String.CreateGuid() },
{ name: "Simple editor 2", editorId: String.CreateGuid() },
{ name: "Simple editor 3", editorId: selectedId },
{ name: "Simple editor 4", editorId: String.CreateGuid() },
{ name: "Simple editor 5", editorId: String.CreateGuid() },
{ name: "Simple editor 6", editorId: String.CreateGuid() }
],
preValues: [
{
label: "Custom pre value 1",
description: "Enter a value for this pre-value",
key: "myPreVal",
view: "requiredfield",
validation: [
{
type: "Required"
}
]
},
{
label: "Custom pre value 2",
description: "Enter a value for this pre-value",
key: "myPreVal",
view: "requiredfield",
validation: [
{
type: "Required"
}
]
}
]
var dataType = mocksUtils.getMockDataType(id, selectedId);
};
return [200, dataType, null];
}
@@ -69,17 +33,77 @@ angular.module('umbraco.mocks').
return response;
}
function returnPreValues(status, data, headers) {
if (!mocksUtils.checkAuth()) {
return [401, null, null];
}
var editorId = mocksUtils.getParameterByName(data, "editorId") || "83E9AD36-51A7-4440-8C07-8A5623AC6979";
var preValues = [
{
label: "Custom pre value 1 for editor " + editorId,
description: "Enter a value for this pre-value",
key: "myPreVal",
view: "requiredfield",
validation: [
{
type: "Required"
}
]
},
{
label: "Custom pre value 2 for editor " + editorId,
description: "Enter a value for this pre-value",
key: "myPreVal",
view: "requiredfield",
validation: [
{
type: "Required"
}
]
}
];
return [200, preValues, null];
}
function returnSave(status, data, headers) {
if (!mocksUtils.checkAuth()) {
return [401, null, null];
}
var postedData = angular.fromJson(headers);
var dataType = mocksUtils.getMockDataType(postedData.id, postedData.selectedEditor);
dataType.notifications = [{
header: "Saved",
message: "Data type saved",
type: 0
}];
return [200, dataType, null];
}
return {
register: function() {
$httpBackend
.whenPOST(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/PostSave'))
.respond(returnSave);
$httpBackend
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetById'))
.respond(returnById);
.respond(returnById);
$httpBackend
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetEmpty'))
.respond(returnEmpty);
$httpBackend
.whenGET(mocksUtils.urlRegex('/umbraco/UmbracoApi/DataType/GetPreValues'))
.respond(returnPreValues);
},
expectGetById: function() {
$httpBackend

View File

@@ -7,6 +7,17 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
return {
getPreValues: function (editorId) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"dataTypeApiBaseUrl",
"GetPreValues",
[{ editorId: editorId }])),
'Failed to retreive pre values for editor id ' + editorId);
},
getById: function (id) {
return umbRequestHelper.resourcePromise(
@@ -39,7 +50,7 @@ function dataTypeResource($q, $http, umbDataFormatter, umbRequestHelper) {
//TODO: SD: I need to finish this on Monday!
action: "save" + (isNew ? "New" : "")
}),
'Failed to save data for data type id ' + id);
'Failed to save data for data type id ' + dataType.id);
}
};
}

View File

@@ -196,9 +196,13 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
args.scope.$broadcast("saved", { scope: args.scope });
if (!this.redirectToCreatedContent(args.scope.content.id)) {
//we are not redirecting because this is not new content, it is existing content. In this case
// we need to detect what properties have changed and re-bind them with the server data
this.reBindChangedProperties(args.scope.content, args.newContent);
// we need to detect what properties have changed and re-bind them with the server data.
//call the callback
if (args.rebindCallback && angular.isFunction(args.rebindCallback)) {
args.rebindCallback();
}
}
},
@@ -227,7 +231,7 @@ function contentEditingHelper($location, $routeParams, notificationsService, ser
//clear the query strings
$location.search(null);
//change to new path
$location.path("/" + $routeParams.section + "/" + $routeParams.method + "/" + id);
$location.path("/" + $routeParams.section + "/" + $routeParams.tree + "/" + $routeParams.method + "/" + id);
//don't add a browser history for this
$location.replace();
return true;

View File

@@ -68,7 +68,7 @@ angular.module('umbraco.services')
if (!args) {
throw "args cannot be null";
}
if (!args.type) {
if (args.type === undefined || args.type === null) {
throw "args.type cannot be null";
}
if (!args.header) {

View File

@@ -58,10 +58,13 @@ function ContentEditController($scope, $routeParams, $location, contentResource,
contentResource.publish(cnt, $routeParams.create, $scope.files)
.then(function (data) {
contentEditingHelper.handleSuccessfulSave({
scope: $scope,
newContent: data
newContent: data,
rebindCallback: contentEditingHelper.reBindChangedProperties(scope.content, data)
});
}, function (err) {
contentEditingHelper.handleSaveError(err, $scope);
});
@@ -77,10 +80,13 @@ function ContentEditController($scope, $routeParams, $location, contentResource,
contentResource.save(cnt, $routeParams.create, $scope.files)
.then(function (data) {
contentEditingHelper.handleSuccessfulSave({
scope: $scope,
newContent: data
newContent: data,
rebindCallback: contentEditingHelper.reBindChangedProperties(scope.content, data)
});
}, function (err) {
contentEditingHelper.handleSaveError(err, $scope);
});

View File

@@ -42,6 +42,7 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc
dataTypeResource.getScaffold($routeParams.id, $routeParams.doctype)
.then(function(data) {
$scope.loaded = true;
$scope.preValuesLoaded = true;
$scope.content = data;
createDisplayProps();
});
@@ -51,6 +52,7 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc
dataTypeResource.getById($routeParams.id)
.then(function(data) {
$scope.loaded = true;
$scope.preValuesLoaded = true;
$scope.content = data;
createDisplayProps();
createPreValueProps($scope.content.preValues);
@@ -66,8 +68,19 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc
//ensure there is a form object assigned.
var currentForm = angularHelper.getRequiredCurrentForm($scope);
//TODO: We need to handle the dynamic loading of the pre-value editor view whenever the drop down changes!
$scope.$watch("content.selectedEditor", function (newVal, oldVal) {
//when the value changes, we need to dynamically load in the new editor
if (newVal && oldVal && newVal != oldVal) {
//we are editing so get the content item from the server
dataTypeResource.getPreValues(newVal)
.then(function (data) {
$scope.preValuesLoaded = true;
$scope.content.preValues = data;
createPreValueProps($scope.content.preValues);
});
}
});
$scope.save = function (cnt) {
$scope.$broadcast("saving", { scope: $scope });
@@ -79,8 +92,13 @@ function DataTypeEditController($scope, $routeParams, $location, dataTypeResourc
dataTypeResource.save(cnt, $routeParams.create)
.then(function (data) {
//TODO: SD: I need to finish this on monday!
alert("Woot!");
contentEditingHelper.handleSuccessfulSave({
scope: $scope,
newContent: data,
rebindCallback: function() {
createPreValueProps(data.preValues);
}
});
}, function (err) {
contentEditingHelper.handleSaveError(err, $scope);

View File

@@ -57,10 +57,13 @@ function mediaEditController($scope, $routeParams, mediaResource, notificationsS
mediaResource.save(cnt, $routeParams.create, $scope.files)
.then(function (data) {
contentEditingHelper.handleSuccessfulSave({
scope: $scope,
newContent: data
newContent: data,
rebindCallback: contentEditingHelper.reBindChangedProperties(scope.content, data)
});
}, function (err) {
contentEditingHelper.handleSaveError(err, $scope);
});