diff --git a/apps/bookmarks/ajax/updateList.php b/apps/bookmarks/ajax/updateList.php index 9290757d0b..61983cc0f5 100644 --- a/apps/bookmarks/ajax/updateList.php +++ b/apps/bookmarks/ajax/updateList.php @@ -50,6 +50,13 @@ if($filterTag){ $offset = isset($_GET['page']) ? intval($_GET['page']) * 10 : 0; $params[] = $offset; +$sort = isset($_GET['sort']) ? ($_GET['sort']) : 'bookmarks_sorting_recent'; +if($sort == 'bookmarks_sorting_clicks') { + $sqlSort = 'clickcount DESC'; +} else { + $sqlSort = 'id DESC'; +} + if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ $_gc_separator = ', \' \''; } else { @@ -72,7 +79,7 @@ $query = OC_DB::prepare(' AND *PREFIX*bookmarks.user_id = ? GROUP BY url '.$sqlFilterTag.' - ORDER BY *PREFIX*bookmarks.id DESC + ORDER BY *PREFIX*bookmarks.'.$sqlSort.' LIMIT ?, 10'); $bookmarks = $query->execute($params)->fetchAll(); diff --git a/apps/bookmarks/css/bookmarks.css b/apps/bookmarks/css/bookmarks.css index 0fa4a3b6b2..9655917244 100644 --- a/apps/bookmarks/css/bookmarks.css +++ b/apps/bookmarks/css/bookmarks.css @@ -23,6 +23,21 @@ text-decoration: underline; } +.bookmarks_sorting { + float: left; + margin-left: 2em; +} + +.bookmarks_sorting li { + padding: 1ex 1em; + border: 1px solid gray; + -moz-border-radius:1em; -webkit-border-radius:1em; border-radius:1em; +} + +.bookmarks_sorting_active { + font-weight: bold; +} + .bookmarks_add { display: none; } @@ -64,4 +79,8 @@ .bookmark_tags { color: #ff3333; -} \ No newline at end of file +} + +.clear { + clear:both; +} diff --git a/apps/bookmarks/js/bookmarks.js b/apps/bookmarks/js/bookmarks.js index ad3aefde20..93b21c3243 100644 --- a/apps/bookmarks/js/bookmarks.js +++ b/apps/bookmarks/js/bookmarks.js @@ -1,6 +1,8 @@ var bookmarks_page = 0; var bookmarks_loading = false; +var bookmarks_sorting = 'bookmarks_sorting_recent'; + $(document).ready(function() { $('.bookmarks_addBtn').click(function(event){ $('.bookmarks_add').slideToggle(); @@ -10,6 +12,9 @@ $(document).ready(function() { $(window).scroll(updateOnBottom); $('#bookmark_add_url').focusout(getMetadata); + $('.' + bookmarks_sorting).addClass('bookmarks_sorting_active'); + + $('.bookmarks_sorting li').click(function(event){changeSorting(this)}); $('.bookmarks_list').empty(); getBookmarks(); @@ -20,9 +25,10 @@ function getBookmarks() { //have patience :) return; } + $.ajax({ url: 'ajax/updateList.php', - data: 'tag=' + encodeURI($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page, + data: 'tag=' + encodeURI($('#bookmarkFilterTag').val()) + '&page=' + bookmarks_page + '&sort=' + bookmarks_sorting, success: function(bookmarks){ bookmarks_page += 1; $('.bookmark_link').unbind('click', recordClick); @@ -50,6 +56,17 @@ function getMetadata() { }); } +function changeSorting(sortEl) { + $('.' + bookmarks_sorting).removeClass('bookmarks_sorting_active'); + bookmarks_sorting = sortEl.className; + $('.' + bookmarks_sorting).addClass('bookmarks_sorting_active'); + + $('.bookmarks_list').empty(); + bookmarks_page = 0; + bookmarks_loading = false; + getBookmarks(); +} + function addBookmark(event) { var url = encodeEntities($('#bookmark_add_url').val()) var title = encodeEntities($('#bookmark_add_title').val()) diff --git a/apps/bookmarks/templates/list.php b/apps/bookmarks/templates/list.php index 203b48e1cb..a2c89b310a 100644 --- a/apps/bookmarks/templates/list.php +++ b/apps/bookmarks/templates/list.php @@ -12,6 +12,13 @@
+