FR.components.commentsPanel=Ext.extend(Ext.ux.ListPanel,{path:false,layout:"border",icon:"fa-comments",title:"Comments",cls:"fr-comments-panel",bodyCssClass:"fr-comments-panel-body",initComponent:function(){this.store=new Ext.data.JsonStore({url:URLRoot+"/?module=comments&section=ajax&page=load",root:"comments",totalProperty:"totalCount",id:"id",fields:["id","date_added","timer","uid","val","username","fullName","self","followup"],listeners:{load:function(store){var d=store.reader.jsonData;if(d.error){this.listView.getTemplateTarget().update('<div class="x-list-message">'+d.error+"</div>")}this.listView.el.scroll("b",1e4,true)},scope:this}});var tpl='<div class="comments">'+'<tpl for="rows">'+'<div class="comment <tpl if="self">own</tpl> <tpl if="followup">followup</tpl>">'+'<tpl if="!followup"><div class="basicAvatar" ext:qtip="{fullName}&lt;br&gt; {date_added:date("l, F jS, Y \\\\a\\\\t h:i A")}" style="background-image:url(a/?uid={uid})"></div></tpl>'+'<div class="text">';if(User.perms.write_comments){tpl+='<div class="removeBtn"><a onclick="FR.UI.deleteComment(\''+this.id+"', '{id}')\"><i class=\"fa fa-close\"></i></a></div>"}tpl+="{val}"+"</div>"+"</div>"+"</tpl>"+"</div>";this.listViewCfg={emptyText:'<img class="illustration" src="'+FR.illustrationsURL+'/comments.svg" />'+FR.T("No comments available for this item"),region:"center",autoScroll:true,columns:[],tpl:tpl,listeners:{containercontextmenu:this.print,scope:this}};this.inputBox=new Ext.form.TextArea({emptyText:"Write a comment...",enableKeyEvents:true,listeners:{keydown:function(field,e){if(e.getKey()==e.ENTER){if(!e.shiftKey){this.addComment()}}},scope:this}});this.btns={submit:new Ext.Button({cls:"fr-btn-primary",text:"Submit comment",handler:this.addComment,scope:this}),print:new Ext.Button({iconCls:"fa-print",handler:this.print,scope:this})};this.writePanel=new Ext.Panel({region:"south",layout:"fit",cls:"commentField",height:Ext.isSmallScreen?114:50,split:true,items:this.inputBox,margins:Settings.layout.commentField&&Settings.layout.commentField.margins?Settings.layout.commentField.margins:"0 15 15 0",bbar:{style:"padding:1px 2px;",hidden:!Ext.isSmallScreen,items:[this.btns.print,"->",this.btns.submit]}});this.extraItem=this.writePanel;Ext.apply(this,{listeners:{activate:function(p){if(!Ext.isMobile){p.inputBox.focus()}p.onInfoPanelRefresh()}}});FR.components.commentsPanel.superclass.initComponent.apply(this,arguments)},onInfoPanelRefresh:function(){var path=this.infoPanel.fileInfo.path;var cCount=this.infoPanel.fileInfo.comments||0;this.setTabBubble(cCount);if(path==this.path){return false}if(!this.active){return false}this.path=path;this.store.removeAll(true);this.listView.refresh();if(this.infoPanel.target.checkRequirement("comment")){this.writePanel.show()}else{this.writePanel.hide()}this.doLayout(true);this.store.setBaseParam("path",path);this.store.load()},addComment:function(){var c=this.inputBox.getValue();if(c.length>0){this.action("add",{comment:c})}},print:function(){window.open(URLRoot+"/?module=comments&page=print&path="+encodeURIComponent(this.path))},deleteComment:function(cid){new Ext.ux.prompt({text:"Are you sure you want to remove the comment?",confirmHandler:function(){this.action("remove",{commentId:cid})},scope:this})},action:function(action,params){FR.actions.process({url:"/?module=comments&section=ajax&page="+action,params:Ext.apply(params,this.store.baseParams),loadMsg:action=="remove"?"Removing comment...":"Posting comment...",successCallback:function(){this.inputBox.reset();this.store.load()},scope:this})}});FR.UI.deleteComment=function(panelId,cId){Ext.getCmp(panelId).deleteComment(cId)};