{I" class:ETI"BundledAsset;FI"logical_path;TI"basepack/forms/query.js;FI" pathname;TI"U/home/lukas/projects/basepack/app/assets/javascripts/basepack/forms/query.coffee;FI"content_type;TI"application/javascript;TI" mtime;Tl+p zSI" length;Ti|I" digest;TI"%2670ff3018602315348c2687545c25a9;FI" source;TI"|(function() { Basepack.QueryForm = (function() { function QueryForm($container, $menu) { var that; this.$container = $container; this.$filters = this.$container.find(".filters"); this.$menu = $menu; this.options = { regional: { datePicker: { dateFormat: "mm/dd/yy" } }, predicates: {}, enum_options: {} }; that = this; this.$menu.on("click", "a[data-field-label]", function(e) { e.preventDefault(); return that.append($(this).data("field-label"), $(this).data("field-name"), $(this).data("field-type"), $(this).data("field-value"), $(this).data("field-operator"), $(this).data("field-template"), $.now().toString().slice(6, 11)); }); this.$container.on("click", ".delete", function(e) { var form; e.preventDefault(); form = $(this).parents("form"); $(this).parents(".filter").remove(); return !that.$filters.children().length && that.$container.hide("fast"); }); this.$container.on("change", ".predicate", function(e) { return that.setup_additional_control($(this)); }); } QueryForm.prototype.setup = function(data) { var field, i, _i, _len, _ref, _results; this.options = data.options; _ref = data.initial; _results = []; for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { field = _ref[i]; _results.push(this.append(field.label, field.name, field.type, field.value, field.predicate, field.template, i)); } return _results; }; QueryForm.prototype.setup_additional_control = function($predicate_select) { var selected_option; selected_option = $predicate_select.find("option:selected"); if ($(selected_option).data("type") === "boolean") { $predicate_select.siblings(".additional-fieldset").prop("disabled", true).hide(); $predicate_select.siblings(".textarea-value").prop("disabled", true).hide(); return $predicate_select.siblings(".boolean-value").prop("disabled", false); } else { $predicate_select.siblings(".boolean-value").prop("disabled", true); if ($predicate_select.val() === "one_of") { $predicate_select.siblings(".textarea-value").prop("disabled", false).show(); return $predicate_select.siblings(".additional-fieldset").prop("disabled", true).hide(); } else { $predicate_select.siblings(".textarea-value").prop("disabled", true).hide(); return $predicate_select.siblings(".additional-fieldset").prop("disabled", false).show(); } } }; QueryForm.prototype.select_option = function(name, selected, options, klass) { var html; html = (""; }; QueryForm.prototype.select_predicate = function(name, value, options, klass) { return JST["basepack/forms/query/predicate"]({ name: name, value: value, options: options, klass: klass, predicates: this.options.predicates, selected: value || "cont" }); }; QueryForm.prototype.append = function(field_label, field_name, field_type, field_value, field_predicate, field_template, index) { var additional_control, condition_name, content, control, el, form, name_control, operator_name, value_name, _i, _len, _ref; condition_name = "f[c][" + index + "][a][0][name]"; value_name = "f[c][" + index + "][v][0][value]"; operator_name = "f[c][" + index + "][p]"; if (field_template) { control = _.template(field_template)({ label: field_label, type: field_type, value: field_value || "", predicate: field_predicate, index: index, name: value_name, field_name: field_name, condition_name: condition_name, operator_name: operator_name, select_option: this.select_option }); } else { switch (field_type) { case "boolean": control = this.select_predicate(operator_name, field_predicate || "true", ["true", "false", "null", "not_null"]); break; case "date": case "datetime": case "timestamp": control = this.select_predicate(operator_name, field_predicate || "eq", ["eq", "not_eq", "lt", "lteq", "gt", "gteq", "present", "blank", "null", "not_null"]); additional_control = JST["basepack/forms/query/date"]({ name: value_name, value: field_value }); break; case "enum": control = this.select_predicate(operator_name, field_predicate || "eq", ["eq", "not_eq", "null", "not_null"]); additional_control = this.select_option(value_name, field_value, this.options.enum_options[field_name] || []); break; case "string": case "text": case "belongs_to_association": control = this.select_predicate(operator_name, field_predicate || "cont", ["eq", "not_eq", "matches", "does_not_match", "cont", "not_cont", "start", "not_start", "end", "not_end", "present", "blank", "one_of", "null", "not_null"]); additional_control = " "; break; case "integer": case "decimal": case "float": control = this.select_predicate(operator_name, field_predicate || "eq", ["eq", "not_eq", "lt", "lteq", "gt", "gteq", "one_of", "null", "not_null"]); additional_control = " "; break; case "ql": name_control = " "; control = ""; break; default: control = ""; additional_control = " "; } } content = JST["basepack/forms/query/filter"]({ index: index, name_control: name_control, condition_name: condition_name, field_name: field_name, field_label: field_label, control: control, additional_control: additional_control, value_name: value_name, field_value: field_value }); this.$filters.append(content); this.$container.show("fast"); this.$filters.find(".filter-" + index + " .date").datepicker(this.options.regional.datePicker); _ref = this.$filters.find(".predicate[name=\"" + operator_name + "\"]"); for (_i = 0, _len = _ref.length; _i < _len; _i++) { el = _ref[_i]; this.setup_additional_control($(el)); } form = new Basepack.Form(this.$filters.find(".filter-" + index)); return form.bind(); }; return QueryForm; })(); }).call(this); ;TI"required_assets_digest;TI"%81e65ca3210eededa1e70d49579aade2;FI" _version;TI"%361c512b9086418778df946c0d278f91;F