Ext.namespace("Zarafa.widgets.twidget");Zarafa.widgets.twidget.ABOUT='<p>Copyright (C) 2005 - 2015  Zarafa B.V. &lt;info@zarafa.com&gt; and its licensors</p><p>This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.</p><p>This program 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 Affero General Public License for more details.</p><p>You should have received a copy of the GNU Affero General Public License along with this program.  If not, see <a href="http://www.gnu.org/licenses/" target="_blank">http://www.gnu.org/licenses/</a>.</p><hr /><p>The twidget plugin contains the following third-party components:</p><h1>Ext.ux.JSONP</h1><p>Copyright (C) 2013 CodeSmith Tools, LLC. All rights reserved.  jsonp.js is distributed under the terms of the GNU Lesser General Public License: <a href="http://www.gnu.org/copyleft/lgpl.html" target="_blank">http://www.gnu.org/copyleft/lgpl.html</a></p>';
Ext.namespace("Zarafa.widgets.twidget");
Zarafa.widgets.twidget.SenderInfoWidget=Ext.extend(Zarafa.core.ui.widget.Widget,{store:undefined,record:undefined,rowSelectionModel:undefined,constructor:function(b){b=b||{};this.store=new Ext.data.ArrayStore({autoDestroy:true,storeId:"twidget",idIndex:0,fields:["id","image","sender","user","text"],data:[]});this.rowSelectionModel=new Ext.grid.RowSelectionModel({singleSelect:true});Ext.applyIf(b,{about:Zarafa.widgets.twidget.ABOUT,height:260,layout:"fit",hasConfig:true,items:[{xtype:"grid",disableSelection:true,
store:this.store,border:true,sm:this.rowSelectionModel,viewConfig:{deferEmptyText:false,emptyText:'<div class="emptytext">'+_("No sender info found.")+"</div>",forceFit:true,enableRowBody:true,getRowClass:function(a,c,d){d.body=a.get("text");return"x-grid3-row-expanded"}},colModel:new Ext.grid.ColumnModel({columns:[{header:"",dataIndex:"image",editable:false,menuDisabled:true,renderer:function(a){return'<img style="width: 16px; height: 16px" src="'+a+'">'},width:50},{header:_("Username"),dataIndex:"user",
editable:false,menuDisabled:true,renderer:function(a){return"<b>@"+a+"</b>"},width:200},{header:_("Sender"),dataIndex:"sender",editable:false,menuDisabled:true,width:200}]})}]});Zarafa.widgets.twidget.SenderInfoWidget.superclass.constructor.call(this,b)},initEvents:function(){Zarafa.widgets.twidget.SenderInfoWidget.superclass.initEvents.apply(this,arguments);this.mon(this.rowSelectionModel,"rowselect",this.onRowSelect,this);var b=container.getContextByName("mail");b&&this.mon(b.getModel(),"previewrecordchange",
this.onPreviewRecordChange,this)},onPreviewRecordChange:function(b,a){if(this.record){var c=this.record.getStore();c&&this.mun(c,"open",this.onOpen,this)}this.store.removeAll();if(this.record=a)if(a.isOpened())this.loadRecord(a);else{this.mon(a.getStore(),"open",this.onOpen,this);a.open()}},onRowSelect:function(b,a,c){window.open("https://twitter.com/"+c.get("user")+"/statuses/"+c.get("id"))},onOpen:function(b,a){if(this.record&&this.record.equals(a)){this.mun(b,"open",this.onOpen,this);this.loadRecord(a)}},
loadRecord:function(b){var a=b.getBody(false),c=/twitter.com\/(\w+)/;b=undefined;c=c.exec(a);if(Ext.isEmpty(c)){c=/^(.*?\W)?@(\w{1,15})\b/;c=c.exec(a);Ext.isEmpty(c)||(b=c[2])}else b=c[1];if(b!==undefined){a=this.get("max_count");Ext.isDefined(a)||(a=10);c=this.get("include_rts");Ext.isDefined(c)||(c=true);Ext.ux.JSONP.request({url:"https://api.twitter.com/1/statuses/user_timeline.json",params:{screen_name:b,count:String(a),include_rts:String(c)},success:this.onTwitterUpdate,callbackKey:"callback",
scope:this})}},onTwitterUpdate:function(b){Ext.each(b,function(a,c){var d=a;if(d.retweeted_status!=undefined)d=d.retweeted_status;this.store.add([new this.store.recordType({id:d.id_str,user:d.user.screen_name,sender:d.user.name,text:d.text,image:Ext.isSecure?d.user.profile_image_url_https:d.user.profile_image_url},c)])},this)},config:function(){var b=new Ext.Window({title:_("Configure widget"),layout:"fit",width:320,height:200,items:[{xtype:"form",labelWidth:120,frame:true,items:[{xtype:"zarafa.spinnerfield",
fieldLabel:_("Maximum results"),name:"max_count",minValue:5,maxValue:100,incrementValue:1,defaultValue:this.get("max_count")||10,listeners:{change:this.onFieldChange,scope:this},plugins:["zarafa.numberspinner"]},{xtype:"checkbox",fieldLabel:_("Include retweets"),name:"include_rts",checked:Ext.isDefined(this.get("include_rts"))?this.get("include_rts"):true,listeners:{check:this.onFieldChange,scope:this}}],buttons:[{text:_("Close"),scope:this,handler:function(){b.close()}}]}]});b.show(this)},onFieldChange:function(b,
a){this.set(b.getName(),a)}});Zarafa.onReady(function(){container.registerWidget(new Zarafa.core.ui.widget.WidgetMetaData({name:"twidget",displayName:_("Twidget"),iconPath:"plugins/twidget/resources/images/twidget.png",widgetConstructor:Zarafa.widgets.twidget.SenderInfoWidget}))});
