added sample tests

This commit is contained in:
Rushabh Mehta
2011-06-28 13:26:02 +05:30
parent 3766a5598d
commit ab24d950bb
23 changed files with 38 additions and 556 deletions

View File

@@ -1,23 +0,0 @@
KBItemToolbar=function(args,kb){$.extend(this,args);var me=this;this.make=function(){this.wrapper=$a(this.parent,'div','',{});this.line1=$a(this.wrapper,'div','',{color:'#888',fontSize:'11px',margin:'7px 0px'});this.line2=$a(this.wrapper,'div','',{marginBottom:'7px'});this.make_timestamp();this.make_vote();if(this.with_tags)
this.make_tags();}
this.make_timestamp=function(){this.line1.innerHTML=repl('By %(name)s | %(when)s',{name:wn.utils.full_name(this.det.first_name,this.det.last_name),when:wn.datetime.comment_when(this.det.modified)})}
this.make_vote=function(){new KBPoints(this.line2,this.det.points,this.det._users_voted,this.doctype,this.det.name,this.det.owner);}
this.make_tags=function(){this.tags_area=$a(this.line2,'span','kb-tags')
this.tags=new TagList(this.tags_area,this.det._user_tags&&(this.det._user_tags.split(',')),this.doctype,this.det.name,0,kb.set_tag_filter)}
this.make();}
KBPoints=function(parent,points,voted,dt,dn,owner){var me=this;voted=voted?voted.split(','):[];this.wrapper=$a(parent,'span','',{fontSize:'11px',marginRight:'13px'});this.render_points=function(p){if(!this.points_area)
this.points_area=$a(this.wrapper,'span');this.points_area.innerHTML=cint(p)+' point'+(p>1?'s':'');}
this.render_points(points);if(user!='Guest'&&!in_list(voted,user)&&user!=owner){this.vote_up=$a(this.wrapper,'img','images/ui/vote_up.gif',{margin:'0px 0px -2px 7px',cursor:'pointer'});this.vote_down=$a(this.wrapper,'img','images/ui/vote_down.gif',{margin:'0px 0px -3px 0px',cursor:'pointer'});this.vote_up.title='Vote Up';this.vote_down.title='Vote Down';var callback=function(r,rt){if(r.exc){msgprint(r.exc);return;}
$dh(me.vote_up);$dh(me.vote_down);me.render_points(r.message);}
this.vote_up.onclick=function(){$c_page('knowledge_base','questions','vote',{vote:'up',dn:dn,dt:dt},callback);}
this.vote_down.onclick=function(){$c_page('knowledge_base','questions','vote',{vote:'down',dn:dn,dt:dt},callback);}}}
EditableText=function(args){$.extend(this,args);var me=this;this.display=$a(me.parent,'div',me.disp_class,'',me.text);this.input=$a(me.parent,'textarea',me.inp_class,{display:'none'});var div=$a(me.parent,'div','',{marginTop:'5px',height:'23px'});this.edit_btn=$a(div,'span','',{color:'#333',marginLeft:'-2px',cursor:'pointer',padding:'3px',backgroundColor:'#ddd',cssFloat:'left'});$br(this.edit_btn,'3px')
$a(this.edit_btn,'div','wn-icon ic-pencil',{marginBottom:'-2px',cssFloat:'left'});$a(this.edit_btn,'span','link_type',{marginLeft:'3px',color:'#555',fontSize:'11px'},'Edit');this.edit_btn.onclick=function(){me.input.value=me.display.innerHTML;me.show_as_input();}
this.save_btn=$btn(div,'Save',function(){var v=me.rich_text?wn.tinymce.get_value(me.input):me.input.value;if(!v){msgprint('Please write something!');return;}
me.save_btn.set_working();$c_page('knowledge_base','question_view','update_item',{dt:me.dt,dn:me.dn,fn:me.fieldname,text:v},function(r,rt){me.save_btn.done_working();if(r.exc){msgprint(r.exc);return;}
me.display.innerHTML=v;me.show_as_text();});},{display:'none'});this.cancel_btn=$a(div,'span','link_type',{color:'#555',display:'none'},'Cancel',{marginLeft:'7px'});this.cancel_btn.onclick=function(){me.show_as_text();}
this.show_as_text=function(){$ds(me.display);$ds(me.edit_btn);if(me.rich_text)
wn.tinymce.remove(me.input);$dh(me.input);$dh(me.save_btn);$dh(me.cancel_btn);}
this.show_as_input=function(){$ds(me.input);$ds(me.save_btn);$ds(me.cancel_btn);$dh(me.edit_btn);$dh(me.display);if(me.rich_text)
wn.tinymce.add_simple(me.input,'300px');}}

View File

@@ -1,24 +0,0 @@
pscript['onload_question-view']=function(){var w=page_body.pages['question-view'];w.className='layout_wrapper';new PageHeader(w,'Knowledge Base');w.link=$ln($a(w,'div'),'< Back to all questions',function(){loadpage('questions');})
w.body=$a(w,'div','qv-body');}
pscript['refresh_question-view']=function(){var qid=window.location.hash.split('/')[1];if(qid){pscript.question_view(qid);}}
pscript.question_view=function(qid,qtext){var w=page_body.pages['question-view'];new KBQuestionView(w,qid,qtext);}
KBQuestionView=function(w,qid,qtext){var me=this;w.body.innerHTML='';w.question_area=$a(w.body,'div','social qv-question-wrapper');w.answer_area=$a(w.body,'div','social qv-answer-wrapper');w.add_answer_link=$a(w.body,'div','',{margin:'3px 0px'});w.add_answer_area=$a(w.body,'div','qv-add-answer');this.make_question=function(){new EditableText({parent:w.question_area,dt:'Question',dn:qid,fieldname:'question',text:qtext,inp_class:'qv-input',disp_class:'qv-text'});}
this.make_answer_list=function(){this.ans_list=new KBAnswerList({parent:w.answer_area,qid:qid})}
this.make_add_answer=function(){$c_page('knowledge_base','question_view','has_answered',qid,function(r,rt){if(r.message=='No'){me.make_answer_box_link();}});}
this.make_answer_box_link=function(){$a(w.add_answer_link,'span','link_type',null,'+ Add your answer',function(){$dh(w.add_answer_link);me.make_answer_box();});}
this.make_answer_box=function(){$ds(w.add_answer_area);$a(w.add_answer_area,'h3','',{},'Add Your Answer')
this.input=$a(w.add_answer_area,'textarea');wn.tinymce.add_simple(this.input);this.btn=$btn($a(w.add_answer_area,'div'),'Post',function(){var v=wn.tinymce.get_value(me.input);if(!v){msgprint('Write something!');return;}
me.btn.set_working();$c_page('knowledge_base','question_view','add_answer',{qid:qid,answer:v},function(r,rt){me.btn.done_working();me.ans_list.list.run();$dh(w.add_answer_area);});});}
this.setup=function(){if(qtext){this.make();}
else{$c_page('knowledge_base','question_view','get_question',qid,function(r,rt){qtext=r.message;me.make();});}}
this.make=function(){set_title(qtext);this.make_question();this.make_answer_list();this.make_add_answer();}
this.setup();}
KBAnswerList=function(args){var me=this;$.extend(this,args);this.make_list=function(){this.list=new wn.widgets.Listing({parent:me.parent,as_dict:1,no_results_message:'No answers yet, be the first one to answer!',render_row:function(body,data){new KBAnswer(body,data)},get_query:function(){return repl("SELECT t1.name, t1.owner, t1.answer, t1.points, t1._users_voted, t2.first_name, "
+"t2.last_name, t1.modified from tabAnswer t1, tabProfile t2 "
+"where question='%(qid)s' and t1.owner = t2.name "
+"order by t1.points desc, t1.modified desc",{qid:me.qid})}});this.list.run();}
this.make_list();}
KBAnswer=function(body,data){body.className='qv-answer';new EditableText({parent:body,dt:'Answer',dn:data.name,fieldname:'answer',text:data.answer,inp_class:'qv-ans-input',disp_class:'qv-ans-text',rich_text:1});var div=$a(body,'div','',{})
new KBItemToolbar({parent:div,det:data,with_tags:0,doctype:'Answer'},null)}
$import(knowledge_base.kb_common);

View File

@@ -1,27 +0,0 @@
pscript.onload_questions=function(){var w=page_body.pages['questions'];var tab=make_table(w,1,2,'100%',['75%','25%'],{});var body=$a($td(tab,0,0),'div','layout_wrapper');new PageHeader(body,'Knowledge Base');var kb=new KnowledgeBase(body);$y($td(tab,0,1),{paddingTop:'53px'});this.sidebar=new wn.widgets.PageSidebar($td(tab,0,1),{sections:[{title:'Top Tags',render:function(body){new wn.widgets.TagCloud(body,'Question',function(tag){kb.set_tag_filter(tag)});}}]});set_title('Knowledge Base');}
function KnowledgeBase(w){var me=this;this.sort_by='modified';this.tag_filter_dict={};this.make_search_bar=function(){this.search=$a($a(w,'div','kb-search-wrapper'),'textarea');$(this.search).add_default_text('Enter keywords or a new Question');var div=$a(w,'div','kb-btn-wrapper');$btn(div,'Search',function(){me.run()},{fontSize:'14px'});$btn(div,'Ask',function(){me.ask()},{fontSize:'14px'});}
this.ask=function(){if(this.search.value==$(this.search).attr('default_text')){msgprint('Please enter some text');return;}
this.suggest();}
this.suggest=function(){this.dialog=new wn.widgets.Dialog({title:'Suggest a users',width:400,fields:[{fieldtype:'HTML',options:'Optional: Suggest a few users who can help you answer this question<br>'},{fieldtype:'Link',fieldname:'profile1',label:'1st User',options:'Profile'},{fieldtype:'Link',fieldname:'profile2',label:'2nd User',options:'Profile'},{fieldtype:'Link',fieldname:'profile3',label:'3rd User',options:'Profile'},{fieldtype:'Button',fieldname:'ask',label:'Add the Question'}]});this.dialog.fields_dict.ask.input.onclick=function(){me.dialog.hide();me.add_question(values(me.dialog.get_values()));}
this.dialog.show();}
this.add_question=function(suggest_list){$c_page('knowledge_base','questions','add_question',{question:this.search.value,suggest:suggest_list},function(r,rt){$(me.search).val('').blur();me.run();})}
this.make_tag_filter_area=function(){this.tag_filters=$a(w,'div','kb-tag-filter-area');$a(this.tag_filters,'span','',{marginRight:'4px',color:'#442'},'<i>Showing for:</i>');this.tag_area=$a(this.tag_filters,'span');}
this.make_list=function(){this.make_tag_filter_area();this.list_area=$a(w,'div','',{marginRight:'13px'})
this.no_result=$a(w,'div','help_box',{display:'none'},'No questions asked yet! Be the first one to ask')
this.list=new wn.widgets.Listing({parent:this.list_area,no_results_message:'No questions found. Ask a new question!',as_dict:1,get_query:function(){var v=me.search.value==$(me.search).attr('default_text')?'':me.search.value;cond=v?(' and t1.question like "%'+v+'%"'):'';if(me.tag_filter_dict){for(f in me.tag_filter_dict){cond+=' and t1.`_user_tags` like "%'+f+'%"'}}
return repl('select t1.name, t1.owner, t1.question, t1.points, t1.modified, t1._user_tags, '
+'t1._users_voted, t2.first_name, t2.last_name '
+'from tabQuestion t1, tabProfile t2 '
+'where t1.docstatus!=2 '
+'and t1.owner = t2.name'
+'%(cond)s order by t1.modified desc',{user:user,cond:cond})},render_row:function(parent,data,listing){new KBQuestion(parent,data,me);}});this.list.run();}
this.set_tag_filter=function(tag){if(in_list(keys(me.tag_filter_dict),tag.label))return;var filter_tag=new SingleTag({parent:me.tag_area,label:tag.label,dt:'Question',color:tag.color});filter_tag.remove=function(tag_remove){$(tag_remove.body).fadeOut();delete me.tag_filter_dict[tag_remove.label];if(!keys(me.tag_filter_dict).length){$(me.tag_filters).slideUp();}
me.run();}
me.tag_filter_dict[tag.label]=filter_tag;$ds(me.tag_filters);me.run();}
this.run=function(){this.list.run();}
this.make_search_bar();this.make_list();}
KBQuestion=function(parent,det,kb){this.make=function(){this.wrapper=$a(parent,'div','kb-question-wrapper');this.q_area=$a($a(this.wrapper,'div'),'h3','kb-questions link_type',{display:'inline',textDecoration:'none'},det.question);this.q_area.onclick=function(){var q=this;window.location.href='#!question-view/'+q.id;}
this.q_area.id=det.name;this.q_area.txt=det.question;new KBItemToolbar({parent:this.wrapper,det:det,with_tags:1,doctype:'Question'},kb)}
this.make()}
$import(knowledge_base.kb_common);