1if(typeof $==='undefined'&&typeof jQuery==='function')$=jQuery;$.ajaxSetup({'cache':true});TRIGGERED_READY=false;varFromAttribute=function(object,variableName,element,tag){if(Object.getOwnPropertyDescriptor(object,variableName)!==undefined)throw new Error('varAsAttribute: var "'+variableName+'" already defined') 2if(typeof tag==='undefined')tag='data-'+variableName;Object.defineProperty(object,[variableName],{set:function(value){$(element).attr(tag,value)},get:function(){return $(element).attr(tag)}})} 3function errorHandler(x){alert(x)} 4Modules={list:{},loadHelper:function(text){$('head').append(text)},loadHelper_css:function(text){$('head').append(text)},loadHelper_sync:function(filePath){var req=new XMLHttpRequest();req.open("GET",filePath,false);req.send(null);var headElement=document.getElementsByTagName("head")[0];var newScriptElement=document.createElement("script");newScriptElement.type="text/javascript";newScriptElement.text=req.responseText;headElement.appendChild(newScriptElement)},load:function(module){var moduleName=module.name||module;if(Modules.exists(moduleName)==false){var url=module.url||module;var type=module.type||'';if(type=='')type=url.substr(url.lastIndexOf('.')+1).toLowerCase();if(module.sync==true) 5Modules.loadHelper_sync(url);else if(type=='css') 6Modules.loadHelper_css('<link rel="stylesheet" href="'+url+'" type="text\/css"><\/link>');else 7Modules.loadHelper('<script type="text/javascript" src="'+url+'"><\/script>');Modules.list[moduleName]=module}},exists:function(module){var name=module.name||module;return typeof Modules.list[name]!=='undefined'}};function isset(){var a=arguments,l=a.length,i=0,undef;if(l===0){throw new Error('Empty isset')} 8while(i!==l){if(a[i]===undef||a[i]===null){return false} 9i++} 10return true} 11function isString(value){return(typeof value==='string'||value instanceof String)} 12function nl2br(str,is_xhtml){var breakTag=(is_xhtml||typeof is_xhtml==='undefined')?'<br '+'/>':'<br>';return(str+'').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g,'$1'+breakTag+'$2')} 13function htmlEntities(str){return String(str).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"')} 14function decodeHtmlEntities(html){return $('<div>').html(html).text()}(function(proxied){window.alert=function(){if(typeof arguments[0]=='string')arguments[0]=decodeHtmlEntities(arguments[0]);return proxied.apply(this,arguments)}})(window.alert);function urlExists(url,callback){var http=new XMLHttpRequest();if(typeof callback==='function'){http.onreadystatechange=function(){if(this.readyState==4){callback(this.status==200)}};http.open("HEAD",url,true);http.send()}else{http.open('HEAD',url,false);http.send();console.log(http);return http.status==200}} 15addDisplayLabels=function(element){$(element).find('>[data-structure="field"]').each(function(){})} 16addFieldLabel=function(fieldElement){if($(fieldElement).hasAttr('data-label')==false||$(fieldElement).attr('data-label-auto')!=="false")$(fieldElement).attr('data-label',$(fieldElement).data('field').getLabel())} 17showDetails=function(displayOrEntity,options){if(typeof options==='undefined')options={};if(typeof displayOrEntity.entity!=='undefined') 18options.entity=displayOrEntity.entity;else options.entity=displayOrEntity;var entity=options.entity;console.log(options);console.log(entity);var tabId=entity.view.name+'_'+entity.getPrimary('string');var display=new Display(options);var title='TITLE';if(typeof options.title!=='undefined')title=options.title;else{title=entity.view.name;if(typeof entity.view.displayField!=='undefined'&&entity.view.displayField!=''){title=entity.fields[entity.view.displayField].toDisplay()}} 19if(typeof options.output==='undefined') 20var tab=Container_Manager.addTab({title:title,content:display.element,id:tabId});else{$(options.output).html(display.element);scrollToElement(options.output)}} 21translations=[];translations['de']=[];translations['de']['Delete']='Löschen';translations['de']['New']='Neu';translations['de']['Duplicate']='Duplizieren';translations['de']['Create a copy']='Kopie erstellen';trans=function(word,language){if(typeof language==='undefined')language=APP_LANGUAGE;if(language=='en')return word;
21if(typeof translations[language][word]!=='undefined') 22return translations[language][word];return word} 23makeButton=(type,options_or_display_or_entity)=>{var options=new Object();var display;var entity;if(typeof type=='string'||type instanceof String){if(typeof options_or_display_or_entity!=='undefined'&&options_or_display_or_entity instanceof Display==false&&options_or_display_or_entity instanceof Entity==false){options=options_or_display_or_entity} 24options.type=type} 25else options=type;if(typeof options_or_display_or_entity!=='undefined'){if(options_or_display_or_entity instanceof Display){display=options_or_display_or_entity;entity=display.entity};if(options_or_display_or_entity instanceof Entity)entity=options_or_display_or_entity} 26if(typeof options.display!='undefined'){display=options.display;entity=display.entity};if(typeof options.entity!='undefined'){entity=options.entity};if(typeof options.type!='undefined'){if(typeof options.icon=='undefined')options.icon=options.type} 27if(typeof options.text=='undefined')options.text='';var button;if(typeof options.icon==='string'&&options.icon.substr(0,2)=='&#') 28button=$('<button class="icon" data-icon="'+options.icon+'">'+options.text+'</button>');else button=$('<button class="icon '+options.icon+'">'+options.text+'</button>');if(typeof options.variant==='undefined'){if(typeof display!=='undefined'&&typeof display.displaySet!=='undefined'&&typeof display.displaySet.variant_details!=='undefined') 29options.variant=display.displaySet.variant_details;else if(typeof display!=='undefined'&&typeof display.variants!=='undefined') 30options.variant=display.variant}
31if(options.type=='detail'){if(typeof options.showDetails==='undefined'){options.showDetails=showDetails} 32button.on('click',function(){options.editable=true;options.showDetails(entity,options)})} 33else if(options.type=='delete'){if(isset(options.hint)==false)options.hint='Delete';button.on('click',function(event){event.originalEvent.stopPropagation();entity.trash(true)})}else if(options.type=='duplicate'){if(isset(options.hint)==false)options.hint='Create a copy';button.on('click',function(){var duplicate=entity.clone();var titleField=duplicate.getTitleField();if(titleField!=false)titleField.set('COPY - '+titleField.get('string'),'string');showDetails(duplicate,{editable:true,variant:options.variant,title:duplicate.getTitle()})})} 34else if(options.type=='duplicateWithChildren'){if(isset(options.hint)==false)options.hint='Create a full copy';button.on('click',function(){entity.cloneWithChildren()})} 35if(typeof options.hint!='undefined'){var hint=trans(options.hint) 36button.attr('data-hint',hint);button.attr('title',hint)} 37if(typeof options.click!='undefined'){if(typeof display!='undefined')button.on('click',()=>{options.click(display,button)});else button.on('click',()=>{options.click(button)})} 38if(isset(options.class))button.addClass(options.class);return button};function makeMenuButton(className,onClickFunction){var button=$.parseHTML('<li class="'+className+'"></li>');$(button).on('click',onClickFunction);return button} 39function uniqueId(){function s4(){return Math.floor((1+Math.random())*0x10000).toString(16).substring(1)} 40return s4()+s4()+s4()+s4()+s4()+s4()+s4()+s4()}
41function sortList(list,sortFunction){var mylist=$(list);var listitems=mylist.children('li').get();listitems.sort(sortFunction);$.each(listitems,function(idx,itm){mylist.append(itm)})} 42function getAttributesAsObject(element){var arrAttributes=new Object();$(element).each(function(){$.each(this.attributes,function(){arrAttributes[this.name]=this.value})});return arrAttributes} 43function restoreAttributesFromObject(element,arrAttributes){var currentAttributes=getAttributesAsObject(element);for(var name in currentAttributes){if(isset(arrAttributes[name])==false){element.removeAttr(name)}else if(arrAttributes[name]!=currentAttributes[name]){element.attr(name,arrAttributes[name])}}} 44$.fn.inculcateAttributes=function(){$(this).data('inculcatedAttributes',getAttributesAsObject(this))};$.fn.rememberAttributes=function(){restoreAttributesFromObject(this,$(this).data('inculcatedAttributes'))};function createCookie(name,value,days){return Cookies.create(name,value,days)} 45function readCookie(name,orCreateValue){return Cookies.read(name,orCreateValue)} 46function eraseCookie(name){return Cookies.erase(name)} 47Cookies={create:function(name,value,days){if(days){var date=new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires="; expires="+date.toGMTString()} 48else var expires="";if(typeof value=='string')document.cookie=name+"="+value+expires+"; path=/;";else document.cookie=name+"="+JSON.stringify(value)+expires+"; path=/;"},read:function(name,orReturn){var nameEQ=name+"=";var ca=document.cookie.split(';');for(var i=0;i<ca.length;i++){var c=ca[i];while(c.charAt(0)==' ')c=c.substring(1,c.length);if(c.indexOf(nameEQ)==0){var value=c.substring(nameEQ.length,c.length);if(value=='undefined')return orReturn;if(value.charAt(0)=='{'&&value.charAt(value.length-1)=='}')return JSON.parse(value);else return value}} 49return orReturn},erase:function(name){createCookie(name,"",-1)},addClass:function(classes,selector){if(typeof selector=='undefined')selector='body';
49$(selector).addClass(classes);var div=document.createElement("DIV");var cookieValue=this.read('classes_'+selector,'');$(div).addClass(cookieValue);$(div).addClass(classes);this.create('classes_'+selector,$(div).attr('class'));div.remove()},removeClass:function(classes,selector){if(typeof selector=='undefined')selector='body';$(selector).removeClass(classes);var div=document.createElement("DIV");var cookieValue=this.read('classes_'+selector,'');$(div).addClass(cookieValue);$(div).removeClass(classes);this.create('classes_'+selector,$(div).attr('class'));div.remove()},toggleClass:function(classes,selector){if(typeof selector=='undefined')selector='body';if($(selector).hasClass(classes)) 50this.removeClass(classes,selector);else this.addClass(classes,selector)},addAttribute:function(name,value,selector){if(typeof selector=='undefined')selector='body';$(selector).attr(name,value);var cookieValue=this.read('attributes_'+selector,{});cookieValue[name]=value;this.create('attributes_'+selector,cookieValue)},removeAttribute:function(name,selector){if(typeof selector=='undefined')selector='body';$(selector).removeAttr(name);var cookieValue=this.read('attributes_'+selector,{});delete cookieValue[name];if(Object.keys(cookieValue).length==0) 51this.erase('attributes_'+selector);else this.create('attributes_'+selector,cookieValue)}} 52$(document).on('readyOnce',function(){var body=$('body') 53body.addClass(Cookies.read('classes_body'),'');var bodyAttributes=Cookies.read('attributes_body',{});for(var index in bodyAttributes)body.attr(index,bodyAttributes[index])});function getUrlVariable(variable){var search=window.location.search.substring(1);var params=search.split("&");for(var i=0;i<params.length;i++){var pair=params[i].split("=");if(pair[0]==variable){return pair[1]}} 54return(false)} 55function firstLetterToUppercase(string){return string.charAt(0).toUpperCase()+string.slice(1)} 56$(document).on('ready',function(event){if(TRIGGERED_READY)return;TRIGGERED_READY=true;setTimeout(function(){try{$(document).trigger('readyOnce',event)} 57catch(err){console.log('ERROR: TRIGGER READYONCE');throw(err)} 58TRIGGERED_READYONCE=true;try{$(document).trigger('readyLater',event)} 59catch(err){console.log('ERROR: TRIGGER READYLATER');throw(err)} 60TRIGGERED_READYLATER=true;console.log('TRIGGERED_READYLATER')},2000);$(document).trigger('readyFirst',event);if(User.isAdmin())if(typeof TRIGGERED_BEFOREREADY==='undefined')alert('DESIGN TEMPLATE REQUIRES kickstart_bottom.php')});setTimeout(function(){if(typeof TRIGGERED_BEFOREREADY=='undefined'){console.log('FORCE READY');$(document).trigger("beforeReady");TRIGGERED_BEFOREREADY=true;setTimeout(function(){$(document).trigger('ready')},500)}},3000);$(document).on('readyLater',function(event){setInterval(function(){jQuery(window).trigger('resize').trigger('scroll')},5000)});(function($){jQuery.fn.onEvent=function(){window.jQuery.fn.on.apply(this,arguments);var eventData={owner:this,event:arguments[0],params:arguments};eventData.off=function(){eventData.owner.offEvent(eventData)} 61return eventData};jQuery.fn.onEventAndNow=function(){window.jQuery.fn.on.apply(this,arguments);var eventData={owner:this,event:arguments[0],params:arguments};eventData.off=function(){eventData.owner.offEvent(eventData)} 62arguments[1]();return eventData};jQuery.fn.offEvent=function(eventData){return window.jQuery.fn.off.apply(this,eventData.params)};var originalFunction_html=window.jQuery.fn.html;window.jQuery.fn.html=function(){this.triggerHandler('modifying');var newHTML=originalFunction_html.apply(this,arguments);this.triggerHandler('modified');if(arguments.length)$(arguments).each(function(){$(this).triggerHandler('inserted')});return newHTML};var originalFunction_append=window.jQuery.fn.append;window.jQuery.fn.append=function(){this.triggerHandler('modifying');var newHTML=originalFunction_append.apply(this,arguments);this.triggerHandler('modified',arguments);if(arguments.length)$(arguments).each(function(){try{var x=this;if($(this).css('display')==''){setTimeout(function(){$(x).triggerHandler('inserted')},50)}else{$(x).triggerHandler('inserted')}} 63catch(err){}});return newHTML};var originalFunction_prepend=window.jQuery.fn.prepend;window.jQuery.fn.prepend=function(){this.triggerHandler('modifying');var newHTML=originalFunction_prepend.apply(this,arguments);this.triggerHandler('modified',arguments);if(arguments.length)$(arguments).each(function(){$(this).triggerHandler('inserted')});return newHTML};var originalFunction_after=window.jQuery.fn.after;window.jQuery.fn.after=function(){var parent=$(this).parent();parent.triggerHandler('modifying');var newHTML=originalFunction_after.apply(this,arguments);parent.triggerHandler('modified',arguments);if(arguments.length)$(arguments).each(function(){$(this).triggerHandler('inserted')});return newHTML};var originalFunction_before=window.jQuery.fn.before;window.jQuery.fn.before=function(){var parent=$(this).parent();parent.triggerHandler('modifying');var newHTML=originalFunction_before.apply(this,arguments);parent.triggerHandler('modified',arguments);if(arguments.length)$(arguments).each(function(){$(this).triggerHandler('inserted')});return newHTML};var originalFunction_remove=window.jQuery.fn.remove;window.jQuery.fn.remove=function(){var newHTML=originalFunction_remove.apply(this,arguments);return newHTML}}(jQuery));treatAllElements=function(element,handlerFunction){$(element).find('>*').each(function(){handlerFunction(this)});$(element).on('modified',function(event,newElement){if(typeof newElement!=='undefined'&&newElement.length!==0)handlerFunction(newElement)})} 64$.fn.hasAttr=function(attributeName){return(this.attr(attributeName)!==un
64defined)};$.fn.findWithRoot=function(selector){return this.filter(selector).add(this.find(selector))};$.fn.randomize=function(selector){(selector?this.find(selector):this).parent().each(function(){$(this).children(selector).sort(function(){return Math.random()-0.5}).detach().appendTo(this)});return this};String.prototype.replaceAll=function(search,replacement){var target=this;return target.replace(new RegExp(search.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),'g'),replacement)};benchmark_start=function(){var d=new Date();benchmark_value=d.getTime();console.log('Benchmark start:',benchmark_value)} 65benchmark_stop=function(doAlert){var d=new Date();benchmark_value=d.getTime()-benchmark_value;console.log('Benchmark stop:',d.getTime());console.log('Benchmark result:',benchmark_value);if(doAlert)alert(benchmark_value)} 66provideJSON=function(command,data,callback){var callbackJSON=function(stringData){var entitySets={};try{var dataJSON=JSON.parse(stringData);if(typeof(dataJSON.entitySets)!=='undefined'){for(var index in dataJSON.entitySets){var es=new EntitySet();es.loadFromJSON(dataJSON.entitySets[index]);dataJSON.entitySets[index]=es}} 67if(typeof(dataJSON.script)!=='undefined'){Function('data',dataJSON.script)(dataJSON)} 68if(jQuery.type(callback)==="function")callback(dataJSON)}catch(err){console.log(err);if(jQuery.type(callback)==="function")callback({'json_error':'ERROR',json_text:stringData})}} 69return provide(command,data,callbackJSON)} 70provide=function(command,data,callback){var commandObject;if(jQuery.type(command)==="string"){commandObject={'command':command}}else commandObject=command;if(jQuery.type(commandObject.command)==="string"){if(commandObject.command.indexOf('/')>-1){commandObject.url=commandObject.command}else commandObject.url='provider/plugins/'+commandObject.command+'/'} 71commandObject.success=function(result,textStatus,jqXHR){if(jQuery.type(callback)==="function")callback(result,textStatus,jqXHR)};commandObject.error=function(result,textStatus,jqXHR){if(jQuery.type(callback)==="function")callback(result,textStatus,jqXHR)};if(typeof data!=='undefined'){if(jQuery.type(data)==="string")commandObject.data={'data':data};else commandObject.data=data} 72if(typeof commandObject.method==='undefined'){commandObject.method='POST'} 73console.log(commandObject);return $.ajax(commandObject)};provideEntitySet=function(command,data,callback){var es=new EntitySet();var providerURL='provider/'+command;if(providerURL.slice(-1)!='/')providerURL='/';if(typeof data!='undefined'){var url=new URL(URL_ROOT+providerURL);url.search=new URLSearchParams(data);console.log(url)} 74es.loadFromURL(url.toString(),callback);return es} 75$(document).on('beforeReady',function(){$('[data-provide]').each(function(){var element=$(this);var data=null;if(element.hasAttr('data-provide-data'))data=element.attr('data-provide-data') 76provide(element.attr('data-provide'),data,function(result){element.html(result);element.addClass('enhancement_sub')})})});getSubmitData=function(element){var values={};for(var i=0;i<element.childNodes.length;i++){if(element.childNodes[i].name!=undefined&&element.childNodes[i].name!=""){if(element.childNodes[i].type=="textarea"){var notTinyMCE=true;if(typeof(tinyMCE)!="undefined") 77if(typeof(tinyMCE.get(element.childNodes[i].name))!="undefined"&&tinyMCE.get(element.childNodes[i].name)!==null){values[element.childNodes[i].name]=tinyMCE.get(element.childNodes[i].name).getContent();notTinyMCE=false} 78if(notTinyMCE)values[element.childNodes[i].name]=element.childNodes[i].value} 79else if(element.childNodes[i].type=="checkbox"||element.childNodes[i].type=="radio"){if(element.childNodes[i].checked==true)values[element.childNodes[i].name]=1;else values[element.childNodes[i].name]=0} 80else if(element.childNodes[i].type!="radio"||element.childNodes[i].type!="checkbox"||element.childNodes[i].checked==true){values[element.childNodes[i].name]=element.childNodes[i].value}} 81if(element.childNodes[i].childNodes.length>0){var subArray=getDisplayValuesArray(element.childNodes[i]);for(var index in subArray) 82values[index]=subArray[index]}} 83return values} 84getEntitiesFromElement=(element)=>{var entities={};$(element).findWithRoot('[data-view]').each(function(){var entity=$(this).data('entity');if(entity instanceof Entity){entities[entity.view.name+'_'+entity.getPrimary('string')]=entity}});return entities};getEntity=function(optional){if(typeof optional==='undefined')optional=window.event;if(optional instanceof Entity)return optional;if(optional instanceof Event)optional=$(event.target);if(optional instanceof HTMLElement)optional=$(optional);if(optional instanceof jQuery)if(typeof optional.data('entity')!=='undefined')return optional.data('entity');else{var element=optional.closest('[data-view], [data-template]');if(typeof element.data('entity')!='undefined')return element.data('entity');if(typeof element.data('placeholders')!='undefined'&&typeof element.data('placeholders')['entity']!='undefined')return element.data('placeholders')['entity']} 85return false} 86getDisplay=function(optional){if(typeof optional==='undefined')optional=window.event;if(optional instanceof Event)optional=$(event.target);if(optional instanceof HTMLElement)optional=$(optional);if(optional instanceof jQuery)if(typeof optional.data('display')!=='undefined')return optional.data('display');else return optional.closest('[data-structure="entity"]').data('display')||false;return false} 87class Hireling{task=undefined;outcome=undefined;identifier=undefined;onlyOnce=false;onlyIfFailed=false;supervisor=undefined;info='';dos=0;isDoing=false;isCompleted=false;_stateLast='unset';get stateLast(){if(this.outcome instanceof Job)return this.outcome.stateLast;return this._stateLast} 88set stateLast(state){if(this.outcome instanceof Job)this.outcome.stateLast=state;this._stateLast=state}
89get result(){if(this.outcome instanceof Job)return this.outcome.result;else return this.outcome} 90remove=()=>{this.supervisor.hirelings.splice(this.supervisor.hirelings.indexOf(this),1);this.supervisor.check()} 91do=(input)=>{var hireling=this;hireling.isDoing=true;if(hireling.onlyIfFailed&&hireling.stateLast=='success'){hireling.isCompleted=true;hireling.supervisor.check();return} 92hireling.dos++;if(typeof hireling.task==='function'&&hireling.task instanceof Job==false){try{hireling.outcome=hireling.task(input)}catch(e){hireling.outcome=e;console.error(e)}} 93else hireling.outcome=hireling.task;if(hireling.outcome instanceof Job){var outcome=hireling.outcome;hireling.outcome.do(input);outcome.onDone(()=>{hireling.isCompleted=true;if(outcome.state()=='fail'){hireling.supervisor.errors++;hireling.stateLast='fail'} 94else hireling.stateLast='success';hireling.supervisor.check();if(hireling.onlyOnce)hireling.remove()},true)}else{if(hireling.outcome instanceof Error){hireling.supervisor.errors++;hireling.stateLast='fail'} 95hireling.isCompleted=true;hireling.stateLast='success';hireling.supervisor.check();if(hireling.onlyOnce)hireling.remove()}}} 96class ExtensibleFunction extends Function{constructor(f){return Object.setPrototypeOf(f,new.target.prototype)}} 97class Job extends ExtensibleFunction{ready=0;errors=0;dos=0;dosMax=-1;hirelings=new Array();result=undefined;await=false;isDoing=false;isCompleted=false;sequential=false;resetWhenDone=false;input=undefined;stateSelf='unset';stateLast='unset';jobFunctionType='do';info='';self=this;constructor(initialState){super((jobInput,onlyOnce,onlyIfFailed)=>{if(this.jobFunctionType=='do')return this.doSuccess(jobInput);else{if(typeof onlyOnce==='undefined')onlyOnce=false;if(typeof onlyIfFailed==='undefined')onlyIfFailed=false;return this.hire(jobInput,onlyOnce,onlyIfFailed)}});EventMaker(this);if(this.jobFunctionType=='on')alert(onlyOnce);if(initialState=='await')this.await=true;else if(typeof initialState!=='undefined'){if(initialState=='success')this.doSuccess();else this.doFail()} 98return this};get isAvailable(){return this.isCompleted==true||this.isDoing==false} 99get total(){return Object.keys(this.hirelings).length} 100state=()=>{if(this.errors>0||this.stateSelf=='fail')return'fail';if(this.stateSelf=='success')return'success';return'unset'} 101reset=()=>{if(this.isAvailable==false)return false;if(this.isDoing==false&&this.isCompleted==false)return false;this.isDoing=false;this.isCompleted=false;this.stateSelf='unset';this.input=undefined;this.ready=0;this.errors=0;if(this.jobs('success',false))this.jobs('success').reset();if(this.jobs('fail',false))this.jobs('fail').reset();if(this.jobs('done',false))this.jobs('done').reset();for(var index in this.hirelings){this.hirelings[index].isDoing=false;this.hirelings[index].isCompleted=false;if(this.hirelings[index].onlyOnce==true){}else{if(this.hirelings[index].task instanceof Job){this.hirelings[index].task.reset()} 102this.hirelings[index].outcome=undefined}}} 103hire=(funct,onlyOnce,onlyIfFailed,identifier)=>{if(typeof onlyOnce==='undefined')onlyOnce=false;if(typeof onlyIfFailed==='undefined')onlyIfFailed=false;this.stateLast='unset';var hireling=new Hireling();hireling.task=funct;hireling.onlyOnce=onlyOnce;hireling.onlyIfFailed=onlyIfFailed;hireling.identifier=identifier;hireling.supervisor=this;this.hirelings.push(hireling);this.trigger('hire',hireling);if(this.isDoing){if(this.isCompleted||this.sequential==false){hireling.do(this.input);if(hireling.onlyOnce==true){hireling.remove()}}} 104return hireling} 105doIfFailed=(input,triggerSuccessAgain)=>{if(this.isAvailable==false)return this;if(this.stateLast=='success'){if(triggerSuccessAgain==true){if(this.jobs('success',false))this.jobs('success').do(this.input);else this.jobs.promisedDo['success']=this.input} 106return this} 107return this.do(input)} 108do=(input)=>{if(this.isAvailable==false){this.check();if(this.isAvailable==true&&User.isAdmin()){console.log('-----');console.log(this.isDoing);console.log(this.isCompleted);console.log(this.info);console.log(this.await);console.log(this.ready);console.log(this.total);console.log('-----');alert('ADMIN: check was not triggered '+this.info)} 109if(this.isAvailable==false)return this} 110this.reset();if(this.dosMax>0&&this.dos>=this.dosMax){this.stateSelf='fail';this.isCompleted=true;if(this.jobs('fail',false))this.jobs('fail').do(this);return this} 111var job=this;if(window.debugging==true){setTimeout(function(){if(job.isCompleted==false)console.log('... checking Job - UNFINISHED!',job)},6000)} 112this.dos++;this.isDoing=true;this.input=input;this.doNextHireling(input);return this}
113doNextHireling=(input)=>{if(this.total==0){this.check();return false} 114for(var index in this.hirelings){if(this.hirelings[index].isDoing==false){this.hirelings[index].do(input);if(this.sequential)break}} 115return false} 116doSuccess=(input)=>{this.stateSelf='success';if(this.isAvailable==true)return this.do(input);this.check();return this} 117doFail=(input)=>{this.stateSelf='fail';if(this.isAvailable==true)return this.do(input);this.check();return this} 118onSuccess=(funct,onlyOnce)=>{var name='success';return this.jobs(name,true).hire(funct,onlyOnce)} 119onFail=(funct,onlyOnce)=>{var name='fail';return this.jobs(name,true).hire(funct,onlyOnce)} 120onDone=(funct,onlyOnce)=>{var name='done';return this.jobs(name,true).hire(funct,onlyOnce)} 121onAvailable=(funct)=>{if(this.isDoing==false||this.isCompleted) 122return funct();var name='done';console.log(this.isDoing,this.isCompleted,this.total);return this.jobs(name,true).hire(funct,true)} 123check=()=>{if(this.isCompleted==false){var nextHirelingInSequence=false;var stillExecuting=false;this.ready=0;for(var index in this.hirelings){if(this.hirelings[index].isCompleted)this.ready++;if(this.hirelings[index].isDoing&&this.hirelings[index].isCompleted==false){stillExecuting=true} 124if(this.hirelings[index].isDoing==false&&this.hirelings[index].isCompleted==false){if(nextHirelingInSequence==null)nextHirelingInSequence=this.hirelings[index].isDoing}} 125if(this.isDoing){if(this.ready==this.total||(this.sequential&&this.state()=='fail')){var waiting=false;if(this.state()=='fail'){this.stateLast='fail';this.isCompleted=true;if(this.jobs('fail',false))this.jobs('fail').do(this.input);else this.jobs.promisedDo['fail']=this.input} 126else{if(this.stateSelf=='success'||this.await!=true){this.stateLast='success';this.isCompleted=true;if(this.jobs('success',false))this.jobs('success').do(this.input);else this.jobs.promisedDo['success']=this.input}else waiting=true} 127if(waiting==false){if(this.jobs('done',false))this.jobs('done').do(this.input);else this.jobs.promisedDo['done']=this.input}} 128else{if(stillExecuting==false||this.sequential==false)this.doNextHireling(this.input)}}}} 129hireEvent=(eventJob,onlyOnce,onlyIfFailed)=>{eventJob.onSuccess(this,onlyOnce,onlyIfFailed);this.hire(eventJob,false,true)} 130debug=()=>{var txt='INFO: '+this.info+"\n";txt+='isCompleted: '+this.isCompleted+"\n";txt+='isDoing: '+this.isDoing+"\n";txt+='state: '+this.state()+' stateSelf='+this.stateSelf+"\n";txt+='stateLast: '+this.stateLast+"\n";txt+='dos: '+this.dos+"\n";txt+='sequential: '+this.sequential+"\n";txt+='total='+this.total+' ready='+this.ready+"\n";for(var index in this.hirelings){var info=this.hirelings[index].task.info||'';txt+='-- hireling['+index+'] '+info+' isCompleted='+this.hirelings[index].isCompleted+' isDoing= '+this.hirelings[index].isDoing+"\n"} 131window.debugJob=this;console.log(txt);console.log(this);return txt}} 132j=new Job('await');j.info=' j ';f=new Job();f.info=' f ';f.hire(()=>{alert('doing f')});f.hire(new Job());j.on('success',function(){alert('!! j success')});func=()=>{var tim=new Job('await');tim.info='tim';setTimeout(function(){tim.doFail();console.log('tim FAIL')},5000);return tim} 133funcSuccess=()=>{var tim=new Job('await');tim.info='tim';setTimeout(function(){tim.doSuccess();console.log('tim SUCCESS');console.log('total',j.total);console.log('ready',j.ready)},1000);return tim} 134j.sequential=true;alertSuccess=function(){alert('success')};alertFail=function(){alert('fail')};e={} 135EventMaker(e,'test');e.jobs.test.onSuccess(alertSuccess);e.jobs.test.onFail(alertFail);function Test(){var n=new Job().do;n.x='y';return n} 136function EventMaker(object,propertyName,element){if(typeof object==='undefined')object={};if(typeof object.jobs==='undefined'){if(typeof object.on!=='undefined')throw('EventMaker: Property "on" already exists.');if(typeof object.trigger!=='undefined')throw('EventMaker: Property "trigger" already exists.');if(typeof object.jobs!=='undefined')throw('EventMaker: Property "events" already exists.');object.jobs=(name,create)=>{if(typeof create==='undefined')create=true;if(typeof object.jobs[name]!=='undefined')return object.jobs[name];
136if(create){var job=new Job();job.info=name;object.jobs[name]=job;if(object.jobs.promisedDo.hasOwnProperty(name)){job.do(object.jobs.promisedDo[name]);delete object.jobs.promisedDo[name]};return job} 137return false} 138object.jobs.promisedDo={};object.on=function(name,funct,onlyOnce,onlyIfFailed){var job=object.jobs(name,true);return job.hire(funct,onlyOnce,onlyIfFailed)} 139object.trigger=function(name,input){var job=object.jobs(name);job.doSuccess(input);return job}} 140if(typeof propertyName!=='undefined'){var capitalName=propertyName[0].toUpperCase()+propertyName.substring(1);var job=object.jobs(propertyName);var jobBefore=job.jobs('before');var jobSuccess=job.jobs('success');var jobFail=job.jobs('fail');var jobDone=job.jobs('done');object[propertyName]=job;job['onBefore']=jobBefore;jobBefore.jobFunctionType='on';job['onSuccess']=jobSuccess;jobSuccess.jobFunctionType='on';job['onFail']=jobFail;jobFail.jobFunctionType='on';job['onDone']=jobDone;jobDone.jobFunctionType='on';object['on'+capitalName]=job.hire;job.sequential=true;job.hire(jobBefore).info='before';if(typeof element!=='undefined'){var loop=false;$(element).on(propertyName,()=>{if(loop==false){loop=true;var handlerObject={data:{},object:object,element:element,job:object[propertyName],jobName:propertyName};object[propertyName](handlerObject);loop=false}});object['on'+capitalName](()=>{if(loop==false){loop=true;$(element).triggerHandler(propertyName);loop=false}})}} 141return object} 142App={version:3.6,ready:EventMaker(),initialize:EventMaker(),urlParams:Object.fromEntries(new URLSearchParams(window.location.search).entries())};if(typeof URL_PARAMS!=='undefined'){for(var index in URL_PARAMS){App.urlParams['param_'+index]=URL_PARAMS[index]}} 143EventMaker(App);$(document).on('readyOnce',App.trigger('readyOnce'));$(document).on('readyLater',App.trigger('readyLater'));var PLACEHOLDERS=new Job();$(document).on('readyOnce',function(){PLACEHOLDERS.doSuccess().onDone(()=>{replacePlaceholders($('#content'),PLACEHOLDERS.hirelings)})});getPlaceholders=function(optional){if(typeof optional==='undefined')optional=window.event;if(optional instanceof Event)optional=$(event.target);if(optional instanceof HTMLElement)optional=$(optional);if(optional instanceof jQuery)return optional.closest('[data-template]').data('placeholders')||false;if(optional instanceof Event==false&&(optional instanceof Object||optional instanceof Array))return optional;return false} 144replacePlaceholders=function(html,placeholdersOrHirelings){var placeholders=[];for(var index in placeholdersOrHirelings){if(placeholdersOrHirelings[index]instanceof Hireling){if(typeof placeholdersOrHirelings[index].identifier=='undefined') 145placeholders[index]=placeholdersOrHirelings[index].result;else placeholders[placeholdersOrHirelings[index].identifier]=placeholdersOrHirelings[index].result} 146else placeholders[index]=placeholdersOrHirelings[index]} 147if(html instanceof jQuery==false)html=$(html);html.removeAttr('data-template-editor');for(var entityName in placeholders){var entity=placeholders[entityName];if(entity){var replaceFields=[];console.log('entity');console.log(entityName);console.log(placeholders);for(var index in entity.fields){replaceFields['###'+entityName+'_'+index+'###']=entity.fields[index].getForWeb()} 148for(var index in replaceFields){var re=new RegExp(index,'g');html.html(html.html().replace(re,replaceFields[index]))}}} 149html.data('placeholders',placeholders);html.findWithRoot('[data-placeholder]').each(function(){var display=$(this);var entity=placeholders[display.attr('data-placeholder')];if(display.attr('data-placeholder')=='')entity=placeholders['entity'];if(typeof entity==='undefined'||(display.hasAttr('data-field')&&typeof entity.fields[display.attr('data-field')]==='undefined')){}else{if(display.hasAttr('data-field')){if(display.hasAttr('data-default')&&entity.isNew==true)entity.set(display.attr('data-field'),display.attr('data-default'),'string');entity.fields[display.attr('data-field')].toDisplay(display);if(display.hasClass('editable')){if(typeof displayToAdminFieldEditor!=='undefined'){displayToAdminFieldEditor(display)}}}else{display.data('entity',entity)} 150if(display.hasAttr('data-label-auto')&&display.attr('data-label-auto')!='false'){addFieldLabel(display)}}});html.findWithRoot('[data-placeholder-attr]').each(function(){var element=$(this);var attributes=element.attr('data-placeholder-attr');attributes=attributes.split(' ');for(var index in attributes){var attribute=attributes[index];if(attribute.startsWith('###')&&attribute.endsWith('###')){for(var entityName in placeholders){var entity=placeholders[entityName];for(var fieldName in entity.fields){if(attribute=='###'+entityName+'_'+fieldName+'###'){}}}} 151else{}}});html.findWithRoot('[data-placeholder-attr]').each(function(){var attrContainer=$(this);var target=attrContainer.prevAll(':not([data-placeholder-attr])').first();console.log('t',target);$(target).attr('xx','yyy');if(attrContainer.attr('data-placeholder-attr')!=''){if(attrContainer.attr('data-placeholder-attr')=='data-icon')target.attr(attrContainer.attr('data-placeholder-attr'),decodeHtmlEntities(attrContainer.text()));else target.attr(attrContainer.attr('data-placeholder-attr'),attrContainer.text())}
152$(attrContainer.find('[data-placeholder][data-field]').data('field')).on('changed',function(){if(attrContainer.attr('data-placeholder-attr')!='')target.attr(attrContainer.attr('data-placeholder-attr'),attrContainer.text())})});html.findWithRoot('.btnInfo').on('click',function(){UI.showMessage($(this).attr('data-info'))});initializeModules(html);html.findWithRoot('.gallery').each(function(){UI.gallery({element:this,gallery_id:convertValue($(this).attr('data-gallery-id'),'binary','string')})});return html} 153Templates={};Templates.data={};EventMaker(Templates,'ready');Templates.load=function(url,callback){var job=new Job('await');if(url.indexOf('app_version')===-1){if(url.indexOf('?')===-1)url+='?app_version='+APP_VERSION;else url+='&app_version='+APP_VERSION} 154jQuery.get(url,function(data){$(data).findWithRoot('[data-template]').each(function(){Templates.data[$(this).attr('data-template')]=this.outerHTML});if(typeof callback==='function')callback();job.doSuccess();Templates.ready()}).error(function(){job.doFail();Templates.ready.doFail()});return job} 155Templates.get=function(name,placeholders){$(document).triggerHandler(name+'_onReplacePlaceholders',{name:name,placeholders:placeholders});var html=$(Templates.data[name]);replacePlaceholders(html,placeholders);$(document).triggerHandler(name+'_afterReplacePlaceholders',{name:name,placeholders:placeholders,element:html});return html} 156window.addEventListener("click",function(event){var element=$(event.target).closest('[data-a]');if(element.length>0){action(element.attr('data-a'),element);event.preventDefault();event.cancelBubble=true;return false}},true);function action(command,html){if(html instanceof jQuery&&html.length==0)return;if(typeof html==='undefined')html=window.event.target;var element=$(html);if(typeof command==='undefined')command=element.attr('data-a');var target=getActionTarget(element);var actionJob=new Job();var actionData={};actionData.element=element;actionData.command=command;actionData.target=target;actionData.handled=false;actionData.job=actionJob;$(document).triggerHandler('action',actionData);if(actionData.handled)return actionData.job;if(command=='close'){$(target).triggerHandler('close')} 157else if(command=='toggle-class'){console.log(target);target.toggleClass(element.attr('data-a-toggle-class'))} 158else if(command=='toggle'){if(target.hasClass('selected'))action('deselect',target);else action('select',target)} 159else if(command=='selection'){var content=makeRelationPanel(element);content.addClass('messagePanel');var dialog=UI.dialog({content:content,closeOnEscape:true,classes:'',scroller:'bg',classes:'message',buttons:[{title:'Abbrechen',type:'cancel'}]});var entity=getEntity(element);var field=element.data('field');if(typeof field=='string')field=entity.fields[field];$(field).on('changed',element,function(event){dialog.close()})} 160else if(command=='select'){if(target.hasAttr('data-a-owner')==false){action('select',getActionOwner(target));return} 161if(target.hasClass('selected'))return;var owner=getActionOwner(target);if(owner.attr('data-a-owner')=='single')action('deselect',owner);target.addClass('selected');target.find('[data-a="select"]:not(.selected), [data-a="toggle"]:not(.selected), [data-l="select"]:not(.selected)').each(function(){$(this).addClass('selected');$(this).triggerHandler('select')});$(target).triggerHandler('select')} 162else if(command=='deselect'){if(target.hasAttr('data-a-owner')==false){action('deselect',getActionOwner(target));return} 163target.removeClass('selected');target.find('.selected').each(function(){$(this).removeClass('selected');$(this).triggerHandler('deselect')})} 164else if(command=='new'){var results=target.findWithRoot('[data-structure="set"]');var ds=results.data('displaySet');var display=ds.addBlankDisplay();return display} 165else if(command=='new-details'){var results=target.findWithRoot('[data-structure="set"]');var ds=results.data('displaySet');var display=ds.addBlankDisplay();var variant=undefined;console.log(element);console.log(ds.element);if(element.hasAttr('data-variant'))variant=element.attr('data-variant');else if(target.hasAttr('data-variant'))variant=target.attr('data-variant');else if(ds.element.hasAttr('data-variant-details'))variant=ds.element.attr('data-variant-details');
165showDetails(display.entity,{editable:true,variant:variant,title:display.entity.getTitleField().toDisplay()});return display} 166else if(command=='delete'){var entity=getEntity(element);UI.showMessage('Möchten Sie den Eintrag wirklich löschen?','Hinweis',function(result){if(result=='Ja')entity.delete()},['Ja','Nein'])} 167else if(command=='duplicate'){var entity=getEntity(element);var variant=undefined;if(target.hasAttr('data-variant')){variant=target.attr('data-variant')};var duplicate=entity.clone();var titleField=duplicate.getTitleField();if(titleField!=false)titleField.set('COPY - '+titleField.get('string'),'string');showDetails(duplicate,{editable:true,variant:variant,title:duplicate.getTitle()})} 168else if(command=='details'){var entity=getEntity(element);var options={};options.title=entity.getTitle();options.editable=true;if(element.hasAttr('data-variant')){options.variant=element.attr('data-variant')} 169else if(target.hasAttr('data-variant')){options.variant=target.attr('data-variant')};if(element.hasAttr('data-a-output')){options.output=element.attr('data-a-output')} 170else if(target.hasAttr('data-a-output')){options.output=target.attr('data-a-output')};showDetails(entity,options)} 171else if(command=='restore-all'){var entities=getEntitiesFromElement(target);for(var index in entities){(function(){var entity=entities[index];if(entity.isNew){entity.delete()}else{if(entity.trash())entity.trash(false);if(entity.status()!=STATUS_UNCHANGED)entity.restore()}})()}} 172else if(command=='store'||command=='store-all'||command=='store-partial'){if(target[0]==element[0])target=element.closest('[data-view]');console.log(target);var isValid=validateForm(target);if(isValid||command=='store-partial'){var entities=getEntitiesFromElement(target);console.log(entities);var saveJobs=actionJob;saveJobs.info='saveJobs';for(var index in entities){(function(){var entity=entities[index];if(entity.status()!=STATUS_UNCHANGED||entity.trash){saveJobs.hire(entity.store())}})()};return saveJobs.do()}} 173else if(command=='set-now'){var entity=getEntity(element);if(element.hasAttr('data-a-set-field')){entity.set(element.attr('data-a-set-field'),new Date())}} 174else if(command=='submit'){console.log(target);var valid=validateForm(target);if(valid==false&&target.hasAttr('data-on-invalid')) 175Function(target.attr('data-on-invalid'))();if(valid==false)return new Job('fail');var data={};target.find('input[name]').each(function(){data[$(this).attr('name')]=this.value});console.log(data);target.findWithRoot('[data-template]').each(function(){var name=$(this).attr('data-template');App.trigger('validate_'+name,{element:this})});if(target.hasAttr('data-provider')){provideJSON(target.attr('data-provider'),data,function(result){if(result.success==true&&target.hasAttr('data-on-success')) 176Function(target.attr('data-on-success'))(result);if(result.success==false&&target.hasAttr('data-on-fail')) 177Function(target.attr('data-on-fail'))(result);if(target.hasAttr('data-on-done')) 178Function(target.attr('data-on-done'))(result)}) 179return};console.log(target);console.log(element);var entities=getEntitiesFromElement(target);var saveJobs=actionJob;saveJobs.info='saveJobs';if(target.hasAttr('data-on-success'))saveJobs.on('success',()=>{Function(target.attr('data-on-success')+'()')()},true);if(target.hasAttr('data-on-fail'))saveJobs.on('fail',()=>{Function(target.attr('data-on-fail')+'()')()},true);for(var index in entities){(function(){var entity=entities[index];if(entity.status()!=STATUS_UNCHANGED||entity.isNew){saveJobs.hire(entity.store,true)}})()};console.log(entities);console.log(saveJobs);x=saveJobs;saveJobs.doSuccess();return saveJobs} 180else if(command=='select-from'){var field=element.data('field');var relationView='locations_types';var content=$('<div></div>');var dsSelect=new DisplaySet({query:new Query('VIEW '+relationView+' ORDER BY position'),each:function(display){console.log(display);$(display.element).on('click',function(){dialog.close();field.set(display.entity.getPrimary('string'),'string')})},callback:function(){content.append(dsSelect.element)}}) 181var dialog=UI.dialog({content:content,buttons:[{title:'Abbrechen',type:'cancel'}]})} 182else if(command=='print'){printElement(target)} 183else if(command=='excel'){console.log(target);var results=target.findWithRoot('[data-structure="set"]');var ds=results.data('displaySet');
183ds.entitySet.downloadExcel()} 184else if(command=='to-x'){x=getEntity();console.log(target);console.log(element.closest('[data-view]'));console.log(element);console.log(x)}} 185function getActionOwner(html){var element=$(html);return element.parent().closest('[data-a-owner]')} 186function getActionTarget(html){var element=$(html);var target=element;if(typeof element.data('target')!='undefined')target=$(element.data('target'));else if(element.hasAttr('data-a-target')){var targetString=element.attr('data-a-target');if(targetString=='parent')target=element.parent();else target=$(targetString)} 187else if(element.hasAttr('data-a-parent')){if(element.attr('data-a-parent')!='') 188target=element.closest(element.attr('data-a-parent'));else target=element.parent(element.attr('data-a-parent'))} 189else{var controller=element.closest('.controller, [data-a-owner]');if(controller.length>0)target=controller} 190while(target[0]!=element[0]){element=target;if(target.hasAttr('[data-a-owner]'))return target;target=getActionTarget(target)} 191return $(target)} 192function Autosave(optionsOrEntity){if(this instanceof Window){if(typeof autosave==='undefined')autosave=new Autosave(optionsOrEntity);if(optionsOrEntity instanceof Entity)autosave.add(optionsOrEntity);return autosave} 193var self=this;if(typeof optionsOrEntity==='undefined')optionsOrEntity={};this.interval=optionsOrEntity.interval||5000;this.entities=[];this.halted=false;this.add=function(entity){if(this.entities.indexOf(entity)===-1)this.entities.push(entity)} 194this.remove=function(entity){var position=this.entities.indexOf(entity);if(position<0)return false;this.entities.splice(position,1);return true} 195this.addView=function(viewOrName){var viewName=viewOrName;if(viewOrName instanceof View)viewName=viewOrName.name();$(document).on('entityReady_'+viewName,function(event,entity){self.add(entity)})} 196this.checkSave=function(){if(self.halted)return;$.each(self.entities,function(key,entity){if(entity.status()==STATUS_CHANGED||(entity.trash()&&entity.status()!=STATUS_DELETED))entity.store()});self.start()} 197this.start=function(){self.halted=false;setTimeout(function(){self.checkSave()},self.interval)} 198self.stop=function(){this.halted=true} 199if(optionsOrEntity instanceof Entity)this.add(optionsOrEntity);self.start();return this} 200printElement=function(element){window.scrollTo(0,0);if($(element)[0]==document.body){$(element).addClass('printContent');print();$(element).removeClass('printContent');return} 201$('body').addClass('printing');var clone=$(element).clone();clone.addClass('printContent');$('body').append(clone);var height=clone.outerHeight();clone.css('padding','40px');clone.css('font-size','13px');setTimeout(function(){window.print();clone.remove();$('body').removeClass('printing')},1500)} 202now=function(){return new DateTime()}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.