Ext.ns("feyaSoft.openSource");feyaSoft.openSource.ForumPanel=function(config){this.config=config;this.myPageSize=25;var selectBoxModel=new Ext.grid.RowSelectionModel({singleSelect:true});function showFile(val){if(val==null){val=""}else{if(val!=null){val='<img class="function-file-download" src="images/icons/attach.png" style="cursor:pointer"></img>'}}return val}this.itemCM=new Ext.grid.ColumnModel([{id:"id",header:"Identify",dataIndex:"id",width:100,hidden:true},{header:"Post Title",width:350,sortable:true,dataIndex:"subject",renderer:feyaSoft.openSource.Renderers.topic},{header:"Replies",width:30,dataIndex:"totalReply"},{header:"Update Time",width:80,dataIndex:"updateTime",renderer:feyaSoft.openSource.Renderers.lastPost},{header:"File",dataIndex:"uploadFileLoc",width:20,renderer:showFile}]);this.dataStore=new Ext.data.JsonStore({url:"openSourceForum/list?parentId=0&type="+config.type,remoteSort:true,fields:[]});this.dataStore.setDefaultSort("updateTime","DESC");this.pageBar=new Ext.PagingToolbar({pageSize:this.myPageSize,store:this.dataStore,displayInfo:true,displayMsg:"Displaying items {0} - {1} of {2}",emptyMsg:"not result to display"});this.searchField=new Ext.form.TextField({width:400});this.menubar=[{text:"New Post",tooltip:"Add a new Post",iconCls:"addItem",handler:function(){this.checkLogin({action:"new"})},scope:this},"-","Search: ",this.searchField,{iconCls:"icon_search",handler:this.onSearchFn,scope:this}];feyaSoft.openSource.ForumPanel.superclass.constructor.call(this,{region:"center",store:this.dataStore,cm:this.itemCM,sm:selectBoxModel,trackMouseOver:false,loadMask:{msg:"loading..."},viewConfig:{forceFit:true},tbar:this.menubar,bbar:this.pageBar});this.on("rowclick",this.onRowClickFn,this)};Ext.extend(feyaSoft.openSource.ForumPanel,Ext.grid.GridPanel,{loadThread:function(){this.dataStore.load({params:{start:0,limit:this.myPageSize}})},onSearchFn:function(){var v=this.searchField.getValue();this.dataStore.filterBy(function(rd,id){var subject=rd.data.subject;var desc=rd.data.description;if(-1!=subject.indexOf(v)||-1!=desc.indexOf(v)){return true}return false},this)},checkLogin:function(config){Ext.Ajax.request({url:"userWholeAccess/isUserLogin",success:function(result,request){var jsonData=Ext.decode(result.responseText);if(jsonData.success=="true"){if(config.action=="new"){new feyaSoft.openSource.myCalendar.CreateEditForum({myOwner:this,type:this.config.type,parentId:"0"})}else{if(config.action=="details"){new feyaSoft.openSource.myCalendar.DetailsForum({myOwner:this,type:this.config.type,parentId:config.id})}else{if(config.action=="edit"){var record=config.record;new feyaSoft.openSource.myCalendar.CreateEditForum({myOwner:this,type:this.config.type,parentId:"0",record:record})}else{if(config.action=="reply"){var record=config.record;new feyaSoft.openSource.myCalendar.CreateEditForum({myOwner:this,type:this.config.type,parentId:record.id,replySub:record.data.subject})}}}}}else{new feyaSoft.openSource.Login()}},failure:function(result,request){new feyaSoft.openSource.Login()},scope:this})},onRowClickFn:function(grid,rowIndex,e){var target=e.getTarget();var targetEl=Ext.get(target);var rd=this.dataStore.getAt(rowIndex);var id=rd.data.id;if(targetEl.hasClass("function-file-download")){var url="openSourceForum/download?id="+id;window.open(url,"Download")}else{if(targetEl.hasClass("x-thread-topic-link")){this.gotoTopic(rd)}}},gotoTopic:function(topic){var mp=this.ownerCt;var dp=mp.items.get(1);mp.getLayout().setActiveItem(1);dp.loadTopic(topic)},reload:function(){this.dataStore.reload()}});feyaSoft.openSource.Renderers=(function(){var topicTpl=new Ext.XTemplate('<tpl for="."><div class="forum_topic"><b><a class="x-thread-topic-link" href="#">{subject}</a></b></div><div class="forum_author" style="font-size:13;">by: {author}&nbsp;&nbsp;<i style="color:gray;">{createTime}</i></div>',"</tpl>");topicTpl.compile();return{topic:function(value,p,record){var data=record.data;return topicTpl.apply({subject:data.subject,author:data.author,createTime:data.createTime.format("Y-m-d H:i")})},lastPost:function(value,p,r){return String.format('<span class="post-date">{0}</span><br/>by: {1}',value.dateFormat("M j, Y, g:i a"),r.data.lastPoster)}}})();