diff options
-rw-r--r-- | js/controller/ShareController.js | 10 | ||||
-rw-r--r-- | templates/part.content.php | 2 |
2 files changed, 11 insertions, 1 deletions
diff --git a/js/controller/ShareController.js b/js/controller/ShareController.js index 2977dc2c2..57722f416 100644 --- a/js/controller/ShareController.js +++ b/js/controller/ShareController.js @@ -25,7 +25,17 @@ app.controller('ShareController', function (ShareResource) { }); }; + // Dict <itemId, List<Int>(user_id)>: Local mapping b/w users & articles: [Article 1 : <Jimmy, Aurelien, ...>, Article 2: <...>] + this.usersSharedArticles = {}; + this.shareItem = function(itemId, userId) { + if (this.usersSharedArticles[itemId] && this.usersSharedArticles[itemId].includes(userId)) {return ; } + + // quick initialization (instead of if (...) : []) + this.usersSharedArticles[itemId] = this.usersSharedArticles[itemId] ? this.usersSharedArticles[itemId] : []; + + this.usersSharedArticles[itemId].push(userId); + var response = ShareResource.shareItem(itemId, userId); response.then((result) => { return result; diff --git a/templates/part.content.php b/templates/part.content.php index 962247e8f..f210508c6 100644 --- a/templates/part.content.php +++ b/templates/part.content.php @@ -119,7 +119,7 @@ </form> - <a + <a ng-repeat="user in Share.userList" ng-click="Share.shareItem(item.id, user.value.shareWith)"> {{ user.value.shareWith }} |