diff --git a/src/Umbraco.Web.UI/umbraco/js/umbraco.directives.js b/src/Umbraco.Web.UI/umbraco/js/umbraco.directives.js index 03da48327b..43203f401a 100644 --- a/src/Umbraco.Web.UI/umbraco/js/umbraco.directives.js +++ b/src/Umbraco.Web.UI/umbraco/js/umbraco.directives.js @@ -489,7 +489,7 @@ angular.module('umbraco.directives', []) if (!iAttrs.tabs) throw "a 'tabs' attribute must be set for umbHeader which represents the collection of tabs"; - var hasProcessed = false; + //var hasProcessed = false; //when the tabs change, we need to hack the planet a bit and force the first tab content to be active, //unfortunately twitter bootstrap tabs is not playing perfectly with angular. @@ -497,10 +497,11 @@ angular.module('umbraco.directives', []) //don't process if we cannot or have already done so if (!newValue) return; - if (hasProcessed || !newValue.length || newValue.length == 0) return; + //if (hasProcessed || !newValue.length || newValue.length == 0) return; + if (!newValue.length || newValue.length == 0) return; //set the flag - hasProcessed = true; + //hasProcessed = true; var $panes = $('div.tab-content'); var activeTab = _.find(newValue, function (item) { diff --git a/src/Umbraco.Web.UI/umbraco/js/umbraco.resources.js b/src/Umbraco.Web.UI/umbraco/js/umbraco.resources.js index 5a9b31e021..ecd180700f 100644 --- a/src/Umbraco.Web.UI/umbraco/js/umbraco.resources.js +++ b/src/Umbraco.Web.UI/umbraco/js/umbraco.resources.js @@ -141,6 +141,43 @@ define(['app', 'angular'], function (app, angular) { function getSaveUrl() { return Umbraco.Sys.ServerVariables.contentEditorApiBaseUrl + "PostSaveContent"; } + /** internal method process the saving of data and post processing the result */ + function saveContentItem(content, action) { + 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) { + //TODO: transform the request callback and add the files associated with the request + }, + 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 { getContent: function (id) { @@ -277,56 +314,12 @@ define(['app', 'angular'], function (app, angular) { /** saves or updates a content object */ saveContent: function (content) { - - var deferred = $q.defer(); - - //save the data - umbRequestHelper.postMultiPartRequest( - getSaveUrl(content.id), - umbDataFormatter.formatContentPostData(content, "save"), - function (data) { - //TODO: transform the request callback and add the files associated with the request - }, - function (data, status, headers, config) { - //success callback - - //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 saveContentItem(content, "save"); }, /** saves and publishes a content object */ publishContent: function (content) { - - var deferred = $q.defer(); - - //save the data - umbRequestHelper.postMultiPartRequest( - getSaveUrl(content.id), - { key: "contentItem", value: umbDataFormatter.formatContentPostData(content, "publish") }, - function (data) { - //TODO: transform the request callback and add the files associated with the request - }, - function (data, status, headers, config) { - //success callback - - //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 saveContentItem(content, "publish"); } }; diff --git a/src/Umbraco.Web/HttpCookieExtensions.cs b/src/Umbraco.Web/HttpCookieExtensions.cs new file mode 100644 index 0000000000..4e49610ca6 --- /dev/null +++ b/src/Umbraco.Web/HttpCookieExtensions.cs @@ -0,0 +1,50 @@ +using System.Web; +using Umbraco.Core; + +namespace Umbraco.Web +{ + /// + /// Extension methods used to check/set cookie values + /// + /// + /// This should 100% supercede the StateManager.Cookies + /// + internal static class HttpCookieExtensions + { + internal const string PreviewCookieName = "UMB_PREVIEW"; + + /// + /// Does a preview cookie exist ? + /// + /// + /// + public static bool HasPreviewCookie(this HttpRequestBase request) + { + return request.Cookies[PreviewCookieName] != null; + } + + /// + /// Does a cookie exist with the specified key ? + /// + /// + /// + /// + public static bool HasCookie(this HttpRequestBase request, string key) + { + return request.Cookies[key] != null; + } + + /// + /// Is there a cookie with the key supplied and does it have a value that is not empty + /// + /// + /// + /// + public static bool HasCookieValue(this HttpRequestBase request, string key) + { + return request.Cookies[key] != null + && request.Cookies[key].Value != null + && request.Cookies[key].Value.IsNullOrWhiteSpace() == false; + } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/HttpRequestExtensions.cs b/src/Umbraco.Web/HttpRequestExtensions.cs index 12deeb5d5c..3743fd5705 100644 --- a/src/Umbraco.Web/HttpRequestExtensions.cs +++ b/src/Umbraco.Web/HttpRequestExtensions.cs @@ -7,51 +7,6 @@ using Umbraco.Core; namespace Umbraco.Web { /// - /// Extension methods used to check/set cookie values - /// - /// - /// This should 100% supercede the StateManager.Cookies - /// - internal static class HttpCookieExtensions - { - internal const string PreviewCookieName = "UMB_PREVIEW"; - - /// - /// Does a preview cookie exist ? - /// - /// - /// - public static bool HasPreviewCookie(this HttpRequestBase request) - { - return request.Cookies[PreviewCookieName] != null; - } - - /// - /// Does a cookie exist with the specified key ? - /// - /// - /// - /// - public static bool HasCookie(this HttpRequestBase request, string key) - { - return request.Cookies[key] != null; - } - - /// - /// Is there a cookie with the key supplied and does it have a value that is not empty - /// - /// - /// - /// - public static bool HasCookieValue(this HttpRequestBase request, string key) - { - return request.Cookies[key] != null - && request.Cookies[key].Value != null - && request.Cookies[key].Value.IsNullOrWhiteSpace() == false; - } - } - - /// /// Extension methods for the HttpRequest and HttpRequestBase objects /// public static class HttpRequestExtensions diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index bd449126b8..1c371d025c 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -293,6 +293,7 @@ +