Updated the saving model and validator inheritance chain to better support members, have the members editor display data and posting/validating data - now need to get the correct fields being displayed and the correct tab/layout but coming along very nicely!

This commit is contained in:
Shannon
2013-09-27 16:59:38 +10:00
parent 82c784d560
commit a3d674f574
27 changed files with 341 additions and 84 deletions

View File

@@ -27,11 +27,17 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
/** internal method process the saving of data and post processing the result */
function saveContentItem(content, action, files) {
return umbRequestHelper.postSaveContent(
umbRequestHelper.getApiUrl(
return umbRequestHelper.postSaveContent({
restApiUrl: umbRequestHelper.getApiUrl(
"contentApiBaseUrl",
"PostSave"),
content, action, files);
content: content,
action: action,
files: files,
dataFormatter: function (c, a) {
return umbDataFormatter.formatContentPostData(c, a);
}
});
}
return {

View File

@@ -7,11 +7,17 @@ function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
/** internal method process the saving of data and post processing the result */
function saveMediaItem(content, action, files) {
return umbRequestHelper.postSaveContent(
umbRequestHelper.getApiUrl(
return umbRequestHelper.postSaveContent({
restApiUrl: umbRequestHelper.getApiUrl(
"mediaApiBaseUrl",
"PostSave"),
content, action, files);
content: content,
action: action,
files: files,
dataFormatter: function (c, a) {
return umbDataFormatter.formatMediaPostData(c, a);
}
});
}
return {

View File

@@ -7,11 +7,18 @@ function memberResource($q, $http, umbDataFormatter, umbRequestHelper) {
/** internal method process the saving of data and post processing the result */
function saveMember(content, action, files) {
return umbRequestHelper.postSaveContent(
umbRequestHelper.getApiUrl(
return umbRequestHelper.postSaveContent({
restApiUrl: umbRequestHelper.getApiUrl(
"memberApiBaseUrl",
"PostSave"),
content, action, files);
content: content,
action: action,
files: files,
dataFormatter: function(c, a) {
return umbDataFormatter.formatMemberPostData(c, a);
}
});
}
return {

View File

@@ -151,26 +151,43 @@ function umbRequestHelper($http, $q, umbDataFormatter, angularHelper, dialogServ
},
/** Used for saving media/content specifically */
postSaveContent: function (restApiUrl, content, action, files) {
postSaveContent: function (args) {
if (!args.restApiUrl) {
throw "args.restApiUrl is a required argument";
}
if (!args.content) {
throw "args.content is a required argument";
}
if (!args.action) {
throw "args.action is a required argument";
}
if (!args.files) {
throw "args.files is a required argument";
}
if (!args.dataFormatter) {
throw "args.dataFormatter is a required argument";
}
var deferred = $q.defer();
//save the active tab id so we can set it when the data is returned.
var activeTab = _.find(content.tabs, function (item) {
var activeTab = _.find(args.content.tabs, function (item) {
return item.active;
});
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(content.tabs, activeTab));
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(args.content.tabs, activeTab));
//save the data
this.postMultiPartRequest(
restApiUrl,
{ key: "contentItem", value: umbDataFormatter.formatContentPostData(content, action) },
args.restApiUrl,
{ key: "contentItem", value: args.dataFormatter(args.content, args.action) },
function (data, formData) {
//now add all of the assigned files
for (var f in files) {
for (var f in args.files) {
//each item has a property id and the file object, we'll ensure that the id is suffixed to the key
// so we know which property it belongs to on the server side
formData.append("file_" + files[f].id, files[f].file);
formData.append("file_" + args.files[f].id, args.files[f].file);
}
},

View File

@@ -196,24 +196,45 @@ function umbDataFormatter() {
return saveModel;
},
/** formats the display model used to display the content to the model used to save the content */
formatContentPostData: function (displayModel, action) {
/** formats the display model used to display the member to the model used to save the member */
formatMemberPostData: function(displayModel, action) {
//this is basically the same as for media but we need to explicitly add the username,email to the save model
var saveModel = this.formatMediaPostData(displayModel, action);
var genericTab = _.find(displayModel.tabs, function (item) {
return item.id === 0;
});
var propLogin = _.find(genericTab.properties, function (item) {
return item.alias === "_umb_login";
});
var propEmail = _.find(genericTab.properties, function (item) {
return item.alias === "_umb_email";
});
saveModel.email = propEmail.value;
saveModel.username = propLogin.value;
return saveModel;
},
/** formats the display model used to display the media to the model used to save the media */
formatMediaPostData: function(displayModel, action) {
//NOTE: the display model inherits from the save model so we can in theory just post up the display model but
// we don't want to post all of the data as it is unecessary.
var saveModel = {
id: displayModel.id,
properties: [],
name: displayModel.name,
contentTypeAlias : displayModel.contentTypeAlias,
contentTypeAlias: displayModel.contentTypeAlias,
parentId: displayModel.parentId,
//set the action on the save model
action: action
};
_.each(displayModel.tabs, function (tab) {
_.each(tab.properties, function (prop) {
//don't include the custom generic tab properties
if (!prop.alias.startsWith("_umb_")) {
saveModel.properties.push({
@@ -222,25 +243,36 @@ function umbDataFormatter() {
value: prop.value
});
}
else {
//here we need to map some of our internal properties to the content save item
switch (prop.alias) {
case "_umb_expiredate":
saveModel.expireDate = prop.value;
break;
case "_umb_releasedate":
saveModel.releaseDate = prop.value;
break;
case "_umb_template":
saveModel.templateAlias = prop.value;
break;
}
}
});
});
return saveModel;
},
/** formats the display model used to display the content to the model used to save the content */
formatContentPostData: function (displayModel, action) {
//this is basically the same as for media but we need to explicitly add some extra properties
var saveModel = this.formatMediaPostData(displayModel, action);
var genericTab = _.find(displayModel.tabs, function (item) {
return item.id === 0;
});
var propExpireDate = _.find(genericTab.properties, function(item) {
return item.alias === "_umb_expiredate";
});
var propReleaseDate = _.find(genericTab.properties, function (item) {
return item.alias === "_umb_releasedate";
});
var propTemplate = _.find(genericTab.properties, function (item) {
return item.alias === "_umb_template";
});
saveModel.expireDate = propExpireDate.value;
saveModel.releaseDate = propReleaseDate.value;
saveModel.templateAlias = propTemplate.value;
return saveModel;
}
};