[Svn] r6080 - trunk/roundcubemail/program/js

trac at roundcube.net trac at roundcube.net
Fri Apr 13 15:50:55 CEST 2012


Author: alec
Date: 2012-04-13 08:50:54 -0500 (Fri, 13 Apr 2012)
New Revision: 6080

Modified:
   trunk/roundcubemail/program/js/app.js
Log:
- Code improvements, handle post/get request arguments as objects


Modified: trunk/roundcubemail/program/js/app.js
===================================================================
--- trunk/roundcubemail/program/js/app.js	2012-04-13 13:31:19 UTC (rev 6079)
+++ trunk/roundcubemail/program/js/app.js	2012-04-13 13:50:54 UTC (rev 6080)
@@ -231,8 +231,7 @@
           this.enable_command('reply-list', this.env.list_post);
 
           if (this.env.action == 'show') {
-            this.http_request('pagenav', '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox)
-              + (this.env.search_request ? '&_search='+this.env.search_request : ''),
+            this.http_request('pagenav', {_uid: this.env.uid, _mbox: this.env.mailbox, _search: this.env.search_request},
               this.display_message('', 'loading'));
           }
 
@@ -281,7 +280,7 @@
         if (this.gui_objects.mailboxlist) {
           this.env.unread_counts = {};
           this.gui_objects.folderlist = this.gui_objects.mailboxlist;
-          this.http_request('getunread', '');
+          this.http_request('getunread');
         }
 
         // init address book widget
@@ -300,11 +299,13 @@
 
         // ask user to send MDN
         if (this.env.mdn_request && this.env.uid) {
-          var mdnurl = '_uid='+this.env.uid+'&_mbox='+urlencode(this.env.mailbox);
-          if (confirm(this.get_label('mdnrequest')))
-            this.http_post('sendmdn', mdnurl);
-          else
-            this.http_post('mark', mdnurl+'&_flag=mdnsent');
+          var postact = 'sendmdn',
+            postdata = {_uid: this.env.uid, _mbox: this.env.mailbox};
+          if (!confirm(this.get_label('mdnrequest'))) {
+            postdata._flag = 'mdnsent';
+            postact = 'mark';
+          }
+          this.http_post(postact, postdata);
         }
 
         break;
@@ -1235,8 +1236,8 @@
 
       return url.replace(/(\?.*)$/, urldata);
     }
-    else
-      return url + '?' + name + '=' + value;
+
+    return url + '?' + name + '=' + value;
   };
 
   this.is_framed = function()
@@ -1891,7 +1892,7 @@
 
   this.set_list_options = function(cols, sort_col, sort_order, threads)
   {
-    var update, add_url = '';
+    var update, post_data = {};
 
     if (sort_col === undefined)
       sort_col = this.env.sort_col;
@@ -1905,7 +1906,7 @@
 
     if (this.env.threading != threads) {
       update = 1;
-      add_url += '&_threads=' + threads;
+      post_data._threads = threads;
     }
 
     if (cols && cols.length) {
@@ -1925,12 +1926,12 @@
 
       if (newcols.join() != oldcols.join()) {
         update = 1;
-        add_url += '&_cols=' + newcols.join(',');
+        post_data._cols = newcols.join(',');
       }
     }
 
     if (update)
-      this.list_mailbox('', '', sort_col+'_'+sort_order, add_url);
+      this.list_mailbox('', '', sort_col+'_'+sort_order, post_data);
   };
 
   // when user doble-clicks on a row
@@ -1970,7 +1971,7 @@
             ref.set_unread_count(ref.env.mailbox, ref.env.unread_counts[ref.env.mailbox], ref.env.mailbox == 'INBOX');
           }
           if (ref.env.preview_pane_mark_read > 0)
-            ref.http_post('mark', '_uid='+id+'&_flag=read&_quiet=1');
+            ref.http_post('mark', {_uid: id, _flag: 'read', _quiet: 1});
         }, this.env.preview_pane_mark_read * 1000);
       }
     }
@@ -2033,23 +2034,23 @@
   };
 
   // list messages of a specific mailbox
-  this.list_mailbox = function(mbox, page, sort, add_url)
+  this.list_mailbox = function(mbox, page, sort, url)
   {
-    var url = '', target = window;
+    var target = window;
 
+    if (typeof url != 'object')
+      url = {};
+
     if (!mbox)
       mbox = this.env.mailbox ? this.env.mailbox : 'INBOX';
 
-    if (add_url)
-      url += add_url;
-
     // add sort to url if set
     if (sort)
-      url += '&_sort=' + sort;
+      url._sort = sort;
 
     // also send search request to get the right messages
     if (this.env.search_request)
-      url += '&_search='+this.env.search_request;
+      url._search = this.env.search_request;
 
     // set page=1 if changeing to another mailbox
     if (this.env.mailbox != mbox) {
@@ -2062,7 +2063,7 @@
     this.clear_message_list();
 
     if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort))
-      url += '&_refresh=1';
+      url._refresh = 1;
 
     this.select_folder(mbox, '', true);
     this.unmark_folder(mbox, 'recent', '', true);
@@ -2076,13 +2077,16 @@
 
     if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) {
       target = window.frames[this.env.contentframe];
-      url += '&_framed=1';
+      url._framed = 1;
     }
 
     // load message list to target frame/window
     if (mbox) {
       this.set_busy(true, 'loading');
-      this.location_href(this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+url, target);
+      url._mbox = mbox;
+      if (page)
+        url._page = page;
+      this.location_href(url, target);
     }
   };
 
@@ -2097,15 +2101,20 @@
   };
 
   // send remote request to load message list
-  this.list_mailbox_remote = function(mbox, page, add_url)
+  this.list_mailbox_remote = function(mbox, page, post_data)
   {
     // clear message list first
     this.message_list.clear();
 
-    // send request to server
-    var url = '_mbox='+urlencode(mbox)+(page ? '&_page='+page : ''),
-      lock = this.set_busy(true, 'loading');
-    this.http_request('list', url+add_url, lock);
+    var lock = this.set_busy(true, 'loading');
+
+    if (typeof post_data != 'object')
+      post_data = {};
+    post_data._mbox = mbox;
+    if (page)
+      post_data._page = page;
+
+    this.http_request('list', post_data, lock);
   };
 
   // removes messages that doesn't exists from list selection array
@@ -2498,23 +2507,23 @@
     if (!mbox || mbox == this.env.mailbox || (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)))
       return;
 
-    var a_uids = [],
+    var a_uids = [], n, selection,
       lock = this.display_message(this.get_label('copyingmessage'), 'loading'),
-      add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
+      post_data = {_mbox: this.env.mailbox, _target_mbox: mbox, _from: (this.env.action ? this.env.action : '')};
 
     if (this.env.uid)
       a_uids[0] = this.env.uid;
     else {
-      var selection = this.message_list.get_selection();
-      for (var n in selection) {
+      selection = this.message_list.get_selection();
+      for (n in selection) {
         a_uids.push(selection[n]);
       }
     }
 
-    add_url += '&_uid='+this.uids_to_list(a_uids);
+    post_data._uid = this.uids_to_list(a_uids);
 
     // send request to server
-    this.http_post('copy', '_mbox='+urlencode(this.env.mailbox)+add_url, lock);
+    this.http_post('copy', post_data, lock);
   };
 
   // move selected messages to the specified mailbox
@@ -2528,19 +2537,18 @@
       return;
 
     var lock = false,
-      add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : '');
+      add_post = {_target_mbox: mbox, _from: (this.env.action ? this.env.action : '')};
 
     // show wait message
-    if (this.env.action == 'show') {
+    if (this.env.action == 'show')
       lock = this.set_busy(true, 'movingmessage');
-    }
     else
       this.show_contentframe(false);
 
     // Hide message command buttons until a message is selected
     this.enable_command(this.env.message_commands, false);
 
-    this._with_selected_messages('moveto', lock, add_url);
+    this._with_selected_messages('moveto', lock, add_post);
   };
 
   // delete selected messages from the current mailbox
@@ -2595,15 +2603,18 @@
       return;
 
     this.show_contentframe(false);
-    this._with_selected_messages('delete', false, '&_from='+(this.env.action ? this.env.action : ''));
+    this._with_selected_messages('delete', false, {_from: this.env.action ? this.env.action : ''});
   };
 
   // Send a specifc moveto/delete request with UIDs of all selected messages
   // @private
-  this._with_selected_messages = function(action, lock, add_url)
+  this._with_selected_messages = function(action, lock, post_data)
   {
-    var a_uids = [], count = 0, msg;
+    var a_uids = [], count = 0, msg, lock;
 
+    if (typeof(post_data) != 'object')
+      post_data = {};
+
     if (this.env.uid)
       a_uids[0] = this.env.uid;
     else {
@@ -2634,18 +2645,19 @@
 
     // also send search request to get the right messages
     if (this.env.search_request)
-      add_url += '&_search='+this.env.search_request;
+      post_data._search = this.env.search_request;
 
     if (this.env.display_next && this.env.next_uid)
-      add_url += '&_next_uid='+this.env.next_uid;
+      post_data._next_uid = this.env.next_uid;
 
     if (count < 0)
-      add_url += '&_count='+(count*-1);
-    else if (count > 0) 
-      // remove threads from the end of the list
+      post_data._count = (count*-1);
+    // remove threads from the end of the list
+    else if (count > 0)
       this.delete_excessive_thread_rows();
 
-    add_url += '&_uid='+this.uids_to_list(a_uids);
+    post_data._uid = this.uids_to_list(a_uids);
+    post_data._mbox = this.env.mailbox;
 
     if (!lock) {
       msg = action == 'moveto' ? 'movingmessage' : 'deletingmessage';
@@ -2653,7 +2665,7 @@
     }
 
     // send request to server
-    this.http_post(action, '_mbox='+urlencode(this.env.mailbox)+add_url, lock);
+    this.http_post(action, post_data, lock);
   };
 
   // set a specific flag to one or more messages
@@ -2712,7 +2724,7 @@
   this.toggle_read_status = function(flag, a_uids)
   {
     var i, len = a_uids.length,
-      url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag,
+      post_data = {_uid: this.uids_to_list(a_uids), _flag: flag},
       lock = this.display_message(this.get_label('markingmessage'), 'loading');
 
     // mark all message rows as read/unread
@@ -2721,9 +2733,9 @@
 
     // also send search request to get the right messages
     if (this.env.search_request)
-      url += '&_search='+this.env.search_request;
+      post_data._search = this.env.search_request;
 
-    this.http_post('mark', url, lock);
+    this.http_post('mark', post_data, lock);
 
     for (i=0; i<len; i++)
       this.update_thread_root(a_uids[i], flag);
@@ -2733,7 +2745,7 @@
   this.toggle_flagged_status = function(flag, a_uids)
   {
     var i, len = a_uids.length,
-      url = '_uid='+this.uids_to_list(a_uids)+'&_flag='+flag,
+      post_data = {_uid: this.uids_to_list(a_uids), _flag: flag},
       lock = this.display_message(this.get_label('markingmessage'), 'loading');
 
     // mark all message rows as flagged/unflagged
@@ -2742,9 +2754,9 @@
 
     // also send search request to get the right messages
     if (this.env.search_request)
-      url += '&_search='+this.env.search_request;
+      post_data._search = this.env.search_request;
 
-    this.http_post('mark', url, lock);
+    this.http_post('mark', post_data, lock);
   };
 
   // mark all message rows as deleted/undeleted
@@ -2782,7 +2794,7 @@
   this.flag_as_undeleted = function(a_uids)
   {
     var i, len=a_uids.length,
-      url = '_uid='+this.uids_to_list(a_uids)+'&_flag=undelete',
+      post_data = {_uid: this.uids_to_list(a_uids), _flag: 'undelete'},
       lock = this.display_message(this.get_label('markingmessage'), 'loading');
 
     for (i=0; i<len; i++)
@@ -2790,16 +2802,17 @@
 
     // also send search request to get the right messages
     if (this.env.search_request)
-      url += '&_search='+this.env.search_request;
+      post_data._search = this.env.search_request;
 
-    this.http_post('mark', url, lock);
+    this.http_post('mark', post_data, lock);
     return true;
   };
 
   this.flag_as_deleted = function(a_uids)
   {
-    var add_url = '',
-      r_uids = [],
+    var r_uids = [],
+      post_data = {_uid: this.uids_to_list(a_uids), _flag: 'delete'},
+      lock = this.display_message(this.get_label('markingmessage'), 'loading'),
       rows = this.message_list ? this.message_list.rows : [],
       count = 0;
 
@@ -2823,29 +2836,27 @@
       if(!this.env.display_next)
         this.message_list.clear_selection();
       if (count < 0)
-        add_url += '&_count='+(count*-1);
+        post_data._count = (count*-1);
       else if (count > 0) 
         // remove threads from the end of the list
         this.delete_excessive_thread_rows();
     }
 
-    add_url = '&_from='+(this.env.action ? this.env.action : ''),
-      lock = this.display_message(this.get_label('markingmessage'), 'loading');
+    if (this.env.action)
+      post_data._from = this.env.action;
 
     // ??
     if (r_uids.length)
-      add_url += '&_ruid='+this.uids_to_list(r_uids);
+      post_data._ruid = this.uids_to_list(r_uids);
 
-    if (this.env.skip_deleted) {
-      if (this.env.display_next && this.env.next_uid)
-        add_url += '&_next_uid='+this.env.next_uid;
-    }
+    if (this.env.skip_deleted && this.env.display_next && this.env.next_uid)
+      post_data._next_uid = this.env.next_uid;
 
     // also send search request to get the right messages
     if (this.env.search_request)
-      add_url += '&_search='+this.env.search_request;
+      post_data._search = this.env.search_request;
 
-    this.http_post('mark', '_uid='+this.uids_to_list(a_uids)+'&_flag=delete'+add_url, lock);
+    this.http_post('mark', post_data, lock);
     return true;
   };
 
@@ -2892,24 +2903,23 @@
 
   this.expunge_mailbox = function(mbox)
   {
-    var lock, url = '_mbox='+urlencode(mbox);
+    var lock, post_data = {_mbox: mbox};
 
     // lock interface if it's the active mailbox
     if (mbox == this.env.mailbox) {
       lock = this.set_busy(true, 'loading');
-      url += '&_reload=1';
+      post_data._reload = 1;
       if (this.env.search_request)
-        url += '&_search='+this.env.search_request;
+        post_data._search = this.env.search_request;
     }
 
     // send request to server
-    this.http_post('expunge', url, lock);
+    this.http_post('expunge', post_data, lock);
   };
 
   this.purge_mailbox = function(mbox)
   {
-    var lock = false,
-      url = '_mbox='+urlencode(mbox);
+    var lock, post_data = {_mbox: mbox};
 
     if (!confirm(this.get_label('purgefolderconfirm')))
       return false;
@@ -2917,11 +2927,11 @@
     // lock interface if it's the active mailbox
     if (mbox == this.env.mailbox) {
        lock = this.set_busy(true, 'loading');
-       url += '&_reload=1';
+       post_data._reload = 1;
      }
 
     // send request to server
-    this.http_post('purge', url, lock);
+    this.http_post('purge', post_data, lock);
   };
 
   // test if purge command is allowed
@@ -3037,7 +3047,7 @@
           if (id.charAt(0) == 'E' && this.env.contactdata[id].index