Ext.namespace("Zarafa.plugins.calendarimporter.dialogs"); /** * @class Zarafa.plugins.calendarimporter.dialogs.ImportPanel * @extends Ext.form.FormPanel */ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, { /* store the imported timezone here... */ timezone: null, /** * @constructor * @param {object} config */ constructor : function (config) { config = config || {}; var self = this; Ext.apply(config, { xtype : 'calendarimporter.importpanel', 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;' }, items : [ this.createSelectBox(), this.initForm() ], buttons: [ this.createExportAllButton(), this.createSubmitAllButton(), this.createSubmitButton(), this.createCancelButton() ] }); Zarafa.plugins.calendarimporter.dialogs.ImportPanel.superclass.constructor.call(this, config); }, /** * Init embedded form, this is the form that is * posted and contains the attachments * @private */ initForm : function () { return { xtype: 'form', ref: 'addFormPanel', layout : 'column', fileUpload: true, autoWidth: true, autoHeight: true, border: false, bodyStyle: 'padding: 5px;', defaults: { anchor: '95%', border: false, bodyStyle: 'padding: 5px;' }, items: [this.createUploadField()] }; }, /** * Init embedded form, this is the form that is * posted and contains the attachments * @private */ createGrid : function(eventdata) { var parsedData = []; if(eventdata !== null) { var parsedData = new Array(eventdata.events.length); for(var i=0; i < eventdata.events.length; i++) { parsedData[i] = new Array(eventdata.events[i]["SUMMARY"], new Date(parseInt(eventdata.events[i]["DTSTART"])), new Date(parseInt(eventdata.events[i]["DTEND"])), eventdata.events[i]["LOCATION"], eventdata.events[i]["DESCRIPTION"]); } } // create the data store var store = new Ext.data.ArrayStore({ fields: [ {name: 'title'}, {name: 'start'}, {name: 'end'}, {name: 'location'}, {name: 'description'} ], data: parsedData }); return { xtype: 'grid', ref: 'eventgrid', id: 'eventgrid', columnWidth: 1.0, store: store, width: '100%', height: 300, title: 'Select events to import', frame: true, colModel: new Ext.grid.ColumnModel({ defaults: { width: 300, sortable: true }, columns: [ {id: 'Summary', header: 'Title', width: 300, sortable: true, dataIndex: 'title'}, {header: 'Start', width: 150, sortable: true, dataIndex: 'start'}, {header: 'End', width: 150, sortable: true, dataIndex: 'end'}, {header: 'Location', width: 150, sortable: true, dataIndex: 'location'}, {header: 'Description', width: 150, sortable: true, dataIndex: 'description'} ] }), sm: new Ext.grid.RowSelectionModel({multiSelect:true}) } }, createSelectBox: function() { ctx = container.getContextByName('calendar'); model = ctx.getModel(); defaultFolder = model.getDefaultFolder(); // @type: Zarafa.hierarchy.data.MAPIFolderRecord subFolders = defaultFolder.getChildren(); var myStore = new Ext.data.ArrayStore({ fields: ['calendar_id', 'calendar_displayname'], idIndex: 0 // id for each record will be the first element }); /* Calendar Record holds the name and real name of the calender */ var CalendarRecord = Ext.data.Record.create([ {name: 'realname', type: "string"}, {name: 'displayname', type: "string"} ]); /* Store the default folder */ var myNewRecord = new CalendarRecord({ realname: defaultFolder.getDefaultFolderKey(), displayname: defaultFolder.getDisplayName() }); myStore.add(myNewRecord); for(i=0;i 0) { // call export function here! var responseHandler = new Zarafa.plugins.calendarimporter.data.ResponseHandler({ successCallback: this.downLoadICS.createDelegate(this) }); container.getRequest().singleRequest( 'calendarexportermodule', 'export', { data: response, calendar: this.calendarselector.value }, responseHandler ); container.getNotifier().notify('info', 'Exported', 'Found ' + response.item.length + ' entries to export.'); } else { container.getNotifier().notify('info', 'Export Failed', 'There were no items to export!'); Zarafa.common.dialogs.MessageBox.hide(); } this.dialog.close(); }, /** * download ics file =) * @param {Object} response * @private */ downLoadICS : function(response) { Zarafa.common.dialogs.MessageBox.hide(); if(response.status === true) { // needs to be window.open, document.location.href kills the extjs response handler... window.open('plugins/calendarimporter/php/download.php?fileid='+response.fileid+'&basedir='+response.basedir+'&secid='+response.secid+'&realname='+response.realname,"Download"); } else { container.getNotifier().notify('error', 'Export Failed', 'ICal File creation failed!'); } }, importCheckedEvents: function () { //receive existing calendar store var selIndex = this.calendarselector.selectedIndex; var calValue = this.calendarselector.value; if(selIndex == -1) { // no calendar choosen Ext.MessageBox.show({ title : _('Error'), msg : _('You have to choose a calendar!'), icon : Ext.MessageBox.ERROR, buttons : Ext.MessageBox.OK }); } else { if(this.eventgrid.selModel.getCount() < 1) { Ext.MessageBox.show({ title : _('Error'), msg : _('You have to choose at least one event to import!'), icon : Ext.MessageBox.ERROR, buttons : Ext.MessageBox.OK }); } else { var calendarStore = new Zarafa.calendar.AppointmentStore(); var calendarFolder = container.getHierarchyStore().getDefaultFolder('calendar'); if(calValue != "calendar") { var subFolders = calendarFolder.getChildren(); for(i=0;i