[reportview] Editable
This commit is contained in:
parent
a7cc50f504
commit
a33299a6f5
4 changed files with 88 additions and 6 deletions
|
|
@ -2,7 +2,7 @@
|
|||
{
|
||||
"creation": "2013-01-29 10:47:14",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-07-05 14:31:53",
|
||||
"modified": "2013-08-08 14:21:55",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
"fieldname": "naming_series",
|
||||
"fieldtype": "Select",
|
||||
"hidden": 1,
|
||||
"label": "Naming Series",
|
||||
"label": "Document Numbering Series",
|
||||
"options": "COMM-"
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -144,7 +144,8 @@ wn.views.ReportView = wn.ui.Listing.extend({
|
|||
fields: $.map(this.columns, function(v) { return me.get_full_column_name(v) }),
|
||||
order_by: this.get_order_by(),
|
||||
filters: this.filter_list.get_filters(),
|
||||
docstatus: ['0','1','2']
|
||||
docstatus: ['0','1','2'],
|
||||
with_childnames: 1
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -244,6 +245,62 @@ wn.views.ReportView = wn.ui.Listing.extend({
|
|||
if(this.start!=0 && !options.autoHeight) {
|
||||
this.grid.scrollRowIntoView(this.data.length-1);
|
||||
}
|
||||
|
||||
this.grid.onDblClick.subscribe(function(e, args) {
|
||||
var row = me.dataView.getItem(args.row);
|
||||
var cell = me.grid.getColumns()[args.cell];
|
||||
me.edit_cell(row, cell.docfield);
|
||||
});
|
||||
|
||||
this.dataView.onRowsChanged.subscribe(function (e, args) {
|
||||
me.grid.invalidateRows(args.rows);
|
||||
me.grid.render();
|
||||
});
|
||||
},
|
||||
|
||||
edit_cell: function(row, docfield) {
|
||||
if(wn.model.std_fields_list.indexOf(docfield.fieldname)!==-1) {
|
||||
wn.throw(wn._("Cannot edit standard fields"));
|
||||
}
|
||||
var me = this;
|
||||
var d = new wn.ui.Dialog({
|
||||
title: wn._("Edit") + " " + wn._(docfield.label),
|
||||
fields: [docfield, {"fieldtype": "Button", "label": "Update"}],
|
||||
});
|
||||
d.get_input(docfield.fieldname).val(row[docfield.fieldname]);
|
||||
d.get_input("update").on("click", function() {
|
||||
wn.call({
|
||||
method: "webnotes.client.set_value",
|
||||
args: {
|
||||
doctype: docfield.parent,
|
||||
docname: row[docfield.parent===me.doctype ? "name" : docfield.parent+":name"],
|
||||
fieldname: docfield.fieldname,
|
||||
value: d.get_value(docfield.fieldname)
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc) {
|
||||
d.hide();
|
||||
var doclist = r.message;
|
||||
$.each(me.dataView.getItems(), function(i, item) {
|
||||
if (item.name === doclist[0].name) {
|
||||
var new_item = $.extend({}, item, doclist[0]);
|
||||
$.each(doclist, function(i, doc) {
|
||||
if(item[doc.doctype + ":name"]===doc.name) {
|
||||
$.each(doc, function(k, v) {
|
||||
if(wn.model.std_fields_list.indexOf(k)===-1) {
|
||||
new_item[k] = v;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
me.dataView.updateItem(item.id, new_item);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
d.show();
|
||||
},
|
||||
|
||||
set_data: function() {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes import _
|
||||
import webnotes.model
|
||||
import json
|
||||
|
||||
@webnotes.whitelist()
|
||||
|
|
@ -22,6 +24,24 @@ def get_value(doctype, fieldname, filters=None, as_dict=True, debug=False):
|
|||
fieldname = json.loads(fieldname)
|
||||
return webnotes.conn.get_value(doctype, json.loads(filters), fieldname, as_dict=as_dict, debug=debug)
|
||||
|
||||
@webnotes.whitelist()
|
||||
def set_value(doctype, docname, fieldname, value):
|
||||
if fieldname in webnotes.model.default_fields:
|
||||
webnotes.throw(_("Cannot edit standard fields"))
|
||||
|
||||
doc = webnotes.conn.get_value(doctype, docname, ["parenttype", "parent"], as_dict=True)
|
||||
if doc.parent:
|
||||
bean = webnotes.bean(doc.parenttype, doc.parent)
|
||||
child = bean.doclist.getone({"doctype": doctype, "name": docname})
|
||||
child.fields[fieldname] = value
|
||||
else:
|
||||
bean = webnotes.bean(doctype, docname)
|
||||
bean.doc.fields[fieldname] = value
|
||||
|
||||
bean.save()
|
||||
|
||||
return [d.fields for d in bean.doclist]
|
||||
|
||||
@webnotes.whitelist()
|
||||
def insert(doclist):
|
||||
if isinstance(doclist, basestring):
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ def get_form_params():
|
|||
|
||||
def execute(doctype, query=None, filters=None, fields=None, docstatus=None,
|
||||
group_by=None, order_by=None, limit_start=0, limit_page_length=None,
|
||||
as_list=False, debug=False):
|
||||
as_list=False, with_childnames=False, debug=False):
|
||||
|
||||
if query:
|
||||
return run_custom_query(query)
|
||||
|
|
@ -39,7 +39,7 @@ def execute(doctype, query=None, filters=None, fields=None, docstatus=None,
|
|||
if not filters: filters = []
|
||||
if not docstatus: docstatus = []
|
||||
|
||||
args = prepare_args(doctype, filters, fields, docstatus, group_by, order_by)
|
||||
args = prepare_args(doctype, filters, fields, docstatus, group_by, order_by, with_childnames)
|
||||
args.limit = add_limit(limit_start, limit_page_length)
|
||||
|
||||
query = """select %(fields)s from %(tables)s where %(conditions)s
|
||||
|
|
@ -47,7 +47,7 @@ def execute(doctype, query=None, filters=None, fields=None, docstatus=None,
|
|||
|
||||
return webnotes.conn.sql(query, as_dict=not as_list, debug=debug)
|
||||
|
||||
def prepare_args(doctype, filters, fields, docstatus, group_by, order_by):
|
||||
def prepare_args(doctype, filters, fields, docstatus, group_by, order_by, with_childnames):
|
||||
global tables
|
||||
tables = get_tables(doctype, fields)
|
||||
load_doctypes()
|
||||
|
|
@ -56,6 +56,11 @@ def prepare_args(doctype, filters, fields, docstatus, group_by, order_by):
|
|||
|
||||
args = webnotes._dict()
|
||||
|
||||
if with_childnames:
|
||||
for t in tables:
|
||||
if t != "`tab" + doctype + "`":
|
||||
fields.append(t + ".name as '%s:name'" % t[4:-1])
|
||||
|
||||
# query dict
|
||||
args.tables = ', '.join(tables)
|
||||
args.conditions = ' and '.join(conditions)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue