
{% load crispy_forms_tags i18n compress %}

{% block css_extra %}
<style type="text/css">
#settings_button {
    position: fixed;
    top: 70px;
    right: 0;
    z-index: 1040;
    cursor: pointer;
}

#settings_menu {
    padding: 10px;
    position: fixed;
    top: 70px;
    right: -250px;
    width: 250px;
    z-index: 1040;
}
</style>
{% endblock %}

<div class="no-print btn btn-primary" id="settings_button"><i class="fa fa-gear"></i></div>
<div class="no-print panel panel-default" id="settings_menu">

    {% for action in request.LEONARDO_CONFIG.page_actions %}
      {% include action %}
    {% endfor %}

  </div>
</div>

<script type="text/javascript">
$(function () {
  var $settingsButton = $("#settings_button");
  var $demo_settings = $('#settings_menu');
  $settingsButton.draggable({
    axis:'y',
    start: function( event, ui ) {
       event.stopPropagation();
    },
    stop: function( event, ui ) {
        localStorage.setItem('settingsButton_position',ui.position.top);
        $settingsButton.css("left", "");
    },
    drag: function( event, ui ) {
        $demo_settings.css("top", ui.position.top);
    }
  });
  
  var y = localStorage.getItem('settingsButton_position') || 150;
  $settingsButton.css("top", parseInt(y));
  $demo_settings.css("top", parseInt(y));


  $settingsButton.click(function () {
    if (!$settingsButton.hasClass("open")) {
      localStorage.setItem('settingsButton_open',true);
      $settingsButton.animate({"right": "250px"});
      $settingsButton.addClass("open");
      $demo_settings.animate({"right": "0"});
    } else {
      localStorage.setItem('settingsButton_open',false);
      $settingsButton.animate({"right": "0"});
        $settingsButton.css('left', '');
      $demo_settings.animate({"right": "-250px"});
      $settingsButton.removeClass("open");
    }
  });

  if(localStorage.getItem('settingsButton_open') === "true"){
    $settingsButton.animate({"right": "250px"});
    $demo_settings.animate({"right": "0"});
    $settingsButton.addClass("open");
  }

});

</script>
