1 line
6.2 KiB
JavaScript
1 line
6.2 KiB
JavaScript
var __runInitializers=this&&this.__runInitializers||function(thisArg,initializers,value){for(var useValue=arguments.length>2,i=0;i<initializers.length;i++)value=useValue?initializers[i].call(thisArg,value):initializers[i].call(thisArg);return useValue?value:void 0},__esDecorate=this&&this.__esDecorate||function(ctor,descriptorIn,decorators,contextIn,initializers,extraInitializers){function accept(f){if(void 0!==f&&"function"!=typeof f)throw new TypeError("Function expected");return f}for(var _,kind=contextIn.kind,key="getter"===kind?"get":"setter"===kind?"set":"value",target=!descriptorIn&&ctor?contextIn.static?ctor:ctor.prototype:null,descriptor=descriptorIn||(target?Object.getOwnPropertyDescriptor(target,contextIn.name):{}),done=!1,i=decorators.length-1;i>=0;i--){var context={};for(var p in contextIn)context[p]="access"===p?{}:contextIn[p];for(var p in contextIn.access)context.access[p]=contextIn.access[p];context.addInitializer=function(f){if(done)throw new TypeError("Cannot add initializers after decoration has completed");extraInitializers.push(accept(f||null))};var result=(0,decorators[i])("accessor"===kind?{get:descriptor.get,set:descriptor.set}:descriptor[key],context);if("accessor"===kind){if(void 0===result)continue;if(null===result||"object"!=typeof result)throw new TypeError("Object expected");(_=accept(result.get))&&(descriptor.get=_),(_=accept(result.set))&&(descriptor.set=_),(_=accept(result.init))&&initializers.unshift(_)}else(_=accept(result))&&("field"===kind?initializers.unshift(_):descriptor[key]=_)}target&&Object.defineProperty(target,contextIn.name,descriptor),done=!0};import{OkCancelPrompt}from"../Helpers/TcHmiPopups/OkCancelPrompt.js";import{DirectoryBrowser}from"../Helpers/TcHmiDirectoryBrowser/DirectoryBrowser.js";import{ListBrowsingDisplay}from"../Helpers/TcHmiDirectoryBrowser/ListBrowsingDisplay.js";let SelectRecipePrompt=(()=>{var _a,_b;let ___onPathChanged_decorators,___onSelectionChanged_decorators,_classSuper=OkCancelPrompt,_instanceExtraInitializers=[];return class extends _classSuper{static{const _metadata="function"==typeof Symbol&&Symbol.metadata?Object.create(_classSuper[Symbol.metadata]??null):void 0;___onPathChanged_decorators=[(_a=TcHmi).CallbackMethod.bind(_a)],___onSelectionChanged_decorators=[(_b=TcHmi).CallbackMethod.bind(_b)],__esDecorate(this,null,___onPathChanged_decorators,{kind:"method",name:"__onPathChanged",static:!1,private:!1,access:{has:obj=>"__onPathChanged"in obj,get:obj=>obj.__onPathChanged},metadata:_metadata},null,_instanceExtraInitializers),__esDecorate(this,null,___onSelectionChanged_decorators,{kind:"method",name:"__onSelectionChanged",static:!1,private:!1,access:{has:obj=>"__onSelectionChanged"in obj,get:obj=>obj.__onSelectionChanged},metadata:_metadata},null,_instanceExtraInitializers),_metadata&&Object.defineProperty(this,Symbol.metadata,{enumerable:!0,configurable:!0,writable:!0,value:_metadata})}static#tchmiFQN="TcHmi.Controls.Beckhoff.TcHmiRecipeSelectComponents."+this.name;__recipeBrowser=__runInitializers(this,_instanceExtraInitializers);__initialPath=null;__emptyNotification;constructor(pathDisplay,parentControl){super(parentControl);const ulist=document.createElement("ul");ulist.className=`${this.__className}-browsing-box`,this.__elementContent.appendChild(ulist);const browsingDisplay=new ListBrowsingDisplay(ulist,this.__parentControl);this.__recipeBrowser=new DirectoryBrowser([pathDisplay,browsingDisplay],this.__parentControl),this.__recipeBrowser.onPathChange.add(this.__onPathChanged),this.__recipeBrowser.onSelectionChange.add(this.__onSelectionChanged),this.__emptyNotification=document.createElement("div"),this.__emptyNotification.className="empty-notification",this.__elementContent.appendChild(this.__emptyNotification)}__onPathChanged(currentItem,_path){currentItem&&TcHmi.Server.RecipeManagement.isRecipe(currentItem.payload)?(this.__okButton.setIsEnabled(!0),this.__ok()):this.__okButton.setIsEnabled(!1)}__onSelectionChanged(selectedItems){selectedItems&&1===selectedItems.length&&TcHmi.Server.RecipeManagement.isRecipe(selectedItems[0].payload)?this.__okButton.setIsEnabled(!0):this.__okButton.setIsEnabled(!1)}destroy(force=!1){this.suspend(),super.destroy(force)}suspend(){this.__recipeBrowser.suspend(!0)}resume(){this.__recipeBrowser.resume()}async setPath(value){await this.__recipeBrowser.setPath(value);const currentItem=this.__recipeBrowser.getCurrentItem()?.payload,path=this.__recipeBrowser.getPath();return currentItem&&TcHmi.Server.RecipeManagement.isRecipe(currentItem)&&path?{name:path.join("::"),recipe:currentItem}:null}reset(){this.__recipeBrowser.setPath([])}setRecipeList(rootDirectory){this.__recipeBrowser.setDirectory(rootDirectory,folder=>new Map(Object.entries(folder)),TcHmi.Server.RecipeManagement.isRecipe),this.__emptyNotification.classList.toggle("show",!rootDirectory||0===Object.keys(rootDirectory).length)}async __ok(){let recipe=this.__recipeBrowser.getCurrentItem()?.payload;if(!recipe)return void this.__prompt?.error(new Error("No recipes available."));const selectedItem=this.__recipeBrowser.getSelectedItems()?.[0];let path=this.__recipeBrowser.getPath();TcHmi.Server.RecipeManagement.isRecipe(recipe)&&path?await this.__recipeBrowser.setPath(path.slice(0,-1)):selectedItem&&TcHmi.Server.RecipeManagement.isRecipe(selectedItem.payload)?(recipe=selectedItem.payload,path?.push(selectedItem.name)):recipe=void 0,recipe&&path?this.__prompt?.answer({isOk:!0,value:{name:path.join("::"),recipe}}):this.__prompt?.error(new Error("Invalid recipe selection."))}__cancel(){this.__initialPath&&this.__recipeBrowser.setPath(this.__initialPath),super.__cancel()}async prompt(){this.__initialPath=this.__recipeBrowser.getPath();const currentItem=this.__recipeBrowser.getCurrentItem()?.payload,promise=super.prompt();return this.__initialPath&&this.__initialPath.length>0&¤tItem&&TcHmi.Server.RecipeManagement.isRecipe(currentItem)&&await this.__recipeBrowser.setPath(this.__initialPath.slice(0,-1))&&this.__recipeBrowser.selectItem(this.__initialPath[this.__initialPath.length-1],!1),promise}setTexts(texts){super.setTexts(texts),this.__applyTextToElement("headerText",texts.headerText,this.__elementHeader),this.__applyTextToElement("noRecipesText",texts.noRecipesText,this.__emptyNotification)}}})();export{SelectRecipePrompt}; |