diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-07 00:21:02 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-02-07 00:21:02 +0100 |
commit | 467f320d98fd9279d234b9aea1b8fbf19f710900 (patch) | |
tree | 347b6edf614236e3a239b9382f89720b3215eced /js | |
parent | 8c1ee2f48b040b8d679c2fc1d38e8b9582b6b691 (diff) |
moved from cakefile to grunt
Diffstat (limited to 'js')
-rw-r--r-- | js/app.js | 2396 |
1 files changed, 1388 insertions, 1008 deletions
@@ -1,7 +1,8 @@ -// Generated by CoffeeScript 1.3.3 +(function(angular, $, OC, oc_requesttoken){ + /* -# ownCloud - News app +# ownCloud # # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> @@ -12,42 +13,31 @@ */ -(function() { - var app, markingRead, scrolling, - __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; }; +/* +# Various config stuff for owncloud +*/ - app = angular.module('News', []).config(function($provide) { - var config; - config = { - MarkReadTimeout: 500, - ScrollTimeout: 500, - initialLoadedItemsNr: 20, - FeedUpdateInterval: 6000000 - }; - return $provide.value('Config', config); - }); - app.run([ - 'PersistenceNews', function(PersistenceNews) { - return PersistenceNews.loadInitial(); +(function() { + + angular.module('OC', []).config([ + '$httpProvider', function($httpProvider) { + $httpProvider.defaults.get['requesttoken'] = oc_requesttoken; + $httpProvider.defaults.post['requesttoken'] = oc_requesttoken; + $httpProvider.defaults.post['Content-Type'] = 'application/x-www-form-urlencoded'; + $httpProvider.defaults.get['Content-Type'] = 'application/x-www-form-urlencoded'; + return $httpProvider.defaults.transformRequest = function(data) { + if (angular.isDefined(data)) { + return data; + } else { + return $.param(data); + } + }; } ]); - $(document).ready(function() { - $(this).keyup(function(e) { - if ((e.which === 116) || (e.which === 82 && e.ctrlKey)) { - document.location.reload(true); - return false; - } - }); - return $('#browselink').click(function() { - return $('#file_upload_start').trigger('click'); - }); - }); - /* - # ownCloud - News app + # ownCloud # # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> @@ -58,75 +48,108 @@ */ - scrolling = true; - - markingRead = true; + angular.module('OC').factory('_Request', function() { + var Request; + Request = (function() { + + function Request(_$http, _$rootScope, _publisher, _token, _router) { + var _this = this; + this._$http = _$http; + this._$rootScope = _$rootScope; + this._publisher = _publisher; + this._token = _token; + this._router = _router; + this._initialized = false; + this._shelvedRequests = []; + this._$rootScope.$on('routesLoaded', function() { + _this._executeShelvedRequests(); + _this._initialized = true; + return _this._shelvedRequests = []; + }); + } - angular.module('News').directive('whenScrolled', [ - '$rootScope', 'Config', function($rootScope, Config) { - return function(scope, elm, attr) { - return elm.bind('scroll', function() { - if (scrolling) { - scrolling = false; - setTimeout(function() { - return scrolling = true; - }, Config.ScrollTimeout); - if (markingRead) { - markingRead = false; - setTimeout(function() { - var $elems, feed, feedItem, id, offset, _i, _len, _results; - markingRead = true; - $elems = $(elm).find('.feed_item:not(.read)'); - _results = []; - for (_i = 0, _len = $elems.length; _i < _len; _i++) { - feedItem = $elems[_i]; - offset = $(feedItem).position().top; - if (offset <= -50) { - id = parseInt($(feedItem).data('id'), 10); - feed = parseInt($(feedItem).data('feed'), 10); - _results.push($rootScope.$broadcast('read', { - id: id, - feed: feed - })); - } else { - break; - } - } - return _results; - }, Config.MarkReadTimeout); - } - return scope.$apply(attr.whenScrolled); + Request.prototype.request = function(route, routeParams, data, onSuccess, onFailure, config) { + var defaultConfig, key, url, value, + _this = this; + if (routeParams == null) { + routeParams = {}; + } + if (data == null) { + data = {}; + } + if (onSuccess == null) { + onSuccess = null; + } + if (onFailure == null) { + onFailure = null; + } + if (config == null) { + config = {}; + } + if (!this._initialized) { + this._shelveRequest(route, routeParams, data, method, config); + return; + } + url = this._router.generate(route, routeParams); + defaultConfig = { + method: 'GET', + url: url, + data: data + }; + for (key in config) { + value = config[key]; + defaultConfig[key] = value; + } + return this._$http(config).success(function(data, status, headers, config) { + var name, _ref, _results; + if (onSuccess) { + onSuccess(data, status, headers, config); + } + _ref = data.data; + _results = []; + for (name in _ref) { + value = _ref[name]; + _results.push(_this.publisher.publishDataTo(name, value)); + } + return _results; + }).error(function(data, status, headers, config) { + if (onFailure) { + return onFailure(data, status, headers, config); } }); }; - } - ]); - - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ + Request.prototype._shelveRequest = function(route, routeParams, data, method, config) { + var request; + request = { + route: route, + routeParams: routeParams, + data: data, + config: config, + method: method + }; + return this._shelvedRequests.push(request); + }; - angular.module('News').directive('onEnter', function() { - return function(scope, elm, attr) { - return elm.bind('keyup', function(e) { - if (e.keyCode === 13) { - e.preventDefault(); - return scope.$apply(attr.onEnter); + Request.prototype._executeShelvedRequests = function() { + var req, _i, _len, _ref, _results; + _ref = this._shelvedRequests; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + req = _ref[_i]; + _results.push(this.post(req.route, req.routeParams, req.data, req.method, req.config)); } - }); - }; + return _results; + }; + + return Request; + + })(); + return Request; }); /* - # ownCloud - News app + # ownCloud # # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> @@ -137,126 +160,154 @@ */ - angular.module('News').directive('feedNavigation', function() { - return function(scope, elm, attr) { - var jumpTo, jumpToNextItem, jumpToPreviousItem; - jumpTo = function($scrollArea, $item) { - var position; - position = $item.offset().top - $scrollArea.offset().top + $scrollArea.scrollTop(); - return $scrollArea.scrollTop(position); - }; - jumpToPreviousItem = function(scrollArea) { - var $item, $items, $previous, $scrollArea, item, notJumped, _i, _len; - $scrollArea = $(scrollArea); - $items = $scrollArea.find('.feed_item'); - notJumped = true; - for (_i = 0, _len = $items.length; _i < _len; _i++) { - item = $items[_i]; - $item = $(item); - if ($item.position().top >= 0) { - $previous = $item.prev(); - if ($previous.length > 0) { - jumpTo($scrollArea, $previous); - } - notJumped = false; - break; + angular.module('OC').factory('_Model', function() { + var Model; + Model = (function() { + + function Model() { + this.foreignKeys = {}; + this.data = []; + this.ids = {}; + } + + Model.prototype.handle = function(data) { + var item, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _results; + if (data['create'] !== void 0) { + _ref = data['create']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + item = _ref[_i]; + this.create(item); } } - if ($items.length > 0 && notJumped) { - return jumpTo($scrollArea, $items.last()); + if (data['update'] !== void 0) { + _ref1 = data['update']; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + item = _ref1[_j]; + this.update(item); + } + } + if (data['delete'] !== void 0) { + _ref2 = data['delete']; + _results = []; + for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) { + item = _ref2[_k]; + _results.push(this["delete"](item)); + } + return _results; } }; - jumpToNextItem = function(scrollArea) { - var $item, $items, $scrollArea, item, _i, _len, _results; - $scrollArea = $(scrollArea); - $items = $scrollArea.find('.feed_item'); + + Model.prototype.hasForeignKey = function(name) { + return this.foreignKeys[name] = {}; + }; + + Model.prototype.create = function(data) { + var id, ids, name, _base, _ref, _results; + if (this.ids[data.id] !== void 0) { + return this.update(data); + } else { + this.data.push(data); + this.ids[data.id] = data; + _ref = this.foreignKeys; + _results = []; + for (name in _ref) { + ids = _ref[name]; + id = data[name]; + (_base = this.foreignKeys[name])[id] || (_base[id] = []); + _results.push(this.foreignKeys[name][id].push(data)); + } + return _results; + } + }; + + Model.prototype.update = function(item) { + var currentItem, key, value, _results; + currentItem = this.ids[item.id]; _results = []; - for (_i = 0, _len = $items.length; _i < _len; _i++) { - item = $items[_i]; - $item = $(item); - if ($item.position().top > 1) { - jumpTo($scrollArea, $item); - break; + for (key in item) { + value = item[key]; + if (this.foreignKeys[key] !== void 0) { + if (value !== currentItem[key]) { + this._updateForeignKeyCache(key, currentItem, item); + } + } + if (key !== 'id') { + _results.push(currentItem[key] = value); } else { _results.push(void 0); } } return _results; }; - return $(document).keydown(function(e) { - var focused, scrollArea; - focused = $(':focus'); - if (!(focused.is('input') || focused.is('select') || focused.is('textarea') || focused.is('checkbox') || focused.is('button'))) { - scrollArea = elm; - if (e.keyCode === 74 || e.keyCode === 39) { - return jumpToNextItem(scrollArea); - } else if (e.keyCode === 75 || e.keyCode === 37) { - return jumpToPreviousItem(scrollArea); - } + + Model.prototype["delete"] = function(item) { + if (this.getById(item.id) !== void 0) { + return this.removeById(item.id); } - }); - }; - }); + }; - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ + Model.prototype._updateForeignKeyCache = function(name, currentItem, toItem) { + var foreignKeyItems, fromValue, toValue; + fromValue = currentItem[name]; + toValue = toItem[name]; + foreignKeyItems = this.foreignKeys[name][fromValue]; + this._removeForeignKeyCacheItem(foreignKeyItems, currentItem); + return this.foreignKeys[name][toValue].push(item); + }; + Model.prototype._removeForeignKeyCacheItem = function(foreignKeyItems, item) { + var fkItem, index, _i, _len, _results; + _results = []; + for (index = _i = 0, _len = foreignKeyItems.length; _i < _len; index = ++_i) { + fkItem = foreignKeyItems[index]; + if (fkItem.id === id) { + _results.push(this.foreignKeys[key][item[key]].splice(index, 1)); + } else { + _results.push(void 0); + } + } + return _results; + }; - /* - # This is used to signal the settings bar that the app has been focused and that - # it should hide - */ + Model.prototype.removeById = function(id) { + var foreignKeyItems, ids, index, item, key, _i, _len, _ref, _ref1; + item = this.getById(id); + _ref = this.foreignKeys; + for (key in _ref) { + ids = _ref[key]; + foreignKeyItems = ids[item[key]]; + this._removeForeignKeyCacheItem(foreignKeyItems, item); + } + _ref1 = this.data; + for (index = _i = 0, _len = _ref1.length; _i < _len; index = ++_i) { + item = _ref1[index]; + if (item.id === id) { + this.data.splice(index, 1); + } + } + return delete this.ids[id]; + }; + Model.prototype.getById = function(id) { + return this.ids[id]; + }; - angular.module('News').directive('hideSettingsWhenFocusLost', [ - '$rootScope', function($rootScope) { - return function(scope, elm, attr) { - $(document.body).click(function() { - $rootScope.$broadcast('hidesettings'); - return scope.$apply(attr.hideSettingsWhenFocusLost); - }); - return $(elm).click(function(e) { - return e.stopPropagation(); - }); + Model.prototype.getAll = function() { + return this.data; }; - } - ]); - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ + Model.prototype.getAllOfForeignKeyWithId = function(foreignKeyName, foreignKeyId) { + return this.foreignKeys[foreignKeyName][foreignKeyId]; + }; + return Model; - angular.module('News').directive('draggable', function() { - return function(scope, elm, attr) { - var details; - details = { - revert: true, - stack: '> li', - zIndex: 1000, - axis: 'y' - }; - return $(elm).draggable(details); - }; + })(); + return Model; }); /* - # ownCloud - News app + # ownCloud # # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> @@ -268,35 +319,16 @@ /* - Thise directive can be bound on an input element with type file and name files [] - When a file is input, the content will be broadcasted as a readFile event + # Inject router into angular to make testing easier */ - angular.module('News').directive('readFile', [ - '$rootScope', function($rootScope) { - return function(scope, elm, attr) { - return $(elm).change(function() { - var file, reader; - if (window.File && window.FileReader && window.FileList) { - file = elm[0].files[0]; - reader = new FileReader(); - reader.onload = function(e) { - var content; - content = e.target.result; - return $rootScope.$broadcast('readFile', content); - }; - return reader.readAsText(file); - } else { - return alert('Your browser does not support the FileReader API!'); - } - }); - }; - } - ]); + angular.module('OC').factory('Router', function() { + return OC.Router; + }); /* - # ownCloud - News app + # ownCloud # # @author Bernhard Posselt # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> @@ -307,148 +339,89 @@ */ - angular.module('News').directive('droppable', [ - '$rootScope', function($rootScope) { - return function(scope, elm, attr) { - var $elem, details; - $elem = $(elm); - details = { - accept: '.feed', - hoverClass: 'dnd_over', - greedy: true, - drop: function(event, ui) { - var data; - $('.dnd_over').removeClass('dnd_over'); - data = { - folderId: parseInt($elem.data('id'), 10), - feedId: parseInt($(ui.draggable).data('id'), 10) - }; - $rootScope.$broadcast('moveFeedToFolder', data); - return scope.$apply(attr.droppable); - } - }; - return $elem.droppable(details); - }; - } - ]); - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # + # Used for properly distributing received model data from the server */ - angular.module('News').filter('feedInFolder', function() { - return function(feeds, folderId) { - var feed, result, _i, _len; - result = []; - for (_i = 0, _len = feeds.length; _i < _len; _i++) { - feed = feeds[_i]; - if (feed.folderId === folderId) { - result.push(feed); - } - } - return result; - }; - }); - - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ - + angular.module('OC').factory('_Publisher', function() { + var Publisher; + Publisher = (function() { - angular.module('News').factory('_FeedModel', [ - 'Model', function(Model) { - var FeedModel; - FeedModel = (function(_super) { + function Publisher() { + this.subscriptions = {}; + } - __extends(FeedModel, _super); + Publisher.prototype.subscribeModelTo = function(model, name) { + var _base; + (_base = this.subscriptions)[name] || (_base[name] = []); + return this.subscriptions[name].push(model); + }; - function FeedModel() { - FeedModel.__super__.constructor.call(this); + Publisher.prototype.publishDataTo = function(data, name) { + var subscriber, _i, _len, _ref, _results; + _ref = this.subscriptions[name] || []; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + subscriber = _ref[_i]; + _results.push(subscriber.handle(data)); } + return _results; + }; - FeedModel.prototype.add = function(item) { - return FeedModel.__super__.add.call(this, this.bindAdditional(item)); - }; - - FeedModel.prototype.bindAdditional = function(item) { - if (item.icon === "url()") { - item.icon = 'url(' + OC.imagePath('news', 'rss.svg') + ')'; - } - return item; - }; - - return FeedModel; - - })(Model); - return FeedModel; - } - ]); + return Publisher; - /* - # ownCloud - News app - # - # @author Bernhard Posselt - # Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> - # - # This file is licensed under the Affero General Public License version 3 or later. - # See the COPYING-README file - # - */ + })(); + return Publisher; + }); +}).call(this); - angular.module('News').factory('_GarbageRegistry', function() { - var GarbageRegistry; - GarbageRegistry = (function() { - function GarbageRegistry(itemModel) { - this.itemModel = itemModel; - this.registeredItemIds = {}; - } +/* +# ownCloud - News app +# +# @author Bernhard Posselt +# Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> +# +# This file is licensed under the Affero General Public License version 3 or later. +# See the COPYING-README file +# +*/ - GarbageRegistry.prototype.register = function(item) { - var itemId; - itemId = item.id; - return this.registeredItemIds[itemId] = item; - }; - GarbageRegistry.prototype.unregister = function(item) { - var itemId; - itemId = item.id; - return delete this.registeredItemIds[itemId]; - }; +(function() { + var app, markingRead, scrolling, + __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; }; - GarbageRegistry.prototype.clear = function() { - var id, item, _ref; - _ref = this.registeredItemIds; - for (id in _ref) { - item = _ref[id]; - if (!item.keptUnread) { - this.itemModel.removeById(parseInt(id, 10)); - } - item.keptUnread = false; - } - return this.registeredItemIds = {}; - }; + app = angular.module('News', []).config(function($provide) { + var config; + config = { + MarkReadTimeout: 500, + ScrollTimeout: 500, + initialLoadedItemsNr: 20, + FeedUpdateInterval: 6000000 + }; + return $provide.value('Config', config); + }); - return GarbageRegistry; + app.run([ + 'PersistenceNews', function(PersistenceNews) { + return PersistenceNews.loadInitial(); + } + ]); - })(); - return GarbageRegistry; + $(document).ready(function() { + $(this).keyup(function(e) { + if ((e.which === 116) || (e.which === 82 && e.ctrlKey)) { + document.location.reload(true); + return false; + } + }); + return $('#browselink').click(function() { + return $('#file_upload_start').trigger('click'); + }); }); /* @@ -493,191 +466,106 @@ */ - angular.module('News').factory('_PersistenceNews', [ - 'Persistence', function(Persistence) { - var PersistenceNews; - PersistenceNews = (function(_super) { + angular.module('News').factory('_ItemModel', [ + 'Model', function(Model) { + var ItemModel; + ItemModel = (function(_super) { - __extends(PersistenceNews, _super); + __extends(ItemModel, _super); - function PersistenceNews($http, $rootScope, loading, publisher) { - this.$rootScope = $rootScope; - this.loading = loading; - this.publisher = publisher; - PersistenceNews.__super__.constructor.call(this, 'news', $http); + function ItemModel(cache, feedType) { + this.cache = cache; + this.feedType = feedType; + ItemModel.__super__.constructor.call(this); } - PersistenceNews.prototype.updateModels = function(data) { - var type, value, _results; - _results = []; - for (type in data) { - value = data[type]; - _results.push(this.publisher.publish(type, value)); - } - return _results; - }; - - PersistenceNews.prototype.loadInitial = function() { - var _this = this; - this.loading.loading += 1; - return OC.Router.registerLoadedCallback(function() { - return _this.post('init', {}, function(json) { - _this.loading.loading -= 1; - _this.updateModels(json.data); - _this.$rootScope.$broadcast('triggerHideRead'); - return _this.setInitialized(true); - }, null, true); - }); + ItemModel.prototype.clearCache = function() { + this.cache.clear(); + return ItemModel.__super__.clearCache.call(this); }; - PersistenceNews.prototype.loadFeed = function(type, id, latestFeedId, latestTimestamp, limit) { - var data, - _this = this; - if (limit == null) { - limit = 20; + ItemModel.prototype.add = function(item) { + item = this.bindAdditional(item); + if (ItemModel.__super__.add.call(this, item)) { + return this.cache.add(this.getItemById(item.id)); } - data = { - type: type, - id: id, - latestFeedId: latestFeedId, - latestTimestamp: latestTimestamp, - limit: limit - }; - this.loading.loading += 1; - return this.post('loadfeed', data, function(json) { - _this.loading.loading -= 1; - return _this.updateModels(json.data); - }); }; - PersistenceNews.prototype.createFeed = function(feedUrl, folderId, onSuccess, onError) { - var data, - _this = this; - data = { - feedUrl: feedUrl, - folderId: folderId + ItemModel.prototype.bindAdditional = function(item) { + item.getRelativeDate = function() { + return moment.unix(this.date).fromNow(); }; - return this.post('createfeed', data, function(json) { - onSuccess(json.data); - return _this.updateModels(json.data); - }, onError); - }; - - PersistenceNews.prototype.deleteFeed = function(feedId, onSuccess) { - var data; - data = { - feedId: feedId + item.getAuthorLine = function() { + if (this.author !== null && this.author.trim() !== "") { + return "by " + this.author; + } else { + return ""; + } }; - return this.post('deletefeed', data, onSuccess); + return item; }; - PersistenceNews.prototype.moveFeedToFolder = function(feedId, folderId) { - var data; - data = { - feedId: feedId, - folderId: folderId - }; - return this.post('movefeedtofolder', data); + ItemModel.prototype.removeById = function(itemId) { + var item; + item = this.getItemById(itemId); + if (item !== void 0) { + this.cache.remove(item); + return ItemModel.__super__.removeById.call(this, itemId); + } }; - PersistenceNews.prototype.createFolder = function(folderName, onSuccess) { - var data, - _this = this; - data = { - folderName: folderName - }; - return this.post('createfolder', data, function(json) { - onSuccess(json.data); - return _this.updateModels(json.data); - }); + ItemModel.prototype.getHighestId = function(type, id) { + return this.cache.getHighestId(type, id); }; - PersistenceNews.prototype.deleteFolder = function(folderId) { - var data; - data = { - folderId: folderId - }; - return this.post('deletefolder', data); + ItemModel.prototype.getHighestTimestamp = function(type, id) { + return this.cache.getHighestTimestamp(type, id); }; - PersistenceNews.prototype.changeFolderName = function(folderId, newFolderName) { - var data; - data = { - folderId: folderId, - newFolderName: newFolderName - }; - return this.post('folderName', data); + ItemModel.prototype.getLowestId = function(type, id) { + return this.cache.getLowestId(type, id); }; - PersistenceNews.prototype.showAll = function(isShowAll) { - var data; - data = { - showAll: isShowAll - }; - return this.post('setshowall', data); + ItemModel.prototype.getLowestTimestamp = function(type, id) { + return this.cache.getLowestTimestamp(type, id); }; - PersistenceNews.prototype.markRead = function(itemId, isRead) { - var data, status; - if (isRead) { - status = 'read'; - } else { - status = 'unread'; - } - data = { - itemId: itemId, - status: status - }; - return this.post('setitemstatus', data); + ItemModel.prototype.getFeedsOfFolderId = function(id) { + return this.cache.getFeedsOfFolderId(id); }; - PersistenceNews.prototype.setImportant = function(itemId, isImportant) { - var data, status; - if (isImportant) { - status = 'important'; - } else { - status = 'unimportant'; + ItemModel.prototype.getItemsByTypeAndId = function(type, id) { + var feedId, items, _i, _len, _ref; + switch (type) { + case this.feedType.Feed: + items = this.cache.getItemsOfFeed(id) || []; + return items; + case this.feedType.Subscriptions: + return this.getItems(); + case this.feedType.Folder: + items = []; + _ref = this.cache.getFeedIdsOfFolder(id); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + feedId = _ref[_i]; + items = items.concat(this.cache.getItemsOfFeed(feedId) || []); + } + return items; + case this.feedType.Starred: + |