2016-11-29 19:58:23 +01:00
/ * *
* SettingsWidget . js , Kopano calender to ics im / exporter
*
* Author : Christoph Haas < christoph . h @ sprinternet . at >
* 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
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* 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
*
* /
2014-05-01 15:28:51 +02:00
Ext . namespace ( 'Zarafa.plugins.calendarimporter.settings' ) ;
/ * *
* @ class Zarafa . plugins . calendarimporter . settings . SettingsWidget
* @ extends Zarafa . settings . ui . SettingsWidget
* @ xtype calendarimporter . settingswidget
*
* /
Zarafa . plugins . calendarimporter . settings . SettingsWidget = Ext . extend ( Zarafa . settings . ui . SettingsWidget , {
2016-11-29 19:58:23 +01:00
/ * *
* @ cfg { Zarafa . settings . SettingsContext } settingsContext
* /
settingsContext : undefined ,
/ * *
* @ constructor
* @ param { Object } config Configuration object
* /
constructor : function ( config ) {
config = config || { } ;
Ext . applyIf ( config , {
title : dgettext ( 'plugin_calendarimporter' , 'Calendar Import/Export plugin settings' ) ,
xtype : 'calendarimporter.settingswidget' ,
items : [
{
xtype : 'checkbox' ,
name : 'zarafa/v1/plugins/calendarimporter/enable_sync' ,
ref : 'enableSync' ,
fieldLabel : dgettext ( 'plugin_calendarimporter' , 'Enable ical sync' ) ,
lazyInit : false
} ,
this . createSelectBox ( ) ,
this . createTimezoneBox ( )
]
} ) ;
Zarafa . plugins . calendarimporter . settings . SettingsWidget . superclass . constructor . call ( this , config ) ;
} ,
createSelectBox : function ( ) {
var myStore = Zarafa . plugins . calendarimporter . data . Actions . getAllCalendarFolders ( true ) ;
return {
xtype : "selectbox" ,
ref : 'defaultCalendar' ,
editable : false ,
name : "zarafa/v1/plugins/calendarimporter/default_calendar" ,
2016-10-31 23:42:42 +01:00
value : Zarafa . plugins . calendarimporter . data . Actions . getCalendarFolderByName ( container . getSettingsModel ( ) . get ( "zarafa/v1/plugins/calendarimporter/default_calendar" ) ) . entryid ,
2016-11-29 19:58:23 +01:00
width : 100 ,
fieldLabel : dgettext ( 'plugin_calendarimporter' , 'Default calender' ) ,
store : myStore ,
mode : 'local' ,
labelSeperator : ":" ,
border : false ,
anchor : "100%" ,
scope : this ,
allowBlank : false
}
} ,
createTimezoneBox : function ( ) {
return {
xtype : "selectbox" ,
ref : 'defaultTimezone' ,
editable : false ,
name : "zarafa/v1/plugins/calendarimporter/default_timezone" ,
value : Zarafa . plugins . calendarimporter . data . Timezones . unMap ( container . getSettingsModel ( ) . get ( "zarafa/v1/plugins/calendarimporter/default_timezone" ) ) ,
width : 100 ,
fieldLabel : dgettext ( 'plugin_calendarimporter' , 'Default timezone' ) ,
store : Zarafa . plugins . calendarimporter . data . Timezones . store ,
labelSeperator : ":" ,
mode : 'local' ,
border : false ,
anchor : "100%" ,
scope : this ,
allowBlank : false
}
} ,
/ * *
* Called by the { @ link Zarafa . settings . ui . SettingsCategory Category } when
* it has been called with { @ link zarafa . settings . ui . SettingsCategory # update } .
* This is used to load the latest version of the settings from the
* { @ link Zarafa . settings . SettingsModel } into the UI of this category .
* @ param { Zarafa . settings . SettingsModel } settingsModel The settings to load
* /
update : function ( settingsModel ) {
this . enableSync . setValue ( settingsModel . get ( this . enableSync . name ) ) ;
this . defaultCalendar . setValue ( Zarafa . plugins . calendarimporter . data . Actions . getCalendarFolderByName ( settingsModel . get ( this . defaultCalendar . name ) ) . entryid ) ;
this . defaultTimezone . setValue ( settingsModel . get ( this . defaultTimezone . name ) ) ;
} ,
/ * *
* Called by the { @ link Zarafa . settings . ui . SettingsCategory Category } when
* it has been called with { @ link zarafa . settings . ui . SettingsCategory # updateSettings } .
* This is used to update the settings from the UI into the { @ link Zarafa . settings . SettingsModel settings model } .
* @ param { Zarafa . settings . SettingsModel } settingsModel The settings to update
* /
updateSettings : function ( settingsModel ) {
2016-10-31 23:42:42 +01:00
// check if the user changed a value
var changed = false ;
2016-11-29 19:58:23 +01:00
if ( settingsModel . get ( this . enableSync . name ) != this . enableSync . getValue ( ) ) {
2016-10-31 23:42:42 +01:00
changed = true ;
2016-11-29 19:58:23 +01:00
} else if ( settingsModel . get ( this . defaultCalendar . name ) != Zarafa . plugins . calendarimporter . data . Actions . getCalendarFolderByEntryid ( this . defaultCalendar . getValue ( ) ) . display _name ) {
2016-10-31 23:42:42 +01:00
changed = true ;
2016-11-29 19:58:23 +01:00
} else if ( settingsModel . get ( this . defaultTimezone . name ) != this . defaultTimezone . getValue ( ) ) {
2016-10-31 23:42:42 +01:00
changed = true ;
}
2016-11-29 19:58:23 +01:00
if ( changed ) {
2016-10-31 23:42:42 +01:00
// Really save changes
settingsModel . set ( this . enableSync . name , this . enableSync . getValue ( ) ) ;
2016-11-01 00:34:32 +01:00
settingsModel . set ( this . defaultCalendar . name , Zarafa . plugins . calendarimporter . data . Actions . getCalendarFolderByEntryid ( this . defaultCalendar . getValue ( ) ) . display _name ) ; // store name
2016-10-31 23:42:42 +01:00
settingsModel . set ( this . defaultTimezone . name , this . defaultTimezone . getValue ( ) ) ;
this . onUpdateSettings ( ) ;
}
2016-11-29 19:58:23 +01:00
} ,
2016-10-31 23:42:42 +01:00
/ * *
* 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
* /
2016-11-29 19:58:23 +01:00
onUpdateSettings : function ( ) {
2016-10-31 23:42:42 +01:00
var message = _ ( 'Your WebApp needs to be reloaded to make the changes visible!' ) ;
message += '<br/><br/>' ;
message += _ ( 'WebApp will automatically restart in order for these changes to take effect' ) ;
message += '<br/>' ;
Zarafa . common . dialogs . MessageBox . addCustomButtons ( {
title : _ ( 'Restart WebApp' ) ,
2016-11-29 19:58:23 +01:00
msg : message ,
2016-10-31 23:42:42 +01:00
icon : Ext . MessageBox . QUESTION ,
2016-11-29 19:58:23 +01:00
fn : this . restartWebapp ,
customButton : [ {
text : _ ( 'Restart' ) ,
name : 'restart'
2016-10-31 23:42:42 +01:00
} , {
2016-11-29 19:58:23 +01:00
text : _ ( 'Cancel' ) ,
name : 'cancel'
2016-10-31 23:42:42 +01:00
} ] ,
2016-11-29 19:58:23 +01:00
scope : this
2016-10-31 23:42:42 +01:00
} ) ;
} ,
/ * *
* 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
* /
2016-11-29 19:58:23 +01:00
restartWebapp : function ( button ) {
2016-10-31 23:42:42 +01:00
if ( button === 'restart' ) {
var contextModel = this . ownerCt . settingsContext . getModel ( ) ;
var realModel = contextModel . getRealSettingsModel ( ) ;
realModel . save ( ) ;
this . loadMask = new Zarafa . common . ui . LoadMask ( Ext . getBody ( ) , {
2016-11-29 19:58:23 +01:00
msg : '<b>' + _ ( 'Webapp is reloading, Please wait.' ) + '</b>'
2016-10-31 23:42:42 +01:00
} ) ;
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
* /
2016-11-29 19:58:23 +01:00
onSettingsSave : function ( model , parameters ) {
2016-10-31 23:42:42 +01:00
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
* /
2016-11-29 19:58:23 +01:00
onSettingsException : function ( model , type , action , options , response ) {
2016-10-31 23:42:42 +01:00
this . loadMask . hide ( ) ;
// Remove event handlers
this . mun ( model , 'save' , this . onSettingsSave , this ) ;
this . mun ( model , 'exception' , this . onSettingsException , this ) ;
}
2014-05-01 15:28:51 +02:00
} ) ;
Ext . reg ( 'calendarimporter.settingswidget' , Zarafa . plugins . calendarimporter . settings . SettingsWidget ) ;