1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-01-31 01:52:11 +01:00

Merge branch 'master' into navigation

This commit is contained in:
Jan-Christoph Borchardt 2013-01-17 15:01:37 +07:00
commit ebbde7e14b
5 changed files with 66 additions and 23 deletions

View File

@ -34,17 +34,17 @@ if(isset($_POST['url'])) {
$pub = isset($_POST['is_public']) ? true : false; $pub = isset($_POST['is_public']) ? true : false;
if(isset($_POST['record_id']) && is_numeric($_POST['record_id']) ) { //EDIT if(isset($_POST['record_id']) && is_numeric($_POST['record_id']) ) { //EDIT
$bm = $_POST['record_id']; $id = OC_Bookmarks_Bookmarks::editBookmark($_POST['record_id'], $_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
OC_Bookmarks_Bookmarks::editBookmark($bm, $_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
} }
else { else {
if(isset($_POST['from_own'])) { if(isset($_POST['from_own'])) {
$datas = OC_Bookmarks_Bookmarks::getURLMetadata($_POST['url']); $datas = OC_Bookmarks_Bookmarks::getURLMetadata($_POST['url']);
if(isset($datas['title'])) $title = $datas['title']; if(isset($datas['title'])) $title = $datas['title'];
} }
$bm = OC_Bookmarks_Bookmarks::addBookmark($_POST['url'], $title, $tags, $_POST['description'], $pub); $id = OC_Bookmarks_Bookmarks::addBookmark($_POST['url'], $title, $tags, $_POST['description'], $pub);
} }
OCP\JSON::success(array('id'=>$bm,'title'=>$title)); $bm = OC_Bookmarks_Bookmarks::findOneBookmark($id);
OCP\JSON::success(array('item'=>$bm));
exit(); exit();
} }
OC_JSON::error(); OC_JSON::error();

View File

@ -43,7 +43,7 @@ else { // type == bookmark
if($sort == 'bookmarks_sorting_clicks') { if($sort == 'bookmarks_sorting_clicks') {
$sqlSortColumn = 'clickcount'; $sqlSortColumn = 'clickcount';
} else { } else {
$sqlSortColumn = 'id'; $sqlSortColumn = 'lastmodified';
} }
$bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true); $bookmarks = OC_Bookmarks_Bookmarks::findBookmarks($offset, $sqlSortColumn, $filterTag, true);
OCP\JSON::success(array('data' => $bookmarks)); OCP\JSON::success(array('data' => $bookmarks));

View File

@ -98,6 +98,7 @@ input.disabled, input.disabled:hover, input.disabled:focus {
font-weight: bold; font-weight: bold;
display: inline-block; display: inline-block;
margin-right: 0.8em; margin-right: 0.8em;
margin-top:0.7em;
width: 20%; width: 20%;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
@ -205,7 +206,7 @@ input.disabled, input.disabled:hover, input.disabled:focus {
font-weight: normal; font-weight: normal;
float:left; float:left;
padding: 0.3em; padding: 0.3em;
position: relative; position: relative;
} }
ul.tagit li.tagit-new { ul.tagit li.tagit-new {
@ -249,8 +250,8 @@ li:hover em { display : none; }
#tag_filter ul.tagit li.tagit-choice .close{ #tag_filter ul.tagit li.tagit-choice .close{
margin-top: -8px; margin-top: -8px;
cursor: pointer; cursor: pointer;
margin-top: -8px; margin-top: -8px;
position: absolute; position: absolute;
right: 0.1em; right: 0.1em;
top: 50%; top: 50%;
} }
@ -262,12 +263,12 @@ li:hover em { display : none; }
text-overflow:ellipsis; text-overflow:ellipsis;
overflow:hidden; overflow:hidden;
display:block; display:block;
float:left; float:left;
position: absolute; position: absolute;
left: 25%; left: 25%;
width:40%; width:40%;
top: 0.7em; top: 0.7em;
font-weight:500; font-weight:500;
} }
.bookmark_date, .bookmark_submit { .bookmark_date, .bookmark_submit {
font-size:small; font-size:small;
@ -276,7 +277,7 @@ li:hover em { display : none; }
color:gray; color:gray;
/* margin-top:2.5em; */ /* margin-top:2.5em; */
margin-right: 0.2em; margin-right: 0.2em;
top:0.8em; top:0.8em;
} }
/* /*
@ -295,6 +296,19 @@ li:hover em { display : none; }
width: 80%; width: 80%;
} }
.bookmark_single .bookmark_edit_btn {
display:none;
}
.bookmark_single:hover .bookmark_edit_btn {
display:block;
}
.bookmark_single:focus .bookmark_edit_btn {
display:block;
opacity:1;
}
.bookmark_single_form { .bookmark_single_form {
padding-top: 1em; padding-top: 1em;
border-bottom: 1px solid #DDD; border-bottom: 1px solid #DDD;

View File

@ -173,16 +173,17 @@ function addBookmark(event) {
} }
$('#add_url').val(''); $('#add_url').val('');
bookmark = { url: url, description:'', title:'', from_own: '1'}; bookmark = { url: url, description:'', title:'', from_own: '1', added_date: new Date()};
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'), url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
data: bookmark, data: bookmark,
success: function(data){ success: function(data){
if (data.status == 'success') { if (data.status == 'success') {
bookmark.id = data.id; // First remove old BM if exists
bookmark.title = data.title $('.bookmark_single').filterAttr('data-id', data.item.id).remove();
bookmark.added_date = new Date();
bookmark = $.extend({}, bookmark, data.item);
updateBookmarksList(bookmark, 'prepend'); updateBookmarksList(bookmark, 'prepend');
checkEmpty(); checkEmpty();
watchUrlField(); watchUrlField();

View File

@ -51,7 +51,23 @@ class OC_Bookmarks_Bookmarks{
$tags = $query->execute($params)->fetchAll(); $tags = $query->execute($params)->fetchAll();
return $tags; return $tags;
} }
public static function findOneBookmark($id) {
if($CONFIG_DBTYPE == 'pgsql') {
$group_fct = 'array_agg(tag)';
}
else {
$group_fct = 'GROUP_CONCAT(tag)';
}
$sql = "SELECT *, (select $group_fct from *PREFIX*bookmarks_tags where bookmark_id = b.id) as tags
FROM *PREFIX*bookmarks b
WHERE user_id = ? and id = ?";
$query = OCP\DB::prepare($sql);
$result = $query->execute(array(OCP\USER::getUser(), $id))->fetchRow();
$result['tags'] = explode(',', $result['tags']);
return $result;
}
/** /**
* @brief Finds all bookmarks, matching the filter * @brief Finds all bookmarks, matching the filter
* @param offset result offset * @param offset result offset
@ -295,11 +311,23 @@ class OC_Bookmarks_Bookmarks{
* @return int The id of the bookmark created * @return int The id of the bookmark created
*/ */
public static function addBookmark($url, $title, $tags=array(), $description='', $is_public=false) { public static function addBookmark($url, $title, $tags=array(), $description='', $is_public=false) {
$is_public = $is_public ? 1 : 0; $is_public = $is_public ? 1 : 0;
//FIXME: Detect and do smth when user adds a known URL $enc_url = htmlspecialchars_decode($url);
$_ut = self::getNowValue(); $_ut = self::getNowValue();
// Change lastmodified date if the record if already exists
$sql = "SELECT id from *PREFIX*bookmarks WHERE url = ? and user_id = ?";
$query = OCP\DB::prepare($sql, 1);
$result = $query->execute(array($enc_url, OCP\USER::getUser()));
if(count($result) != 0) {
$row = $result->fetchRow();
$sql = "UPDATE *PREFIX*bookmarks SET lastmodified = $_ut WHERE url = ? and user_id = ?";
$query = OCP\DB::prepare($sql);
$query->execute(array($enc_url, OCP\USER::getUser()));
return $row['id'];
}
$query = OCP\DB::prepare(" $query = OCP\DB::prepare("
INSERT INTO *PREFIX*bookmarks INSERT INTO *PREFIX*bookmarks
(url, title, user_id, public, added, lastmodified, description) (url, title, user_id, public, added, lastmodified, description)
@ -307,7 +335,7 @@ class OC_Bookmarks_Bookmarks{
"); ");
$params=array( $params=array(
htmlspecialchars_decode($url), $enc_url,
htmlspecialchars_decode($title), htmlspecialchars_decode($title),
OCP\USER::getUser(), OCP\USER::getUser(),
$is_public, $is_public,