// Generated by CoffeeScript 1.12.7
var ExampleCustomDataType,
  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;

ExampleCustomDataType = (function(superClass) {
  extend(ExampleCustomDataType, superClass);

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

  ExampleCustomDataType.prototype.getCustomDataTypeName = function() {
    return "custom:base.example-plugin.slider";
  };

  ExampleCustomDataType.prototype.getCustomDataOptionsInDatamodelInfo = function(custom_settings) {
    if (custom_settings.range) {
      return [
        $$("example.custom.data.type.datamodel_info", {
          from: custom_settings.range.from,
          to: custom_settings.range.to
        })
      ];
    } else {
      return [];
    }
  };

  ExampleCustomDataType.prototype.initData = function(data) {
    if (!data[this.name()]) {
      return data[this.name()] = {};
    }
  };

  ExampleCustomDataType.prototype.renderDetailOutput = function(data, top_level_data, opts) {
    var cdata;
    cdata = data[this.name()];
    return new CUI.Label({
      "class": this.__getClass(),
      text: cdata.value + " [" + cdata.description + "]"
    });
  };

  ExampleCustomDataType.prototype.__getClass = function() {
    var mask_settings, ref;
    mask_settings = this.getCustomMaskSettings();
    return ["ez5-example-custom-data-type", "ez5-example-custom-data-type--" + (((ref = mask_settings.appearance) != null ? ref.color : void 0) || "red")].join(" ");
  };

  ExampleCustomDataType.prototype.renderEditorInput = function(data, top_level_data, opts) {
    var cdata, custom_settings, form, mask_settings;
    custom_settings = this.getCustomSchemaSettings();
    mask_settings = this.getCustomMaskSettings();
    console.debug("mask settings:", this.__getClass(), mask_settings);
    this.initData(data);
    cdata = data[this.name()];
    form = new CUI.Form({
      data: cdata,
      "class": this.__getClass(),
      fields: [
        {
          form: {
            label: $$("example.custom.data.type.input.value")
          },
          type: CUI.Slider,
          name: "value"
        }, {
          type: CUI.Input,
          name: "description"
        }
      ],
      onDataChanged: (function(_this) {
        return function() {
          return CUI.Events.trigger({
            node: form,
            type: "editor-changed"
          });
        };
      })(this)
    }).start();
    return form;
  };

  ExampleCustomDataType.prototype.getSaveData = function(data, save_data, opts) {
    var cdata, ref;
    cdata = data[this.name()] || ((ref = data._template) != null ? ref[this.name()] : void 0);
    save_data[this.name()] = CUI.util.copyObject(cdata, true);
  };

  return ExampleCustomDataType;

})(CustomDataType);

CustomDataType.register(ExampleCustomDataType);
