From 74eb8a0848bf7ed07c0c3efa51bf3e16dd040d11 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Tue, 14 Jul 2015 14:24:13 +0200 Subject: [PATCH] fix updating of bookmarks via bookmarklet --- controller/webviewcontroller.php | 2 +- js/bookmarklet.js | 45 ++++++++++++++++++++------------ templates/addBookmarklet.php | 5 +++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/controller/webviewcontroller.php b/controller/webviewcontroller.php index 2b8f7c4a..3d62e314 100644 --- a/controller/webviewcontroller.php +++ b/controller/webviewcontroller.php @@ -49,7 +49,7 @@ class WebViewController extends Controller { $bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db); $description = ""; $tags = []; - if ($bookmarkExists != false){ + if ($bookmarkExists !== false){ $bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db); $description = $bookmark['description']; $tags = $bookmark['tags']; diff --git a/js/bookmarklet.js b/js/bookmarklet.js index 3b19fa9e..93d206ba 100644 --- a/js/bookmarklet.js +++ b/js/bookmarklet.js @@ -22,18 +22,28 @@ function updateLoadingAnimation() { } } -$(function () { +$(document).ready(function () { $(".submit").click(function () { increaseAjaxCallCount(); - var tags = ''; - $('.tagit-choice .tagit-label').each(function() { - tags += '&item[tags][]='+$(this).text(); - }); - var dataString = 'url=' + $("input#url").val() + '&description=' + - $("textarea#description").val() + '&title=' + $("input#title").val() + tags; + + var endpoint = 'bookmark'; + var method = 'POST'; + var id = ''; + if($('#bookmarkID').length > 0) { + endpoint += '/'+ $('#bookmarkID').val(); + method = 'PUT'; + id = '&record_id=' + $('#bookmarkID').val(); + } + + var tags = ''; + $('.tagit-choice .tagit-label').each(function() { + tags += '&item[tags][]='+$(this).text(); + }); + var dataString = 'url=' + $("input#url").val() + '&description=' + + $("textarea#description").val() + '&title=' + $("input#title").val() + tags + id; $.ajax({ - type: "POST", - url: "bookmark", + type: method, + url: endpoint, data: dataString, complete: function () { decreaseAjaxCallCount(); @@ -52,15 +62,16 @@ $(function () { }); return false; }); - $.get('tag', function(data) { - $('.tags').tagit({ - allowSpaces: true, - availableTags : data, - placeholderText: t('bookmark', 'Tags') - }); - }); + + $.get('tag', function (data) { + $('.tags').tagit({ + allowSpaces: true, + availableTags: data, + placeholderText: t('bookmark', 'Tags') + }); + }); }); function closeWindow() { window.close(); -} \ No newline at end of file +} diff --git a/templates/addBookmarklet.php b/templates/addBookmarklet.php index eefa6d5a..ab0ff07a 100644 --- a/templates/addBookmarklet.php +++ b/templates/addBookmarklet.php @@ -14,7 +14,7 @@ $bookmarkExists = $_['bookmarkExists'];
">
@@ -26,6 +26,9 @@ $bookmarkExists = $_['bookmarkExists'];
  • + + +