fixes in communication doctype

This commit is contained in:
Anand Doshi 2012-05-31 18:23:16 +05:30
parent a6708fb748
commit c5d857896e
4 changed files with 21 additions and 113 deletions

View File

@ -1,5 +1,5 @@
cur_frm.cscript.refresh = function(doc, dt, dn) {
if(!doc.islocal) {
if(!doc.__islocal) {
var field_list = ['lead', 'customer', 'supplier', 'contact', 'opportunity',
'quotation', 'support_ticket'];
var hide_list = [];
@ -52,6 +52,7 @@ cur_frm.cscript.render_communication_list = function(doc, dt, dn) {
{width: '12%', content:'communication_date',
css: {'text-align': 'right', 'color':'#777'}}
],
});
cur_frm.cscript.render_list(doc, 'Communication', cur_frm.communication_html,
@ -65,8 +66,7 @@ cur_frm.cscript.render_communication_list = function(doc, dt, dn) {
// Render List
cur_frm.cscript.render_list = function(doc, doctype, wrapper, ListView,
new_doc_constructor) {
cur_frm.cscript.render_list = function(doc, doctype, wrapper, ListView, make_new_doc) {
wn.model.with_doctype(doctype, function(r) {
if(r && r['403']) {
return;
@ -76,86 +76,14 @@ cur_frm.cscript.render_list = function(doc, doctype, wrapper, ListView,
default_filters: [
[doctype, doc.doctype.toLowerCase(), '=', doc.name],
],
new_doc_constructor: new_doc_constructor || null,
});
if (make_new_doc) {
RecordListView = RecordListView.extend({
make_new_doc: make_new_doc,
});
}
var record_list_view = new RecordListView(doctype, wrapper, ListView);
});
}
// Transaction List related functions
cur_frm.cscript.render_list2 = function(parent, doc, doctype, args) {
$(parent).css({ 'padding-top': '10px' });
cur_frm.transaction_list = new wn.ui.Listing({
parent: parent,
page_length: 10,
get_query: function() {
return cur_frm.cscript.get_query_list({
parent: doc.doctype.toLowerCase(),
parent_name: doc.name,
doctype: doctype,
fields: (function() {
var fields = [];
for(var i in args) {
fields.push(args[i].fieldname);
}
return fields.join(", ");
})(),
});
},
as_dict: 1,
no_result_message: repl('No %(doctype)s created for this %(parent)s',
{ doctype: doctype, parent: doc.doctype }),
render_row: function(wrapper, data) {
render_html = cur_frm.cscript.render_list_row(data, args, doctype);
$(wrapper).html(render_html);
},
});
cur_frm.transaction_list.run();
}
cur_frm.cscript.render_list_row = function(data, args, doctype) {
var content = [];
var currency = data.currency;
for (var a in args) {
for (var d in data) {
if (args[a].fieldname === d && args[a].fieldname !== 'currency') {
if (args[a].type === 'Link') {
data[d] = repl('<a href="#!Form/%(doctype)s/%(name)s">\
%(name)s</a>', { doctype: doctype, name: data[d]});
} else if (args[a].type === 'Currency') {
data[d] = currency + " " + fmt_money(data[d]);
} else if (args[a].type === 'Percentage') {
data[d] = flt(data[d]) + '%';
} else if (args[a].type === 'Date') {
data[d] = wn.datetime.only_date(data[d]);
}
if (args[a].style == undefined) {
args[a].style = '';
}
data[d] = repl('\
<td width="%(width)s" title="%(title)s" style="%(style)s">\
%(content)s</td>',
{
content: data[d],
width: args[a].width,
title: args[a].label,
style: args[a].style,
});
content.push(data[d]);
break;
}
}
}
content = content.join("\n");
return '<table><tr>' + content + '</tr></table>';
}
cur_frm.cscript.get_query_list = function(args) {
var query = repl("\
select %(fields)s from `tab%(doctype)s` \
where %(parent)s = '%(parent_name)s' \
order by modified desc", args);
return query;
}

View File

@ -5,7 +5,7 @@
{
'creation': '2012-05-29 16:56:41',
'docstatus': 0,
'modified': '2012-05-31 14:46:44',
'modified': '2012-05-31 16:14:39',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -266,28 +266,9 @@
# DocField
{
'doctype': u'DocField',
'fieldname': u'next_action',
'fieldname': u'communication_medium',
'fieldtype': u'Select',
'label': u'Next Action',
'options': u'\nFollow Up\nCreate Opportunity\nSend Quotation\nCreate Support Ticket\nCreate Customer Issue',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'next_action_date',
'fieldtype': u'Date',
'label': u'Next Action Date',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'medium',
'fieldtype': u'Select',
'label': u'Medium',
'label': u'Communication Medium',
'options': u'\nChat\nPhone\nEmail\nSMS\nVisit\nOther',
'permlevel': 0
},
@ -333,9 +314,9 @@
'colour': u'White:FFF',
'default': u'__user',
'doctype': u'DocField',
'fieldname': u'profile',
'fieldname': u'user',
'fieldtype': u'Link',
'label': u'Profile',
'label': u'User',
'options': u'Profile',
'permlevel': 1
},

View File

@ -305,9 +305,9 @@ if(this.show_filters){this.make_filters();}},add_button:function(label,click,ico
if(icon){$('<i>').addClass(icon).appendTo($button);}
$button.html(label).click(click);return $button}},show_view:function($btn,$div,$btn_unsel,$div_unsel){$btn_unsel.removeClass('btn-info');$btn_unsel.find('i').removeClass('icon-white');$div_unsel.toggle(false);$btn.addClass('btn-info');$btn.find('i').addClass('icon-white');$div.toggle(true);},set_events:function(){var me=this;this.$w.find('.btn-more').click(function(){me.run({append:true});});if(this.title){this.$w.find('h3').html(this.title).toggle(true);}
if(!(this.hide_refresh||this.no_refresh)){this.add_button('Refresh',function(){me.run();},'icon-refresh');}
if(this.new_doctype){this.add_button('New '+this.new_doctype,function(){me.new_doc_constructor?me.new_doc_constructor(me.new_doctype):newdoc(me.new_doctype);},'icon-plus');}
if(this.new_doctype){this.add_button('New '+this.new_doctype,function(){me.make_new_doc(me.new_doctype);},'icon-plus');}
if(me.show_filters){this.add_button('Show Filters',function(){me.filter_list.show_filters();},'icon-search').addClass('btn-filter');}
if(me.no_toolbar||me.hide_toolbar){me.$w.find('.list-toolbar-wrapper').toggle(false);}},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
if(me.no_toolbar||me.hide_toolbar){me.$w.find('.list-toolbar-wrapper').toggle(false);}},make_new_doc:function(new_doctype){new_doc(new_doctype);},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
this.onrun=a0;if(a0&&a0.callback)
this.onrun=a0.callback;if(!a1&&!(a0&&a0.append))
this.start=0;me.set_working(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(a0),callback:function(r){me.set_working(false);me.render_results(r)},no_spinner:this.opts.no_loading});},set_working:function(flag){this.$w.find('.img-load').toggle(flag);},get_call_args:function(opts){if(!this.method){this.query=this.get_query?this.get_query():this.query;this.add_limits();var args={query_max:this.query_max,as_dict:1}
@ -969,7 +969,7 @@ wn.views.DocListView=wn.ui.Listing.extend({init:function(doctype){this.doctype=d
<div style="clear: both"></div>\
</div>',{label:this.label}));this.appframe=new wn.ui.AppFrame(this.$page.find('.appframe-area'));wn.views.breadcrumbs($('<span>').appendTo(this.appframe.$titlebar),locals.DocType[this.doctype].module);},setup:function(){var me=this;me.can_delete=wn.model.can_delete(me.doctype);me.meta=locals.DocType[me.doctype];me.$page.find('.wnlist-area').empty(),me.setup_docstatus_filter();me.setup_listview();me.init_list();me.init_stats();me.make_report_button();me.add_delete_option();},make_report_button:function(){var me=this;if(wn.boot.profile.can_get_report.indexOf(this.doctype)!=-1){this.appframe.add_button('Build Report',function(){wn.set_route('Report2',me.doctype);},'icon-th')}},setup_docstatus_filter:function(){var me=this;this.can_submit=$.map(locals.DocPerm,function(d){if(d.parent==me.meta.name&&d.submit)return 1
else return null;}).length;if(this.can_submit){this.$page.find('.show-docstatus').removeClass('hide');this.$page.find('.show-docstatus input').click(function(){me.run();})}},setup_listview:function(){if(this.meta.__listjs){eval(this.meta.__listjs);this.listview=new wn.doclistviews[this.doctype](this);}else{this.listview=new wn.views.ListView(this);}
this.listview.parent=this;this.wrapper=this.$page.find('.wnlist-area');this.page_length=20;this.allow_delete=true;},init_list:function(auto_run){this.make({method:'webnotes.widgets.doclistview.get',get_args:this.get_args,parent:this.wrapper,start:0,page_length:this.page_length,show_filters:true,show_grid:true,new_doctype:this.doctype,new_doc_constructor:this.new_doc_constructor||null,allow_delete:this.allow_delete,no_result_message:this.make_no_result(),columns:this.listview.fields});if((auto_run!==false)&&(auto_run!==0))this.run();},make_no_result:function(){return repl('<div class="well"><p>No %(doctype_label)s found</p>\
this.listview.parent=this;this.wrapper=this.$page.find('.wnlist-area');this.page_length=20;this.allow_delete=true;},init_list:function(auto_run){this.make({method:'webnotes.widgets.doclistview.get',get_args:this.get_args,parent:this.wrapper,start:0,page_length:this.page_length,show_filters:true,show_grid:true,new_doctype:this.doctype,allow_delete:this.allow_delete,no_result_message:this.make_no_result(),columns:this.listview.fields});if((auto_run!==false)&&(auto_run!==0))this.run();},make_no_result:function(){return repl('<div class="well"><p>No %(doctype_label)s found</p>\
%(description)s\
<hr>\
<p><button class="btn btn-info btn-small"\
@ -1022,8 +1022,7 @@ if(diff==2){data.when='2 days ago'}
if(data.docstatus==0||data.docstatus==null){data.docstatus_icon='icon-pencil';data.docstatus_title='Editable';}else if(data.docstatus==1){data.docstatus_icon='icon-lock';data.docstatus_title='Submitted';}else if(data.docstatus==2){data.docstatus_icon='icon-remove';data.docstatus_title='Cancelled';}
for(key in data){if(data[key]==null){data[key]='';}}},add_user_tags:function(parent,data){var me=this;if(data._user_tags){if($(parent).html().length>0){$(parent).append('<br />');}
$.each(data._user_tags.split(','),function(i,t){if(t){$('<span class="label label-info" style="cursor: pointer; line-height: 200%">'
+strip(t)+'</span>').click(function(){me.doclistview.set_filter('_user_tags',$(this).text())}).appendTo(parent);}});}},show_hide_check_column:function(){if(!this.doclistview.can_delete){this.columns=$.map(this.columns,function(v,i){if(v.content!='check')return v});}}})
wn.provide('wn.views.RecordListView');wn.views.RecordListView=wn.views.DocListView.extend({init:function(doctype,wrapper,ListView){this.doctype=doctype;this.wrapper=wrapper;this.listview=new ListView(this);this.listview.parent=this;this.setup();},setup:function(){var me=this;me.page_length=10;$(me.wrapper).empty();me.init_list();},get_args:function(){var args=this._super();$.each((this.default_filters||[]),function(i,f){args.filters.push(f);});args.docstatus=args.docstatus.concat((this.default_docstatus||[]));return args;},});
+strip(t)+'</span>').click(function(){me.doclistview.set_filter('_user_tags',$(this).text())}).appendTo(parent);}});}},show_hide_check_column:function(){if(!this.doclistview.can_delete){this.columns=$.map(this.columns,function(v,i){if(v.content!='check')return v});}}});wn.provide('wn.views.RecordListView');wn.views.RecordListView=wn.views.DocListView.extend({init:function(doctype,wrapper,ListView){this.doctype=doctype;this.wrapper=wrapper;this.listview=new ListView(this);this.listview.parent=this;this.setup();},setup:function(){var me=this;me.page_length=10;$(me.wrapper).empty();me.init_list();},get_args:function(){var args=this._super();$.each((this.default_filters||[]),function(i,f){args.filters.push(f);});args.docstatus=args.docstatus.concat((this.default_docstatus||[]));return args;},});
/*
* lib/js/wn/views/formview.js
*/

View File

@ -192,9 +192,9 @@ if(this.show_filters){this.make_filters();}},add_button:function(label,click,ico
if(icon){$('<i>').addClass(icon).appendTo($button);}
$button.html(label).click(click);return $button}},show_view:function($btn,$div,$btn_unsel,$div_unsel){$btn_unsel.removeClass('btn-info');$btn_unsel.find('i').removeClass('icon-white');$div_unsel.toggle(false);$btn.addClass('btn-info');$btn.find('i').addClass('icon-white');$div.toggle(true);},set_events:function(){var me=this;this.$w.find('.btn-more').click(function(){me.run({append:true});});if(this.title){this.$w.find('h3').html(this.title).toggle(true);}
if(!(this.hide_refresh||this.no_refresh)){this.add_button('Refresh',function(){me.run();},'icon-refresh');}
if(this.new_doctype){this.add_button('New '+this.new_doctype,function(){me.new_doc_constructor?me.new_doc_constructor(me.new_doctype):newdoc(me.new_doctype);},'icon-plus');}
if(this.new_doctype){this.add_button('New '+this.new_doctype,function(){me.make_new_doc(me.new_doctype);},'icon-plus');}
if(me.show_filters){this.add_button('Show Filters',function(){me.filter_list.show_filters();},'icon-search').addClass('btn-filter');}
if(me.no_toolbar||me.hide_toolbar){me.$w.find('.list-toolbar-wrapper').toggle(false);}},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
if(me.no_toolbar||me.hide_toolbar){me.$w.find('.list-toolbar-wrapper').toggle(false);}},make_new_doc:function(new_doctype){new_doc(new_doctype);},make_filters:function(){this.filter_list=new wn.ui.FilterList({listobj:this,$parent:this.$w.find('.list-filters').toggle(true),doctype:this.doctype,filter_fields:this.filter_fields});},clear:function(){this.data=[];this.$w.find('.result-list').empty();this.$w.find('.result').toggle(true);this.$w.find('.no-result').toggle(false);this.start=0;},run:function(){var me=this;var a0=arguments[0];var a1=arguments[1];if(a0&&typeof a0=='function')
this.onrun=a0;if(a0&&a0.callback)
this.onrun=a0.callback;if(!a1&&!(a0&&a0.append))
this.start=0;me.set_working(true);wn.call({method:this.opts.method||'webnotes.widgets.query_builder.runquery',args:this.get_call_args(a0),callback:function(r){me.set_working(false);me.render_results(r)},no_spinner:this.opts.no_loading});},set_working:function(flag){this.$w.find('.img-load').toggle(flag);},get_call_args:function(opts){if(!this.method){this.query=this.get_query?this.get_query():this.query;this.add_limits();var args={query_max:this.query_max,as_dict:1}