openrat-cms

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

commit 82d64e4e8eac4d5229582a6c1b4adc213c2ee12d
parent f808b08090dda23fd3d46fcf4f259e77e4e08604
Author: Jan Dankert <develop@jandankert.de>
Date:   Sat, 27 Apr 2019 23:50:02 +0200

Formularsteuerung erfolgt über die Klasse "Form", dadurch entfällt viel Gefrickel im DOM-Baum. Das Formular muss nicht mehr wissen, wo es im DOM-Baum eingefügt ist.

Diffstat:
modules/cms-ui/themes/default/production/combined.min.js | 14+++++++-------
modules/cms-ui/themes/default/script/openrat.js | 168++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
modules/cms-ui/themes/default/script/openrat.min.js | 7++++---
modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.js | 1+
modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.min.js | 4++--
modules/template-engine/components/html/form/form.js | 110-------------------------------------------------------------------------------
modules/template-engine/components/html/form/form.min.js | 7+++----
7 files changed, 184 insertions(+), 127 deletions(-)

diff --git a/modules/cms-ui/themes/default/production/combined.min.js b/modules/cms-ui/themes/default/production/combined.min.js @@ -275,7 +275,7 @@ else{return{top:0,left:0}}},_cacheMargins:function(){this.margins={left:(parseIn else{this.currentItem.show()};if(this.fromOutside&&!e){s.push(function(t){this._trigger("receive",t,this._uiHash(this.fromOutside))})};if((this.fromOutside||this.domPosition.prev!==this.currentItem.prev().not(".ui-sortable-helper")[0]||this.domPosition.parent!==this.currentItem.parent()[0])&&!e){s.push(function(t){this._trigger("update",t,this._uiHash())})};if(this!==this.currentContainer){if(!e){s.push(function(t){this._trigger("remove",t,this._uiHash())});s.push((function(t){return function(e){t._trigger("receive",e,this._uiHash(this))}}).call(this,this.currentContainer));s.push((function(t){return function(e){t._trigger("update",e,this._uiHash(this))}}).call(this,this.currentContainer))}};function o(t,e,i){return function(s){i._trigger(t,s,e._uiHash(e))}};for(i=this.containers.length-1;i>=0;i--){if(!e){s.push(o("deactivate",this,this.containers[i]))};if(this.containers[i].containerCache.over){s.push(o("out",this,this.containers[i]));this.containers[i].containerCache.over=0}};if(this.storedCursor){this.document.find("body").css("cursor",this.storedCursor);this.storedStylesheet.remove()};if(this._storedOpacity){this.helper.css("opacity",this._storedOpacity)};if(this._storedZIndex){this.helper.css("zIndex",this._storedZIndex==="auto"?"":this._storedZIndex)};this.dragging=!1;if(!e){this._trigger("beforeStop",t,this._uiHash())};this.placeholder[0].parentNode.removeChild(this.placeholder[0]);if(!this.cancelHelperRemoval){if(this.helper[0]!==this.currentItem[0]){this.helper.remove()};this.helper=null};if(!e){for(i=0;i<s.length;i++){s[i].call(this,t)};this._trigger("stop",t,this._uiHash())};this.fromOutside=!1;return!this.cancelHelperRemoval},_trigger:function(){if(t.Widget.prototype._trigger.apply(this,arguments)===!1){this.cancel()}},_uiHash:function(e){var i=e||this;return{helper:i.helper,placeholder:i.placeholder||t([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:e?e.element:null}}})})); /* ./modules/cms-ui/themes/default/script/plugin/jquery-plugin-orSearch.min.js */;jQuery.fn.orSearch=function(e){var t=$.extend({'dropdown':'unknown'},e);return $(this).keyup(function(){let searchArgument=$(this).val();if(searchArgument.length>3){$(t.dropdown).empty();$.ajax({'type':'GET',url:'./api/?action=search&subaction=quicksearch&output=json&search='+searchArgument,data:null,success:function(e,a,n){for(id in e.output.result){let result=e.output.result[id];let div=$('<div class="entry clickable" title="'+result.desc+'"></div>');let link=$('<a href="./?action='+result.type+'&id='+result.id+'"></a>');$(link).attr('data-type','open').attr('data-name',result.name).attr('data-action',result.type).attr('data-id',result.id).attr('data-extra','[]');$(link).append('<i class="image-icon image-icon--action-'+result.type+'" />');$(link).append('<span>'+result.name+'</span>');$(div).append(link);$(t.dropdown).append(div)};$(t.dropdown).closest('.or-menu').addClass('open');$(t.dropdown).find('.clickable').orLinkify()}})} else{$(t.dropdown).empty()}})}; -/* ./modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.min.js */;var popupWindow;jQuery.fn.orLinkify=function(){$(this).find("a").click(function(t){t.preventDefault()});return $(this).click(function(){$(this).find("a").first().each(function(){let type=$(this).attr("data-type");if($(this).parent().hasClass("inactive"))return;switch(type){case"post":submitLink(this,$(this).attr("data-data"));break;case"dialog":startDialog($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"edit":startEdit($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"url":submitUrl(this,$(this).attr("data-url"));break;case"external":window.open($(this).attr("data-url")," _blank");break;case"popup":popupWindow=window.open($(this).attr("data-url"),"Popup","location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes");break;case"help":help(this,$(this).attr("data-url"),$(this).attr("data-suffix"));break;case"fullscreen":fullscreen(this);break;case"open":openNewAction($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-id"),jQuery.parseJSON($(this).attr("data-extra").replace(/'/g,"\"")));break;default:alert("Fatal: Cannot open link: "+$(this).html())}})})};$(document).on("orViewLoaded",function(t,a){if(typeof popupWindow!="undefined")$(t.target).find("a[data-type='popup']").each(function(){popupWindow.location.href=$(this).attr("data-url")})});$(document).on("orDataChanged",function(t,a){if(typeof popupWindow!="undefined")popupWindow.location.reload()}); +/* ./modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.min.js */;var popupWindow;jQuery.fn.orLinkify=function(){$(this).find("a").click(function(t){t.preventDefault()});return $(this).click(function(){$(this).find("a").first().each(function(){let type=$(this).attr("data-type");if($(this).parent().hasClass("inactive"))return;switch(type){case"post":submitLink(this,$(this).attr("data-data"));break;case"dialog":startDialog($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"edit":startEdit($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"url":throw"probably unused, isn't it?";submitUrl(this,$(this).attr("data-url"));break;case"external":window.open($(this).attr("data-url")," _blank");break;case"popup":popupWindow=window.open($(this).attr("data-url"),"Popup","location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes");break;case"help":help(this,$(this).attr("data-url"),$(this).attr("data-suffix"));break;case"fullscreen":fullscreen(this);break;case"open":openNewAction($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-id"),jQuery.parseJSON($(this).attr("data-extra").replace(/'/g,"\"")));break;default:alert("Fatal: Cannot open link: "+$(this).html())}})})};$(document).on("orViewLoaded",function(t,a){if(typeof popupWindow!="undefined")$(t.target).find("a[data-type='popup']").each(function(){popupWindow.location.href=$(this).attr("data-url")})});$(document).on("orDataChanged",function(t,a){if(typeof popupWindow!="undefined")popupWindow.location.reload()}); /* ./modules/cms-ui/themes/default/script/plugin/jquery-plugin-orTree.min.js */;jQuery.fn.orTree=function(){$(this).each(function(a,e){$(e).children('.or-navtree-node-control').click(function(){var a=$(this).parent('.or-navtree-node');if($(a).is('.or-navtree-node--is-open')){$(a).children('ul').slideUp('fast').remove();$(a).removeClass('or-navtree-node--is-open').addClass('or-navtree-node--is-closed').find('.tree-icon').removeClass('image-icon--node-open').addClass('image-icon--node-closed')} else{$(e).closest('div.view').addClass('loader');var o=$(a).data('type'),t=$(a).data('id'),i=$(a).data('extra'),n='./api/?action=tree&subaction=loadBranch&id='+t+'&type='+o+'&output=json';if(typeof i==='string'){jQuery.each(jQuery.parseJSON(i.replace(/'/g,'"')),function(e,a){n=n+'&'+e+'='+a})} else if(typeof i==='object'){jQuery.each(i,function(e,a){n=n+'&'+e+'='+a})} @@ -10999,18 +10999,18 @@ jQuery.trumbowyg={langs:{en:{viewHTML:"View HTML",undo:"Undo",redo:"Redo",format /* ./modules//template-engine/components/html/column/column.min.js */;$(document).on('orViewLoaded',function(o,n){}); /* ./modules//template-engine/components/html/image/image.min.js */;$(document).on('orViewLoaded',function(o,n){var e=document.querySelectorAll('img.image-icon');SVGInjector(e)}); /* ./modules//template-engine/components/html/group/group.min.js */;$(document).on('orViewLoaded',function(e,o){registerOpenClose($(e.target).find('fieldset.toggle-open-close'))}); -/* ./modules//template-engine/components/html/form/form.min.js */;$(document).on('orViewLoaded',function(e,t){$(e.target).find('form[data-autosave="true"] input[type="checkbox"]').click(function(){$(this).closest('form').submit()});$(e.target).find('.or-form-btn--cancel').click(function(){$(e.target).html('').parent().removeClass('is-open')});$(e.target).find('form').submit(function(e){if($(this).data('target')=='view'){formSubmit($(this));e.preventDefault()}})});function formSubmit(e){var r=$('<div class="notice info"><div class="text loader"></div></div>');$('#noticebar').prepend(r);$(r).show();$(e).find('.error').removeClass('error');var o=$(e).serializeArray(),t={};$(o).each(function(e,r){t[r.name]=r.value});var s=$(e).attr('method').toUpperCase();if(s=='GET'){let view=new View(t.action,t.subaction,t.id,t);view.start($(e).parent('.view'))} -else{var a='./api/';$(e).closest('div.content').addClass('loader');a+='?output=json';o['output']='json';if($(e).data('async')||$(e).data('async')=='true'){$('#dialog > .view').html('');$('#dialog').removeClass('is-open').addClass('is-closed')};$.ajax({'type':'POST',url:a,data:o,success:function(t,o,a){$(e).closest('div.content').removeClass('loader');$(r).remove();doResponse(t,o,e)},error:function(t,o,a){$(e).closest('div.content').removeClass('loader');$(r).remove();try{let error=jQuery.parseJSON(t.responseText);notify('','','error',error.error,[error.description])}catch(s){let msg=t.responseText;notify('','','error','Server Error',[msg])}}});$(e).fadeIn()}};function doResponse(e,t,r){if(t!='success'){alert('Server error: '+t);return};$.each(e['notices'],function(t,e){if($(r).data('async')=='true')notifyBrowser(e.text);notify(e.type,e.name,e.status,e.text,e.log);if(e.status=='ok'){if($(r).data('async')!='true'){$('#dialog > .view').html('').hide();$('#dialog').removeClass('is-open').addClass('is-closed');$(r).closest('div.panel').find('div.header ul.views li.action.active').removeClass('dirty')};$(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){};if(e.control.redirect)window.location.href=e.control.redirect}; +/* ./modules//template-engine/components/html/form/form.min.js */;function doResponse(e,t,r){if(t!='success'){alert('Server error: '+t);return};$.each(e['notices'],function(t,e){if($(r).data('async')=='true')notifyBrowser(e.text);notify(e.type,e.name,e.status,e.text,e.log);if(e.status=='ok'){if($(r).data('async')!='true'){$('#dialog > .view').html('').hide();$('#dialog').removeClass('is-open').addClass('is-closed');$(r).closest('div.panel').find('div.header ul.views li.action.active').removeClass('dirty')};$(document).trigger('orDataChanged')} +else{}});$.each(e['errors'],function(t,e){$('input[name='+e+']').addClass('error').parent().addClass('error').parents('fieldset').addClass('show').addClass('open')});if(!e.control){};if(e.control.redirect)window.location.href=e.control.redirect}; /* ./modules//template-engine/components/html/upload/upload.min.js */;$(document).on('orViewLoaded',function(e,n){var a=$(e.target).find('form'),o=$(e.target).find('div.or-dropzone-upload > div.input');o.on('dragenter',function(e){e.stopPropagation();e.preventDefault();$(this).css('border','1px dotted gray')});o.on('dragover',function(e){e.stopPropagation();e.preventDefault()});o.on('drop',function(e){$(this).css('border','1px dotted red');e.preventDefault();var n=e.originalEvent.dataTransfer.files;handleFileUpload(a,n)});$(e.target).find('input[type=file]').change(function(){var e=$(this).prop('files');handleFileUpload(a,e)})});function handleFileUpload(e,o){for(var t=0,r;r=o[t];t++){var n=new FormData();n.append('file',r);n.append('action','folder');n.append('subaction',$(e).data('method'));n.append('output','json');n.append('token',$(e).find('input[name=token]').val());n.append('id',$(e).find('input[name=id]').val());var a=$('<div class="notice info"><div class="text loader"></div></div>');$('#noticebar').prepend(a);$(a).show();$.ajax({'type':'POST',url:'./api/',cache:!1,contentType:!1,processData:!1,data:n,success:function(n,o,t){$(a).remove();doResponse(n,o,e)},error:function(n,o,d){$(e).closest('div.content').removeClass('loader');$(a).remove();var r;try{var t=jQuery.parseJSON(n.responseText);r=t.error+'/'+t.description+': '+t.reason}catch(i){r=n.responseText};notify('error',r)}})}}; /* ./modules//template-engine/components/html/tree/tree.min.js */;$(document).on('orViewLoaded',function(o,n){}); /* ./modules/cms-ui/themes/default/script/openrat.min.js */;var OR_THEMES_EXT_DIR='modules/cms-ui/themes/';$(function(){$('html').removeClass('nojs');$('.initial-hidden').removeClass('initial-hidden');registerHeaderEvents();registerWorkbenchEvents();$('.view').each(function(e){afterViewLoaded(this)});window.onpopstate=function(e){Navigator.navigateTo(e.state)};initActualHistoryState();Workbench.initialize();loadTree();$(document).keyup(function(e){if(e.keyCode==27){$('#dialog .view').fadeOut('fast').html('');$('#dialog').removeClass('is-open').addClass('is-closed')}});$('.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)});$('#noticebar .notice .image-icon--menu-close').click(function(){$(this).closest('.notice').fadeOut('fast',function(){$(this).remove()})});$('#noticebar .notice').each(function(){let noticeToClose=this;setTimeout(function(){$(noticeToClose).fadeOut('slow',function(){$(this).remove()})},30*1000)});registerOpenClose($('section.toggle-open-close'));$('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)Workbench.loadNewActionIntoElement(e)})});function initActualHistoryState(){var e={};e.name=window.document.title;var t=new URLSearchParams(window.location.search);if(t.has('action')){e.action=t.get('action');e.id=t.get('id');e.name=window.document.title;e.data={};var t=Array.from(t.entries());for(var i in t){e.data[t[i][0]]=t[i][1]};Navigator.toActualHistory(e);filterMenus(e.action,e.id,e.data)}};var Navigator=new function(){'use strict';this.navigateTo=function(e){Workbench.loadNewActionState(e)};this.navigateToNew=function(e){Workbench.loadNewActionState(e);window.history.pushState(e,e.name,createUrl(e.action,null,e.id,e.data,!1))};this.navigateToNewAction=function(e,t,i,n){var o={action:e,method:t,id:i,data:n};this.navigateToNew(o)};this.toActualHistory=function(e){window.history.replaceState(e,e.name,createUrl(e.action,null,e.id,e.data,!1))}},Workbench=new function(){'use strict';this.initialize=function(){this.initializePingTimer()};this.initializePingTimer=function(){var e=function(){$.ajax(createUrl('title','ping',0))},t=5;window.setInterval(e,t*60*1000)};this.loadNewActionState=function(e){Workbench.loadNewAction(e.action,e.id,e.data)};this.loadNewAction=function(e,t,i){$('#editor').attr('data-action',e);$('#editor').attr('data-id',t);$('#editor').attr('data-extra',JSON.stringify(i));$('#workbench section.closed .view-loader').empty();$('#workbench section.open .view-loader').each(function(e){var t=$(this);Workbench.loadNewActionIntoElement(t)});filterMenus(e,t,i)};this.loadNewActionIntoElement=function(e){var t=$('#editor').attr('data-action'),i=$('#editor').attr('data-id'),n=$('#editor').attr('data-extra'),o=e.data('method');let view=new View(t,o,i,n);view.start(e)}};function registerWorkbenchEvents(){$('div.header').dblclick(function(){fullscreen(this)});$('div#filler').click(function(){if($('div#dialog').hasClass('modal')){} -else{$('div#dialog').removeClass('is-open').addClass('is-closed');$('div#dialog > .view').html('')}})};function loadView(e,t,i,n,o){Navigator.navigateToNewAction(t,i,n,o)};function afterViewLoaded(e){var t=$(e).closest('section');t.toggleClass('is-empty',$(e).is(':empty'));$(e).trigger('orViewLoaded');$(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,i){$(i).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,i,n){var o=$(e).parent();$(o).find('input[type=text]').attr('value',t);$(o).find('input[type=hidden]').attr('value',n)}})});registerDragAndDrop(e);$(e).find('input').change(function(){$(this).parent('div.view').addClass('dirty')});$(e).find('.or-theme-chooser').change(function(){setUserStyle(this.value)})};function registerDragAndDrop(e){registerDraggable(e);registerDroppable(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;$(this).find('.or-selector-link-value').val(dropped.data('id'));$(this).find('.or-selector-link-name').val(dropped.data('id'))}})};function registerHeaderEvents(){$('body').click(function(){$('.toolbar-icon.menu').parents('.or-menu').removeClass('open')});$('#title .toolbar-icon.menu').click(function(e){e.stopPropagation();$(this).parents('.or-menu').toggleClass('open')});$('#title .toolbar-icon.menu').mouseover(function(){$(this).parents('.or-menu').find('.toolbar-icon.menu').removeClass('open');$(this).addClass('open')});$('#title div.search input').orSearch({dropdown:'#title div.search div.dropdown'})};function fullscreen(e){$(e).closest('div.panel').fadeOut('fast',function(){$(this).toggleClass('fullscreen').fadeIn('fast')})};function loadTree(){$('.or-navtree .or-navtree-node').orTree()};function submitUrl(e,t){postUrl(t,e)};function postUrl(e,t){e+='&output=json';$.ajax({'type':'POST',url:e,data:{},success:function(e,i,n){$('div.panel div.status div.loader').html('&nbsp;');doResponse(e,i,t)}})};function View(e,t,i,n){this.action=e;this.method=t;this.id=i;this.params=n;this.before=function(){};this.start=function(e){this.before();this.element=e;this.loadView()};this.afterLoad=function(){};this.loadView=function(){let url=createUrl(this.action,this.method,this.id,this.params,!0);let element=this.element;$(this.element).empty().fadeTo(1,0.7).addClass('loader').html('').load(url,function(e,t,i){$(element).fadeTo(350,1);$(element).removeClass('loader');if(t=='error'){$(element).html('');notify('','','error','Server Error',['Server Error while requesting url '+url,e]);return};afterViewLoaded(element)})}};function startDialog(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);view.before=function(){$('div#dialog > .view').html('<div class="header"><img class="icon" title="" src="./themes/default/images/icon/'+i+'.png" />'+e+'</div>');$('div#dialog > .view').data('id',n);$('div#dialog').removeClass('is-closed').addClass('is-open')};view.start($('div#dialog > .view'))};function startEdit(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);$edit=$('#edit');$edit.addClass('is-open');view.start($('#edit > .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,i,n){$('nav').removeClass('open');setTitle(e);setNewAction(t,i,n)};function filterMenus(e,t,i){$('div.clickable').addClass('active');$('div.clickable.filtered').removeClass('active').addClass('inactive');$('div.clickable.filtered.on-action-'+e).addClass('active').removeClass('inactive');$('div.clickable.filtered a').attr('data-action',e);$('div.clickable.filtered a').attr('data-id',t);$('div.clickable.filtered a').attr('data-extra',JSON.stringify(i))};function setNewAction(e,t,i){Navigator.navigateToNewAction(e,'edit',t,i)};function setNewId(e){};function notifyBrowser(e){if(!('Notification' in window)){return} +else{$('div#dialog').removeClass('is-open').addClass('is-closed');$('div#dialog > .view').html('')}})};function loadView(e,t,i,n,o){Navigator.navigateToNewAction(t,i,n,o)};function afterViewLoaded(e){var t=$(e).closest('section');t.toggleClass('is-empty',$(e).is(':empty'));$(e).trigger('orViewLoaded');$(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,i){$(i).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,i,n){var o=$(e).parent();$(o).find('input[type=text]').attr('value',t);$(o).find('input[type=hidden]').attr('value',n)}})});registerDragAndDrop(e);$(e).find('input').change(function(){$(this).parent('div.view').addClass('dirty')});$(e).find('.or-theme-chooser').change(function(){setUserStyle(this.value)})};function registerDragAndDrop(e){registerDraggable(e);registerDroppable(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;$(this).find('.or-selector-link-value').val(dropped.data('id'));$(this).find('.or-selector-link-name').val(dropped.data('id'))}})};function registerHeaderEvents(){$('body').click(function(){$('.toolbar-icon.menu').parents('.or-menu').removeClass('open')});$('#title .toolbar-icon.menu').click(function(e){e.stopPropagation();$(this).parents('.or-menu').toggleClass('open')});$('#title .toolbar-icon.menu').mouseover(function(){$(this).parents('.or-menu').find('.toolbar-icon.menu').removeClass('open');$(this).addClass('open')});$('#title div.search input').orSearch({dropdown:'#title div.search div.dropdown'})};function fullscreen(e){$(e).closest('div.panel').fadeOut('fast',function(){$(this).toggleClass('fullscreen').fadeIn('fast')})};function loadTree(){$('.or-navtree .or-navtree-node').orTree()};function submitUrl(e,t){postUrl(t,e)};function postUrl(e,t){e+='&output=json';$.ajax({'type':'POST',url:e,data:{},success:function(e,i,n){$('div.panel div.status div.loader').html('&nbsp;');doResponse(e,i,t)}})};function Form(){this.setLoadStatus=function(e){$(this.element).closest('div.content').toggleClass('loader',e)};this.initOnElement=function(e){this.element=e;$(e).find('form[data-autosave="true"] input[type="checkbox"]').click(function(){$(this).closest('form').submit()});let form=this;$(e).find('.or-form-btn--cancel').click(function(){form.cancel()});$(e).submit(function(e){if($(this).data('target')=='view'){form.submit();e.preventDefault()}})};this.cancel=function(){$(this.element).html('').parent().removeClass('is-open')};this.close=function(){};this.submit=function(){var t=$('<div class="notice info"><div class="text loader"></div></div>');$('#noticebar').prepend(t);$(t).show();$(this.element).find('.error').removeClass('error');var i=$(this.element).serializeArray(),e={};$(i).each(function(t,i){e[i.name]=i.value});var n=$(this.element).attr('method').toUpperCase();if(n=='GET'){this.forwardTo(e.action,e.subaction,e.id,e)} +else{let url='./api/';this.setLoadStatus(!0);url+='?output=json';i['output']='json';if($(this.element).data('async')||$(this.element).data('async')=='true'){this.close()};let form=this;$.ajax({'type':'POST',url:url,data:i,success:function(e,i,n){form.setLoadStatus(!1);$(t).remove();doResponse(e,i,form)},error:function(e,i,n){form.setLoadStatus(!1);$(t).remove();try{let error=jQuery.parseJSON(e.responseText);notify('','','error',error.error,[error.description])}catch(o){let msg=e.responseText;notify('','','error','Server Error',[msg])}}});$(form.element).fadeIn()}}};function View(e,t,i,n){this.action=e;this.method=t;this.id=i;this.params=n;this.before=function(){};this.start=function(e){this.before();this.element=e;this.loadView()};this.afterLoad=function(){};this.close=function(){$(this.element).empty()};this.loadView=function(){let url=createUrl(this.action,this.method,this.id,this.params,!0);let element=this.element;let view=this;$(this.element).empty().fadeTo(1,0.7).addClass('loader').html('').load(url,function(e,t,i){$(element).fadeTo(350,1);$(element).removeClass('loader');$(element).find('form').each(function(){let form=new Form();form.close=function(){view.close()};form.initOnElement(this)});if(t=='error'){$(element).html('');notify('','','error','Server Error',['Server Error while requesting url '+url,e]);return};afterViewLoaded(element)})}};function startDialog(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);view.before=function(){$('div#dialog > .view').html('<div class="header"><img class="icon" title="" src="./themes/default/images/icon/'+i+'.png" />'+e+'</div>');$('div#dialog > .view').data('id',n);$('div#dialog').removeClass('is-closed').addClass('is-open')};view.start($('div#dialog > .view'))};function startEdit(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);$edit=$('#edit');$edit.addClass('is-open');view.start($('#edit > .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,i,n){$('nav').removeClass('open');setTitle(e);setNewAction(t,i,n)};function filterMenus(e,t,i){$('div.clickable').addClass('active');$('div.clickable.filtered').removeClass('active').addClass('inactive');$('div.clickable.filtered.on-action-'+e).addClass('active').removeClass('inactive');$('div.clickable.filtered a').attr('data-action',e);$('div.clickable.filtered a').attr('data-id',t);$('div.clickable.filtered a').attr('data-extra',JSON.stringify(i))};function setNewAction(e,t,i){Navigator.navigateToNewAction(e,'edit',t,i)};function setNewId(e){};function notifyBrowser(e){if(!('Notification' in window)){return} else if(Notification.permission==='granted'){let notification=new Notification(e)} else if(Notification.permission!=='denied'){Notification.requestPermission(function(t){if(t==='granted'){let notification=new Notification(e)}})}};function setUserStyle(e){var t=$('html'),i=t.attr('class').split(/\s+/);$.each(i,function(e,i){if(i.startsWith('theme-')){t.removeClass(i)}});t.addClass('theme-'+e.toLowerCase())};function insert(e,t,i){var n=document.forms[0].elements[e];n.focus();if(typeof document.selection!='undefined'){var r=document.selection.createRange(),o=r.text;r.text=t+o+i;r=document.selection.createRange();if(o.length==0){r.move('character',-i.length)} else{r.moveStart('character',t.length+o.length+i.length)};r.select()} -else if(typeof n.selectionStart!='undefined'){var l=n.selectionStart,s=n.selectionEnd,o=n.value.substring(l,s);n.value=n.value.substr(0,l)+t+o+i+n.value.substr(s);var a;if(o.length==0){a=l+t.length} -else{a=l+t.length+o.length+i.length};n.selectionStart=a;n.selectionEnd=a} +else if(typeof n.selectionStart!='undefined'){var s=n.selectionStart,l=n.selectionEnd,o=n.value.substring(s,l);n.value=n.value.substr(0,s)+t+o+i+n.value.substr(l);var a;if(o.length==0){a=s+t.length} +else{a=s+t.length+o.length+i.length};n.selectionStart=a;n.selectionEnd=a} else{a=n.value.length;var o=prompt('Text');n.value=n.value.substr(0,a)+t+o+i+n.value.substr(a)}};function createUrl(e,t,i,n,a){var o='./';o+='?action='+e;if(t!=null)o+='&subaction='+t;o+='&id='+i;if(a)o+='&embed=1';if(typeof n==='string'){n=n.replace(/'/g,'"');var r=jQuery.parseJSON(n);jQuery.each(r,function(e,t){if(e=='action'||e=='subaction'||e=='id')return;o=o+'&'+e+'='+t})} else if(typeof n==='object'){jQuery.each(n,function(e,t){if(e=='action'||e=='subaction'||e=='id')return;o=o+'&'+e+'='+t})} else{};return o};function resizeWorkbenchContainer(e){};function resizeWorkbench(){};function resizeTabs(e){};function help(e,t,i){var n=$(e).closest('div.panel').find('li.action.active').attr('data-action'),o=$(e).closest('div.panel').find('li.action.active').attr('data-method');window.open(t+n+'/'+o+i,'OpenRat_Help','location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes')};function notify(e,t,i,n,log=[]){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);if(t)$(notice).append('<div class="name"><i class="or-action-full image-icon image-icon--action-'+e+'"></i> '+t+'</div>');$(notice).append('<div class="text">'+htmlEntities(n)+'</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).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)};function htmlEntities(e){return String(e).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;')};function registerOpenClose(e){$(e).children('.on-click-open-close').click(function(){$(this).closest('.toggle-open-close').toggleClass('open closed')})}; \ No newline at end of file diff --git a/modules/cms-ui/themes/default/script/openrat.js b/modules/cms-ui/themes/default/script/openrat.js @@ -501,7 +501,9 @@ function loadTree() * @param element * @param action Action * @param id Id + * @deprecated */ + function submitUrl( element,url ) { postUrl( url,element ); @@ -511,7 +513,12 @@ function submitUrl( element,url ) } +/** + * @deprecated + * @param url + * @param element + */ function postUrl(url,element) { url += '&output=json'; @@ -520,10 +527,155 @@ function postUrl(url,element) $('div.panel div.status div.loader').html('&nbsp;'); doResponse(data,textStatus,element); } } ); - + } +/** + * Form. + * + * @constructor + */ +function Form() { + + this.setLoadStatus = function( isLoading ) { + $(this.element).closest('div.content').toggleClass('loader',isLoading); + } + + this.initOnElement = function( element ) { + this.element = element; + + // Autosave in Formularen. Bei Veränderungen wird das Formular sofort abgeschickt. + $(element).find('form[data-autosave="true"] input[type="checkbox"]').click( function() { + $(this).closest('form').submit(); + }); + + // After click to "OK" the form is submitted. + // Why this?? input type=submit will submit! + /* + $(event.target).find('input.submit.ok').click( function() { + $(this).closest('form').submit(); + }); + */ + + let form = this; + + $(element).find('.or-form-btn--cancel').click( function() { + form.cancel(); + + }); + + // Submithandler for the whole form. + $(element).submit( function( event ) { + + // + if ($(this).data('target')=='view') + { + form.submit(); + event.preventDefault(); + } + // target=top will load the native way without javascript. + }); + } + + this.cancel = function() { + $(this.element).html('').parent().removeClass('is-open'); + } + + this.close = function() { + + } + + this.submit = function() { + + + // Show progress + var status = $('<div class="notice info"><div class="text loader"></div></div>'); + $('#noticebar').prepend(status); // Notice anhängen. + $(status).show(); + + // Alle vorhandenen Error-Marker entfernen. + // Falls wieder ein Fehler auftritt, werden diese erneut gesetzt. + $(this.element).find('.error').removeClass('error'); + + var params = $(this.element).serializeArray(); + var data = {}; + $(params).each(function(index, obj){ + data[obj.name] = obj.value; + }); + + var formMethod = $(this.element).attr('method').toUpperCase(); + + if ( formMethod == 'GET' ) + { + // Mehrseitiges Formular + // Die eingegebenen Formulardaten werden zur nächsten Action geschickt. + //Workbench.loadViewIntoElement( $(form).parent('.view'),data.action, data.subaction,data.id,data ); + this.forwardTo( data.action, data.subaction,data.id,data ); + } + else + { + let url = './api/'; // Alle Parameter befinden sich im Formular + + // POST-Request + this.setLoadStatus(true); + url += '?output=json'; + params['output'] = 'json';// Irgendwie geht das nicht. + + if ( $(this.element).data('async') || $(this.element).data('async')=='true') + { + // Verarbeitung erfolgt asynchron, das heißt, dass der evtl. geöffnete Dialog + // beendet wird. + this.close(); + // Async: Window is closed, but the action will be startet now. + } + + let form = this; + $.ajax( { 'type':'POST',url:url, data:params, success:function(data, textStatus, jqXHR) + { + form.setLoadStatus(false); + $(status).remove(); + + doResponse(data,textStatus,form); + }, + error:function(jqXHR, textStatus, errorThrown) { + form.setLoadStatus(false); + $(status).remove(); + + try + { + let error = jQuery.parseJSON( jqXHR.responseText ); + notify('','','error',error.error,[error.description]); + } + catch( e ) + { + let msg = jqXHR.responseText; + notify('','','error','Server Error',[msg]); + } + + + } + + } ); + $(form.element).fadeIn(); + } + + } +} + + + +/** + * View. + * Eine View ist ein HTML-Fragment, in das eine Action geladen wird. + * Das Erzeugen der View, das Laden vom Server sowie das Schließen sind hier gekapselt. + * + * @param action + * @param method + * @param id + * @param params + * @constructor + */ function View( action,method,id,params ) { this.action = action; @@ -543,17 +695,31 @@ function View( action,method,id,params ) { } + this.close = function() { + $(this.element).empty(); + } + this.loadView = function() { let url = createUrl( this.action,this.method,this.id,this.params,true); // URL für das Laden erzeugen. let element = this.element; + let view = this; $(this.element).empty().fadeTo(1,0.7).addClass('loader').html('').load(url,function(response, status, xhr) { + $(element).fadeTo(350,1); $(element).removeClass("loader"); + $(element).find('form').each( function() { + let form = new Form(); + form.close = function() { + view.close(); + } + form.initOnElement(this); + + }); if ( status == "error" ) { // Seite nicht gefunden. diff --git a/modules/cms-ui/themes/default/script/openrat.min.js b/modules/cms-ui/themes/default/script/openrat.min.js @@ -1,10 +1,11 @@ ;var OR_THEMES_EXT_DIR='modules/cms-ui/themes/';$(function(){$('html').removeClass('nojs');$('.initial-hidden').removeClass('initial-hidden');registerHeaderEvents();registerWorkbenchEvents();$('.view').each(function(e){afterViewLoaded(this)});window.onpopstate=function(e){Navigator.navigateTo(e.state)};initActualHistoryState();Workbench.initialize();loadTree();$(document).keyup(function(e){if(e.keyCode==27){$('#dialog .view').fadeOut('fast').html('');$('#dialog').removeClass('is-open').addClass('is-closed')}});$('.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)});$('#noticebar .notice .image-icon--menu-close').click(function(){$(this).closest('.notice').fadeOut('fast',function(){$(this).remove()})});$('#noticebar .notice').each(function(){let noticeToClose=this;setTimeout(function(){$(noticeToClose).fadeOut('slow',function(){$(this).remove()})},30*1000)});registerOpenClose($('section.toggle-open-close'));$('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)Workbench.loadNewActionIntoElement(e)})});function initActualHistoryState(){var e={};e.name=window.document.title;var t=new URLSearchParams(window.location.search);if(t.has('action')){e.action=t.get('action');e.id=t.get('id');e.name=window.document.title;e.data={};var t=Array.from(t.entries());for(var i in t){e.data[t[i][0]]=t[i][1]};Navigator.toActualHistory(e);filterMenus(e.action,e.id,e.data)}};var Navigator=new function(){'use strict';this.navigateTo=function(e){Workbench.loadNewActionState(e)};this.navigateToNew=function(e){Workbench.loadNewActionState(e);window.history.pushState(e,e.name,createUrl(e.action,null,e.id,e.data,!1))};this.navigateToNewAction=function(e,t,i,n){var o={action:e,method:t,id:i,data:n};this.navigateToNew(o)};this.toActualHistory=function(e){window.history.replaceState(e,e.name,createUrl(e.action,null,e.id,e.data,!1))}},Workbench=new function(){'use strict';this.initialize=function(){this.initializePingTimer()};this.initializePingTimer=function(){var e=function(){$.ajax(createUrl('title','ping',0))},t=5;window.setInterval(e,t*60*1000)};this.loadNewActionState=function(e){Workbench.loadNewAction(e.action,e.id,e.data)};this.loadNewAction=function(e,t,i){$('#editor').attr('data-action',e);$('#editor').attr('data-id',t);$('#editor').attr('data-extra',JSON.stringify(i));$('#workbench section.closed .view-loader').empty();$('#workbench section.open .view-loader').each(function(e){var t=$(this);Workbench.loadNewActionIntoElement(t)});filterMenus(e,t,i)};this.loadNewActionIntoElement=function(e){var t=$('#editor').attr('data-action'),i=$('#editor').attr('data-id'),n=$('#editor').attr('data-extra'),o=e.data('method');let view=new View(t,o,i,n);view.start(e)}};function registerWorkbenchEvents(){$('div.header').dblclick(function(){fullscreen(this)});$('div#filler').click(function(){if($('div#dialog').hasClass('modal')){} -else{$('div#dialog').removeClass('is-open').addClass('is-closed');$('div#dialog > .view').html('')}})};function loadView(e,t,i,n,o){Navigator.navigateToNewAction(t,i,n,o)};function afterViewLoaded(e){var t=$(e).closest('section');t.toggleClass('is-empty',$(e).is(':empty'));$(e).trigger('orViewLoaded');$(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,i){$(i).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,i,n){var o=$(e).parent();$(o).find('input[type=text]').attr('value',t);$(o).find('input[type=hidden]').attr('value',n)}})});registerDragAndDrop(e);$(e).find('input').change(function(){$(this).parent('div.view').addClass('dirty')});$(e).find('.or-theme-chooser').change(function(){setUserStyle(this.value)})};function registerDragAndDrop(e){registerDraggable(e);registerDroppable(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;$(this).find('.or-selector-link-value').val(dropped.data('id'));$(this).find('.or-selector-link-name').val(dropped.data('id'))}})};function registerHeaderEvents(){$('body').click(function(){$('.toolbar-icon.menu').parents('.or-menu').removeClass('open')});$('#title .toolbar-icon.menu').click(function(e){e.stopPropagation();$(this).parents('.or-menu').toggleClass('open')});$('#title .toolbar-icon.menu').mouseover(function(){$(this).parents('.or-menu').find('.toolbar-icon.menu').removeClass('open');$(this).addClass('open')});$('#title div.search input').orSearch({dropdown:'#title div.search div.dropdown'})};function fullscreen(e){$(e).closest('div.panel').fadeOut('fast',function(){$(this).toggleClass('fullscreen').fadeIn('fast')})};function loadTree(){$('.or-navtree .or-navtree-node').orTree()};function submitUrl(e,t){postUrl(t,e)};function postUrl(e,t){e+='&output=json';$.ajax({'type':'POST',url:e,data:{},success:function(e,i,n){$('div.panel div.status div.loader').html('&nbsp;');doResponse(e,i,t)}})};function View(e,t,i,n){this.action=e;this.method=t;this.id=i;this.params=n;this.before=function(){};this.start=function(e){this.before();this.element=e;this.loadView()};this.afterLoad=function(){};this.loadView=function(){let url=createUrl(this.action,this.method,this.id,this.params,!0);let element=this.element;$(this.element).empty().fadeTo(1,0.7).addClass('loader').html('').load(url,function(e,t,i){$(element).fadeTo(350,1);$(element).removeClass('loader');if(t=='error'){$(element).html('');notify('','','error','Server Error',['Server Error while requesting url '+url,e]);return};afterViewLoaded(element)})}};function startDialog(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);view.before=function(){$('div#dialog > .view').html('<div class="header"><img class="icon" title="" src="./themes/default/images/icon/'+i+'.png" />'+e+'</div>');$('div#dialog > .view').data('id',n);$('div#dialog').removeClass('is-closed').addClass('is-open')};view.start($('div#dialog > .view'))};function startEdit(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);$edit=$('#edit');$edit.addClass('is-open');view.start($('#edit > .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,i,n){$('nav').removeClass('open');setTitle(e);setNewAction(t,i,n)};function filterMenus(e,t,i){$('div.clickable').addClass('active');$('div.clickable.filtered').removeClass('active').addClass('inactive');$('div.clickable.filtered.on-action-'+e).addClass('active').removeClass('inactive');$('div.clickable.filtered a').attr('data-action',e);$('div.clickable.filtered a').attr('data-id',t);$('div.clickable.filtered a').attr('data-extra',JSON.stringify(i))};function setNewAction(e,t,i){Navigator.navigateToNewAction(e,'edit',t,i)};function setNewId(e){};function notifyBrowser(e){if(!('Notification' in window)){return} +else{$('div#dialog').removeClass('is-open').addClass('is-closed');$('div#dialog > .view').html('')}})};function loadView(e,t,i,n,o){Navigator.navigateToNewAction(t,i,n,o)};function afterViewLoaded(e){var t=$(e).closest('section');t.toggleClass('is-empty',$(e).is(':empty'));$(e).trigger('orViewLoaded');$(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,i){$(i).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,i,n){var o=$(e).parent();$(o).find('input[type=text]').attr('value',t);$(o).find('input[type=hidden]').attr('value',n)}})});registerDragAndDrop(e);$(e).find('input').change(function(){$(this).parent('div.view').addClass('dirty')});$(e).find('.or-theme-chooser').change(function(){setUserStyle(this.value)})};function registerDragAndDrop(e){registerDraggable(e);registerDroppable(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;$(this).find('.or-selector-link-value').val(dropped.data('id'));$(this).find('.or-selector-link-name').val(dropped.data('id'))}})};function registerHeaderEvents(){$('body').click(function(){$('.toolbar-icon.menu').parents('.or-menu').removeClass('open')});$('#title .toolbar-icon.menu').click(function(e){e.stopPropagation();$(this).parents('.or-menu').toggleClass('open')});$('#title .toolbar-icon.menu').mouseover(function(){$(this).parents('.or-menu').find('.toolbar-icon.menu').removeClass('open');$(this).addClass('open')});$('#title div.search input').orSearch({dropdown:'#title div.search div.dropdown'})};function fullscreen(e){$(e).closest('div.panel').fadeOut('fast',function(){$(this).toggleClass('fullscreen').fadeIn('fast')})};function loadTree(){$('.or-navtree .or-navtree-node').orTree()};function submitUrl(e,t){postUrl(t,e)};function postUrl(e,t){e+='&output=json';$.ajax({'type':'POST',url:e,data:{},success:function(e,i,n){$('div.panel div.status div.loader').html('&nbsp;');doResponse(e,i,t)}})};function Form(){this.setLoadStatus=function(e){$(this.element).closest('div.content').toggleClass('loader',e)};this.initOnElement=function(e){this.element=e;$(e).find('form[data-autosave="true"] input[type="checkbox"]').click(function(){$(this).closest('form').submit()});let form=this;$(e).find('.or-form-btn--cancel').click(function(){form.cancel()});$(e).submit(function(e){if($(this).data('target')=='view'){form.submit();e.preventDefault()}})};this.cancel=function(){$(this.element).html('').parent().removeClass('is-open')};this.close=function(){};this.submit=function(){var t=$('<div class="notice info"><div class="text loader"></div></div>');$('#noticebar').prepend(t);$(t).show();$(this.element).find('.error').removeClass('error');var i=$(this.element).serializeArray(),e={};$(i).each(function(t,i){e[i.name]=i.value});var n=$(this.element).attr('method').toUpperCase();if(n=='GET'){this.forwardTo(e.action,e.subaction,e.id,e)} +else{let url='./api/';this.setLoadStatus(!0);url+='?output=json';i['output']='json';if($(this.element).data('async')||$(this.element).data('async')=='true'){this.close()};let form=this;$.ajax({'type':'POST',url:url,data:i,success:function(e,i,n){form.setLoadStatus(!1);$(t).remove();doResponse(e,i,form)},error:function(e,i,n){form.setLoadStatus(!1);$(t).remove();try{let error=jQuery.parseJSON(e.responseText);notify('','','error',error.error,[error.description])}catch(o){let msg=e.responseText;notify('','','error','Server Error',[msg])}}});$(form.element).fadeIn()}}};function View(e,t,i,n){this.action=e;this.method=t;this.id=i;this.params=n;this.before=function(){};this.start=function(e){this.before();this.element=e;this.loadView()};this.afterLoad=function(){};this.close=function(){$(this.element).empty()};this.loadView=function(){let url=createUrl(this.action,this.method,this.id,this.params,!0);let element=this.element;let view=this;$(this.element).empty().fadeTo(1,0.7).addClass('loader').html('').load(url,function(e,t,i){$(element).fadeTo(350,1);$(element).removeClass('loader');$(element).find('form').each(function(){let form=new Form();form.close=function(){view.close()};form.initOnElement(this)});if(t=='error'){$(element).html('');notify('','','error','Server Error',['Server Error while requesting url '+url,e]);return};afterViewLoaded(element)})}};function startDialog(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);view.before=function(){$('div#dialog > .view').html('<div class="header"><img class="icon" title="" src="./themes/default/images/icon/'+i+'.png" />'+e+'</div>');$('div#dialog > .view').data('id',n);$('div#dialog').removeClass('is-closed').addClass('is-open')};view.start($('div#dialog > .view'))};function startEdit(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);$edit=$('#edit');$edit.addClass('is-open');view.start($('#edit > .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,i,n){$('nav').removeClass('open');setTitle(e);setNewAction(t,i,n)};function filterMenus(e,t,i){$('div.clickable').addClass('active');$('div.clickable.filtered').removeClass('active').addClass('inactive');$('div.clickable.filtered.on-action-'+e).addClass('active').removeClass('inactive');$('div.clickable.filtered a').attr('data-action',e);$('div.clickable.filtered a').attr('data-id',t);$('div.clickable.filtered a').attr('data-extra',JSON.stringify(i))};function setNewAction(e,t,i){Navigator.navigateToNewAction(e,'edit',t,i)};function setNewId(e){};function notifyBrowser(e){if(!('Notification' in window)){return} else if(Notification.permission==='granted'){let notification=new Notification(e)} else if(Notification.permission!=='denied'){Notification.requestPermission(function(t){if(t==='granted'){let notification=new Notification(e)}})}};function setUserStyle(e){var t=$('html'),i=t.attr('class').split(/\s+/);$.each(i,function(e,i){if(i.startsWith('theme-')){t.removeClass(i)}});t.addClass('theme-'+e.toLowerCase())};function insert(e,t,i){var n=document.forms[0].elements[e];n.focus();if(typeof document.selection!='undefined'){var r=document.selection.createRange(),o=r.text;r.text=t+o+i;r=document.selection.createRange();if(o.length==0){r.move('character',-i.length)} else{r.moveStart('character',t.length+o.length+i.length)};r.select()} -else if(typeof n.selectionStart!='undefined'){var l=n.selectionStart,s=n.selectionEnd,o=n.value.substring(l,s);n.value=n.value.substr(0,l)+t+o+i+n.value.substr(s);var a;if(o.length==0){a=l+t.length} -else{a=l+t.length+o.length+i.length};n.selectionStart=a;n.selectionEnd=a} +else if(typeof n.selectionStart!='undefined'){var s=n.selectionStart,l=n.selectionEnd,o=n.value.substring(s,l);n.value=n.value.substr(0,s)+t+o+i+n.value.substr(l);var a;if(o.length==0){a=s+t.length} +else{a=s+t.length+o.length+i.length};n.selectionStart=a;n.selectionEnd=a} else{a=n.value.length;var o=prompt('Text');n.value=n.value.substr(0,a)+t+o+i+n.value.substr(a)}};function createUrl(e,t,i,n,a){var o='./';o+='?action='+e;if(t!=null)o+='&subaction='+t;o+='&id='+i;if(a)o+='&embed=1';if(typeof n==='string'){n=n.replace(/'/g,'"');var r=jQuery.parseJSON(n);jQuery.each(r,function(e,t){if(e=='action'||e=='subaction'||e=='id')return;o=o+'&'+e+'='+t})} else if(typeof n==='object'){jQuery.each(n,function(e,t){if(e=='action'||e=='subaction'||e=='id')return;o=o+'&'+e+'='+t})} else{};return o};function resizeWorkbenchContainer(e){};function resizeWorkbench(){};function resizeTabs(e){};function help(e,t,i){var n=$(e).closest('div.panel').find('li.action.active').attr('data-action'),o=$(e).closest('div.panel').find('li.action.active').attr('data-method');window.open(t+n+'/'+o+i,'OpenRat_Help','location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes')};function notify(e,t,i,n,log=[]){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);if(t)$(notice).append('<div class="name"><i class="or-action-full image-icon image-icon--action-'+e+'"></i> '+t+'</div>');$(notice).append('<div class="text">'+htmlEntities(n)+'</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).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)};function htmlEntities(e){return String(e).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;')};function registerOpenClose(e){$(e).children('.on-click-open-close').click(function(){$(this).closest('.toggle-open-close').toggleClass('open closed')})}; \ No newline at end of file diff --git a/modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.js b/modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.js @@ -39,6 +39,7 @@ jQuery.fn.orLinkify = function() break; case 'url': + throw "probably unused, isn't it?"; submitUrl(this,$(this).attr('data-url') ); break; diff --git a/modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.min.js b/modules/cms-ui/themes/default/script/plugin/jquery-plugin-orLinkify.min.js @@ -1 +1 @@ -;var popupWindow;jQuery.fn.orLinkify=function(){$(this).find("a").click(function(t){t.preventDefault()});return $(this).click(function(){$(this).find("a").first().each(function(){let type=$(this).attr("data-type");if($(this).parent().hasClass("inactive"))return;switch(type){case"post":submitLink(this,$(this).attr("data-data"));break;case"dialog":startDialog($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"edit":startEdit($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"url":submitUrl(this,$(this).attr("data-url"));break;case"external":window.open($(this).attr("data-url")," _blank");break;case"popup":popupWindow=window.open($(this).attr("data-url"),"Popup","location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes");break;case"help":help(this,$(this).attr("data-url"),$(this).attr("data-suffix"));break;case"fullscreen":fullscreen(this);break;case"open":openNewAction($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-id"),jQuery.parseJSON($(this).attr("data-extra").replace(/'/g,"\"")));break;default:alert("Fatal: Cannot open link: "+$(this).html())}})})};$(document).on("orViewLoaded",function(t,a){if(typeof popupWindow!="undefined")$(t.target).find("a[data-type='popup']").each(function(){popupWindow.location.href=$(this).attr("data-url")})});$(document).on("orDataChanged",function(t,a){if(typeof popupWindow!="undefined")popupWindow.location.reload()});- \ No newline at end of file +;var popupWindow;jQuery.fn.orLinkify=function(){$(this).find("a").click(function(t){t.preventDefault()});return $(this).click(function(){$(this).find("a").first().each(function(){let type=$(this).attr("data-type");if($(this).parent().hasClass("inactive"))return;switch(type){case"post":submitLink(this,$(this).attr("data-data"));break;case"dialog":startDialog($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"edit":startEdit($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-method"),$(this).attr("data-id"),$(this).attr("data-extra"));break;case"url":throw"probably unused, isn't it?";submitUrl(this,$(this).attr("data-url"));break;case"external":window.open($(this).attr("data-url")," _blank");break;case"popup":popupWindow=window.open($(this).attr("data-url"),"Popup","location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes");break;case"help":help(this,$(this).attr("data-url"),$(this).attr("data-suffix"));break;case"fullscreen":fullscreen(this);break;case"open":openNewAction($(this).attr("data-name"),$(this).attr("data-action"),$(this).attr("data-id"),jQuery.parseJSON($(this).attr("data-extra").replace(/'/g,"\"")));break;default:alert("Fatal: Cannot open link: "+$(this).html())}})})};$(document).on("orViewLoaded",function(t,a){if(typeof popupWindow!="undefined")$(t.target).find("a[data-type='popup']").each(function(){popupWindow.location.href=$(this).attr("data-url")})});$(document).on("orDataChanged",function(t,a){if(typeof popupWindow!="undefined")popupWindow.location.reload()});+ \ No newline at end of file diff --git a/modules/template-engine/components/html/form/form.js b/modules/template-engine/components/html/form/form.js @@ -1,114 +1,4 @@ // -$(document).on('orViewLoaded',function(event, data) { - - // Autosave in Formularen. Bei Veränderungen wird das Formular sofort abgeschickt. - $(event.target).find('form[data-autosave="true"] input[type="checkbox"]').click( function() { - $(this).closest('form').submit(); - }); - - // After click to "OK" the form is submitted. - // Why this?? input type=submit will submit! - /* - $(event.target).find('input.submit.ok').click( function() { - $(this).closest('form').submit(); - }); - */ - - $(event.target).find('.or-form-btn--cancel').click( function() { - $(event.target).html('').parent().removeClass('is-open'); - }); - - // Submithandler for the whole form. - $(event.target).find('form').submit(function( event ) { - - // - if ($(this).data('target')=='view') - { - formSubmit($(this)); - event.preventDefault(); - } - // target=top will load the native way without javascript. - }); - -} ); - - - - -function formSubmit(form) -{ - // Show progress - var status = $('<div class="notice info"><div class="text loader"></div></div>'); - $('#noticebar').prepend(status); // Notice anhängen. - $(status).show(); - - // Alle vorhandenen Error-Marker entfernen. - // Falls wieder ein Fehler auftritt, werden diese erneut gesetzt. - $(form).find('.error').removeClass('error'); - - var params = $(form).serializeArray(); - var data = {}; - $(params).each(function(index, obj){ - data[obj.name] = obj.value; - }); - - var formMethod = $(form).attr('method').toUpperCase(); - - if ( formMethod == 'GET' ) - { - // Mehrseitiges Formular - // Die eingegebenen Formulardaten werden zur nächsten Action geschickt. - //Workbench.loadViewIntoElement( $(form).parent('.view'),data.action, data.subaction,data.id,data ); - let view = new View( data.action, data.subaction,data.id,data ); - view.start( $(form).parent('.view') ); - } - else - { - var url = './api/'; // Alle Parameter befinden sich im Formular - - // POST-Request - $(form).closest('div.content').addClass('loader'); - url += '?output=json'; - params['output'] = 'json';// Irgendwie geht das nicht. - - if ( $(form).data('async') || $(form).data('async')=='true') - { - // Verarbeitung erfolgt asynchron, das heißt, dass der evtl. geöffnete Dialog - // beendet wird. - $('#dialog > .view').html(''); // Dialog beenden - $('#dialog').removeClass('is-open').addClass('is-closed'); // Dialog schließen - } - - $.ajax( { 'type':'POST',url:url, data:params, success:function(data, textStatus, jqXHR) - { - $(form).closest('div.content').removeClass('loader'); - $(status).remove(); - - doResponse(data,textStatus,form); - }, - error:function(jqXHR, textStatus, errorThrown) { - $(form).closest('div.content').removeClass('loader'); - $(status).remove(); - - try - { - let error = jQuery.parseJSON( jqXHR.responseText ); - notify('','','error',error.error,[error.description]); - } - catch( e ) - { - let msg = jqXHR.responseText; - notify('','','error','Server Error',[msg]); - } - - - } - - } ); - $(form).fadeIn(); - } -} - diff --git a/modules/template-engine/components/html/form/form.min.js b/modules/template-engine/components/html/form/form.min.js @@ -1,3 +1,2 @@ -;$(document).on('orViewLoaded',function(e,t){$(e.target).find('form[data-autosave="true"] input[type="checkbox"]').click(function(){$(this).closest('form').submit()});$(e.target).find('.or-form-btn--cancel').click(function(){$(e.target).html('').parent().removeClass('is-open')});$(e.target).find('form').submit(function(e){if($(this).data('target')=='view'){formSubmit($(this));e.preventDefault()}})});function formSubmit(e){var r=$('<div class="notice info"><div class="text loader"></div></div>');$('#noticebar').prepend(r);$(r).show();$(e).find('.error').removeClass('error');var o=$(e).serializeArray(),t={};$(o).each(function(e,r){t[r.name]=r.value});var s=$(e).attr('method').toUpperCase();if(s=='GET'){let view=new View(t.action,t.subaction,t.id,t);view.start($(e).parent('.view'))} -else{var a='./api/';$(e).closest('div.content').addClass('loader');a+='?output=json';o['output']='json';if($(e).data('async')||$(e).data('async')=='true'){$('#dialog > .view').html('');$('#dialog').removeClass('is-open').addClass('is-closed')};$.ajax({'type':'POST',url:a,data:o,success:function(t,o,a){$(e).closest('div.content').removeClass('loader');$(r).remove();doResponse(t,o,e)},error:function(t,o,a){$(e).closest('div.content').removeClass('loader');$(r).remove();try{let error=jQuery.parseJSON(t.responseText);notify('','','error',error.error,[error.description])}catch(s){let msg=t.responseText;notify('','','error','Server Error',[msg])}}});$(e).fadeIn()}};function doResponse(e,t,r){if(t!='success'){alert('Server error: '+t);return};$.each(e['notices'],function(t,e){if($(r).data('async')=='true')notifyBrowser(e.text);notify(e.type,e.name,e.status,e.text,e.log);if(e.status=='ok'){if($(r).data('async')!='true'){$('#dialog > .view').html('').hide();$('#dialog').removeClass('is-open').addClass('is-closed');$(r).closest('div.panel').find('div.header ul.views li.action.active').removeClass('dirty')};$(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){};if(e.control.redirect)window.location.href=e.control.redirect};- \ No newline at end of file +;function doResponse(e,t,r){if(t!='success'){alert('Server error: '+t);return};$.each(e['notices'],function(t,e){if($(r).data('async')=='true')notifyBrowser(e.text);notify(e.type,e.name,e.status,e.text,e.log);if(e.status=='ok'){if($(r).data('async')!='true'){$('#dialog > .view').html('').hide();$('#dialog').removeClass('is-open').addClass('is-closed');$(r).closest('div.panel').find('div.header ul.views li.action.active').removeClass('dirty')};$(document).trigger('orDataChanged')} +else{}});$.each(e['errors'],function(t,e){$('input[name='+e+']').addClass('error').parent().addClass('error').parents('fieldset').addClass('show').addClass('open')});if(!e.control){};if(e.control.redirect)window.location.href=e.control.redirect};+ \ No newline at end of file