@@ -234,12 +234,14 @@ _f.Frm.prototype.set_query = function(fieldname, opt1, opt2) { | |||||
_f.Frm.prototype.set_value = function(field, value) { | _f.Frm.prototype.set_value = function(field, value) { | ||||
var me = this; | var me = this; | ||||
var _set = function(f, v) { | var _set = function(f, v) { | ||||
me.doc[f] = v; | |||||
me.fields_dict[f].refresh(); | |||||
if(me.fields_dict[f]) { | |||||
me.doc[f] = v; | |||||
me.fields_dict[f].refresh(); | |||||
} | |||||
} | } | ||||
if(typeof field=="string") { | if(typeof field=="string") { | ||||
_set(field, value) | _set(field, value) | ||||
} else { | |||||
} else if($.isPlainObject(field)) { | |||||
$.each(field, function(f, v) { | $.each(field, function(f, v) { | ||||
_set(f, v); | _set(f, v); | ||||
}) | }) | ||||
@@ -249,10 +251,11 @@ _f.Frm.prototype.set_value = function(field, value) { | |||||
_f.Frm.prototype.call = function(opts) { | _f.Frm.prototype.call = function(opts) { | ||||
var me = this; | var me = this; | ||||
if(!opts.doc) { | if(!opts.doc) { | ||||
opts.method = wn.model.get_server_module_name(me.doctype) + "." + opts.method; | |||||
if(opts.method.indexOf(".")==-1) | |||||
opts.method = wn.model.get_server_module_name(me.doctype) + "." + opts.method; | |||||
opts.original_callback = opts.callback; | opts.original_callback = opts.callback; | ||||
opts.callback = function(r) { | opts.callback = function(r) { | ||||
if(typeof (r.message || "")=="object") { | |||||
if($.isPlainObject(r.message)) { | |||||
me.set_value(r.message); | me.set_value(r.message); | ||||
} | } | ||||
opts.original_callback && opts.original_callback(r); | opts.original_callback && opts.original_callback(r); | ||||
@@ -298,7 +298,7 @@ _f.Frm.prototype.setup_footer = function() { | |||||
_f.Frm.prototype.set_intro = function(txt) { | _f.Frm.prototype.set_intro = function(txt) { | ||||
if(!this.intro_area) { | if(!this.intro_area) { | ||||
this.intro_area = $('<div class="alert form-intro-area">') | |||||
this.intro_area = $('<div class="alert form-intro-area" style="margin-top: 20px;">') | |||||
.insertBefore(this.page_layout.body.firstChild); | .insertBefore(this.page_layout.body.firstChild); | ||||
} | } | ||||
if(txt) { | if(txt) { | ||||
@@ -1005,20 +1005,21 @@ _f.Frm.prototype.reload_doc = function() { | |||||
} | } | ||||
_f.Frm.prototype.savesubmit = function(btn) { | _f.Frm.prototype.savesubmit = function(btn) { | ||||
var answer = confirm("Permanently Submit "+this.docname+"?"); | |||||
var me = this; | var me = this; | ||||
if(answer) { | |||||
wn.confirm("Permanently Submit "+this.docname+"?", function() { | |||||
this.save('Submit', function(r) { | this.save('Submit', function(r) { | ||||
if(!r.exc && me.cscript.on_submit) { | if(!r.exc && me.cscript.on_submit) { | ||||
me.runclientscript('on_submit', me.doctype, me.docname); | me.runclientscript('on_submit', me.doctype, me.docname); | ||||
} | } | ||||
}, btn); | |||||
} | |||||
}, btn); | |||||
}); | |||||
} | } | ||||
_f.Frm.prototype.savecancel = function(btn) { | _f.Frm.prototype.savecancel = function(btn) { | ||||
var answer = confirm("Permanently Cancel "+this.docname+"?"); | |||||
if(answer) this.save('Cancel', null, btn); | |||||
var me = this; | |||||
wn.confirm("Permanently Submit "+this.docname+"?", function() { | |||||
this.save('Cancel', null, btn); | |||||
}); | |||||
} | } | ||||
// delete the record | // delete the record | ||||
@@ -84,16 +84,24 @@ $.extend(wn.perm, { | |||||
if(!name) return true; | if(!name) return true; | ||||
var out =false; | var out =false; | ||||
if(p.match) { | if(p.match) { | ||||
if(user_defaults[p.match]) { | |||||
for(var i=0;i<user_defaults[p.match].length;i++) { | |||||
if(p.match.indexOf(":")!=-1) { | |||||
keys = p.match.split(":"); | |||||
var document_key = keys[0]; | |||||
var default_key = keys[1]; | |||||
} else { | |||||
var document_key = p.match; | |||||
var default_key = p.match; | |||||
} | |||||
if(user_defaults[default_key]) { | |||||
for(var i=0;i<user_defaults[default_key].length;i++) { | |||||
// user must have match field in defaults | // user must have match field in defaults | ||||
if(user_defaults[p.match][i]==locals[doctype][name][p.match]) { | |||||
if(user_defaults[default_key][i]==locals[doctype][name][document_key]) { | |||||
// must match document | // must match document | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} else if(!locals[doctype][name][p.match]) { // blanks are true | |||||
} else if(!locals[doctype][name][document_key]) { // blanks are true | |||||
return true; | return true; | ||||
} else { | } else { | ||||
return false; | return false; | ||||
@@ -522,14 +522,17 @@ class Document: | |||||
if has_perm and match and match != -1: | if has_perm and match and match != -1: | ||||
for m in match: | for m in match: | ||||
if self.fields.get(m, 'no value') in self._user_defaults.get(m, 'no default'): | |||||
if ":" in m: | |||||
document_key, default_key = m.split(":") | |||||
else: | |||||
document_key = default_key = m | |||||
if self.fields.get(document_key, 'no value') in \ | |||||
self._user_defaults.get(default_key, 'no default'): | |||||
has_perm = 1 | has_perm = 1 | ||||
break # permission found! break | break # permission found! break | ||||
else: | else: | ||||
has_perm = 0 | |||||
if verbose: | |||||
webnotes.msgprint("Value not allowed: '%s' for '%s'" % (self.fields.get(m, 'no value'), m)) | |||||
has_perm = 0 | |||||
return has_perm | return has_perm | ||||
@@ -129,7 +129,8 @@ class ModelWrapper: | |||||
Raises exception if permission is not valid | Raises exception if permission is not valid | ||||
""" | """ | ||||
if not self.doc.check_perm(verbose=1): | if not self.doc.check_perm(verbose=1): | ||||
webnotes.msgprint("Not enough permission to save %s" % self.doc.doctype, raise_exception=1) | |||||
webnotes.msgprint("Not enough permission to save %s" % | |||||
self.doc.doctype, raise_exception=1) | |||||
def check_links(self): | def check_links(self): | ||||
""" | """ | ||||
@@ -145,7 +145,7 @@ class Profile: | |||||
res = webnotes.conn.sql("""select defkey, defvalue | res = webnotes.conn.sql("""select defkey, defvalue | ||||
from `tabDefaultValue` where parent in ("%s") order by idx""" % '", "'.join(roles)) | from `tabDefaultValue` where parent in ("%s") order by idx""" % '", "'.join(roles)) | ||||
self.defaults = {'owner': [self.name,]} | |||||
self.defaults = {'owner': [self.name], "user": [self.name]} | |||||
for rec in res: | for rec in res: | ||||
if not self.defaults.has_key(rec[0]): | if not self.defaults.has_key(rec[0]): | ||||
@@ -108,7 +108,7 @@ def run_custom_query(data): | |||||
query = data['query'] | query = data['query'] | ||||
if '%(key)s' in query: | if '%(key)s' in query: | ||||
query = query.replace('%(key)s', 'name') | query = query.replace('%(key)s', 'name') | ||||
return webnotes.conn.sql(query, as_dict=1, debug=1) | |||||
return webnotes.conn.sql(query, as_dict=1) | |||||
def load_doctypes(): | def load_doctypes(): | ||||
"""load all doctypes and roles""" | """load all doctypes and roles""" | ||||
@@ -192,9 +192,15 @@ def build_match_conditions(data, conditions): | |||||
if d.doctype == 'DocPerm' and d.parent == data['doctype']: | if d.doctype == 'DocPerm' and d.parent == data['doctype']: | ||||
if d.role in roles: | if d.role in roles: | ||||
if d.match: # role applicable | if d.match: # role applicable | ||||
for v in webnotes.user.defaults.get(d.match, ['**No Match**']): | |||||
if ':' in d.match: | |||||
document_key, default_key = d.match.split(":") | |||||
else: | |||||
default_key = document_key = d.match | |||||
for v in webnotes.user.defaults.get(default_key, ['**No Match**']): | |||||
match_conditions.append('`tab%s`.%s="%s"' % (data['doctype'], | match_conditions.append('`tab%s`.%s="%s"' % (data['doctype'], | ||||
d.match, v)) | |||||
document_key, v)) | |||||
elif d.read == 1 and d.permlevel == 0: | elif d.read == 1 and d.permlevel == 0: | ||||
# don't restrict if another read permission at level 0 | # don't restrict if another read permission at level 0 | ||||
# exists without a match restriction | # exists without a match restriction | ||||