1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2008, 2009, 2010, 2011, 2012, 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) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates the import/export page. 26 * @class 27 * This class represents the import/export page. 28 * 29 * @param {DwtControl} parent the containing widget 30 * @param {Object} section the page 31 * @param {ZmPrefController} controller the prefs controller 32 * 33 * @extends ZmPreferencesPage 34 * 35 * @private 36 */ 37 ZmImportExportPage = function(parent, section, controller) { 38 ZmPreferencesPage.apply(this, arguments); 39 }; 40 41 ZmImportExportPage.prototype = new ZmPreferencesPage; 42 ZmImportExportPage.prototype.constructor = ZmImportExportPage; 43 44 ZmImportExportPage.prototype.toString = 45 function () { 46 return "ZmImportExportPage"; 47 }; 48 49 // 50 // ZmPreferencesPage methods 51 // 52 53 ZmImportExportPage.prototype.reset = 54 function(useDefaults) { 55 ZmPreferencesPage.prototype.reset.apply(this, arguments); 56 var button = this.getFormObject("IMPORT_BUTTON"); 57 if (button) { 58 button.setEnabled(true); 59 } 60 }; 61 62 ZmImportExportPage.prototype.hasResetButton = 63 function() { 64 return false; 65 }; 66 67 // 68 // Protected methods 69 // 70 71 ZmImportExportPage.prototype._setupCustom = function(id, setup, value) { 72 if (id == "EXPORT_FOLDER") { 73 var view = new ZmExportView({parent:this}); 74 this.setFormObject(id, view); 75 return view; 76 } 77 if (id == "EXPORT_BUTTON") { 78 var button = new DwtButton({parent:this, id: id}); 79 button.setText(setup.displayName); 80 button.addSelectionListener(new AjxListener(this, this._handleExportButton)); 81 this.setFormObject(id, button); 82 return button; 83 } 84 if (id == "IMPORT_FOLDER") { 85 var view = new ZmImportView({parent:this}); 86 this.setFormObject(id, view); 87 return view; 88 } 89 if (id == "IMPORT_BUTTON") { 90 var button = new DwtButton({parent:this, id: id}); 91 button.setText(setup.displayName); 92 button.addSelectionListener(new AjxListener(this, this._handleImportButton)); 93 this.setFormObject(id, button); 94 return button; 95 } 96 return ZmPreferencesPage.prototype._setupCustom.apply(this, arguments); 97 }; 98 99 // handlers 100 101 ZmImportExportPage.prototype._handleImportButton = function() { 102 var button = this.getFormObject("IMPORT_BUTTON"); 103 if (button) { 104 button.setEnabled(false); 105 } 106 107 // get import params 108 var importView = this.getFormObject("IMPORT_FOLDER"); 109 var params = {}; 110 params = importView && importView.getParams(); 111 params.callback = params.errorCallback = new AjxCallback(this, this._handleImportComplete); 112 113 // import 114 var controller = appCtxt.getImportExportController(); 115 if (controller.importData(params)) { 116 var params = { 117 msg: ZmMsg.importStarted, 118 level: ZmStatusView.LEVEL_INFO 119 }; 120 appCtxt.setStatusMsg(params); 121 } 122 else if (button) { 123 button.setEnabled(true); 124 } 125 }; 126 127 ZmImportExportPage.prototype._handleExportButton = function() { 128 // get export params 129 var exportView = this.getFormObject("EXPORT_FOLDER"); 130 var params = exportView.getParams(); 131 132 // export 133 var controller = appCtxt.getImportExportController(); 134 controller.exportData(params); 135 }; 136 137 ZmImportExportPage.prototype._handleImportComplete = function() { 138 var button = this.getFormObject("IMPORT_BUTTON"); 139 if (button) { 140 button.setEnabled(true); 141 } 142 };