o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1381142257.680385: @value"{I" class:EFI"ProcessedAsset;FI"logical_path;FI"8locomotive/views/shared/fields/many_to_many_view.js;TI" pathname;FI"/Users/papipo/.rvm/gems/ruby-1.9.3-p448/gems/locomotive_cms-2.1.0/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee;TI"content_type;FI"application/javascript;FI" mtime;FI"2013-10-07T10:55:40+02:00;FI" length;FiI" digest;F"%ee9157f87b82ff5c4c51d328d9021be8I" source;FI"(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()()); 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).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;F"%c095809eb307fdf64b6e8ab99f54d9edI"required_paths;F[I"/Users/papipo/.rvm/gems/ruby-1.9.3-p448/gems/locomotive_cms-2.1.0/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee;TI"dependency_paths;F[{I" path;FI"/Users/papipo/.rvm/gems/ruby-1.9.3-p448/gems/locomotive_cms-2.1.0/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee;TI" mtime;FI"2013-10-07T10:55:40+02:00;FI" digest;F"%97b9e0db8f2aa513b9790d8e73d555e0I" _version;F"%ffd318ca8b794f42f5029101c2cf5d91