From c5f9dd086b78319d5e8170b62ae854a8e9d625c0 Mon Sep 17 00:00:00 2001 From: Alexandre Cloutier Date: Tue, 12 Aug 2014 17:43:01 -0400 Subject: [PATCH] Possibility to collapsed threads with persistance --- UI/MailerUI/UIxMailActions.m | 79 +++++++++++++++++++++ UI/MailerUI/product.plist | 10 +++ UI/WebServerResources/MailerUI.js | 48 +++++++++++-- UI/WebServerResources/SOGoDataTable.js | 1 - UI/WebServerResources/SOGoMailDataSource.js | 9 ++- 5 files changed, 139 insertions(+), 8 deletions(-) diff --git a/UI/MailerUI/UIxMailActions.m b/UI/MailerUI/UIxMailActions.m index b21cd160f..27e5e9a8f 100644 --- a/UI/MailerUI/UIxMailActions.m +++ b/UI/MailerUI/UIxMailActions.m @@ -145,6 +145,85 @@ return response; } +- (id) markMessageCollapseAction +{ + NSMutableDictionary *moduleSettings, *threadsCollapsed; + NSMutableArray *mailboxThreadsCollapsed; + NSString *msguid, *currentMailbox, *currentAccount, *keyForMsgUIDs; + SOGoUserSettings *us; + us = [[context activeUser] userSettings]; + moduleSettings = [us objectForKey: @"Mail"]; + + msguid = [[self clientObject] nameInContainer]; + currentMailbox = [[[self clientObject] container] nameInContainer]; + currentAccount = [[[[self clientObject] container] container] nameInContainer]; + keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox]; + + // Check if the module threadsCollapsed is created in the userSettings + if ([moduleSettings objectForKey:@"threadsCollapsed"]) + { + // Check if the currentMailbox already have other threads saved and add the new collapsed thread + threadsCollapsed = [moduleSettings objectForKey:@"threadsCollapsed"]; + if ([threadsCollapsed objectForKey:keyForMsgUIDs]) + { + mailboxThreadsCollapsed = [threadsCollapsed objectForKey:keyForMsgUIDs]; + if (![mailboxThreadsCollapsed containsObject:msguid]) + [mailboxThreadsCollapsed addObject:msguid]; + } + else + { + mailboxThreadsCollapsed = [NSMutableArray arrayWithObject:msguid]; + [threadsCollapsed setObject:mailboxThreadsCollapsed forKey:keyForMsgUIDs]; + } + } + else + { + // Created the module threadsCollapsed and add the new collapsed thread + mailboxThreadsCollapsed = [NSMutableArray arrayWithObject:msguid]; + threadsCollapsed = [NSMutableDictionary dictionaryWithObject:mailboxThreadsCollapsed forKey:keyForMsgUIDs]; + [moduleSettings setObject:threadsCollapsed forKey: @"threadsCollapsed"]; + } + + [us synchronize]; + + return [self responseWith204]; +} + +- (id) markMessageUncollapseAction +{ + NSMutableDictionary *moduleSettings, *threadsCollapsed; + NSMutableArray *mailboxThreadsCollapsed; + NSString *msguid, *currentMailbox, *currentAccount, *keyForMsgUIDs; + SOGoUserSettings *us; + us = [[context activeUser] userSettings]; + moduleSettings = [us objectForKey: @"Mail"]; + + msguid = [[self clientObject] nameInContainer]; + currentMailbox = [[[self clientObject] container] nameInContainer]; + currentAccount = [[[[self clientObject] container] container] nameInContainer]; + keyForMsgUIDs = [NSString stringWithFormat:@"/%@/%@", currentAccount, currentMailbox]; + + // Check if the module threadsCollapsed is created in the userSettings + if ([moduleSettings objectForKey:@"threadsCollapsed"]) + { + // Check if the currentMailbox already have other threads saved and remove the uncollapsed thread + threadsCollapsed = [moduleSettings objectForKey:@"threadsCollapsed"]; + if ([threadsCollapsed objectForKey:keyForMsgUIDs]) + { + mailboxThreadsCollapsed = [threadsCollapsed objectForKey:keyForMsgUIDs]; + [mailboxThreadsCollapsed removeObject:msguid]; + + if ([mailboxThreadsCollapsed count] == 0) + [threadsCollapsed removeObjectForKey:keyForMsgUIDs]; + + [us synchronize]; + } + } + // TODO : Manage errors + + return [self responseWith204]; +} + /* SOGoDraftObject */ - (WOResponse *) editAction { diff --git a/UI/MailerUI/product.plist b/UI/MailerUI/product.plist index 4956cf286..3060fe3ec 100644 --- a/UI/MailerUI/product.plist +++ b/UI/MailerUI/product.plist @@ -252,6 +252,16 @@ actionClass = "UIxMailActions"; actionName = "forward"; }; + markMessageUncollapse = { + protectedBy = "View"; + actionClass = "UIxMailActions"; + actionName = "markMessageUncollapse"; + }; + markMessageCollapse = { + protectedBy = "View"; + actionClass = "UIxMailActions"; + actionName = "markMessageCollapse"; + }; markMessageUnflagged = { protectedBy = "View"; actionClass = "UIxMailActions"; diff --git a/UI/WebServerResources/MailerUI.js b/UI/WebServerResources/MailerUI.js index 3ce06319c..d80268e24 100644 --- a/UI/WebServerResources/MailerUI.js +++ b/UI/WebServerResources/MailerUI.js @@ -219,13 +219,16 @@ function openMessageWindowsForSelection(action, firstOnly) { return false; } -/* + function mailListToggleMessageThread(row, cell) { var show = row.hasClassName('closedThread'); + var msguid = row.id.split("_")[1]; + var action = "markMessageCollapse"; $(cell).down('img').remove(); if (show) { row.removeClassName('closedThread'); row.addClassName('openedThread'); + action = "markMessageUncollapse"; var img = createElement("img", null, null, { src: ResourcesURL + '/arrow-down.png' }); cell.insertBefore(img, cell.firstChild); } @@ -241,8 +244,23 @@ function mailListToggleMessageThread(row, cell) { else row.hide(); } + + // Update the dictionnary of the collapsed threads + var mailbox = Mailer.currentMailbox; + var url = ApplicationBaseURL + encodeURI(mailbox) + "/" + msguid + "/" + action; + var data = { "currentMailbox": Mailer.currentMailbox, "msguid": msguid }; + + triggerAjaxRequest(url, mailListToggleMessageCollapseCallback); } -*/ + +function mailListToggleMessageCollapseCallback(http) { + var data = http.callbackData; + if (!isHttpStatus204(http.status)) { + log("Message Collapse Failed (" + http.status + "): " + http.statusText); + } + //Mailer.dataTable.invalidate(data["msguid"], true); +} + /* Triggered when clicking on the read/unread dot of a message row or * through the contextual menu. */ @@ -929,6 +947,8 @@ function openMailbox(mailbox, reload) { /* * Called from SOGoDataTable.render() */ +var show = false; + function messageListCallback(row, data, isNew) { var currentMessage = Mailer.currentMessages[Mailer.currentMailbox]; row.id = data['rowID']; @@ -940,13 +960,31 @@ function messageListCallback(row, data, isNew) { if (data['uid'] == currentMessage) row.addClassName('_selected'); - if (data['Thread']) - row.addClassName('openedThread'); + if (data['Thread']) { + if (UserSettings.Mail.threadsCollapsed) { + var mailbox = Mailer.currentMailbox; + var collapsedList = UserSettings.Mail.threadsCollapsed[mailbox]; + if (collapsedList != undefined && collapsedList.indexOf(row.id.split("_")[1]) != -1) { + row.addClassName('closedThread'); + show = true; + } + else { + row.addClassName('openedThread'); + } + } + } + else if (data['ThreadLevel'] > 0) { if (data['ThreadLevel'] > 10) data['ThreadLevel'] = 10; row.addClassName('thread'); row.addClassName('thread' + data['ThreadLevel']); + + if (show) + row.hide(); } + + else + show = false; var cells = row.childElements(); for (var j = 0; j < cells.length; j++) { @@ -1222,7 +1260,7 @@ function onMessageSelectionChange(event) { t = t.parentNode; if (t.tagName == 'TD') { if (t.className == 'messageThreadColumn') { - //mailListToggleMessageThread(t.parentNode, t); Disable thread collapsing + mailListToggleMessageThread(t.parentNode, t); } else if (t.className == 'messageUnreadColumn') { mailListToggleMessagesRead(t.parentNode); diff --git a/UI/WebServerResources/SOGoDataTable.js b/UI/WebServerResources/SOGoDataTable.js index ee04b19f7..8cb0a94f0 100644 --- a/UI/WebServerResources/SOGoDataTable.js +++ b/UI/WebServerResources/SOGoDataTable.js @@ -248,7 +248,6 @@ var SOGoDataTableInterface = { j++, i++) { var row = this.rowModel.cloneNode(true); this.rowRenderCallback(row, data[j], true); - row.show(); this.body.insertBefore(row, this.rowBottom); } } diff --git a/UI/WebServerResources/SOGoMailDataSource.js b/UI/WebServerResources/SOGoMailDataSource.js index 7826ffe32..6535f57ff 100644 --- a/UI/WebServerResources/SOGoMailDataSource.js +++ b/UI/WebServerResources/SOGoMailDataSource.js @@ -196,8 +196,13 @@ SOGoMailDataSource = Class.create({ data[j] = this.cache.get(this.uids[i][0]); // Add thread-related data - if (parseInt(this.uids[i][2]) > 0) - data[j]['Thread'] = ' '; //''; + if (parseInt(this.uids[i][2]) > 0) { + var mailbox = Mailer.currentMailbox; + if ((UserSettings.Mail.threadsCollapsed[Mailer.currentMailbox] != undefined) && (UserSettings.Mail.threadsCollapsed[Mailer.currentMailbox].indexOf((this.uids[i][0]).toString())) != -1) + data[j]['Thread'] = ''; + else + data[j]['Thread'] = ''; + } else if (data[j]['Thread']) delete data[j]['Thread']; if (parseInt(this.uids[i][1]) > -1)