Sha256: 23ae8b70c68ff1352821785ec703a5d0065cf90f7c76c08b66a1d090151754ef

Contents?: true

Size: 1.85 KB

Versions: 36

Compression:

Stored size: 1.85 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, param, _base;

    param = this.resource.param_name || this.resource.toString();
    data = {};
    data[param] = record.json();
    (_base = data[param]).id || (_base.id = data[param]._id);
    delete data[param]._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.toString());
  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

36 entries across 36 versions & 1 rubygems

Version Path
ende-0.3.13 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.12 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.11 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.10 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.9 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.8 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.7 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.6 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.5 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.4 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.3 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.2 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.1 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.3.0 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.21 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.20 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.19 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.18 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.17 vendor/components/indefinido-indemma/lib/record/validations/remote.js
ende-0.2.16 vendor/components/indefinido-indemma/lib/record/validations/remote.js