Example #1
0
  constructor(props) {
    super(props);

    this.state = {
      isLoading: false,

      title: '',
      category: null,
      categories: props.categories,
      weight: 0,
      is_hidden: 0,
      is_closed: false,

      validators: {
        title: [
          validators.required()
        ]
      },

      errors: {}
    };

    this.isHiddenChoices = [
      {
        'value': 0,
        'icon': 'visibility',
        'label': gettext("No")
      },
      {
        'value': 1,
        'icon': 'visibility_off',
        'label': gettext("Yes")
      },
    ];

    this.isClosedChoices = [
      {
        'value': false,
        'icon': 'lock_outline',
        'label': gettext("No")
      },
      {
        'value': true,
        'icon': 'lock',
        'label': gettext("Yes")
      },
    ];

    this.acl = {};
    this.props.categories.forEach((category) => {
      if (category.post) {
        if (!this.state.category) {
          this.state.category = category.id;
        }

        this.acl[category.id] = {
          can_pin_threads: category.post.pin,
          can_close_threads: category.post.close,
          can_hide_threads: category.post.hide,
        };
      }
    });
  }
Example #2
0
File: merge.js Project: l0ud/Misago
  constructor(props) {
    super(props);

    this.state = {
      isLoading: false,

      title: '',
      category: null,
      weight: 0,
      is_hidden: 0,
      is_closed: false,

      validators: {
        title: [
          validators.required()
        ]
      },

      errors: {}
    };

    this.acl = {};
    for (const i in props.user.acl.categories) {
      if (!props.user.acl.categories.hasOwnProperty(i)) {
        continue;
      }

      const acl = props.user.acl.categories[i];
      this.acl[acl.id] = acl;
    }

    this.categoryChoices = [];
    props.categories.forEach((category) => {
      if (category.level > 0) {
        const acl = this.acl[category.id];
        const disabled = !acl.can_start_threads || (category.is_closed && !acl.can_close_threads);

        this.categoryChoices.push({
          value: category.id,
          disabled: disabled,
          level: category.level - 1,
          label: category.name
        });

        if (!disabled && !this.state.category) {
          this.state.category = category.id;
        }
      }
    });

    this.isHiddenChoices = [
      {
        'value': 0,
        'icon': 'visibility',
        'label': gettext("No")
      },
      {
        'value': 1,
        'icon': 'visibility_off',
        'label': gettext("Yes")
      },
    ];

    this.isClosedChoices = [
      {
        'value': false,
        'icon': 'lock_outline',
        'label': gettext("No")
      },
      {
        'value': true,
        'icon': 'lock',
        'label': gettext("Yes")
      },
    ];
  }
Example #3
0
import React from "react"
import { required } from "misago/utils/validators"
import snackbar from "misago/services/snackbar"

let validateRequired = required()

export default class extends React.Component {
  validate() {
    let errors = {}
    if (!this.state.validators) {
      return errors
    }

    let validators = {
      required: this.state.validators.required || this.state.validators,
      optional: this.state.validators.optional || {}
    }

    let validatedFields = []

    // add required fields to validation
    for (let name in validators.required) {
      if (
        validators.required.hasOwnProperty(name) &&
        validators.required[name]
      ) {
        validatedFields.push(name)
      }
    }

    // add optional fields to validation