diff --git a/plugins/kolab_notes/kolab_notes.php b/plugins/kolab_notes/kolab_notes.php index 9a613f65..15f846ca 100644 --- a/plugins/kolab_notes/kolab_notes.php +++ b/plugins/kolab_notes/kolab_notes.php @@ -364,6 +364,17 @@ class kolab_notes extends rcube_plugin } break; + case 'move': + $uids = explode(',', $note['uid']); + foreach ($uids as $uid) { + $note['uid'] = $uid; + if (!($success = $this->move_note($note, $note['to']))) { + $refresh = $this->get_note($note); + break; + } + } + break; + case 'delete': $uids = explode(',', $note['uid']); foreach ($uids as $uid) { @@ -408,7 +419,7 @@ class kolab_notes extends rcube_plugin // moved from another folder if ($note['_fromlist'] && ($fromfolder = $this->folders[$note['_fromlist']])) { - if (!$fromfolder->move($note['id'], $folder->name)) + if (!$fromfolder->move($note['uid'], $folder->name)) return false; unset($note['_fromlist']); @@ -449,6 +460,22 @@ class kolab_notes extends rcube_plugin return $saved; } + /** + * Move the given note to another folder + */ + function move_note($note, $list_id) + { + $this->_read_lists(); + $tofolder = $this->folders[$list_id]; + $fromfolder = $this->folders[$note['list']]; + + if ($fromfolder && $tofolder) { + return $fromfolder->move($note['uid'], $tofolder->name); + } + + return false; + } + /** * Remove a single note record from the backend * diff --git a/plugins/kolab_notes/kolab_notes_ui.php b/plugins/kolab_notes/kolab_notes_ui.php index f3821400..5b4fbbc8 100644 --- a/plugins/kolab_notes/kolab_notes_ui.php +++ b/plugins/kolab_notes/kolab_notes_ui.php @@ -49,6 +49,7 @@ class kolab_notes_ui #$this->plugin->register_handler('plugin.detailview', array($this, 'detailview')); $this->rc->output->include_script('list.js'); + $this->rc->output->include_script('treelist.js'); $this->plugin->include_script('notes.js'); $this->plugin->include_script('jquery.tagedit.js'); @@ -99,7 +100,7 @@ class kolab_notes_ui $class .= ' '.$prop['class_name']; $items .= html::tag('li', array('id' => 'rcmliknb' . $html_id, 'class' => trim($class)), - html::span(array('class' => 'listname', 'title' => $title), Q($prop['listname'])) . + html::span(array('class' => 'listname', 'title' => $title), $prop['listname']) . html::span(array('class' => 'count'), '') ); } diff --git a/plugins/kolab_notes/localization/en_US.inc b/plugins/kolab_notes/localization/en_US.inc index 4301d1a7..3fe7d505 100644 --- a/plugins/kolab_notes/localization/en_US.inc +++ b/plugins/kolab_notes/localization/en_US.inc @@ -11,6 +11,7 @@ $labels['notags'] = 'No tags'; $labels['removetag'] = 'Remove tag'; $labels['created'] = 'Created'; $labels['changed'] = 'Last Modified'; +$labels['now'] = 'Now'; $labels['savingdata'] = 'Saving data...'; $labels['recordnotfound'] = 'Record not found'; diff --git a/plugins/kolab_notes/notes.js b/plugins/kolab_notes/notes.js index 7365ac98..fe90072f 100644 --- a/plugins/kolab_notes/notes.js +++ b/plugins/kolab_notes/notes.js @@ -25,6 +25,8 @@ function rcube_kolab_notes_ui(settings) var ui_loading = false; var saving_lock; var search_query; + var folder_drop_target; + var notebookslist; var noteslist; var notesdata = {}; var tagsfilter = []; @@ -47,7 +49,7 @@ function rcube_kolab_notes_ui(settings) rcmail.register_command('list-edit', function(){ list_edit_dialog(me.selected_list); }, false); rcmail.register_command('list-remove', function(){ list_remove(me.selected_list); }, false); rcmail.register_command('save', save_note, true); - rcmail.register_command('delete', delete_note, false); + rcmail.register_command('delete', delete_notes, false); rcmail.register_command('search', quicksearch, true); rcmail.register_command('reset-search', reset_search, true); @@ -67,17 +69,30 @@ function rcube_kolab_notes_ui(settings) // initialize folder selectors var li, id; for (id in me.notebooks) { - init_folder_li(id); - if (me.notebooks[id].editable && (!me.selected_list || (me.notebooks[id].active && !me.notebooks[me.selected_list].active))) { me.selected_list = id; } } + notebookslist = new rcube_treelist_widget(rcmail.gui_objects.notebooks, { + id_prefix: 'rcmliknb', + selectable: true, + check_droptarget: function(node) { + return !node.virtual && node.id != me.selected_list; + } + }); + notebookslist.addEventListener('select', function(node) { + var id = node.id; + if (me.notebooks[id]) { + rcmail.enable_command('list-edit', 'list-remove', me.notebooks[id].editable); + fetch_notes(id); // sets me.notebooks[id] + } + }); + // initialize notes list widget if (rcmail.gui_objects.noteslist) { noteslist = new rcube_list_widget(rcmail.gui_objects.noteslist, - { multiselect:true, draggable:false, keyboard:false }); + { multiselect:true, draggable:true, keyboard:false }); noteslist.addEventListener('select', function(list) { var note; if (list.selection.length == 1 && (note = notesdata[list.selection[0]])) { @@ -90,6 +105,25 @@ function rcube_kolab_notes_ui(settings) rcmail.enable_command('delete', me.notebooks[me.selected_list] && me.notebooks[me.selected_list].editable && list.selection.length > 0); }) + .addEventListener('dragstart', function(e) { + folder_drop_target = null; + notebookslist.drag_start(); + }) + .addEventListener('dragmove', function(e) { + folder_drop_target = notebookslist.intersects(rcube_event.get_mouse_pos(e), true); + }) + .addEventListener('dragend', function(e) { + notebookslist.drag_end(); + + // move dragged notes to this folder + if (folder_drop_target) { + noteslist.draglayer.hide(); + move_notes(folder_drop_target); + noteslist.clear_selection(); + reset_view(); + } + folder_drop_target = null; + }) .init(); } @@ -179,7 +213,7 @@ function rcube_kolab_notes_ui(settings) if (me.selected_list) { rcmail.enable_command('createnote', true); - $('#rcmliknb'+me.selected_list).click(); + notebookslist.select(me.selected_list) } } this.init = init; @@ -200,23 +234,6 @@ function rcube_kolab_notes_ui(settings) return String(str).replace(/\s+$/, '').replace(/^\s+/, ''); } - /** - * - */ - function init_folder_li(id) - { - $('#rcmliknb'+id).click(function(e){ - var id = $(this).data('id'); - rcmail.enable_command('list-edit', 'list-remove', me.notebooks[id].editable); - fetch_notes(id); - me.selected_list = id; - }) - .dblclick(function(e){ - // list_edit_dialog($(this).data('id')); - }) - .data('id', id); - } - /** * */ @@ -224,7 +241,15 @@ function rcube_kolab_notes_ui(settings) { if (!uid) { noteslist.clear_selection(); - me.selected_note = { list:me.selected_list, uid:null, title:rcmail.gettext('newnote','kolab_notes'), description:'', categories:[] } + me.selected_note = { + list: me.selected_list, + uid: null, + title: rcmail.gettext('newnote','kolab_notes'), + description: '', + categories: [], + created: rcmail.gettext('now', 'kolab_notes'), + changed: rcmail.gettext('now', 'kolab_notes') + } render_note(me.selected_note); } else { @@ -273,10 +298,9 @@ function rcube_kolab_notes_ui(settings) if (rcmail.busy) return; - if (id) { + if (id && id != me.selected_list) { me.selected_list = id; - $('li.selected', rcmail.gui_objects.notebooks).removeClass('selected') - $('#rcmliknb'+id).addClass('selected'); + noteslist.clear_selection(); } ui_loading = rcmail.set_busy(true, 'loading'); @@ -599,7 +623,10 @@ function rcube_kolab_notes_ui(settings) rcmail.http_post('action', { _data: savedata, _do: savedata.uid?'edit':'new' }, true); } - function delete_note() + /** + * + */ + function delete_notes() { if (!noteslist.selection.length) { return false; @@ -623,7 +650,28 @@ function rcube_kolab_notes_ui(settings) reset_view(); update_tagcloud(); } + } + /** + * + */ + function move_notes(list_id) + { + var rec, id, uids = []; + for (var i=0; i < noteslist.selection.length; i++) { + id = noteslist.selection[i]; + rec = notesdata[id]; + if (rec) { + noteslist.remove_row(id); + uids.push(rec.uid); + delete notesdata[id]; + } + } + + if (uids.length) { + saving_lock = rcmail.set_busy(true, 'kolab_notes.savingdata'); + rcmail.http_post('action', { _data: { uid: uids.join(','), list: me.selected_list, to: list_id }, _do: 'move' }, true); + } } } diff --git a/plugins/kolab_notes/skins/larry/notes.css b/plugins/kolab_notes/skins/larry/notes.css index 747e0d19..f3fec4ae 100644 --- a/plugins/kolab_notes/skins/larry/notes.css +++ b/plugins/kolab_notes/skins/larry/notes.css @@ -231,7 +231,7 @@ display: block; position: absolute; top: 7px; - left: 32px; + left: 9px; right: 26px; cursor: default; padding-bottom: 2px;