All files / dist/src/fieldcontrols ContentReference.js

0% Statements 0/57
0% Branches 0/65
0% Functions 0/13
0% Lines 0/52
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                                                                                                                                                                                                 
"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");
const aurelia_validation_1 = require("aurelia-validation");
let ContentReference = class ContentReference extends FieldBaseControl_1.FieldBaseControl {
    constructor() {
        super(...arguments);
        this.availableValues = [];
        this.searchString = '';
        this.isOpened = false;
    }
    get rules() {
        const parentRules = super.rules;
        let thisRules = aurelia_validation_1.ValidationRules
            .ensure('searchString')
            .satisfies((v, obj) => {
            if (!obj.settings.Compulsory && !v) {
                return true;
            }
            if (obj.selectedContent && (v === obj.selectedContent.DisplayName || v === obj.selectedContent.Name)) {
                return true;
            }
            return false;
        }).withMessage('Invalid value.')
            .rules;
        return [...parentRules, ...thisRules];
    }
    searchStringChanged(newValue) {
        if (this.selectedContent && newValue !== this.selectedContent.DisplayName && newValue !== this.selectedContent.Name || !this.selectedContent) {
            this.selectedContent = null;
            this.value && this.value.Search(this.searchString, 10, 0, { select: 'all' }).Exec().subscribe(res => {
                this.availableValues = res.Result;
                this.isOpened = true;
            }, err => {
            });
        }
    }
    activate(model) {
        super.activate(model);
        this.value && this.value.GetContent && this.value.GetContent().subscribe(c => {
            if (c !== null) {
                this.selectedContent = c;
                this.searchString = c.DisplayName || c.Name || '';
                this.isOpened = false;
            }
        });
    }
    pickValue(content) {
        this.value.SetContent(content);
        this.selectedContent = content;
        this.searchString = content.DisplayName || content.Name || '';
        this.isOpened = false;
        if (this.rules.length)
            this.controller.validate();
    }
    focusIn() {
        if (this.searchString.length > 0 && !this.selectedContent) {
            this.isOpened = true;
        }
    }
    focusOut() {
        this.isOpened = false;
        if (this.rules.length)
            this.controller.validate();
    }
};
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Array)
], ContentReference.prototype, "availableValues", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", String)
], ContentReference.prototype, "searchString", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Object)
], ContentReference.prototype, "selectedContent", void 0);
__decorate([
    aurelia_framework_1.bindable,
    __metadata("design:type", Boolean)
], ContentReference.prototype, "isOpened", void 0);
ContentReference = __decorate([
    aurelia_framework_1.customElement('content-reference')
], ContentReference);
exports.ContentReference = ContentReference;
//# sourceMappingURL=ContentReference.js.map