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

Almost working in inline bookmark edit/add.

This commit is contained in:
Brice Maron 2012-09-02 15:18:36 +00:00
parent 18372c5220
commit 19925df098
5 changed files with 44 additions and 43 deletions

View File

@ -34,10 +34,10 @@ if(isset($_POST['url'])) {
if(isset($_POST['record_id']) && is_numeric($_POST['record_id']) ) { //EDIT
$bm = $_POST['record_id'];
OC_Bookmarks_Bookmarks::editBookmark($bm, $_POST['url'], $_POST['title'], $tags, $_POST['desc'], $pub);
OC_Bookmarks_Bookmarks::editBookmark($bm, $_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
}
else {
$bm = OC_Bookmarks_Bookmarks::addBookmark($_POST['url'], $_POST['title'], $tags, $_POST['desc'], $pub);
$bm = OC_Bookmarks_Bookmarks::addBookmark($_POST['url'], $_POST['title'], $tags, $_POST['description'], $pub);
}
OCP\JSON::success(array('id'=>$bm));
exit();

View File

@ -316,6 +316,12 @@ li:hover em { display : none; }
width: 80%;
}
.bookmark_single_form {
padding-top: 1em;
border-bottom: 1px solid #DDD;
padding-left: 2em;
}
.bookmark_single_form .tagit{
width: 80%;
box-shadow: 0 1px 1px #FFFFFF, 0 1px 0 #BBBBBB inset;

View File

@ -193,16 +193,17 @@ function createEditDialog(record){
function addBookmark(event) {
url = $('#add_url').val();
createEditDialog({ url: url});
$('#add_url').val('');
bookmark = { url: url, description:'', title:''};
$.ajax({
type: 'GET',
url: OC.filePath('bookmarks', 'ajax', 'getInfos.php'),
data: { type: 'url_info', url: url},
type: 'POST',
url: OC.filePath('bookmarks', 'ajax', 'editBookmark.php'),
data: bookmark,
success: function(data){
if (data.status == 'success') {
$('.ui-dialog').data('bookmark_dialog').setTitle(data.title);
bookmark.id = data.id;
bookmark.added_date = new Date();
updateBookmarksList(bookmark, 'prepend');
}
}
});
@ -213,7 +214,7 @@ function delBookmark(event) {
$.ajax({
type: 'POST',
url: OC.filePath('bookmarks', 'ajax', 'delBookmark.php'),
data: 'id=' + record.data('id'),
data: { id: record.data('id') },
success: function(data){
if (data.status == 'success') {
record.remove();
@ -228,14 +229,12 @@ function delBookmark(event) {
function editBookmark(event) {
var record = $(this).parent().parent();
bookmark = record.data('record');
console.log(bookmark);
//createEditDialog(bookmark);
html = tmpl("item_form_tmpl", bookmark);
record.after(html);
record.hide();
rec_form = record.next().find('form');
console.log(rec_form);
rec_form.find('.bookmark_form_tags ul').tagit({
allowSpaces: true,
availableTags: fullTags,
@ -251,6 +250,7 @@ function cancelBookmark(event) {
rec_form.prev().show();
rec_form.remove();
}
function submitBookmark(event) {
event.preventDefault();
form_values = $(this).serialize();
@ -268,8 +268,10 @@ function submitBookmark(event) {
}
});
}
function updateBookmarksList(bookmark) {
var tags = bookmark.tags;
function updateBookmarksList(bookmark, position='append') {
bookmark = $.extend({title:'', description:'', added_date: new Date('now'), tags:[] }, bookmark);
tags = bookmark.tags;
var taglist = '';
for ( var i=0, len=tags.length; i<len; ++i ){
if(tags[i] != '')
@ -278,10 +280,11 @@ function updateBookmarksList(bookmark) {
if(!hasProtocol(bookmark.url)) {
bookmark.url = 'http://' + bookmark.url;
}
if(bookmark.title == '') bookmark.title = bookmark.url;
bookmark.added_date = new Date();
bookmark.added_date.setTime(parseInt(bookmark.added)*1000);
if(bookmark.added) {
bookmark.added_date.setTime(parseInt(bookmark.added)*1000);
}
if(bookmark_view == 'image') { //View in images
service_url = formatString(shot_provider, {url: encodeEntities(bookmark.url), title: bookmark.title, width: 200});
$('.bookmarks_list').append(
@ -308,30 +311,22 @@ function updateBookmarksList(bookmark) {
}
$('div[data-id="'+ bookmark.id +'"] a.bookmark_tag').bind('click', addFilterTag);
}
else { // View in text
$('.bookmarks_list').append(
'<div class="bookmark_single" data-id="' + bookmark.id +'" >' +
'<p class="bookmark_actions">' +
'<span class="bookmark_edit">' +
'<img class="svg" src="'+OC.imagePath('core', 'actions/rename')+'" title="Edit">' +
'</span>' +
'<span class="bookmark_delete">' +
'<img class="svg" src="'+OC.imagePath('core', 'actions/delete')+'" title="Delete">' +
'</span>&nbsp;' +
'</p>' +
'<p class="bookmark_title">'+
'<a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.title) + '</a>' +
'</p>' +
'<p class="bookmark_url"><a href="' + encodeEntities(bookmark.url) + '" target="_blank" class="bookmark_link">' + encodeEntities(bookmark.url) + '</a></p>' +
'<p class="bookmark_date">' + formatDate(bookmark.added_date) + '</p>' +
'<p class="bookmark_desc">'+ encodeEntities(bookmark.description) + '</p>' +
'</div>'
);
$('div[data-id="'+ bookmark.id +'"]').data('record', bookmark);
if(taglist != '') {
$('div[data-id="'+ bookmark.id +'"]').append('<p class="bookmark_tags">' + taglist + '</p>');
else {
html = tmpl("item_tmpl", bookmark);
if(position == "prepend") {
$('.bookmarks_list').prepend(html);
} else {
$('.bookmarks_list').append(html);
}
$('div[data-id="'+ bookmark.id +'"] a.bookmark_tag').bind('click', addFilterTag);
line = $('div[data-id="'+ bookmark.id +'"]');
line.data('record', bookmark);
if(taglist != '') {
line.append('<p class="bookmark_tags">' + taglist + '</p>');
}
line.find('a.bookmark_tag').bind('click', addFilterTag);
line.find('.bookmark_link').click(recordClick);
line.find('.bookmark_delete').click(delBookmark);
line.find('.bookmark_edit').click(editBookmark);
}
}

View File

@ -30,7 +30,7 @@
</li>
<li>
<textarea name="desc" class="desc" value="<?php echo $_['bookmark']['desc']; ?>" placeholder="<?php echo $l->t('Description of the page');?>"></textarea>
<textarea name="description" class="desc" value="<?php echo $_['bookmark']['desc']; ?>" placeholder="<?php echo $l->t('Description of the page');?>"></textarea>
</li>
<li>

View File

@ -69,7 +69,7 @@
</span>&nbsp;
</p>
<p class="bookmark_title">
<a href="<%= encodeEntities(url) %>" target="_blank" class="bookmark_link"><%= encodeEntities(title) %></a>
<a href="<%= encodeEntities(url) %>" target="_blank" class="bookmark_link"><%= encodeEntities(title == '' ? url : title ) %></a>
</p>
<p class="bookmark_url"><a href="<%= encodeEntities(url) %>" target="_blank" class="bookmark_link"><%= encodeEntities(url) %></a></p>
<p class="bookmark_date"><%= formatDate(added_date) %></p>
@ -90,7 +90,7 @@
<li><%=tags[i]%></li>
<% } %>
</ul></div>
<p class="bookmark_form_desc"><textarea name="desc" placeholder="<?php echo $l->t('Description of the page');?>"><%= description%></textarea> </p>
<p class="bookmark_form_desc"><textarea name="description" placeholder="<?php echo $l->t('Description of the page');?>"><%= description%></textarea> </p>
<p class="bookmark_form_submit"><button class="reset" ><?php echo $l->t('Cancel');?></button><input type="submit" value="<?php echo $l->t('Save');?>"></p>
</form>
</div>