From 19925df098aecaca81353c460b835f6257ddc953 Mon Sep 17 00:00:00 2001
From: Brice Maron
Date: Sun, 2 Sep 2012 15:18:36 +0000
Subject: [PATCH] Almost working in inline bookmark edit/add.
---
ajax/editBookmark.php | 4 +--
css/bookmarks.css | 6 ++++
js/bookmarks.js | 71 ++++++++++++++++++++-----------------------
templates/addBm.php | 2 +-
templates/list.php | 4 +--
5 files changed, 44 insertions(+), 43 deletions(-)
diff --git a/ajax/editBookmark.php b/ajax/editBookmark.php
index 5b9d2ffe..fbfe4f81 100644
--- a/ajax/editBookmark.php
+++ b/ajax/editBookmark.php
@@ -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();
diff --git a/css/bookmarks.css b/css/bookmarks.css
index c5fe48cd..7fe274ae 100644
--- a/css/bookmarks.css
+++ b/css/bookmarks.css
@@ -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;
diff --git a/js/bookmarks.js b/js/bookmarks.js
index 601ec2ec..c9212e0f 100644
--- a/js/bookmarks.js
+++ b/js/bookmarks.js
@@ -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' +
- '' +
- '' +
- '' +
- '' +
- '' +
- '' +
- ' ' +
- '
' +
- ''+
- '' + encodeEntities(bookmark.title) + '' +
- '
' +
- '' + encodeEntities(bookmark.url) + '
' +
- '' + formatDate(bookmark.added_date) + '
' +
- ''+ encodeEntities(bookmark.description) + '
' +
- ''
- );
- $('div[data-id="'+ bookmark.id +'"]').data('record', bookmark);
- if(taglist != '') {
- $('div[data-id="'+ bookmark.id +'"]').append('' + taglist + '
');
+ 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('' + taglist + '
');
+ }
+ 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);
}
}
diff --git a/templates/addBm.php b/templates/addBm.php
index 065efb18..e45319a7 100644
--- a/templates/addBm.php
+++ b/templates/addBm.php
@@ -30,7 +30,7 @@
-
+
diff --git a/templates/list.php b/templates/list.php
index b9925ed5..87b3ac25 100644
--- a/templates/list.php
+++ b/templates/list.php
@@ -69,7 +69,7 @@
- <%= encodeEntities(title) %>
+ <%= encodeEntities(title == '' ? url : title ) %>
<%= encodeEntities(url) %>
<%= formatDate(added_date) %>
@@ -90,7 +90,7 @@
<%=tags[i]%>
<% } %>
-
+