openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

commit 47074f7e15f7c3e91a913b0d2482a0ee6cb7a94c
parent d73ece9f1689b215a6f205a822bd1889deb888b7
Author: Jan Dankert <develop@jandankert.de>
Date:   Wed, 30 Oct 2019 21:48:12 +0100

New: Setting the theme-color at login/logout for mobile devices.

Diffstat:
modules/cms-ui/action/IndexAction.class.php | 17++++++++++++++++-
modules/cms-ui/themes/default/layout/index.php | 2+-
modules/cms-ui/themes/default/production/combined.min.js | 2+-
modules/cms-ui/themes/default/script/openrat/workbench.js | 21++++++++++++++++-----
modules/cms-ui/themes/default/script/openrat/workbench.min.js | 2+-
5 files changed, 35 insertions(+), 9 deletions(-)

diff --git a/modules/cms-ui/action/IndexAction.class.php b/modules/cms-ui/action/IndexAction.class.php @@ -84,7 +84,22 @@ class IndexAction extends Action $user = Session::getUser(); - $output = array( 'style' => $this->getUserStyle($user) ); + $output = array(); + + $currentStyle = $this->getUserStyle($user); + $output['style'] = $currentStyle; + + + $styleConfig = config('style-default'); // default style config + $userStyleConfig = config('style', $currentStyle); // user style config + + if (is_array($userStyleConfig)) + $styleConfig = array_merge($styleConfig, $userStyleConfig ); // Merging user style into default style + else + ; // Unknown style name, we are ignoring this. + + // Theme base color for smartphones colorizing their status bar. + $output['theme-color'] = $this->getColorHexCode($styleConfig['title_background_color']); $this->outputAsJSON( $output ); } diff --git a/modules/cms-ui/themes/default/layout/index.php b/modules/cms-ui/themes/default/layout/index.php @@ -20,7 +20,7 @@ <?php foreach( $cssFiles as $cssFile) { ?> <link rel="stylesheet" type="text/css" href="<?php echo $cssFile ?>" /> <?php } ?> <link rel="stylesheet" type="text/css" href="<?php echo Html::url('index','themestyle',0,array('embed'=>'1')) ?>" /> - <meta name="theme-color" content="<?php echo $themeColor ?>" /> + <meta id="theme-color" name="theme-color" content="<?php echo $themeColor ?>" /> <link rel="manifest" href="<?php echo Html::url('index','manifest',0,array('embed'=>'1')) ?>" /> <link rel="shortcut icon" type="image/x-icon" href="<?php echo $favicon_url ?>"> </head> diff --git a/modules/cms-ui/themes/default/production/combined.min.js b/modules/cms-ui/themes/default/production/combined.min.js @@ -10997,7 +10997,7 @@ else{};return e}}; else{let url='./api/';this.setLoadStatus(!0);url+='';e.output='json';if($(this.element).data('async')){this.close()};let form=this;$.ajax({'type':'POST',url:url,data:e,success:function(e,t,r){form.setLoadStatus(!1);$(status).remove();form.doResponse(e,t,form.element)},error:function(e,t,r){form.setLoadStatus(!1);$(status).remove();try{let error=jQuery.parseJSON(e.responseText);Openrat.Workbench.notify('','','error',error.error,[error.description])}catch(s){let msg=e.responseText;Openrat.Workbench.notify('','','error','Server Error',[msg])}}});$(form.element).fadeIn()}};this.doResponse=function(e,t,r){if(t!='success'){alert('Server error: '+t);return};let form=this;$.each(e['notices'],function(t,e){let notifyBrowser=$(r).data('async');Openrat.Workbench.notify(e.type,e.name,e.status,e.text,e.log,notifyBrowser);if(e.status=='ok'){if(!$(r).data('async')){form.close();$(r).closest('div.panel').find('div.header ul.views li.action.active').removeClass('dirty')};let afterSuccess=$(r).data('afterSuccess');let async=$(r).data('async');if(afterSuccess){if(afterSuccess=='reloadAll'){Openrat.Workbench.reloadAll()}} else{if(async);else Openrat.Workbench.reloadViews()};$(document).trigger('orDataChanged')} else{}});$.each(e['errors'],function(e,t){$('input[name='+t+']').addClass('error').parent().addClass('error').parents('fieldset').addClass('show').addClass('open')});if(e.control.redirect)window.location.href=e.control.redirect}}; -/* ./modules/cms-ui/themes/default/script/openrat/workbench.min.js */;Openrat.Workbench=new function(){'use strict';this.state={};this.initialize=function(){this.initializePingTimer();this.initializeState();this.initializeMenues();this.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};this.initializeMenues=function(){filterMenus()};this.initializeState=function(){let parts=window.location.hash.split('/');let state={action:'index',id:0};if(parts.length>=2)state.action=parts[1].toLowerCase();if(parts.length>=3)state.id=parts[2].replace(/[^0-9_]/gim,'');Openrat.Workbench.state=state;$('#editor').attr('data-action',state.action);$('#editor').attr('data-id',state.id);$('#editor').attr('data-extra','{}');Openrat.Navigator.toActualHistory(state)};this.initializePingTimer=function(){var t=function(){$.ajax(Openrat.View.createUrl('title','ping',0))},i=5;window.setInterval(t,i*60*1000)};this.loadNewActionState=function(t){Openrat.Workbench.state=t;Openrat.Workbench.loadNewAction(t.action,t.id,t.data);filterMenus();$(document).trigger('orNewAction')};this.loadNewAction=function(t,i,e){$('#editor').attr('data-action',t);$('#editor').attr('data-id',i);$('#editor').attr('data-extra',JSON.stringify(e));this.reloadViews()};this.reloadViews=function(){$('#workbench section.closed .view-loader').empty();Openrat.Workbench.loadViews($('#workbench section.open .view-loader'))};this.reloadAll=function(){$('#workbench .view').empty();Openrat.Workbench.loadViews($('#workbench .view.view-loader, #workbench .view.view-static'));this.loadUserStyle()};this.loadUserStyle=function(){let url=Openrat.View.createUrl('index','userinfo',0);$.getJSON(url,function(t){let style=t['style'];Openrat.Workbench.setUserStyle(style)})};this.loadViews=function(t){t.each(function(t){let $targetDOMElement=$(this);Openrat.Workbench.loadNewActionIntoElement($targetDOMElement)})};this.loadNewActionIntoElement=function(t){let action;if(t.is('.view-static'))action=t.attr('data-action');else action=$('#editor').attr('data-action');let id=$('#editor').attr('data-id');let params=$('#editor').attr('data-extra');let method=t.data('method');let view=new Openrat.View(action,method,id,params);view.start(t)};this.setUserStyle=function(t){var i=$('html'),e=i.attr('class').split(/\s+/);$.each(e,function(t,e){if(e.startsWith('theme-')){i.removeClass(e)}});i.addClass('theme-'+t.toLowerCase())};let notifyBrowser=function(t){if(!('Notification' in window)){return} +/* ./modules/cms-ui/themes/default/script/openrat/workbench.min.js */;Openrat.Workbench=new function(){'use strict';this.state={};this.initialize=function(){this.initializePingTimer();this.initializeState();this.initializeMenues();this.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};this.initializeMenues=function(){filterMenus()};this.initializeState=function(){let parts=window.location.hash.split('/');let state={action:'index',id:0};if(parts.length>=2)state.action=parts[1].toLowerCase();if(parts.length>=3)state.id=parts[2].replace(/[^0-9_]/gim,'');Openrat.Workbench.state=state;$('#editor').attr('data-action',state.action);$('#editor').attr('data-id',state.id);$('#editor').attr('data-extra','{}');Openrat.Navigator.toActualHistory(state)};this.initializePingTimer=function(){var t=function(){$.ajax(Openrat.View.createUrl('title','ping',0))},i=5;window.setInterval(t,i*60*1000)};this.loadNewActionState=function(t){Openrat.Workbench.state=t;Openrat.Workbench.loadNewAction(t.action,t.id,t.data);filterMenus();$(document).trigger('orNewAction')};this.loadNewAction=function(t,i,e){$('#editor').attr('data-action',t);$('#editor').attr('data-id',i);$('#editor').attr('data-extra',JSON.stringify(e));this.reloadViews()};this.reloadViews=function(){$('#workbench section.closed .view-loader').empty();Openrat.Workbench.loadViews($('#workbench section.open .view-loader'))};this.reloadAll=function(){$('#workbench .view').empty();Openrat.Workbench.loadViews($('#workbench .view.view-loader, #workbench .view.view-static'));this.loadUserStyle()};this.loadUserStyle=function(){let url=Openrat.View.createUrl('index','userinfo',0);$.getJSON(url,function(t){let style=t['style'];Openrat.Workbench.setUserStyle(style);let color=t['theme-color'];Openrat.Workbench.setThemeColor(color)})};this.loadViews=function(t){t.each(function(t){let $targetDOMElement=$(this);Openrat.Workbench.loadNewActionIntoElement($targetDOMElement)})};this.loadNewActionIntoElement=function(t){let action;if(t.is('.view-static'))action=t.attr('data-action');else action=$('#editor').attr('data-action');let id=$('#editor').attr('data-id');let params=$('#editor').attr('data-extra');let method=t.data('method');let view=new Openrat.View(action,method,id,params);view.start(t)};this.setUserStyle=function(t){var i=$('html'),e=i.attr('class').split(/\s+/);$.each(e,function(t,e){if(e.startsWith('theme-')){i.removeClass(e)}});i.addClass('theme-'+t.toLowerCase())};this.setThemeColor=function(t){$('#theme-color').attr('content',t)};let notifyBrowser=function(t){if(!('Notification' in window)){return} else if(Notification.permission==='granted'){let notification=new Notification(t)} else if(Notification.permission!=='denied'){Notification.requestPermission(function(i){if(i==='granted'){let notification=new Notification(t)}})}};this.notify=function(t,e,i,o,log=[],notifyTheBrowser=!1){if(notifyTheBrowser)notifyBrowser(o);let notice=$('<div class="notice '+i+'"></div>');let toolbar=$('<div class="or-notice-toolbar"></div>');if(log.length)$(toolbar).append('<i class="or-action-full image-icon image-icon--menu-fullscreen"></i>');$(toolbar).append('<i class="or-action-close image-icon image-icon--menu-close"></i>');$(notice).append(toolbar);let id=0;if(e)$(notice).append('<div class="name clickable"><a href="" data-type="open" data-action="'+t+'" data-id="'+id+'"><i class="or-action-full image-icon image-icon--action-'+t+'"></i> '+e+'</a></div>');$(notice).append('<div class="text">'+htmlEntities(o)+'</div>');if(log.length){let logLi=log.reduce((result,item)=>{result+='<li><pre>'+htmlEntities(item)+'</pre></li>';return result},'');$(notice).append('<div class="log"><ul>'+logLi+'</ul></div>')};$('#noticebar').prepend(notice);$(notice).orLinkify();$(notice).find('.or-action-full').click(function(){$(notice).toggleClass('full')});$(notice).find('.or-action-close').click(function(){$(notice).fadeOut('fast',function(){$(notice).remove()})});let timeout=1;if(i=='ok')timeout=20;if(i=='info')timeout=60;if(i=='warning')timeout=120;if(i=='error')timeout=120;if(timeout>0)setTimeout(function(){$(notice).fadeOut('slow',function(){$(this).remove()})},timeout*1000)}}; /* ./modules/cms-ui/themes/default/script/openrat/navigator.min.js */;Openrat.Navigator=new function(){'use strict';this.navigateTo=function(t){Openrat.Workbench.loadNewActionState(t)};this.navigateToNew=function(t){this.navigateTo(t);window.history.pushState(t,t.name,this.createShortUrl(t.action,t.id))};this.toActualHistory=function(t){window.history.replaceState(t,t.name,this.createShortUrl(t.action,t.id))};this.createShortUrl=function(t,i){return'./#/'+t+(i?'/'+i:'')}}; diff --git a/modules/cms-ui/themes/default/script/openrat/workbench.js b/modules/cms-ui/themes/default/script/openrat/workbench.js @@ -144,11 +144,13 @@ Openrat.Workbench = new function() let url = Openrat.View.createUrl('index','userinfo',0 ); // Die Inhalte des Zweiges laden. - $.getJSON(url, function (json) { + $.getJSON(url, function (themeData) { - // Den neuen Unter-Zweig erzeugen. - let style = json['style']; + let style = themeData['style']; Openrat.Workbench.setUserStyle(style); + + let color = themeData['theme-color']; + Openrat.Workbench.setThemeColor(color); }); } @@ -189,9 +191,8 @@ Openrat.Workbench = new function() /** - * Setzt einen neuen Theme. + * Sets a new theme. * @param styleName - * @returns */ this.setUserStyle = function( styleName ) { @@ -206,6 +207,16 @@ Openrat.Workbench = new function() } + /** + * Sets a new theme color. + * @param color Theme-color + */ + this.setThemeColor = function( color ) + { + $('#theme-color').attr('content',color); + } + + /** diff --git a/modules/cms-ui/themes/default/script/openrat/workbench.min.js b/modules/cms-ui/themes/default/script/openrat/workbench.min.js @@ -1,3 +1,3 @@ -;Openrat.Workbench=new function(){'use strict';this.state={};this.initialize=function(){this.initializePingTimer();this.initializeState();this.initializeMenues();this.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};this.initializeMenues=function(){filterMenus()};this.initializeState=function(){let parts=window.location.hash.split('/');let state={action:'index',id:0};if(parts.length>=2)state.action=parts[1].toLowerCase();if(parts.length>=3)state.id=parts[2].replace(/[^0-9_]/gim,'');Openrat.Workbench.state=state;$('#editor').attr('data-action',state.action);$('#editor').attr('data-id',state.id);$('#editor').attr('data-extra','{}');Openrat.Navigator.toActualHistory(state)};this.initializePingTimer=function(){var t=function(){$.ajax(Openrat.View.createUrl('title','ping',0))},i=5;window.setInterval(t,i*60*1000)};this.loadNewActionState=function(t){Openrat.Workbench.state=t;Openrat.Workbench.loadNewAction(t.action,t.id,t.data);filterMenus();$(document).trigger('orNewAction')};this.loadNewAction=function(t,i,e){$('#editor').attr('data-action',t);$('#editor').attr('data-id',i);$('#editor').attr('data-extra',JSON.stringify(e));this.reloadViews()};this.reloadViews=function(){$('#workbench section.closed .view-loader').empty();Openrat.Workbench.loadViews($('#workbench section.open .view-loader'))};this.reloadAll=function(){$('#workbench .view').empty();Openrat.Workbench.loadViews($('#workbench .view.view-loader, #workbench .view.view-static'));this.loadUserStyle()};this.loadUserStyle=function(){let url=Openrat.View.createUrl('index','userinfo',0);$.getJSON(url,function(t){let style=t['style'];Openrat.Workbench.setUserStyle(style)})};this.loadViews=function(t){t.each(function(t){let $targetDOMElement=$(this);Openrat.Workbench.loadNewActionIntoElement($targetDOMElement)})};this.loadNewActionIntoElement=function(t){let action;if(t.is('.view-static'))action=t.attr('data-action');else action=$('#editor').attr('data-action');let id=$('#editor').attr('data-id');let params=$('#editor').attr('data-extra');let method=t.data('method');let view=new Openrat.View(action,method,id,params);view.start(t)};this.setUserStyle=function(t){var i=$('html'),e=i.attr('class').split(/\s+/);$.each(e,function(t,e){if(e.startsWith('theme-')){i.removeClass(e)}});i.addClass('theme-'+t.toLowerCase())};let notifyBrowser=function(t){if(!('Notification' in window)){return} +;Openrat.Workbench=new function(){'use strict';this.state={};this.initialize=function(){this.initializePingTimer();this.initializeState();this.initializeMenues();this.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};this.initializeMenues=function(){filterMenus()};this.initializeState=function(){let parts=window.location.hash.split('/');let state={action:'index',id:0};if(parts.length>=2)state.action=parts[1].toLowerCase();if(parts.length>=3)state.id=parts[2].replace(/[^0-9_]/gim,'');Openrat.Workbench.state=state;$('#editor').attr('data-action',state.action);$('#editor').attr('data-id',state.id);$('#editor').attr('data-extra','{}');Openrat.Navigator.toActualHistory(state)};this.initializePingTimer=function(){var t=function(){$.ajax(Openrat.View.createUrl('title','ping',0))},i=5;window.setInterval(t,i*60*1000)};this.loadNewActionState=function(t){Openrat.Workbench.state=t;Openrat.Workbench.loadNewAction(t.action,t.id,t.data);filterMenus();$(document).trigger('orNewAction')};this.loadNewAction=function(t,i,e){$('#editor').attr('data-action',t);$('#editor').attr('data-id',i);$('#editor').attr('data-extra',JSON.stringify(e));this.reloadViews()};this.reloadViews=function(){$('#workbench section.closed .view-loader').empty();Openrat.Workbench.loadViews($('#workbench section.open .view-loader'))};this.reloadAll=function(){$('#workbench .view').empty();Openrat.Workbench.loadViews($('#workbench .view.view-loader, #workbench .view.view-static'));this.loadUserStyle()};this.loadUserStyle=function(){let url=Openrat.View.createUrl('index','userinfo',0);$.getJSON(url,function(t){let style=t['style'];Openrat.Workbench.setUserStyle(style);let color=t['theme-color'];Openrat.Workbench.setThemeColor(color)})};this.loadViews=function(t){t.each(function(t){let $targetDOMElement=$(this);Openrat.Workbench.loadNewActionIntoElement($targetDOMElement)})};this.loadNewActionIntoElement=function(t){let action;if(t.is('.view-static'))action=t.attr('data-action');else action=$('#editor').attr('data-action');let id=$('#editor').attr('data-id');let params=$('#editor').attr('data-extra');let method=t.data('method');let view=new Openrat.View(action,method,id,params);view.start(t)};this.setUserStyle=function(t){var i=$('html'),e=i.attr('class').split(/\s+/);$.each(e,function(t,e){if(e.startsWith('theme-')){i.removeClass(e)}});i.addClass('theme-'+t.toLowerCase())};this.setThemeColor=function(t){$('#theme-color').attr('content',t)};let notifyBrowser=function(t){if(!('Notification' in window)){return} else if(Notification.permission==='granted'){let notification=new Notification(t)} else if(Notification.permission!=='denied'){Notification.requestPermission(function(i){if(i==='granted'){let notification=new Notification(t)}})}};this.notify=function(t,e,i,o,log=[],notifyTheBrowser=!1){if(notifyTheBrowser)notifyBrowser(o);let notice=$('<div class="notice '+i+'"></div>');let toolbar=$('<div class="or-notice-toolbar"></div>');if(log.length)$(toolbar).append('<i class="or-action-full image-icon image-icon--menu-fullscreen"></i>');$(toolbar).append('<i class="or-action-close image-icon image-icon--menu-close"></i>');$(notice).append(toolbar);let id=0;if(e)$(notice).append('<div class="name clickable"><a href="" data-type="open" data-action="'+t+'" data-id="'+id+'"><i class="or-action-full image-icon image-icon--action-'+t+'"></i> '+e+'</a></div>');$(notice).append('<div class="text">'+htmlEntities(o)+'</div>');if(log.length){let logLi=log.reduce((result,item)=>{result+='<li><pre>'+htmlEntities(item)+'</pre></li>';return result},'');$(notice).append('<div class="log"><ul>'+logLi+'</ul></div>')};$('#noticebar').prepend(notice);$(notice).orLinkify();$(notice).find('.or-action-full').click(function(){$(notice).toggleClass('full')});$(notice).find('.or-action-close').click(function(){$(notice).fadeOut('fast',function(){$(notice).remove()})});let timeout=1;if(i=='ok')timeout=20;if(i=='info')timeout=60;if(i=='warning')timeout=120;if(i=='error')timeout=120;if(timeout>0)setTimeout(function(){$(notice).fadeOut('slow',function(){$(this).remove()})},timeout*1000)}}; \ No newline at end of file