Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SettingCollection.js « Collection « src - git.mdns.eu/nextcloud/passwords-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e7acff15f407b8bdc2cb05d1060f1625defefbb (plain)
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
import AbstractCollection from './AbstractCollection';

export default class SettingCollection extends AbstractCollection {


    /**
     * @param {(Number|String)} index
     * @return {AbstractModel|string|null}
     * @api
     */
    get(index) {
        if(this._elements.hasOwnProperty(index)) {
            return this._elements[index];
        }

        for(let element of this._elements) {
            if(element.getId() === index || element.getName() === index) return element;
        }

        return null;
    }

    /**
     * @param {(String|AbstractModel)} id
     * @api
     */
    has(id) {
        id = typeof id === 'string' ? id:id.getId();

        for(let element of this._elements) {
            if(element.getId() === id || element.getName() === id) return true;
        }

        return false;
    }

    /**
     * @param {String} id
     * @private
     */
    _removeElement(id) {
        for(let i = 0; i < this._elements.length; i++) {
            if(this._elements[i].getId() === id || this._elements[i].getName() === id) {
                this._elements.splice(i, 1);
                i--;
            }
        }
    }
}