Got media saving now.

Signed-off-by: Shannon <sdeminick@gmail.com>
This commit is contained in:
Shannon
2013-06-11 01:56:30 +02:00
committed by Shannon
parent 4bf09089e6
commit 3fee64d6eb
15 changed files with 348 additions and 313 deletions

View File

@@ -27,46 +27,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
}
/** internal method process the saving of data and post processing the result */
function saveContentItem(content, action, files) {
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) {
return item.active;
});
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(content.tabs, activeTab));
//save the data
umbRequestHelper.postMultiPartRequest(
getSaveUrl(content.id),
{ key: "contentItem", value: umbDataFormatter.formatContentPostData(content, action) },
function (data, formData) {
//now add all of the assigned files
for (var f in 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);
}
},
function (data, status, headers, config) {
//success callback
//reset the tabs and set the active one
_.each(data.tabs, function (item) {
item.active = false;
});
data.tabs[activeTabIndex].active = true;
//the data returned is the up-to-date data so the UI will refresh
deferred.resolve(data);
},
function (data, status, headers, config) {
//failure callback
deferred.reject('Failed to publish data for content id ' + content.id);
});
return deferred.promise;
return umbRequestHelper.postSaveContent(getSaveUrl(content.id), content, action, files);
}
return {
@@ -238,7 +199,7 @@ angular.module('umbraco.resources').factory('contentTypeResource', contentTypeRe
* @name umbraco.resources.treeResource
* @description Loads in data for trees
**/
function mediaResource($q, $http) {
function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
/** internal method to get the api url */
function getMediaUrl(contentId) {
@@ -261,46 +222,7 @@ function mediaResource($q, $http) {
/** internal method process the saving of data and post processing the result */
function saveMediaItem(content, action, files) {
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) {
return item.active;
});
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(content.tabs, activeTab));
//save the data
umbRequestHelper.postMultiPartRequest(
getSaveUrl(content.id),
{ key: "mediaItem", value: umbDataFormatter.formatContentPostData(content, action) },
function (data, formData) {
//now add all of the assigned files
for (var f in 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);
}
},
function (data, status, headers, config) {
//success callback
//reset the tabs and set the active one
_.each(data.tabs, function (item) {
item.active = false;
});
data.tabs[activeTabIndex].active = true;
//the data returned is the up-to-date data so the UI will refresh
deferred.resolve(data);
},
function (data, status, headers, config) {
//failure callback
deferred.reject('Failed to save data for media id ' + content.id);
});
return deferred.promise;
return umbRequestHelper.postSaveContent(getSaveUrl(content.id), content, action, files);
}
return {

View File

@@ -590,8 +590,52 @@ angular.module('umbraco.services')
* @name umbraco.services:umbRequestHelper
* @description A helper object used for sending requests to the server
**/
function umbRequestHelper($http) {
function umbRequestHelper($http, $q, umbDataFormatter) {
return {
postSaveContent: function (restApiUrl, content, action, files) {
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) {
return item.active;
});
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(content.tabs, activeTab));
//save the data
this.postMultiPartRequest(
restApiUrl,
{ key: "contentItem", value: umbDataFormatter.formatContentPostData(content, action) },
function (data, formData) {
//now add all of the assigned files
for (var f in 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);
}
},
function (data, status, headers, config) {
//success callback
//reset the tabs and set the active one
_.each(data.tabs, function (item) {
item.active = false;
});
data.tabs[activeTabIndex].active = true;
//the data returned is the up-to-date data so the UI will refresh
deferred.resolve(data);
},
function (data, status, headers, config) {
//failure callback
deferred.reject('Failed to save data for media id ' + content.id);
});
return deferred.promise;
},
/** Posts a multi-part mime request to the server */
postMultiPartRequest: function (url, jsonData, transformCallback, successCallback, failureCallback) {

View File

@@ -19,46 +19,7 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
}
/** internal method process the saving of data and post processing the result */
function saveContentItem(content, action, files) {
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) {
return item.active;
});
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(content.tabs, activeTab));
//save the data
umbRequestHelper.postMultiPartRequest(
getSaveUrl(content.id),
{ key: "contentItem", value: umbDataFormatter.formatContentPostData(content, action) },
function (data, formData) {
//now add all of the assigned files
for (var f in 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);
}
},
function (data, status, headers, config) {
//success callback
//reset the tabs and set the active one
_.each(data.tabs, function (item) {
item.active = false;
});
data.tabs[activeTabIndex].active = true;
//the data returned is the up-to-date data so the UI will refresh
deferred.resolve(data);
},
function (data, status, headers, config) {
//failure callback
deferred.reject('Failed to publish data for content id ' + content.id);
});
return deferred.promise;
return umbRequestHelper.postSaveContent(getSaveUrl(content.id), content, action, files);
}
return {

View File

@@ -3,7 +3,7 @@
* @name umbraco.resources.treeResource
* @description Loads in data for trees
**/
function mediaResource($q, $http) {
function mediaResource($q, $http, umbDataFormatter, umbRequestHelper) {
/** internal method to get the api url */
function getMediaUrl(contentId) {
@@ -26,46 +26,7 @@ function mediaResource($q, $http) {
/** internal method process the saving of data and post processing the result */
function saveMediaItem(content, action, files) {
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) {
return item.active;
});
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(content.tabs, activeTab));
//save the data
umbRequestHelper.postMultiPartRequest(
getSaveUrl(content.id),
{ key: "mediaItem", value: umbDataFormatter.formatContentPostData(content, action) },
function (data, formData) {
//now add all of the assigned files
for (var f in 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);
}
},
function (data, status, headers, config) {
//success callback
//reset the tabs and set the active one
_.each(data.tabs, function (item) {
item.active = false;
});
data.tabs[activeTabIndex].active = true;
//the data returned is the up-to-date data so the UI will refresh
deferred.resolve(data);
},
function (data, status, headers, config) {
//failure callback
deferred.reject('Failed to save data for media id ' + content.id);
});
return deferred.promise;
return umbRequestHelper.postSaveContent(getSaveUrl(content.id), content, action, files);
}
return {

View File

@@ -5,8 +5,52 @@
* @name umbraco.services:umbRequestHelper
* @description A helper object used for sending requests to the server
**/
function umbRequestHelper($http) {
function umbRequestHelper($http, $q, umbDataFormatter) {
return {
postSaveContent: function (restApiUrl, content, action, files) {
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) {
return item.active;
});
var activeTabIndex = (activeTab === undefined ? 0 : _.indexOf(content.tabs, activeTab));
//save the data
this.postMultiPartRequest(
restApiUrl,
{ key: "contentItem", value: umbDataFormatter.formatContentPostData(content, action) },
function (data, formData) {
//now add all of the assigned files
for (var f in 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);
}
},
function (data, status, headers, config) {
//success callback
//reset the tabs and set the active one
_.each(data.tabs, function (item) {
item.active = false;
});
data.tabs[activeTabIndex].active = true;
//the data returned is the up-to-date data so the UI will refresh
deferred.resolve(data);
},
function (data, status, headers, config) {
//failure callback
deferred.reject('Failed to save data for media id ' + content.id);
});
return deferred.promise;
},
/** Posts a multi-part mime request to the server */
postMultiPartRequest: function (url, jsonData, transformCallback, successCallback, failureCallback) {

View File

@@ -30,13 +30,20 @@ angular.module("umbraco")
$scope.saveAndPublish = function (cnt) {
cnt.publishDate = new Date();
contentResource.publishContent(cnt, $routeParams.create, $scope.files);
notificationsService.success("Published", "Content has been saved and published");
contentResource.publishContent(cnt, $routeParams.create, $scope.files)
.then(function(data) {
$scope.content = data;
notificationsService.success("Published", "Content has been saved and published");
});
};
$scope.save = function (cnt) {
cnt.updateDate = new Date();
contentResource.saveContent(cnt, $routeParams.create, $scope.files);
notificationsService.success("Saved", "Content has been saved");
contentResource.saveContent(cnt, $routeParams.create, $scope.files)
.then(function (data) {
$scope.content = data;
notificationsService.success("Saved", "Content has been saved");
});
};
});

View File

@@ -28,8 +28,11 @@ function mediaEditController($scope, $routeParams, mediaResource, notificationsS
$scope.save = function (cnt) {
cnt.updateDate = new Date();
mediaResource.saveMedia(cnt, $routeParams.create, $scope.files);
notificationsService.success("Saved", "Media has been saved");
mediaResource.saveMedia(cnt, $routeParams.create, $scope.files)
.then(function (data) {
$scope.content = data;
notificationsService.success("Saved", "Media has been saved");
});
};
}