{% extends "_base.jinja" %}

{% from "_sidebar.jinja" import sidebar %}
{% from "_edit.jinja" import form_item %}

{% block title %}Chart Edit - Polaris{% endblock %}

{% block script %}
  {{ super() }}
  <script src="{{ cdn_url_for('bootstrap-select.js') }}"></script>
  <script src="{{ cdn_url_for('bootstrap-switch.js') }}"></script>
  <script src="{{ cdn_url_for('polaris.js') }}"></script>
{% endblock %}

{% block body %}
  <body ng-controller="EditCtrl">
    {{
      sidebar(icons=["fui-plus"], user=user, href={
        "fui-plus": "/chart/new"
      })
    }}
    <div class="content">
      <div class="container" style="width:67%;">
        <div class="title">{{ "Update Chart" if id else "Create Chart" }}</div>
        <form novalidate ng-submit="submit()" class="form-horizontal" role="form">
          <input ng-model="type" ng-init="type='{{ "update" if id else "new" }}'" type="hidden">
          <input ng-model="page" ng-init="page='chart'" type="hidden">

          {% if id is defined %}
            {{ form_item('uuid', id, disabled=True) }}
          {% endif %}

          {{ form_item("name", name, validation="valid-name") }}
          {{ form_item("slug", slug) }}
          {{ form_item("source", source if source is defined else sources, disabled=True) }}
          {% if user is defined %}
            {{ form_item('user', user if user is string else user.email, disabled=True) }}
          {% endif %}
          {{ form_item("options", options, col=8, is_json=True, validation="valid-json") }}

          <div class="form-group">
            <label class="col-md-2 control-label" style="padding-top:0;">public</label>
            <input ng-model="public" flat-switch="{{ 'on' if is_public else 'off' }}"
              type="checkbox" data-toggle="switch">
          </div>

          <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
              <button type="submit" class="btn btn-success" ng-click="actionType='save'">
                Save</button>
              {% if id is defined %}
              <button type="submit" class="btn btn-danger" ng-click="actionType='delete'">
                Delete</button>
              {% endif %}
            </div>
          </div>
        </form>
      </div>
    </div>
  </body>
{% endblock %}
