<commit_before>/** @jsx React.DOM */
'use strict';
var React = require('react');
var fetched = require('../fetched');
var globals = require('../globals');
var item = require('./item');
var richtext = require('./richtext');
var _ = require('underscore');

var ReactForms = require('react-forms');
var Schema = ReactForms.schema.Schema;
var Property = ReactForms.schema.Property;

var ItemBlockView = item.ItemBlockView;
var ObjectPicker = require('../inputs').ObjectPicker;
var RichTextBlockView = richtext.RichTextBlockView;


var TeaserCore = React.createClass({
    render: function() {
        var image = this.props.value.image;
        var url;
        if (typeof image === 'string') {
            url = image;
            if (url.indexOf('/') !== 0) {
                url = '/' + url;
            }
        }
        return (
            <div className="teaser thumbnail clearfix">
                {typeof image === 'object' ?
                    <ItemBlockView context={image}/>
                :
                    <fetched.FetchedData>
                        <fetched.Param name="context" url={url} />
                        <ItemBlockView />
                    </fetched.FetchedData>
                }
                <div className="caption" dangerouslySetInnerHTML={{__html: this.props.value.body}}></div>
            </div>
        );
    }
});


var TeaserBlockView = React.createClass({

    getDefaultProps: function() {
        return {value: {
            href: '#',
            image: '',
            body: ' ',
        }};
    },

    shouldComponentUpdate: function(nextProps) {
        return (!_.isEqual(nextProps.value, this.props.value));
    },

    render: function() {
        return (
            <div>
                {this.props.value.href ?
                    <a className="img-link" href={this.props.value.href}>
                        {this.transferPropsTo(<TeaserCore />)}
                    </a>
                :
                    <div>
                        {this.transferPropsTo(<TeaserCore />)}
                    </div>
                }
            </div>
        );
    }
});


var RichEditor = React.createClass({

    childContextTypes: {
        editable: React.PropTypes.bool
    },

    getChildContext: function() {
        return {editable: true};
    },

    getInitialState: function() {
        return {value: {body: this.props.value || '<p></p>'}};
    },

    render: function() {
        return (
            <div className="form-control" style={{height: 'auto'}}>
                {this.transferPropsTo(<RichTextBlockView value={this.state.value} onChange={this.onChange} />)}
            </div>
        );
    },

    onChange: function(value) {
        this.props.onChange(value.body);
    }
});



var displayModeSelect = (
    <div><select>
        <option value="">default</option>
    </select></div>
);
var imagePicker = <ObjectPicker searchBase={"?mode=picker&type=image"} />;

globals.blocks.register({
    label: 'teaser block',
    icon: 'icon icon-image',
    schema: (
        <Schema>
            <Property name="display" label="Display Layout" input={displayModeSelect} defaultValue="search" />
            <Property name="image" label="Image" input={imagePicker} />
            <Property name="body" label="Caption" input={<RichEditor />} />
            <Property name="href" label="Link URL" />
        </Schema>
    ),
    view: TeaserBlockView
}, 'teaserblock');
<commit_msg>No need to worry about plain uuids in path now.<commit_after>/** @jsx React.DOM */
'use strict';
var React = require('react');
var fetched = require('../fetched');
var globals = require('../globals');
var item = require('./item');
var richtext = require('./richtext');
var _ = require('underscore');

var ReactForms = require('react-forms');
var Schema = ReactForms.schema.Schema;
var Property = ReactForms.schema.Property;

var ItemBlockView = item.ItemBlockView;
var ObjectPicker = require('../inputs').ObjectPicker;
var RichTextBlockView = richtext.RichTextBlockView;


var TeaserCore = React.createClass({
    render: function() {
        var image = this.props.value.image;
        // Must work with both paths (edit form) and embedded objects (display)
        return (
            <div className="teaser thumbnail clearfix">
                {typeof image === 'object' ?
                    <ItemBlockView context={image}/>
                :
                    <fetched.FetchedData>
                        <fetched.Param name="context" url={image} />
                        <ItemBlockView />
                    </fetched.FetchedData>
                }
                <div className="caption" dangerouslySetInnerHTML={{__html: this.props.value.body}}></div>
            </div>
        );
    }
});


var TeaserBlockView = React.createClass({

    getDefaultProps: function() {
        return {value: {
            href: '#',
            image: '',
            body: ' ',
        }};
    },

    shouldComponentUpdate: function(nextProps) {
        return (!_.isEqual(nextProps.value, this.props.value));
    },

    render: function() {
        return (
            <div>
                {this.props.value.href ?
                    <a className="img-link" href={this.props.value.href}>
                        {this.transferPropsTo(<TeaserCore />)}
                    </a>
                :
                    <div>
                        {this.transferPropsTo(<TeaserCore />)}
                    </div>
                }
            </div>
        );
    }
});


var RichEditor = React.createClass({

    childContextTypes: {
        editable: React.PropTypes.bool
    },

    getChildContext: function() {
        return {editable: true};
    },

    getInitialState: function() {
        return {value: {body: this.props.value || '<p></p>'}};
    },

    render: function() {
        return (
            <div className="form-control" style={{height: 'auto'}}>
                {this.transferPropsTo(<RichTextBlockView value={this.state.value} onChange={this.onChange} />)}
            </div>
        );
    },

    onChange: function(value) {
        this.props.onChange(value.body);
    }
});



var displayModeSelect = (
    <div><select>
        <option value="">default</option>
    </select></div>
);
var imagePicker = <ObjectPicker searchBase={"?mode=picker&type=image"} />;

globals.blocks.register({
    label: 'teaser block',
    icon: 'icon icon-image',
    schema: (
        <Schema>
            <Property name="display" label="Display Layout" input={displayModeSelect} defaultValue="search" />
            <Property name="image" label="Image" input={imagePicker} />
            <Property name="body" label="Caption" input={<RichEditor />} />
            <Property name="href" label="Link URL" />
        </Schema>
    ),
    view: TeaserBlockView
}, 'teaserblock');

{'fraction_non_alphanumeric': 0.14931466899970838, 'fraction_numerical': 0.00014581510644502772, 'mean_word_length': 1.9075879610004238, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1553517', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1877, 'n_words': 375}