1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-30 11:24:21 +01:00
fab-manager/app/assets/javascripts/directives/selectMember.js.erb
2018-11-21 11:08:53 +01:00

49 lines
1.6 KiB
Plaintext

/* eslint-disable
no-return-assign,
no-undef,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
'use strict';
/**
* This directive will allow to select a member.
* Please surround it with a ng-if directive to prevent it from being used by a non-admin user.
* The resulting member will be set into the parent $scope (=> $scope.ctrl.member).
* The directive takes an optional parameter "subscription" as a "boolean string" that will filter the user
* which have a valid running subscription or not.
* Usage: <select-member [subscription="false|true"]></select-member>
*/
Application.Directives.directive('selectMember', [ 'Diacritics', 'Member', function (Diacritics, Member) {
return ({
restrict: 'E',
templateUrl: '<%= asset_path "shared/_member_select.html" %>',
link (scope, element, attributes) {
return scope.autoCompleteName = function (nameLookup) {
if (!nameLookup) {
return;
}
scope.isLoadingMembers = true;
const asciiName = Diacritics.remove(nameLookup);
const q = { query: asciiName };
if (attributes.subscription) {
q['subscription'] = attributes.subscription;
}
return Member.search(q, function (users) {
scope.matchingMembers = users;
return scope.isLoadingMembers = false;
}
, function (error) { console.error(error); });
};
}
});
}]);