summaryrefslogtreecommitdiffstats
path: root/js/service/ItemResource.js
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-09-11 03:55:52 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-09-11 03:55:52 +0200
commitea9ebd4826fe9807af5bc17e786b3dc58f163970 (patch)
tree2894b40614ebe977797cea5745b215e2a2851f61 /js/service/ItemResource.js
parent594b92f649d8ed8a705f1af23639463078170d46 (diff)
port to es5 and add es6 shims for object prototypes instead
Diffstat (limited to 'js/service/ItemResource.js')
-rw-r--r--js/service/ItemResource.js199
1 files changed, 110 insertions, 89 deletions
diff --git a/js/service/ItemResource.js b/js/service/ItemResource.js
index 420e20775..cc67cc003 100644
--- a/js/service/ItemResource.js
+++ b/js/service/ItemResource.js
@@ -7,134 +7,155 @@
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright Bernhard Posselt 2014
*/
-app.factory('ItemResource', (Resource, $http, BASE_URL, ITEM_BATCH_SIZE) => {
+app.factory('ItemResource', function (Resource, $http, BASE_URL,
+ ITEM_BATCH_SIZE) {
'use strict';
- class ItemResource extends Resource {
+ var ItemResource = function ($http, BASE_URL, ITEM_BATCH_SIZE) {
+ Resource.call(this, $http, BASE_URL);
+ this.starredCount = 0;
+ this.batchSize = ITEM_BATCH_SIZE;
+ };
- constructor ($http, BASE_URL, ITEM_BATCH_SIZE) {
- super($http, BASE_URL);
- this.starredCount = 0;
- this.batchSize = ITEM_BATCH_SIZE;
- }
+ ItemResource.prototype = Object.create(Resource.prototype);
- receive (value, channel) {
- switch (channel) {
+ ItemResource.prototype.receive = function (value, channel) {
+ switch (channel) {
- case 'newestItemId':
- this.newestItemId = value;
- break;
+ case 'newestItemId':
+ this.newestItemId = value;
+ break;
- case 'starred':
- this.starredCount = value;
- break;
+ case 'starred':
+ this.starredCount = value;
+ break;
- default:
- super.receive(value, channel);
- }
+ default:
+ Resource.prototype.receive.call(this, value, channel);
}
+ };
- getNewestItemId () {
- return this.newestItemId;
- }
+ ItemResource.prototype.getNewestItemId = function () {
+ return this.newestItemId;
+ };
+
+
+ ItemResource.prototype.getStarredCount = function () {
+ return this.starredCount;
+ };
- getStarredCount () {
- return this.starredCount;
+ ItemResource.prototype.star = function (itemId, isStarred) {
+ if (isStarred === undefined) {
+ isStarred = true;
}
+ var it = this.get(itemId);
+ var url = this.BASE_URL +
+ '/items/' + it.feedId + '/' + it.guidHash + '/star';
- star (itemId, isStarred=true) {
- let it = this.get(itemId);
- let url = `${this.BASE_URL}/items/${it.feedId}/${it.guidHash}/star`;
+ it.starred = isStarred;
- it.starred = isStarred;
+ if (isStarred) {
+ this.starredCount += 1;
+ } else {
+ this.starredCount -= 1;
+ }
- if (isStarred) {
- this.starredCount += 1;
- } else {
- this.starredCount -= 1;
+ return this.http({
+ url: url,
+ method: 'POST',
+ data: {
+ isStarred: isStarred
}
+ });
+ };
+
- return this.http({
- url: url,
- method: 'POST',
- data: {
- isStarred: isStarred
- }
- });
+ ItemResource.prototype.toggleStar = function (itemId) {
+ if (this.get(itemId).starred) {
+ this.star(itemId, false);
+ } else {
+ this.star(itemId, true);
}
+ };
- toggleStar (itemId) {
- if (this.get(itemId).starred) {
- this.star(itemId, false);
- } else {
- this.star(itemId, true);
- }
+ ItemResource.prototype.markItemRead = function (itemId, isRead) {
+ if (isRead === undefined) {
+ isRead = true;
}
+ this.get(itemId).unread = !isRead;
+ return this.http({
+ url: this.BASE_URL + '/items/' + itemId + '/read',
+ method: 'POST',
+ data: {
+ isRead: isRead
+ }
+ });
+ };
- markItemRead (itemId, isRead=true) {
- this.get(itemId).unread = !isRead;
- return this.http({
- url: `${this.BASE_URL}/items/${itemId}/read`,
- method: 'POST',
- data: {
- isRead: isRead
- }
- });
- }
+ ItemResource.prototype.markItemsRead = function (itemIds) {
+ var self = this;
- markItemsRead (itemIds) {
- for (let itemId of itemIds) {
- this.get(itemId).unread = false;
+ itemIds.forEach(function(itemId) {
+ self.get(itemId).unread = false;
+ });
+
+ return this.http({
+ url: this.BASE_URL + '/items/read/multiple',
+ method: 'POST',
+ data: {
+ itemIds: itemIds
}
+ });
+ };
+
- return this.http({
- url: `${this.BASE_URL}/items/read/multiple`,
- method: 'POST',
- data: {
- itemIds: itemIds
- }
- });
+ ItemResource.prototype.markFeedRead = function (feedId, read) {
+ if (read === undefined) {
+ read = true;
}
+ var items = this.values.filter(function (element) {
+ return element.feedId === feedId;
+ });
- markFeedRead (feedId, read=true) {
- for (let item of this.values.filter(i => i.feedId === feedId)) {
- item.unread = !read;
- }
- return this.http.post(`${this.BASE_URL}/feeds/${feedId}/read`);
- }
+ items.forEach(function (item) {
+ item.unread = !read;
+ });
+ return this.http.post(this.BASE_URL + '/feeds/' + 'feedId' + '/read');
+ };
- markRead () {
- for (let item of this.values) {
- item.unread = false;
- }
- return this.http.post(`${this.BASE_URL}/items/read`);
- }
+ ItemResource.prototype.markRead = function () {
+ this.values.forEach(function (item) {
+ item.unread = false;
+ });
- autoPage (type, id) {
- return this.http({
- url: `${this.BASE_URL}/items`,
- method: 'GET',
- params: {
- type: type,
- id: id,
- offset: this.size(),
- limit: this.batchSize
- }
- });
- }
+ return this.http.post(this.BASE_URL + '/items/read');
+ };
+
+
+ ItemResource.prototype.autoPage = function (type, id) {
+ return this.http({
+ url: this.BASE_URL + '/items',
+ method: 'GET',
+ params: {
+ type: type,
+ id: id,
+ offset: this.size(),
+ limit: this.batchSize
+ }
+ });
+ };
- }
return new ItemResource($http, BASE_URL, ITEM_BATCH_SIZE);
}); \ No newline at end of file