+
@@ -366,14 +368,6 @@
-
-
-
-
-
-
-
-
@@ -382,16 +376,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -402,14 +386,6 @@
-
-
-
-
-
-
-
-
@@ -420,16 +396,91 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/js/data/Actions.js b/js/data/Actions.js
index 513f9a4..68d6e5a 100644
--- a/js/data/Actions.js
+++ b/js/data/Actions.js
@@ -61,5 +61,118 @@ Zarafa.plugins.calendarimporter.data.Actions = {
downloadFrame.dom.contentWindow.location = link;
}
+ },
+
+ /**
+ * Get all calendar folders.
+ * @param {boolean} asDropdownStore If true, a simple array store will be returned.
+ * @returns {*}
+ */
+ getAllCalendarFolders: function (asDropdownStore) {
+ asDropdownStore = Ext.isEmpty(asDropdownStore) ? false : asDropdownStore;
+
+ var allFolders = [];
+
+ var inbox = container.getHierarchyStore().getDefaultStore();
+ var pub = container.getHierarchyStore().getPublicStore();
+
+ if (!Ext.isEmpty(inbox.subStores) && inbox.subStores.folders.totalLength > 0) {
+ for (var i = 0; i < inbox.subStores.folders.totalLength; i++) {
+ var folder = inbox.subStores.folders.getAt(i);
+ if (folder.get("container_class") == "IPF.Appointment") {
+ if (asDropdownStore) {
+ allFolders.push([
+ folder.get("entryid"),
+ folder.get("display_name")
+ ]);
+ } else {
+ allFolders.push({
+ display_name : folder.get("display_name"),
+ entryid : folder.get("entryid"),
+ store_entryid: folder.get("store_entryid"),
+ is_public : false
+ });
+ }
+ }
+ }
+ }
+
+ if (!Ext.isEmpty(pub.subStores) && pub.subStores.folders.totalLength > 0) {
+ for (var j = 0; j < pub.subStores.folders.totalLength; j++) {
+ var folder = pub.subStores.folders.getAt(j);
+ if (folder.get("container_class") == "IPF.Appointment") {
+ if (asDropdownStore) {
+ allFolders.push([
+ folder.get("entryid"),
+ folder.get("display_name") + " (Public)"
+ ]);
+ } else {
+ allFolders.push({
+ display_name : folder.get("display_name"),
+ entryid : folder.get("entryid"),
+ store_entryid: folder.get("store_entryid"),
+ is_public : true
+ });
+ }
+ }
+ }
+ }
+
+ if (asDropdownStore) {
+ return allFolders.sort(Zarafa.plugins.calendarimporter.data.Actions.dynamicSort(1));
+ } else {
+ return allFolders;
+ }
+ },
+
+ /**
+ * Return a calendar folder element by name.
+ * @param {string} name
+ * @returns {*}
+ */
+ getCalendarFolderByName: function (name) {
+ var folders = Zarafa.plugins.calendarimporter.data.Actions.getAllCalendarFolders(false);
+
+ for (var i = 0; i < folders.length; i++) {
+ if (folders[i].display_name == name) {
+ return folders[i];
+ }
+ }
+
+ return container.getHierarchyStore().getDefaultFolder('calendar');
+ },
+
+ /**
+ * Return a calendar folder element by entryid.
+ * @param {string} entryid
+ * @returns {*}
+ */
+ getCalendarFolderByEntryid: function (entryid) {
+ var folders = Zarafa.plugins.calendarimporter.data.Actions.getAllCalendarFolders(false);
+
+ for (var i = 0; i < folders.length; i++) {
+ if (folders[i].entryid == entryid) {
+ return folders[i];
+ }
+ }
+
+ return container.getHierarchyStore().getDefaultFolder('calendar');
+ },
+
+ /**
+ * Dynamic sort function, sorts by property name.
+ * @param {string|int} property
+ * @returns {Function}
+ */
+ dynamicSort: function (property) {
+ var sortOrder = 1;
+ if (property[0] === "-") {
+ sortOrder = -1;
+ property = property.substr(1);
+ }
+ return function (a, b) {
+ var result = (a[property].toLowerCase() < b[property].toLowerCase()) ? -1 : (a[property].toLowerCase() > b[property].toLowerCase()) ? 1 : 0;
+ return result * sortOrder;
+ }
}
};
\ No newline at end of file
diff --git a/js/dialogs/ImportPanel.js b/js/dialogs/ImportPanel.js
index a4f6684..abdc201 100644
--- a/js/dialogs/ImportPanel.js
+++ b/js/dialogs/ImportPanel.js
@@ -158,119 +158,6 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
};
},
- /**
- * Get all calendar folders.
- * @param {boolean} asDropdownStore If true, a simple array store will be returned.
- * @returns {*}
- */
- getAllCalendarFolders: function (asDropdownStore) {
- asDropdownStore = Ext.isEmpty(asDropdownStore) ? false : asDropdownStore;
-
- var allFolders = [];
-
- var inbox = container.getHierarchyStore().getDefaultStore();
- var pub = container.getHierarchyStore().getPublicStore();
-
- if (!Ext.isEmpty(inbox.subStores) && inbox.subStores.folders.totalLength > 0) {
- for (var i = 0; i < inbox.subStores.folders.totalLength; i++) {
- var folder = inbox.subStores.folders.getAt(i);
- if (folder.get("container_class") == "IPF.Appointment") {
- if (asDropdownStore) {
- allFolders.push([
- folder.get("entryid"),
- folder.get("display_name")
- ]);
- } else {
- allFolders.push({
- display_name : folder.get("display_name"),
- entryid : folder.get("entryid"),
- store_entryid: folder.get("store_entryid"),
- is_public : false
- });
- }
- }
- }
- }
-
- if (!Ext.isEmpty(pub.subStores) && pub.subStores.folders.totalLength > 0) {
- for (var j = 0; j < pub.subStores.folders.totalLength; j++) {
- var folder = pub.subStores.folders.getAt(j);
- if (folder.get("container_class") == "IPF.Appointment") {
- if (asDropdownStore) {
- allFolders.push([
- folder.get("entryid"),
- folder.get("display_name") + " (Public)"
- ]);
- } else {
- allFolders.push({
- display_name : folder.get("display_name"),
- entryid : folder.get("entryid"),
- store_entryid: folder.get("store_entryid"),
- is_public : true
- });
- }
- }
- }
- }
-
- if (asDropdownStore) {
- return allFolders.sort(this.dynamicSort(1));
- } else {
- return allFolders;
- }
- },
-
- /**
- * Dynamic sort function, sorts by property name.
- * @param {string|int} property
- * @returns {Function}
- */
- dynamicSort: function (property) {
- var sortOrder = 1;
- if (property[0] === "-") {
- sortOrder = -1;
- property = property.substr(1);
- }
- return function (a, b) {
- var result = (a[property].toLowerCase() < b[property].toLowerCase()) ? -1 : (a[property].toLowerCase() > b[property].toLowerCase()) ? 1 : 0;
- return result * sortOrder;
- }
- },
-
- /**
- * Return a calendar folder element by name.
- * @param {string} name
- * @returns {*}
- */
- getCalendarFolderByName: function (name) {
- var folders = this.getAllCalendarFolders(false);
-
- for (var i = 0; i < folders.length; i++) {
- if (folders[i].display_name == name) {
- return folders[i];
- }
- }
-
- return container.getHierarchyStore().getDefaultFolder('calendar');
- },
-
- /**
- * Return a calendar folder element by entryid.
- * @param {string} entryid
- * @returns {*}
- */
- getCalendarFolderByEntryid: function (entryid) {
- var folders = this.getAllCalendarFolders(false);
-
- for (var i = 0; i < folders.length; i++) {
- if (folders[i].entryid == entryid) {
- return folders[i];
- }
- }
-
- return container.getHierarchyStore().getDefaultFolder('calendar');
- },
-
/**
* Reloads the data of the grid
* @private
@@ -349,14 +236,14 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
},
createSelectBox: function() {
- var myStore = this.getAllCalendarFolders(true);
+ var myStore = Zarafa.plugins.calendarimporter.data.Actions.getAllCalendarFolders(true);
return {
xtype: "selectbox",
ref: 'calendarselector',
editable: false,
name: "choosen_calendar",
- value: Ext.isEmpty(this.folder) ? this.getCalendarFolderByName(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_calendar")).entryid : this.folder,
+ value: Ext.isEmpty(this.folder) ? Zarafa.plugins.calendarimporter.data.Actions.getCalendarFolderByName(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_calendar")).entryid : this.folder,
width: 100,
fieldLabel: "Select folder",
store: myStore,
@@ -620,7 +507,7 @@ Zarafa.plugins.calendarimporter.dialogs.ImportPanel = Ext.extend(Ext.Panel, {
buttons : Zarafa.common.dialogs.MessageBox.OK
});
} else {
- var calendarFolder = this.getCalendarFolderByEntryid(calValue);
+ var calendarFolder = Zarafa.plugins.calendarimporter.data.Actions.getCalendarFolderByEntryid(calValue);
this.loadMask.show();
var uids = [];
diff --git a/js/settings/SettingsWidget.js b/js/settings/SettingsWidget.js
index 6d3c034..784c357 100644
--- a/js/settings/SettingsWidget.js
+++ b/js/settings/SettingsWidget.js
@@ -40,43 +40,14 @@ Zarafa.plugins.calendarimporter.settings.SettingsWidget = Ext.extend(Zarafa.sett
},
createSelectBox: function() {
- var defaultFolder = container.getHierarchyStore().getDefaultFolder('calendar'); // @type: Zarafa.hierarchy.data.MAPIFolderRecord
- var subFolders = defaultFolder.getChildren();
- var myStore = [];
-
- /* add all local calendar folders */
- var i = 0;
- myStore.push(new Array(defaultFolder.getDefaultFolderKey(), defaultFolder.getDisplayName()));
- for(i = 0; i < subFolders.length; i++) {
- /* Store all subfolders */
- myStore.push(new Array(subFolders[i].getDisplayName(), subFolders[i].getDisplayName(), false)); // 3rd field = isPublicfolder
- }
-
- /* add all shared calendar folders */
- var pubStore = container.getHierarchyStore().getPublicStore();
-
- 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.Appointment")){
- myStore.push(new Array(pubSubFolders[i].getDisplayName(), pubSubFolders[i].getDisplayName() + " [Shared]", true)); // 3rd field = isPublicfolder
- }
- }
- } catch (e) {
- console.log("Error opening the shared folder...");
- console.log(e);
- }
- }
-
+ var myStore = Zarafa.plugins.calendarimporter.data.Actions.getAllCalendarFolders(true);
+
return {
xtype: "selectbox",
ref : 'defaultCalendar',
editable: false,
name: "zarafa/v1/plugins/calendarimporter/default_calendar",
- value: container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_calendar"),
+ value: Zarafa.plugins.calendarimporter.data.Actions.getCalendarFolderByName(container.getSettingsModel().get("zarafa/v1/plugins/calendarimporter/default_calendar")).entryid,
width: 100,
fieldLabel: "Default calender",
store: myStore,
@@ -128,10 +99,115 @@ Zarafa.plugins.calendarimporter.settings.SettingsWidget = Ext.extend(Zarafa.sett
* @param {Zarafa.settings.SettingsModel} settingsModel The settings to update
*/
updateSettings : function(settingsModel) {
- settingsModel.set(this.enableSync.name, this.enableSync.getValue());
- settingsModel.set(this.defaultCalendar.name, this.defaultCalendar.getValue());
- settingsModel.set(this.defaultTimezone.name, this.defaultTimezone.getValue());
- }
+ // check if the user changed a value
+ var changed = false;
+
+ if(settingsModel.get(this.enableSync.name) != this.enableSync.getValue()) {
+ changed = true;
+ } else if(settingsModel.get(this.defaultCalendar.name) != this.defaultCalendar.getValue()) {
+ changed = true;
+ } else if(settingsModel.get(this.defaultTimezone.name) != this.defaultTimezone.getValue()) {
+ changed = true;
+ }
+
+ if(changed) {
+ // Really save changes
+ settingsModel.set(this.enableSync.name, this.enableSync.getValue());
+ settingsModel.set(this.defaultCalendar.name, this.defaultCalendar.getValue());
+ settingsModel.set(this.defaultTimezone.name, this.defaultTimezone.getValue());
+
+ this.onUpdateSettings();
+ }
+ },
+
+ /**
+ * Called after the {@link Zarafa.settings.SettingsModel} fires the {@link Zarafa.settings.SettingsModel#save save}
+ * event to indicate the settings were successfully saved and it will forcefully realod the webapp.
+ * settings which were saved to the server.
+ * @private
+ */
+ onUpdateSettings : function()
+ {
+ var message = _('Your WebApp needs to be reloaded to make the changes visible!');
+ message += '
';
+ message += _('WebApp will automatically restart in order for these changes to take effect');
+ message += ' ';
+
+ Zarafa.common.dialogs.MessageBox.addCustomButtons({
+ title: _('Restart WebApp'),
+ msg : message,
+ icon: Ext.MessageBox.QUESTION,
+ fn : this.restartWebapp,
+ customButton : [{
+ text : _('Restart'),
+ name : 'restart'
+ }, {
+ text : _('Cancel'),
+ name : 'cancel'
+ }],
+ scope : this
+ });
+
+ },
+
+ /**
+ * Event handler for {@link #onResetSettings}. This will check if the user
+ * wishes to reset the default settings or not.
+ * @param {String} button The button which user pressed.
+ * @private
+ */
+ restartWebapp : function(button)
+ {
+ if (button === 'restart') {
+ var contextModel = this.ownerCt.settingsContext.getModel();
+ var realModel = contextModel.getRealSettingsModel();
+
+ realModel.save();
+
+ this.loadMask = new Zarafa.common.ui.LoadMask(Ext.getBody(), {
+ msg : '' + _('Webapp is reloading, Please wait.') + ''
+ });
+ this.loadMask.show();
+
+ this.mon(realModel, 'save', this.onSettingsSave, this);
+ this.mon(realModel, 'exception', this.onSettingsException, this);
+ }
+
+ },
+
+ /**
+ * Called when the {@link Zarafa.settings.} fires the {@link Zarafa.settings.SettingsModel#save save}
+ * event to indicate the settings were successfully saved and it will forcefully realod the webapp.
+ * @param {Zarafa.settings.SettingsModel} model The model which fired the event.
+ * @param {Object} parameters The key-value object containing the action and the corresponding
+ * settings which were saved to the server.
+ * @private
+ */
+ onSettingsSave : function(model, parameters)
+ {
+ this.mun(model, 'save', this.onSettingsSave, this);
+ Zarafa.core.Util.reloadWebapp();
+ },
+
+ /**
+ * Called when the {@link Zarafa.settings.SettingsModel} fires the {@link Zarafa.settings.SettingsModel#exception exception}
+ * event to indicate the settings were not successfully saved.
+ * @param {Zarafa.settings.SettingsModel} model The settings model which fired the event
+ * @param {String} type The value of this parameter will be either 'response' or 'remote'.
+ * @param {String} action Name of the action (see {@link Ext.data.Api#actions}).
+ * @param {Object} options The object containing a 'path' and 'value' field indicating
+ * respectively the Setting and corresponding value for the setting which was being saved.
+ * @param {Object} response The response object as received from the PHP-side
+ * @private
+ */
+ onSettingsException : function(model, type, action, options, response)
+ {
+ this.loadMask.hide();
+
+ // Remove event handlers
+ this.mun(model, 'save', this.onSettingsSave, this);
+ this.mun(model, 'exception', this.onSettingsException, this);
+ }
});
Ext.reg('calendarimporter.settingswidget', Zarafa.plugins.calendarimporter.settings.SettingsWidget);