mirror of
https://github.com/owncloud/bookmarks.git
synced 2024-12-02 06:24:11 +01:00
Add possibility to rename and delete tags
This commit is contained in:
parent
ca750e4d6b
commit
8817ea366a
41
ajax/delTag.php
Normal file
41
ajax/delTag.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - bookmarks plugin
|
||||||
|
*
|
||||||
|
* @author Arthur Schiwon
|
||||||
|
* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//no apps or filesystem
|
||||||
|
$RUNTIME_NOSETUPFS=true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Check if we are a user
|
||||||
|
OCP\JSON::checkLoggedIn();
|
||||||
|
OCP\JSON::checkAppEnabled('bookmarks');
|
||||||
|
|
||||||
|
if(isset($_POST['old_name']))
|
||||||
|
{
|
||||||
|
OC_Bookmarks_Bookmarks::deleteTag($_POST['old_name']);
|
||||||
|
OCP\JSON::success();
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
OC_JSON::error();
|
||||||
|
exit();
|
41
ajax/renameTag.php
Normal file
41
ajax/renameTag.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - bookmarks plugin
|
||||||
|
*
|
||||||
|
* @author Arthur Schiwon
|
||||||
|
* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 3 of the License, or any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//no apps or filesystem
|
||||||
|
$RUNTIME_NOSETUPFS=true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Check if we are a user
|
||||||
|
OCP\JSON::checkLoggedIn();
|
||||||
|
OCP\JSON::checkAppEnabled('bookmarks');
|
||||||
|
|
||||||
|
if(isset($_POST['old_name']) && isset($_POST['new_name']) && $_POST['new_name'] != '')
|
||||||
|
{
|
||||||
|
OC_Bookmarks_Bookmarks::renameTag($_POST['old_name'], $_POST['new_name']);
|
||||||
|
OCP\JSON::success();
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
OC_JSON::error();
|
||||||
|
exit();
|
@ -164,11 +164,6 @@
|
|||||||
/* background: none repeat scroll 0 0 #DEE7F8; */
|
/* background: none repeat scroll 0 0 #DEE7F8; */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#tag_filter {
|
|
||||||
padding-left: 1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#leftcontent > ul > li, .leftcontent li {
|
#leftcontent > ul > li, .leftcontent li {
|
||||||
padding: 0.2em;
|
padding: 0.2em;
|
||||||
padding-left:1em;
|
padding-left:1em;
|
||||||
@ -193,6 +188,10 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ul.tagit li.tagit-new {
|
||||||
|
padding-left: 0em;
|
||||||
|
}
|
||||||
|
|
||||||
.tag_list em , .share_list em{
|
.tag_list em , .share_list em{
|
||||||
float:right;
|
float:right;
|
||||||
display:block;
|
display:block;
|
||||||
@ -210,6 +209,12 @@ li:hover em { display : none; }
|
|||||||
background: none repeat scroll 0 0 #F8F8F8;
|
background: none repeat scroll 0 0 #F8F8F8;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#tag_filter .tagit {
|
||||||
|
margin: 0.3em;
|
||||||
|
}
|
||||||
|
#tag_filter ul.tagit > li.tagit-new {
|
||||||
|
padding:0;
|
||||||
|
}
|
||||||
#tag_filter ul.tagit li.tagit-choice {
|
#tag_filter ul.tagit li.tagit-choice {
|
||||||
background: none repeat scroll 0 0 #DEE7F8;
|
background: none repeat scroll 0 0 #DEE7F8;
|
||||||
padding: 0.2em 18px 0.2em 0.5em;
|
padding: 0.2em 18px 0.2em 0.5em;
|
||||||
|
@ -16,7 +16,6 @@ $(document).ready(function() {
|
|||||||
onTagRemoved: filterTagsChanged
|
onTagRemoved: filterTagsChanged
|
||||||
}).tagit('option', 'onTagAdded', filterTagsChanged);
|
}).tagit('option', 'onTagAdded', filterTagsChanged);
|
||||||
|
|
||||||
|
|
||||||
getBookmarks();
|
getBookmarks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -28,15 +27,16 @@ function addFilterTag(event) {
|
|||||||
function updateTagsList(tag) {
|
function updateTagsList(tag) {
|
||||||
$('.tag_list').append('<li><a href="" class="tag">'+tag['tag']+'</a>'+
|
$('.tag_list').append('<li><a href="" class="tag">'+tag['tag']+'</a>'+
|
||||||
'<p class="tags_actions">'+
|
'<p class="tags_actions">'+
|
||||||
'<span class="bookmark_edit">'+
|
'<span class="tag_edit">'+
|
||||||
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">'+
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">'+
|
||||||
'</span>'+
|
'</span>'+
|
||||||
'<span class="bookmark_delete">'+
|
'<span class="tag_delete">'+
|
||||||
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">'+
|
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">'+
|
||||||
'</span>'+
|
'</span>'+
|
||||||
'</p>'+
|
'</p>'+
|
||||||
'<em>'+tag['nbr']+'</em>'+
|
'<em>'+tag['nbr']+'</em>'+
|
||||||
'</li>');
|
'</li>');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterTagsChanged()
|
function filterTagsChanged()
|
||||||
@ -61,7 +61,11 @@ function getBookmarks() {
|
|||||||
for(var i in tags.data) {
|
for(var i in tags.data) {
|
||||||
updateTagsList(tags.data[i]);
|
updateTagsList(tags.data[i]);
|
||||||
}
|
}
|
||||||
|
$('.tag_list .tag_edit').click(renameTag);
|
||||||
|
$('.tag_list .tag_delete').click(deleteTag);
|
||||||
$('.tag_list a.tag').click(addFilterTag);
|
$('.tag_list a.tag').click(addFilterTag);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -212,3 +216,51 @@ function hasProtocol(url) {
|
|||||||
var regexp = /(ftp|http|https|sftp)/;
|
var regexp = /(ftp|http|https|sftp)/;
|
||||||
return regexp.test(url);
|
return regexp.test(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renameTag(event) {
|
||||||
|
tag_el = $(this).closest('li');
|
||||||
|
tag_el.append('<input name="tag_new_name" type="text">');
|
||||||
|
|
||||||
|
tag_name = tag_el.find('.tag').hide().text();
|
||||||
|
tag_el.find('input').val(tag_name).bind('blur',submitTagName);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitTagName(event) {
|
||||||
|
tag_el = $(this).closest('li')
|
||||||
|
new_tag_name = tag_el.find('input').val();
|
||||||
|
old_tag_name = tag_el.find('.tag').show().text();
|
||||||
|
tag_el.find('input').remove();
|
||||||
|
|
||||||
|
//submit
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: OC.filePath('bookmarks', 'ajax', 'renameTag.php'),
|
||||||
|
data: { old_name: old_tag_name, new_name: new_tag_name},
|
||||||
|
success: function(bookmarks){
|
||||||
|
if (bookmarks.status =='success') {
|
||||||
|
filterTagsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteTag(event){
|
||||||
|
tag_el = $(this).closest('li');
|
||||||
|
var old_tag_name = tag_el.find('.tag').show().text();
|
||||||
|
OC.dialogs.confirm(t('bookmarks', 'Are you sure you want to remove this tag fro every entry?'),
|
||||||
|
t('bookmarks', 'Warning'), function(answer) {
|
||||||
|
if(answer) {
|
||||||
|
$.ajax({
|
||||||
|
type: 'POST',
|
||||||
|
url: OC.filePath('bookmarks', 'ajax', 'delTag.php'),
|
||||||
|
data: { old_name: old_tag_name},
|
||||||
|
success: function(bookmarks){
|
||||||
|
if (bookmarks.status =='success') {
|
||||||
|
filterTagsChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
@ -121,4 +121,46 @@ class OC_Bookmarks_Bookmarks{
|
|||||||
$result = $query->execute();
|
$result = $query->execute();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function renameTag($old, $new)
|
||||||
|
{
|
||||||
|
$user_id = OCP\USER::getUser();
|
||||||
|
|
||||||
|
// Update the record
|
||||||
|
$query = OCP\DB::prepare("
|
||||||
|
UPDATE *PREFIX*bookmarks_tags SET
|
||||||
|
tag = ?
|
||||||
|
WHERE tag = ?
|
||||||
|
AND exists( select id from *PREFIX*bookmarks where user_id = ? and bookmark_id = id)
|
||||||
|
");
|
||||||
|
|
||||||
|
$params=array(
|
||||||
|
$new,
|
||||||
|
$old,
|
||||||
|
$user_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $query->execute($params);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function deleteTag($old)
|
||||||
|
{
|
||||||
|
$user_id = OCP\USER::getUser();
|
||||||
|
|
||||||
|
// Update the record
|
||||||
|
$query = OCP\DB::prepare("
|
||||||
|
DELETE FROM *PREFIX*bookmarks_tags
|
||||||
|
WHERE tag = ?
|
||||||
|
AND exists( select id from *PREFIX*bookmarks where user_id = ? and bookmark_id = id)
|
||||||
|
");
|
||||||
|
|
||||||
|
$params=array(
|
||||||
|
$old,
|
||||||
|
$user_id,
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = $query->execute($params);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user