utill.service.js update to support icons

This commit is contained in:
Per Ploug
2013-06-11 18:06:52 +02:00
parent 30ebf71c15
commit 0ace3a1f74
2 changed files with 73 additions and 71 deletions

6
.gitignore vendored
View File

@@ -71,9 +71,9 @@ src/Umbraco.Web.UI/umbraco/js/umbraco.*
src/Umbraco.Web.UI/umbraco/js/routes.js
src/Umbraco.Web.UI/umbraco/js/main.js
src/Umbraco.Web.UI/umbraco/js/app.js
src/Umbraco.Web.UI/umbraco/Views/**/*.js
src/Umbraco.Web.UI/umbraco/Views/**/*.css
src/Umbraco.Web.UI/umbraco/Views/**/*.html
src/Umbraco.Web.UI/umbraco/[V]iews/**/*.js
src/Umbraco.Web.UI/umbraco/[V]iews/**/*.css
src/Umbraco.Web.UI/umbraco/[V]iews/**/*.html
src/Umbraco.Web.UI/umbraco/assets/*
src/Umbraco.Web.UI.Client/build/*
src/Umbraco.Web.UI.Client/build/*

View File

@@ -5,34 +5,34 @@
* @name umbraco.services:umbImageHelper
* @description A helper object used for parsing image paths
**/
function umbImageHelper() {
function umbImageHelper() {
return {
/** formats the display model used to display the content to the model used to save the content */
getThumbnail: function (options) {
if (!options && !options.imageModel && !options.scope) {
throw "The options objet does not contain the required parameters: imageModel, scope";
if (!options && !options.imageModel && !options.scope) {
throw "The options objet does not contain the required parameters: imageModel, scope";
}
if (options.imageModel.contentTypeAlias.toLowerCase() == "image") {
var imageProp = _.find(options.imageModel.properties, function (item) {
return item.alias == 'umbracoFile';
});
var imageVal = options.scope.$eval(imageProp.value);
if (imageVal.length && imageVal.length >0 && imageVal[0].isImage) {
return this.getThumbnailFromPath(imageVal[0].file);
}
}
return "";
},
getThumbnailFromPath: function(imagePath) {
var ext = imagePath.substr(imagePath.lastIndexOf('.'));
return imagePath.substr(0, imagePath.lastIndexOf('.')) + "_thumb" + ext;
}
};
if (options.imageModel.contentTypeAlias.toLowerCase() === "image") {
var imageProp = _.find(options.imageModel.properties, function (item) {
return item.alias === 'umbracoFile';
});
var imageVal = options.scope.$eval(imageProp.value);
if (imageVal.length && imageVal.length >0 && imageVal[0].isImage) {
return this.getThumbnailFromPath(imageVal[0].file);
}
}
return "";
},
getThumbnailFromPath: function(imagePath) {
var ext = imagePath.substr(imagePath.lastIndexOf('.'));
return imagePath.substr(0, imagePath.lastIndexOf('.')) + "_thumb" + ext;
}
};
}
angular.module('umbraco.services').factory('umbImageHelper', umbImageHelper);
angular.module('umbraco.services').factory('umbImageHelper', umbImageHelper);
/**
* @ngdoc factory
* @name umbraco.services:umbRequestHelper
@@ -41,47 +41,47 @@ angular.module('umbraco.services').factory('umbImageHelper', umbImageHelper);
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;
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 */
@@ -227,12 +227,14 @@ angular.module('umbraco.services').factory('umbFormHelper', umbFormHelper);
function treeIconHelper() {
var converter = [
{ oldIcon: ".sprTreeFolder", newIcon: "icon-folder-close" },
{ oldIcon: ".sprTreeFolder_o", newIcon: "icon-folder-open" },
{ oldIcon: ".sprTreeMediaFile", newIcon: "icon-music" },
{ oldIcon: ".sprTreeMediaMovie", newIcon: "icon-movie" },
{ oldIcon: ".sprTreeMediaPhoto", newIcon: "icon-picture" }
];
{ oldIcon: ".sprTreeSettingDomain", newIcon: "icon-home" },
{ oldIcon: ".sprTreeDoc", newIcon: "icon-file-alt" },
{ oldIcon: ".sprTreeFolder", newIcon: "icon-folder-close" },
{ oldIcon: ".sprTreeFolder_o", newIcon: "icon-folder-open" },
{ oldIcon: ".sprTreeMediaFile", newIcon: "icon-music" },
{ oldIcon: ".sprTreeMediaMovie", newIcon: "icon-movie" },
{ oldIcon: ".sprTreeMediaPhoto", newIcon: "icon-picture" }
];
return {
/** If the tree node has a legacy icon */