[6510] | 1 | dots = /\./gi; |
---|
| 2 | dashes = /\//gi; |
---|
| 3 | flags = [ 'Attachment', 'Forwarded' ,'Recent', 'Unseen', 'Answered', 'Draft', 'Deleted', 'Flagged', 'Followupflag', 'Label' ]; |
---|
| 4 | months = ['Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec']; |
---|
| 5 | current_folder = 'INBOX'; |
---|
[6545] | 6 | current_count = DataLayer.get( 'message', { criteria: { count: true, properties: {context:{folder:current_folder}} } }, true ); |
---|
[6510] | 7 | |
---|
| 8 | DataLayer.codec( 'folder', 'tree', { |
---|
| 9 | |
---|
| 10 | encoder: function( data ){ |
---|
| 11 | |
---|
| 12 | if( preferences.use_local_messages == 1 || expresso_offline) |
---|
| 13 | { |
---|
| 14 | var folders = expresso_local_messages.list_local_folders(); |
---|
| 15 | |
---|
| 16 | var stripParents = /^(.*)\/([^\/]*)/; |
---|
| 17 | |
---|
| 18 | $.each( folders, function( i, folder ){ |
---|
| 19 | |
---|
| 20 | if(typeof(folder) == 'undefined') return; |
---|
| 21 | |
---|
| 22 | var id = 'local_messages/' + folder[0]; |
---|
| 23 | |
---|
| 24 | var parts = stripParents.exec( id ); |
---|
| 25 | |
---|
| 26 | data[data.length] = { 'id' : id, |
---|
| 27 | 'commonName' : parts[2], |
---|
| 28 | 'parentFolder' : parts[1] }; |
---|
| 29 | }); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | var trees = [[],[],[]], |
---|
| 33 | |
---|
| 34 | root = { inbox: /^INBOX/, share: /^user/, local: /^local_messages/ }; |
---|
| 35 | |
---|
| 36 | for (var i = 0; i < data.length; i++ ) |
---|
| 37 | { |
---|
| 38 | var index = root.inbox.test(data[i].id) ? 0 : |
---|
| 39 | root.share.test(data[i].id) ? 1 : |
---|
| 40 | root.local.test(data[i].id) ? 2 : |
---|
| 41 | 'false'; |
---|
| 42 | |
---|
| 43 | if( isNaN(index) ) continue; |
---|
| 44 | |
---|
| 45 | if (!unorphanize(trees[index], data[i])) |
---|
| 46 | { |
---|
| 47 | data[i].children = []; |
---|
| 48 | trees[index].push(data[i]); |
---|
| 49 | } |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | return( { folders: trees } ); |
---|
| 53 | } |
---|
| 54 | } ); |
---|
| 55 | |
---|
| 56 | DataLayer.codec( 'message', 'jqGrid', { |
---|
| 57 | |
---|
| 58 | encoder: function( data, crit ){ |
---|
[6545] | 59 | |
---|
| 60 | crit = crit.criteria; |
---|
[6510] | 61 | |
---|
[6545] | 62 | if( !crit.properties.context.folder.indexOf( 'local_messages/' ) ) |
---|
[6510] | 63 | { |
---|
[6545] | 64 | var msgs = expresso_local_messages.get_local_range_msgs( crit.properties.context.folder.replace(dots, "/").replace("local_messages/", ""), |
---|
[6510] | 65 | crit.offset + 1, crit.limit, "SORTARRIVAL", crit.orderDesc, "ALL", 1, 1 ); |
---|
| 66 | |
---|
| 67 | for( var i = 0; i < msgs.length; i++ ) |
---|
| 68 | { |
---|
| 69 | msgs[i].size = msgs[i].Size; |
---|
| 70 | msgs[i].timestamp = msgs[i].udate * 1000; |
---|
| 71 | msgs[i].flags = []; |
---|
| 72 | |
---|
| 73 | for( var ii = 0; ii < flags.length; ii++ ) |
---|
| 74 | if( f = $.trim( msgs[i][ flags[ii] ] ) ) |
---|
| 75 | msgs[i].flags[ msgs[i].flags.length ] = f; |
---|
| 76 | |
---|
| 77 | msgs[i].flags = msgs[i].flags.join(','); |
---|
| 78 | } |
---|
| 79 | |
---|
[6545] | 80 | data = msgs; |
---|
[6510] | 81 | } |
---|
| 82 | |
---|
[6545] | 83 | return( {"rows": data, |
---|
| 84 | "records": data.num_msgs || current_count, |
---|
| 85 | "page": crit.offset / crit.limit + 1, |
---|
| 86 | "total": Math.ceil( data.num_msgs || current_count / crit.limit )} ); |
---|
[6510] | 87 | }, |
---|
| 88 | criteria: function( crit ){ |
---|
| 89 | |
---|
[6545] | 90 | return { criteria: { properties: {context:{folder: current_folder || 'INBOX'}}, offset: crit.rows * ( crit.page - 1 ), limit: crit.rows, orderDesc: crit.sord == "desc", currentCount: current_count } }; |
---|
[6510] | 91 | |
---|
| 92 | } |
---|
| 93 | }); |
---|
| 94 | |
---|
| 95 | //BASE_PATH = '../'; |
---|
| 96 | //encontra os pais de todas as pastas e cria uma nova estrutura adicionando os filhos a um array no atributo 'children' do respectivo pai |
---|
| 97 | unorphanize = function(root, element) { |
---|
| 98 | var ok = false; |
---|
| 99 | for (var i=0; i<root.length; i++) { |
---|
| 100 | if (root[i].id == element.parentFolder) { |
---|
| 101 | element.children = new Array(); |
---|
| 102 | root[i].children.push(element); |
---|
| 103 | return true; |
---|
| 104 | } else if (ok = unorphanize(root[i].children, element)) { |
---|
| 105 | break; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | return ok; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | /* --- helpers --- */ |
---|
| 113 | bytes2Size = function(bytes) { |
---|
| 114 | var sizes = ['B', 'KB', 'MB', 'GB', 'TB']; |
---|
| 115 | if (bytes == 0) return 'n/a'; |
---|
| 116 | var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024))); |
---|
| 117 | var size = (i<2) ? Math.round((bytes / Math.pow(1024, i))) : Math.round((bytes / Math.pow(1024, i)) * 100)/100; |
---|
| 118 | return size + ' ' + sizes[i]; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | flags2Class = function(cellvalue, options, rowObject) { |
---|
| 122 | var classes = ''; |
---|
| 123 | cellvalue = cellvalue.split(','); |
---|
| 124 | cell = { |
---|
| 125 | Unseen: parseInt(cellvalue[0]) ? 'Unseen' : 'Seen', |
---|
| 126 | Answered: parseInt(cellvalue[1]) ? 'Answered' : (parseInt(cellvalue[2]) ? 'Forwarded' : ''), |
---|
| 127 | Flagged: parseInt(cellvalue[3]) ? 'Flagged' : '', |
---|
| 128 | Recent: parseInt(cellvalue[4]) ? 'Recent' : '', |
---|
| 129 | Draft: parseInt(cellvalue[5]) ? 'Draft' : '' |
---|
| 130 | }; |
---|
| 131 | for(var flag in cell){ |
---|
| 132 | classes += '<span class="flags '+ (cell[flag]).toLowerCase() + '"' + (cell[flag] != "" ? 'title="'+ get_lang(cell[flag])+'"' : '')+'> </span>'; |
---|
| 133 | } |
---|
| 134 | if(rowObject.labels){ |
---|
| 135 | var titles = []; |
---|
| 136 | var count = 0; |
---|
| 137 | for(i in rowObject.labels){ |
---|
| 138 | titles[count] = " "+rowObject.labels[i].name; |
---|
| 139 | count++; |
---|
| 140 | } |
---|
| 141 | titles = titles.join(); |
---|
| 142 | classes += '<span class="flags labeled" title="'+titles+'"> </span>'; |
---|
| 143 | }else{ |
---|
| 144 | classes += '<span class="flags"> </span>'; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | if(rowObject.followupflagged){ |
---|
| 148 | if(rowObject.followupflagged.followupflag.id < 7){ |
---|
| 149 | var nameFollowupflag = get_lang(rowObject.followupflagged.followupflag.name); |
---|
| 150 | }else{ |
---|
| 151 | var nameFollowupflag = rowObject.followupflagged.followupflag.name; |
---|
| 152 | } |
---|
| 153 | if(rowObject.followupflagged.isDone == 1){ |
---|
| 154 | classes += '<span class="flags followupflagged" title="'+nameFollowupflag+'" style="background:'+rowObject.followupflagged.backgroundColor+';"><img style=" margin-left:-3px;" src="../prototype/modules/mail/img/flagChecked.png"></span>'; |
---|
| 155 | }else{ |
---|
| 156 | classes += '<span class="flags followupflagged" title="'+nameFollowupflag+'" style="background:'+rowObject.followupflagged.backgroundColor+';"><img src="../prototype/modules/mail/img/flagEditor.png"></span>'; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | return classes; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | NormaliseFrom = function(cellvalue, options, rowObject) { |
---|
| 165 | rowObject['flags'] = rowObject['flags'].split(","); |
---|
| 166 | if(rowObject['flags'][rowObject['flags'].length-1] == 1){ |
---|
| 167 | return get_lang(special_folders["Drafts"]); |
---|
| 168 | } |
---|
| 169 | return cellvalue; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | NormaliseSubject = function(cellvalue, options, rowObject) { |
---|
| 173 | return html_entities(cellvalue); |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | date2Time = function (timestamp) { |
---|
| 177 | date = new Date(); |
---|
| 178 | if( typeof timestamp === "string" ) |
---|
| 179 | timestamp = parseInt( timestamp, 10 ); |
---|
| 180 | dat = new Date(timestamp); |
---|
| 181 | if ((date.getTime() - timestamp) < (24*60*60*1000)) { |
---|
| 182 | return '<span class="timable" title="'+dat.getTime()+'"></span>'; |
---|
| 183 | } else { |
---|
| 184 | date = new Date(timestamp); |
---|
| 185 | if(is_ie){ |
---|
| 186 | var b = date.toString().split(' '); |
---|
| 187 | var c = b[2] + "/" + months.indexOf(b[1]) + "/" + b[5]; |
---|
| 188 | return '<span class="datable">' + c + '</span>'; |
---|
| 189 | }else{ |
---|
| 190 | var b = date.toISOString().split("T")[0].split("-"); |
---|
| 191 | var c = b[2] + "/" + b[1] + "/" + b[0]; |
---|
| 192 | return '<span class="datable">' + c + '</span>'; |
---|
| 193 | } |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | changeTabIndex = function (elements) { |
---|
| 198 | // jQuery('#foldertree').attr('tabIndex', '1').focus(); |
---|
| 199 | } |
---|
| 200 | |
---|
| 201 | selectedMessagesCount = function() { |
---|
| 202 | var byte_size = 0, total_messages = 0; |
---|
| 203 | for (var folder in selectedMessages) { |
---|
| 204 | for (var message in selectedMessages[folder]) { |
---|
| 205 | if (selectedMessages[folder][message]) { |
---|
| 206 | byte_size += parseInt(onceOpenedMessages[folder][message].size); |
---|
| 207 | total_messages++; |
---|
| 208 | } |
---|
| 209 | } |
---|
| 210 | } |
---|
| 211 | $("#selected_messages_number").html(total_messages).next().html(bytes2Size(byte_size)); |
---|
| 212 | return total_messages; |
---|
| 213 | } |
---|