GO.comments.CommentDialog=function(b){if(!b){b={}}this.buildForm();var a=function(){this.formPanel.items.items[0].focus()};b.collapsible=true;b.layout="fit";b.modal=false;b.resizable=false;b.width=600;b.autoHeight=true;b.closeAction="hide";b.title=GO.comments.lang.comment;b.items=this.formPanel;b.focus=a.createDelegate(this);b.buttons=[{text:GO.lang.cmdOk,handler:function(){this.submitForm(true)},scope:this},{text:GO.lang.cmdClose,handler:function(){this.hide()},scope:this}];GO.comments.CommentDialog.superclass.constructor.call(this,b);this.addEvents({save:true})};Ext.extend(GO.comments.CommentDialog,Ext.Window,{show:function(b,a){if(!this.rendered){this.render(Ext.getBody())}if(!b){b=0}this.setCommentId(b);delete this.link_config;if(this.comment_id>0){this.formPanel.load({url:GO.settings.modules.comments.url+"json.php",waitMsg:GO.lang.waitMsgLoad,success:function(c,d){GO.comments.CommentDialog.superclass.show.call(this)},failure:function(c,d){Ext.Msg.alert(GO.lang.strError,d.result.feedback)},scope:this})}else{this.formPanel.form.reset();GO.comments.CommentDialog.superclass.show.call(this)}if(a&&a.link_config){this.link_config=a.link_config;this.formPanel.baseParams.link_id=a.link_config.id;this.formPanel.baseParams.link_type=a.link_config.type}},setCommentId:function(a){this.formPanel.form.baseParams.comment_id=a;this.comment_id=a},submitForm:function(a){this.formPanel.form.submit({url:GO.settings.modules.comments.url+"action.php",params:{task:"save_comment"},waitMsg:GO.lang.waitMsgSave,success:function(b,c){this.fireEvent("save",this);if(a){this.hide()}else{if(c.result.comment_id){this.setCommentId(c.result.comment_id)}}if(this.link_config&&this.link_config.callback){this.link_config.callback.call(this)}},failure:function(b,c){if(c.failureType=="client"){Ext.MessageBox.alert(GO.lang.strError,GO.lang.strErrorsInForm)}else{Ext.MessageBox.alert(GO.lang.strError,c.result.feedback)}},scope:this})},buildForm:function(){this.formPanel=new Ext.form.FormPanel({waitMsgTarget:true,url:GO.settings.modules.comments.url+"action.php",border:false,autoHeight:true,cls:"go-form-panel",baseParams:{task:"comment"},items:[{xtype:"textarea",name:"comments",anchor:"100%",height:200,hideLabel:true}]})}});GO.comments.showCommentDialog=function(b,a){if(!GO.comments.commentDialog){GO.comments.commentDialog=new GO.comments.CommentDialog()}if(GO.comments.commentDialogListeners){GO.comments.commentDialog.on(GO.comments.commentDialogListeners);delete GO.comments.commentDialogListeners}GO.comments.commentDialog.show(b,a)};GO.comments.browseComments=function(a,b){if(!GO.comments.commentsBrowser){GO.comments.commentsBrowser=new GO.comments.CommentsBrowser()}if(GO.comments.commentDialogListeners){GO.comments.commentsBrowser.on(GO.comments.commentDialogListeners)}GO.comments.commentsBrowser.show({link_id:a,link_type:b})};GO.newMenuItems.push({text:GO.comments.lang.comment,iconCls:"go-menu-icon-comments",handler:function(a,b){GO.comments.showCommentDialog(0,{link_config:a.parentMenu.link_config})}});GO.comments.CommentsGrid=function(a){if(!a){a={}}a.layout="fit";a.autoScroll=true;a.split=true;a.border=false;a.store=new GO.data.JsonStore({url:GO.settings.modules.comments.url+"json.php",baseParams:{task:"comments"},root:"results",id:"id",totalProperty:"total",fields:["id","link_id","link_type","user_name","ctime","mtime","comments"],remoteSort:true});a.store.on("load",function(){this.setWritePermission(this.store.reader.jsonData.write_permission)},this);a.paging=true;var b=new Ext.grid.ColumnModel({defaults:{sortable:true},columns:[{header:GO.lang.strOwner,dataIndex:"user_name",sortable:false,renderer:function(c){return"<i>"+c+"</i>"}},{header:GO.lang.strCtime,dataIndex:"ctime",align:"right",renderer:function(c){return"<b>"+c+"</b>"}}]});a.cm=b;a.viewConfig={forceFit:true,enableRowBody:true,showPreview:true,getRowClass:this.applyRowClass};a.disabled=true;a.sm=new Ext.grid.RowSelectionModel();a.loadMask=true;a.tbar=[{iconCls:"btn-add",text:GO.lang.cmdAdd,cls:"x-btn-text-icon",handler:function(){GO.comments.showCommentDialog();GO.comments.commentDialog.formPanel.baseParams.link_id=this.store.baseParams.link_id;GO.comments.commentDialog.formPanel.baseParams.link_type=this.store.baseParams.link_type},scope:this},{iconCls:"btn-delete",text:GO.lang.cmdDelete,cls:"x-btn-text-icon",handler:function(){this.deleteSelected()},scope:this}];GO.comments.CommentsGrid.superclass.constructor.call(this,a);this.on("rowdblclick",function(d,e){if(this.writePermission){var c=d.getStore().getAt(e);GO.comments.commentDialog.show(c.data.id)}},this)};Ext.extend(GO.comments.CommentsGrid,GO.grid.GridPanel,{writePermission:false,setWritePermission:function(a){this.writePermission=a;this.getTopToolbar().setDisabled(!a)},afterRender:function(){GO.comments.commentDialogListeners={save:function(){this.store.reload()},scope:this};GO.comments.CommentsGrid.superclass.afterRender.call(this)},applyRowClass:function(a,d,c,b){if(this.showPreview){c.body='<p class="description">'+a.data.comments+"</p>";return"x-grid3-row-expanded"}return"x-grid3-row-collapsed"},setLinkId:function(a,b){this.store.baseParams.link_id=a;this.store.baseParams.link_type=b;this.store.loaded=false;this.setDisabled(a<1)},onShow:function(){GO.grid.LinksPanel.superclass.onShow.call(this);if(!this.store.loaded){this.store.load()}}});GO.comments.displayPanelTemplate='<tpl if="values.comments && values.comments.length">{[this.collapsibleSectionHeader(GO.comments.lang.recentComments, "comments-"+values.panelId, "comments")]}<table cellpadding="0" cellspacing="0" border="0" class="display-panel" id="comments-{panelId}"><tpl if="!comments.length"><tr><td colspan="3">'+GO.lang.strNoItems+'</td></tr></tpl><tpl for="comments"><tr><td><i>{user_name}</i></td><td style="text-align:right"><b>{ctime}</b></td></tr><tr><td colspan="2" style="padding-left:5px">{comments}<hr /></td></tr></tpl><tr><td colspan="4"><a class="display-panel-browse" href="#" onclick="GO.comments.browseComments({id}, {link_type});">'+GO.lang.browse+"</a></td></tr></table></tpl>";GO.comments.CommentsBrowser=function(a){Ext.apply(this,a);this.commentsGrid=new GO.comments.CommentsGrid();GO.comments.CommentsBrowser.superclass.constructor.call(this,{layout:"fit",modal:false,minWidth:300,minHeight:300,height:500,width:700,plain:true,maximizable:true,closeAction:"hide",title:GO.comments.lang.browseComments,items:this.commentsGrid,buttons:[{text:GO.lang.cmdClose,handler:function(){this.hide()},scope:this}]});this.addEvents({link:true})};Ext.extend(GO.comments.CommentsBrowser,GO.Window,{show:function(a){this.commentsGrid.setLinkId(a.link_id,a.link_type);this.commentsGrid.store.load();GO.comments.CommentsBrowser.superclass.show.call(this)}});