From 05d369fb2cdb58b1d7ad4573b3c9ce1f7ee22ad0 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Tue, 20 Jul 2010 23:34:09 -0700 Subject: [PATCH] Remembering the view type of the features list and added some rough and simple client app settings functionality --HG-- branch : dev --- .../Orchard.Modules/Orchard.Modules.csproj | 6 - .../Orchard.Modules/Views/Admin/Features.ascx | 7 +- .../Orchard.Themes/Orchard.Themes.csproj | 7 + .../Modules/Orchard.Themes/Scripts/base.js | 150 +++++++++++++++++- .../Scripts}/jquery.switchable.js | 14 +- .../Styles/Images}/detail-view-on.gif | Bin .../Styles/Images}/detail-view.gif | Bin .../Styles/Images}/summary-view-on.gif | Bin .../Styles/Images}/summary-view.gif | Bin .../Styles}/jquery.switchable.css | 0 .../Orchard.Themes/Views/UI/Switchable.ascx | 8 + src/Orchard/UI/Resources/ResourceManager.cs | 6 +- 12 files changed, 177 insertions(+), 21 deletions(-) rename src/Orchard.Web/Modules/{Orchard.Modules/scripts => Orchard.Themes/Scripts}/jquery.switchable.js (52%) rename src/Orchard.Web/Modules/{Orchard.Modules/styles/images => Orchard.Themes/Styles/Images}/detail-view-on.gif (100%) rename src/Orchard.Web/Modules/{Orchard.Modules/styles/images => Orchard.Themes/Styles/Images}/detail-view.gif (100%) rename src/Orchard.Web/Modules/{Orchard.Modules/styles/images => Orchard.Themes/Styles/Images}/summary-view-on.gif (100%) rename src/Orchard.Web/Modules/{Orchard.Modules/styles/images => Orchard.Themes/Styles/Images}/summary-view.gif (100%) rename src/Orchard.Web/Modules/{Orchard.Modules/styles => Orchard.Themes/Styles}/jquery.switchable.css (100%) create mode 100644 src/Orchard.Web/Modules/Orchard.Themes/Views/UI/Switchable.ascx diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Orchard.Modules.csproj b/src/Orchard.Web/Modules/Orchard.Modules/Orchard.Modules.csproj index fa5c5a7bf..e0824a43b 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/Orchard.Modules.csproj +++ b/src/Orchard.Web/Modules/Orchard.Modules/Orchard.Modules.csproj @@ -81,12 +81,6 @@ - - - - - - diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.ascx b/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.ascx index 0868b17b0..902f80906 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.ascx +++ b/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Features.ascx @@ -1,15 +1,12 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> <%@ Import Namespace="Orchard.Localization" %> <%@ Import Namespace="Orchard.Modules.Extensions" %> -<%@ Import Namespace="Orchard.Mvc.Html"%> <%@ Import Namespace="Orchard.Modules.ViewModels"%> <%@ Import Namespace="Orchard.Utility.Extensions" %><% - Html.RegisterStyle("admin.css"); - Html.RegisterStyle("jquery.switchable.css"); - Html.RegisterFootScript("jquery.switchable.js"); %> + Html.RegisterStyle("admin.css"); %>

<%: Html.TitleForPage(T("Manage Features").ToString()) %>

<% if (Model.Features.Count() > 0) { %> -
    <% +
      "><% var featureGroups = Model.Features.OrderBy(f => f.Descriptor.Category).GroupBy(f => f.Descriptor.Category); foreach (var featureGroup in featureGroups) { var categoryName = LocalizedString.TextOrDefault(featureGroup.First().Descriptor.Category, T("Uncategorized")); diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj index dea0eb979..36b88375e 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj +++ b/src/Orchard.Web/Modules/Orchard.Themes/Orchard.Themes.csproj @@ -89,10 +89,16 @@ + + + + + + @@ -106,6 +112,7 @@ + diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js b/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js index 665c1fbc9..5c6b184e4 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js +++ b/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js @@ -1,5 +1,47 @@ (function ($) { - //todo: (heskew) make use of the autofocus attribute instead + // Some simple settings storage/retrieval + $.extend({ + orchard: { + __cookieName: "Orchrd", // Orchard, on a diet + __cookieExpiration: 180, // roughly 6 months + cookie: function (scope, value, options) { // a light-weight wrapper around $.cookie for an Orchard.* cookie name + return $.cookie($.orchard.__cookieName + (scope ? "-" + scope.toLowerCase() : ""), value, options); + }, + setting: function (name, value, options) { // cookie-stored settings (only, at the moment) + if (value && value.path) { + options = value; + value = undefined; + } + var scope = (options && options.path && options.path.replace(/\W+/g, "-")) || ""; // this could become a problem with long paths as it's appended to the cookie name + var cookie = $.orchard.cookie(scope); + var key = (name + ((options && !!options.key && options.key) || "")).replace(/\W+/g, "-"); + if (typeof value === "undefined") { // try to get the setting value from the default "root" cookie + if (cookie) { + var data = $.parseJSON(cookie); + return data && data[key]; + } + return undefined; + } + else { // store the setting value - the setting isn't removable by the way, setting to "" might be enough for most cases + var data = (cookie && $.parseJSON(cookie)) || {}; + data[key] = value; + var dataString = (function (obj) { //todo: pull out into a seperate function + if (!obj) { return ""; } + var k, str = "{"; + for (k in obj) { // only really simple stringification + str = str + "\"" + k + "\":\"" + obj[k] + "\","; + } + if (str.length > 1) { + str = str.substring(0, str.length - 1); + } + return str + "}"; + })(data); + $.orchard.cookie(scope, dataString, { expires: $.orchard.__cookieExpiration, path: (options && options.path) || "/" }); // todo: default path should be app path + } + } + } + }); + // Some input (auto)focus and input-controlled toggle $.fn.extend({ helpfullyFocus: function () { var _this = $(this); @@ -13,7 +55,7 @@ return; } // otherwise, make the autofocus attribute work - var autofocus = _this.find(":input[autofocus=autofocus]").first(); + var autofocus = _this.find(":input[autofocus]").first(); return autofocus.focus(); }, toggleWhatYouControl: function () { @@ -62,7 +104,7 @@ $("body").append(_this); }); })(); - // a little better autofocus + // (do) a little better autofocus $(function () { $("body").helpfullyFocus(); }); @@ -89,4 +131,104 @@ _this.click(function () { form.submit(); return false; }); }); }); -})(jQuery); \ No newline at end of file +})(jQuery); + +/////////////////////////////////////////////////////////////// +// --- some plugins leaned on by core script components // +/////////////////////////////////////////////////////////////// +/** + * Cookie plugin + * + * Copyright (c) 2006 Klaus Hartl (stilbuero.de) + * Dual licensed under the MIT and GPL licenses: + * http://www.opensource.org/licenses/mit-license.php + * http://www.gnu.org/licenses/gpl.html + * + */ + +/** + * Create a cookie with the given name and value and other optional parameters. + * + * @example $.cookie('the_cookie', 'the_value'); + * @desc Set the value of a cookie. + * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true }); + * @desc Create a cookie with all available options. + * @example $.cookie('the_cookie', 'the_value'); + * @desc Create a session cookie. + * @example $.cookie('the_cookie', null); + * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain + * used when the cookie was set. + * + * @param String name The name of the cookie. + * @param String value The value of the cookie. + * @param Object options An object literal containing key/value pairs to provide optional cookie attributes. + * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object. + * If a negative value is specified (e.g. a date in the past), the cookie will be deleted. + * If set to null or omitted, the cookie will be a session cookie and will not be retained + * when the the browser exits. + * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie). + * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie). + * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will + * require a secure protocol (like HTTPS). + * @type undefined + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ + +/** + * Get the value of a cookie with the given name. + * + * @example $.cookie('the_cookie'); + * @desc Get the value of a cookie. + * + * @param String name The name of the cookie. + * @return The value of the cookie. + * @type String + * + * @name $.cookie + * @cat Plugins/Cookie + * @author Klaus Hartl/klaus.hartl@stilbuero.de + */ +jQuery.cookie = function(name, value, options) { + if (typeof value != 'undefined') { // name and value given, set cookie + options = options || {}; + if (value === null) { + value = ''; + options.expires = -1; + } + var expires = ''; + if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) { + var date; + if (typeof options.expires == 'number') { + date = new Date(); + date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000)); + } else { + date = options.expires; + } + expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE + } + // CAUTION: Needed to parenthesize options.path and options.domain + // in the following expressions, otherwise they evaluate to undefined + // in the packed version for some reason... + var path = options.path ? '; path=' + (options.path) : ''; + var domain = options.domain ? '; domain=' + (options.domain) : ''; + var secure = options.secure ? '; secure' : ''; + document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); + } else { // only name given, get cookie + var cookieValue = null; + if (document.cookie && document.cookie != '') { + var cookies = document.cookie.split(';'); + for (var i = 0; i < cookies.length; i++) { + var cookie = jQuery.trim(cookies[i]); + // Does this cookie string begin with the name we want? + if (cookie.substring(0, name.length + 1) == (name + '=')) { + cookieValue = decodeURIComponent(cookie.substring(name.length + 1)); + break; + } + } + } + return cookieValue; + } +}; \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Modules/scripts/jquery.switchable.js b/src/Orchard.Web/Modules/Orchard.Themes/Scripts/jquery.switchable.js similarity index 52% rename from src/Orchard.Web/Modules/Orchard.Modules/scripts/jquery.switchable.js rename to src/Orchard.Web/Modules/Orchard.Themes/Scripts/jquery.switchable.js index cd7bb0209..5cca7a883 100644 --- a/src/Orchard.Web/Modules/Orchard.Modules/scripts/jquery.switchable.js +++ b/src/Orchard.Web/Modules/Orchard.Themes/Scripts/jquery.switchable.js @@ -4,18 +4,26 @@ var _this = $(this); var theSwitch = $("
      •  
      "); - theSwitch.find(".summary-view").click(function () { $(this).switchToSummaryView(_this); }); - theSwitch.find(".detail-view").click(function () { $(this).switchToDetailView(_this); }); + var summarySwitch = theSwitch.find(".summary-view").click(function () { $(this).switchToSummaryView(_this); }); + var detailSwitch = theSwitch.find(".detail-view").click(function () { $(this).switchToDetailView(_this); }); - theSwitch.addClass(_this.hasClass("summary-view") ? "summary-switched" : "detail-switched"); + var setting = $.orchard.setting("switchable", { path: document.location.pathname }) + || (_this.hasClass("summary-view") ? "summary-view" : "detail-view"); + if (setting === "summary-view") { + summarySwitch.switchToSummaryView(_this); + } else { + detailSwitch.switchToDetailView(_this); + } theSwitch.insertBefore(_this); }, switchToDetailView: function (switched) { + $.orchard.setting("switchable", "detail-view", { path: document.location.pathname }); $(this).closest(".switch-for-switchable").addClass("detail-switched").removeClass("summary-switched"); switched.addClass("detail-view").removeClass("summary-view"); }, switchToSummaryView: function (switched) { + $.orchard.setting("switchable", "summary-view", { path: document.location.pathname }); $(this).closest(".switch-for-switchable").addClass("summary-switched").removeClass("detail-switched"); switched.addClass("summary-view").removeClass("detail-view"); } diff --git a/src/Orchard.Web/Modules/Orchard.Modules/styles/images/detail-view-on.gif b/src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/detail-view-on.gif similarity index 100% rename from src/Orchard.Web/Modules/Orchard.Modules/styles/images/detail-view-on.gif rename to src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/detail-view-on.gif diff --git a/src/Orchard.Web/Modules/Orchard.Modules/styles/images/detail-view.gif b/src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/detail-view.gif similarity index 100% rename from src/Orchard.Web/Modules/Orchard.Modules/styles/images/detail-view.gif rename to src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/detail-view.gif diff --git a/src/Orchard.Web/Modules/Orchard.Modules/styles/images/summary-view-on.gif b/src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/summary-view-on.gif similarity index 100% rename from src/Orchard.Web/Modules/Orchard.Modules/styles/images/summary-view-on.gif rename to src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/summary-view-on.gif diff --git a/src/Orchard.Web/Modules/Orchard.Modules/styles/images/summary-view.gif b/src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/summary-view.gif similarity index 100% rename from src/Orchard.Web/Modules/Orchard.Modules/styles/images/summary-view.gif rename to src/Orchard.Web/Modules/Orchard.Themes/Styles/Images/summary-view.gif diff --git a/src/Orchard.Web/Modules/Orchard.Modules/styles/jquery.switchable.css b/src/Orchard.Web/Modules/Orchard.Themes/Styles/jquery.switchable.css similarity index 100% rename from src/Orchard.Web/Modules/Orchard.Modules/styles/jquery.switchable.css rename to src/Orchard.Web/Modules/Orchard.Themes/Styles/jquery.switchable.css diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/UI/Switchable.ascx b/src/Orchard.Web/Modules/Orchard.Themes/Views/UI/Switchable.ascx new file mode 100644 index 000000000..39c0c902a --- /dev/null +++ b/src/Orchard.Web/Modules/Orchard.Themes/Views/UI/Switchable.ascx @@ -0,0 +1,8 @@ +<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> +<% + Html.RegisterStyle("jquery.switchable.css"); + Html.RegisterFootScript("jquery.switchable.js"); + var cssClass = string.Format("{0} switchable", Model); + + %> + <%:cssClass %> \ No newline at end of file diff --git a/src/Orchard/UI/Resources/ResourceManager.cs b/src/Orchard/UI/Resources/ResourceManager.cs index 657dc0a08..dfb0ec32e 100644 --- a/src/Orchard/UI/Resources/ResourceManager.cs +++ b/src/Orchard/UI/Resources/ResourceManager.cs @@ -43,7 +43,7 @@ namespace Orchard.UI.Resources { context.SetAttribute("rel", "stylesheet"); if (!_styles.Contains(context)) - _styles.Add(context); + _styles.Insert(0, context); return context; } @@ -60,7 +60,7 @@ namespace Orchard.UI.Resources { context.SetAttribute("type", "text/javascript"); if (!_headScripts.Contains(context)) - _headScripts.Add(context); + _headScripts.Insert(0, context); return context; } @@ -73,7 +73,7 @@ namespace Orchard.UI.Resources { context.SetAttribute("type", "text/javascript"); if (!_footScripts.Contains(context)) - _footScripts.Add(context); + _footScripts.Insert(0, context); return context; }