its wCLog now, as js styleguides command us.
[citadel.git] / webcit / static / zapduplicates.js
1 function loadZapMessages(transport)
2 {
3     var dupes = '';
4     var dupcount = 0;
5     try {
6         var data = evalJSON(transport.responseText);
7         if (!!data && transport.responseText.length < 2) {
8             alert("Message loading failed");
9         } 
10         nummsgs = data['nummsgs'];
11         msgs = data['msgs'];
12         var length = msgs.length;
13         rowArray = new Array(length); // store so they can be sorted
14         wCLog("Row array length: "+rowArray.length);
15         for(var x=1; x<length; ++x) {
16             var currentRow = msgs[x];
17             var LastRow = msgs[x-1];
18             if ((currentRow[1] == LastRow[1]) &&
19                 (currentRow[2] == LastRow[2]) &&
20                 (currentRow[4] == LastRow[4]))
21             {
22                 dupcount ++;
23                 dupes += currentRow[0] + ',' ;
24                 if (dupes.length > 800) {
25                     var mvCommand = "g_cmd=MOVE%20" + dupes + "|"+encodeURIComponent('Trash')+"|0";
26                     new Ajax.Request("ajax_servcmd", {
27                         parameters: mvCommand,
28                         method: 'post',
29                     });
30                     dupes = "";
31                 }
32
33             }
34
35         }
36
37     } catch (e) {
38         window.alert(e+"|"+e.description);
39     }
40     var mvCommand = "g_cmd=MOVE%20" + dupes + "|"+encodeURIComponent('Trash')+"|0";
41     new Ajax.Request("ajax_servcmd", {
42         parameters: mvCommand,
43         method: 'post',
44     });
45
46     alert ('deleted: '+dupcount+'messages');
47 }
48
49 function TriggerLoadDupes ()
50 {
51 //    alert("bla");
52 // http://127.0.0.1:2000/roommsgs?room=test%20rss&startmsg=0&stopmsg=499&SortBy=Subject&SortOrder=1
53         roomName = getTextContent(document.getElementById("rmname"));
54     var parameters = {'room':roomName, 'startmsg': 0, 'stopmsg': -1, 'SortBy' : 'Subject', 'SortOrder' : 1};
55
56         new Ajax.Request("roommsgs", {
57                 method: 'get',
58                                 onSuccess: loadZapMessages,
59                                 parameters: parameters,
60                                 sanitize: false,
61                                 evalJSON: false,
62                                 onFailure: function(e) { alert("Failure: " + e);}
63         });
64 }