diff --git a/controller/webviewcontroller.php b/controller/webviewcontroller.php index ba44d0d9..3d62e314 100644 --- a/controller/webviewcontroller.php +++ b/controller/webviewcontroller.php @@ -48,11 +48,19 @@ class WebViewController extends Controller { public function bookmarklet($url = "", $title = "") { $bookmarkExists = Bookmarks::bookmarkExists($url, $this->userId, $this->db); $description = ""; - if ($bookmarkExists != false){ + $tags = []; + if ($bookmarkExists !== false){ $bookmark = Bookmarks::findUniqueBookmark($bookmarkExists, $this->userId, $this->db); $description = $bookmark['description']; + $tags = $bookmark['tags']; } - $params = array('url' => $url, 'title' => $title, 'description' => $description, 'bookmarkExists' => $bookmarkExists); + $params = array( + 'url' => $url, + 'title' => $title, + 'description' => $description, + 'bookmarkExists'=> $bookmarkExists, + 'tags' => $tags + ); return new TemplateResponse('bookmarks', 'addBookmarklet', $params); // templates/main.php } diff --git a/js/bookmarklet.js b/js/bookmarklet.js index 39adbc20..93d206ba 100644 --- a/js/bookmarklet.js +++ b/js/bookmarklet.js @@ -22,14 +22,28 @@ function updateLoadingAnimation() { } } -$(function () { +$(document).ready(function () { $(".submit").click(function () { increaseAjaxCallCount(); + + 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(); + $("textarea#description").val() + '&title=' + $("input#title").val() + tags + id; $.ajax({ - type: "POST", - url: "bookmark", + type: method, + url: endpoint, data: dataString, complete: function () { decreaseAjaxCallCount(); @@ -48,8 +62,16 @@ $(function () { }); return false; }); + + $.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 ce7c8992..ab0ff07a 100644 --- a/templates/addBookmarklet.php +++ b/templates/addBookmarklet.php @@ -1,6 +1,8 @@ @@ -12,7 +14,7 @@ $bookmarkExists = $_['bookmarkExists'];
">
@@ -24,6 +26,9 @@ $bookmarkExists = $_['bookmarkExists'];
-
\ No newline at end of file +