All files / sp-admin/mixins details.js

50% Statements 10/20
42.86% Branches 6/14
66.67% Functions 4/6
50% Lines 10/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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              2x 2x     2x 1x     1x 1x                                                     4x           1x 1x     1x            
import debounce from '../util/debounce';
// a details page view mixin
export default {
    detailsId: {},
    getItem: {},
    detailsPromise: {
        get () {
            Eif (!this.getItem) {
                this.getItem = debounce(this.model, this.model.get, 200);
            }
 
            if (!this.detailsId) {
                return Promise.resolve(null);
            }
 
            Eif (this.localDetailsObject && this.model.id(this.localDetailsObject) === this.detailsId) {
                return Promise.resolve(this.localDetailsObject);
            }
 
            if (!this.model) {
                return Promise.reject('Connection to server not configured.');
            }
 
            if (this.detailsId) {
                return this.getItem(this.detailsId);
            }
 
            return Promise.resolve(null);
        }
    },
    localDetailsObject: {},
    detailsObject: {
        get (val, resolve) {
            const promise = this.detailsPromise;
            if (!promise) {
                return;
            }
            promise.then((obj) => {
                resolve(obj);
            });
        }
    },
    showDetails (object) {
        this.assign({
            detailsId: this.model.id(object),
            localDetailsObject: object
        });
    },
    showDetailsFromEvent (args) {
        const [, object] = args;
        this.showDetails(object);
    },
    clearDetails () {
        this.assign({
            detailsId: null,
            localDetailsObject: null
        });
    }
};