o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1384093247.229198: @value"©{I" class:ETI"ProcessedAsset;FI"logical_path;TI"8locomotive/views/shared/fields/many_to_many_view.js;FI" pathname;TI"~/Users/didier/Documents/LocomotiveCMS/engine/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;TI"2013-07-06T11:40:04+02:00;TI" length;TiÌI" digest;TI"%22df1b1b6042756fd55324fd3c6fb27a;FI" source;TI"Ì(function() { var _base, _base1, _ref, __hasProp = {}.hasOwnProperty, __extends = 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; }; (_base = Locomotive.Views).Shared || (_base.Shared = {}); (_base1 = Locomotive.Views.Shared).Fields || (_base1.Fields = {}); Locomotive.Views.Shared.Fields.ManyToManyView = (function(_super) { __extends(ManyToManyView, _super); function ManyToManyView() { _ref = ManyToManyView.__super__.constructor.apply(this, arguments); return _ref; } ManyToManyView.prototype.tagName = 'div'; ManyToManyView.prototype.className = 'list'; ManyToManyView.prototype.events = { 'click .new-entry a.add': 'add_entry', 'keypress .new-entry select': 'add_entry', 'click ul span.actions a.remove': 'remove_entry' }; ManyToManyView.prototype.template = function() { return ich["" + this.options.name + "_list"]; }; ManyToManyView.prototype.entry_template = function() { return ich["" + this.options.name + "_entry"]; }; ManyToManyView.prototype.initialize = function() { _.bindAll(this, 'refresh_position_entries'); this.collection = this.model.get(this.options.name); return this.all_entries = this.options.all_entries; }; ManyToManyView.prototype.render = function() { $(this.el).html(this.template()()).attr('id', "" + this.model.paramRoot + "_" + this.options.name + "_ids"); this.insert_entries(); this.make_entries_sortable(); this.refresh_select_field(); return this; }; ManyToManyView.prototype.ui_enabled = function() { return this.template() != null; }; ManyToManyView.prototype.insert_entries = function() { var _this = this; if (this.collection.length > 0) { return this.collection.each(function(entry) { return _this.insert_entry(entry); }); } else { return this.$('.empty').show(); } }; ManyToManyView.prototype.insert_entry = function(entry) { var entry_html; if (this.collection.get(entry.get('_id')) == null) { this.collection.add(entry); } this.$('.empty').hide(); entry_html = $(this.entry_template()({ label: entry.get('_label') })); entry_html.data('data-entry-id', entry.id); return this.$('> ul').append(entry_html); }; ManyToManyView.prototype.make_entries_sortable = function() { return this.sortable_list = this.$('> ul').sortable({ handle: '.handle', items: 'li', axis: 'y', update: this.refresh_position_entries }); }; ManyToManyView.prototype.refresh_position_entries = function() { var _this = this; return this.$('> ul > li').each(function(index, entry_html) { var entry, id; id = $(entry_html).data('data-entry-id'); entry = _this.collection.get(id); return entry.set_attribute("__position", index); }); }; ManyToManyView.prototype.add_entry = function(event) { var entry, entry_id; event.stopPropagation() & event.preventDefault(); entry_id = this.$('.new-entry select').val(); entry = this.get_entry_from_id(entry_id); if (entry == null) { return; } this.insert_entry(entry); return this.refresh_select_field(); }; ManyToManyView.prototype.remove_entry = function(event) { var entry; event.stopPropagation() & event.preventDefault(); if (confirm($(event.target).closest('a').data('confirm'))) { entry = this.get_entry_from_element($(event.target)); this.collection.remove(entry); $(event.target).closest('li').remove(); if (this.$('> ul > li').size() === 0) { this.$('.empty').show(); } return this.refresh_position_entries() & this.refresh_select_field(); } }; ManyToManyView.prototype.refresh_select_field = function() { var _this = this; this.$('.new-entry select optgroup, .new-entry select option').remove(); return _.each(this.all_entries, function(entry_or_group) { var group_html, option; if (_.isArray(entry_or_group.entries)) { group_html = $('').attr('label', entry_or_group.name); _.each(entry_or_group.entries, function(entry) { var option; if (_this.collection.get(entry._id) == null) { option = new Option(entry._label, entry._id, false); return group_html.append(option); } }); return _this.$('.new-entry select').append(group_html); } else { if (_this.collection.get(entry_or_group._id) == null) { option = new Option(entry_or_group._label, entry_or_group._id, false); return _this.$('.new-entry select').append(option); } } }); }; ManyToManyView.prototype.get_entry_from_element = function(element) { var entry_html, id; entry_html = $(element).closest('li'); id = $(entry_html).data('data-entry-id'); return this.collection.get(id); }; ManyToManyView.prototype.get_entry_from_id = function(id) { var entry, _this = this; entry = null; _.each(this.all_entries, function(entry_or_group) { if (_.isArray(entry_or_group.entries)) { return entry || (entry = _.detect(entry_or_group.entries, function(_entry) { return _entry._id === id; })); } else { if (entry_or_group._id === id) { return entry = entry_or_group; } } }); if (entry != null) { return new Locomotive.Models.ContentEntry(entry); } else { return null; } }; return ManyToManyView; })(Backbone.View); }).call(this); ;TI"dependency_digest;TI"%44764c3fcbdfc4b32862d9d925df78d2;FI"required_paths;T[I"~/Users/didier/Documents/LocomotiveCMS/engine/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee;FI"dependency_paths;T[{I" path;TI"~/Users/didier/Documents/LocomotiveCMS/engine/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee;FI" mtime;TI"2013-07-06T11:40:04+02:00;TI" digest;TI"%46decb93dc7e08b0755e076af2553870;FI" _version;TI"%ffd318ca8b794f42f5029101c2cf5d91;F