plugins/kolab_notes

Thomas Brüderli bruederli at kolabsys.com
Tue Nov 4 19:02:23 CET 2014


 plugins/kolab_notes/notes.js |   39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

New commits:
commit 52da8302cb0f29c57fac5a2c7b054c70c1e18c53
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Tue Nov 4 19:01:53 2014 +0100

    Apply dialog decision when dragging a yet unsaved note to another list (#3516)

diff --git a/plugins/kolab_notes/notes.js b/plugins/kolab_notes/notes.js
index 5a9e05f..d6e43d6 100644
--- a/plugins/kolab_notes/notes.js
+++ b/plugins/kolab_notes/notes.js
@@ -219,9 +219,28 @@ function rcube_kolab_notes_ui(settings)
                 // move dragged notes to this folder
                 if (folder_drop_target) {
                     noteslist.draglayer.hide();
-                    move_notes(folder_drop_target);
-                    noteslist.clear_selection();
-                    reset_view();
+
+                    // check unsaved changes first
+                    var new_folder_id = folder_drop_target;
+                    warn_unsaved_changes(
+                        // ok
+                        function() {
+                            move_notes(new_folder_id);
+                            reset_view();
+                            noteslist.clear_selection();
+                        },
+                        // nok
+                        undefined,
+                        // beforesave
+                        function(savedata) {
+                            savedata.list = new_folder_id;
+
+                            // remove from list and thus avoid being moved (again)
+                            var id = me.selected_note.id;
+                            noteslist.remove_row(id);
+                            delete notesdata[id];
+                        }
+                    );
                 }
                 folder_drop_target = null;
             })
@@ -1094,7 +1113,7 @@ function rcube_kolab_notes_ui(settings)
     {
         data.id = rcmail.html_identifier_encode(data.uid);
 
-        var row, is_new = notesdata[data.id] == undefined
+        var row, is_new = (notesdata[data.id] == undefined && data.list == me.selected_list);
         notesdata[data.id] = data;
 
         if (is_new || me.selected_note && data.id == me.selected_note.id) {
@@ -1142,7 +1161,7 @@ function rcube_kolab_notes_ui(settings)
     /**
      * Collect data from the edit form and submit it to the server
      */
-    function save_note()
+    function save_note(beforesave)
     {
         if (!me.selected_note) {
             return false;
@@ -1150,6 +1169,11 @@ function rcube_kolab_notes_ui(settings)
 
         var savedata = get_save_data();
 
+        // run savedata through the given callback function
+        if (typeof beforesave == 'function') {
+            beforesave(savedata);
+        }
+
         // add reference to old list if changed
         if (me.selected_note.list && savedata.list != me.selected_note.list) {
             savedata._fromlist = me.selected_note.list;
@@ -1227,7 +1251,7 @@ function rcube_kolab_notes_ui(settings)
     /**
      * Check for unsaved changes and warn the user
      */
-    function warn_unsaved_changes(ok, nok)
+    function warn_unsaved_changes(ok, nok, beforesave)
     {
         if (typeof ok != 'function')
             ok = function(){ };
@@ -1248,8 +1272,9 @@ function rcube_kolab_notes_ui(settings)
             buttons.push({
                 text: rcmail.gettext('save'),
                 click: function() {
-                    save_note();
+                    save_note(beforesave);
                     dialog.dialog('close');
+                    rcmail.busy = false;  // don't block next action
                     ok();
                 }
             });




More information about the commits mailing list