Sha256: 457d59b9f2ed232c1788ff012639000941d30e9e3ae9402991593edfde3ff04f

Contents?: true

Size: 1.8 KB

Versions: 23

Compression:

Stored size: 1.8 KB

Contents

var composed, remoteable, rest, root, stampit, validations;

root = typeof exports !== "undefined" && exports !== null ? exports : window;

validations = require('../validatable');

rest = require('../rest');

stampit = require('../../../vendor/stampit');

remoteable = stampit({
  validate_each: function(record, attribute, value) {
    var data,
      _this = this;

    data = this.json(record);
    return this.post(data).done(function(json) {
      return _this.succeeded(json, record);
    });
  },
  json: function(record) {
    var data, _base;

    data = {};
    data[this.resource] = record.json();
    (_base = data[this.resource]).id || (_base.id = data[this.resource]._id);
    delete data[this.resource]._id;
    return data;
  },
  post: function(data) {
    return jQuery.ajax({
      url: this.route,
      data: data,
      type: 'post',
      dataType: 'json',
      context: this
    });
  },
  succeeded: function(json, record) {
    var error_message, error_messages, _i, _len, _results;

    error_messages = json[this.attribute_name];
    if (!error_messages) {
      return;
    }
    _results = [];
    for (_i = 0, _len = error_messages.length; _i < _len; _i++) {
      error_message = error_messages[_i];
      _results.push(record.errors.add(this.attribute_name, 'server', {
        server_message: error_message
      }));
    }
    return _results;
  }
}, {
  message: "Remote validation failed",
  route: null
}, function() {
  var pluralized_resource;

  pluralized_resource = model.pluralize(this.model.resource);
  this.resource = this.model.resource;
  this.route || (this.route = "/" + pluralized_resource + "/validate");
  return this;
});

composed = stampit.compose(validations.validatable, remoteable);

composed.definition_key = 'validates_remotely';

validations.manager.validators.remote = composed;

Version data entries

23 entries across 14 versions & 1 rubygems

Version Path
ende-0.2.3 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.2 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.1 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.0 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.14 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.14 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.13 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.13 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.12 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.12 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.11 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.11 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.10 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.10 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.9 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.9 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.8 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.8 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.7 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.1.7 vendor/assets/components/indefinido-indemma/lib/record/validations/remote.js