/*! phoscon-app 2024-01-19 */

function restCreateResource(collection,data){return new Promise((resolve,reject)=>{collection.create(data,{wait:!0,success:function(model,rsp,options){1===rsp.length&&rsp[0].success&&rsp[0].success.id?(model.set({id:rsp[0].success.id}),model.unset("0",{silent:!0}),resolve(model.id)):reject(new Error("invalid response"))},error:function(model,xhr,options){reject(new Error(xhr.status))}})})}function restUpdateResource(model,data){return new Promise((resolve,reject)=>{model&&data?model.save(data,{patch:!0,success:function(model,rsp,options){var success=0,error=0;rsp&&rsp.length>0&&(rsp.forEach(x=>{x.success?success++:x.error&&error++}),success>0&&0==error)?resolve(model.id):reject(new Error("failed to update resource"))},error:function(model,xhr,options){reject(new Error(xhr.status))}}):reject(new Error("missing parameters"))})}function restSaveResource(model,data){return new Promise((resolve,reject)=>{model?(data||(data={}),model.save(data,{success:function(model,rsp,options){var success=0,error=0;rsp&&rsp.length>0&&(rsp.forEach(x=>{x.success?success++:x.error&&error++}),success>0&&0==error)?resolve(model.id):reject(new Error("failed to update resource"))},error:function(model,xhr,options){reject(new Error(xhr.status))}})):reject(new Error("missing parameters"))})}function restGetResource(resource){return new Promise((resolve,reject)=>{resource?resource.fetch({headers:{"Access-Control-Allow-Origin":"*"},mode:"no-cors",cache:!1,success:function(model,rsp,options){"length"in rsp&&rsp.length>0&&rsp[0].error?reject(new Error(rsp)):resource.id?resolve(resource.id):resolve(rsp)},error:function(model,xhr,options){var err={status:xhr.status,xhr:xhr};xhr.responseJSON&&(err.json=xhr.responseJSON),reject(err)}}):reject(new Error("missing parameters"))})}function restDeleteResource(model){return new Promise((resolve,reject)=>{model?model.destroy({wait:!0,success:function(model,rsp,options){resolve(model.id)},error:function(model,xhr,options){404===xhr.status?resolve(model.id):reject(new Error(xhr.status))}}):reject(new Error("missing parameters"))})}function getUrlPrefix(pathname){return-1===(pathname=pathname||location.pathname).indexOf("/pwa")?"":-1===pathname.indexOf(".html")?"":-1===pathname.indexOf("hassio_ingress")?"":pathname.replace(/\/pwa\/\w+.html$/i,"")||""}