Skip to content

Commit

Permalink
Switch default to Theme.LIGHT
Browse files Browse the repository at this point in the history
- Add remembering last switched theme to cookies (reference #52 )
  • Loading branch information
piotrzarzycki21 committed Apr 19, 2024
1 parent db5e0c0 commit 7ac31cb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package controller.startup.prepareView
{
override public function execute(note: INotification):void
{
sendNotification(ApplicationConstants.COMMAND_SWITCH_THEME, Theme.DARK);
sendNotification(ApplicationConstants.COMMAND_SWITCH_THEME);

var app:IApplication = note.getBody() as IApplication;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,32 @@ package controller.startup.prepareView
{
override public function execute(note:INotification):void
{
var theme:String = String(note.getBody());
var themeProxy:ProxyTheme = facade.retrieveProxy(ProxyTheme.NAME) as ProxyTheme;
var themeId:* = document.getElementById(themeProxy.themeId);
var themeProxy:ProxyTheme = facade.retrieveProxy(ProxyTheme.NAME) as ProxyTheme;
var currentTheme:Object = themeProxy.getTheme();

var themeId:* = document.getElementById(currentTheme.themeId);
if (themeId)
{
document.head.removeChild(themeId);
}

var theme:Object = note.getBody();
if (!theme)
{
theme = currentTheme.theme;
}

switch (theme)
{
case Theme.DARK:
themeProxy.themeId = loadCSS("resources/themes/" + Theme.DARK + "/defaults.css");
themeProxy.theme = Theme.DARK;
themeId = loadCSS("resources/themes/" + Theme.DARK + "/defaults.css");
window["DevExpress"].ui.themes.current("generic." + Theme.DARK);
themeProxy.setTheme(Theme.DARK, themeId);
break;
default:
themeProxy.themeId = loadCSS("resources/themes/" + Theme.LIGHT + "/defaults.css");
themeProxy.theme = Theme.LIGHT;
themeId = loadCSS("resources/themes/" + Theme.LIGHT + "/defaults.css");
window["DevExpress"].ui.themes.current("generic." + Theme.LIGHT);
themeProxy.setTheme(Theme.LIGHT, themeId);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ package mediator
private function onSwitchTheme(event:MouseEvent):void
{
var themeProxy:ProxyTheme = facade.retrieveProxy(ProxyTheme.NAME) as ProxyTheme;
var theme:String = themeProxy.theme;
sendNotification(ApplicationConstants.COMMAND_SWITCH_THEME, theme == Theme.DARK ? Theme.LIGHT : Theme.DARK);
var currentTheme:Object = themeProxy.getTheme();
sendNotification(ApplicationConstants.COMMAND_SWITCH_THEME, currentTheme.theme == Theme.DARK ? Theme.LIGHT : Theme.DARK);
}

private function onNavigationSectionChange(event:Event):void
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model.proxy
{
import org.puremvc.as3.multicore.patterns.proxy.Proxy;
import constants.Theme;

public class ProxyTheme extends Proxy
{
Expand All @@ -9,33 +10,38 @@ package model.proxy
public function ProxyTheme()
{
super(NAME);

this.setData({theme: Theme.LIGHT});
}

private var _themeId:String;

public function get themeId():String
public function getTheme():Object
{
return _themeId;
}

public function set themeId(value:String):void
{
if (_themeId != value)
var currentTheme:String = window["Cookies"].get("MyAccountTheme");
var currentThemeId:String = window["Cookies"].get("MyAccountThemeId");

for (var t:String in Theme)
{
_themeId = value;
if (Theme[t] == currentTheme)
{
return {theme: currentTheme, themeId: currentThemeId};
}
}

return this.getData();
}

public function get theme():String
{
return String(this.getData());
}

public function set theme(value:String):void

public function setTheme(theme:String, themeId:String):void
{
if (String(this.getData()) != value)
for (var t:String in Theme)
{
this.setData(value);
if (Theme[t] == theme)
{
window["Cookies"].set("MyAccountTheme", theme);
window["Cookies"].set("MyAccountThemeId", themeId);

this.setData({theme: theme, themeId: themeId});
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<link rel="dx-theme" data-theme="generic.dark" data-active="true" href="https://cdn3.devexpress.com/jslib/23.1.3/css/dx.dark.css">

<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.5/js.cookie.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/devextreme-quill/1.6.2/dx-quill.min.js"></script>
<script type="text/javascript" src="https://cdn3.devexpress.com/jslib/23.1.3/js/dx.all.js"></script>

Expand Down

0 comments on commit 7ac31cb

Please sign in to comment.