UNPKG

@darwino/darwino-react

Version:

A set of Javascript classes and utilities

81 lines (74 loc) 2.27 kB
/* * (c) Copyright Darwino Inc. 2014-2017. */ import React, { Component } from "react"; import { UserService } from '@darwino/darwino'; import BasePicker from './BasePicker'; /* * User picker */ class BaseUserPicker extends BasePicker { constructor(props, context) { super(props, context); this.onSearchChange = this.onSearchChange.bind(this); this.userService = this.props.userService || new UserService(); this.timeout = this.props.timeout || 300; this.limit = this.props.limit || 50; this.attributes = this.props.attributes || ["dn", "cn"]; this.currentSearch = ""; this.currentRequest = 0; this.defValueAttr = "dn"; this.defLabelAttr = "cn"; this.state.users = []; } componentDidMount() { this.execSearch("", this.currentRequest); } onSearchChange(e) { var search = e.target.value; var cr = ++this.currentRequest; setTimeout(() => { if (cr == this.currentRequest) { this.execSearch(search, cr); } }, 300); } execSearch(search, check) { //typeAhead(query,attributes,skip,limit,options,cb) { this.userService.typeAhead(search, this.attributes, 0, this.limit, null, r => { if (check == this.currentRequest) { r.sort((a, b) => { return a.cn.localeCompare(b.cn); }); this.setState({ users: r }); } }); } renderItem(value, index) { var label = this.itemLabel(value); return /*#__PURE__*/React.createElement("a", { key: index, onClick: e => this.selectValue(this.itemValue(value)) }, /*#__PURE__*/React.createElement("div", { className: "media" }, /*#__PURE__*/React.createElement("div", { className: "media-left" }, /*#__PURE__*/React.createElement("img", { className: "media-object", src: this.userService.getUserPhotoUrl(value.dn), className: "img-circle", style: { width: 35, height: 35 } })), /*#__PURE__*/React.createElement("div", { className: "media-body" }, /*#__PURE__*/React.createElement("h4", { className: "media-heading" }, label != undefined && label.toString()), value.dn))); } } export default BaseUserPicker; //# sourceMappingURL=BaseUserPicker.js.map