1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc.
  5  *
  6  * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at: https://www.zimbra.com/license
  9  * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15
 10  * have been added to cover use of software over a computer network and provide for limited attribution
 11  * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
 12  *
 13  * Software distributed under the License is distributed on an "AS IS" basis,
 14  * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing rights and limitations under the License.
 16  * The Original Code is Zimbra Open Source Web Client.
 17  * The Initial Developer of the Original Code is Zimbra, Inc.  All rights to the Original Code were
 18  * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015.
 19  *
 20  * All portions of the code are Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * Creates a new, empty "traditional view" controller.
 26  * @constructor
 27  * @class
 28  * This class manages the two-pane message view. The top pane contains a list
 29  * view of the messages in the conversation, and the bottom pane contains the current
 30  * message.
 31  *
 32  * @author Parag Shah
 33  * 
 34  * @param {DwtControl}					container					the containing shell
 35  * @param {ZmApp}						mailApp						the containing application
 36  * @param {constant}					type						type of controller
 37  * @param {string}						sessionId					the session id
 38  * @param {ZmSearchResultsController}	searchResultsController		containing controller
 39  * 
 40  * @extends		ZmDoublePaneController
 41  * 
 42  * @private
 43  */
 44 ZmTradController = function(container, mailApp, type, sessionId, searchResultsController) {
 45 	ZmDoublePaneController.apply(this, arguments);
 46 
 47 	this._listeners[ZmOperation.SHOW_CONV] = this._showConvListener.bind(this);
 48 };
 49 
 50 ZmTradController.prototype = new ZmDoublePaneController;
 51 ZmTradController.prototype.constructor = ZmTradController;
 52 
 53 ZmTradController.prototype.isZmTradController = true;
 54 ZmTradController.prototype.toString = function() { return "ZmTradController"; };
 55 
 56 ZmMailListController.GROUP_BY_ITEM[ZmId.VIEW_TRAD]		= ZmItem.MSG;
 57 ZmMailListController.GROUP_BY_SETTING[ZmId.VIEW_TRAD]	= ZmSetting.GROUP_BY_MESSAGE;
 58 
 59 // view menu
 60 ZmMailListController.GROUP_BY_ICON[ZmId.VIEW_TRAD]		= "MessageView";
 61 ZmMailListController.GROUP_BY_MSG_KEY[ZmId.VIEW_TRAD]	= "byMessage";
 62 ZmMailListController.GROUP_BY_SHORTCUT[ZmId.VIEW_TRAD]	= ZmKeyMap.VIEW_BY_MSG;
 63 ZmMailListController.GROUP_BY_VIEWS.push(ZmId.VIEW_TRAD);
 64 
 65 // Public methods
 66 
 67 ZmTradController.getDefaultViewType =
 68 function() {
 69 	return ZmId.VIEW_TRAD;
 70 };
 71 ZmTradController.prototype.getDefaultViewType = ZmTradController.getDefaultViewType;
 72 
 73 /**
 74  * Displays the given message list in a two-pane view.
 75  *
 76  * @param {ZmSearchResult}	searchResults		the current search results
 77  */
 78 ZmTradController.prototype.show =
 79 function(searchResults) {
 80 	ZmDoublePaneController.prototype.show.call(this, searchResults, searchResults.getResults(ZmItem.MSG));
 81 	if (!appCtxt.isExternalAccount() && !this.isSearchResults && !(searchResults && searchResults.search && searchResults.search.isDefaultToMessageView)) {
 82 		appCtxt.set(ZmSetting.GROUP_MAIL_BY, ZmSetting.GROUP_BY_MESSAGE);
 83 	}
 84 	this._resetNavToolBarButtons(ZmId.VIEW_TRAD);
 85 };
 86 
 87 ZmTradController.prototype.handleKeyAction =
 88 function(actionCode, ev) {
 89 
 90 	DBG.println(AjxDebug.DBG3, "ZmTradController.handleKeyAction");
 91 
 92 	switch (actionCode) {
 93 		case ZmKeyMap.KEEP_READING:
 94 			return this._keepReading(false, ev);
 95 			break;
 96 
 97 		default:
 98 			return ZmDoublePaneController.prototype.handleKeyAction.apply(this, arguments);
 99 	}
100 };
101 
102 // Private methods
103 
104 ZmTradController.prototype._createDoublePaneView = 
105 function() {
106 	return (new ZmTradView({parent:this._container, posStyle:Dwt.ABSOLUTE_STYLE,
107 							controller:this, dropTgt:this._dropTgt}));
108 };
109 
110 ZmTradController.prototype._resetOperations = 
111 function(parent, num) {
112 	ZmDoublePaneController.prototype._resetOperations.apply(this, arguments);
113 	parent.enable(ZmOperation.SHOW_CONV, (num == 1) && !appCtxt.isWebClientOffline());
114 };
115 
116 ZmTradController.prototype._paginate = 
117 function(view, bPageForward, convIdx, limit) {
118 	view = view || this._currentViewId;
119 	return ZmDoublePaneController.prototype._paginate.call(this, view, bPageForward, convIdx, limit);
120 };
121 
122 ZmTradController.prototype._resetNavToolBarButtons = 
123 function(view) {
124 
125 	view = view || this.getCurrentViewId();
126 	ZmDoublePaneController.prototype._resetNavToolBarButtons.call(this, view);
127 	if (!this._navToolBar[view]) { return; }
128 
129 	this._navToolBar[view].setToolTip(ZmOperation.PAGE_BACK, ZmMsg.previousPage);
130 	this._navToolBar[view].setToolTip(ZmOperation.PAGE_FORWARD, ZmMsg.nextPage);
131 };
132 
133 ZmTradController.prototype._keepReading = 
134 function(check, ev) {
135 	
136 	if (!this.isReadingPaneOn() || !this._itemViewCurrent()) { return false; }
137 	var mlv = this._mailListView;
138 	if (!mlv || mlv.getSelectionCount() != 1) { return false; }
139 	
140 	var itemView = this.getItemView();
141 	var result = itemView && itemView._keepReading(check);
142 	if (check) {
143 		result = result || !!(this._getUnreadItem(DwtKeyMap.SELECT_NEXT));
144 	}
145 	else {
146 		result = result || this.handleKeyAction(ZmKeyMap.NEXT_UNREAD, ev);
147 		if (result) {
148 			this._checkKeepReading();
149 		}
150 	}
151 	return result;
152 };
153 
154 ZmTradController.prototype._showConvListener =
155 function() {
156 	var msg = this.getMsg();
157 	if (!msg) { return; }
158 
159 	var list = new ZmMailList(ZmItem.CONV);
160 	list.search = msg.list.search;
161 	var conv = ZmConv.createFromMsg(msg, {list: list});
162 	AjxDispatcher.run("GetConvController").show(conv, this, null, null, msg);
163 };
164 
165 // Callbacks
166 
167 ZmTradController.prototype._handleResponsePaginate = 
168 function(view, saveSelection, loadIndex, offset, result, ignoreResetSelection) {
169 	// bug fix #5134 - overload to ignore resetting the selection since it is handled by setView
170 	ZmMailListController.prototype._handleResponsePaginate.call(this, view, saveSelection, loadIndex, offset, result, true);
171 };
172