All files / dist/src/fieldcontrols ContentListReference.js

0% Statements 0/68
0% Branches 0/49
0% Functions 0/16
0% Lines 0/60
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115                                                                                                                                                                                                                                     
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
const FieldBaseControl_1 = require("./FieldBaseControl");
const aurelia_framework_1 = require("aurelia-framework");
let ContentListReference = class ContentListReference extends FieldBaseControl_1.FieldBaseControl {
    constructor() {
        super(...arguments);
        this.Items = [];
        this.availableValues = [];
        this.searchString = '';
        this.isOpened = false;
        this.isFocused = false;
        this.selectionIndex = 0;
    }
    searchStringChanged(newValue) {
        this.searchString && this.value && this.value.Search(this.searchString, 10, 0, { select: 'all' }).Exec().subscribe(res => {
            this.availableValues = res.Result.filter(a => this.Items.indexOf(a) === -1 && a !== this.content);
            this.isOpened = true;
            this.selectionIndex = 0;
        }, err => {
        }) || (this.availableValues = []);
    }
    removeReference(item) {
        this.Items = this.Items.filter(i => i !== item);
        this.value.SetContent(this.Items);
    }
    activate(model) {
        super.activate(model);
        this.value && this.value.GetContent && this.value.GetContent({
            select: 'all'
        }).subscribe(c => {
            this.Items = c;
        });
    }
    pickValue(content) {
        this.Items.push(content);
        this.Items = this.Items.map(a => a);
        this.searchString = '';
        this.isOpened = false;
        this.isFocused = false;
        if (this.rules.length)
            this.controller.validate();
        this.value.SetContent(this.Items);
    }
    focusIn() {
        if (this.searchString.length > 0) {
            this.isOpened = true;
        }
        this.isFocused = true;
        this.searchInput.focus();
    }
    focusOut() {
        this.isOpened = false;
        if (this.rules.length)
            this.controller.validate();
        this.isFocused = false;
    }
    handleSearchKeyUp($event) {
        switch ($event.keyCode) {
            case 38: {
                this.selectionIndex = Math.max(this.selectionIndex - 1, 0);
                break;
            }
            case 40: {
                this.selectionIndex = Math.min(this.selectionIndex + 1, this.availableValues.length - 1);
                break;
            }
            case 13: {
                if (this.availableValues[this.selectionIndex]) {
                    this.pickValue(this.availableValues[this.selectionIndex]);
                    $event.preventDefault();
                    $event.stopPropagation();
                }
            }
        }
    }
};
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Array)
], ContentListReference.prototype, "Items", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Array)
], ContentListReference.prototype, "availableValues", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", String)
], ContentListReference.prototype, "searchString", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Boolean)
], ContentListReference.prototype, "isOpened", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Boolean)
], ContentListReference.prototype, "isFocused", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Number)
], ContentListReference.prototype, "selectionIndex", void 0);
ContentListReference = __decorate([
    aurelia_framework_1.customElement('contentlist-reference')
], ContentListReference);
exports.ContentListReference = ContentListReference;
//# sourceMappingURL=ContentListReference.js.map