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

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

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

  BaseMigrationNodePreset.prototype.initOpts = function() {
    BaseMigrationNodePreset.__super__.initOpts.call(this);
    return this.addOpts({
      context: {
        mandatory: true
      }
    });
  };

  BaseMigrationNodePreset.prototype.getDisplayText = function() {
    return ez5.loca.getBestFrontendValue(this.getData().right_preset.displayname);
  };

  BaseMigrationNodePreset.getSourceNodesFromData = function(migration, data) {
    var children, context, contextChildren, contextData, i, len, preset;
    children = [];
    for (context in data) {
      contextData = data[context];
      contextChildren = [];
      for (i = 0, len = contextData.length; i < len; i++) {
        preset = contextData[i];
        contextChildren.push(new BaseMigrationNodePreset({
          migration: migration,
          data: preset,
          context: context
        }));
      }
      children.push(new BaseMigrationNodePresetContext({
        migration: migration,
        context: context,
        children: contextChildren
      }));
    }
    return [
      new BaseMigrationNodePresets({
        migration: migration,
        children: children
      })
    ];
  };

  BaseMigrationNodePreset.prototype.getActionPane = function() {
    var pane;
    pane = this.getActionPaneBase();
    return pane;
  };

  BaseMigrationNodePreset.prototype.checkMigrateButton = function() {
    return this.__migrateBtn.enable();
  };

  BaseMigrationNodePreset.prototype.getActionFields = function() {
    return [
      {
        type: CUI.Output,
        form: {
          label: this.children ? $$("base.migration.node.presets.text") : $$("base.migration.node.preset.text")
        },
        text: this.getDisplayText()
      }
    ];
  };

  BaseMigrationNodePreset.prototype.migrate = function() {
    var position, presetData;
    position = BaseMigrationNodePresetContext.prototype.getNextPresetPosition.apply(this);
    presetData = this.getPreset(position);
    return BaseMigrationNodePresetContext.prototype.savePresets.apply(this, [[presetData]]);
  };

  BaseMigrationNodePreset.prototype.getPreset = function(position) {
    var data;
    data = this.getData();
    data.right_preset._position = position;
    data.right_preset._version = 1;
    delete data.right_preset._id;
    return data;
  };

  return BaseMigrationNodePreset;

})(BaseMigrationNodeData);
