/** * @author diogenes */ function mail_sync() { this.dbGears = null; this.localServer = null; this.store = null; this.folders = new Array(); this.messages = null; this.attachs = null; this.url_attachs = null; this.main_title = null; } mail_sync.prototype.open_conn = function(){ var db_in_other_use = true; while (db_in_other_use) { try { this.dbGears.open('database-test'); db_in_other_use = false; } catch (ex) { db_in_other_use=true; } } } mail_sync.prototype.start_sync = function() { if(this.folders.length!=0) { //Já está sincronizando... return; } this.main_title = document.getElementById('main_title').innerHTML; this.dbGears = google.gears.factory.create('beta.database'); this.localServer = google.gears.factory.create('beta.localserver'); this.store = this.localServer.createStore('test-store'); this.messages = null; this.attachs = null; this.url_attachs = null; this.open_conn(); var rs = this.dbGears.execute("select id_folder,folder_name from folders_sync where uid_usuario=?",[account_id]); document.getElementById('main_title').innerHTML = get_lang("Creating folders structure"); while(rs.isValidRow()) { var temp = new Array(); temp[0] = rs.field(0); temp[1] = rs.field(1); temp[2] = null; var rs2 = this.dbGears.execute("select mail.original_id from mail inner join folder on mail.id_folder=folder.rowid where folder.folder = ? and mail.uid_usuario=?",[temp[1]==get_lang('Inbox')?'Inbox':temp[1],account_id]); while(rs2.isValidRow()) { if(temp[2]==null) temp[2]=rs2.field(0)+","; else temp[2]+=rs2.field(0)+","; rs2.next(); } this.folders.push(temp); //Criando estrutura de pastas... var folders_to_check = temp[0].split("/");//Todas as pastas tem ao menos INBOX/ if (folders_to_check.length == 1) var actual_check = "Inbox"; else { folders_to_check = folders_to_check.slice(1); var actual_check = folders_to_check[0]; } for (var i in folders_to_check) { var rs2 = this.dbGears.execute("select rowid from folder where folder=? and uid_usuario=?", [actual_check, account_id]); if (!rs2.isValidRow()) { this.dbGears.execute("insert into folder (folder,uid_usuario) values (?,?)", [actual_check, account_id]); ttreeBox.update_folder(); } if(i+1' + select_available_folders.options[i].text + ''; } } else { if ( (select_sync_folders.innerHTML.indexOf('value="'+select_available_folders.options[i].value+'"')) == '-1' ) { new_options += ''; } } } } if (new_options != '') { select_sync_folders.innerHTML = ' ' + new_options + select_sync_folders.innerHTML; select_sync_folders.outerHTML = select_sync_folders.outerHTML; } } mail_sync.prototype.remove_folder = function(select_sync_folders) { for(var i = 0;i < select_sync_folders.options.length; i++) if(select_sync_folders.options[i].selected) select_sync_folders.options[i--] = null; } var expresso_mail_sync; expresso_mail_sync = new mail_sync();