Browse Source

closes #25: reset query form and refocus it

Davide Alberani 9 years ago
parent
commit
b2c6b5dd0f
3 changed files with 31 additions and 9 deletions
  1. 9 9
      angular_app/event-info.html
  2. 9 0
      angular_app/js/controllers.js
  3. 13 0
      angular_app/js/directives.js

+ 9 - 9
angular_app/event-info.html

@@ -62,16 +62,16 @@
                                         <p ng-if="person.company || person.job"><i ng-if="person.job">{{person.job}}</i><span ng-if="person.company && person.job">&nbsp;@&nbsp;</span><i ng-if="person.company">{{person.company}}</i></p>
                                     </td>
                                     <td>
-                                        <button class="btn btn-link" name="switch-attended" ng-click="setPersonAttribute(person, 'attended', !person.attended)"><span class="glyphicon {{(person.attended) && 'glyphicon-ok-sign text-success' || 'glyphicon-remove-sign text-danger'}}"></span></button>
+                                        <button class="btn btn-link" reset-focus name="switch-attended" ng-click="setPersonAttributeAndRefocus(person, 'attended', !person.attended)"><span class="glyphicon {{(person.attended) && 'glyphicon-ok-sign text-success' || 'glyphicon-remove-sign text-danger'}}"></span></button>
+                                    </td>
+                                    <td ng-repeat="col in customFields">
+                                        <span ng-if="col.type == 'boolean'">
+                                            <button class="btn btn-link" ng-click="setPersonAttribute(person, col.key, !person[col.key])"><span class="glyphicon {{(person[col.key]) && 'glyphicon-ok-sign text-success' || 'glyphicon-remove-sign text-danger'}}"></span></button>
+                                        </span>
+                                        <span ng-if="col.type != 'boolean'">
+                                            {{person[col.key]}}
+                                        </span>
                                     </td>
-                                <td ng-repeat="col in customFields">
-                                    <span ng-if="col.type == 'boolean'">
-                                        <button class="btn btn-link" ng-click="setPersonAttribute(person, col.key, !person[col.key])"><span class="glyphicon {{(person[col.key]) && 'glyphicon-ok-sign text-success' || 'glyphicon-remove-sign text-danger'}}"></span></button>
-                                    </span>
-                                    <span ng-if="col.type != 'boolean'">
-                                        {{person[col.key]}}
-                                    </span>
-                                </td>
                                     <td>
                                         <button ng-click="removeAttendee(person)" type="button" class="btn btn-link glyphicon glyphicon-trash"></button>
                                     </td>

+ 9 - 0
angular_app/js/controllers.js

@@ -119,6 +119,8 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person',
                 }
                 $scope.newPerson = {};
             });
+            $scope.query = '';
+            console.log(angular.element($scope.query));
         };
 
         $scope.fastAddPerson = function(person, isNew) {
@@ -148,6 +150,13 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person',
             });
         };
 
+        $scope.focusinControl = {};
+
+        $scope.setPersonAttributeAndRefocus = function(person, key, value) {
+            $scope.setPersonAttribute(person, key, value);
+            $scope.query = '';
+        };
+
         $scope.removeAttendee = function(person) {
             Event.deletePerson({
                     _id: $stateParams.id,

+ 13 - 0
angular_app/js/directives.js

@@ -25,3 +25,16 @@ eventManApp.directive('eventmanFocus', function () {
     };
 });
 
+
+eventManApp.directive('resetFocus', function () {
+    function link(scope, element, attrs) {
+        element.on('click', function() {
+            var el = angular.element(document.querySelector('#query-persons'));
+            el.length && el[0].focus();
+        });
+    };
+    return {
+        link: link
+    };
+});
+