mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 03:09:09 +00:00
Sourced wnframework-modules from Google Code as erpnext
This commit is contained in:
0
knowledge_base/page/questions/__init__.py
Normal file
0
knowledge_base/page/questions/__init__.py
Normal file
27
knowledge_base/page/questions/questions.comp.js
Normal file
27
knowledge_base/page/questions/questions.comp.js
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
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);
|
||||
29
knowledge_base/page/questions/questions.css
Normal file
29
knowledge_base/page/questions/questions.css
Normal file
@@ -0,0 +1,29 @@
|
||||
div.kb-search-wrapper textarea {
|
||||
height: 2.2em;
|
||||
width: 80%;
|
||||
font-size: 14px;
|
||||
padding: 3px;
|
||||
margin-bottom: 7px;
|
||||
}
|
||||
|
||||
.kb-question-wrapper {
|
||||
border-bottom: 1px solid #AAA;
|
||||
padding-bottom: 3px;
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
|
||||
.kb-questions {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.kb-question-details {
|
||||
margin: 11px 0px 11px 29px;
|
||||
}
|
||||
|
||||
.kb-tag-filter-area {
|
||||
padding: 7px;
|
||||
background-color: #F2F2E8;
|
||||
color: #222;
|
||||
margin: 7px 0px;
|
||||
display: none;
|
||||
}
|
||||
0
knowledge_base/page/questions/questions.html
Normal file
0
knowledge_base/page/questions/questions.html
Normal file
206
knowledge_base/page/questions/questions.js
Normal file
206
knowledge_base/page/questions/questions.js
Normal file
@@ -0,0 +1,206 @@
|
||||
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');
|
||||
|
||||
// kb
|
||||
var kb = new KnowledgeBase(body);
|
||||
|
||||
// sidebar
|
||||
$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');
|
||||
}
|
||||
|
||||
// knowledge base object
|
||||
// has a box for search or ask a question
|
||||
// and list of top rated search results
|
||||
//
|
||||
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'});
|
||||
}
|
||||
|
||||
// ask a new question
|
||||
this.ask = function() {
|
||||
if(this.search.value==$(this.search).attr('default_text')) {
|
||||
msgprint('Please enter some text'); return;
|
||||
}
|
||||
this.suggest();
|
||||
}
|
||||
|
||||
// suggest a few users who can answer
|
||||
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();
|
||||
}
|
||||
|
||||
// add a new question to the database
|
||||
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();
|
||||
})
|
||||
}
|
||||
|
||||
// where tags that filter will be displayed
|
||||
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');
|
||||
}
|
||||
|
||||
// make a list of questions
|
||||
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() {
|
||||
|
||||
// filter by search string
|
||||
var v = me.search.value==$(me.search).attr('default_text') ? '' : me.search.value;
|
||||
cond = v ? (' and t1.question like "%'+v+'%"') : '';
|
||||
|
||||
// filter by tags
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
// add a tag filter to the search in the
|
||||
// main page
|
||||
this.set_tag_filter = function(tag) {
|
||||
|
||||
// check if exists
|
||||
if(in_list(keys(me.tag_filter_dict), tag.label)) return;
|
||||
|
||||
// create a tag in filters
|
||||
var filter_tag = new SingleTag({
|
||||
parent: me.tag_area,
|
||||
label: tag.label,
|
||||
dt: 'Question',
|
||||
color: tag.color
|
||||
});
|
||||
|
||||
// remove tag from filters
|
||||
filter_tag.remove = function(tag_remove) {
|
||||
$(tag_remove.body).fadeOut();
|
||||
delete me.tag_filter_dict[tag_remove.label];
|
||||
|
||||
// hide everything?
|
||||
if(!keys(me.tag_filter_dict).length) {
|
||||
$(me.tag_filters).slideUp(); // hide
|
||||
}
|
||||
|
||||
// run
|
||||
me.run();
|
||||
}
|
||||
|
||||
// add to dict
|
||||
me.tag_filter_dict[tag.label] = filter_tag;
|
||||
$ds(me.tag_filters);
|
||||
|
||||
// run
|
||||
me.run();
|
||||
}
|
||||
this.run = function() {
|
||||
this.list.run();
|
||||
}
|
||||
|
||||
this.make_search_bar();
|
||||
this.make_list();
|
||||
|
||||
}
|
||||
|
||||
// single kb question
|
||||
// "question
|
||||
// points | tag 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;
|
||||
//loadpage('question-view', function() { pscript.question_view(q.id, q.txt) })
|
||||
}
|
||||
|
||||
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);
|
||||
37
knowledge_base/page/questions/questions.py
Normal file
37
knowledge_base/page/questions/questions.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import webnotes
|
||||
|
||||
from webnotes.utils import load_json, cint, cstr
|
||||
|
||||
# add a new question
|
||||
def add_question(arg):
|
||||
args = load_json(arg)
|
||||
|
||||
from webnotes.model.doc import Document
|
||||
d = Document('Question')
|
||||
d.question = args['question'].title()
|
||||
d.points = 1
|
||||
d.save(1)
|
||||
|
||||
if args['suggest']:
|
||||
from my_company.page.my_company.my_company import post_comment
|
||||
for s in args['suggest']:
|
||||
if s:
|
||||
post_comment({
|
||||
'uid': s,
|
||||
'comment': 'Please help me and answer the question "%s" in the Knowledge Base' % d.question,
|
||||
'notify': 1
|
||||
})
|
||||
|
||||
|
||||
def vote(arg):
|
||||
args = load_json(arg)
|
||||
|
||||
res = webnotes.conn.sql("select points, _users_voted from `tab%s` where name=%s" % (args['dt'], '%s'), args['dn'])[0]
|
||||
p = cint(res[0])
|
||||
p = args['vote']=='up' and p+1 or p-1
|
||||
|
||||
# update
|
||||
webnotes.conn.sql("update `tab%s` set points=%s, _users_voted=%s where name=%s" % (args['dt'], '%s', '%s', '%s'), \
|
||||
(p, cstr(res[1]) + ',' + webnotes.user.name, args['dn']))
|
||||
|
||||
return p
|
||||
26
knowledge_base/page/questions/questions.txt
Normal file
26
knowledge_base/page/questions/questions.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
[
|
||||
{
|
||||
'content': None,
|
||||
'creation': '2011-05-09 11:04:37',
|
||||
'docstatus': 0,
|
||||
'doctype': 'Page',
|
||||
'icon': None,
|
||||
'idx': None,
|
||||
'menu_index': None,
|
||||
'modified': '2011-03-29 13:53:57',
|
||||
'modified_by': 'Administrator',
|
||||
'module': 'Knowledge Base',
|
||||
'name': 'Questions',
|
||||
'owner': 'Administrator',
|
||||
'page_name': 'Questions',
|
||||
'parent': None,
|
||||
'parent_node': None,
|
||||
'parentfield': None,
|
||||
'parenttype': None,
|
||||
'script': None,
|
||||
'show_in_menu': None,
|
||||
'standard': 'Yes',
|
||||
'static_content': None,
|
||||
'style': None
|
||||
}
|
||||
]
|
||||
Reference in New Issue
Block a user