/*! phoscon-app 2025-05-20 */

function displaySceneParameter(){var txt="";app.activeModel&&(txt+='<svg class="item-icon" width="48" height="48"><use transform="scale(1)" xlink:href="#scenes-icon" /></svg> ',txt+=app.activeModel.attributes.name),$(".main-head h1 .item-name").html(txt),$(".main-head h1 .item-name").removeAttr("data-translateid"),$(".main-head h1 .item-name").attr("data-target","#renameSensorModal")}function restCreateScene(data){return new Promise((resolve,reject)=>{data.name&&0!==data.name.length?app.groups.get(app.session.gid)?$.ajax({url:"//"+app.session.gw+"/api/"+app.apikey+"/groups/"+app.session.gid+"/scenes",dataType:"json",type:"POST",cache:!1,data:JSON.stringify(data),contentType:"application/json; charset=utf-8",headers:{Accept:apiversion},success:function(json,status,xhr){if(1===json.length&&"success"in json[0]&&json[0].success.id){var scid=json[0].success.id;app.recentlyCreatedScene=scid,restGetResource(app.scenes).then(rsp=>{scid in rsp?resolve(scid):reject(new Error("failed to create scene"))})}else reject(new Error("failed to create scene"))},error:function(jqXHR,textStatus,errorThrown){reject(new Error(errorThrown))},timeout:1e4}):reject(new Error("group not found")):reject(new Error("invalid scene name"))})}function restRecallScene(successCallback,errorCallback){$.ajax({url:"//"+app.session.gw+"/api/"+app.apikey+"/groups/"+app.session.gid+"/scenes/"+app.session.scid+"/recall",dataType:"json",type:"PUT",cache:!1,contentType:"application/json; charset=utf-8",headers:{Accept:apiversion},success:function(json,status,xhr){console.log("success recall scene "+app.session.scid),void 0!==successCallback&&successCallback({})},error:function(jqXHR,textStatus,errorThrown){console.log("error recall scene: "+errorThrown),void 0!==errorCallback&&errorCallback({error:jqXHR.status})},timeout:1e4})}function restStoreScene(model){return new Promise((resolve,reject)=>{if(model){var tt=model.get("transitiontime"),param="";void 0!==tt&&(param='{"transitiontime":'+tt+"}"),$.ajax({url:"//"+app.session.gw+"/api/"+app.apikey+"/groups/"+app.session.gid+"/scenes/"+app.session.scid+"/store",dataType:"json",type:"PUT",cache:!1,data:param,contentType:"application/json; charset=utf-8",headers:{Accept:apiversion},success:function(json,status,xhr){console.log("success stored scene "+app.session.scid),resolve()},error:function(jqXHR,textStatus,errorThrown){reject(new Error("failed to store scene"))},timeout:1e4})}else reject()})}function recallScene(){restRecallScene(function(rsp){rsp.error})}app.saveScene=function(){if(app.state!==SCENE_CHANGED)throw"unexpected app state";if(app.activeModel){if(app.activeModel.has("tt")){var tt=app.activeModel.get("tt");app.activeModel.set({transitiontime:tt})}app.state=SCENE_SAVING,app.saveSceneGui(),restStoreScene(app.activeModel).then(()=>restGetResource(app.scenes))}},app.saveSceneGui=function(){var scene=$('#sceneList > li.list-group-item[data-sid="'+app.session.scid+'"]');setTimeout(()=>{scene.find(".g-spinner").addClass("op-true")},700),app.spinTimer&&clearTimeout(app.spinTimer),app.saveTimer&&clearTimeout(app.saveTimer),app.spinTimer=setTimeout(()=>{app.savelock=!1,delete app.spinTimer,scene.find(".g-spinner").removeClass("op-true"),scene.find(".save-ok").addClass("op-true"),$(".nav-head").css("pointer-events","auto"),app.saveTimer=setTimeout(()=>{delete app.saveTimer,scene.find(".save-ok").removeClass("op-true")},2e3),app.setSceneStateIdle()},4e3)},$(document).on("show.bs.modal","#deleteSceneModal",function(){$(".modal-body span b",this).html(app.activeModel.get("name"))});