adhara
Version:
foundation for any kind of website: microframework
1 lines • 205 kB
JavaScript
"use strict";var _AdharaListView$DEFAU,_set=function set(object,property,value,receiver){var desc=Object.getOwnPropertyDescriptor(object,property);if(void 0===desc){var parent=Object.getPrototypeOf(object);null!==parent&&set(parent,property,value,receiver)}else if("value"in desc&&desc.writable)desc.value=value;else{var setter=desc.set;void 0!==setter&&setter.call(receiver,value)}return value},_get=function get(object,property,receiver){null===object&&(object=Function.prototype);var desc=Object.getOwnPropertyDescriptor(object,property);if(void 0===desc){var parent=Object.getPrototypeOf(object);return null===parent?void 0:get(parent,property,receiver)}if("value"in desc)return desc.value;var getter=desc.get;return void 0!==getter?getter.call(receiver):void 0},_slicedToArray=function(){return function(arr,i){if(Array.isArray(arr))return arr;if(Symbol.iterator in Object(arr))return function(arr,i){var _arr=[],_n=!0,_d=!1,_e=void 0;try{for(var _s,_i=arr[Symbol.iterator]();!(_n=(_s=_i.next()).done)&&(_arr.push(_s.value),!i||_arr.length!==i);_n=!0);}catch(err){_d=!0,_e=err}finally{try{!_n&&_i.return&&_i.return()}finally{if(_d)throw _e}}return _arr}(arr,i);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}();function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++)arr2[i]=arr[i];return arr2}return Array.from(arr)}var _marked=regeneratorRuntime.mark(range);function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}function _asyncToGenerator(fn){return function(){var gen=fn.apply(this,arguments);return new Promise(function(resolve,reject){return function step(key,arg){try{var info=gen[key](arg),value=info.value}catch(error){return void reject(error)}if(!info.done)return Promise.resolve(value).then(function(value){step("next",value)},function(err){step("throw",err)});resolve(value)}("next")})}}function _possibleConstructorReturn(self,call){if(!self)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!call||"object"!=typeof call&&"function"!=typeof call?self:call}function _inherits(subClass,superClass){if("function"!=typeof superClass&&null!==superClass)throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}var TemplateEngineHelpers=function(){function TemplateEngineHelpers(){_classCallCheck(this,TemplateEngineHelpers)}return _createClass(TemplateEngineHelpers,null,[{key:"getHelpers",value:function(currentHelpers){var if_helper=currentHelpers.if;return{addAttr:function(attributes,default_attributes){if(attributes||default_attributes){var attrData=[];default_attributes=default_attributes&&"string"==typeof default_attributes?JSON.parse(default_attributes):{};var class_names=attributes&&(attributes.className||attributes.class)||"";return class_names+=default_attributes.hasOwnProperty("class")?" "+default_attributes.class:"",attributes=Object.assign(default_attributes,attributes),class_names&&(attributes.class=class_names),loop(attributes,function(key,value){if(key&&void 0!==value){if("style"===key){var css_values=[];loop(value,function(css_prop,css_value){css_values.push(css_prop+":"+css_value+";")}),value=css_values.join("")}"string"==typeof value&&(value='"'+value.replace(/"/g,'\\"')+'"'),attrData.push(key+"="+value)}}),new window.Handlebars.SafeString(attrData.join(" "))}},addProps:function(){var properties=Array.prototype.slice.call(arguments);return properties.splice(0,properties.length-1).join(" ")},selectedClass:function(selected,selectedClassName){return!0===selected?selectedClassName:""},include:function(template_name,context){return new window.Handlebars.SafeString(TemplateUtils.execute(template_name,context))},math:function(param1,operation,param2){var lvalue=parseFloat(String(param1)),rvalue=parseFloat(String(param2));return{"+":lvalue+rvalue,"-":lvalue-rvalue,"*":lvalue*rvalue,"/":lvalue/rvalue,"%":lvalue%rvalue}[operation]},i18n:function(i18nKey){var subs=Array.prototype.slice.call(arguments);return subs=subs.splice(1,subs.length-2),Adhara.i18n.get(i18nKey,subs)},get:function(object,path){return getValueFromJSON(object,path)},if:function(param1,operator,param2,options){return"object"===(void 0===operator?"undefined":_typeof(operator))?if_helper.call(this,param1,operator):evaluateLogic(param1,operator,param2)?options.fn(this):options.inverse(this)},mIf:function(){for(var arr=[!0,"and",!0],args_len=arguments.length-1,options=arguments[args_len],i=0;i<args_len;i++)0===i?arr[0]=arguments[i]:i%2==1?arr[1]=arguments[i]:(arr[2]=arguments[i],arr[0]=evaluateLogic(arr[0],arr[1],arr[2]));return arr[0]?options.fn(this):options.inverse(this)},eIf:function(param1,operator,param2){return evaluateLogic(param1,operator,param2)},global:function(global_letiable){return 0===global_letiable.indexOf("Adhara.")?getValueFromJSON(Adhara,global_letiable.substring("Adhara.".length)):getValueFromJSON(window,global_letiable)},loop:function(looper,options){for(var structure="",i=0;i<looper.length;i++)structure+=options.fn(looper[i]);return structure},append:function(){var args=Array.prototype.slice.call(arguments);return args.pop(),args.map(function(arg){return"object"===(void 0===arg?"undefined":_typeof(arg))?JSON.stringify(arg):arg}).join("")},make_json:function(str){return JSON.parse(str)},make_context:function(){for(var context={},i=0;i<arguments.length-1;i+=2)context[arguments[i]]=arguments[i+1];return context},fn_call:function(fn){return call_fn.apply(this,Array.prototype.slice.call(arguments).slice(0,-1))},loopObject:function(looper,options){var structure="";return loop(looper,function(key,value){structure+=options.fn({key:key,value:value})}),structure},iterate_range:function(start,step,end,options){for(var str_buf="",i=start;i<=end;i+=step)str_buf+=options.fn(i);return str_buf},route:function(url){return new Handlebars.SafeString('href="'+Adhara.router.transformURL(url)+'" route')}}}},{key:"registerHelpers",value:function(){window.Handlebars.registerHelper(TemplateEngineHelpers.getHelpers(window.Handlebars.helpers))}}]),TemplateEngineHelpers}(),TAB=9,ENTER=13,UP_ARROW=38,DOWN_ARROW=40,BACKSPACE=8,ESCAPE=27,SHIFT=16,SPACE=32;function handleForm(form){if(!form.submitting){form.submitting=!0;var apiData=void 0;if(!!form.querySelector('input[type="file"]'))apiData=new FormData(form);else{var formData=jQuery(form).serializeArray();apiData={},jQuery.each(formData,function(i,fieldData){apiData[fieldData.name]=fieldData.value})}var format_fn=form.getAttribute("format-data");format_fn&&(apiData=call_fn(format_fn,apiData)),!1!==apiData&&RestAPI[form.getAttribute("api-method")]({url:form.action.split(window.location.host)[1],data:apiData,successMessage:form.getAttribute("success-message"),handleError:"false"!==form.getAttribute("handle-error"),success:function(data){"true"===form.getAttribute("form-clear")&&form.reset(),jQuery(form).trigger("success",data)},failure:function(message){jQuery(form).trigger("failure",message)}})}}function registerAdharaUtils(){Adhara.templateEngine.helpersHandler.registerHelpers(),jQuery(document).on("submit","form.api-form",function(event){event.preventDefault(),handleForm(this)}),jQuery(document).on("success","form.dialog-form",function(){this.close.click()})}function evaluateLogic(param1,operator,param2){return"in"===operator?param2&&-1!==param2.indexOf(param1):"not_in"===operator?param2&&-1===param2.indexOf(param1):"contains"===operator?param1&&-1!==param1.indexOf(param2):"not_contains"===operator?param1&&-1===param1.indexOf(param2):"has"===operator?param1&¶m1.hasOwnProperty(param2):{"||":param1||param2,"&&":param1&¶m2,"|":param1|param2,"&":param1¶m2,"==":param1==param2,"===":param1===param2,"!=":param1!=param2,"!==":param1!==param2,">":param1>param2,"<":param1<param2,">=":param1>=param2,"<=":param1<=param2,equals:param1==param2,and:param1&¶m2,or:param1||param2}[operator]}function getValueFromJSON(object,path,identifier){try{if(!path)return object;for(var keys=path.split("."),i=0;i<keys.length;i++){var key_in=keys[i];if(-1!==key_in.indexOf("[")){var arr=key_in.split("["),arrName=arr[0],index=arr[1].split("]")[0];if(isNaN(index)){for(var rite=object[arrName],separator=index.substring(identifier.length,index.length),formattedVal="",j=0;j<rite.length;j++)j>0&&(formattedVal+=separator),formattedVal+=getValueFromJSON(rite[j],path.split(".").splice(i+1).join("."),identifier);object=formattedVal}else object=object[arrName][index];break}object=object[key_in]}return object}catch(e){return}}function setValueToJson(object,path,value){var keys=path.split(".");loop(keys,function(i,key){i+1<keys.length?(object.hasOwnProperty(key)&&object[key]&&"object"===_typeof(object[key])||(object[key]={}),object=object[key]):object[key]=value})}function call_fn(fn){if(fn){var args=Array.prototype.slice.call(arguments);if(args.splice(0,1),"function"==typeof fn)return fn.apply(fn,args);try{if((fn=getValueFromJSON(window,fn))&&fn!==window)return fn.apply(window[fn],args)}catch(e){throw"TypeError"===e.name&&-1!==e.message.indexOf("is not a function")?new Error("error executing function : "+fn):e}}}function call_fn_or_def(fn){var args=Array.prototype.slice.call(arguments),def_fn=args.pop();return"function"!=typeof def_fn&&"function"!=typeof window[def_fn]&&(args.push(def_fn),def_fn=void 0),fn?call_fn.apply(call_fn,args):def_fn?(args[0]=def_fn,call_fn.apply(call_fn,args)):void 0}function loop(object,cbk,reverseIterate){var i=void 0,loop_size=void 0;if(object instanceof Array)if(loop_size=object.length,reverseIterate)for(i=loop_size-1;i>=0&&!1!==cbk(i,object[i]);i--);else for(i=0;i<loop_size&&!1!==cbk(i,object[i]);i++);else{var keys=Object.keys(object);for(loop_size=keys.length,i=0;i<loop_size&&!1!==cbk(keys[i],object[keys[i]]);i++);}}var TemplateUtils={};!function(){var preCompiledCache={};TemplateUtils.execute=function(template_or_template_string,context,cache){var template=window.Handlebars.templates[template_or_template_string];return!template&&window.Handlebars.hasOwnProperty("compile")&&(!1!==cache?(template=preCompiledCache[template_or_template_string])||(template=preCompiledCache[template_or_template_string]=window.Handlebars.compile(template_or_template_string)):template=window.Handlebars.compile(template_or_template_string)),template(context)}}();var Internationalize=function(){function Internationalize(key_map){_classCallCheck(this,Internationalize),this.key_map=key_map}return _createClass(Internationalize,[{key:"getValue",value:function(key,subs,default_value){if(key){var value=this.key_map[key];if(void 0===value&&(value=getValueFromJSON(this.key_map,key)),void 0===value)return default_value;subs=subs||[];for(var placeholders=value.match(/{[0-9]+}/g)||[],i=0;i<placeholders.length;i++){var sub=subs[i]||"";try{-1!==sub.indexOf(".")&&(sub=this.get(sub))}catch(e){}value=value.replace(new RegExp("\\{"+i+"\\}","g"),sub)}return value.trim()}}},{key:"get",value:function(key,subs){var default_value=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return"string"==typeof subs&&(default_value=subs),this.getValue(key,subs,default_value||key)}}]),Internationalize}();function MutateViews(baseClass){for(var _len=arguments.length,mixins=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++)mixins[_key-1]=arguments[_key];function copyProps(target,source){Object.getOwnPropertyNames(source).concat(Object.getOwnPropertySymbols(source)).forEach(function(prop){prop.match(/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length|context)$/)||Object.defineProperty(target,prop,Object.getOwnPropertyDescriptor(source,prop))})}var base=function(_baseClass){function base(){for(var _ref,_len2=arguments.length,args=Array(_len2),_key2=0;_key2<_len2;_key2++)args[_key2]=arguments[_key2];_classCallCheck(this,base);var _this=_possibleConstructorReturn(this,(_ref=base.__proto__||Object.getPrototypeOf(base)).call.apply(_ref,[this].concat(args)));return mixins.forEach(function(mixin){copyProps(_this,new(Function.prototype.bind.apply(mixin,[null].concat(args))))}),_this}return _inherits(base,baseClass),base}();return mixins.forEach(function(mixin){copyProps(base.prototype,mixin.prototype),copyProps(base,mixin)}),base}function cloneObject(obj){var clone=obj instanceof Array?[]:{};for(var i in obj)null==obj[i]||"object"!==_typeof(obj[i])||"Object"!==obj[i].constructor.name&&"Array"!==obj[i].constructor.name?clone[i]=obj[i]:clone[i]=cloneObject(obj[i]);return clone}var Time=function(){function Time(){_classCallCheck(this,Time)}return _createClass(Time,null,[{key:"sleep",value:function(){var _ref2=_asyncToGenerator(regeneratorRuntime.mark(function _callee(millis){return regeneratorRuntime.wrap(function(_context){for(;;)switch(_context.prev=_context.next){case 0:return _context.abrupt("return",new Promise(function(resolve,reject){setTimeout(resolve,millis)}));case 1:case"end":return _context.stop()}},_callee,this)}));return function(_x2){return _ref2.apply(this,arguments)}}()}]),Time}(),AdharaTicker=function(){function AdharaTicker(interval,exponential_factor,min_interval){_classCallCheck(this,AdharaTicker),this.interval=0===interval?interval:interval||2e3,this.exponential_factor=exponential_factor||1,this.min_interval=min_interval||0,this.initial_interval=interval,this.timeoutId=null}return _createClass(AdharaTicker,[{key:"scheduleNextTick",value:function(){var _this2=this;this.pause(),this.interval<=this.min_interval||(this.timeoutId=window.setTimeout(function(){_this2.onExecute()},this.interval))}},{key:"next",value:function(){this.scheduleNextTick()}},{key:"onExecute",value:function(){this.interval*=this.exponential_factor,this.on_execute(this.next)}},{key:"start",value:function(execute){this.on_execute=execute,this.scheduleNextTick()}},{key:"pause",value:function(){window.clearTimeout(this.timeoutId)}},{key:"resume",value:function(){this.scheduleNextTick()}},{key:"stop",value:function(){this.pause(),this.interval=this.initial_interval}},{key:"restart",value:function(){this.stop(),this.scheduleNextTick()}}]),AdharaTicker}(),CoalesceTasker=function(){function CoalesceTasker(){var wait_for=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;_classCallCheck(this,CoalesceTasker),this.wait_for=wait_for,this.timer_idx=0}return _createClass(CoalesceTasker,[{key:"execute",value:function(){var _ref3=_asyncToGenerator(regeneratorRuntime.mark(function _callee2(executor,terminator){var _this3=this;return regeneratorRuntime.wrap(function(_context2){for(;;)switch(_context2.prev=_context2.next){case 0:return this.terminator&&this.terminator(),this.executor=executor,this.terminator=terminator,clearTimeout(this.timer_idx),_context2.abrupt("return",new Promise(function(resolve,reject){_this3.timer_idx=setTimeout(function(){_this3.executor(),resolve()},_this3.wait_for)}));case 5:case"end":return _context2.stop()}},_callee2,this)}));return function(_x4,_x5){return _ref3.apply(this,arguments)}}()}]),CoalesceTasker}(),AdharaRouter=null;!function(){var registeredUrlPatterns={},baseURI="",defaultTitle=document.title,appName="",queryParams={},pathParams={},historyStack=[],currentUrl=void 0,currentRoute=void 0,listeners={},middlewares=[];function getFullUrl(){return window.location.href}function getPathName(){return AdharaRouter.transformURL(window.location.pathname)}function getFullPath(){return getPathName()+window.location.search+window.location.hash}function getSearchString(){return window.location.search.substring(1)}function isCurrentPath(new_path){function stripSlash(path){return 0===path.indexOf("/")?path.substring(1):path}return stripSlash(getFullPath())===stripSlash(new_path)}function matchUrl(){var path=getPathName(),matchFound=!1;for(var regex in registeredUrlPatterns)if(registeredUrlPatterns.hasOwnProperty(regex)&&!matchFound){var formed_regex=new RegExp(regex);if(formed_regex.test(path)){matchFound=!0;var opts=registeredUrlPatterns[regex];return{opts:opts,path:path,params:formed_regex.exec(path),meta:opts.meta}}}}function matchAndCall(){var _this4=this,matchOptions=matchUrl();if(matchOptions){var opts=matchOptions.opts,path=matchOptions.path,params=matchOptions.params,meta=matchOptions.meta;if(params.splice(0,1),opts&&opts.fn){var _pathParams={},_iteratorNormalCompletion=!0,_didIteratorError=!1,_iteratorError=void 0;try{for(var _step,_iterator=params.entries()[Symbol.iterator]();!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=!0){var _ref4=_step.value,_ref5=_slicedToArray(_ref4,2),index=_ref5[0],param=_ref5[1];_pathParams[opts.path_param_keys[index]]=param}}catch(err){_didIteratorError=!0,_iteratorError=err}finally{try{!_iteratorNormalCompletion&&_iterator.return&&_iterator.return()}finally{if(_didIteratorError)throw _iteratorError}}currentRoute=opts,pathParams=_pathParams,currentUrl=getFullUrl(),fetchQueryParams(),function(params,proceed){var i=0;!function _proceed(){var middleware_fn=middlewares[i++];middleware_fn?call_fn(middleware_fn,params,_proceed):proceed()}()}({view_name:opts.view_name,path:path,query_params:_getQueryParams(),path_params:_pathParams},function(){params.push(queryParams),document.title=[appName||defaultTitle,meta.title].filter(function(_){return _}).join(" | "),opts.fn.constructor instanceof AdharaView.constructor?Adhara.onRoute(opts.fn,params):opts.fn.apply(_this4,params)})}}return!!matchOptions}var curr_path=void 0;function updateHistoryStack(){curr_path&&historyStack.push(curr_path),curr_path=getFullPath()}var settingURL=!1;function _getQueryParams(){var qp={};return getSearchString()?loop(getSearchString().split("&"),function(i,paramPair){paramPair=paramPair.split("="),qp[decodeURIComponent(paramPair[0])]=decodeURIComponent(paramPair[1])}):qp={},qp}function fetchQueryParams(){queryParams=_getQueryParams()}function generateCurrentUrl(){var url=getPathName(),params=[];return loop(queryParams,function(key,value){params.push(encodeURIComponent(key)+"="+encodeURIComponent(value))}),params.length&&(url+="?"+params.join("&")),url}function _route(route_type,route_options){route_type&&route_type!==AdharaRouter.RouteTypes.SET?route_type===AdharaRouter.RouteTypes.NAVIGATE?AdharaRouter.navigateTo(generateCurrentUrl(),route_options&&route_options.force||!1):route_type===AdharaRouter.RouteTypes.OVERRIDE?AdharaRouter.overrideURL(generateCurrentUrl()):route_type===AdharaRouter.RouteTypes.UPDATE&&AdharaRouter.updateURL(generateCurrentUrl()):AdharaRouter.setURL(generateCurrentUrl())}var STATE_KEY="__adhara_router__",Router=function(){function Router(){_classCallCheck(this,Router)}return _createClass(Router,null,[{key:"transformURL",value:function(url){return url.startsWith(baseURI)?url:baseURI+url}},{key:"register_one",value:function(pattern,view_name,fn,meta){for(var path_param_keys=[],regex=/{{([a-zA-Z$_][a-zA-Z0-9$_]*)}}/g,match=regex.exec(pattern);null!=match;)path_param_keys.push(match[1]),match=regex.exec(pattern);pattern=pattern.replace(new RegExp("\\{\\{[a-zA-Z$_][a-zA-Z0-9$_]*\\}\\}","g"),""),pattern=(pattern="^"+this.transformURL(pattern.substring(1))).replace(/[?]/g,"\\?"),meta=meta||{},registeredUrlPatterns[pattern]={view_name:view_name,fn:fn,path_param_keys:path_param_keys,meta:meta}}},{key:"deRegister",value:function(regex){registeredUrlPatterns[regex]=void 0}},{key:"register",value:function(list){var _iteratorNormalCompletion2=!0,_didIteratorError2=!1,_iteratorError2=void 0;try{for(var _step2,_iterator2=list[Symbol.iterator]();!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=!0){var conf=_step2.value;this.register_one(conf.url,conf.view_name,conf.view,conf.meta)}}catch(err){_didIteratorError2=!0,_iteratorError2=err}finally{try{!_iteratorNormalCompletion2&&_iterator2.return&&_iterator2.return()}finally{if(_didIteratorError2)throw _iteratorError2}}}},{key:"configure",value:function(router_configuration){if(router_configuration.base_uri&&(baseURI=router_configuration.base_uri),router_configuration.app_name&&(appName=router_configuration.app_name),router_configuration.routes&&Router.register(router_configuration.routes),router_configuration.on_route_listeners)for(var listener_name in router_configuration.on_route_listeners)router_configuration.on_route_listeners.hasOwnProperty(listener_name)&&Router.onRoute(listener_name,router_configuration.on_route_listeners[listener_name]);if(router_configuration.middlewares){var _iteratorNormalCompletion3=!0,_didIteratorError3=!1,_iteratorError3=void 0;try{for(var _step3,_iterator3=router_configuration.middlewares[Symbol.iterator]();!(_iteratorNormalCompletion3=(_step3=_iterator3.next()).done);_iteratorNormalCompletion3=!0){var middleware_fn=_step3.value;Router.registerMiddleware(middleware_fn)}}catch(err){_didIteratorError3=!0,_iteratorError3=err}finally{try{!_iteratorNormalCompletion3&&_iterator3.return&&_iterator3.return()}finally{if(_didIteratorError3)throw _iteratorError3}}}}},{key:"onRoute",value:function(listener_name,listener_fn){listeners[listener_name]=listener_fn}},{key:"offRouteListener",value:function(listener_name){listeners[listener_name]=void 0}},{key:"registerMiddleware",value:function(middleware_fn){"function"==typeof middleware_fn&&middlewares.push(middleware_fn)}},{key:"route",value:function(){if(settingURL)settingURL=!1;else if(!matchAndCall())throw new Error("No route registered for this url : "+getPathName());loop(listeners,function(listener_name,listener_fn){call_fn(listener_fn)})}},{key:"getCurrentRoute",value:function(){return currentRoute||(currentRoute=matchUrl().opts),currentRoute}},{key:"getCurrentPageName",value:function(){return AdharaRouter.getCurrentRoute().view_name}},{key:"getCurrentURL",value:function(){return getFullPath()}},{key:"getCurrentPath",value:function(){return getPathName()}},{key:"getCurrentHash",value:function(){return window.location.hash.substring(1)}},{key:"go",value:function(url){if(isCurrentPath(url))return!1;history.pushState(_defineProperty({},STATE_KEY,!0),parent.document.title,url);var state=history.state;return updateHistoryStack(),pathParams={},void 0!==state&&""!==state&&(!0!==state[STATE_KEY]&&!0!==state.data[STATE_KEY]||this.route()),!0}},{key:"setURL",value:function(url){url=this.transformURL(url),settingURL=!0,this.go(url)||(settingURL=!1)}},{key:"overrideURL",value:function(url){url=this.transformURL(url),history.replaceState(_defineProperty({},STATE_KEY,!0),parent.document.title,url)}},{key:"updateURL",value:function(url){settingURL=!0,this.overrideURL(url)}},{key:"navigateTo",value:function(url,force){isCurrentPath(url=this.transformURL(url))?force&&this.route():this.go(url)&&fetchQueryParams()}},{key:"goBack",value:function(backwardURL){if(!backwardURL&&!(backwardURL=historyStack.slice(-1)[0]))return!1;backwardURL=this.transformURL(backwardURL);var backwardIndex=historyStack.lastIndexOf(backwardURL);if(-1===backwardIndex)this.navigateTo(backwardURL);else{var stackLen=historyStack.length,negativeIndex=backwardIndex-stackLen;historyStack.splice(stackLen+negativeIndex,-negativeIndex),history.go(negativeIndex)}}},{key:"peekStack",value:function(){return historyStack.slice()}},{key:"getQueryParam",value:function(param_name){return getFullUrl()!==currentUrl&&(currentUrl=getFullUrl(),fetchQueryParams()),queryParams[param_name]}},{key:"getQueryParams",value:function(){return _getQueryParams()}},{key:"getPathParam",value:function(param_name){return pathParams[param_name]}},{key:"updateQueryParams",value:function(new_params,drop_existing,route_type,route_options){route_type||(route_type=this.RouteTypes.NAVIGATE),drop_existing?queryParams=new_params:Object.assign(queryParams,new_params),_route(route_type,route_options)}},{key:"removeQueryParams",value:function(param_keys,route_type,route_options){loop(param_keys,function(idx,key){delete queryParams[key]}),_route(route_type,route_options)}},{key:"getURLPatternByPageName",value:function(view_name){var matched_pattern=null;return loop(registeredUrlPatterns,function(pattern,options){if(options.view_name===view_name)return matched_pattern=pattern,!1}),matched_pattern}}]),Router}();AdharaRouter=Router,window.onpopstate=function(e){AdharaRouter.route()},AdharaRouter.RouteTypes=Object.freeze({NAVIGATE:"navigate",OVERRIDE:"override",SET:"set",UPDATE:"update"}),AdharaRouter.enableAllAnchors=!0,AdharaRouter.listen=function(){function hasAttribute(elem,attribute_name){return elem.hasAttribute(attribute_name)}function routeHandler(event){var re=function(event){return"A"!==event.target.nodeName?event.currentTarget:event.target}(event);if((AdharaRouter.enableAllAnchors||hasAttribute(re,"route"))&&hasAttribute(re,"href")&&!hasAttribute(re,"skiprouting")){var target=this.getAttribute("target"),miniURL=this.getAttribute("href").trim(),isHash=0===miniURL.indexOf("#");if(target&&"_self"!==target||-1!==miniURL.indexOf("javascript")||isHash)return;var url=miniURL;try{if(new URL(url).host!==window.location.host)return}catch(e){}if(this.getAttribute("data-back"))AdharaRouter.goBack(url);else{var force="false"!==this.getAttribute("data-force");AdharaRouter.navigateTo(url,force)}url&&(event.preventDefault(),event.stopPropagation())}}jQuery(document).on("click","a",routeHandler),jQuery(document).on("click","[route]",routeHandler)},updateHistoryStack()}();var Toast={make:function(title,content,type){return Adhara.app?Adhara.app.toast(title,content,type):window.ToastHandler?window.ToastHandler[type](content,title):void console.log("No toast handler found. Toast message: type-"+type+", title-"+title+", content="+content)},error:function(message){return Toast.make("Error!",message,"error")},success:function(message){return Toast.make("Success",message,"success")}},AdharaDefaultToaster={};function range(start,stop){var i,_i,step=arguments.length>2&&void 0!==arguments[2]?arguments[2]:1;return regeneratorRuntime.wrap(function(_context3){for(;;)switch(_context3.prev=_context3.next){case 0:if(!(step>=0)){_context3.next=10;break}i=start;case 2:if(!(i+step<=stop)){_context3.next=8;break}return _context3.next=5,i;case 5:i+=step,_context3.next=2;break;case 8:_context3.next=17;break;case 10:_i=start;case 11:if(!(_i+step>=stop)){_context3.next=17;break}return _context3.next=14,_i;case 14:_i+=step,_context3.next=11;break;case 17:case"end":return _context3.stop()}},_marked,this)}function deserialize(str,context){if("object"===(void 0===context?"undefined":_typeof(context))&&context.blob){var _data=JSON.parse(str);return new context.blob(_data)}if(context){var _data2=JSON.parse(str);return new context.blob(_data2)}throw new Error("context passed is invalid: "+context)}function isPrimitive(ob){return ob!==Object(ob)}!function(){var notifyQueue=0;AdharaDefaultToaster.make=function(title,content,type){var maxNotificationsHeight=window.innerHeight-200,currentNotificationsHeight=0;jQuery.each(jQuery(".notification"),function(){currentNotificationsHeight+=jQuery(this).height()+40});var proceed=currentNotificationsHeight<maxNotificationsHeight,notifyTimeout=0===notifyQueue?0:2e3;content||"failure"!==type||(content="Error occurred...");var nid=performance.now();return setTimeout(function(){0===notifyQueue&&proceed?(notifyQueue++,function(title,content,type,id){id="notification_"+id;var $notificationDiv=jQuery('<div class="notification '+type+'" id="'+id+'"/>'),$title=jQuery('<strong style="display:block" />').text(title),$content=jQuery("<p />").html(content);$notificationDiv.append($title).append($content),jQuery("body").append($notificationDiv);var existing_notifications=jQuery(".notification");existing_notifications.length>0&&jQuery.each(existing_notifications,function(index,value){if(jQuery(this).attr("id")!==id){var new_top=parseFloat(jQuery(this).css("top"))+$notificationDiv.height()+40;jQuery(this).animate({top:new_top+"px"},"fast")}}),jQuery("#"+id).animate({right:"0px"},"fast",function(){notifyQueue--}),setTimeout(function(){jQuery("#"+id).animate({opacity:"0.5"},"fast",function(){jQuery("#"+id).hide("slide",{direction:"right"},"slow",function(){setTimeout(function(){jQuery("#"+id).remove()},1e3)})})},5e3)}(title,content,type,nid)):AdharaDefaultToaster.make(title,content,type)},notifyTimeout),{remove:function(){jQuery("#notification_"+nid).remove()}}}}();var Serializable=function(){function Serializable(data){if(_classCallCheck(this,Serializable),!Serializable._validateData(data))throw new Error("blob must be initialized with serializable(tree-like, non-array) object: "+data)}return _createClass(Serializable,null,[{key:"_validateData",value:function(data){if(isPrimitive(data))return!0;if("object"!==(void 0===data?"undefined":_typeof(data))||null===data||data instanceof Array)return!0;var eq_success=function equivalence(ob1,ob2){if(isPrimitive(ob1)&&isPrimitive(ob2))return ob1===ob2;if(isPrimitive(ob1)!==isPrimitive(ob2))return!1;for(var key in ob1)if(ob1.hasOwnProperty(key)&&!equivalence(ob1[key],ob2[key]))return!1;return!0}(JSON.parse(JSON.stringify(data)),data);return eq_success||console.warn("Equivalence check failed for the data. Data is not serializable.",data),eq_success}}]),_createClass(Serializable,[{key:"serialize",value:function(){throw new Error("Need to define method: serialize")}}]),Serializable}(),DataBlob=function(_Serializable){function DataBlob(data){_classCallCheck(this,DataBlob);var _this5=_possibleConstructorReturn(this,(DataBlob.__proto__||Object.getPrototypeOf(DataBlob)).call(this,data));if(!data)return _possibleConstructorReturn(_this5);if(_this5._data=data,!1===_this5.validate(data))throw new Error("assigned data does not clear the custom validation: "+data);return _this5.onInit(),_this5}return _inherits(DataBlob,Serializable),_createClass(DataBlob,[{key:"onInit",value:function(){}},{key:"validate",value:function(){return!0}},{key:"_formatTimeBit",value:function(value){return(1===value.toString().length?"0":"")+value.toString()}},{key:"_formatTime",value:function(date){return this._formatTimeBit(date.getHours())+":"+this._formatTimeBit(date.getMinutes())+":"+this._formatTimeBit(date.getSeconds())}},{key:"_formatDate",value:function(date){return this._formatTimeBit(date.getMonth()+1)+"/"+this._formatTimeBit(date.getDate())+"/"+date.getFullYear()}},{key:"data",get:function(){return this._data},set:function(data){if(!Serializable._validateData(data))throw new Error("blob must represent a non-array, tree-like object "+data);if(!1===this.validate(data))throw new Error("assigned data does not clear the custom validation: "+data);this._data=data}},{key:"packet",get:function(){return this.serialize()}}],[{key:"_context",get:function(){return"base"}}]),DataBlob}(),NetworkMethods={GET:"get",POST:"post",PUT:"put",DELETE:"delete",PATCH:"patch"},NetworkProvider=function(){function NetworkProvider(){_classCallCheck(this,NetworkProvider)}return _createClass(NetworkProvider,[{key:"formatResponse",value:function(data){return data}},{key:"getCookie",value:function(cookie_name){var cookieValue=null;if(document.cookie&&""!==document.cookie)for(var cookies=document.cookie.split(";"),i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,cookie_name.length+1)===cookie_name+"="){cookieValue=decodeURIComponent(cookie.substring(cookie_name.length+1));break}}return cookieValue}},{key:"isFullURL",value:function(link){return link.startsWith("http://")||link.startsWith("https://")||link.startsWith("//")}},{key:"formatURL",value:function(url){if(this.isFullURL(url))return url;var baseURL=this.baseURL;return baseURL.endsWith("/")&&(baseURL=baseURL.substr(0,baseURL.length-1)),url.startsWith("/")&&(url=url.substr(1)),baseURL+"/"+url}},{key:"_handleSE",value:function(xhr,success_fn,error_fn){xhr.status>=400?(0===xhr.readyState&&0===xhr.status&&""===error_fn.err&&(error_fn.err="Unable to connect to server"),error_fn(xhr,error_fn.err||"error",xhr.responseText)):success_fn(xhr.responseText,"success",xhr)}},{key:"ajax",value:function(o){"get"!==o.method&&o.data instanceof Object&&(Object.keys(o.data).length?o.data=JSON.stringify(o.data):delete o.data),"get"!==o.method&&"delete"!==o.method&&(o.headers["Content-Type"]="application/json"),jQuery.ajax(o)}},{key:"multipart",value:function(o){var xhr=new XMLHttpRequest;xhr.open(o.method.toUpperCase(),o.url),delete o.headers["Content-Type"],loop(o.headers,function(header,value){xhr.setRequestHeader(header,value)}),xhr.onreadystatechange=function(){xhr.readyState===XMLHttpRequest.DONE&&(xhr.status>=400?o.error(xhr,"error",xhr.responseText):o.success(xhr.responseText,"success",xhr))},xhr.send(o.data)}},{key:"send",value:function(){var _ref6=_asyncToGenerator(regeneratorRuntime.mark(function _callee3(o){var _this6=this;return regeneratorRuntime.wrap(function(_context4){for(;;)switch(_context4.prev=_context4.next){case 0:return _context4.abrupt("return",new Promise(function(resolve,reject){o.success=function(d,s,x){_this6._handleSE(x,function(){return resolve([d,x])},function(){return reject([d,x])})},o.error=function(x,s,e){var err_fn=function(){return reject([e,x])};err_fn.err=e,_this6._handleSE(x,null,err_fn)},o.data instanceof FormData?_this6.multipart(o):_this6.ajax(o)}));case 1:case"end":return _context4.stop()}},_callee3,this)}));return function(_x7){return _ref6.apply(this,arguments)}}()},{key:"preFlightIntercept",value:function(method,url,data){}},{key:"_preFlightIntercept",value:function(method,url,data){this.preFlightIntercept(method,url,data)}},{key:"postResponseIntercept",value:function(method,url,data,response,xhr){}},{key:"_postResponseIntercept",value:function(method,url,data,response,xhr){this.postResponseIntercept(method,url,data,response,xhr)}},{key:"postErrorResponseIntercept",value:function(method,url,data,response,xhr){}},{key:"_postErrorResponseIntercept",value:function(method,url,data,response,xhr){this.postErrorResponseIntercept(method,url,data,response,xhr)}},{key:"_send",value:function(){var _ref7=_asyncToGenerator(regeneratorRuntime.mark(function _callee4(method,url,data,options){var _ref8,_ref9,r,x;return regeneratorRuntime.wrap(function(_context5){for(;;)switch(_context5.prev=_context5.next){case 0:return url=this.formatURL(url),this._preFlightIntercept(method,url,null),_context5.prev=2,_context5.next=5,this.send(Object.assign({url:url,headers:this.headers,method:method,data:data},options));case 5:return _ref8=_context5.sent,_ref9=_slicedToArray(_ref8,2),r=_ref9[0],x=_ref9[1],this._postResponseIntercept(method,url,null,r,x),_context5.abrupt("return",this.formatResponse(r));case 13:throw _context5.prev=13,_context5.t0=_context5.catch(2),console.log("API errored out::",_context5.t0),this._postErrorResponseIntercept(method,url,data,_context5.t0[0],_context5.t0[1]),_context5.t0[0];case 18:case"end":return _context5.stop()}},_callee4,this,[[2,13]])}));return function(_x8,_x9,_x10,_x11){return _ref7.apply(this,arguments)}}()},{key:"get",value:function(){var _ref10=_asyncToGenerator(regeneratorRuntime.mark(function _callee5(url,data,options){return regeneratorRuntime.wrap(function(_context6){for(;;)switch(_context6.prev=_context6.next){case 0:return data&&"object"===(void 0===data?"undefined":_typeof(data))&&(data=Object.entries(data).map(function(_ref11){var _ref12=_slicedToArray(_ref11,2);return _ref12[0]+"="+_ref12[1]}).join("&")),_context6.next=3,this._send(NetworkMethods.GET,url,data,options);case 3:return _context6.abrupt("return",_context6.sent);case 4:case"end":return _context6.stop()}},_callee5,this)}));return function(_x12,_x13,_x14){return _ref10.apply(this,arguments)}}()},{key:"post",value:function(){var _ref13=_asyncToGenerator(regeneratorRuntime.mark(function _callee6(url,data,options){return regeneratorRuntime.wrap(function(_context7){for(;;)switch(_context7.prev=_context7.next){case 0:return _context7.next=2,this._send(NetworkMethods.POST,url,data,options);case 2:return _context7.abrupt("return",_context7.sent);case 3:case"end":return _context7.stop()}},_callee6,this)}));return function(_x15,_x16,_x17){return _ref13.apply(this,arguments)}}()},{key:"put",value:function(){var _ref14=_asyncToGenerator(regeneratorRuntime.mark(function _callee7(url,data,options){return regeneratorRuntime.wrap(function(_context8){for(;;)switch(_context8.prev=_context8.next){case 0:return _context8.next=2,this._send(NetworkMethods.PUT,url,data,options);case 2:return _context8.abrupt("return",_context8.sent);case 3:case"end":return _context8.stop()}},_callee7,this)}));return function(_x18,_x19,_x20){return _ref14.apply(this,arguments)}}()},{key:"patch",value:function(){var _ref15=_asyncToGenerator(regeneratorRuntime.mark(function _callee8(url,data,options){return regeneratorRuntime.wrap(function(_context9){for(;;)switch(_context9.prev=_context9.next){case 0:return _context9.next=2,this._send(NetworkMethods.PATCH,url,data,options);case 2:return _context9.abrupt("return",_context9.sent);case 3:case"end":return _context9.stop()}},_callee8,this)}));return function(_x21,_x22,_x23){return _ref15.apply(this,arguments)}}()},{key:"delete",value:function(){var _ref16=_asyncToGenerator(regeneratorRuntime.mark(function _callee9(url,data,options){return regeneratorRuntime.wrap(function(_context10){for(;;)switch(_context10.prev=_context10.next){case 0:return _context10.next=2,this._send(NetworkMethods.DELETE,url,data,options);case 2:return _context10.abrupt("return",_context10.sent);case 3:case"end":return _context10.stop()}},_callee9,this)}));return function(_x24,_x25,_x26){return _ref16.apply(this,arguments)}}()},{key:"baseURL",get:function(){return"/"}},{key:"headers",get:function(){return{"Content-Type":"application/json"}}}]),NetworkProvider}(),DataInterface=function DataInterface(network){_classCallCheck(this,DataInterface),this.network=network||new NetworkProvider},Context=function(){function Context(key,view){_classCallCheck(this,Context),this.key=key,this.view=view}return _createClass(Context,[{key:"removeFromParent",value:function(){this.parentContext.childContexts.splice(this.parentContext.childContexts.indexOf(this),1)}},{key:"getViewFromRenderTree",value:function(classRef,instanceKey){return this.searchViewInCurrentTreeAndUp(classRef,instanceKey)||this.searchViewInWholeTree(classRef,instanceKey)}},{key:"checkKey",value:function(contextKey,instanceKey){return!instanceKey||contextKey===instanceKey}},{key:"searchViewInCurrentTreeAndUp",value:function(classRef,instanceKey){return classRef===Adhara.container.constructor?Adhara.container:this.view!==Adhara.container?this.parentContext.view.constructor===classRef&&this.checkKey(this.parentContext.key,instanceKey)?this.parentContext.view:this.parentContext.getViewFromRenderTree(classRef,instanceKey):void 0}},{key:"searchViewInWholeTree",value:function(classRef,instanceKey){return this.searchViewInCurrentTreeAndUp(Adhara.container.constructor).context.searchChildren(classRef,instanceKey)}},{key:"searchChildren",value:function(classRef,instanceKey){var _iteratorNormalCompletion4=!0,_didIteratorError4=!1,_iteratorError4=void 0;try{for(var _step4,_iterator4=this.childContexts[Symbol.iterator]();!(_iteratorNormalCompletion4=(_step4=_iterator4.next()).done);_iteratorNormalCompletion4=!0){var context=_step4.value;if(context.view.constructor===classRef&&this.checkKey(context.key,instanceKey))return context.view}}catch(err){_didIteratorError4=!0,_iteratorError4=err}finally{try{!_iteratorNormalCompletion4&&_iterator4.return&&_iterator4.return()}finally{if(_didIteratorError4)throw _iteratorError4}}var _iteratorNormalCompletion5=!0,_didIteratorError5=!1,_iteratorError5=void 0;try{for(var _step5,_iterator5=this.childContexts[Symbol.iterator]();!(_iteratorNormalCompletion5=(_step5=_iterator5.next()).done);_iteratorNormalCompletion5=!0){var matchedView=_step5.value.searchChildren(classRef,instanceKey);if(matchedView)return matchedView}}catch(err){_didIteratorError5=!0,_iteratorError5=err}finally{try{!_iteratorNormalCompletion5&&_iterator5.return&&_iterator5.return()}finally{if(_didIteratorError5)throw _iteratorError5}}}},{key:"parentContext",set:function(parent_context){this._parentContext=parent_context,this._parentContext.childContext=this},get:function(){return this._parentContext||Adhara.container.context}},{key:"childContext",set:function(child_context){this._childContexts||(this._childContexts=[]),this._childContexts.push(child_context)}},{key:"childContexts",get:function(){return this._childContexts||[]}}]),Context}(),AdharaEventHandler=function(){function AdharaEventHandler(){_classCallCheck(this,AdharaEventHandler),this._event_listeners={},this._registerEvents(this.events)}return _createClass(AdharaEventHandler,[{key:"_registerEvents",value:function(event_names){var _this7=this,_loop=function(event_name){_this7._event_listeners[event_name]=[],_this7["on"+event_name]=function(handler){_this7._event_listeners[event_name].push(handler)},_this7["off"+event_name]=function(handler){_this7._event_listeners[event_name].splice(_this7._event_listeners[event_name].indexOf(handler),1)}},_iteratorNormalCompletion6=!0,_didIteratorError6=!1,_iteratorError6=void 0;try{for(var _step6,_iterator6=event_names[Symbol.iterator]();!(_iteratorNormalCompletion6=(_step6=_iterator6.next()).done);_iteratorNormalCompletion6=!0){_loop(_step6.value)}}catch(err){_didIteratorError6=!0,_iteratorError6=err}finally{try{!_iteratorNormalCompletion6&&_iterator6.return&&_iterator6.return()}finally{if(_didIteratorError6)throw _iteratorError6}}}},{key:"trigger",value:function(event_name){for(var _len3=arguments.length,data=Array(_len3>1?_len3-1:0),_key3=1;_key3<_len3;_key3++)data[_key3-1]=arguments[_key3];var _iteratorNormalCompletion7=!0,_didIteratorError7=!1,_iteratorError7=void 0;try{for(var _step7,_iterator7=this._event_listeners[event_name][Symbol.iterator]();!(_iteratorNormalCompletion7=(_step7=_iterator7.next()).done);_iteratorNormalCompletion7=!0){var event_handler=_step7.value;event_handler.apply(event_handler,data)}}catch(err){_didIteratorError7=!0,_iteratorError7=err}finally{try{!_iteratorNormalCompletion7&&_iterator7.return&&_iterator7.return()}finally{if(_didIteratorError7)throw _iteratorError7}}}},{key:"events",get:function(){return[]}}]),AdharaEventHandler}(),AdharaView=function(_AdharaEventHandler){function AdharaView(){var settings=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};_classCallCheck(this,AdharaView);var _this8=_possibleConstructorReturn(this,(AdharaView.__proto__||Object.getPrototypeOf(AdharaView)).call(this));_this8.settings=settings,_this8.settings.options||(_this8.settings.options={});var _this8$settings=_this8.settings,key=_this8$settings.key,c=_this8$settings.c;return _this8.ts="d"+performance.now().toString().replace(".","-"),_this8.context=new Context(key||_this8.ts,_this8),_this8._parentContainer=c,Adhara.addViewToInstances(_this8),_this8.is_active=!1,_this8._registerEvents(["ViewRendered","SubViewsRendered","ViewFormatted","ViewDestroyed"]),_this8.fetching_data=!1,_this8.onInit(),_this8._subViews=[],_this8.rendered_subviews=[],_this8.rendered=!1,_this8.initialized=!0,_this8.error=null,_this8}return _inherits(AdharaView,AdharaEventHandler),_createClass(AdharaView,[{key:"onInit",value:function(){}},{key:"getCustomTemplate",value:function(type){var _iteratorNormalCompletion8=!0,_didIteratorError8=!1,_iteratorError8=void 0;try{for(var _step8,_iterator8=Adhara.viewHierarchy[Symbol.iterator]();!(_iteratorNormalCompletion8=(_step8=_iterator8.next()).done);_iteratorNormalCompletion8=!0){var ViewClass=_step8.value;if(ViewClass.isPrototypeOf(this.constructor)&&Adhara.app.customViewConfig[type]&&Adhara.app.customViewConfig[type][ViewClass.name])return Adhara.app.customViewConfig[type][ViewClass.name]}}catch(err){_didIteratorError8=!0,_iteratorError8=err}finally{try{!_iteratorNormalCompletion8&&_iterator8.return&&_iterator8.return()}finally{if(_didIteratorError8)throw _iteratorError8}}}},{key:"getTemplate",value:function(){return this.fetching_data?this.fetchingDataTemplate:this.error&&this.errorTemplate||this.template}},{key:"isActive",value:function(){return Adhara.isActiveView(this)&&this.is_active}},{key:"create",value:function(parentViewInstance){var _this9=this;Adhara.addToActiveViews(this),this.parentViewInstance=parentViewInstance,this.is_active=!0,this.fetch().then(function(){_this9.render()}),this.render()}},{key:"fetch",value:function(){var _ref17=_asyncToGenerator(regeneratorRuntime.mark(function _callee10(){return regeneratorRuntime.wrap(function(_context12){for(;;)switch(_context12.prev=_context12.next){case 0:return this.fetching_data=!0,_context12.next=3,this.fetchData();case 3:this.fetching_data=!1;case 4:case"end":return _context12.stop()}},_callee10,this)}));return function(){return _ref17.apply(this,arguments)}}()},{key:"fetchData",value:function(){var _ref18=_asyncToGenerator(regeneratorRuntime.mark(function _callee11(){return regeneratorRuntime.wrap(function(_context13){for(;;)switch(_context13.prev=_context13.next){case 0:case"end":return _context13.stop()}},_callee11,this)}));return function(){return _ref18.apply(this,arguments)}}()},{key:"_getHTML",value:function(template){return Adhara.app.renderTemplate(template||this.getTemplate(),this)}},{key:"getParentContainerElement",value:function(){return document.querySelector(this.parentContainer)}},{key:"querySelector",value:function(css_selector){return this.getParentContainerElement().querySelector(css_selector)}},{key:"querySelectorAll",value:function(css_selector){return this.getParentContainerElement().querySelectorAll(css_selector)}},{key:"setState",value:function(){this.render()}},{key:"render",value:function(){var _this10=this;this.parentViewInstance&&(this.context.parentContext=this.parentViewInstance.context);var container=this.getParentContainerElement();container?(container.innerHTML=this._getHTML(),this.fetching_data||(this.trigger("ViewRendered"),this._format(container),setTimeout(function(){_this10.format(container),_this10.trigger("ViewFormatted")},0),this.renderSubViews(),this.trigger("SubViewsRendered"),this.rendered=!0)):console.warn("No container defined/available for "+this.constructor.name+", selecting with "+this.parentContainer)}},{key:"renderSubViews",value:function(){this.rendered_subviews.forEach(function(_){_.destroy()}),this.rendered_subviews=[];var _iteratorNormalCompletion9=!0,_didIteratorError9=!1,_iteratorError9=void 0;try{for(var _step9,_iterator9=(this.subViews||[])[Symbol.iterator]();!(_iteratorNormalCompletion9=(_step9=_iterator9.next()).done);_iteratorNormalCompletion9=!0){var sub_view=_step9.value;this.rendered_subviews.push(Adhara.createView(sub_view,this))}}catch(err){_didIteratorError9=!0,_iteratorError9=err}finally{try{!_iteratorNormalCompletion9&&_iterator9.return&&_iterator9.return()}finally{if(_didIteratorError9)throw _iteratorError9}}}},{key:"_format",value:function(container){for(var _this11=this,_loop2=function(action){var onActionElements=container.querySelectorAll("[data-on"+action+"]"),_loop3=function(actionElement){if("true"===actionElement.dataset["_ae_"+action+"_"])return"continue";actionElement.addEventListener(action,function(event){var data=actionElement.dataset,action_key="on"+action;if(_this11[data[action_key]])_this11[data[action_key]](event,data,_this11);else{var fn=getValueFromJSON(window,data[action_key]);if(!fn)throw new Error("Invalid function: "+data[action_key]+" in View "+_this11.constructor.name);fn(event,data,_this11)}}),actionElement.dataset["_ae_"+action+"_"]="true"},_iteratorNormalCompletion10=!0,_didIteratorError10=!1,_iteratorError10=void 0;try{for(var _step10,_iterator10=onActionElements[Symbol.iterator]();!(_iteratorNormalCompletion10=(_step10=_iterator10.next()).done);_iteratorNormalCompletion10=!0)_loop3(_step10.value)}catch(err){_didIteratorError10=!0,_iteratorError10=err}finally{try{!_iteratorNormalCompletion10&&_iterator10.return&&_iterator10.return()}finally{if(_didIteratorError10)throw _iteratorError10}}},_arr=["click","change","blur","scroll","contextmenu","copy","cut","dblclick","drag","dragend","dragenter","dragleave","dragover","dragstart","drop","focus","focusin","focusout","input","invalid","mousedown","mouseenter","mouseleave","mouseover","mouseout","mouseup","paste","show","toggle","wheel","keyup","keydown","keypress","load"],_i2=0;_i2<_arr.length;_i2++){_loop2(_arr[_i2])}}},{key:"format",value:function(container){}},{key:"refresh",value:function(){Adhara.createView(this,this.parentViewInstance)}},{key:"onDestroy",value:function(){}},{key:"destroy",value:function(){this.onDestroy(),this.trigger("ViewDestroyed"),this.is_active=!1,this.context.removeFromParent();try{this.getParentContainerElement().innerHTML=""}catch(e){}}},{key:"template",get:function(){if(this.settings.t)return this.settings.t;if(Adhara.router.getCurrentPageName())return Adhara.router.getCurrentPageName().replace(/_/g,"-");var className=this.constructor.name.toLowerCase();return className.endsWith("view")?className.slice(0,className.length-4):className}},{key:"parentContainer",get:funct