From f157a9e5144fde90dc31add4006b9132e1489aa1 Mon Sep 17 00:00:00 2001
From: Luke Bennett <lukeeeebennettplus@gmail.com>
Date: Sun, 28 Aug 2016 00:18:48 +0100
Subject: [PATCH] Added type and action dropdowns, need to finalize by removing
 all inline and polishing off the selected dropdown states

---
 app/views/dashboard/todos/index.html.haml | 40 ++++++++++++++++++-----
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/app/views/dashboard/todos/index.html.haml b/app/views/dashboard/todos/index.html.haml
index ffdb88975a5..4a8536315a5 100644
--- a/app/views/dashboard/todos/index.html.haml
+++ b/app/views/dashboard/todos/index.html.haml
@@ -38,14 +38,15 @@
         = dropdown_tag(user_dropdown_label(params[:author_id], 'Author'), options: { toggle_class: 'js-user-search js-filter-submit js-author-search', title: 'Filter by author', filter: true, filterInput: 'input#search', dropdown_class: 'dropdown-menu-user dropdown-menu-selectable dropdown-menu-author js-filter-submit',
           placeholder: 'Search authors', data: { any_user: 'Any Author', first_user: (current_user.username if current_user), current_user: true, project_id: (@project.id if @project), selected: params[:author_id], field_name: 'author_id', default_label: 'Author' } })
       .filter-item.inline
-        -# = select_tag('type', todo_types_options,
-        -#   class: 'select2 trigger-submit', include_blank: true,
-        -#   data: {placeholder: 'Type'})
+        - if params[:type].present?
+          = hidden_field_tag(:type, params[:type])
+        = dropdown_tag(params[:type] || 'Type', options: { toggle_class: 'js-type-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-type js-filter-submit',
+          data: { data: todo_types_options, selected: params[:type], field_name: 'type', default_label: 'Type' } })
       .filter-item.inline.actions-filter
-        -# = select_tag('action_id', todo_actions_options,
-        -#   class: 'select2 trigger-submit', include_blank: true,
-        -#   data: {placeholder: 'Action'})
-
+        - if params[:action_id].present?
+          = hidden_field_tag(:action_id, params[:action_id])
+        = dropdown_tag(params[:action_id] || 'Action', options: { toggle_class: 'js-action-search js-filter-submit', dropdown_class: 'dropdown-menu-selectable dropdown-menu-action js-filter-submit',
+          data: { data: todo_actions_options, selected: params[:action_id], field_name: 'action_id', default_label: 'Action' } })
       .pull-right
         .dropdown.inline.prepend-left-10
           %button.dropdown-toggle.btn{type: 'button', 'data-toggle' => 'dropdown'}
@@ -91,12 +92,35 @@
     data: $projectDropdown.data('data'),
     clicked: function() {
       if ($projectDropdown.hasClass('js-filter-submit')) {
-        console.log('booM!');
         return $projectDropdown.closest('form').submit();
       }
     }
   });
 
+  $typeDropdown = $('.js-type-search');
+  $typeDropdown.glDropdown({
+    selectable: true,
+    fieldName: 'type_id',
+    data: $typeDropdown.data('data'),
+    clicked: function() {
+      if ($typeDropdown.hasClass('js-filter-submit')) {
+        return $typeDropdown.closest('form').submit();
+      }
+    }
+  });
+
+  $actionDropdown = $('.js-action-search');
+  $actionDropdown.glDropdown({
+    selectable: true,
+    fieldName: 'action_id',
+    data: $actionDropdown.data('data'),
+    clicked: function() {
+      if ($actionDropdown.hasClass('js-filter-submit')) {
+        return $actionDropdown.closest('form').submit();
+      }
+    }
+  });
+
   $('form.filter-form').on('submit', function (event) {
     event.preventDefault();
     Turbolinks.visit(this.action + '&' + $(this).serialize());
-- 
GitLab