{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="submit" form="form-module" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>
        <a href="{{ cancel }}" data-toggle="tooltip" title="{{ button_cancel }}" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    {% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-pencil"></i> {{ text_edit }}</h3>
      </div>
      <div class="panel-body">
        <form action="{{ action }}" method="post" enctype="multipart/form-data" id="form-module" class="form-horizontal">
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-name">{{ entry_name }}</label>
            <div class="col-sm-10">
              <input type="text" name="name" value="{{ name }}" placeholder="{{ entry_name }}" class="form-control" />
              {% if error_name %}
              <div class="text-danger">{{ error_name }}</div>
              {% endif %}
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status">{{ entry_status }}</label>
            <div class="col-sm-10">
              <select name="status" class="form-control">
                {% if status %}
                <option value="1" selected="selected">{{ text_enabled }}</option>
                <option value="0">{{ text_disabled }}</option>
                {% else %}
                <option value="1">{{ text_enabled }}</option>
                <option value="0" selected="selected">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div>
          {# <div class="form-group">
            <label class="col-sm-2 control-label" for="input-status">{{ entry_home }}</label>
            <div class="col-sm-10">
              <select name="homelink" class="form-control">
                {% if homelink %}
                <option value="1" selected="selected">{{ text_enabled }}</option>
                <option value="0">{{ text_disabled }}</option>
                {% else %}
                <option value="1">{{ text_enabled }}</option>
                <option value="0" selected="selected">{{ text_disabled }}</option>
                {% endif %}
              </select>
            </div>
          </div> #}
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-name">{{ entry_columns }}</label>
            <div class="col-sm-10">
              <input type="text" name="columns" value="{{ columns }}" placeholder="{{ entry_columns }}" class="form-control" />
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label" for="input-name">{{ entry_levels }}</label>
            <div class="col-sm-10">
              <input type="text" name="levels" value="{{ levels }}" placeholder="{{ entry_levels }}" class="form-control" />
            </div>
          </div>
          <div class="form-group">
            <input type="hidden" name="active_category" value={{ active_category}}>
            <label class="col-sm-2 control-label" for="input-status">{{ entry_category }}</label>
            <div class="col-sm-10">
              <table id="MahardhiCategory" class="table table-striped table-bordered text-center">
                <tr>
                  <td>
                    <select multiple="multiple" id="all_category" style="width: 320px; height: 260px;">
                      <optgroup label="Product Category">
                        {{ category_option }}
                      </optgroup>
                      <optgroup label="CMS Page">
                        {{ cms_page_option }}
                      </optgroup>                      
                    </select>
                  </td>
                  <td>
                    <select multiple="multiple" id="active_category" style="width: 320px; height: 260px;">
                      {{ active_category_option }}
                    </select>
                  </td>
                </tr>
                <tr>
                  <td><a href="#" id="AddMenu" class="btn btn-primary">{{ entry_add }}</a></td>
                  <td><a href="#" id="RemoveMenu" class="btn btn-default">{{ entry_remove }}</a></td>
                  <td >
                      <a href="#" id="MenuUp" class="btn btn-default" >&uarr;</a><br/>
                      <a href="#" id="MenuDown" class="btn btn-default">&darr;</a><br/>
                  </td>
                </tr>
              </table>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>
{{ footer }}
<script type="text/javascript">
            function addMenu(){
              $("#all_category option:selected").each(function(i){
                var val = $(this).val();
                var text = $(this).text();
                text = text.replace(/(^\s*)|(\s*$)/gi,"");
                $("#active_category").append("<option value=\""+val+"\">"+text+"</option>");
              });
              serialize();
              return false;
            }

            function removeMenu(){
              $("#active_category option:selected").each(function(i){
                $(this).remove();
              });
              serialize();
              return false;
            }

            function serialize(){
              var options = "";
              $("#active_category option").each(function(i){
                options += $(this).val() + ",";
              });
              $("input[name='active_category']").val(options.substr(0, options.length - 1));
            }

            function moveMenu(up){
              var moveUpDown = $("#active_category option:selected");
              if (moveUpDown.length >1){
                alert('Please select Only one Category or page');
                return false;
              }
              if (up){
                moveUpDown.prev().insertAfter(moveUpDown);
              }
              else{
                moveUpDown.next().insertBefore(moveUpDown);
              }
              serialize();
              return false;
            }

            $(document).ready(function(){
              $("#AddMenu").click(addMenu);
              $("#all_category").dblclick(addMenu);
              $("#RemoveMenu").click(removeMenu);
              $("#active_category").dblclick(removeMenu);
              
              $("#MenuUp").on('click',function(e){
                e.preventDefault();
                moveMenu(true);
              });

              $("#MenuDown").on('click',function(e){
                e.preventDefault();
                moveMenu();
              });
            });
            </script>
