Changeset 759 in subversion
- Timestamp:
- Aug 29, 2007 9:03:06 PM (6 years ago)
- Location:
- branches/devel-vnext/program/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/devel-vnext/program/js/app.js
r752 r759 34 34 // create protected reference to myself 35 35 rcube_webmail_client = this; 36 this.ref = 'rcube_webmail_client';37 var ref = this;36 this.ref = 'rcube_webmail_client'; 37 var ref = this; 38 38 39 39 // webmail client settings … … 132 132 case 'mail': 133 133 if (this.gui_objects.messagelist) { 134 this.message_list = new rcube_list_widget(this.gui_objects.messagelist, {multiselect:true, draggable:true, keyboard:true, dblclick_time:this.dblclick_time}); 134 this.message_list = new rcube_list_widget( 135 this.gui_objects.messagelist, 136 {multiselect:true,draggable:true,keyboard:true,dblclick_time:this.dblclick_time} 137 ); 135 138 this.message_list.row_init = function(o){ p.init_message_row(o); }; 136 139 this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); }); … … 159 162 ); 160 163 161 if (this.env.action=='show' || this.env.action=='preview') { 162 this.enable_command('show', 'reply', 'reply-all', 'forward', 'moveto', 'delete', 'viewsource', 'print', 'load-attachment', true); 164 if (this.env.action == 'show' || this.env.action == 'preview') { 165 this.enable_command( 166 'show', 'reply', 'reply-all', 167 'forward', 'moveto', 'delete', 168 'viewsource', 'print', 169 'load-attachment', true 170 ); 163 171 if (this.env.next_uid) { 164 172 this.enable_command('nextmessage', true); … … 200 208 } 201 209 202 if (this.env.messagecount && (this.env.mailbox==this.env.trash_mailbox || this.env.mailbox==this.env.junk_mailbox)) { 210 // only enable purge for trash folder 211 if (this.env.messagecount && (this.env.mailbox == this.env.trash_mailbox || this.env.mailbox == this.env.junk_mailbox)) { 203 212 this.enable_command('purge', true); 204 213 } … … 209 218 210 219 // init message compose form 211 if (this.env.action =='compose') {220 if (this.env.action == 'compose') { 212 221 this.init_messageform(); 213 222 } 214 223 215 224 // show printing dialog 216 if (this.env.action =='print') {225 if (this.env.action == 'print') { 217 226 window.print(); 218 227 } … … 225 234 break; 226 235 227 228 case 'addressbook': 229 if (this.gui_objects.contactslist) 230 { 231 this.contact_list = new rcube_list_widget(this.gui_objects.contactslist, {multiselect:true, draggable:true, keyboard:true}); 232 this.contact_list.addEventListener('keypress', function(o){ p.contactlist_keypress(o); }); 233 this.contact_list.addEventListener('select', function(o){ p.contactlist_select(o); }); 234 this.contact_list.addEventListener('dragstart', function(o){ p.drag_active = true; }); 235 this.contact_list.addEventListener('dragend', function(o){ p.drag_active = false; }); 236 this.contact_list.init(); 237 238 if (this.env.cid) 239 this.contact_list.highlight_row(this.env.cid); 240 241 if (this.gui_objects.contactslist.parentNode) 242 { 243 this.gui_objects.contactslist.parentNode.onmousedown = function(e){ return p.click_on_list(e); }; 244 document.onmouseup = function(e){ return p.doc_mouse_up(e); }; 236 case 'addressbook': 237 if (this.gui_objects.contactslist) { 238 this.contact_list = new rcube_list_widget(this.gui_objects.contactslist, {multiselect:true, draggable:true, keyboard:true}); 239 this.contact_list.addEventListener('keypress', function(o){ p.contactlist_keypress(o); }); 240 this.contact_list.addEventListener('select', function(o){ p.contactlist_select(o); }); 241 this.contact_list.addEventListener('dragstart', function(o){ p.drag_active = true; }); 242 this.contact_list.addEventListener('dragend', function(o){ p.drag_active = false; }); 243 this.contact_list.init(); 244 245 if (this.env.cid) { 246 this.contact_list.highlight_row(this.env.cid); 247 } 248 249 if (this.gui_objects.contactslist.parentNode) { 250 this.gui_objects.contactslist.parentNode.onmousedown = function(e){ return p.click_on_list(e); }; 251 document.onmouseup = function(e){ return p.doc_mouse_up(e); }; 252 } 253 else { 254 this.contact_list.focus(); 255 } 256 } 257 this.set_page_buttons(); 258 259 if (this.env.address_sources && !this.env.address_sources[this.env.source].readonly) { 260 this.enable_command('add', true); 261 } 262 263 if (this.env.cid) { 264 this.enable_command('show', 'edit', true); 265 } 266 267 if ((this.env.action == 'add' || this.env.action == 'edit') && this.gui_objects.editform) { 268 this.enable_command('save', true); 269 } 270 else { 271 this.enable_command('search', 'reset-search', 'moveto', true); 272 } 273 this.enable_command('list', true); 274 break; 275 276 277 case 'settings': 278 this.enable_command('preferences', 'identities', 'save', 'folders', true); 279 280 if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity') { 281 this.enable_command('edit', 'add', 'delete', true); 282 } 283 284 if (this.env.action=='edit-identity' || this.env.action=='add-identity') { 285 this.enable_command('save', true); 286 } 287 288 if (this.env.action=='folders') { 289 this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', 'delete-folder', true); 290 } 291 292 if (this.gui_objects.identitieslist) { 293 this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist, {multiselect:false, draggable:false, keyboard:false}); 294 this.identity_list.addEventListener('select', function(o){ p.identity_select(o); }); 295 this.identity_list.init(); 296 this.identity_list.focus(); 297 298 if (this.env.iid) { 299 this.identity_list.highlight_row(this.env.iid); 300 } 301 } 302 break; 303 304 case 'login': 305 var input_user = rcube_find_object('_user'); 306 var input_pass = rcube_find_object('_pass'); 307 308 if (input_user) { 309 input_user.onkeypress = function(e){ return rcmail.login_user_keypress(e); }; 310 } 311 312 if (input_user && input_user.value=='') { 313 input_user.focus(); 314 } 315 else if (input_pass) { 316 input_pass.focus(); 317 } 318 319 this.enable_command('login', true); 320 break; 321 322 default: 323 break; 324 } 325 326 327 // enable basic commands 328 this.enable_command('logout', true); 329 330 // flag object as complete 331 this.loaded = true; 332 333 // show message 334 if (this.pending_message) { 335 this.display_message(this.pending_message[0], this.pending_message[1]); 336 } 337 338 // start keep-alive interval 339 this.start_keepalive(); 340 341 // execute all foreign onload scripts 342 for (var i=0; i<this.onloads.length; i++) { 343 if (typeof(this.onloads[i]) == 'string') { 344 eval(this.onloads[i]); 245 345 } 246 else 247 this.contact_list.focus(); 248 } 249 250 this.set_page_buttons(); 251 252 if (this.env.address_sources && !this.env.address_sources[this.env.source].readonly) 253 this.enable_command('add', true); 254 255 if (this.env.cid) 256 this.enable_command('show', 'edit', true); 257 258 if ((this.env.action=='add' || this.env.action=='edit') && this.gui_objects.editform) 259 this.enable_command('save', true); 260 else 261 this.enable_command('search', 'reset-search', 'moveto', true); 262 263 this.enable_command('list', true); 264 break; 265 266 267 case 'settings': 268 this.enable_command('preferences', 'identities', 'save', 'folders', true); 269 270 if (this.env.action=='identities' || this.env.action=='edit-identity' || this.env.action=='add-identity') 271 this.enable_command('edit', 'add', 'delete', true); 272 273 if (this.env.action=='edit-identity' || this.env.action=='add-identity') 274 this.enable_command('save', true); 275 276 if (this.env.action=='folders') 277 this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', 'delete-folder', true); 278 279 if (this.gui_objects.identitieslist) 280 { 281 this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist, {multiselect:false, draggable:false, keyboard:false}); 282 this.identity_list.addEventListener('select', function(o){ p.identity_select(o); }); 283 this.identity_list.init(); 284 this.identity_list.focus(); 285 286 if (this.env.iid) 287 this.identity_list.highlight_row(this.env.iid); 288 } 289 290 break; 291 292 case 'login': 293 var input_user = rcube_find_object('_user'); 294 var input_pass = rcube_find_object('_pass'); 295 if (input_user) 296 input_user.onkeypress = function(e){ return rcmail.login_user_keypress(e); }; 297 if (input_user && input_user.value=='') 298 input_user.focus(); 299 else if (input_pass) 300 input_pass.focus(); 301 302 this.enable_command('login', true); 303 break; 304 305 default: 306 break; 307 } 308 309 310 // enable basic commands 311 this.enable_command('logout', true); 312 313 // flag object as complete 314 this.loaded = true; 315 316 // show message 317 if (this.pending_message) 318 this.display_message(this.pending_message[0], this.pending_message[1]); 319 320 // start keep-alive interval 321 this.start_keepalive(); 322 323 324 // execute all foreign onload scripts 325 for (var i=0; i<this.onloads.length; i++) 326 { 327 if (typeof(this.onloads[i]) == 'string') 328 eval(this.onloads[i]); 329 else if (typeof(this.onloads[i]) == 'function') 330 this.onloads[i](); 331 } 332 }; 333 334 335 // start interval for keep-alive/recent_check signal 336 this.start_keepalive = function() 337 { 338 if (this.env.keep_alive && !this.env.framed && this.task=='mail' && this.gui_objects.messagelist) 339 this._int = setInterval(function(){ ref.check_for_recent(); }, this.env.keep_alive * 1000); 340 else if (this.env.keep_alive && !this.env.framed && this.task!='login') 341 this._int = setInterval(function(){ ref.send_keep_alive(); }, this.env.keep_alive * 1000); 346 else if (typeof(this.onloads[i]) == 'function') { 347 this.onloads[i](); 348 } 349 } 350 }; 351 352 // start interval for keep-alive/recent_check signal 353 this.start_keepalive = function() 354 { 355 if (this.env.keep_alive && !this.env.framed && this.task=='mail' && this.gui_objects.messagelist) { 356 this._int = setInterval(function(){ ref.check_for_recent(); }, this.env.keep_alive * 1000); 357 } 358 else if (this.env.keep_alive && !this.env.framed && this.task!='login') { 359 this._int = setInterval(function(){ ref.send_keep_alive(); }, this.env.keep_alive * 1000); 360 } 342 361 } 343 362 344 345 this.init_message_row = function(row) 346 { 347 var uid = row.uid; 348 if (uid && this.env.messages[uid]) 349 { 350 row.deleted = this.env.messages[uid].deleted ? true : false; 351 row.unread = this.env.messages[uid].unread ? true : false; 352 row.replied = this.env.messages[uid].replied ? true : false; 353 } 354 355 // set eventhandler to message icon 356 if ((row.icon = row.obj.cells[0].childNodes[0]) && row.icon.nodeName=='IMG') 357 { 358 var p = this; 359 row.icon.id = 'msgicn_'+row.uid; 360 row.icon._row = row.obj; 361 row.icon.onmousedown = function(e) { p.command('toggle_status', this); }; 362 } 363 }; 363 this.init_message_row = function(row) 364 { 365 var uid = row.uid; 366 //console.log('We init on row: ' + uid); 367 if (uid && this.env.messages[uid]) { 368 row.deleted = this.env.messages[uid].deleted ? true : false; 369 row.unread = this.env.messages[uid].unread ? true : false; 370 row.replied = this.env.messages[uid].replied ? true : false; 371 } 372 373 // set eventhandler to message icon 374 if ((row.icon = row.obj.cells[0].childNodes[0]) && row.icon.nodeName=='IMG') { 375 var p = this; 376 row.icon.id = 'msgicn_'+row.uid; 377 row.icon._row = row.obj; 378 row.icon.onmousedown = function(e) { p.command('toggle_status', this); }; 379 } 380 }; 364 381 365 382 … … 432 449 433 450 // execute a specific command on the web client 434 this.command = function(command, props, obj) { 451 this.command = function(command, props, obj) 452 { 435 453 if (obj && obj.blur) { 436 454 obj.blur(); … … 456 474 457 475 458 // process command 459 switch (command) 460 { 476 // process command 477 switch (command) { 461 478 case 'login': 462 479 if (this.gui_objects.loginform) … … 938 955 } 939 956 940 return obj ? false : true; 941 }; 942 957 return obj ? false : true; 958 }; 943 959 944 960 // set command enabled or disabled … … 960 976 }; 961 977 962 963 978 // lock/unlock interface 964 979 this.set_busy = function(a, message) { 965 980 if (a && message) { 966 981 var msg = this.get_label(message); 967 if (msg ==message)982 if (msg == message) { 968 983 msg = 'Loading...'; 969 984 } 970 985 this.display_message(msg, 'loading', true); 971 986 } … … 988 1003 } 989 1004 }; 990 991 1005 992 1006 // return a localized string … … 995 1009 return this.labels[name]; 996 1010 } 997 else { 998 return name; 999 } 1000 }; 1001 1002 1003 // switch to another application task 1004 this.switch_task = function(task) 1005 { 1006 if (this.task===task && task!='mail') 1007 return; 1008 1009 var url = this.get_task_url(task); 1010 if (task=='mail') 1011 url += '&_mbox=INBOX'; 1012 1013 this.redirect(url); 1014 }; 1015 1016 1011 return name; 1012 }; 1013 1014 // switch to another application task 1015 this.switch_task = function(task) 1016 { 1017 if (this.task===task && task!='mail') { 1018 return; 1019 } 1020 1021 var url = this.get_task_url(task); 1022 if (task=='mail') { 1023 url += '&_mbox=INBOX'; 1024 } 1025 1026 this.redirect(url); 1027 }; 1028 1029 // get_task_url 1017 1030 this.get_task_url = function(task, url) 1018 1031 { … … 1023 1036 }; 1024 1037 1025 1026 1038 // called when a request timed out 1027 1039 this.request_timed_out = function() … … 1031 1043 }; 1032 1044 1033 1034 /*********************************************************/ 1035 /********* event handling methods *********/ 1036 /*********************************************************/ 1037 1038 1039 this.doc_mouse_up = function(e) 1040 { 1041 if (this.message_list) 1042 this.message_list.blur(); 1043 else if (this.contact_list) 1044 this.contact_list.blur(); 1045 }; 1046 1047 this.focus_folder = function(id) 1048 { 1049 var li; 1050 if (this.drag_active && this.check_droptarget(id) && (li = this.get_folder_li(id))) 1051 this.set_classname(li, 'droptarget', true); 1052 } 1045 /*********************************************************/ 1046 /********* event handling methods *********/ 1047 /*********************************************************/ 1048 1049 this.doc_mouse_up = function(e) 1050 { 1051 if (this.message_list) { 1052 this.message_list.blur(); 1053 } 1054 else if (this.contact_list) { 1055 this.contact_list.blur(); 1056 } 1057 }; 1058 1059 this.focus_folder = function(id) 1060 { 1061 var li; 1062 if (this.drag_active && this.check_droptarget(id) && (li = this.get_folder_li(id))) { 1063 this.set_classname(li, 'droptarget', true); 1064 } 1065 }; 1053 1066 1054 1067 this.unfocus_folder = function(id) … … 1058 1071 this.set_classname(li, 'droptarget', false); 1059 1072 } 1060 } 1073 }; 1061 1074 1062 1075 // onmouseup handler for folder list item … … 1074 1087 }; 1075 1088 1089 // click on list 1076 1090 this.click_on_list = function(e) 1077 1091 { 1078 if (this.message_list) 1092 if (this.message_list) { 1093 console.log('We clicked.'); 1079 1094 this.message_list.focus(); 1080 else if (this.contact_list) 1095 } 1096 else if (this.contact_list) { 1081 1097 this.contact_list.focus(); 1098 } 1082 1099 1083 1100 var mbox_li; 1084 if (mbox_li = this.get_folder_li()) 1101 if (mbox_li = this.get_folder_li()) { 1085 1102 this.set_classname(mbox_li, 'unfocused', true); 1103 } 1086 1104 1087 1105 rcube_event.cancel(e); … … 1091 1109 this.msglist_select = function(list) 1092 1110 { 1093 if (this.preview_timer) 1111 if (this.preview_timer) { 1094 1112 clearTimeout(this.preview_timer); 1113 } 1095 1114 1096 1115 var selected = list.selection.length==1; … … 1106 1125 1107 1126 // start timer for message preview (wait for double click) 1108 if (selected && this.env.contentframe) 1127 if (selected && this.env.contentframe) { 1109 1128 this.preview_timer = setTimeout(function(){ ref.msglist_get_preview(); }, this.dblclick_time + 10); 1110 else if (this.env.contentframe) 1129 } 1130 else if (this.env.contentframe) { 1111 1131 this.show_contentframe(false); 1112 }; 1113 1114 1115 this.msglist_dbl_click = function(list) 1116 { 1117 if (this.preview_timer) 1118 clearTimeout(this.preview_timer); 1119 1120 var uid = list.get_single_selection(); 1121 if (uid && this.env.mailbox == this.env.drafts_mailbox) 1122 this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true); 1123 else if (uid) 1124 this.show_message(uid, false, false); 1125 }; 1126 1127 1128 this.msglist_keypress = function(list) 1129 { 1130 if (list.key_pressed == list.ENTER_KEY) 1131 this.command('show'); 1132 else if (list.key_pressed == list.DELETE_KEY) 1133 this.command('delete'); 1134 }; 1135 1136 1137 this.msglist_get_preview = function() 1138 { 1139 var uid = this.get_single_uid(); 1140 if (uid && this.env.contentframe && !this.drag_active) 1141 this.show_message(uid, false, true); 1142 else if (this.env.contentframe) 1143 this.show_contentframe(false); 1144 }; 1145 1146 1147 this.check_droptarget = function(id) 1148 { 1149 if (this.task == 'mail') 1150 return (id != this.env.mailbox); 1151 else if (this.task == 'addressbook') 1152 return (id != this.env.source && this.env.address_sources[id] && !this.env.address_sources[id].readonly); 1153 }; 1154 1155 1156 /*********************************************************/ 1157 /********* (message) list functionality *********/ 1158 /*********************************************************/ 1159 1160 1161 // when user doble-clicks on a row 1162 this.show_message = function(id, safe, preview) 1163 { 1164 var add_url = ''; 1165 var action = preview ? 'preview': 'show'; 1166 var target = window; 1167 if (preview && this.env.contentframe && window.frames && window.frames[this.env.contentframe]) 1168 { 1169 target = window.frames[this.env.contentframe]; 1170 add_url = '&_framed=1'; 1171 } 1172 1173 if (safe) 1174 add_url = '&_safe=1'; 1175 1176 if (id) 1177 { 1178 var url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox)+add_url; 1179 if (action == 'preview' && String(target.location.href).indexOf(url) >= 0) 1180 this.show_contentframe(true); 1181 else 1182 { 1183 this.set_busy(true, 'loading'); 1184 target.location.href = this.env.comm_path+url; 1185 } 1186 } 1187 }; 1188 1189 1190 this.show_contentframe = function(show) 1191 { 1192 var frm; 1193 if (this.env.contentframe && (frm = rcube_find_object(this.env.contentframe))) 1194 { 1195 if (!show && window.frames[this.env.contentframe] && frames[this.env.contentframe].location.href.indexOf(this.env.blankpage)<0) 1196 frames[this.env.contentframe].location.href = this.env.blankpage; 1197 if (!bw.safari) 1198 frm.style.display = show ? 'block' : 'none'; 1199 } 1200 1201 if (!show && this.busy) 1202 this.set_busy(false); 1203 }; 1204 1205 1206 // list a specific page 1207 this.list_page = function(page) 1208 { 1209 if (page=='next') 1210 page = this.env.current_page+1; 1211 if (page=='last') 1212 page = this.env.pagecount; 1213 if (page=='prev' && this.env.current_page>1) 1214 page = this.env.current_page-1; 1215 if (page=='first' && this.env.current_page>1) 1216 page = 1; 1217 1218 if (page > 0 && page <= this.env.pagecount) 1219 { 1220 this.env.current_page = page; 1221 1222 if (this.task=='mail') 1223 this.list_mailbox(this.env.mailbox, page); 1224 else if (this.task=='addressbook') 1225 this.list_contacts(this.env.source, page); 1226 } 1227 }; 1228 1229 1230 // list messages of a specific mailbox 1231 this.list_mailbox = function(mbox, page, sort) 1232 { 1233 this.last_selected = 0; 1234 var add_url = ''; 1235 var target = window; 1236 1237 if (!mbox) 1238 mbox = this.env.mailbox; 1239 1240 // add sort to url if set 1241 if (sort) 1242 add_url += '&_sort=' + sort; 1243 1244 // also send search request to get the right messages 1245 if (this.env.search_request) 1246 add_url += '&_search='+this.env.search_request; 1247 1248 // set page=1 if changeing to another mailbox 1249 if (!page && mbox != this.env.mailbox) 1250 { 1251 page = 1; 1252 this.env.current_page = page; 1253 if (this.message_list) 1254 this.message_list.clear_selection(); 1255 this.show_contentframe(false); 1256 } 1257 1258 if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort)) 1259 add_url += '&_refresh=1'; 1260 1261 this.select_folder(mbox, this.env.mailbox); 1262 this.env.mailbox = mbox; 1263 1264 // load message list remotely 1265 if (this.gui_objects.messagelist) 1266 { 1267 this.list_mailbox_remote(mbox, page, add_url); 1268 return; 1269 } 1270 1271 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) 1272 { 1273 target = window.frames[this.env.contentframe]; 1274 add_url += '&_framed=1'; 1275 } 1276 1277 // load message list to target frame/window 1278 if (mbox) 1279 { 1280 this.set_busy(true, 'loading'); 1281 target.location.href = this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+add_url; 1282 } 1283 }; 1284 1132 } 1133 }; 1134 1135 1136 this.msglist_dbl_click = function(list) 1137 { 1138 if (this.preview_timer) 1139 clearTimeout(this.preview_timer); 1140 1141 var uid = list.get_single_selection(); 1142 if (uid && this.env.mailbox == this.env.drafts_mailbox) { 1143 this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true); 1144 } 1145 else if (uid) { 1146 this.show_message(uid, false, false); 1147 } 1148 }; 1149 1150 1151 this.msglist_keypress = function(list) 1152 { 1153 if (list.key_pressed == list.ENTER_KEY) { 1154 this.command('show'); 1155 } 1156 else if (list.key_pressed == list.DELETE_KEY) { 1157 this.command('delete'); 1158 } 1159 }; 1160 1161 1162 this.msglist_get_preview = function() 1163 { 1164 var uid = this.get_single_uid(); 1165 if (uid && this.env.contentframe && !this.drag_active) { 1166 this.show_message(uid, false, true); 1167 } 1168 else if (this.env.contentframe) { 1169 this.show_contentframe(false); 1170 } 1171 }; 1172 1173 1174 this.check_droptarget = function(id) 1175 { 1176 if (this.task == 'mail') { 1177 return (id != this.env.mailbox); 1178 } 1179 else if (this.task == 'addressbook') { 1180 return (id != this.env.source && this.env.address_sources[id] && !this.env.address_sources[id].readonly); 1181 } 1182 }; 1183 1184 1185 /*********************************************************/ 1186 /********* (message) list functionality *********/ 1187 /*********************************************************/ 1188 1189 // when user doble-clicks on a row 1190 this.show_message = function(id, safe, preview) 1191 { 1192 var add_url = ''; 1193 var action = preview ? 'preview': 'show'; 1194 var target = window; 1195 if (preview && this.env.contentframe && window.frames && window.frames[this.env.contentframe]) { 1196 target = window.frames[this.env.contentframe]; 1197 add_url = '&_framed=1'; 1198 } 1199 1200 if (safe) { 1201 add_url = '&_safe=1'; 1202 } 1203 1204 if (id) { 1205 var url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox)+add_url; 1206 if (action == 'preview' && String(target.location.href).indexOf(url) >= 0) { 1207 this.show_contentframe(true); 1208 } 1209 } 1210 else { 1211 this.set_busy(true, 'loading'); 1212 target.location.href = this.env.comm_path+url; 1213 } 1214 }; 1215 1216 // ??? what is this for ??? 1217 this.show_contentframe = function(show) 1218 { 1219 var frm; 1220 if (this.env.contentframe && (frm = rcube_find_object(this.env.contentframe))) { 1221 if (!show && window.frames[this.env.contentframe] && frames[this.env.contentframe].location.href.indexOf(this.env.blankpage)<0) 1222 frames[this.env.contentframe].location.href = this.env.blankpage; 1223 if (!bw.safari) 1224 frm.style.display = show ? 'block' : 'none'; 1225 } 1226 1227 if (!show && this.busy) 1228 this.set_busy(false); 1229 }; 1230 1231 // list a specific page 1232 this.list_page = function(page) 1233 { 1234 if (page=='next') { 1235 page = this.env.current_page+1; 1236 } 1237 if (page=='last') { 1238 page = this.env.pagecount; 1239 } 1240 if (page=='prev' && this.env.current_page>1) { 1241 page = this.env.current_page-1; 1242 } 1243 if (page=='first' && this.env.current_page>1) { 1244 page = 1; 1245 } 1246 1247 if (page > 0 && page <= this.env.pagecount) { 1248 this.env.current_page = page; 1249 1250 if (this.task=='mail') { 1251 this.list_mailbox(this.env.mailbox, page); 1252 } 1253 else if (this.task=='addressbook') { 1254 this.list_contacts(this.env.source, page); 1255 } 1256 } 1257 }; 1258 1259 1260 // list messages of a specific mailbox 1261 this.list_mailbox = function(mbox, page, sort) 1262 { 1263 this.last_selected = 0; 1264 var add_url = ''; 1265 var target = window; 1266 1267 if (!mbox) 1268 mbox = this.env.mailbox; 1269 1270 // add sort to url if set 1271 if (sort) 1272 add_url += '&_sort=' + sort; 1273 1274 // also send search request to get the right messages 1275 if (this.env.search_request) 1276 add_url += '&_search='+this.env.search_request; 1277 1278 // set page=1 if changeing to another mailbox 1279 if (!page && mbox != this.env.mailbox) { 1280 page = 1; 1281 this.env.current_page = page; 1282 if (this.message_list) { 1283 this.message_list.clear_selection(); 1284 } 1285 this.show_contentframe(false); 1286 } 1287 1288 if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort)) { 1289 add_url += '&_refresh=1'; 1290 } 1291 1292 this.select_folder(mbox, this.env.mailbox); 1293 this.env.mailbox = mbox; 1294 1295 // load message list remotely 1296 if (this.gui_objects.messagelist) { 1297 this.list_mailbox_remote(mbox, page, add_url); 1298 return; 1299 } 1300 1301 if (this.env.contentframe && window.frames && window.frames[this.env.contentframe]) { 1302 target = window.frames[this.env.contentframe]; 1303 add_url += '&_framed=1'; 1304 } 1305 1306 // load message list to target frame/window 1307 if (mbox) { 1308 this.set_busy(true, 'loading'); 1309 target.location.href = this.env.comm_path+'&_mbox='+urlencode(mbox)+(page ? '&_page='+page : '')+add_url; 1310 } 1311 }; 1285 1312 1286 1313 // send remote request to load message list … … 1296 1323 }; 1297 1324 1298 1325 // expunge/compact 1299 1326 this.expunge_mailbox = function(mbox) 1300 1327 { … … 1314 1341 }; 1315 1342 1316 1343 // delete all mail in a mailbox 1317 1344 this.purge_mailbox = function(mbox) 1318 1345 { … … 1320 1347 var add_url = ''; 1321 1348 1322 if (!confirm(this.get_label('purgefolderconfirm'))) 1349 if (!confirm(this.get_label('purgefolderconfirm'))) { 1323 1350 return false; 1351 } 1324 1352 1325 1353 // lock interface if it's the active mailbox … … 1336 1364 }; 1337 1365 1338 1339 // move selected messages to the specified mailbox 1340 this.move_messages = function(mbox) 1341 { 1342 // exit if current or no mailbox specified or if selection is empty 1343 if (!mbox || !this.env.uid || mbox==this.env.mailbox) 1344 { 1345 if (!this.message_list || !this.message_list.get_selection().length) 1346 return; 1347 } 1348 1349 var lock = false; 1350 var add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : ''); 1351 1352 // show wait message 1353 if (this.env.action=='show') 1354 { 1355 lock = true; 1356 this.set_busy(true, 'movingmessage'); 1357 } 1358 else 1359 this.show_contentframe(false); 1360 1361 this._with_selected_messages('moveto', lock, add_url); 1362 }; 1363 1364 // delete selected messages from the current mailbox 1365 this.delete_messages = function() 1366 { 1367 var selection = this.message_list ? this.message_list.get_selection() : new Array(); 1368 1369 // exit if no mailbox specified or if selection is empty 1370 if (!this.env.uid && !selection.length) 1371 return; 1372 1373 // if there is a trash mailbox defined and we're not currently in it: 1374 if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase() != String(this.env.trash_mailbox).toLowerCase()) 1375 { 1376 // if shift was pressed delete it immediately 1377 if (this.message_list && this.message_list.shiftkey) 1378 { 1379 if (confirm(this.get_label('deletemessagesconfirm'))) 1380 this.permanently_remove_messages(); 1381 } 1382 else 1383 this.move_messages(this.env.trash_mailbox); 1384 } 1385 // if there is a trash mailbox defined but we *are* in it: 1386 else if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase() == String(this.env.trash_mailbox).toLowerCase()) 1387 this.permanently_remove_messages(); 1388 // if there isn't a defined trash mailbox and the config is set to flag for deletion 1389 else if (!this.env.trash_mailbox && this.env.flag_for_deletion) 1390 { 1391 this.mark_message('delete'); 1392 if(this.env.action=="show") 1393 this.command('nextmessage','',this); 1394 else if (selection.length == 1) 1395 this.message_list.select_next(); 1396 } 1397 // if there isn't a defined trash mailbox and the config is set NOT to flag for deletion 1398 else if (!this.env.trash_mailbox) 1399 this.permanently_remove_messages(); 1400 }; 1401 1402 1403 // delete the selected messages permanently 1404 this.permanently_remove_messages = function() 1405 { 1406 // exit if no mailbox specified or if selection is empty 1407 if (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)) 1408 return; 1409 1410 this.show_contentframe(false); 1411 this._with_selected_messages('delete', false, '&_from='+(this.env.action ? this.env.action : '')); 1412 }; 1413 1414 // Send a specifc request with UIDs of all selected messages 1415 // @private 1416 this._with_selected_messages = function(action, lock, add_url) 1417 { 1418 var a_uids = new Array(); 1419 if (this.env.uid) 1420 a_uids[a_uids.length] = this.env.uid; 1421 else 1422 { 1423 var selection = this.message_list.get_selection(); 1424 var id; 1425 for (var n=0; n<selection.length; n++) 1426 { 1427 id = selection[n]; 1428 a_uids[a_uids.length] = id; 1429 this.message_list.remove_row(id); 1430 } 1431 1432 this.message_list.select_next(); 1433 } 1434 1435 // also send search request to get the right messages 1436 if (this.env.search_request) 1437 add_url += '&_search='+this.env.search_request; 1438 1439 // send request to server 1440 this.http_post(action, '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, lock); 1441 }; 1442 1443 1444 // set a specific flag to one or more messages 1445 this.mark_message = function(flag, uid) 1446 { 1447 var a_uids = new Array(); 1448 var selection = this.message_list ? this.message_list.get_selection() : new Array(); 1449 1450 if (uid) 1451 a_uids[0] = uid; 1452 else if (this.env.uid) 1453 a_uids[0] = this.env.uid; 1454 else if (this.message_list) 1455 { 1456 for (var id, n=0; n<selection.length; n++) 1457 { 1458 id = selection[n]; 1459 if ((flag=='read' && this.message_list.rows[id].unread) || (flag=='unread' && !this.message_list.rows[id].unread) 1460 || (flag=='delete' && !this.message_list.rows[id].deleted) || (flag=='undelete' && this.message_list.rows[id].deleted)) 1461 a_uids[a_uids.length] = id; 1462 } 1463 } 1464 1465 // nothing to do 1466 if (!a_uids.length) 1467 return; 1468 1469 switch (flag) 1470 { 1471 case 'read': 1472 case 'unread': 1473 this.toggle_read_status(flag, a_uids); 1474 break; 1475 case 'delete': 1476 case 'undelete': 1477 this.toggle_delete_status(a_uids); 1478 break; 1479 } 1480 }; 1481 1482 // set class to read/unread 1483 this.toggle_read_status = function(flag, a_uids) 1484 { 1366 // move selected messages to the specified mailbox 1367 this.move_messages = function(mbox) 1368 { 1369 // exit if current or no mailbox specified or if selection is empty 1370 if (!mbox || !this.env.uid || mbox==this.env.mailbox) { 1371 if (!this.message_list || !this.message_list.get_selection().length) { 1372 return; 1373 } 1374 } 1375 1376 var lock = false; 1377 var add_url = '&_target_mbox='+urlencode(mbox)+'&_from='+(this.env.action ? this.env.action : ''); 1378 1379 // show wait message 1380 if (this.env.action=='show') { 1381 lock = true; 1382 this.set_busy(true, 'movingmessage'); 1383 } 1384 else { 1385 this.show_contentframe(false); 1386 } 1387 1388 this._with_selected_messages('moveto', lock, add_url); 1389 }; 1390 1391 // delete selected messages from the current mailbox 1392 this.delete_messages = function() 1393 { 1394 var selection = this.message_list ? this.message_list.get_selection() : new Array(); 1395 1396 // exit if no mailbox specified or if selection is empty 1397 if (!this.env.uid && !selection.length) { 1398 return; 1399 } 1400 1401 // if there is a trash mailbox defined and we're not currently in it: 1402 if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase() != String(this.env.trash_mailbox).toLowerCase()) { 1403 // if shift was pressed delete it immediately 1404 if (this.message_list && this.message_list.shiftkey) { 1405 if (confirm(this.get_label('deletemessagesconfirm'))) { 1406 this.permanently_remove_messages(); 1407 } 1408 } 1409 else { 1410 this.move_messages(this.env.trash_mailbox); 1411 } 1412 } 1413 // if there is a trash mailbox defined but we *are* in it: 1414 else if (this.env.trash_mailbox && String(this.env.mailbox).toLowerCase() == String(this.env.trash_mailbox).toLowerCase()) { 1415 this.permanently_remove_messages(); 1416 } 1417 // if there isn't a defined trash mailbox and the config is set to flag for deletion 1418 else if (!this.env.trash_mailbox && this.env.flag_for_deletion) { 1419 this.mark_message('delete'); 1420 if(this.env.action == "show") { 1421 this.command('nextmessage','',this); 1422 } 1423 else if (selection.length == 1) { 1424 this.message_list.select_next(); 1425 } 1426 } 1427 // if there isn't a defined trash mailbox and the config is set NOT to flag for deletion 1428 else if (!this.env.trash_mailbox) { 1429 this.permanently_remove_messages(); 1430 } 1431 }; 1432 1433 1434 // delete the selected messages permanently 1435 this.permanently_remove_messages = function() 1436 { 1437 // exit if no mailbox specified or if selection is empty 1438 if (!this.env.uid && (!this.message_list || !this.message_list.get_selection().length)) { 1439 return; 1440 } 1441 1442 this.show_contentframe(false); 1443 this._with_selected_messages('delete', false, '&_from='+(this.env.action ? this.env.action : '')); 1444 }; 1445 1446 /** 1447 * Send a specifc request with UIDs of all selected messages 1448 * @private 1449 */ 1450 this._with_selected_messages = function(action, lock, add_url) 1451 { 1452 var a_uids = new Array(); 1453 if (this.env.uid) { 1454 a_uids[a_uids.length] = this.env.uid; 1455 } 1456 else { 1457 var selection = this.message_list.get_selection(); 1458 var id; 1459 for (var n=0; n<selection.length; n++) { 1460 id = selection[n]; 1461 a_uids[a_uids.length] = id; 1462 this.message_list.remove_row(id); 1463 } 1464 1465 this.message_list.select_next(); 1466 } 1467 1468 // also send search request to get the right messages 1469 if (this.env.search_request) 1470 add_url += '&_search='+this.env.search_request; 1471 1472 // send request to server 1473 this.http_post(action, '_uid='+a_uids.join(',')+'&_mbox='+urlencode(this.env.mailbox)+add_url, lock); 1474 }; 1475 1476 // set a specific flag to one or more messages 1477 this.mark_message = function(flag, uid) 1478 { 1479 var a_uids = new Array(); 1480 var selection = this.message_list ? this.message_list.get_selection() : new Array(); 1481 1482 if (uid) 1483 a_uids[0] = uid; 1484 else if (this.env.uid) 1485 a_uids[0] = this.env.uid; 1486 else if (this.message_list) { 1487 for (var id, n=0; n<selection.length; n++) { 1488 id = selection[n]; 1489 if ( 1490 (flag=='read' && this.message_list.rows[id].unread) 1491 || (flag=='unread' && !this.message_list.rows[id].unread) 1492 || (flag=='delete' && !this.message_list.rows[id].deleted) 1493 || (flag=='undelete' && this.message_list.rows[id].deleted) 1494 ) { 1495 a_uids[a_uids.length] = id; 1496 } 1497 } 1498 } 1499 1500 // nothing to do 1501 if (!a_uids.length) { 1502 return; 1503 } 1504 1505 switch (flag) { 1506 case 'read': 1507 case 'unread': 1508 this.toggle_read_status(flag, a_uids); 1509 break; 1510 case 'delete': 1511 case 'undelete': 1512 this.toggle_delete_status(a_uids); 1513 break; 1514 } 1515 }; 1516 1517 // set class to read/unread 1518 this.toggle_read_status = function(flag, a_uids) 1519 { 1485 1520 // mark all message rows as read/unread 1486 1521 var icn_src; … … 1629 1664 1630 1665 1631 /*********************************************************/ 1632 /********* login form methods *********/ 1633 /*********************************************************/ 1634 1635 // handler for keyboard events on the _user field 1636 this.login_user_keypress = function(e) 1637 { 1638 var key = rcube_event.get_keycode(e); 1639 var elm; 1640 1641 // enter 1642 if ((key==13) && (elm = rcube_find_object('_pass'))) 1643 { 1644 elm.focus(); 1645 return false; 1646 } 1647 }; 1648 1649 1650 /*********************************************************/ 1651 /********* message compose methods *********/ 1652 /*********************************************************/ 1653 1654 1655 // checks the input fields before sending a message 1656 this.check_compose_input = function() 1666 /*********************************************************/ 1667 /********* login form methods *********/ 1668 /*********************************************************/ 1669 1670 // handler for keyboard events on the _user field 1671 this.login_user_keypress = function(e) 1672 { 1673 var key = rcube_event.get_keycode(e); 1674 var elm; 1675 1676 // enter 1677 if ((key==13) && (elm = rcube_find_object('_pass'))) 1678 { 1679 elm.focus(); 1680 return false; 1681 } 1682 }; 1683 1684 /*********************************************************/ 1685 /********* message compose methods *********/ 1686 /*********************************************************/ 1687 1688 // checks the input fields before sending a message 1689 this.check_compose_input = function() 1657 1690 { 1658 1691 // check input fields … … 3637 3670 // helper function to call the init method with a delay 3638 3671 function call_init(o) 3639 { 3640 if (window[o] && window[o].init) 3641 setTimeout(o+'.init()', 200); 3642 } 3643 3672 { 3673 if (window[o] && window[o].init) { 3674 setTimeout(o+'.init()', 200); 3675 } 3676 } 3677 -
branches/devel-vnext/program/js/list.js
r754 r759 304 304 select_row: function(id, mod_key, with_mouse) 305 305 { 306 //console.log('Selecting... Multiselect: ' + this.multiselect); 307 //console.log('mod_key: ' + mod_key); 308 306 309 var select_before = this.selection.join(','); 310 311 //console.log('Already selected: ' + select_before); 307 312 if (!this.multiselect) { 308 313 mod_key = 0; … … 484 489 else // unselect row 485 490 { 486 var p = find_in_array(id, this.selection);487 var a_pre = this.selection.slice(0, p);491 var p = find_in_array(id, this.selection); 492 var a_pre = this.selection.slice(0, p); 488 493 var a_post = this.selection.slice(p+1, this.selection.length); 489 494
Note: See TracChangeset
for help on using the changeset viewer.
