Browse Source

[feature] Linked With now shows parent Documents

version-14
Rushabh Mehta 12 years ago
parent
commit
a17bd79ed8
6 changed files with 51 additions and 26 deletions
  1. +3
    -3
      public/js/wn/form/layout.js
  2. +13
    -6
      public/js/wn/form/linked_with.js
  3. +6
    -0
      public/js/wn/misc/utils.js
  4. +8
    -8
      public/js/wn/ui/listing.js
  5. +20
    -8
      webnotes/model/doctype.py
  6. +1
    -1
      webnotes/widgets/form/load.py

+ 3
- 3
public/js/wn/form/layout.js View File

@@ -187,9 +187,9 @@ wn.ui.form.Layout = Class.extend({
},
focus_on_next_field: function(start_idx, 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;
}
}


+ 13
- 6
public/js/wn/form/linked_with.js View File

@@ -17,10 +17,16 @@ wn.ui.form.LinkedWith = Class.extend({
make_dialog: function() {
var me = this;
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({
width: 700,
hide_on_page_refresh: true,
@@ -50,8 +56,6 @@ wn.ui.form.LinkedWith = Class.extend({
this.dialog.get_input("list_by").change(function() {
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) {
me.make_listing();
@@ -97,7 +101,10 @@ wn.ui.form.LinkedWith = Class.extend({
});
me.lst.filter_list.show_filters(true);
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;
}
});

+ 6
- 0
public/js/wn/misc/utils.js View File

@@ -153,6 +153,9 @@ wn.utils = {
},
sort: function(list, key, compare_type, reverse) {
if(list.length < 2)
return list;

var sort_fn = {
"string": function(a, b) {
return cstr(a[key]).localeCompare(cstr(b[key]));
@@ -161,6 +164,9 @@ wn.utils = {
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]);


+ 8
- 8
public/js/wn/ui/listing.js View File

@@ -349,9 +349,9 @@ wn.ui.Listing = Class.extend({
query += ' LIMIT ' + this.start + ',' + (this.page_length+1);
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);
//this.filter_list.show_filters(true);
if(filter) {
var v = filter.field.get_parsed_value();
if(v.indexOf(label)!=-1) {
@@ -361,21 +361,21 @@ wn.ui.Listing = Class.extend({
// second filter set for this field
if(fieldname=='_user_tags') {
// and for tags
this.filter_list.add_filter(this.doctype, fieldname,
this.filter_list.add_filter(doctype, fieldname,
'like', '%' + label);
} else {
// or for rest using "in"
filter.set_values(this.doctype, fieldname, 'in', v + ', ' + label);
filter.set_values(doctype, fieldname, 'in', v + ', ' + label);
}
}
} else {
// no filter for this item,
// 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 {
this.filter_list.add_filter(this.doctype, fieldname, '=', label);
this.filter_list.add_filter(doctype, fieldname, '=', label);
}
}
}

+ 20
- 8
webnotes/model/doctype.py View File

@@ -48,7 +48,6 @@ def get(doctype, processed=False, cached=True):
doclist = from_cache(doctype, processed)
if doclist:
if processed:
add_linked_with(doclist)
update_language(doclist)
return DocTypeDocList(doclist)
@@ -70,16 +69,13 @@ def get(doctype, processed=False, cached=True):
add_print_formats(doclist)
add_search_fields(doclist)
add_workflows(doclist)

# add validators
#add_validators(doctype, doclist)
add_linked_with(doclist)
to_cache(doctype, processed, doclist)

if processed:
add_linked_with(doclist)
update_language(doclist)
return DocTypeDocList(doclist)

def load_docfield_types():
@@ -188,11 +184,27 @@ def add_linked_with(doclist):
links = webnotes.conn.sql("""select parent, fieldname from tabDocField
where (fieldtype="Link" and options=%s)
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)
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):
""" load doclist from cache.


+ 1
- 1
webnotes/widgets/form/load.py View File

@@ -118,7 +118,7 @@ def add_assignments(dt, dn):
})
return cl
@webnotes.whitelist()
def get_badge_info(doctypes, filters):
filters = json.loads(filters)


Loading…
Cancel
Save