Exemple #1
0
      _.each(attributes, function(value, key, list) {
        //Column
        var column = structure.get(key);

        // Don't validate hidden fields
        // @todo should this be adjusted since these fields are now posting in some cases?
        if (column.get('hidden_input')) {
          return;
        }

        // Don't validate ID
        if (key === 'id') {
          return;
        }

        var nullDisallowed = column.get('is_nullable') === 'NO';
        var isNull = isNothing(value);

        var uiSettings = UIManager.getSettings(column.get('ui'));

        var skipSerializationIfNull = uiSettings.skipSerializationIfNull;

        var mess = (!skipSerializationIfNull && nullDisallowed && isNull) ?
          'The field cannot be empty'
          : UIManager.validate(this, key, value);

        if (mess !== undefined) {
          errors.push({attr: key, message: mess});
        }
      }, this);
Exemple #2
0
    comparator: function(rowA, rowB) {
      var UIManager = require('core/UIManager');
      var column = this.getFilter('sort') || 'id';
      var valueA, valueB;

      // @todo find a better way to check is a entriesjunctioncollection
      if(rowA.collection.nestedCollection && ['sort', 'id'].indexOf(column) < 0) {
        rowA = rowA.get('data');
        rowB = rowB.get('data');
      }

      if (UIManager.hasList(rowA, column)) {
        // Sort relational columns in listview https://github.com/RNGR/Directus/issues/452
        valueA = UIManager.getList(rowA, column) || '';
        valueB = UIManager.getList(rowB, column) || '';
      } else {
        valueA = rowA.get(column);
        valueB = rowB.get(column);
      }

      var options, ui, type, schema;

      //There is no value
      if (!rowA.has(column)) {
        if (this.structure && this.structure.get(column) !== undefined) {
          schema = this.structure.get(column);
          ui = schema.get('ui');

          options = UIManager.getSettings(ui);
          if (options.length > 0) {

            //Merge the column values, eg first_name, last_name
            if (_.isArray(options.sortBy)) {
              valueA = _.map(options.sortBy, function(value) { 
                return rowA.get(value);
              }).join('');
              valueB = _.map(options.sortBy, function(value) { 
                return rowB.get(value);
              }).join('');
            } else {
              valueA = rowA.get(options.sortBy);
              valueB = rowB.get(options.sortBy);
            }
          }
        } else {
          valueA = rowA.id;
          valueB = rowB.id;
        }
      }

      // Check if it's a date
      if(app.isStringADate(valueA)) {
        if(!isNaN(Date.parse(valueA))) {
          return this.comparatorValue(new Date(valueA).getTime(), new Date(valueB).getTime());
        }
      }

      return this.comparatorValue(valueA, valueB);
    },