2014-08-06 20:49:36 +02:00
|
|
|
/* -*- Mode: js2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
|
|
|
|
var searchParams = {
|
|
|
|
searchLocation: "",
|
|
|
|
subfolder: true,
|
|
|
|
filterMatching: "AND",
|
|
|
|
filters: []
|
|
|
|
};
|
|
|
|
|
|
|
|
// This variable allowed the user to stop the ongoing search
|
|
|
|
var stopOngoingSearch = false;
|
|
|
|
|
|
|
|
/************ Search mail header ************/
|
|
|
|
|
|
|
|
function onSearchClick() {
|
|
|
|
// This function updates the searchParams
|
|
|
|
var filterRows = $$(".filterRow");
|
2014-08-15 17:41:37 +02:00
|
|
|
var searchButton = $("searchButton").down().innerHTML;
|
2014-08-06 20:49:36 +02:00
|
|
|
var mailAccountsList = $("mailAccountsList").options;
|
|
|
|
|
|
|
|
if (searchButton == _("Search")) {
|
|
|
|
searchParams.filters = [];
|
|
|
|
stopOngoingSearch = false;
|
|
|
|
|
|
|
|
// Get the mailboxe(s)
|
|
|
|
for (i = 0; i < mailAccountsList.length ; i++) {
|
|
|
|
if (mailAccountsList[i].selected) {
|
2014-08-15 17:41:37 +02:00
|
|
|
searchParams.searchLocation = mailAccountsList[i].innerHTML;
|
2014-08-06 20:49:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < filterRows.length; i++){
|
|
|
|
// Get the information from every filter row before triggering the AJAX call
|
|
|
|
var filter = {};
|
|
|
|
var searchByOptions = filterRows[i].down(".searchByList").options;
|
|
|
|
var searchArgumentsOptions = filterRows[i].down(".searchArgumentsList").options;
|
|
|
|
var searchInput = filterRows[i].down(".searchInput");
|
|
|
|
|
|
|
|
// Get the searchBy
|
|
|
|
for (j = 0; j < searchByOptions.length ; j++) {
|
|
|
|
if (searchByOptions[j].selected) {
|
2014-08-15 17:41:37 +02:00
|
|
|
filter.searchBy = searchByOptions[j].innerHTML;
|
2014-08-06 20:49:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the searchArgument
|
|
|
|
for (j = 0; j < searchArgumentsOptions.length ; j++) {
|
|
|
|
if (searchArgumentsOptions[j].selected) {
|
2014-08-15 17:41:37 +02:00
|
|
|
filter.searchArgument = searchArgumentsOptions[j].innerHTML;
|
2014-08-11 15:25:09 +02:00
|
|
|
filter.negative = false;
|
|
|
|
if (filter.searchArgument == "contains") {
|
2014-08-06 20:49:36 +02:00
|
|
|
filter.searchArgument = "doesContain";
|
2014-08-11 15:25:09 +02:00
|
|
|
}
|
|
|
|
else if (filter.searchArgument == "does not contain") {
|
|
|
|
filter.searchArgument = "doesContain";
|
|
|
|
filter.negative = true;
|
|
|
|
}
|
2014-08-06 20:49:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the input text
|
|
|
|
filter.searchInput = searchInput.getValue();
|
|
|
|
|
|
|
|
// Add the filter inside the searchParams.filters if the input is not empty
|
|
|
|
if (!filter.searchInput.empty())
|
|
|
|
searchParams.filters.push(filter);
|
|
|
|
}
|
|
|
|
// Send the request only if there is at least one filter
|
|
|
|
if (searchParams.filters.length > 0) {
|
2014-08-15 17:41:37 +02:00
|
|
|
$("searchButton").down().innerHTML = _("Stop");
|
2014-08-06 20:49:36 +02:00
|
|
|
searchMails();
|
|
|
|
}
|
2014-09-04 16:50:03 +02:00
|
|
|
else
|
|
|
|
alert(_("Please specify at least one filter"));
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
stopOngoingSearch = true;
|
2014-08-11 15:25:09 +02:00
|
|
|
onSearchEnd();
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchMails() {
|
|
|
|
// Variables for the subfolders search
|
|
|
|
var optionsList = $("mailAccountsList").options;
|
|
|
|
var nbOptions = optionsList.length;
|
|
|
|
var selectedIndex = optionsList.selectedIndex;
|
2014-08-27 18:30:33 +02:00
|
|
|
var accountNumber, accountUser, folderPath, folderName;
|
2014-08-06 20:49:36 +02:00
|
|
|
var mailAccountIndex = mailAccounts.indexOf(searchParams.searchLocation);
|
2014-09-04 16:50:03 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
if (mailAccountIndex != -1) {
|
2014-08-27 18:30:33 +02:00
|
|
|
accountNumber = "/" + mailAccountIndex;
|
|
|
|
folderName = accountNumber + "/folderINBOX";
|
|
|
|
accountUser = userNames[mailAccountIndex];
|
|
|
|
folderPath = accountUser;
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
var searchLocation = searchParams.searchLocation.split("/");
|
2014-08-27 18:30:33 +02:00
|
|
|
accountUser = searchLocation[0];
|
|
|
|
accountNumber = "/" + userNames.indexOf(accountUser);
|
2014-08-06 20:49:36 +02:00
|
|
|
|
|
|
|
var position = searchLocation.length;
|
2014-09-04 16:50:03 +02:00
|
|
|
folderName = accountNumber + "/folder" + searchLocation[1].asCSSIdentifier();
|
2014-08-06 20:49:36 +02:00
|
|
|
for (i = 2; i < position; i++)
|
2014-08-13 23:41:58 +02:00
|
|
|
folderName += "/folder" + searchLocation[i];
|
2014-08-06 20:49:36 +02:00
|
|
|
|
2014-08-27 18:30:33 +02:00
|
|
|
folderPath = optionsList[selectedIndex].innerHTML;
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
2014-08-27 18:30:33 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
var subfolders = [];
|
2014-08-27 18:30:33 +02:00
|
|
|
if (searchParams.subfolder === true) {
|
2014-08-06 20:49:36 +02:00
|
|
|
for (i = 0; i < nbOptions; i++) {
|
2014-08-15 17:41:37 +02:00
|
|
|
if ((optionsList[i].innerHTML.search(folderPath) != -1) && (i != selectedIndex)) {
|
|
|
|
var splitArray = optionsList[i].innerHTML.split("/");
|
2014-08-06 20:49:36 +02:00
|
|
|
// Remove the user information since it is not required
|
|
|
|
splitArray.splice(0, 1);
|
|
|
|
var subfolder = [];
|
|
|
|
var level = splitArray.length;
|
|
|
|
for(j = 0; j < level; j++) {
|
|
|
|
subfolder += "/folder" + splitArray[j];
|
|
|
|
}
|
|
|
|
subfolders.push(accountNumber + subfolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-27 18:30:33 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
var urlstr = (ApplicationBaseURL + folderName + "/uids");
|
|
|
|
var callbackData = {"folderName" : folderName, "subfolders" : subfolders, "newSearch" : true};
|
|
|
|
var object = {"filters":searchParams.filters, "sortingAttributes":{"match":searchParams.filterMatching}};
|
|
|
|
var content = Object.toJSON(object);
|
|
|
|
document.searchMailsAjaxRequest = triggerAjaxRequest(urlstr, searchMailsCallback, callbackData, content, {"content-type": "application/json"});
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchMailsCallback(http) {
|
|
|
|
if (http.readyState == 4 && http.status == 200 && !stopOngoingSearch) {
|
|
|
|
var response = http.responseText.evalJSON();
|
|
|
|
var table = $("searchMailFooter").down("tbody");
|
|
|
|
|
|
|
|
// Erase all previous entries before proceeding with the current request
|
|
|
|
if (http.callbackData.newSearch) {
|
|
|
|
var oldEntries = table.rows;
|
|
|
|
var count = oldEntries.length - 1;
|
2014-09-04 16:50:03 +02:00
|
|
|
for (var x = count; x >= 0; x--){
|
|
|
|
$(oldEntries[x]).remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
2014-09-04 16:50:03 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
// ["To", "Attachment", "Flagged", "Subject", "From", "Unread", "Priority", "Date", "Size", "rowClasses", "labels", "rowID", "uid"]
|
|
|
|
if (response.headers.length > 1) {
|
|
|
|
if ($("noSearchResults"))
|
|
|
|
$("noSearchResults").remove();
|
2014-09-04 16:50:03 +02:00
|
|
|
|
|
|
|
for (var i = 1; i < response.headers.length; i++) { // Starts at 1 because the position 0 in the array are the headers of the table
|
|
|
|
var row = document.createElement("tr");
|
2014-08-06 20:49:36 +02:00
|
|
|
Element.addClassName(row, "resultsRow");
|
2014-09-04 16:50:03 +02:00
|
|
|
row.setAttribute("uid", response.headers[i][12]);
|
|
|
|
row.setAttribute("folderName", http.callbackData.folderName);
|
2014-08-06 20:49:36 +02:00
|
|
|
|
2014-09-04 16:50:03 +02:00
|
|
|
var cell1 = document.createElement("td");
|
2014-08-14 20:49:44 +02:00
|
|
|
Element.addClassName(cell1, "td_table_1");
|
2014-08-06 20:49:36 +02:00
|
|
|
cell1.innerHTML = response.headers[i][3];
|
2014-09-04 16:50:03 +02:00
|
|
|
row.appendChild(cell1);
|
2014-08-06 20:49:36 +02:00
|
|
|
|
2014-09-04 16:50:03 +02:00
|
|
|
var cell2 = document.createElement("td");
|
2014-08-14 20:49:44 +02:00
|
|
|
Element.addClassName(cell2, "td_table_2");
|
2014-08-06 20:49:36 +02:00
|
|
|
cell2.innerHTML = response.headers[i][4];
|
2014-09-04 16:50:03 +02:00
|
|
|
row.appendChild(cell2);
|
2014-08-06 20:49:36 +02:00
|
|
|
|
2014-09-04 16:50:03 +02:00
|
|
|
var cell3 = document.createElement("td");
|
2014-08-14 20:49:44 +02:00
|
|
|
Element.addClassName(cell3, "td_table_3");
|
2014-08-11 15:25:09 +02:00
|
|
|
cell3.innerHTML = response.headers[i][0];
|
2014-09-04 16:50:03 +02:00
|
|
|
row.appendChild(cell3);
|
2014-08-06 20:49:36 +02:00
|
|
|
|
2014-09-04 16:50:03 +02:00
|
|
|
var cell4 = document.createElement("td");
|
2014-08-14 20:49:44 +02:00
|
|
|
Element.addClassName(cell4, "td_table_4");
|
2014-08-11 15:25:09 +02:00
|
|
|
cell4.innerHTML = response.headers[i][7];
|
2014-09-04 16:50:03 +02:00
|
|
|
row.appendChild(cell4);
|
2014-08-28 19:20:43 +02:00
|
|
|
|
2014-09-04 16:50:03 +02:00
|
|
|
var cell5 = document.createElement("td");
|
2014-08-28 19:20:43 +02:00
|
|
|
Element.addClassName(cell5, "td_table_5");
|
2014-09-04 16:50:03 +02:00
|
|
|
cell5.setAttribute("colspan", "2");
|
2014-08-28 19:20:43 +02:00
|
|
|
var folderPath = http.callbackData.folderName.split("/");
|
|
|
|
var folderLocation = folderPath[folderPath.length - 1]; // get the last element of the array (location)
|
|
|
|
folderLocation = folderLocation.substr(6); // strip down the prefix folder
|
|
|
|
cell5.innerHTML = folderLocation;
|
2014-09-04 16:50:03 +02:00
|
|
|
row.appendChild(cell5);
|
|
|
|
|
|
|
|
table.appendChild(row);
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (http.callbackData.newSearch) {
|
|
|
|
if (!table.down("tr")) {
|
|
|
|
var row = table.insertRow(0);
|
|
|
|
var cell = row.insertCell(0);
|
|
|
|
var element = document.createElement("span");
|
|
|
|
|
2014-09-04 16:50:03 +02:00
|
|
|
cell.setAttribute("id", "noSearchResults");
|
|
|
|
cell.setAttribute("colspan", "4");
|
2014-08-15 17:41:37 +02:00
|
|
|
element.innerHTML = _("No matches found");
|
2014-08-06 20:49:36 +02:00
|
|
|
cell.appendChild(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (http.callbackData.subfolders.length > 0) {
|
|
|
|
var folderName = http.callbackData.subfolders[0];
|
|
|
|
var subfolders = http.callbackData.subfolders;
|
|
|
|
subfolders.splice(0, 1);
|
|
|
|
|
|
|
|
var urlstr = (ApplicationBaseURL + folderName + "/uids");
|
|
|
|
var callbackData = {"folderName" : folderName, "subfolders" : subfolders, "newSearch" : false};
|
|
|
|
|
|
|
|
// TODO - need to add these following contents ; asc, no-headers, sort
|
|
|
|
var object = {"filters":searchParams.filters, "sortingAttributes":{"match":searchParams.filterMatching}};
|
|
|
|
var content = Object.toJSON(object);
|
|
|
|
document.searchMailsAjaxRequest = triggerAjaxRequest(urlstr, searchMailsCallback, callbackData, content, {"content-type": "application/json"});
|
|
|
|
}
|
|
|
|
else {
|
2014-08-11 15:25:09 +02:00
|
|
|
onSearchEnd();
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-11 15:25:09 +02:00
|
|
|
function onSearchEnd() {
|
2014-08-15 17:41:37 +02:00
|
|
|
$("searchButton").down().innerHTML = _("Search");
|
2014-08-11 15:25:09 +02:00
|
|
|
var nbResults = $$(".resultsRow").length;
|
|
|
|
if (nbResults == 1)
|
|
|
|
$("resultsFound").innerHTML = nbResults + " " + _("result found");
|
|
|
|
else if (nbResults > 0)
|
|
|
|
$("resultsFound").innerHTML = nbResults + " " + _("results found");
|
|
|
|
else
|
|
|
|
$("resultsFound").innerHTML = "";
|
2014-08-14 20:49:44 +02:00
|
|
|
|
2014-08-15 17:41:37 +02:00
|
|
|
TableKit.reloadSortableTable($("searchMailFooter"));
|
|
|
|
$("buttonExpandHeader").addClassName("nosort");
|
2014-08-11 15:25:09 +02:00
|
|
|
}
|
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
function onCancelClick() {
|
|
|
|
disposeDialog();
|
|
|
|
$("searchMailView").remove();
|
2014-08-15 19:06:46 +02:00
|
|
|
$("toolbarSearchButton").disabled = false;
|
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onSearchSubfoldersCheck(event) {
|
|
|
|
searchParams.subfolder = (event.checked ? true : false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onMatchFilters(event) {
|
|
|
|
searchParams.filterMatching = ((event.getAttribute("id") == "matchAllFilters") ? "AND" : "OR");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** Search mail body ****/
|
|
|
|
|
|
|
|
function onAddFilter() {
|
2014-09-04 16:50:03 +02:00
|
|
|
var table = $("searchFiltersList").down("TABLE");
|
2014-08-06 20:49:36 +02:00
|
|
|
var searchByList = $("searchByList").getElementsByTagName("li");
|
|
|
|
var stringArgumentsList = $("stringArgumentsList").getElementsByTagName("li");
|
2014-09-04 16:50:03 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
var rowCount = table.rows.length;
|
|
|
|
var row = table.insertRow(rowCount);
|
|
|
|
Element.addClassName(row, "filterRow");
|
2014-09-04 16:50:03 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
var cell1 = row.insertCell(0);
|
|
|
|
var element1 = document.createElement("select");
|
|
|
|
Element.addClassName(element1, "searchByList");
|
2014-09-04 16:50:03 +02:00
|
|
|
element1.setAttribute("id", "searchByListRow" + rowCount);
|
|
|
|
for (var i = 0; i < searchByList.length; i++) {
|
2014-08-06 20:49:36 +02:00
|
|
|
var option = document.createElement("option");
|
2014-08-15 17:41:37 +02:00
|
|
|
option.innerHTML = searchByList[i].innerHTML;
|
2014-08-06 20:49:36 +02:00
|
|
|
element1.appendChild(option);
|
|
|
|
}
|
|
|
|
cell1.appendChild(element1);
|
2014-09-04 16:50:03 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
var cell2 = row.insertCell(1);
|
|
|
|
var element2 = document.createElement("select");
|
|
|
|
Element.addClassName(element2, "searchArgumentsList");
|
2014-09-04 16:50:03 +02:00
|
|
|
element2.setAttribute("id", "searchArgumentsListRow" + rowCount);
|
|
|
|
for (var i = 0; i < stringArgumentsList.length; i++) {
|
2014-08-06 20:49:36 +02:00
|
|
|
var option = document.createElement("option");
|
2014-08-15 17:41:37 +02:00
|
|
|
option.innerHTML = stringArgumentsList[i].innerHTML;
|
2014-08-06 20:49:36 +02:00
|
|
|
element2.appendChild(option);
|
|
|
|
}
|
|
|
|
cell2.appendChild(element2);
|
|
|
|
|
|
|
|
var cell3 = row.insertCell(2);
|
|
|
|
Element.addClassName(cell3, "inputsCell");
|
|
|
|
var element3 = document.createElement("input");
|
|
|
|
Element.addClassName(element3, "searchInput");
|
2014-09-04 16:50:03 +02:00
|
|
|
element3.setAttribute("type", "text");
|
|
|
|
element3.setAttribute("name", "searchInput");
|
|
|
|
element3.setAttribute("id", "searchInputRow" + rowCount);
|
2014-08-06 20:49:36 +02:00
|
|
|
cell3.appendChild(element3);
|
|
|
|
|
|
|
|
var cell4 = row.insertCell(3);
|
|
|
|
Element.addClassName(cell4, "buttonsCell");
|
2014-09-05 17:01:57 +02:00
|
|
|
cell4.setAttribute("align", "center");
|
2014-08-11 15:25:09 +02:00
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
var buttonsDiv = document.createElement("div");
|
|
|
|
var imageAddFilter = document.createElement("img");
|
|
|
|
var imageRemoveFilter = document.createElement("img");
|
2014-09-04 16:50:03 +02:00
|
|
|
imageAddFilter.setAttribute("src", "/SOGo.woa/WebServerResources/add-icon.png");
|
|
|
|
imageRemoveFilter.setAttribute("src", "/SOGo.woa/WebServerResources/remove-icon.png");
|
2014-08-11 15:25:09 +02:00
|
|
|
Element.addClassName(imageAddFilter, "addFilterButton");
|
|
|
|
Element.addClassName(imageAddFilter, "glow");
|
|
|
|
Element.addClassName(imageRemoveFilter, "removeFilterButton");
|
|
|
|
Element.addClassName(imageRemoveFilter, "glow");
|
2014-09-04 16:50:03 +02:00
|
|
|
imageAddFilter.setAttribute("name", "addFilter");
|
|
|
|
imageAddFilter.setAttribute("id", "addFilterButtonRow" + rowCount);
|
|
|
|
$(imageAddFilter).on("click", onAddFilter);
|
|
|
|
imageRemoveFilter.setAttribute("name", "removeFilter");
|
|
|
|
imageRemoveFilter.setAttribute("id", "removeFilterButtonRow" + rowCount);
|
|
|
|
$(imageRemoveFilter).on("click", onRemoveFilter);
|
|
|
|
buttonsDiv.setAttribute("id", "filterButtons");
|
2014-08-11 15:25:09 +02:00
|
|
|
|
|
|
|
buttonsDiv.appendChild(imageAddFilter);
|
|
|
|
buttonsDiv.appendChild(imageRemoveFilter);
|
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
cell4.appendChild(buttonsDiv);
|
|
|
|
}
|
|
|
|
|
2014-09-04 16:50:03 +02:00
|
|
|
function onRemoveFilter() {
|
|
|
|
var rows = $("searchFiltersList").getElementsByTagName("tr");
|
|
|
|
var currentRow = this.up(".filterRow");
|
2014-08-06 20:49:36 +02:00
|
|
|
|
|
|
|
if(rows.length > 1)
|
2014-09-04 16:50:03 +02:00
|
|
|
$(currentRow).remove();
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**** Search mail Footer ****/
|
|
|
|
|
|
|
|
function onResultSelectionChange(event) {
|
|
|
|
var table = $("searchMailFooter").down("tbody");
|
|
|
|
|
2014-08-15 17:41:37 +02:00
|
|
|
if (event && (event.target.innerHTML != _("No matches found"))) {
|
2014-08-06 20:49:36 +02:00
|
|
|
var node = getTarget(event);
|
|
|
|
|
|
|
|
if (node.tagName == "SPAN")
|
|
|
|
node = node.parentNode;
|
|
|
|
|
|
|
|
// Update rows selection
|
|
|
|
onRowClick(event, node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**** Search mail optionsButtons ****/
|
|
|
|
|
|
|
|
function onOpenClick(event) {
|
|
|
|
// This function is linked with the openButton and the doubleClick on a message
|
|
|
|
var selectedRow = $("searchMailFooter").down("._selected");
|
|
|
|
var msguid = selectedRow.getAttribute("uid");
|
|
|
|
var folderName = selectedRow.getAttribute("folderName");
|
2014-08-27 18:30:33 +02:00
|
|
|
var accountUser = userNames[0];
|
2014-08-06 20:49:36 +02:00
|
|
|
|
2014-08-27 18:30:33 +02:00
|
|
|
var url = "/SOGo/so/" + accountUser + "/Mail" + folderName + "/" + msguid + "/popupview";
|
2014-08-06 20:49:36 +02:00
|
|
|
if (selectedRow) {
|
|
|
|
openMessageWindow(msguid, url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDeleteClick(event) {
|
2014-09-04 16:50:03 +02:00
|
|
|
var messageList = $("resultsTable").down("TABLE");
|
|
|
|
var row = $(messageList).getSelectedRows()[0];
|
2014-08-14 20:49:44 +02:00
|
|
|
if (row) {
|
2014-09-04 16:50:03 +02:00
|
|
|
var rowIds = row.getAttribute("uid");
|
2014-08-14 20:49:44 +02:00
|
|
|
var uids = new Array(); // message IDs
|
|
|
|
var paths = new Array(); // row IDs
|
|
|
|
var unseenCount = 0;
|
|
|
|
var refreshFolder = false;
|
2014-09-04 16:50:03 +02:00
|
|
|
if (rowIds) {
|
2014-08-14 20:49:44 +02:00
|
|
|
messageList.deselectAll();
|
|
|
|
if (unseenCount < 1) {
|
|
|
|
if (row.hasClassName("mailer_unreadmail"))
|
|
|
|
unseenCount--;
|
|
|
|
else
|
|
|
|
unseenCount = 1;
|
2014-09-04 16:50:03 +02:00
|
|
|
|
|
|
|
$(row).remove();
|
2014-08-14 20:49:44 +02:00
|
|
|
}
|
|
|
|
var uid = rowIds;
|
|
|
|
var path = Mailer.currentMailbox + "/" + uid;
|
|
|
|
uids.push(uid);
|
|
|
|
paths.push(path);
|
|
|
|
deleteMessageRequestCount++;
|
|
|
|
|
|
|
|
deleteCachedMessage(path);
|
|
|
|
if (Mailer.currentMessages[Mailer.currentMailbox] == uid) {
|
|
|
|
if (messageContent) messageContent.innerHTML = '';
|
|
|
|
Mailer.currentMessages[Mailer.currentMailbox] = null;
|
|
|
|
}
|
|
|
|
Mailer.dataTable.remove(uid);
|
|
|
|
updateMessageListCounter(0 - rowIds.length, true);
|
|
|
|
if (unseenCount < 0) {
|
|
|
|
var node = mailboxTree.getMailboxNode(Mailer.currentMailbox);
|
|
|
|
if (node) {
|
|
|
|
updateUnseenCount(node, unseenCount, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var url = ApplicationBaseURL + encodeURI(Mailer.currentMailbox) + "/batchDelete";
|
|
|
|
var parameters = "uid=" + uids.join(",");
|
|
|
|
var data = { "id": uids, "mailbox": Mailer.currentMailbox, "path": paths, "refreshUnseenCount": (unseenCount > 0), "refreshFolder": refreshFolder };
|
|
|
|
triggerAjaxRequest(url, deleteMessageCallback, data, parameters,
|
|
|
|
{ "Content-type": "application/x-www-form-urlencoded" });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteMessageCallback (http){
|
|
|
|
if (isHttpStatus204(http.status) || http.status == 200) {
|
|
|
|
var data = http.callbackData;
|
|
|
|
if (http.status == 200) {
|
|
|
|
// The answer contains quota information
|
|
|
|
var rdata = http.responseText.evalJSON(true);
|
|
|
|
if (rdata.quotas && data["mailbox"].startsWith('/0/'))
|
|
|
|
updateQuotas(rdata.quotas);
|
|
|
|
}
|
|
|
|
if (data["refreshUnseenCount"])
|
|
|
|
// TODO : the unseen count should be returned when calling the batchDelete remote action,
|
|
|
|
// in order to avoid this extra AJAX call.
|
|
|
|
getUnseenCountForFolder(data["mailbox"]);
|
|
|
|
if (data["refreshFolder"])
|
|
|
|
Mailer.dataTable.refresh();
|
|
|
|
}
|
|
|
|
else if (!http.callbackData["withoutTrash"]) {
|
|
|
|
showConfirmDialog(_("Warning"),
|
|
|
|
_("The messages could not be moved to the trash folder. Would you like to delete them immediately?"),
|
|
|
|
deleteMessagesWithoutTrash.bind(document, http.callbackData),
|
|
|
|
function() { refreshCurrentFolder(); disposeDialog(); });
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var html = new Element('div').update(http.responseText);
|
|
|
|
log ("Messages deletion failed (" + http.status + ") : ");
|
|
|
|
log (html.down('p').innerHTML);
|
|
|
|
showAlertDialog(_("Operation failed"));
|
|
|
|
refreshCurrentFolder();
|
|
|
|
}
|
|
|
|
onSearchEnd();
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function onResizeClick() {
|
2014-08-11 15:25:09 +02:00
|
|
|
var searchFiltersList = jQuery("#searchFiltersList");
|
|
|
|
var img = $("listCollapse").select('img').first();
|
2014-08-27 18:30:33 +02:00
|
|
|
var dialogWindowHeight = $("searchMailView").getHeight();
|
|
|
|
var state = "collapse";
|
|
|
|
|
2014-08-11 15:25:09 +02:00
|
|
|
if (searchFiltersList[0].visible()) {
|
2014-09-05 22:04:29 +02:00
|
|
|
state = "rise";
|
2014-08-11 15:25:09 +02:00
|
|
|
searchFiltersList.fadeOut(300, function() {
|
2014-08-27 18:30:33 +02:00
|
|
|
adjustResultsTable(state);
|
|
|
|
img.removeClassName('collapse').addClassName('rise');
|
2014-08-11 15:25:09 +02:00
|
|
|
});
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-08-27 18:30:33 +02:00
|
|
|
adjustResultsTable(state);
|
|
|
|
searchFiltersList.fadeIn();
|
|
|
|
img.removeClassName('rise').addClassName('collapse');
|
2014-08-06 20:49:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-27 18:30:33 +02:00
|
|
|
function adjustResultsTable(state) {
|
|
|
|
var resultsTable = $("resultsTable");
|
2014-09-05 17:01:57 +02:00
|
|
|
var height = "innerHeight" in $("searchMailView") ? $("searchMailView").innerHeight : $("searchMailView").offsetHeight;
|
|
|
|
if (state == "collapse") {
|
|
|
|
height -= 266;
|
|
|
|
}
|
2014-08-27 18:30:33 +02:00
|
|
|
else
|
2014-09-05 17:01:57 +02:00
|
|
|
height -= 152;
|
|
|
|
$(resultsTable).style.height = height + "px";
|
2014-08-27 18:30:33 +02:00
|
|
|
}
|
|
|
|
|
2014-08-06 20:49:36 +02:00
|
|
|
/*************** Init ********************/
|
|
|
|
|
|
|
|
function initSearchMailView () {
|
|
|
|
|
|
|
|
// Add one filterRow
|
|
|
|
onAddFilter();
|
2014-08-27 18:30:33 +02:00
|
|
|
adjustResultsTable("collapse");
|
2014-08-06 20:49:36 +02:00
|
|
|
|
|
|
|
// Observers : Event.on(element, eventName[, selector], callback)
|
|
|
|
$("searchMailFooter").down("tbody").on("mousedown", "tr", onResultSelectionChange);
|
|
|
|
$("searchMailFooter").down("tbody").on("dblclick", "tr", onOpenClick);
|
2014-08-27 18:30:33 +02:00
|
|
|
Event.observe(window, "resize", function() {
|
|
|
|
var state = ($("searchFiltersList").visible() ? "collapse": "rise");
|
|
|
|
adjustResultsTable(state);
|
|
|
|
});
|
2014-09-05 22:04:29 +02:00
|
|
|
}
|