1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2011, 2013, 2014, 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) 2011, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * @overview
 26  * This file contains the search application class.
 27  */
 28 
 29 /**
 30  * Creates and initializes the search application.
 31  * @constructor
 32  * @class
 33  * The search app manages user-initiated searches.
 34  *
 35  * @param	{DwtControl}	container		the container
 36  * @param	{ZmController}	parentController	the parent window controller (set by the child window)
 37  * 
 38  * @author Conrad Damon
 39  * 
 40  * @extends		ZmApp
 41  */
 42 ZmSearchApp = function(container, parentController) {
 43 
 44 	ZmApp.call(this, ZmApp.SEARCH, container, parentController);
 45 
 46 	this._groupBy = appCtxt.get(ZmSetting.GROUP_MAIL_BY);
 47 };
 48 
 49 ZmSearchApp.prototype = new ZmApp;
 50 ZmSearchApp.prototype.constructor = ZmSearchApp;
 51 
 52 ZmSearchApp.prototype.isZmSearchApp = true;
 53 ZmSearchApp.prototype.toString = function() {	return "ZmSearchApp"; };
 54 
 55 ZmApp.SEARCH					= ZmId.APP_SEARCH;
 56 ZmApp.CLASS[ZmApp.SEARCH]		= "ZmSearchApp";
 57 ZmApp.SETTING[ZmApp.SEARCH]		= ZmSetting.SEARCH_ENABLED;
 58 
 59 ZmSearchApp.CONTROLLER_CLASS = "ZmSearchResultsController";
 60 
 61 ZmSearchApp.prototype.getSearchResultsController =
 62 function(sessionId, appName) {
 63 	return this.getSessionController({
 64 				controllerClass:	ZmSearchApp.CONTROLLER_CLASS,
 65 				sessionId:			sessionId,
 66 				appName:			appName
 67 			});
 68 };
 69 
 70 // override so we don't try to set overview panel content
 71 ZmSearchApp.prototype.activate =
 72 function(active) {
 73 	this._active = active;
 74 };
 75 
 76 // Not hooked up for activate, but it will be called after displaying the search results
 77 ZmSearchApp.prototype.resetWebClientOfflineOperations =
 78 function(searchResultsController) {
 79 	ZmApp.prototype.resetWebClientOfflineOperations.apply(this);
 80 	if (!searchResultsController) {
 81 		var controllerType = this.getTypeFromController(ZmSearchApp.CONTROLLER_CLASS);
 82 		var sessionId = this.getCurrentSessionId(controllerType);
 83 		searchResultsController = this.getSearchResultsController(sessionId);
 84 	}
 85 	// Only Save affected currently
 86 	var searchResultsToolBar = searchResultsController && searchResultsController._toolbar;
 87 	var saveButton = searchResultsToolBar && searchResultsToolBar.getButton(ZmSearchToolBar.SAVE_BUTTON);
 88 	if (saveButton) {
 89 		saveButton.setEnabled(!appCtxt.isWebClientOffline());
 90 	}
 91 };
 92 
 93 // search app maintains its own "group mail by" setting
 94 ZmSearchApp.prototype.getGroupMailBy = function() {
 95 	return ZmMailApp.prototype.getGroupMailBy.call(this);
 96 };
 97 
 98 ZmSearchApp.prototype.setGroupMailBy = 	function(groupBy) {
 99 	this._groupBy = groupBy;
100 };
101