From b5fdac9823062500aac811f64f9077152f10bf52 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 3 Dec 2012 14:32:38 +0530 Subject: [PATCH] added get_doclist method in model.js --- public/js/wn/model.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/public/js/wn/model.js b/public/js/wn/model.js index 0d0ac06ae1..a7f40b81f3 100644 --- a/public/js/wn/model.js +++ b/public/js/wn/model.js @@ -110,5 +110,29 @@ wn.model = { get: function(doctype, filters) { if(!locals[doctype]) return []; return wn.utils.filter_dict(locals[doctype], filters); - }, + }, + + get_doclist: function(doctype, name, filters) { + var doclist = []; + if(!locals[doctype]) + return doclist; + + doclist[0] = locals[doctype][name]; + + $.each(wn.model.get("DocField", {parent:doctype, fieldtype:"Table"}), + function(i, table_field) { + var child_doclist = wn.model.get(table_field.options, { + parent:name, parenttype: doctype, + parentfield: table_field.fieldname}).sort( + function(a, b) { return a.idx - b.idx; }); + doclist = doclist.concat(child_doclist); + } + ); + + if(filters) { + doclist = wn.utils.filter_dict(doclist, filters); + } + + return doclist; + }, }