mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-21 18:54:32 +01:00
Add possibility to add/edit bookmark
This commit is contained in:
parent
d1fa11e936
commit
ce589e2fa7
40
addBm.php
40
addBm.php
@ -31,24 +31,28 @@ OCP\App::checkAppEnabled('bookmarks');
|
|||||||
require_once('bookmarksHelper.php');
|
require_once('bookmarksHelper.php');
|
||||||
|
|
||||||
|
|
||||||
|
// If we go the dialog form submit
|
||||||
|
if(isset($_POST['url'])) {
|
||||||
|
$tags = isset($_POST['item']['tags']) ? $_POST['item']['tags'] : array();
|
||||||
|
$pub = isset($_POST['is_public']) ? true : false;
|
||||||
|
|
||||||
|
if(isset($_POST['record_id']) && is_numeric($_POST['record_id']) ) { //EDIT
|
||||||
|
$bm = $_POST['record_id'];
|
||||||
|
editBookmark($bm, $_POST['url'], $_POST['title'], $tags, $_POST['desc'], $pub);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$bm = addBookmark($_POST['url'], $_POST['title'], $tags, $_POST['desc'], $pub);
|
||||||
|
}
|
||||||
|
OCP\JSON::success(array('id'=>$bm));
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Prep screen if we come from the bookmarklet
|
||||||
$url ='';
|
$url ='';
|
||||||
if(isset($_GET['url']) ){
|
if(isset($_GET['url']) ){
|
||||||
$url = $_GET['url'];
|
$url = $_GET['url'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($_POST['url'])) {
|
|
||||||
$tags = isset($_POST['item']['tags']) ? $_POST['item']['tags'] : array();
|
|
||||||
$pub = isset($_POST['is_public']) ? true : false;
|
|
||||||
$bm = addBookmark($_POST['url'], $_POST['title'], implode(',',$tags),$_POST['desc'], $pub);
|
|
||||||
OCP\JSON::success(array('id'=>$bm));
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
OCP\Util::addscript('bookmarks','tag-it');
|
|
||||||
OCP\Util::addscript('bookmarks','addBm');
|
|
||||||
OCP\Util::addStyle('bookmarks', 'bookmarks');
|
|
||||||
OCP\Util::addStyle('bookmarks', 'jquery.tagit');
|
|
||||||
|
|
||||||
if(!isset($_GET['title']) || trim($_GET['title']) == '') {
|
if(!isset($_GET['title']) || trim($_GET['title']) == '') {
|
||||||
$datas = getURLMetadata($url);
|
$datas = getURLMetadata($url);
|
||||||
$title = isset($datas['title']) ? $datas['title'] : '';
|
$title = isset($datas['title']) ? $datas['title'] : '';
|
||||||
@ -57,6 +61,14 @@ else{
|
|||||||
$title = $_GET['title'];
|
$title = $_GET['title'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OCP\Util::addscript('bookmarks','tag-it');
|
||||||
|
OCP\Util::addscript('bookmarks','addBm');
|
||||||
|
OCP\Util::addStyle('bookmarks', 'bookmarks');
|
||||||
|
OCP\Util::addStyle('bookmarks', 'jquery.tagit');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$bm = array('title'=> $title,
|
$bm = array('title'=> $title,
|
||||||
'url'=> $url,
|
'url'=> $url,
|
||||||
'tags'=> array(),
|
'tags'=> array(),
|
||||||
|
@ -80,7 +80,7 @@ function analyzeTagRequest($line) {
|
|||||||
return $filterTag;
|
return $filterTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBookmark($url, $title, $tags='', $description='', $is_public=false) {
|
function getNowValue() {
|
||||||
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
|
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
|
||||||
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
|
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
|
||||||
$_ut = "strftime('%s','now')";
|
$_ut = "strftime('%s','now')";
|
||||||
@ -89,9 +89,71 @@ function addBookmark($url, $title, $tags='', $description='', $is_public=false)
|
|||||||
} else {
|
} else {
|
||||||
$_ut = "UNIX_TIMESTAMP()";
|
$_ut = "UNIX_TIMESTAMP()";
|
||||||
}
|
}
|
||||||
|
return $_ut;
|
||||||
|
}
|
||||||
|
|
||||||
|
function editBookmark($id, $url, $title, $tags = array(), $description='', $is_public=false) {
|
||||||
|
|
||||||
$is_public = $is_public ? 1 : 0;
|
$is_public = $is_public ? 1 : 0;
|
||||||
//FIXME: Detect when user adds a known URL
|
$user_id = OCP\USER::getUser();
|
||||||
|
|
||||||
|
// Update the record
|
||||||
|
$query = OCP\DB::prepare("
|
||||||
|
UPDATE *PREFIX*bookmarks SET
|
||||||
|
url = ?, title = ?, public = ?, description = ?,
|
||||||
|
lastmodified = ".getNowValue() ."
|
||||||
|
WHERE id = ?
|
||||||
|
AND user_id = ?
|
||||||
|
");
|
||||||
|
|
||||||
|
$params=array(
|
||||||
|
htmlspecialchars_decode($url),
|
||||||
|
htmlspecialchars_decode($title),
|
||||||
|
$is_public,
|
||||||
|
htmlspecialchars_decode($description),
|
||||||
|
$id,
|
||||||
|
$user_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $query->execute($params);
|
||||||
|
|
||||||
|
// Abort the operation if bookmark couldn't be set
|
||||||
|
// (probably because the user is not allowed to edit this bookmark)
|
||||||
|
if ($result->numRows() == 0) exit();
|
||||||
|
|
||||||
|
|
||||||
|
// Remove old tags
|
||||||
|
$sql = "DELETE from *PREFIX*bookmarks_tags WHERE bookmark_id = ?";
|
||||||
|
$query = OCP\DB::prepare($sql);
|
||||||
|
$query->execute(array($id));
|
||||||
|
|
||||||
|
// Add New Tags
|
||||||
|
addTags($id, $tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTags($bookmark_id, $tags) {
|
||||||
|
$query = OCP\DB::prepare("
|
||||||
|
INSERT INTO *PREFIX*bookmarks_tags
|
||||||
|
(bookmark_id, tag)
|
||||||
|
VALUES (?, ?)
|
||||||
|
");
|
||||||
|
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
if(empty($tag)) {
|
||||||
|
//avoid saving blankspaces
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$params = array($bookmark_id, trim($tag));
|
||||||
|
$query->execute($params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBookmark($url, $title, $tags=array(), $description='', $is_public=false) {
|
||||||
|
|
||||||
|
$is_public = $is_public ? 1 : 0;
|
||||||
|
//FIXME: Detect and do smth when user adds a known URL
|
||||||
|
$_ut = getNowValue();
|
||||||
|
|
||||||
$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)
|
||||||
@ -110,22 +172,7 @@ function addBookmark($url, $title, $tags='', $description='', $is_public=false)
|
|||||||
$b_id = OCP\DB::insertid('*PREFIX*bookmarks');
|
$b_id = OCP\DB::insertid('*PREFIX*bookmarks');
|
||||||
|
|
||||||
if($b_id !== false) {
|
if($b_id !== false) {
|
||||||
$query = OCP\DB::prepare("
|
addTags($b_id, $tags);
|
||||||
INSERT INTO `*PREFIX*bookmarks_tags`
|
|
||||||
(`bookmark_id`, `tag`)
|
|
||||||
VALUES (?, ?)
|
|
||||||
");
|
|
||||||
|
|
||||||
$tags = explode(',', urldecode($tags));
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
if(empty($tag)) {
|
|
||||||
//avoid saving blankspaces
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$params = array($b_id, trim($tag));
|
|
||||||
$query->execute($params);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $b_id;
|
return $b_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
js/addBm.js
23
js/addBm.js
@ -45,6 +45,26 @@
|
|||||||
allowSpaces: true,
|
allowSpaces: true,
|
||||||
availableTags: fullTags
|
availableTags: fullTags
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(base.options['record']) { //Fill the form if it's an edit
|
||||||
|
record = base.options['record'];
|
||||||
|
base.$el.find('.record_id').val(record.id);
|
||||||
|
base.$el.find('.title').val(record.title);
|
||||||
|
base.$el.find('.url-ro code').text(record.url);
|
||||||
|
base.$el.find('.url_input').val(record.url);
|
||||||
|
base.$el.find('.desc').val(record.description);
|
||||||
|
base.$el.find('.is_public').val(record.public);
|
||||||
|
tagit_elem = base.$el.find('.tags');
|
||||||
|
for(var i=0;i<record.tags.length;i++) {
|
||||||
|
tagit_elem.tagit('createTag', record.tags[i]);
|
||||||
|
console.log(record.tags[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(base.$el.find('.url-ro code').text() != '')
|
||||||
|
base.$el.find('.url_input').hide();
|
||||||
|
else
|
||||||
|
base.$el.find('.url_input').shwo()
|
||||||
};
|
};
|
||||||
|
|
||||||
base.init();
|
base.init();
|
||||||
@ -54,7 +74,8 @@
|
|||||||
|
|
||||||
|
|
||||||
$.bookmark_dialog.defaultOptions = {
|
$.bookmark_dialog.defaultOptions = {
|
||||||
on_success: function(){}
|
on_success: function(){},
|
||||||
|
bookmark_record: undefined
|
||||||
};
|
};
|
||||||
|
|
||||||
$.fn.bookmark_dialog = function(options){
|
$.fn.bookmark_dialog = function(options){
|
||||||
|
@ -4,7 +4,7 @@ var bookmarks_loading = false;
|
|||||||
var bookmarks_sorting = 'bookmarks_sorting_recent';
|
var bookmarks_sorting = 'bookmarks_sorting_recent';
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#bookmark_add_submit').click(addOrEditBookmark);
|
$('#bookmark_add_submit').click(addBookmark);
|
||||||
$(window).resize(function () {
|
$(window).resize(function () {
|
||||||
fillWindow($('.bookmarks_list'));
|
fillWindow($('.bookmarks_list'));
|
||||||
});
|
});
|
||||||
@ -20,10 +20,9 @@ $(document).ready(function() {
|
|||||||
getBookmarks();
|
getBookmarks();
|
||||||
});
|
});
|
||||||
|
|
||||||
function addFilterTag(event)
|
function addFilterTag(event) {
|
||||||
{
|
event.preventDefault();
|
||||||
event.preventDefault();
|
$('#tag_filter input').tagit('createTag', $(this).text());
|
||||||
$('#tag_filter input').tagit('createTag', $(this).text());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTagsList(tag) {
|
function updateTagsList(tag) {
|
||||||
@ -43,7 +42,6 @@ function updateTagsList(tag) {
|
|||||||
function filterTagsChanged()
|
function filterTagsChanged()
|
||||||
{
|
{
|
||||||
$('#bookmarkFilterTag').val($('#tag_filter input:hidden').val());
|
$('#bookmarkFilterTag').val($('#tag_filter input:hidden').val());
|
||||||
console.log($('#bookmarkFilterTag').val());
|
|
||||||
bookmarks_page = 0;
|
bookmarks_page = 0;
|
||||||
$('.bookmarks_list').empty();
|
$('.bookmarks_list').empty();
|
||||||
getBookmarks();
|
getBookmarks();
|
||||||
@ -77,7 +75,7 @@ function getBookmarks() {
|
|||||||
}
|
}
|
||||||
$('.bookmark_link').unbind('click', recordClick);
|
$('.bookmark_link').unbind('click', recordClick);
|
||||||
$('.bookmark_delete').unbind('click', delBookmark);
|
$('.bookmark_delete').unbind('click', delBookmark);
|
||||||
$('.bookmark_edit').unbind('click', showBookmark);
|
$('.bookmark_edit').unbind('click', editBookmark);
|
||||||
|
|
||||||
for(var i in bookmarks.data) {
|
for(var i in bookmarks.data) {
|
||||||
updateBookmarksList(bookmarks.data[i]);
|
updateBookmarksList(bookmarks.data[i]);
|
||||||
@ -89,7 +87,7 @@ function getBookmarks() {
|
|||||||
|
|
||||||
$('.bookmark_link').click(recordClick);
|
$('.bookmark_link').click(recordClick);
|
||||||
$('.bookmark_delete').click(delBookmark);
|
$('.bookmark_delete').click(delBookmark);
|
||||||
$('.bookmark_edit').click(showBookmark);
|
$('.bookmark_edit').click(editBookmark);
|
||||||
|
|
||||||
bookmarks_loading = false;
|
bookmarks_loading = false;
|
||||||
if (bookmarks.data.length) {
|
if (bookmarks.data.length) {
|
||||||
@ -99,11 +97,8 @@ function getBookmarks() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// function addBookmark() {
|
|
||||||
// Instead of creating editBookmark() function, Converted the one above to
|
|
||||||
// addOrEditBookmark() to make .js file more compact.
|
|
||||||
|
|
||||||
function addOrEditBookmark(event) {
|
function createEditDialog(record){
|
||||||
dialog_html = $('#edit_dialog').html();
|
dialog_html = $('#edit_dialog').html();
|
||||||
var dialog = $(dialog_html).dialog({
|
var dialog = $(dialog_html).dialog({
|
||||||
width : 620,
|
width : 620,
|
||||||
@ -116,53 +111,16 @@ function addOrEditBookmark(event) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('.ui-dialog').bookmark_dialog({
|
$('.ui-dialog').bookmark_dialog({
|
||||||
'on_success': function(){
|
on_success: function(){
|
||||||
dialog.dialog('destroy').remove();
|
dialog.dialog('destroy').remove();
|
||||||
filterTagsChanged();
|
filterTagsChanged();
|
||||||
}
|
},
|
||||||
|
record: record
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/*var id = $('#bookmark_add_id').val();
|
function addBookmark(event) {
|
||||||
var url = encodeEntities($('#bookmark_add_url').val());
|
createEditDialog();
|
||||||
var title = encodeEntities($('#bookmark_add_title').val());
|
|
||||||
var tags = encodeEntities($('#bookmark_add_tags').val());
|
|
||||||
$("#firstrun").hide();
|
|
||||||
if($.trim(url) == '') {
|
|
||||||
OC.dialogs.alert('A valid bookmark url must be provided', 'Error creating bookmark');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if($.trim(title) == '') {
|
|
||||||
OC.dialogs.alert('A valid bookmark title must be provided', 'Error creating bookmark');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (id == 0) {
|
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: OC.filePath('bookmarks', 'ajax', 'addBookmark.php'),
|
|
||||||
data: 'url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&tags=' + encodeURIComponent(tags),
|
|
||||||
success: function(response){
|
|
||||||
$('.bookmarks_input').val('');
|
|
||||||
$('.bookmarks_list').empty();
|
|
||||||
bookmarks_page = 0;
|
|
||||||
getBookmarks();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$.ajax({
|
|
||||||
type: 'POST',
|
|
||||||
url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
|
|
||||||
data: 'id=' + id + '&url=' + encodeURIComponent(url) + '&title=' + encodeURIComponent(title) + '&tags=' + encodeURIComponent(tags),
|
|
||||||
success: function(){
|
|
||||||
$('.bookmarks_input').val('');
|
|
||||||
$('#bookmark_add_id').val('0');
|
|
||||||
$('.bookmarks_list').empty();
|
|
||||||
bookmarks_page = 0;
|
|
||||||
getBookmarks();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delBookmark(event) {
|
function delBookmark(event) {
|
||||||
@ -182,16 +140,10 @@ function delBookmark(event) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showBookmark(event) {
|
function editBookmark(event) {
|
||||||
var record = $(this).parent().parent();
|
var record = $(this).parent().parent();
|
||||||
$('#bookmark_add_id').val(record.attr('data-id'));
|
bookmark = record.data('record');
|
||||||
$('#bookmark_add_url').val(record.children('.bookmark_url:first').text());
|
createEditDialog(bookmark);
|
||||||
$('#bookmark_add_title').val(record.children('.bookmark_title:first').text());
|
|
||||||
$('#bookmark_add_tags').val(record.children('.bookmark_tags:first').text());
|
|
||||||
|
|
||||||
if ($('.bookmarks_add').css('display') == 'none') {
|
|
||||||
$('.bookmarks_add').slideToggle();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function replaceQueryString(url,param,value) {
|
function replaceQueryString(url,param,value) {
|
||||||
@ -229,6 +181,7 @@ function updateBookmarksList(bookmark) {
|
|||||||
'<p class="bookmark_url"><a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.url) + '</a></p>' +
|
'<p class="bookmark_url"><a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.url) + '</a></p>' +
|
||||||
'</div>'
|
'</div>'
|
||||||
);
|
);
|
||||||
|
$('div[data-id="'+ bookmark.id +'"]').data('record', bookmark);
|
||||||
if(taglist != '') {
|
if(taglist != '') {
|
||||||
$('div[data-id="'+ bookmark.id +'"]').append('<p class="bookmark_tags">' + taglist + '</p>');
|
$('div[data-id="'+ bookmark.id +'"]').append('<p class="bookmark_tags">' + taglist + '</p>');
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
<input type="submit" class="submit" value="<?php echo $l->t("Submit");?>" />
|
<input type="submit" class="submit" value="<?php echo $l->t("Submit");?>" />
|
||||||
<input type="checkbox" <?php if($_['bookmark']['is_public']){echo 'checked="checked"';} ?> id="is_public" name="is_public">
|
<input type="checkbox" <?php if($_['bookmark']['is_public']){echo 'checked="checked"';} ?> id="is_public" name="is_public">
|
||||||
<label for="is_public" class="is_public_label"><?php echo $l->t("Make this link public");?></label>
|
<label for="is_public" class="is_public_label"><?php echo $l->t("Make this link public");?></label>
|
||||||
|
<input type="hidden" class="record_id" value="" name="record_id" />
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user