// Generated by CoffeeScript 1.6.1
(function() {

  this.Conditional = (function() {

    function Conditional(element, callerElId) {
      var dependencies;
      this.el = $(element).find('.conditional-wrapper');
      this.callerElId = callerElId;
      if (callerElId !== void 0) {
        dependencies = this.el.data('depends');
        if ((typeof dependencies === 'string') && (dependencies.length > 0) && (dependencies.indexOf(callerElId) === -1)) {
          return;
        }
      }
      this.url = this.el.data('url');
      if (this.url) {
        this.render(element);
      }
    }

    Conditional.prototype.render = function(element) {
      var _this = this;
      return $.postWithPrefix("" + this.url + "/conditional_get", function(response) {
        var i, parentEl, parentId, _i, _len, _ref;
        _this.el.html('');
        _ref = response.html;
        for (_i = 0, _len = _ref.length; _i < _len; _i++) {
          i = _ref[_i];
          _this.el.append(i);
        }
        parentEl = $(element).parent();
        parentId = parentEl.attr('id');
        if (response.message === false) {
          if (parentEl.hasClass('vert')) {
            parentEl.hide();
          } else {
            $(element).hide();
          }
        } else {
          if (parentEl.hasClass('vert')) {
            parentEl.show();
          } else {
            $(element).show();
          }
        }
        return XBlock.initializeBlocks(_this.el);
      });
    };

    return Conditional;

  })();

}).call(this);
