@@ -187,9 +187,9 @@ wn.ui.form.Layout = Class.extend({ | |||||
}, | }, | ||||
focus_on_next_field: function(start_idx, fields) { | focus_on_next_field: function(start_idx, fields) { | ||||
// loop to find next eligible fields | // loop to find next eligible fields | ||||
for(var ii= start_idx + 1, len = fields.length; ii < len; ii++) { | |||||
if(fields[ii].disp_status==="Write") { | |||||
this.set_focus(fields[ii]); | |||||
for(var i= start_idx + 1, len = fields.length; i < len; i++) { | |||||
if(fields[i].disp_status==="Write" && !in_list(wn.model.no_value_type, fields[i].df.fieldtype)) { | |||||
this.set_focus(fields[i]); | |||||
break; | break; | ||||
} | } | ||||
} | } | ||||
@@ -17,10 +17,16 @@ wn.ui.form.LinkedWith = Class.extend({ | |||||
make_dialog: function() { | make_dialog: function() { | ||||
var me = this; | var me = this; | ||||
this.linked_with = this.frm.meta.__linked_with; | this.linked_with = this.frm.meta.__linked_with; | ||||
var links = $.map(keys(this.linked_with), function(v) { | |||||
return in_list(wn.boot.profile.can_get_report, v) ? {value:v, label:wn._(v)} : null | |||||
}).sort(function(a, b) { return a.label > b.label ? 1 : -1 }); | |||||
var links = []; | |||||
$.each(this.linked_with, function(doctype, tmp) { | |||||
if(wn.model.can_get_report(doctype)) { | |||||
links.push({label: wn._(doctype), value: doctype}); | |||||
} | |||||
}); | |||||
links = wn.utils.sort(links, "label"); | |||||
this.dialog = new wn.ui.Dialog({ | this.dialog = new wn.ui.Dialog({ | ||||
width: 700, | width: 700, | ||||
hide_on_page_refresh: true, | hide_on_page_refresh: true, | ||||
@@ -50,8 +56,6 @@ wn.ui.form.LinkedWith = Class.extend({ | |||||
this.dialog.get_input("list_by").change(function() { | this.dialog.get_input("list_by").change(function() { | ||||
me.doctype = me.dialog.get_input("list_by").val(); | me.doctype = me.dialog.get_input("list_by").val(); | ||||
me.is_table = (!in_list(wn.boot.profile.can_read, me.doctype) && | |||||
in_list(wn.boot.profile.can_get_report, me.doctype)) | |||||
wn.model.with_doctype(me.doctype, function(r) { | wn.model.with_doctype(me.doctype, function(r) { | ||||
me.make_listing(); | me.make_listing(); | ||||
@@ -97,7 +101,10 @@ wn.ui.form.LinkedWith = Class.extend({ | |||||
}); | }); | ||||
me.lst.filter_list.show_filters(true); | me.lst.filter_list.show_filters(true); | ||||
me.lst.filter_list.clear_filters(); | me.lst.filter_list.clear_filters(); | ||||
me.lst.set_filter(me.linked_with[me.doctype], me.frm.doc.name); | |||||
var link_doctype = me.linked_with[me.doctype].child_doctype || me.doctype; | |||||
me.lst.set_filter(me.linked_with[me.doctype].fieldname, me.frm.doc.name, link_doctype); | |||||
me.lst.listview = me.listview; | me.lst.listview = me.listview; | ||||
} | } | ||||
}); | }); |
@@ -153,6 +153,9 @@ wn.utils = { | |||||
}, | }, | ||||
sort: function(list, key, compare_type, reverse) { | sort: function(list, key, compare_type, reverse) { | ||||
if(list.length < 2) | |||||
return list; | |||||
var sort_fn = { | var sort_fn = { | ||||
"string": function(a, b) { | "string": function(a, b) { | ||||
return cstr(a[key]).localeCompare(cstr(b[key])); | return cstr(a[key]).localeCompare(cstr(b[key])); | ||||
@@ -161,6 +164,9 @@ wn.utils = { | |||||
return flt(a[key]) - flt(b[key]); | return flt(a[key]) - flt(b[key]); | ||||
} | } | ||||
}; | }; | ||||
if(!compare_type) | |||||
compare_type = typeof list[0][key]==="string" ? "string" : "number"; | |||||
list.sort(sort_fn[compare_type]); | list.sort(sort_fn[compare_type]); | ||||
@@ -349,9 +349,9 @@ wn.ui.Listing = Class.extend({ | |||||
query += ' LIMIT ' + this.start + ',' + (this.page_length+1); | query += ' LIMIT ' + this.start + ',' + (this.page_length+1); | ||||
return query | return query | ||||
}, | }, | ||||
set_filter: function(fieldname, label) { | |||||
set_filter: function(fieldname, label, doctype) { | |||||
if(!doctype) doctype = this.doctype; | |||||
var filter = this.filter_list.get_filter(fieldname); | var filter = this.filter_list.get_filter(fieldname); | ||||
//this.filter_list.show_filters(true); | |||||
if(filter) { | if(filter) { | ||||
var v = filter.field.get_parsed_value(); | var v = filter.field.get_parsed_value(); | ||||
if(v.indexOf(label)!=-1) { | if(v.indexOf(label)!=-1) { | ||||
@@ -361,21 +361,21 @@ wn.ui.Listing = Class.extend({ | |||||
// second filter set for this field | // second filter set for this field | ||||
if(fieldname=='_user_tags') { | if(fieldname=='_user_tags') { | ||||
// and for tags | // and for tags | ||||
this.filter_list.add_filter(this.doctype, fieldname, | |||||
this.filter_list.add_filter(doctype, fieldname, | |||||
'like', '%' + label); | 'like', '%' + label); | ||||
} else { | } else { | ||||
// or for rest using "in" | // or for rest using "in" | ||||
filter.set_values(this.doctype, fieldname, 'in', v + ', ' + label); | |||||
filter.set_values(doctype, fieldname, 'in', v + ', ' + label); | |||||
} | } | ||||
} | } | ||||
} else { | } else { | ||||
// no filter for this item, | // no filter for this item, | ||||
// setup one | // setup one | ||||
if(fieldname=='_user_tags') { | |||||
this.filter_list.add_filter(this.doctype, fieldname, | |||||
'like', '%' + label); | |||||
if(fieldname==='_user_tags') { | |||||
this.filter_list.add_filter(doctype, fieldname, | |||||
'like', '%' + label); | |||||
} else { | } else { | ||||
this.filter_list.add_filter(this.doctype, fieldname, '=', label); | |||||
this.filter_list.add_filter(doctype, fieldname, '=', label); | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -48,7 +48,6 @@ def get(doctype, processed=False, cached=True): | |||||
doclist = from_cache(doctype, processed) | doclist = from_cache(doctype, processed) | ||||
if doclist: | if doclist: | ||||
if processed: | if processed: | ||||
add_linked_with(doclist) | |||||
update_language(doclist) | update_language(doclist) | ||||
return DocTypeDocList(doclist) | return DocTypeDocList(doclist) | ||||
@@ -70,16 +69,13 @@ def get(doctype, processed=False, cached=True): | |||||
add_print_formats(doclist) | add_print_formats(doclist) | ||||
add_search_fields(doclist) | add_search_fields(doclist) | ||||
add_workflows(doclist) | add_workflows(doclist) | ||||
# add validators | |||||
#add_validators(doctype, doclist) | |||||
add_linked_with(doclist) | |||||
to_cache(doctype, processed, doclist) | to_cache(doctype, processed, doclist) | ||||
if processed: | if processed: | ||||
add_linked_with(doclist) | |||||
update_language(doclist) | update_language(doclist) | ||||
return DocTypeDocList(doclist) | return DocTypeDocList(doclist) | ||||
def load_docfield_types(): | def load_docfield_types(): | ||||
@@ -188,11 +184,27 @@ def add_linked_with(doclist): | |||||
links = webnotes.conn.sql("""select parent, fieldname from tabDocField | links = webnotes.conn.sql("""select parent, fieldname from tabDocField | ||||
where (fieldtype="Link" and options=%s) | where (fieldtype="Link" and options=%s) | ||||
or (fieldtype="Select" and options=%s)""", (doctype, "link:"+ doctype)) | or (fieldtype="Select" and options=%s)""", (doctype, "link:"+ doctype)) | ||||
links += webnotes.conn.sql("""select dt, fieldname from `tabCustom Field` | |||||
links += webnotes.conn.sql("""select dt as parent, fieldname from `tabCustom Field` | |||||
where (fieldtype="Link" and options=%s) | where (fieldtype="Link" and options=%s) | ||||
or (fieldtype="Select" and options=%s)""", (doctype, "link:"+ doctype)) | or (fieldtype="Select" and options=%s)""", (doctype, "link:"+ doctype)) | ||||
links = dict(links) | |||||
ret = {} | |||||
for dt in links: | |||||
ret[dt] = { "fieldname": links[dt] } | |||||
for grand_parent, options in webnotes.conn.sql("""select parent, options from tabDocField | |||||
where fieldtype="Table" | |||||
and options in (select name from tabDocType | |||||
where istable=1 and name in (%s))""" % ", ".join(["%s"] * len(links)) ,tuple(links)): | |||||
ret[grand_parent] = {"child_doctype": options, "fieldname": links[options] } | |||||
if options in ret: | |||||
del ret[options] | |||||
doclist[0].fields["__linked_with"] = dict(list(set(links))) | |||||
doclist[0].fields["__linked_with"] = ret | |||||
def from_cache(doctype, processed): | def from_cache(doctype, processed): | ||||
""" load doclist from cache. | """ load doclist from cache. | ||||
@@ -118,7 +118,7 @@ def add_assignments(dt, dn): | |||||
}) | }) | ||||
return cl | return cl | ||||
@webnotes.whitelist() | @webnotes.whitelist() | ||||
def get_badge_info(doctypes, filters): | def get_badge_info(doctypes, filters): | ||||
filters = json.loads(filters) | filters = json.loads(filters) | ||||