// Generated by CoffeeScript 1.12.7
var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
  hasProp = {}.hasOwnProperty;

ez5.CasterGazetteer = (function(superClass) {
  extend(CasterGazetteer, superClass);

  function CasterGazetteer() {
    return CasterGazetteer.__super__.constructor.apply(this, arguments);
  }

  CasterGazetteer.prototype.__initCasters = function() {
    return [
      {
        name: $$("custom.data.type.gazetteer.name.caster.name"),
        description: $$("custom.data.type.gazetteer.name.caster.description"),
        canCast: (function(_this) {
          return function(from, to) {
            return !(from instanceof LocaTextColumn) && from instanceof TextColumn && to instanceof CustomDataTypeGazetteer;
          };
        })(this),
        doCast: (function(_this) {
          return function(value) {
            var deferred, gazId;
            gazId = CUI.util.getInt(value);
            if (CUI.util.isNull(gazId)) {
              return;
            }
            deferred = new CUI.Deferred();
            ez5.GazetteerUtil.searchById(gazId).done(function(dataFound) {
              var newData;
              newData = {};
              ez5.GazetteerUtil.setObjectData(newData, dataFound);
              return deferred.resolve(newData);
            }).fail(function() {
              return deferred.resolve();
            });
            return deferred.promise();
          };
        })(this)
      }
    ];
  };

  return CasterGazetteer;

})(ez5.CasterPlugin);

ez5.session_ready(function() {
  var ref;
  return (ref = ez5.ScriptRunner.FieldsMigrator.casterPlugins) != null ? ref.registerPlugin(ez5.CasterGazetteer) : void 0;
});
