1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 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) 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * Creates an empty shortcuts page.
 26  * @constructor
 27  * @class
 28  * This class represents a page which allows user to modify the trusted addresses/domain list
 29  * <p>
 30  * Only a single pref (the user's shortcuts gathered together in a string)
 31  * is represented.</p>
 32  *
 33  * @author Santosh Sutar
 34  *
 35  * @param {DwtControl}	parent			the containing widget
 36  * @param {object}	section			the page
 37  * @param {ZmPrefController}	controller		the prefs controller
 38  *
 39  * @extends		ZmPreferencesPage
 40  *
 41  * @private
 42  */
 43 ZmTrustedPage = function(parent, section, controller, id) {
 44 	ZmPreferencesPage.apply(this, arguments);
 45 };
 46 
 47 ZmTrustedPage.prototype = new ZmPreferencesPage;
 48 ZmTrustedPage.prototype.constructor = ZmTrustedPage;
 49 
 50 ZmTrustedPage.prototype.toString =
 51 function () {
 52     return "ZmTrustedPage";
 53 };
 54 
 55 ZmTrustedPage.prototype.showMe =
 56 function() {
 57 	ZmPreferencesPage.prototype.showMe.call(this);
 58 
 59 	if (!this._initialized) {
 60 		this._initialized = true;
 61 	}
 62 };
 63 
 64 ZmTrustedPage.prototype._setupCustom =
 65 function(id, setup, value) {
 66 	if (id == ZmSetting.TRUSTED_ADDR_LIST) {
 67 		this._trustedListControl = new ZmWhiteBlackList(this, id, "TrustedList");
 68         var trustedList = appCtxt.get(ZmSetting.TRUSTED_ADDR_LIST);
 69 
 70         	if (trustedList) {
 71                 for (var i = 0; i < trustedList.length; i++) {
 72                     trustedList[i] = AjxStringUtil.htmlEncode(trustedList[i]);
 73         		}
 74         	}
 75 
 76         this._trustedListControl.loadFromJson(trustedList);
 77 
 78 		return this._trustedListControl;
 79 	}
 80 };
 81 
 82 ZmTrustedPage.prototype.addItem =
 83 function(addr) {
 84     if(addr && this._trustedListControl) {
 85         this._trustedListControl.loadFromJson([addr]);
 86     }
 87 };
 88 
 89 ZmTrustedPage.prototype.reset =
 90 function(useDefaults) {
 91 	ZmPreferencesPage.prototype.reset.apply(this, arguments);
 92 
 93 	if (this._trustedListControl) {
 94 		this._trustedListControl.reset();
 95 	}
 96 };
 97 
 98 ZmTrustedPage.prototype.isDirty =
 99 function() {
100 	var isDirty = ZmPreferencesPage.prototype.isDirty.call(this) || this.isTrustedListDirty();
101 	if (isDirty) {
102 		AjxDebug.println(AjxDebug.PREFS, "Dirty preferences:\n" + "zimbraPrefMailTrustedSenderList");
103 	}
104 	return isDirty;
105 };
106 
107 ZmTrustedPage.prototype.isTrustedListDirty =
108 function() {
109 	if (this._trustedListControl) {
110 		return this._trustedListControl.isDirty();
111 	}
112 	return false;
113 };
114 
115 ZmTrustedPage.prototype.addCommand =
116 function(batchCmd) {
117     if(this._trustedListControl && this._trustedListControl.isDirty()) {
118         var i,
119             value = this._trustedListControl.getValue(),
120             soapDoc = AjxSoapDoc.create("ModifyPrefsRequest", "urn:zimbraAccount"),
121             node,
122             respCallback = new AjxCallback(this, this._postSaveBatchCmd, value.join(','));
123         for(i=0; i<value.length;i++) {
124             node = soapDoc.set("pref", AjxStringUtil.trim(value[i]));
125             node.setAttribute("name", "zimbraPrefMailTrustedSenderList");
126         }
127         batchCmd.addNewRequestParams(soapDoc, respCallback);
128     }
129 };
130 
131 ZmTrustedPage.prototype._postSaveBatchCmd =
132 function(value) {
133     appCtxt.set(ZmSetting.TRUSTED_ADDR_LIST, value.split(','));
134     var settings = appCtxt.getSettings();
135     var trustedListSetting = settings.getSetting(ZmSetting.TRUSTED_ADDR_LIST);
136     trustedListSetting._notify(ZmEvent.E_MODIFY); 
137     if(this._trustedListControl) {
138         this._trustedListControl.saveLocal();
139     }
140 };
141