o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1396088393.830127: @value"§){I" class:ETI"ProcessedAsset;FI"logical_path;TI"3locomotive/views/content_assets/picker_view.js;FI" pathname;TI"ª/Users/didier/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/engine-c0bddd719ddf/app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee;FI"content_type;TI"application/javascript;TI" mtime;TI"2014-03-29T11:18:01+01:00;TI" length;Ti~#I" digest;TI"%52cac0f536977398589f988dde9dd5a3;FI" source;TI"~#(function() { var _base, __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).ContentAssets || (_base.ContentAssets = {}); Locomotive.Views.ContentAssets.PickerView = (function(_super) { __extends(PickerView, _super); function PickerView() { return PickerView.__super__.constructor.apply(this, arguments); } PickerView.prototype.number_items_per_row = 4; PickerView.prototype.page = 1; PickerView.prototype.per_page = 12; PickerView.prototype.total_pages = null; PickerView.prototype.uploading = false; PickerView.prototype._item_views = []; PickerView.prototype.events = { 'click .btn': 'toggle_filter_by_type', 'change input[name=query]': 'fetch_assets' }; PickerView.prototype.render = function() { PickerView.__super__.render.apply(this, arguments); this.enable_dropzone(); this.enable_infinite_scroll(); return this; }; PickerView.prototype.template = function() { return ich.content_asset_picker; }; PickerView.prototype.fetch_assets = function(event) { var xhr; this._reset(); xhr = this.collection.fetch({ data: this._fetch_options(), reset: true, success: (function(_this) { return function() { return _this.open(); }; })(this) }); return xhr.done((function(_this) { return function() { return _this._get_pagination_info(xhr); }; })(this)); }; PickerView.prototype.toggle_filter_by_type = function(event) { $(event.target).toggleClass('on'); return this.fetch_assets(); }; PickerView.prototype.build_uploader = function(el, link) { link.bind('click', function(event) { event.stopPropagation() & event.preventDefault(); return el.click(); }); return el.bind('change', (function(_this) { return function(event) { return _this._persist_files(event); }; })(this)); }; PickerView.prototype.add_asset = function(asset, first) { var view; view = new Locomotive.Views.ContentAssets.PickerItemView({ model: asset, parent: this }); (this._item_views || (this._item_views = [])).push(view); if (this.uploading) { this.$('ul.list').prepend(view.render().el); return this._refresh(); } else { this.$('ul.list .clear').before(view.render().el); this._refresh(); if (first !== true) { return this._move_to_last_asset(); } } }; PickerView.prototype.enable_dropzone = function() { var dropzone; if (!(window.File && window.FileList && window.FileReader)) { return; } dropzone = this.$('ul.list').parent(); dropzone.on('dragover', (function(_this) { return function(event) { _this._stop_event(event); return dropzone.addClass('hovered'); }; })(this)); dropzone.on('dragleave', (function(_this) { return function(event) { _this._stop_event(event); return dropzone.removeClass('hovered'); }; })(this)); dropzone.on('dragenter', (function(_this) { return function(event) { return _this._stop_event(event); }; })(this)); return dropzone.on('drop', (function(_this) { return function(event) { _this._stop_event(event); dropzone.removeClass('hovered'); return _this._persist_files(event); }; })(this)); }; PickerView.prototype.enable_infinite_scroll = function() { var $list; $list = this.$('ul.list'); return $list.on('scroll', (function(_this) { return function(event) { if (_this.throttle_timer != null) { clearTimeout(_this.throttle_timer); } return _this.throttle_timer = setTimeout(function() { var height, isScrolledToEnd, scroll, xhr; height = $list[0].scrollHeight - $list.innerHeight(); scroll = $list.scrollTop(); isScrolledToEnd = scroll >= height; if (isScrolledToEnd && _this.page < _this.total_pages) { _this.page += 1; xhr = _this.collection.fetch({ data: { page: _this.page, per_page: _this.per_page }, success: function() { _this._refresh(); return $list.scrollTop(scroll); } }); return xhr.done(function() { return _this._get_pagination_info(xhr); }); } }, 100); }; })(this)); }; PickerView.prototype.remove_asset = function(asset) { var view; view = _.find(this._item_views, function(tmp) { return tmp.model === asset; }); if (view != null) { view.remove(); } return this._refresh(); }; PickerView.prototype.dialog_class = function() { return 'content-asset-picker-dialog'; }; PickerView.prototype._fetch_options = function() { return _.tap({ per_page: this.per_page }, (function(_this) { return function(options) { options.types = []; _this.$('.asset-types .btn.on').each(function() { return options.types.push($(this).data('type')); }); return options.query = _this.$('input[name=query]').val(); }; })(this)); }; PickerView.prototype._persist_files = function(event) { var files; files = event.target.files || event.originalEvent.dataTransfer.files; this._move_to_top(); this.uploading = true; _.each(files, (function(_this) { return function(file) { var asset, view; asset = new Locomotive.Models.ContentAsset({ uploading: true, source: file }); _this.collection.add(asset.prepare(), { at: 0 }); view = _this._find_view_by_asset(asset); return asset.save({}, { headers: { 'X-Flash': true }, success: function(model, response) { asset.set({ uploading: false }); asset.prepare(); return view.refresh(); }, error: function() { return _this.shake(); }, progress: function(loaded, total) { return view.uploaded_at(loaded, total); } }); }; })(this)); this.uploading = false; return this._recalculate_pagination(_.size(files)); }; PickerView.prototype._recalculate_pagination = function(number_assets_added) { var number_assets_to_delete, previous_total_pages; previous_total_pages = this.total_pages; if (this.page < this.total_pages) { number_assets_to_delete = number_assets_added % this.per_page; while (number_assets_to_delete -= 1) { this.collection.pop(); } } this.total_entries += number_assets_added; this.total_pages = Math.ceil(this.total_entries / this.per_page); if (this.page === previous_total_pages || previous_total_pages === 0) { return this.page = this.total_pages; } }; PickerView.prototype._on_refresh = function() { var self; self = this; return this.$('ul.list li.asset').each(function(index) { if ((index + 1) % self.number_items_per_row === 0) { return $(this).addClass('last'); } else { return $(this).removeClass('last'); } }); }; PickerView.prototype._find_view_by_asset = function(asset) { return _.find(this._item_views || [], function(view) { return view.model.cid === asset.cid; }); }; PickerView.prototype._stop_event = function(event) { return event.stopPropagation() & event.preventDefault(); }; PickerView.prototype._get_pagination_info = function(xhr) { this.total_pages = parseInt(xhr.getResponseHeader('X-Total-Pages')); this.per_page = parseInt(xhr.getResponseHeader('X-Per-Page')); return this.total_entries = parseInt(xhr.getResponseHeader('X-Total-Entries')); }; PickerView.prototype._reset = function() { this.page = 1; this.total_pages = null; _.each(this._item_views || [], function(view) { return view.remove(); }); return PickerView.__super__._reset.call(this); }; return PickerView; })(Locomotive.Views.Shared.AssetPickerView); }).call(this); ;TI"dependency_digest;TI"%0f4be13beb091f8260b61c9e45c79860;FI"required_paths;T[I"¨/Users/didier/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/engine-c0bddd719ddf/app/assets/javascripts/locomotive/views/shared/asset_picker_view.js.coffee;FI"ª/Users/didier/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/engine-c0bddd719ddf/app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee;FI"dependency_paths;T[{I" path;TI"ª/Users/didier/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/engine-c0bddd719ddf/app/assets/javascripts/locomotive/views/content_assets/picker_view.js.coffee;FI" mtime;TI"2014-03-29T11:18:01+01:00;TI" digest;TI"%fee85aab5138af14b0ca012f9f544b4d;F{I" path;TI"¨/Users/didier/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/engine-c0bddd719ddf/app/assets/javascripts/locomotive/views/shared/asset_picker_view.js.coffee;FI" mtime;TI"2014-03-29T11:18:01+01:00;TI" digest;TI"%27e3e984571c5c13f4806c59ed07ca5c;FI" _version;TI"%ffd318ca8b794f42f5029101c2cf5d91;F