calendarimporter: added exportfeature - not finished yet
TODO: ical creater backend, download
This commit is contained in:
36
js/data/ResponseHandler.js
Normal file
36
js/data/ResponseHandler.js
Normal file
@@ -0,0 +1,36 @@
|
||||
Ext.namespace('Zarafa.plugins.calendarimporter.data');
|
||||
|
||||
/**
|
||||
* @class Zarafa.plugins.calendarimporter.data.ResponseHandler
|
||||
* @extends Zarafa.plugins.calendarimporter.data.AbstractResponseHandler
|
||||
*
|
||||
* Export specific response handler.
|
||||
*/
|
||||
Zarafa.plugins.calendarimporter.data.ResponseHandler = Ext.extend(Zarafa.core.data.AbstractResponseHandler, {
|
||||
/**
|
||||
* @cfg {Function} successCallback The function which
|
||||
* will be called after success request.
|
||||
*/
|
||||
successCallback : null,
|
||||
|
||||
/**
|
||||
* Call the successCallback callback function.
|
||||
* @param {Object} response Object contained the response data.
|
||||
*/
|
||||
doExport : function(response)
|
||||
{
|
||||
this.successCallback(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* In case exception happened on server, server will return
|
||||
* exception response with the code of exception.
|
||||
* @param {Object} response Object contained the response data.
|
||||
*/
|
||||
doError: function(response)
|
||||
{
|
||||
alert("error response code: " + response.error.info.code);
|
||||
}
|
||||
});
|
||||
|
||||
Ext.reg('calendarimporter.calendarexporterresponsehandler', Zarafa.plugins.calendarimporter.data.ResponseHandler);
|
@@ -16,10 +16,15 @@ Zarafa.plugins.calendarimporter.dialogs.ImportContentPanel = Ext.extend(Zarafa.c
|
||||
constructor : function(config)
|
||||
{
|
||||
config = config || {};
|
||||
|
||||
var title = _('Import Calendar File');
|
||||
if(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/enable_export")){
|
||||
title = _('Import/Export Calendar File');
|
||||
}
|
||||
|
||||
Ext.applyIf(config, {
|
||||
layout : 'fit',
|
||||
title : _('Import Calendar File'),
|
||||
title : title,
|
||||
closeOnSave : true,
|
||||
width : 400,
|
||||
height : 300,
|
||||
|
@@ -13,7 +13,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
* @constructor
|
||||
* @param {object} config
|
||||
*/
|
||||
constructor : function(config)
|
||||
constructor : function (config)
|
||||
{
|
||||
config = config || {};
|
||||
var self = this;
|
||||
@@ -34,6 +34,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
this.initForm()
|
||||
],
|
||||
buttons: [
|
||||
this.createExportAllButton(),
|
||||
this.createSubmitAllButton(),
|
||||
this.createSubmitButton(),
|
||||
this.createCancelButton()
|
||||
@@ -48,7 +49,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
* posted and contains the attachments
|
||||
* @private
|
||||
*/
|
||||
initForm : function()
|
||||
initForm : function ()
|
||||
{
|
||||
return {
|
||||
xtype: 'form',
|
||||
@@ -75,10 +76,8 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
*/
|
||||
createGrid : function(eventdata) {
|
||||
|
||||
if(eventdata == null) {
|
||||
var parsedData = [
|
||||
];
|
||||
} else {
|
||||
var parsedData = [];
|
||||
if(eventdata !== null) {
|
||||
var parsedData = new Array(eventdata.events.length);
|
||||
|
||||
for(var i=0; i < eventdata.events.length; i++) {
|
||||
@@ -231,6 +230,22 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
}
|
||||
},
|
||||
|
||||
createExportAllButton: function() {
|
||||
return {
|
||||
xtype: "button",
|
||||
ref: "exportAllButton",
|
||||
id: "exportAllButton",
|
||||
hidden: !container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/enable_export"),
|
||||
width: 100,
|
||||
border: false,
|
||||
text: _("Export All"),
|
||||
anchor: "100%",
|
||||
handler: this.exportAllEvents,
|
||||
scope: this,
|
||||
allowBlank: false
|
||||
}
|
||||
},
|
||||
|
||||
createCancelButton: function() {
|
||||
return {
|
||||
xtype: "button",
|
||||
@@ -345,6 +360,68 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.form.FormPa
|
||||
this.dialog.close();
|
||||
}
|
||||
},
|
||||
|
||||
exportAllEvents: function () {
|
||||
//receive existing calendar store
|
||||
var selIndex = this.calendarselector.selectedIndex;
|
||||
var calValue = this.calendarselector.value;
|
||||
|
||||
if(selIndex == -1 || calValue == "") { // no calendar choosen
|
||||
Ext.MessageBox.show({
|
||||
title : _('Error'),
|
||||
msg : _('You have to choose a calendar!'),
|
||||
icon : Ext.MessageBox.ERROR,
|
||||
buttons : Ext.MessageBox.OK
|
||||
});
|
||||
} else {
|
||||
|
||||
var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar');
|
||||
if(calValue != "calendar") {
|
||||
var subFolders = calendarFolder.getChildren();
|
||||
|
||||
for(i=0;i<subFolders.length;i++) {
|
||||
// loo up right folder
|
||||
// TODO: improve!!
|
||||
if(subFolders[i].getDisplayName() == calValue) {
|
||||
calendarFolder = subFolders[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// call export function here!
|
||||
var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({
|
||||
successCallback: this.exportDone.createDelegate(this)
|
||||
});
|
||||
|
||||
container.getRequest().singleRequest(
|
||||
'calendarexportermodule',
|
||||
'export',
|
||||
{
|
||||
calFolder : calValue,
|
||||
calIndex : selIndex,
|
||||
store_entryid : calendarFolder.data.store_entryid,
|
||||
entryid : calendarFolder.data.entryid
|
||||
},
|
||||
responseHandler
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Export done =)
|
||||
* @param {Object} response
|
||||
* @private
|
||||
*/
|
||||
exportDone : function(response)
|
||||
{
|
||||
if(response.status === true) {
|
||||
container.getNotifier().notify('info', 'Exported', 'Exported ' + response.entries + ' entries');
|
||||
} else {
|
||||
container.getNotifier().notify('error', 'Export Failed', 'Failed to export your calendar');
|
||||
}
|
||||
this.dialog.close();
|
||||
},
|
||||
|
||||
importCheckedEvents: function () {
|
||||
//receive existing calendar store
|
||||
|
@@ -1,6 +1,7 @@
|
||||
Ext.namespace("Zarafa.plugins.calendarimporter"); // Assign the right namespace
|
||||
|
||||
Zarafa.plugins.calendarimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, { // create new import plugin
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {Object} config Configuration object
|
||||
@@ -9,9 +10,7 @@ Zarafa.plugins.calendarimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
|
||||
constructor: function (config) {
|
||||
config = config || {};
|
||||
|
||||
Zarafa.plugins.calendarimporter.ImportPlugin.superclass.constructor.call(this, config);
|
||||
|
||||
|
||||
Zarafa.plugins.calendarimporter.ImportPlugin.superclass.constructor.call(this, config);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -41,7 +40,12 @@ Zarafa.plugins.calendarimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
|
||||
navigationContext : container.getContextByName('calendar'),
|
||||
handler : this.onImportButtonClick,
|
||||
scope : this
|
||||
};
|
||||
|
||||
if(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/enable_export")) {
|
||||
button.text = _('Import/Export Calendar');
|
||||
}
|
||||
|
||||
return button;
|
||||
},
|
||||
|
||||
@@ -101,6 +105,6 @@ Zarafa.plugins.calendarimporter.ImportPlugin = Ext.extend(Zarafa.core.Plugin, {
|
||||
*############################################################################################################################*/
|
||||
Zarafa.onReady(function() {
|
||||
if(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/enable") === true) {
|
||||
container.registerPlugin(new Zarafa.plugins.calendarimporter.ImportPlugin)
|
||||
container.registerPlugin(new Zarafa.plugins.calendarimporter.ImportPlugin);
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user