openrat-cms

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

commit 47b9c3f926a21b0cb7f3b7c7aabdca67ddd67a27
parent 1ac211d81eb7795530bd48a4cffa5094b69e1807
Author: Jan Dankert <develop@jandankert.de>
Date:   Wed, 29 Jan 2020 22:55:12 +0100

Refactoring: Moving some UI-specific methods to the ProfileAction, because API-calls do not have access to UI-Actions.

Diffstat:
modules/cms-core/action/ProfileAction.class.php | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/cms-ui/action/IndexAction.class.php | 29+++--------------------------
modules/cms-ui/action/TitleAction.class.php | 7-------
modules/cms-ui/themes/default/production/combined.min.js | 4++--
modules/cms-ui/themes/default/script/openrat/workbench.js | 47+++++++++++++++++++++++++++++++++++++++--------
modules/cms-ui/themes/default/script/openrat/workbench.min.js | 6+++---
modules/util/UIUtils.class.php | 174+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/util/require.php | 2+-
8 files changed, 289 insertions(+), 47 deletions(-)

diff --git a/modules/cms-core/action/ProfileAction.class.php b/modules/cms-core/action/ProfileAction.class.php @@ -20,9 +20,11 @@ namespace cms\action; // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. use cms\model\BaseObject; +use cms\model\User; use language\Language; use LogicException; use Mail; +use modules\util\UIUtils; use security\Base2n; use \Session; @@ -327,4 +329,69 @@ class ProfileAction extends BaseAction } + + public function userinfoView() + { + + $user = Session::getUser(); + + $currentStyle = $this->getUserStyle($user); + $this->setTemplateVar('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. + $this->setTemplateVar('theme-color', UIUtils::getColorHexCode($styleConfig['title_background_color'])); + } + + + /** + * All UI settings. + */ + public function uisettingsView() { + + $this->setTemplateVar('settings',Config()->get('ui') ); + } + + + /** + * The user-dependent language codes. + */ + public function languageView() { + + $this->setTemplateVar('language',Config()->get('language') ); + } + + + + public function pingView() + { + $this->setTemplateVar('pong',1); + } + + + + /** + * @param User $user + * @return string + */ + private function getUserStyle( $user ) + { + // Theme für den angemeldeten Benuter ermitteln + if ( $user && isset(config('style')[$user->style])) + $style = $user->style; + else + $style = config('interface', 'style', 'default'); + + return $style; + } + + } \ No newline at end of file diff --git a/modules/cms-ui/action/IndexAction.class.php b/modules/cms-ui/action/IndexAction.class.php @@ -12,6 +12,7 @@ use JSON; use JSqueeze; use Less_Parser; use Logger; +use modules\util\UIUtils; use ObjectNotFoundException; use Session; use template_engine\TemplateEngineInfo; @@ -57,7 +58,7 @@ class IndexAction extends Action ; // Unknown style name, we are ignoring this. // Theme base color for smartphones colorizing their status bar. - $themeColor = $this->getColorHexCode($styleConfig['title_background_color']); + $themeColor = UIUtils::getColorHexCode($styleConfig['title_background_color']); @@ -80,30 +81,6 @@ class IndexAction extends Action - public function userinfoView() { - - $user = Session::getUser(); - - $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 ); - } - /** * Show the UI. */ @@ -154,7 +131,7 @@ class IndexAction extends Action ; // Unknown style name, we are ignoring this. // Theme base color for smartphones colorizing their status bar. - $this->setTemplateVar('themeColor', $this->getColorHexCode($styleConfig['title_background_color'])); + $this->setTemplateVar('themeColor', UIUtils::getColorHexCode($styleConfig['title_background_color'])); $messageOfTheDay = config('login', 'motd'); diff --git a/modules/cms-ui/action/TitleAction.class.php b/modules/cms-ui/action/TitleAction.class.php @@ -75,13 +75,6 @@ class TitleAction extends Action } - public function pingView() - { - // do nothing here. - // The template is outputting a constant value. - } - - public function historyView() { $resultList = array(); diff --git a/modules/cms-ui/themes/default/production/combined.min.js b/modules/cms-ui/themes/default/production/combined.min.js @@ -10829,9 +10829,9 @@ else{};return url}}; else{let url='./api/';this.setLoadStatus(!0);url+='';data.output='json';if(e==modes.closeAfterSubmit)this.close();let form=this;$.ajax({'type':'POST',url:url,data:data,success:function(t,s,o){form.setLoadStatus(!1);$(status).remove();form.doResponse(t,s,form.element,function(){if(e==modes.closeAfterSuccess){form.close();$(form.element).closest('div.panel').find('div.header ul.views li.action.active').removeClass('dirty')};let afterSuccess=$(form.element).data('afterSuccess');let async=$(form.element).data('async');if(afterSuccess){if(afterSuccess=='reloadAll'){Openrat.Workbench.reloadAll()}} else{if(async);else Openrat.Workbench.reloadViews()}})},error:function(e,t,s){form.setLoadStatus(!1);$(status).remove();try{let error=jQuery.parseJSON(e.responseText);Openrat.Workbench.notify('','','error',error.error,[error.description])}catch(o){let msg=e.responseText;Openrat.Workbench.notify('','','error','Server Error',[msg])}}});$(form.element).fadeIn()}};this.doResponse=function(e,t,s,onSuccess=$.noop){if(t!='success'){alert('Server error: '+t);return};let form=this;$.each(e['notices'],function(t,e){let notifyBrowser=$(s).data('async');Openrat.Workbench.notify(e.type,e.name,e.status,e.text,e.log,notifyBrowser);if(e.status=='ok'){onSuccess();Openrat.Workbench.dataChangedHandler.fire()} 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.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};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,{},!1))},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);this.afterNewActionHandler.fire()};this.afterNewActionHandler=$.Callbacks();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,{},!1);$.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} +/* ./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.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};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(){let ping=function(){let pingPromise=$.json(Openrat.View.createUrl('profile','ping',0,{},!0));pingPromise.fail(function(){console.warn('The server ping has failed.')})};let timeoutMinutes=5;window.setInterval(ping,timeoutMinutes*60*1000)};this.loadNewActionState=function(t){Openrat.Workbench.state=t;Openrat.Workbench.loadNewAction(t.action,t.id,t.data);this.afterNewActionHandler.fire()};this.afterNewActionHandler=$.Callbacks();this.loadNewAction=function(t,e,i){$('#editor').attr('data-action',t);$('#editor').attr('data-id',e);$('#editor').attr('data-extra',JSON.stringify(i));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.loadLanguage();this.loadUISettings()};this.loadUserStyle=function(){let url=Openrat.View.createUrl('profile','userinfo',0,{},!0);$.getJSON(url,function(t){let style=t.output['style'];Openrat.Workbench.setUserStyle(style);let color=t.output['theme-color'];Openrat.Workbench.setThemeColor(color)})};this.settings={};this.language={};this.loadLanguage=function(){let url=Openrat.View.createUrl('profile','language',0,{},!0);$.getJSON(url,function(t){Openrat.Workbench.language=t.output.language})};this.loadUISettings=function(){let url=Openrat.View.createUrl('profile','uisettings',0,{},!0);$.getJSON(url,function(t){Openrat.Workbench.settings=t.output.settings.settings})};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 e=$('html'),i=e.attr('class').split(/\s+/);$.each(i,function(t,i){if(i.startsWith('theme-')){e.removeClass(i)}});e.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)};this.dataChangedHandler=$.Callbacks();this.dataChangedHandler.add(function(){if(popupWindow!==undefined)popupWindow.location.reload()});this.afterViewLoadedHandler=$.Callbacks();let afterViewFunctions=[];this.registerAfterViewLoaded=function(t){afterViewFunctions.push(t)};this.afterViewLoaded=function(t){afterViewFunctions.forEach(function(i){i(t)})}}; +else if(Notification.permission!=='denied'){Notification.requestPermission(function(e){if(e==='granted'){let notification=new Notification(t)}})}};this.notify=function(t,i,e,o,log=[],notifyTheBrowser=!1){if(notifyTheBrowser)notifyBrowser(o);let notice=$('<div class="notice '+e+'"></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(i)$(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> '+i+'</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(e=='ok')timeout=20;if(e=='info')timeout=60;if(e=='warning')timeout=120;if(e=='error')timeout=120;if(timeout>0)setTimeout(function(){$(notice).fadeOut('slow',function(){$(this).remove()})},timeout*1000)};this.dataChangedHandler=$.Callbacks();this.dataChangedHandler.add(function(){if(popupWindow!==undefined)popupWindow.location.reload()});this.afterViewLoadedHandler=$.Callbacks();let afterViewFunctions=[];this.registerAfterViewLoaded=function(t){afterViewFunctions.push(t)};this.afterViewLoaded=function(t){afterViewFunctions.forEach(function(e){e(t)})}}; /* ./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:'')}}; /* ./modules/cms-ui/themes/default/script/openrat/common.min.js */;var OR_THEMES_EXT_DIR='modules/cms-ui/themes/';$(function(){$('html').removeClass('nojs');$('.initial-hidden').removeClass('initial-hidden');function e(){function e(e){$(e).closest('div.panel').fadeOut('fast',function(){$(this).toggleClass('fullscreen').fadeIn('fast')})};$('div.header').dblclick(function(){e(this)})};e();window.onpopstate=function(e){Openrat.Navigator.navigateTo(e.state)};Openrat.Workbench.initialize();Openrat.Workbench.reloadAll();let registerWorkbenchGlobalEvents=function(){$('.keystroke').each(function(){let keystrokeElement=$(this);let keystroke=keystrokeElement.text();if(keystroke.length==0)return;let keyaction=function(){keystrokeElement.click()};$(document).bind('keydown',keystroke,keyaction)});$('section.toggle-open-close .on-click-open-close').click(function(){var t=$(this).closest('section');if(t.hasClass('disabled'))return;var e=t.find('div.view-loader');if(e.children().length==0)Openrat.Workbench.loadNewActionIntoElement(e)})};$('.or-initial-notice').each(function(){Openrat.Workbench.notify('','','info',$(this).text());$(this).remove()});registerWorkbenchGlobalEvents();let closeMenu=function(){$('body').click(function(){$('.toolbar-icon.menu').parents('.or-menu').removeClass('open')})};closeMenu();Openrat.Workbench.afterNewActionHandler.add(function(){let url='./api/?action=tree&subaction=path&id='+Openrat.Workbench.state.id+'&type='+Openrat.Workbench.state.action+'&output=json';$.getJSON(url,function(e){$('nav .or-navtree-node').removeClass('or-navtree-node--selected');let output=e['output'];$.each(output.path,function(e, t){$nav=$('nav .or-navtree-node[data-type='+t.type+'][data-id='+t.id+'].or-navtree-node--is-closed .or-navtree-node-control');$nav.click()});if(output.actual)$('nav .or-navtree-node[data-type='+output.actual.type+'][data-id='+output.actual.id+']').addClass('or-navtree-node--selected');let $breadcrumb=$('.or-breadcrumb').empty();let items=[];$.each(output.path.concat(output.actual),function(e,t){items.push('<li class="or-breadcrumb-item clickable" tabindex="0"><a href="'+Openrat.Navigator.createShortUrl(t.action,t.id)+'" data-type="open" data-action="'+t.action+'" data-id="'+t.id+'"><i class="image-icon image-icon--action-'+t.action+'" />'+t.name+'</a></li>')});$breadcrumb.append(items.join('<li><i class="tree-icon image-icon image-icon--node-closed"></i></li>'));$('.or-breadcrumb .clickable').orLinkify()}).fail(function(e){console.warn(e);console.warn('failed to load path from '+url)}).always(function(){})})});let filterMenus=function(){let action=Openrat.Workbench.state.action;let id=Openrat.Workbench.state.id;$('div.clickable').addClass('active');$('div.clickable.filtered').removeClass('active').addClass('inactive');$('div.clickable.filtered.on-action-'+action).addClass('active').removeClass('inactive');$('div.clickable.filtered a').attr('data-id',id)};$('#title.view').data('afterViewLoaded',function(){filterMenus()});Openrat.Workbench.afterNewActionHandler.add(function(){filterMenus()});Openrat.Workbench.afterViewLoadedHandler.add(function(e){if(typeof popupWindow!='undefined')$(e).find('a[data-type=\'popup\']').each(function(){popupWindow.location.href=$(this).attr('data-url')})});Openrat.Workbench.afterViewLoadedHandler.add(function(e){var n=$(e).closest('section');n.toggleClass('is-empty',$(e).is(':empty'));$(e).closest('div.panel').find('div.header div.dropdown div.entry.perview').remove();$(e).find('.toggle-nav-open-close').click(function(){$('nav').toggleClass('open')});$(e).find('.toggle-nav-small').click(function(){$('nav').toggleClass('small')});$(e).find('div.headermenu > a').each(function(e, t){});$(e).find('div.header > a.back').each(function(t, n){$(n).removeClass('button').wrap('<div class="entry perview" />').parent().appendTo($(e).closest('div.panel').find('div.header div.dropdown').first())});$(e).find('div.selector.tree').each(function(){var e=this;$(this).orTree({type:'project',selectable:$(e).attr('data-types').split(','),id:$(e).attr('data-init-folderid'),onSelect:function(t,n,a){var i=$(e).parent();$(i).find('input[type=text]').attr('value',t);$(i).find('input[type=hidden]').attr('value',a)}})});t(e);$(e).find('input').change(function(){$(this).parent('div.view').addClass('dirty')});$(e).find('.or-theme-chooser').change(function(){Openrat.Workbench.setUserStyle(this.value)});function a(e){$(e).find('.toolbar-icon.menu').click(function(e){e.stopPropagation();$(this).parents('.or-menu').toggleClass('open')});$(e).find('.toolbar-icon.menu').mouseover(function(){$(this).parents('.or-menu').find('.toolbar-icon.menu').removeClass('open');$(this).addClass('open')})};function i(e){$(e).find('.search input').orSearch({dropdown:'#title div.search div.dropdown',select:function(e){openNewAction(e.name,e.action,e.id)}})};function o(e){$(e).find('.selector input').orSearch({dropdown:'.dropdown',select:function(t){$(e).find('.or-selector-link-value').val(t.id);$(e).find('.or-selector-link-name').val(t.name).attr('placeholder',t.name)}})};function l(e){$(e).find('.or-navtree-node').orTree()};a(e);i(e);o(e);l(e);function t(e){registerDraggable(e);registerDroppable(e)};t(e)});function registerDraggable(e){$(e).find('.or-draggable').draggable({helper:'clone',opacity:0.7,zIndex:2,distance:10,cursor:'move',revert:'false'})};function registerTreeBranchEvents(e){registerDraggable(e)};function registerDroppable(e){$(e).find('.or-droppable').droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(e,t){let dropped=t.draggable;let id=dropped.data('id');let name=dropped.data('name');if(!name)name=id;$(this).find('.or-selector-link-value').val(id);$(this).find('.or-selector-link-name').val(name).attr('placeholder',name)}})};function startDialog(e,t,n,a,i){if(!t)t=$('#editor').attr('data-action');if(!a)a=$('#editor').attr('data-id');let view=new Openrat.View(t,n,a,i);view.before=function(){$('#dialog > .view').html('<div class="header"><img class="icon" title="" src="./themes/default/images/icon/'+n+'.png" />'+e+'</div>');$('#dialog > .view').data('id',a);$('#dialog').removeClass('is-closed').addClass('is-open');let view=this;this.escapeKeyClosingHandler=function(e){if(e.keyCode==27){view.close();$(document).off('keyup')}};$(document).keyup(this.escapeKeyClosingHandler);$('#dialog .filler').click(function(){view.close()})};view.close=function(){if($('div#dialog').hasClass('modal'))return;$('#dialog .view').fadeOut('fast').html('');$('#dialog').removeClass('is-open').addClass('is-closed');$(document).unbind('keyup',this.escapeKeyClosingHandler)};view.start($('div#dialog > .view'))};function setTitle(e){if(e)$('head > title').text(e+' - '+$('head > title').data('default'));else $('head > title').text($('head > title').data('default'))};function openNewAction(e,t,n){$('nav').removeClass('open');setTitle(e);Openrat.Navigator.navigateToNew({'action':t,'id':n})};function insert(e,t,a){var n=document.forms[0].elements[e];n.focus();if(typeof document.selection!='undefined'){var l=document.selection.createRange(),i=l.text;l.text=t+i+a;l=document.selection.createRange();if(i.length==0){l.move('character',-a.length)} else{l.moveStart('character',t.length+i.length+a.length)};l.select()} diff --git a/modules/cms-ui/themes/default/script/openrat/workbench.js b/modules/cms-ui/themes/default/script/openrat/workbench.js @@ -69,14 +69,17 @@ Openrat.Workbench = new function() * * "Geben Sie mir ein Ping, Vasily. Und bitte nur ein einziges Ping!" (aus: Jagd auf Roter Oktober) */ - var ping = function() + let ping = function() { - $.ajax( Openrat.View.createUrl('title','ping',0, {}, false) ); - //window.console && console.log("session-ping"); + let pingPromise = $.json( Openrat.View.createUrl('profile','ping',0, {}, true) ); + + pingPromise.fail( function() { + console.warn('The server ping has failed.') + } ); } // Alle 5 Minuten pingen. - var timeoutMinutes = 5; + let timeoutMinutes = 5; window.setInterval( ping, timeoutMinutes*60*1000 ); } @@ -131,25 +134,53 @@ Openrat.Workbench = new function() Openrat.Workbench.loadViews( $('#workbench .view.view-loader, #workbench .view.view-static') ); this.loadUserStyle(); + this.loadLanguage(); + this.loadUISettings(); } this.loadUserStyle = function() { - let url = Openrat.View.createUrl('index','userinfo',0, {},false ); + let url = Openrat.View.createUrl('profile','userinfo',0, {},true ); // Die Inhalte des Zweiges laden. - $.getJSON(url, function (themeData) { + $.getJSON(url, function (response) { - let style = themeData['style']; + let style = response.output['style']; Openrat.Workbench.setUserStyle(style); - let color = themeData['theme-color']; + let color = response.output['theme-color']; Openrat.Workbench.setThemeColor(color); }); } + this.settings = {}; + this.language = {}; + + this.loadLanguage = function() { + + let url = Openrat.View.createUrl('profile','language',0, {},true ); + + // Die Inhalte des Zweiges laden. + $.getJSON(url, function (response) { + + Openrat.Workbench.language = response.output.language; + }); + } + + this.loadUISettings = function() { + + let url = Openrat.View.createUrl('profile','uisettings',0, {},true ); + + // Die Inhalte des Zweiges laden. + $.getJSON(url, function (response) { + + Openrat.Workbench.settings = response.output.settings.settings; + }); + } + + this.loadViews = function( $views ) { 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.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};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,{},!1))},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);this.afterNewActionHandler.fire()};this.afterNewActionHandler=$.Callbacks();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,{},!1);$.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} +;Openrat.Workbench=new function(){'use strict';this.state={};this.initialize=function(){this.initializePingTimer();this.initializeState();this.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};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(){let ping=function(){let pingPromise=$.json(Openrat.View.createUrl('profile','ping',0,{},!0));pingPromise.fail(function(){console.warn('The server ping has failed.')})};let timeoutMinutes=5;window.setInterval(ping,timeoutMinutes*60*1000)};this.loadNewActionState=function(t){Openrat.Workbench.state=t;Openrat.Workbench.loadNewAction(t.action,t.id,t.data);this.afterNewActionHandler.fire()};this.afterNewActionHandler=$.Callbacks();this.loadNewAction=function(t,e,i){$('#editor').attr('data-action',t);$('#editor').attr('data-id',e);$('#editor').attr('data-extra',JSON.stringify(i));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.loadLanguage();this.loadUISettings()};this.loadUserStyle=function(){let url=Openrat.View.createUrl('profile','userinfo',0,{},!0);$.getJSON(url,function(t){let style=t.output['style'];Openrat.Workbench.setUserStyle(style);let color=t.output['theme-color'];Openrat.Workbench.setThemeColor(color)})};this.settings={};this.language={};this.loadLanguage=function(){let url=Openrat.View.createUrl('profile','language',0,{},!0);$.getJSON(url,function(t){Openrat.Workbench.language=t.output.language})};this.loadUISettings=function(){let url=Openrat.View.createUrl('profile','uisettings',0,{},!0);$.getJSON(url,function(t){Openrat.Workbench.settings=t.output.settings.settings})};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 e=$('html'),i=e.attr('class').split(/\s+/);$.each(i,function(t,i){if(i.startsWith('theme-')){e.removeClass(i)}});e.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)};this.dataChangedHandler=$.Callbacks();this.dataChangedHandler.add(function(){if(popupWindow!==undefined)popupWindow.location.reload()});this.afterViewLoadedHandler=$.Callbacks();let afterViewFunctions=[];this.registerAfterViewLoaded=function(t){afterViewFunctions.push(t)};this.afterViewLoaded=function(t){afterViewFunctions.forEach(function(i){i(t)})}};- \ No newline at end of file +else if(Notification.permission!=='denied'){Notification.requestPermission(function(e){if(e==='granted'){let notification=new Notification(t)}})}};this.notify=function(t,i,e,o,log=[],notifyTheBrowser=!1){if(notifyTheBrowser)notifyBrowser(o);let notice=$('<div class="notice '+e+'"></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(i)$(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> '+i+'</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(e=='ok')timeout=20;if(e=='info')timeout=60;if(e=='warning')timeout=120;if(e=='error')timeout=120;if(timeout>0)setTimeout(function(){$(notice).fadeOut('slow',function(){$(this).remove()})},timeout*1000)};this.dataChangedHandler=$.Callbacks();this.dataChangedHandler.add(function(){if(popupWindow!==undefined)popupWindow.location.reload()});this.afterViewLoadedHandler=$.Callbacks();let afterViewFunctions=[];this.registerAfterViewLoaded=function(t){afterViewFunctions.push(t)};this.afterViewLoaded=function(t){afterViewFunctions.forEach(function(e){e(t)})}};+ \ No newline at end of file diff --git a/modules/util/UIUtils.class.php b/modules/util/UIUtils.class.php @@ -0,0 +1,173 @@ +<?php + + +namespace modules\util; + + +class UIUtils +{ + + /** + * Translates a color name into its hexadecimal code. + * + * @param $colorName + * @return mixed|string + */ + public static function getColorHexCode($colorName ) { + + $colorName = strtolower($colorName); + + $colors = array( + 'aliceblue'=>'#f0f8ff', + 'antiquewhite'=>'#faebd7', + 'aqua'=>'#00ffff', + 'aquamarine'=>'#7fffd4', + 'azure'=>'#f0ffff', + 'beige'=>'#f5f5dc', + 'bisque'=>'#ffe4c4', + 'black'=>'#000000', + 'blanchedalmond'=>'#ffebcd', + 'blue'=>'#0000ff', + 'blueviolet'=>'#8a2be2', + 'brown'=>'#a52a2a', + 'burlywood'=>'#deb887', + 'cadetblue'=>'#5f9ea0', + 'chartreuse'=>'#7fff00', + 'chocolate'=>'#d2691e', + 'coral'=>'#ff7f50', + 'cornflowerblue'=>'#6495ed', + 'cornsilk'=>'#fff8dc', + 'crimson'=>'#dc143c', + 'cyan'=>'#00ffff', + 'darkblue'=>'#00008b', + 'darkcyan'=>'#008b8b', + 'darkgoldenrod'=>'#b8860b', + 'darkgray'=>'#a9a9a9', + 'darkgrey'=>'#a9a9a9', + 'darkgreen'=>'#006400', + 'darkkhaki'=>'#bdb76b', + 'darkmagenta'=>'#8b008b', + 'darkolivegreen'=>'#556b2f', + 'darkorange'=>'#ff8c00', + 'darkorchid'=>'#9932cc', + 'darkred'=>'#8b0000', + 'darksalmon'=>'#e9967a', + 'darkseagreen'=>'#8fbc8f', + 'darkslateblue'=>'#483d8b', + 'darkslategray'=>'#2f4f4f', + 'darkslategrey'=>'#2f4f4f', + 'darkturquoise'=>'#00ced1', + 'darkviolet'=>'#9400d3', + 'deeppink'=>'#ff1493', + 'deepskyblue'=>'#00bfff', + 'dimgray'=>'#696969', + 'dimgrey'=>'#696969', + 'dodgerblue'=>'#1e90ff', + 'firebrick'=>'#b22222', + 'floralwhite'=>'#fffaf0', + 'forestgreen'=>'#228b22', + 'fuchsia'=>'#ff00ff', + 'gainsboro'=>'#dcdcdc', + 'ghostwhite'=>'#f8f8ff', + 'gold'=>'#ffd700', + 'goldenrod'=>'#daa520', + 'gray'=>'#808080', + 'grey'=>'#808080', + 'green'=>'#008000', + 'greenyellow'=>'#adff2f', + 'honeydew'=>'#f0fff0', + 'hotpink'=>'#ff69b4', + 'indianred'=>'#cd5c5c', + 'indigo'=>'#4b0082', + 'ivory'=>'#fffff0', + 'khaki'=>'#f0e68c', + 'lavender'=>'#e6e6fa', + 'lavenderblush'=>'#fff0f5', + 'lawngreen'=>'#7cfc00', + 'lemonchiffon'=>'#fffacd', + 'lightblue'=>'#add8e6', + 'lightcoral'=>'#f08080', + 'lightcyan'=>'#e0ffff', + 'lightgoldenrodyellow'=>'#fafad2', + 'lightgray'=>'#d3d3d3', + 'lightgrey'=>'#d3d3d3', + 'lightgreen'=>'#90ee90', + 'lightpink'=>'#ffb6c1', + 'lightsalmon'=>'#ffa07a', + 'lightseagreen'=>'#20b2aa', + 'lightskyblue'=>'#87cefa', + 'lightslategray'=>'#778899', + 'lightslategrey'=>'#778899', + 'lightsteelblue'=>'#b0c4de', + 'lightyellow'=>'#ffffe0', + 'lime'=>'#00ff00', + 'limegreen'=>'#32cd32', + 'linen'=>'#faf0e6', + 'magenta'=>'#ff00ff', + 'maroon'=>'#800000', + 'mediumaquamarine'=>'#66cdaa', + 'mediumblue'=>'#0000cd', + 'mediumorchid'=>'#ba55d3', + 'mediumpurple'=>'#9370d8', + 'mediumseagreen'=>'#3cb371', + 'mediumslateblue'=>'#7b68ee', + 'mediumspringgreen'=>'#00fa9a', + 'mediumturquoise'=>'#48d1cc', + 'mediumvioletred'=>'#c71585', + 'midnightblue'=>'#191970', + 'mintcream'=>'#f5fffa', + 'mistyrose'=>'#ffe4e1', + 'moccasin'=>'#ffe4b5', + 'navajowhite'=>'#ffdead', + 'navy'=>'#000080', + 'oldlace'=>'#fdf5e6', + 'olive'=>'#808000', + 'olivedrab'=>'#6b8e23', + 'orange'=>'#ffa500', + 'orangered'=>'#ff4500', + 'orchid'=>'#da70d6', + 'palegoldenrod'=>'#eee8aa', + 'palegreen'=>'#98fb98', + 'paleturquoise'=>'#afeeee', + 'palevioletred'=>'#d87093', + 'papayawhip'=>'#ffefd5', + 'peachpuff'=>'#ffdab9', + 'peru'=>'#cd853f', + 'pink'=>'#ffc0cb', + 'plum'=>'#dda0dd', + 'powderblue'=>'#b0e0e6', + 'purple'=>'#800080', + 'red'=>'#ff0000', + 'rosybrown'=>'#bc8f8f', + 'royalblue'=>'#4169e1', + 'saddlebrown'=>'#8b4513', + 'salmon'=>'#fa8072', + 'sandybrown'=>'#f4a460', + 'seagreen'=>'#2e8b57', + 'seashell'=>'#fff5ee', + 'sienna'=>'#a0522d', + 'silver'=>'#c0c0c0', + 'skyblue'=>'#87ceeb', + 'slateblue'=>'#6a5acd', + 'slategray'=>'#708090', + 'slategrey'=>'#708090', + 'snow'=>'#fffafa', + 'springgreen'=>'#00ff7f', + 'steelblue'=>'#4682b4', + 'tan'=>'#d2b48c', + 'teal'=>'#008080', + 'thistle'=>'#d8bfd8', + 'tomato'=>'#ff6347', + 'turquoise'=>'#40e0d0', + 'violet'=>'#ee82ee', + 'wheat'=>'#f5deb3', + 'white'=>'#ffffff', + 'whitesmoke'=>'#f5f5f5', + 'yellow'=>'#ffff00', + 'yellowgreen'=>'#9acd32' + ); + + return isset($colors[$colorName])?$colors[$colorName]:$colorName; + } + +}+ \ No newline at end of file diff --git a/modules/util/require.php b/modules/util/require.php @@ -33,7 +33,7 @@ require_once( __DIR__.'/'.'Api.class.php' ); require_once( __DIR__.'/'.'Code.class.php' ); require_once( __DIR__.'/'.'Transformer.class.php' ); require_once( __DIR__.'/'.'Line.class.php' ); -require_once( __DIR__.'/'.'Upload.class.php' ); +require_once( __DIR__.'/'.'UIUtils.class.php' ); require_once( __DIR__.'/'.'Upload.class.php' ); require_once( __DIR__.'/'.'ArchiveTar.class.php' ); require_once( __DIR__.'/'.'ArchiveUnzip.class.php' );