Ext.namespace("Zarafa.plugins.spellchecker");
Zarafa.plugins.spellchecker.SpellcheckerPlugin=Ext.extend(Zarafa.core.Plugin,{initPlugin:function(){Zarafa.plugins.spellchecker.SpellcheckerPlugin.superclass.initPlugin.apply(this,arguments);this.registerInsertionPoint("context.settings.category.mail.aftercomposesettings",this.createSettingsWidget,this);this.registerInsertionPoint("common.htmleditor.tinymceconfig",this.createTinyMCEConfig,this)},getSupportedLanguages:function(){var a={};container.populateInsertionPoint("plugins.spellchecker.supportedlanguages",{scope:this,
languages:a});return a},getDefaultLanguage:function(){var a=container.getSettingsModel().get("zarafa/v1/plugins/spellchecker/spellchecker_language"),b=this.getUserSelectedLanguages(!0);if(!Ext.isEmpty(a)&&0<=b.indexOf(a))return a;switch(container.getSettingsModel().get("zarafa/v1/main/language").substr(0,2)){case "de":a="de_DE";break;case "fr":a="fr_FR";break;case "it":a="it_IT";break;case "es":a="es_ES";break;case "nl":a="nl_NL";break;case "pt":a="pt_PT";break;case "ru":a="ru_RU";break;default:a=
"en_US"}0>b.indexOf(a)&&(a=0<b.length?b[0]:"");container.getSettingsModel().set("zarafa/v1/plugins/spellchecker/spellchecker_language",a);return a},getUserSelectedLanguages:function(a){var b=this.getSupportedLanguages(),c=container.getSettingsModel().get("zarafa/v1/plugins/spellchecker/spellchecker_languages").split(", "),d=[];Ext.each(c,function(c){b.hasOwnProperty(c)&&(a?d.push(c):d.push(b[c]+"="+c))});d.sort();return d},createTinyMCEConfig:function(a,b){var c=this.getUserSelectedLanguages();0!==
c.length&&(b.config.spellchecker_rpc_url="spellchecker.php",b.config.spellchecker_language=this.getDefaultLanguage(),b.config.spellchecker_languages=c.join(", "),b.config.browser_spellcheck=!1,Ext.isDefined(b.config.external_plugins)||(b.config.external_plugins={}),b.config.external_plugins.spellchecker="../../plugins/spellchecker/tinymce-plugin/spellchecker/plugin.min.js",b.config.toolbar1+=" | spellchecker")},createSettingsWidget:function(){return{xtype:"zarafa.settingshtmleditorwidget"}}});
Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"spellchecker",displayName:dgettext("plugin_spell","Spellchecker"),pluginConstructor:Zarafa.plugins.spellchecker.SpellcheckerPlugin}))});Ext.namespace("Zarafa.plugins.spellchecker.settings");
Zarafa.plugins.spellchecker.settings.SettingsHtmlEditorWidget=Ext.extend(Zarafa.settings.ui.SettingsWidget,{settingsLanguagesName:"zarafa/v1/plugins/spellchecker/spellchecker_languages",settingsDefaultLanguageName:"zarafa/v1/plugins/spellchecker/spellchecker_language",constructor:function(a){a=a||{};var b=container.getPluginByName("spellchecker"),c=b.getSupportedLanguages();Ext.applyIf(a,{title:dgettext("plugin_spell","HTML editor settings"),layout:"form",items:[]});if(0<Object.keys(c).length){var c=
b.getUserSelectedLanguages(),b=b.getDefaultLanguage(),d=[];Ext.each(c,function(a){a=a.split("=");d.push([a[1],a[0]])});var e=new Ext.data.ArrayStore({fields:["code","display"],data:d});a.items=[{xtype:"displayfield",hideLabel:!0,value:dgettext("plugin_spell","Enable the following languages for the spell checker")+':<br><span style="opacity:0.5;">('+dgettext("plugin_spell","Note: When no language is selected, the browsers spell checking features will be used")+")</span>"},{xtype:"checkboxgroup",name:this.settingsLanguagesName,
ref:"spellCheckerLanguagesGroup",columns:1,hideLabel:!0,items:this.createSpellCheckerLanguageOptions(),listeners:{change:this.onSpellCheckerLanguagesChange,scope:this}},{xtype:"combo",name:this.settingsDefaultLanguageName,ref:"spellCheckerDefaultLanguageCombo",fieldLabel:dgettext("plugin_spell","Default selected language"),store:e,displayField:"display",valueField:"code",editable:!1,mode:"local",triggerAction:"all",allowBlank:!0,autoSelect:!0,typeAhead:!1,value:b,disabled:0===c.length?!0:!1,validateOnBlur:!1,
invalidClass:"",listeners:{change:this.onSpellCheckerLanguageChange,scope:this}}]}else a.items=[{xtype:"displayfield",hideLabel:!0,value:dgettext("plugin_spell","No language pack found. Ask your administrator to install language pack plugins to use the spellchecker in the HTML editor.")}];Zarafa.plugins.spellchecker.settings.SettingsHtmlEditorWidget.superclass.constructor.call(this,a)},createSpellCheckerLanguageOptions:function(){var a=container.getPluginByName("spellchecker"),b=a.getSupportedLanguages(),
c=a.getUserSelectedLanguages(!0),d=[];Ext.iterate(b,function(a,b){d.push({xtype:"checkbox",name:"spellCheckerLanguages",inputValue:a,boxLabel:b,checked:0<=c.indexOf(a)?!0:!1})});d.sort(function(a,b){return a.boxLabel<b.boxLabel?-1:1});return d},update:function(a){if(Ext.isDefined(this.spellCheckerLanguagesGroup)){this.model=a;var b=a.get(this.settingsName);Ext.isDefined(b)||(b="");b=b.split(", ");Ext.each(this.spellCheckerLanguagesGroup.items.items,function(a){-1<b.indexOf(a.getRawValue())&&a.setValue(!0)},
this)}},onSpellCheckerLanguagesChange:function(a,b){if(this.model){var c=[];Ext.each(b,function(a){c.push(a.getRawValue())});c.sort();c=c.join(", ");this.model.get(a.name)!==c&&this.model.set(a.name,c)}var d=this.spellCheckerDefaultLanguageCombo.getValue(),e=!1,f=[];Ext.each(b,function(a){f.push([a.getRawValue(),a.boxLabel]);a.getRawValue()===d&&(e=!0)});this.spellCheckerDefaultLanguageCombo.getStore().loadData(f);0===b.length?(this.spellCheckerDefaultLanguageCombo.setValue(""),this.spellCheckerDefaultLanguageCombo.disable()):
(this.spellCheckerDefaultLanguageCombo.enable(),e||this.spellCheckerDefaultLanguageCombo.setValue(b[0].getRawValue()))},onSpellCheckerLanguageChange:function(a,b,c){this.model&&this.model.get(a.name)!==b&&this.model.set(a.name,b)}});Ext.reg("zarafa.settingshtmleditorwidget",Zarafa.plugins.spellchecker.settings.SettingsHtmlEditorWidget);//# sourceMappingURL=spellchecker.js.map
