
Ext.namespace("Ext.ux.application.controllers.partagerWindow");Ext.ux.application.controllers.partagerWindow=Ext.extend(Ext.util.Observable,{constructor:function(config,viewCmp){this.viewCmp=viewCmp;Ext.ux.application.controllers.partagerWindow.superclass.constructor.call(this,config);this.config=config;Ext.Ajax.request({url:URL_BASE+"get/page/partage/ConfigPartager",params:{media:config.media,urlPagePartagee:window.location},success:this.configReceived.createDelegate(this)});},configReceived:function(tsp){this.shareConfig=Ext.util.JSON.decode(tsp.responseText);this.viewCmp.dessineWindow(this.shareConfig);}});Ext.namespace("Ext.ux.application.views.partagerWindow");Ext.ux.application.views.partagerWindow=Ext.extend(Ext.Window,{shadow:false,templateBoutonPartage:new Ext.Template(['<div id="{ID_BOUTON}" class="ux-tool {PREFIXE_CLS}-panel">','<span class="ux-tool-text {PREFIXE_CLS}-text">{TEXTE_BOUTON}</span>','<img height="30" width="32" class="{PREFIXE_CLS}-icon" src="{URL_BASE}/client-libs/extjs/resources/images/default/s.gif"/>','</div>']),templateExportPlayer:new Ext.Template(['<table cellspacing="0" class="ux-partager-export-html">','<tbody>','<tr vertical-align: middle>','<td>','{MEDIA}','</td>','</tr>','</tbody>','</table>']),templateSocialNetworks:new Ext.Template(['<div id="{ID_BOUTON}" class="ux-tool {PREFIXE_CLS}-panel">','<span class="ux-tool-text {PREFIXE_CLS}-text">{TEXTE_BOUTON}</span>','<img height="30" width="32" class="{PREFIXE_CLS}-icon" src="{URL_BASE}/client-libs/extjs/resources/images/default/s.gif"/>','</div>',]),constructor:function(config){this.config=config;this.controller=new Ext.ux.application.controllers.partagerWindow(config,this);this.captchaURL=URL_BASE+"/get/page/partage/Captcha?width=202&height=50&characters=5&t=";},envoyerMail:function(){var formPanel=Ext.getCmp('formulaire-mail');if(formPanel.getForm().isValid()){formPanel.el.mask('Please wait','x-mask-loading');formPanel.getForm().submit({method:"POST",url:URL_BASE+'/get/page/partage/Mail',success:this.onSuccessOrFail.createDelegate(this),failure:this.onSuccessOrFail.createDelegate(this)});}else{Ext.Msg.show({title:'Attention',msg:'Les champs en rouge indiquent des erreurs dans votre formulaire',buttons:Ext.Msg.OK});}},onSuccessOrFail:function(form,action){var formPanel=Ext.getCmp('formulaire-mail');formPanel.el.unmask();var result=action.result;if(result.success){this.mailPreviewWindow=new Ext.Window({modal:true,closable:true,width:600,autoHeight:true,items:[{cls:"ux-mail-sent-msg",xtype:"box",html:action.result.msg},{xtype:"panel",cls:"ux-mail-preview",html:action.result.tpl}],listeners:{scope:this.mailPreviewWindow,afterrender:function(){Ext.select("div.ext-el-mask").each(function(mask){mask.on("click",this.close.createDelegate(this));},this);}}}).show();}
else{Ext.MessageBox.alert('Failure',action.result.errors.msg);if(action.result.errors.code=='security_code')
this.onCaptchaChange();}},onCaptchaChange:function(){var captchaURL=this.captchaURL;var curr=Ext.get('activateCodeImg');curr.slideOut('t',{callback:function(){Ext.get('activateCodeImg').dom.src=captchaURL+new Date().getTime();curr.slideIn('t');}},this);},dessineWindow:function(panelsConfig){panelsPartage=panelsConfig;this.tabPanel=new Ext.TabPanel({width:this.config.width-10,autoHeight:true,tabWidth:this.config.width/panelsPartage.length,resizeTabs:true,buttonAlign:'center',enableTabScroll:true,activeTab:0,border:false,animCollapse:true,animScroll:true,baseCls:'ux-partager',defaults:{autoScroll:true,autoWidth:true,autoHeight:true},listeners:{tabchange:function(tp){this.center.createDelegate(this);},scope:this}});var index=0;Ext.each(panelsPartage,function(panelPartage,index){switch(panelPartage.templateHTML){case"templateSocialNetworks":this.tabPanel.add({title:this.templateSocialNetworks.apply({URL_BASE:URL_BASE,PREFIXE_CLS:panelPartage.prefixe_cls,TEXTE_BOUTON:panelPartage.intitule,ID_BOUTON:panelPartage.intitule}),cls:panelPartage.prefixe_cls,closable:false,width:this.config.width/panelsPartage.length,align:'center',autoLoad:{url:panelPartage.autoLoadURL,scripts:true}});break;case"templatePermalienHTML":var lienVisuel;if(panelPartage.lienVisuelCode)
lienVisuel=[{cls:"ux-partager-permalien-msg",xtype:"box",html:panelPartage.lienVisuelMsg},{cls:"ux-partager-permalien-tf",xtype:"textarea",readOnly:true,selectOnFocus:true,value:panelPartage.lienVisuelCode},{xtype:"panel",cls:"ux-partager-visuallink-preview",border:false,autoLoad:{url:panelPartage.lienVisuelURL,callback:this.center.createDelegate(this)}}];this.tabPanel.add({title:this.templateBoutonPartage.apply({URL_BASE:URL_BASE,PREFIXE_CLS:panelPartage.prefixe_cls,TEXTE_BOUTON:panelPartage.intitule,ID_BOUTON:panelPartage.intitule}),iconCls:'tabpanel-icon-partage',cls:"ux-partager-permalien-html",items:[{cls:"ux-partager-permalien-msg",xtype:"box",html:panelPartage.permalienMsg},{cls:"ux-partager-permalien-tf",xtype:"textfield",readOnly:true,selectOnFocus:true,value:panelPartage.permalien}].concat(lienVisuel||[]),closable:false,width:this.config.width/panelsPartage.length,align:'center'});break;case"templatePartageMail":var boxCaptcha=new Ext.BoxComponent({align:'center',columnWidth:.35,autoEl:{tag:'img',height:50,width:202,id:'activateCodeImg',title:panelPartage.aideCodeCaptcha,src:this.captchaURL+new Date().getTime()}});boxCaptcha.on('render',function(){Ext.get('activateCodeImg').on('click',this.onCaptchaChange,this);},this);Ext.apply(Ext.form.VTypes,{emailText:panelPartage.messageMailInvalide});this.simpleForm=new Ext.FormPanel({id:"formulaire-mail",labelWidth:170,buttonAlign:'center',baseCls:'ux-formulaire-mail',xtype:'form',frame:true,bodyStyle:'padding:10px 10px 0',autoWidth:true,defaults:{width:'95%',cls:'ux-tool-text',listeners:{scope:this,specialkey:function(f,e){if(e.getKey()==e.ENTER)
this.envoyerMail();}}},defaultType:'textfield',items:[{xtype:"textarea",fieldLabel:panelPartage.intituleEmailDestinataire,name:'email_destinataire',allowBlank:false,growMin:20,growMax:200,maskRe:/[a-z0-9_\.\-@\+\n\r]/i,blankText:panelPartage.messageChampRequis,validator:function(v){var emails=v.split("\n");for(var index=0;index<emails.length;index++){if(!Ext.form.VTypes.email(emails[index]))
return Ext.form.VTypes.emailText;}
return true;}},{xtype:'hidden',name:'permalien',value:panelPartage.permalien},{xtype:'hidden',name:'page',value:this.config.applicationScope.config.page},{xtype:'hidden',name:'view',value:this.config.applicationScope.config.sharedVars.viewMode},{xtype:'hidden',name:'parcours',value:this.config.applicationScope.config.sharedVars.parcours},{xtype:'hidden',name:'media',value:panelPartage.media},{fieldLabel:panelPartage.intituleNomPrenom,xtype:'textfield',name:'nom_prenom_envoyeur',allowBlank:false,blankText:panelPartage.messageChampRequis},{fieldLabel:panelPartage.intituleEmailEnvoyeur,name:'mail_envoyeur',vtype:'email'},{fieldLabel:panelPartage.intituleCommentaire,xtype:'textarea',name:'commentaire',allowBlank:true,growMin:50,growMax:200,grow:true},{fieldLabel:panelPartage.messageCaptchaRequis,labelStyle:"margin-top: 60px",xtype:"panel",border:false,items:[boxCaptcha,{cls:"ux-field-captcha",xtype:"textfield",name:"captcha_code",listeners:{scope:this,specialkey:function(f,e){if(e.getKey()==e.ENTER)
this.envoyerMail();}}}]}],buttons:[{cls:'ux-button ux-button-envoyer-mail',text:panelPartage.intituleBoutonEnvoyer,handler:this.envoyerMail,scope:this}]});this.tabPanel.add({title:this.templateBoutonPartage.apply({URL_BASE:URL_BASE,PREFIXE_CLS:panelPartage.prefixe_cls,TEXTE_BOUTON:panelPartage.intitule,ID_BOUTON:panelPartage.intitule}),iconCls:'tabpanel-icon-partage',items:[this.simpleForm],closable:false,width:this.config.width/panelsPartage.length,align:'center'});break;case"templateExportPlayer":this.playerExportableCodePanel=new Ext.form.TextArea({urlPlayer:panelPartage.playerExportableURL,codePlayer:panelPartage.playerExportableCode,fieldLabel:panelPartage.intituleCodePlayer,width:'100%',value:String.format(panelPartage.playerExportableCode,panelPartage.players.petit.size[0],panelPartage.players.petit.size[1],"petit"),readOnly:true,selectOnFocus:true});this.playerExportablePreview=new Ext.Panel({cls:"ux-partager-player-exportable-iframe",autoLoad:{url:String.format(panelPartage.playerExportableURL,"petit"),callback:this.center.createDelegate(this)}});var players=[];Ext.iterate(panelPartage.players,function(size,opts){players.push({checked:size=="petit",boxLabel:opts.label,playerSize:size,playerWidth:String(opts.size[0]),playerHeight:String(opts.size[1]),name:"taille",hideLabel:true});},this);this.tabPanel.add({title:this.templateBoutonPartage.apply({URL_BASE:URL_BASE,PREFIXE_CLS:panelPartage.prefixe_cls,TEXTE_BOUTON:panelPartage.intitule,ID_BOUTON:panelPartage.intitule}),iconCls:'tabpanel-icon-partage',items:[{cls:"ux-partager-player-exportable-msg",xtype:"box",html:panelPartage.oEmbedMsg},{xtype:"container",cls:"ux-partager-player-exportable-oembed",items:{xtype:"textfield",readOnly:true,selectOnFocus:true,value:panelPartage.lienOEmbed,width:'100%'}},{cls:"ux-partager-player-exportable-msg",xtype:"box",html:panelPartage.codeMsg},{xtype:"radiogroup",cls:"ux-partager-player-exportable-size",items:players,listeners:{change:function(rg,rb){this.playerExportableCodePanel.setValue(String.format(this.playerExportableCodePanel.codePlayer,rb.playerWidth,rb.playerHeight,rb.playerSize));this.playerExportablePreview.getUpdater().update({url:String.format(this.playerExportableCodePanel.urlPlayer,rb.playerSize),callback:this.center.createDelegate(this)});},scope:this}},{xtype:"panel",border:false,cls:"ux-partager-player-exportable-code",items:this.playerExportableCodePanel},this.playerExportablePreview],closable:false,width:this.config.width/panelsPartage.length,align:'center'});this.doLayout();break;}},this);Ext.ux.application.views.partagerWindow.superclass.constructor.call(this,Ext.apply(this.config,{modal:true,autoHeight:true,resizable:false,closable:true,id:"fenetre-partage",items:[this.tabPanel]}));this.show();}});Ext.reg("ux-partager-window",Ext.ux.application.views.partagerWindow);

