Home Reference Source

application/metaproperties/meta-properties.js

import React from 'react';
import TextMetaProperty from './text-meta-property';
import CheckboxMetaProperty from './checkbox-meta-property';
import LongtextMetaProperty from './longtext-meta-property';
import RichtextMetaProperty from './richtext-meta-property';
import EditortextMetaProperty from './editortext-meta-property';
import PrintonlyMetaProperty from './printonly-meta-property';
import RelatedcontentMetaProperty from './relatedcontent-meta-property';
import DateMetaProperty from './date-meta-property';
import DatetimeMetaProperty from './datetime-meta-property';
import SelectentryMetaProperty from './selectentry-meta-property';
import JsonMetaProperty from './json-meta-property';
import FileMetaProperty from './file-meta-property';
import SecuretextMetaProperty from './secure-text-meta-property';
import RelatedentriesMetaProperty from './relatedentries-meta-property';

class MetaProperties {
    constructor(meta = {}) {
        this.init = this.init.bind(this);

        this.init(meta);
    }

    init(meta) {
        this.registeredMeta = meta;
    }

    propertiesForGroup(group) {
        if (!this.registeredMeta[group]) {
            return [];
        }

        return this.registeredMeta[group];
    }

    getTypes() {
        return [
            {
                type: 'TextMetaProperty',
                description: 'Plain Text'
            },
            {
                type: 'CheckboxMetaProperty',
                description: 'Checkbox'
            },
            {
                type: 'DateMetaProperty',
                description: 'Date'
            },
            {
                type: 'DatetimeMetaProperty',
                description: 'Datetime'
            },
            {
                type: 'LongtextMetaProperty',
                description: 'Multi-line Plain Text'
            },
            {
                type: 'RichtextMetaProperty',
                description: 'Rich Text'
            },
            {
                type: 'EditortextMetaProperty',
                description: 'Code Editor'
            },
            {
                type: 'RelatedcontentMetaProperty',
                description: 'Content and Media'
            },
            {
                type: 'SelectentryMetaProperty',
                description: 'Related Entry'
            },
            {
                type: 'FileMetaProperty',
                description: 'File Upload'
            },
            {
                type: 'SecuretextMetaProperty',
                description: 'Secure Text'
            },
            {
                type: 'RelatedentriesMetaProperty',
                description: 'Multiple related entries'
            }
        ]
    }

    componentForType(type, props) {
        switch(type) {
            case 'TextMetaProperty':
                return <TextMetaProperty {...props} />;
                break;
            case 'LongtextMetaProperty':
                return <LongtextMetaProperty {...props} />;
                break;
            case 'RichtextMetaProperty':
                return <RichtextMetaProperty {...props} />;
                break;
            case 'EditortextMetaProperty':
                return <EditortextMetaProperty {...props} />;
                break;
            case 'PrintonlyMetaProperty':
                return <PrintonlyMetaProperty {...props} />;
                break;
            case 'RelatedcontentMetaProperty':
                return <RelatedcontentMetaProperty {...props} />;
                break;
            case 'CheckboxMetaProperty':
                return <CheckboxMetaProperty {...props} />;
                break;
            case 'DateMetaProperty':
                return <DateMetaProperty {...props} />;
                break;
            case 'DatetimeMetaProperty':
                return <DatetimeMetaProperty {...props} />;
                break;
            case 'SelectentryMetaProperty':
                return <SelectentryMetaProperty {...props} />;
                break;
            case 'JsonMetaProperty':
                return <JsonMetaProperty {...props} />;
                break;
            case 'FileMetaProperty':
                return <FileMetaProperty {...props} />;
                break;
            case 'SecuretextMetaProperty':
                return <SecuretextMetaProperty {...props} />;
                break;
            case 'RelatedentriesMetaProperty':
                return <RelatedentriesMetaProperty {...props} />;
                break;
        }
    }
}

let m;
if (window && window._app_meta) {
    m = new MetaProperties(window._app_meta);
} else {
    m = new MetaProperties;
}

export default m;