code beautifications

This commit is contained in:
2016-06-13 22:59:05 +02:00
parent 21af50aa6c
commit 4ce04ab6f9
12 changed files with 682 additions and 614 deletions

View File

@@ -2,7 +2,7 @@
* ImportContentPanel.js zarafa contact to vcf im/exporter
*
* Author: Christoph Haas <christoph.h@sprinternet.at>
* Copyright (C) 2012-2013 Christoph Haas
* Copyright (C) 2012-2016 Christoph Haas
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,13 +19,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/**
* ImportContentPanel
*
* Container for the importpanel.
*/
Ext.namespace("Zarafa.plugins.contactimporter.dialogs");
Ext.namespace("Zarafa.plugins.contactimporter.dialogs");
/**
* @class Zarafa.plugins.contactimporter.dialogs.ImportContentPanel
@@ -40,23 +40,20 @@ Zarafa.plugins.contactimporter.dialogs.ImportContentPanel = Ext.extend(Zarafa.co
* @constructor
* @param config Configuration structure
*/
constructor : function(config) {
constructor: function (config) {
config = config || {};
var title = _('Import Contacts');
if(container.getSettingsModel().get("zarafa/v1/plugins/contactimporter/enable_export")){
title = _('Import/Export Contacts');
}
Ext.applyIf(config, {
layout : 'fit',
title : title,
closeOnSave : true,
width : 620,
height : 465,
layout : 'fit',
title : title,
closeOnSave: true,
width : 620,
height : 465,
//Add panel
items : [
items : [
{
xtype : 'contactimporter.importcontactpanel',
filename : config.filename
xtype : 'contactimporter.importcontactpanel',
filename: config.filename
}
]
});
@@ -66,4 +63,4 @@ Zarafa.plugins.contactimporter.dialogs.ImportContentPanel = Ext.extend(Zarafa.co
});
Ext.reg('contactimporter.contentpanel' ,Zarafa.plugins.contactimporter.dialogs.ImportContentPanel);
Ext.reg('contactimporter.contentpanel', Zarafa.plugins.contactimporter.dialogs.ImportContentPanel);

View File

@@ -2,7 +2,7 @@
* ImportPanel.js zarafa contact to vcf im/exporter
*
* Author: Christoph Haas <christoph.h@sprinternet.at>
* Copyright (C) 2012-2013 Christoph Haas
* Copyright (C) 2012-2016 Christoph Haas
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -13,7 +13,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -25,7 +25,7 @@
*
* The main Panel of the contactimporter plugin.
*/
Ext.namespace("Zarafa.plugins.contactimporter.dialogs");
Ext.namespace("Zarafa.plugins.contactimporter.dialogs");
/**
* @class Zarafa.plugins.contactimporter.dialogs.ImportPanel
@@ -35,22 +35,22 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
/* path to vcf file on server... */
vcffile: null,
/* The store for the selection grid */
store: null,
store : null,
/**
* @constructor
* @param {object} config
*/
constructor : function (config) {
constructor: function (config) {
config = config || {};
var self = this;
if(!Ext.isEmpty(config.filename)) {
if (!Ext.isEmpty(config.filename)) {
this.vcffile = config.filename;
}
// create the data store
// we only display the firstname, lastname, homephone and primary email address in our grid
this.store = new Ext.data.ArrayStore({
@@ -62,42 +62,42 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
{name: 'record'}
]
});
Ext.apply(config, {
xtype : 'contactimporter.importpanel',
ref : "importcontactpanel",
layout : {
type : 'form',
align : 'stretch'
xtype : 'contactimporter.importpanel',
ref : "importcontactpanel",
layout : {
type : 'form',
align: 'stretch'
},
anchor : '100%',
bodyStyle : 'background-color: inherit;',
defaults : {
border : true,
bodyStyle : 'background-color: inherit; padding: 3px 0px 3px 0px; border-style: none none solid none;'
anchor : '100%',
bodyStyle: 'background-color: inherit;',
defaults : {
border : true,
bodyStyle: 'background-color: inherit; padding: 3px 0px 3px 0px; border-style: none none solid none;'
},
items : [
items : [
this.createSelectBox(),
this.initForm(),
this.createGrid()
],
buttons: [
buttons : [
this.createSubmitAllButton(),
this.createSubmitButton(),
this.createCancelButton()
],
],
listeners: {
afterrender: function (cmp) {
this.loadMask = new Ext.LoadMask(this.getEl(), {msg:'Loading...'});
if(this.vcffile != null) { // if we have got the filename from an attachment
this.loadMask = new Ext.LoadMask(this.getEl(), {msg: 'Loading...'});
if (this.vcffile != null) { // if we have got the filename from an attachment
this.parseContacts(this.vcffile);
}
},
scope: this
scope : this
}
});
Zarafa.plugins.contactimporter.dialogs.ImportPanel.superclass.constructor.call(this, config);
},
@@ -106,22 +106,22 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
* posted and contains the attachments
* @private
*/
initForm : function () {
initForm: function () {
return {
xtype: 'form',
ref: 'addContactFormPanel',
layout : 'column',
xtype : 'form',
ref : 'addContactFormPanel',
layout : 'column',
fileUpload: true,
autoWidth: true,
autoWidth : true,
autoHeight: true,
border: false,
bodyStyle: 'padding: 5px;',
defaults: {
anchor: '95%',
border: false,
border : false,
bodyStyle : 'padding: 5px;',
defaults : {
anchor : '95%',
border : false,
bodyStyle: 'padding: 5px;'
},
items: [this.createUploadField()]
items : [this.createUploadField()]
};
},
@@ -129,14 +129,14 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
* Reloads the data of the grid
* @private
*/
reloadGridStore: function(contactdata) {
reloadGridStore: function (contactdata) {
var parsedData = [];
if(contactdata) {
if (contactdata) {
parsedData = new Array(contactdata.contacts.length);
var i = 0;
for(i = 0; i < contactdata.contacts.length; i++) {
for (i = 0; i < contactdata.contacts.length; i++) {
parsedData[i] = [
contactdata.contacts[i]["display_name"],
contactdata.contacts[i]["given_name"],
@@ -151,63 +151,63 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
this.store.loadData(parsedData, false);
},
/**
* Init embedded form, this is the form that is
* posted and contains the attachments
* @private
*/
createGrid : function() {
createGrid: function () {
return {
xtype: 'grid',
ref: 'contactGrid',
xtype : 'grid',
ref : 'contactGrid',
columnWidth: 1.0,
store: this.store,
width: '100%',
height: 300,
title: 'Select contacts to import',
frame: false,
viewConfig:{
forceFit:true
store : this.store,
width : '100%',
height : 300,
title : 'Select contacts to import',
frame : false,
viewConfig : {
forceFit: true
},
colModel: new Ext.grid.ColumnModel({
colModel : new Ext.grid.ColumnModel({
defaults: {
width: 300,
width : 300,
sortable: true
},
columns: [
columns : [
{id: 'Displayname', header: 'Displayname', width: 350, sortable: true, dataIndex: 'display_name'},
{header: 'Firstname', width: 200, sortable: true, dataIndex: 'given_name'},
{header: 'Lastname', width: 200, sortable: true, dataIndex: 'surname'},
{header: 'Company', sortable: true, dataIndex: 'company_name'}
]
}),
sm: new Ext.grid.RowSelectionModel({multiSelect:true})
sm : new Ext.grid.RowSelectionModel({multiSelect: true})
}
},
createSelectBox: function() {
createSelectBox: function () {
var defaultFolder = container.getHierarchyStore().getDefaultFolder('contact'); // @type: Zarafa.hierarchy.data.MAPIFolderRecord
var subFolders = defaultFolder.getChildren();
var myStore = [];
/* add all local contact folders */
var i = 0;
myStore.push([defaultFolder.getDefaultFolderKey(), defaultFolder.getDisplayName()]);
for(i = 0; i < subFolders.length; i++) {
for (i = 0; i < subFolders.length; i++) {
/* Store all subfolders */
myStore.push([subFolders[i].getDisplayName(), subFolders[i].getDisplayName(), false]); // 3rd field = isPublicfolder
}
/* add all shared contact folders */
var pubStore = container.getHierarchyStore().getPublicStore();
if(typeof pubStore !== "undefined") {
if (typeof pubStore !== "undefined") {
try {
var pubFolder = pubStore.getDefaultFolder("publicfolders");
var pubSubFolders = pubFolder.getChildren();
for(i = 0; i < pubSubFolders.length; i++) {
if(pubSubFolders[i].isContainerClass("IPF.Contact")){
for (i = 0; i < pubSubFolders.length; i++) {
if (pubSubFolders[i].isContainerClass("IPF.Contact")) {
myStore.push([pubSubFolders[i].getDisplayName(), pubSubFolders[i].getDisplayName() + " [Shared]", true]); // 3rd field = isPublicfolder
}
}
@@ -216,128 +216,128 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
console.log(e);
}
}
return {
xtype: "selectbox",
ref: 'addressbookSelector',
editable: false,
name: "choosen_addressbook",
value: container.getSettingsModel().get("zarafa/v1/plugins/contactimporter/default_addressbook"),
width: 100,
fieldLabel: "Select an addressbook",
store: myStore,
mode: 'local',
xtype : "selectbox",
ref : 'addressbookSelector',
editable : false,
name : "choosen_addressbook",
value : container.getSettingsModel().get("zarafa/v1/plugins/contactimporter/default_addressbook"),
width : 100,
fieldLabel : "Select an addressbook",
store : myStore,
mode : 'local',
labelSeperator: ":",
border: false,
anchor: "100%",
scope: this,
allowBlank: false
border : false,
anchor : "100%",
scope : this,
allowBlank : false
}
},
createUploadField: function() {
createUploadField: function () {
return {
xtype: "fileuploadfield",
ref: 'contactfileuploadfield',
xtype : "fileuploadfield",
ref : 'contactfileuploadfield',
columnWidth: 1.0,
id: 'form-file',
name: 'vcfdata',
emptyText: 'Select an .vcf addressbook',
border: false,
anchor: "100%",
scope: this,
allowBlank: false,
listeners: {
id : 'form-file',
name : 'vcfdata',
emptyText : 'Select an .vcf addressbook',
border : false,
anchor : "100%",
scope : this,
allowBlank : false,
listeners : {
'fileselected': this.onFileSelected,
scope: this
scope : this
}
}
},
createSubmitButton: function() {
createSubmitButton: function () {
return {
xtype: "button",
ref: "../submitButton",
disabled: true,
width: 100,
border: false,
text: _("Import"),
anchor: "100%",
handler: this.importCheckedContacts,
scope: this,
xtype : "button",
ref : "../submitButton",
disabled : true,
width : 100,
border : false,
text : _("Import"),
anchor : "100%",
handler : this.importCheckedContacts,
scope : this,
allowBlank: false
}
},
createSubmitAllButton: function() {
createSubmitAllButton: function () {
return {
xtype: "button",
ref: "../submitAllButton",
disabled: true,
width: 100,
border: false,
text: _("Import All"),
anchor: "100%",
handler: this.importAllContacts,
scope: this,
xtype : "button",
ref : "../submitAllButton",
disabled : true,
width : 100,
border : false,
text : _("Import All"),
anchor : "100%",
handler : this.importAllContacts,
scope : this,
allowBlank: false
}
},
createCancelButton: function() {
createCancelButton: function () {
return {
xtype: "button",
width: 100,
border: false,
text: _("Cancel"),
anchor: "100%",
handler: this.close,
scope: this,
xtype : "button",
width : 100,
border : false,
text : _("Cancel"),
anchor : "100%",
handler : this.close,
scope : this,
allowBlank: false
}
},
/**
* This is called when a file has been seleceted in the file dialog
* in the {@link Ext.ux.form.FileUploadField} and the dialog is closed
* @param {Ext.ux.form.FileUploadField} uploadField being added a file to
*/
onFileSelected : function(uploadField) {
onFileSelected: function (uploadField) {
var form = this.addContactFormPanel.getForm();
if (form.isValid()) {
form.submit({
waitMsg: 'Uploading and parsing contacts...',
url: 'plugins/contactimporter/php/upload.php',
failure: function(file, action) {
url : 'plugins/contactimporter/php/upload.php',
failure: function (file, action) {
this.submitButton.disable();
this.submitAllButton.disable();
Zarafa.common.dialogs.MessageBox.show({
title : _('Error'),
msg : _(action.result.error),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons : Zarafa.common.dialogs.MessageBox.OK
title : _('Error'),
msg : _(action.result.error),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
},
success: function(file, action){
success: function (file, action) {
uploadField.reset();
this.vcffile = action.result.vcf_file;
this.parseContacts(this.vcffile);
},
scope : this
scope : this
});
}
},
parseContacts: function (vcfPath) {
this.loadMask.show();
// call export function here!
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
successCallback: this.handleParsingResult.createDelegate(this)
});
container.getRequest().singleRequest(
'contactmodule',
'load',
@@ -347,23 +347,23 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
responseHandler
);
},
handleParsingResult: function(response) {
handleParsingResult: function (response) {
this.loadMask.hide();
if(response["status"] == true) {
if (response["status"] == true) {
this.submitButton.enable();
this.submitAllButton.enable();
this.reloadGridStore(response.parsed);
} else {
this.submitButton.disable();
this.submitAllButton.disable();
Zarafa.common.dialogs.MessageBox.show({
title : _('Parser Error'),
msg : _(response["message"]),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons : Zarafa.common.dialogs.MessageBox.OK
title : _('Parser Error'),
msg : _(response["message"]),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
}
},
@@ -376,117 +376,117 @@ Zarafa.plugins.contactimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
importCheckedContacts: function () {
var newRecords = this.contactGrid.selModel.getSelections();
this.importContacts(newRecords);
},
},
importAllContacts: function () {
//receive Records from grid rows
this.contactGrid.selModel.selectAll(); // select all entries
var newRecords = this.contactGrid.selModel.getSelections();
this.importContacts(newRecords);
},
/**
* This function stores all given events to the appointmentstore
},
/**
* This function stores all given events to the appointmentstore
* @param events
*/
importContacts: function (contacts) {
//receive existing contact store
var folderValue = this.addressbookSelector.getValue();
if(folderValue == undefined) { // no addressbook choosen
if (folderValue == undefined) { // no addressbook choosen
Zarafa.common.dialogs.MessageBox.show({
title : _('Error'),
msg : _('You have to choose an addressbook!'),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons : Zarafa.common.dialogs.MessageBox.OK
title : _('Error'),
msg : _('You have to choose an addressbook!'),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
} else {
var addressbookexist = true;
if(this.contactGrid.selModel.getCount() < 1) {
if (this.contactGrid.selModel.getCount() < 1) {
Zarafa.common.dialogs.MessageBox.show({
title : _('Error'),
msg : _('You have to choose at least one contact to import!'),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons : Zarafa.common.dialogs.MessageBox.OK
title : _('Error'),
msg : _('You have to choose at least one contact to import!'),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
} else {
var contactStore = new Zarafa.contact.ContactStore();
var contactFolder = container.getHierarchyStore().getDefaultFolder('contact');
var contactFolder = container.getHierarchyStore().getDefaultFolder('contact');
var pubStore = container.getHierarchyStore().getPublicStore();
var pubFolder = pubStore.getDefaultFolder("publicfolders");
var pubSubFolders = pubFolder.getChildren();
if(folderValue != "contact") {
if (folderValue != "contact") {
var subFolders = contactFolder.getChildren();
var i = 0;
for(i = 0; i < pubSubFolders.length; i++) {
if(pubSubFolders[i].isContainerClass("IPF.Contact")){
for (i = 0; i < pubSubFolders.length; i++) {
if (pubSubFolders[i].isContainerClass("IPF.Contact")) {
subFolders.push(pubSubFolders[i]);
}
}
for(i=0;i<subFolders.length;i++) {
for (i = 0; i < subFolders.length; i++) {
// look up right folder
// TODO: improve!!
if(subFolders[i].getDisplayName() == folderValue) {
if (subFolders[i].getDisplayName() == folderValue) {
contactFolder = subFolders[i];
break;
}
}
if(contactFolder.isDefaultFolder()) {
if (contactFolder.isDefaultFolder()) {
Zarafa.common.dialogs.MessageBox.show({
title : _('Error'),
msg : _('Selected addressbook does not exist!'),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons : Zarafa.common.dialogs.MessageBox.OK
title : _('Error'),
msg : _('Selected addressbook does not exist!'),
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
addressbookexist = false;
}
}
if(addressbookexist) {
if (addressbookexist) {
this.loadMask.show();
var uids = [];
var store_entryid = "";
//receive Records from grid rows
Ext.each(contacts, function(newRecord) {
uids.push(newRecord.data.record.internal_fields.contact_uid);
Ext.each(contacts, function (newRecord) {
uids.push(newRecord.data.record.internal_fields.contact_uid);
}, this);
store_entryid = contactFolder.get('store_entryid');
var responseHandler = new Zarafa.plugins.contactimporter.data.ResponseHandler({
successCallback: this.importContactsDone.createDelegate(this)
});
container.getRequest().singleRequest(
'contactmodule',
'import',
{
storeid: contactFolder.get("store_entryid"),
folderid: contactFolder.get("entryid"),
uids: uids,
storeid : contactFolder.get("store_entryid"),
folderid : contactFolder.get("entryid"),
uids : uids,
vcf_filepath: this.vcffile
},
responseHandler
);
}
}
}
},
importContactsDone : function (response) {
importContactsDone: function (response) {
this.loadMask.hide();
this.dialog.close();
if(response.status == true) {
if (response.status == true) {
container.getNotifier().notify('info', 'Imported', 'Imported ' + response.count + ' contacts. Please reload your addressbook!');
} else {
Zarafa.common.dialogs.MessageBox.show({
title : _('Error'),
msg : _('Import failed: ') + response.message,
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons : Zarafa.common.dialogs.MessageBox.OK
title : _('Error'),
msg : _('Import failed: ') + response.message,
icon : Zarafa.common.dialogs.MessageBox.ERROR,
buttons: Zarafa.common.dialogs.MessageBox.OK
});
}
}