2012-02-23 07:05:32 +00:00
|
|
|
// ERPNext - web based ERP (http://erpnext.com)
|
|
|
|
// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
// question toolbar
|
|
|
|
// contains - voting widget / tag list and user info / timestamp
|
|
|
|
// By XXXXXX on YYYYY
|
|
|
|
|
|
|
|
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.make_timestamp();
|
2012-08-07 06:42:55 +00:00
|
|
|
this.make_answers();
|
2011-06-08 09:07:15 +00:00
|
|
|
if(this.with_tags)
|
|
|
|
this.make_tags();
|
2012-04-18 11:44:33 +00:00
|
|
|
this.setup_del();
|
2011-06-08 09:07:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2011-08-30 10:07:46 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// allow system manager to delete questions / answers
|
|
|
|
if(has_common(user_roles, ['Administrator', 'System Manager'])) {
|
2012-04-18 11:44:33 +00:00
|
|
|
this.line1.innerHTML += ' | <a style="cursor:pointer;"\
|
|
|
|
class="del-link">delete</a>';
|
2011-08-30 10:07:46 +00:00
|
|
|
}
|
2011-06-08 09:07:15 +00:00
|
|
|
}
|
|
|
|
|
2012-08-07 06:42:55 +00:00
|
|
|
this.make_answers = function() {
|
|
|
|
if(this.doctype=='Question') {
|
|
|
|
if(this.det.answers==0) {
|
|
|
|
this.line1.innerHTML += ' | no answers';
|
|
|
|
} else if(this.det.answers==1) {
|
|
|
|
this.line1.innerHTML += ' | 1 answer';
|
|
|
|
} else {
|
|
|
|
this.line1.innerHTML += ' | '+this.det.answers+' answers';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
this.make_tags = function() {
|
2012-02-24 09:37:39 +00:00
|
|
|
this.line1.innerHTML += ' | '
|
|
|
|
this.tags_area = $a(this.line1, 'span', 'kb-tags')
|
2011-06-08 09:07:15 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2012-04-18 11:44:33 +00:00
|
|
|
this.setup_del = function() {
|
|
|
|
$(this.line1).find('.del-link').click(function() {
|
|
|
|
console.log(1);
|
|
|
|
this.innerHTML = 'deleting...';
|
|
|
|
this.disabled = 1;
|
2012-04-20 05:47:10 +00:00
|
|
|
$c_page('utilities', 'questions', 'delete', {
|
2012-04-18 11:44:33 +00:00
|
|
|
dt: me.doctype, dn: me.det.name}, function(r,rt) {
|
|
|
|
// reload the list
|
|
|
|
kb.list.run()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
this.make();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// displays an editable text,
|
|
|
|
// needs parent, text, disp_class, inp_class
|
|
|
|
// dt, dn
|
|
|
|
|
|
|
|
EditableText = function(args) {
|
|
|
|
$.extend(this, args);
|
|
|
|
var me = this;
|
|
|
|
|
2012-04-18 11:25:43 +00:00
|
|
|
me.$w = $(repl('<div class="ed-text">\
|
|
|
|
<div class="ed-text-display %(disp_class)s"></div>\
|
2012-04-19 12:18:57 +00:00
|
|
|
<a class="ed-text-edit" style="cursor: pointer; float: right; margin-top: -16px;">[edit]</a>\
|
|
|
|
<textarea class="ed-text-input %(inp_class)s hide"></textarea>\
|
2012-08-07 07:23:49 +00:00
|
|
|
<div class="help hide"><br>Formatted as <a href="#markdown-reference"\
|
2012-04-18 11:29:37 +00:00
|
|
|
target="_blank">markdown</a></div>\
|
2012-04-18 11:25:43 +00:00
|
|
|
<button class="btn btn-small btn-info hide ed-text-save">Save</button>\
|
|
|
|
<a class="ed-text-cancel hide" style="cursor: pointer;">Cancel</a>\
|
|
|
|
</div>', args)).appendTo(me.parent);
|
2011-06-08 09:07:15 +00:00
|
|
|
|
2012-04-18 11:25:43 +00:00
|
|
|
this.set_display = function(txt) {
|
|
|
|
me.$w.find('.ed-text-display').html(wn.markdown(txt));
|
|
|
|
me.text = txt;
|
|
|
|
}
|
2011-06-08 09:07:15 +00:00
|
|
|
|
2012-04-18 11:25:43 +00:00
|
|
|
this.set_display(me.text);
|
|
|
|
|
|
|
|
if(me.height) me.$w.find('.ed-text-input').css('height', me.height);
|
|
|
|
|
|
|
|
// edit
|
|
|
|
me.$w.find('.ed-text-edit').click(function() {
|
|
|
|
me.$w.find('.ed-text-input').val(me.text);
|
2011-06-08 09:07:15 +00:00
|
|
|
me.show_as_input();
|
2012-04-18 11:25:43 +00:00
|
|
|
})
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
// save button - save the new text
|
2012-04-18 11:25:43 +00:00
|
|
|
me.$w.find('.ed-text-save').click(
|
|
|
|
function() {
|
|
|
|
var v = me.$w.find('.ed-text-input').val();
|
|
|
|
// check if text is written
|
|
|
|
if(!v) {
|
|
|
|
msgprint('Please write something!');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var btn = this;
|
|
|
|
$(btn).set_working();
|
2012-04-20 05:47:10 +00:00
|
|
|
$c_page('utilities', 'question_view', 'update_item', {
|
2012-04-18 11:25:43 +00:00
|
|
|
dt: me.dt, dn: me.dn, fn: me.fieldname, text: v
|
|
|
|
},
|
|
|
|
function(r) {
|
|
|
|
$(btn).done_working();
|
|
|
|
if(r.exc) {msgprint(r.exc); return; }
|
|
|
|
me.set_display(v);
|
|
|
|
me.show_as_text();
|
|
|
|
});
|
2011-06-08 09:07:15 +00:00
|
|
|
}
|
2012-04-18 11:25:43 +00:00
|
|
|
)
|
|
|
|
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
// cancel button
|
2012-04-18 11:25:43 +00:00
|
|
|
me.$w.find('.ed-text-cancel').click(function() {
|
2011-06-08 09:07:15 +00:00
|
|
|
me.show_as_text();
|
2012-04-18 11:25:43 +00:00
|
|
|
})
|
2011-06-08 09:07:15 +00:00
|
|
|
|
|
|
|
this.show_as_text = function() {
|
2012-04-18 11:25:43 +00:00
|
|
|
me.$w.find('.ed-text-display, .ed-text-edit').toggle(true);
|
|
|
|
me.$w.find('.ed-text-input, .ed-text-save, .ed-text-cancel, .help').toggle(false);
|
2011-06-08 09:07:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.show_as_input = function() {
|
2012-04-18 11:25:43 +00:00
|
|
|
me.$w.find('.ed-text-display, .ed-text-edit').toggle(false);
|
|
|
|
me.$w.find('.ed-text-input, .ed-text-save, .ed-text-cancel, .help').toggle(true);
|
|
|
|
}
|
2011-06-08 09:07:15 +00:00
|
|
|
|
2012-04-20 05:47:10 +00:00
|
|
|
}
|