fixes in form.js, doclist and wrapper
This commit is contained in:
parent
55d5c5c5b0
commit
8b41fbc911
7 changed files with 34 additions and 27 deletions
|
|
@ -39,6 +39,13 @@
|
|||
*/
|
||||
|
||||
wn.provide('_f');
|
||||
wn.provide('wn.ui.form');
|
||||
|
||||
wn.ui.form.Controller = Class.extend({
|
||||
init: function(opts) {
|
||||
$.extend(this, opts);
|
||||
}
|
||||
});
|
||||
|
||||
_f.frms = {};
|
||||
|
||||
|
|
@ -53,7 +60,7 @@ _f.Frm = function(doctype, parent, in_form) {
|
|||
this.opendocs = {};
|
||||
this.sections = [];
|
||||
this.grids = [];
|
||||
this.cscript = {};
|
||||
this.cscript = new wn.ui.form.Controller({frm:this});
|
||||
this.pformat = {};
|
||||
this.fetch_dict = {};
|
||||
this.parent = parent;
|
||||
|
|
|
|||
|
|
@ -149,10 +149,10 @@ _f.FrmHeader = Class.extend({
|
|||
cur_frm.savesubmit(this);}, 'icon-lock');
|
||||
|
||||
// Update after sumit
|
||||
if(docstatus==1 && p[SUBMIT] && cur_frm.doc.__unsaved) {
|
||||
if(docstatus==1 && p[SUBMIT]) {
|
||||
this.appframe.add_button('Update', function() {
|
||||
cur_frm.save('Update', null, this);
|
||||
}, '');
|
||||
}, '').toggle(false);
|
||||
}
|
||||
|
||||
// Cancel
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ def check_if_doc_is_linked(dt, dn):
|
|||
else:
|
||||
item = None
|
||||
try:
|
||||
item = sql("select name, parent, parenttype from `tab%s` where `%s`='%s' and docstatus!=2 limit 1" % (link_dt, link_field, dn))
|
||||
item = sql("select name, parent, parenttype from `tab%s` where `%s`='%s' and docstatus!=2 and `%s`!=parent limit 1" % (link_dt, link_field, dn, link_field))
|
||||
except Exception, e:
|
||||
if e.args[0]==1146: pass
|
||||
else: raise e
|
||||
|
|
|
|||
|
|
@ -573,7 +573,7 @@ class Document:
|
|||
|
||||
self.fields['__unsaved'] = 1
|
||||
|
||||
return doclist
|
||||
return webnotes.doclist(doclist)
|
||||
|
||||
def addchild(self, fieldname, childtype = '', local=0, doclist=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class ModelWrapper:
|
|||
if self.obj: return self.obj
|
||||
|
||||
from webnotes.model.code import get_obj
|
||||
self.obj = get_obj(doc=self.doc, doclist=self.children)
|
||||
self.obj = get_obj(doc=self.doc, doclist=self.doclist)
|
||||
return self.obj
|
||||
|
||||
def to_dict(self):
|
||||
|
|
@ -199,7 +199,7 @@ class ModelWrapper:
|
|||
|
||||
trigger(method, self.obj.doc)
|
||||
|
||||
self.set_doclist([self.obj.doc] + self.obj.doclist)
|
||||
self.set_doclist(self.doclist)
|
||||
|
||||
def save_main(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ def runserverobj():
|
|||
from webnotes.model.wrapper import ModelWrapper
|
||||
from webnotes.utils import cint
|
||||
|
||||
doclist = None
|
||||
wrapper = None
|
||||
method = webnotes.form_dict.get('method')
|
||||
arg = webnotes.form_dict.get('arg')
|
||||
dt = webnotes.form_dict.get('doctype')
|
||||
|
|
@ -43,10 +43,10 @@ def runserverobj():
|
|||
so = webnotes.model.code.get_obj(dt, dn)
|
||||
|
||||
else:
|
||||
doclist = ModelWrapper()
|
||||
doclist.from_compressed(webnotes.form_dict.get('docs'), dn)
|
||||
so = doclist.make_obj()
|
||||
doclist.check_if_latest()
|
||||
wrapper = ModelWrapper()
|
||||
wrapper.from_compressed(webnotes.form_dict.get('docs'), dn)
|
||||
so = wrapper.make_obj()
|
||||
wrapper.check_if_latest()
|
||||
|
||||
check_guest_access(so.doc)
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ def runserverobj():
|
|||
else:
|
||||
webnotes.response['message'] = r
|
||||
|
||||
webnotes.response['docs'] =[so.doc] + so.doclist
|
||||
webnotes.response['docs'] = so.doclist
|
||||
|
||||
def check_guest_access(doc):
|
||||
if webnotes.session['user']=='Guest' and not webnotes.conn.sql("select name from tabDocPerm where role='Guest' and parent=%s and ifnull(`read`,0)=1", doc.doctype):
|
||||
|
|
@ -87,4 +87,4 @@ def make_csv_output(res, dt):
|
|||
|
||||
webnotes.response['result'] = unicode(f.read(), 'utf-8')
|
||||
webnotes.response['type'] = 'csv'
|
||||
webnotes.response['doctype'] = dt.replace(' ','')
|
||||
webnotes.response['doctype'] = dt.replace(' ','')
|
||||
|
|
@ -27,17 +27,17 @@ import webnotes
|
|||
def savedocs():
|
||||
"""save / submit / update doclist"""
|
||||
try:
|
||||
doclist = webnotes.model_wrapper()
|
||||
doclist.from_compressed(webnotes.form_dict.docs, webnotes.form_dict.docname)
|
||||
wrapper = webnotes.model_wrapper()
|
||||
wrapper.from_compressed(webnotes.form_dict.docs, webnotes.form_dict.docname)
|
||||
|
||||
# action
|
||||
action = webnotes.form_dict.action
|
||||
if action=='Update': action='update_after_submit'
|
||||
getattr(doclist, action.lower())()
|
||||
getattr(wrapper, action.lower())()
|
||||
|
||||
# update recent documents
|
||||
webnotes.user.update_recent(doclist.doc.doctype, doclist.doc.name)
|
||||
send_updated_docs(doclist)
|
||||
webnotes.user.update_recent(wrapper.doc.doctype, wrapper.doc.name)
|
||||
send_updated_docs(wrapper)
|
||||
|
||||
except Exception, e:
|
||||
webnotes.msgprint(webnotes._('Did not save'))
|
||||
|
|
@ -48,17 +48,17 @@ def savedocs():
|
|||
def cancel(doctype=None, name=None):
|
||||
"""cancel a doclist"""
|
||||
try:
|
||||
doclist = webnotes.model_wrapper(doctype, name)
|
||||
doclist.cancel()
|
||||
send_updated_docs(doclist)
|
||||
wrapper = webnotes.model_wrapper(doctype, name)
|
||||
wrapper.cancel()
|
||||
send_updated_docs(wrapper)
|
||||
|
||||
except Exception, e:
|
||||
webnotes.errprint(webnotes.utils.getTraceback())
|
||||
webnotes.msgprint(webnotes._("Did not cancel"))
|
||||
raise e
|
||||
|
||||
def send_updated_docs(doclist):
|
||||
webnotes.response['main_doc_name'] = doclist.doc.name
|
||||
webnotes.response['doctype'] = doclist.doc.doctype
|
||||
webnotes.response['docname'] = doclist.doc.name
|
||||
webnotes.response['docs'] = [doclist.doc] + doclist.children
|
||||
def send_updated_docs(wrapper):
|
||||
webnotes.response['main_doc_name'] = wrapper.doc.name
|
||||
webnotes.response['doctype'] = wrapper.doc.doctype
|
||||
webnotes.response['docname'] = wrapper.doc.name
|
||||
webnotes.response['docs'] = wrapper.doclist
|
||||
Loading…
Add table
Reference in a new issue