Custom HABPanel Widget for Selection

Hello,

although I’m reading for quite a while, this is my first post, so I’m new to the community, welcome everyone, and thanks already for the great post I read so far!!

I hope my topic is in the proper section, otherwise pls. let me know.

my issue:
I’m trying to create a custom HABPanel Widget for selection. Actually I want to use a String item which holds various values sperated by a comma. My custom widget should open a modal window, read this item state, split it’s state by the comma, offer several button (depended on the amount of comma-seperated values) and update another item with the selected value). So far so good, my code does this, but the modal window stays open after a button click.

Here is my code:

<section class="custom-modal-container" ng-class="{ active: show_modal }">
  <div for="toggler" class="custom-modal close-modal-area" ng-click="show_modal=false"></div>
  <div class="custom-modal custom-modal-box">

    <div>Was ist zu tun</div>
    <br />
    
    <div class="col-md-4" ng-repeat="element in itemState('ToDo_todo_templates').split(',')">   
      <div class="toggle-modal-button" ng-click="show_modal=false; sendCmd('ToDo_Input_Name',element); show_modal=false">{{element}}</div>
    </div>
    
  </div>
</section>

<section class="custom-modal-content">
  <div class="toggle-modal-button" ng-click="show_modal=true">Task</div>
</section>

I assume it has something todo with the context of the buttons, and that a button cannot “access” the modal window anymore?!?

Would be cool if someone, with more experience on that matter, could help me out :slight_smile:

thanks
martin

Sorry I can’t help, but I did move the post to the HABPanel category where more of the right people will see it hopefully. Good luck!

I would say start with this code and alter it for your needs.

Basically you create a container that has a visibility of hidden. Then you have that .container .active which has a visibility of visible. when the button is clicked, it adds a class called .active which makes the visibility visible. and when you click anything in the modal. it removes the .active component which makes the container not visible again.

<style>
.custom-modal-container {
  background: rgba(0, 0, 0, 0.75);
  opacity: 0;
  color: white;
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  visibility: hidden;
  -webkit-transition: opacity 0.5s, visibility 0s linear 0.5s;
  transition: opacity 0.5s, visibility 0s linear 0.5s;
  z-index: 99999;
}
.custom-modal-container.active {
  opacity: 1;
  visibility: visible;
  -webkit-transition: opacity 0.5s;
  transition: opacity 0.5s;
}

.custom-modal {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 2em;
  border-radius: 0.5em;
  -webkit-transform: translateX(-50%) translateY(-50%);
          transform: translateX(-50%) translateY(-50%);
}
.custom-modal.close-modal-area {
  width: 100%;
  height: 100%;
}
.custom-modal.custom-modal-box {
  background: indianred;
  text-align: center;
}
.custom-modal-content .custom-modal {
  width: 100%;
  max-width: 40em;
}

.toggle-modal-button {
  background-color: transparent;
  color: white;
  display: inline-block;
  padding: 1em;
  cursor: pointer;
  border-radius: 0.5em;
  box-shadow: inset 0 0 1px white;
}
.toggle-modal-button:hover, .toggle-modal-button:focus,
    .toggle-modal-button:active {
  background-color: rgba(0, 0, 0, 0.25);
  box-shadow: none;
}
.custom-modal-content .toggle-modal-button {
  color: rgba(255, 255, 255, 0.75);
  margin-bottom: 1em;
}

.custom-modal-content {
  color: peru;
  width: 90%;
  max-width: 600px;
  padding-top: 2em;
  margin: 0 auto;
}
</style>

<section class="custom-modal-container" ng-class="{ active: show_modal }">
  <div for="toggler" class="custom-modal close-modal-area" ng-click="show_modal=false"></div>
  <div class="custom-modal custom-modal-box">
    <div>Are you sure?</div>
    <br />
    <div class="toggle-modal-button" ng-click="show_modal=false; sendCmd('Presence_Toggle', 'OFF')">Yes</div>
  </div>
</section>

<section class="custom-modal-content">
  <div class="toggle-modal-button" ng-click="show_modal=true">Settings</div>
</section>

Hello,

thanks for your replies. I finally found a working solution I want to share.

<script type="text/ng-template" id="allcats">
    <div class="container" style="padding: 30px; border: 1px solid #456;">
      <a ng-click="$close()" class="pull-right btn btn-danger">X</a>
      <h3 style="color: white">Categories</h3>
        <ul ng-repeat="element in itemState('All_Categories').split(',')">
            <li class="col-md-4" >	   						
                  <div ng-if="itemState('Selected_Category')==element">
        		<div class="toggle-modal-button" style="background: cyan; color: white"  ng-click="$close(); sendCmd('Selected_Category',element)">{{element.split('=')[1]}}</div>
 		  </div>

		  <div ng-if="itemState('Selected_Category')!=element">
		  	<div class="toggle-modal-button" style="background: grey; color: white"  ng-click="$close(); sendCmd('Selected_Category',element)">{{element.split('=')[1]}}</div>
		  </div>    
								
            </li>
        </ul>
     
    </div>
</script>



<div class="toggle-modal-button" style="background: grey; color: white; vertical-align: middle" ng-click="openModal('allcats', true, 'lg')">{{itemState('Selected_Category').split('=')[1]}}</div>

the cool thing for me, in the item “All_Categories” i have a comma separated list like (1=test1,2=test2,3=test3). The Elements are shown as buttons, and clicking one will push this value to item “Selected_Category”. So actually I now have a more flexible Selection-Widget, since I can control the elements dynamically via an item.

It still looks a bit strange (copy and paste of various things :slight_smile:) If so