Merge branch 'master' of github.com:webnotes/wnframework
This commit is contained in:
commit
c276eceadd
11 changed files with 76 additions and 35 deletions
|
|
@ -234,12 +234,14 @@ _f.Frm.prototype.set_query = function(fieldname, opt1, opt2) {
|
|||
_f.Frm.prototype.set_value = function(field, value) {
|
||||
var me = this;
|
||||
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") {
|
||||
_set(field, value)
|
||||
} else {
|
||||
} else if($.isPlainObject(field)) {
|
||||
$.each(field, function(f, v) {
|
||||
_set(f, v);
|
||||
})
|
||||
|
|
@ -249,11 +251,20 @@ _f.Frm.prototype.set_value = function(field, value) {
|
|||
_f.Frm.prototype.call = function(opts) {
|
||||
var me = this;
|
||||
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.callback = function(r) {
|
||||
if(typeof (r.message || "")=="object") {
|
||||
me.set_value(r.message);
|
||||
if($.isPlainObject(r.message)) {
|
||||
if(opts.child) {
|
||||
// update child doc
|
||||
opts.child = locals[opts.child.doctype][opts.child.name];
|
||||
$.extend(opts.child, r.message);
|
||||
me.fields_dict[opts.child.parentfield].refresh();
|
||||
} else {
|
||||
// update parent doc
|
||||
me.set_value(r.message);
|
||||
}
|
||||
}
|
||||
opts.original_callback && opts.original_callback(r);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -298,7 +298,7 @@ _f.Frm.prototype.setup_footer = function() {
|
|||
|
||||
_f.Frm.prototype.set_intro = function(txt) {
|
||||
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);
|
||||
}
|
||||
if(txt) {
|
||||
|
|
@ -1005,20 +1005,21 @@ _f.Frm.prototype.reload_doc = function() {
|
|||
}
|
||||
|
||||
_f.Frm.prototype.savesubmit = function(btn) {
|
||||
var answer = confirm("Permanently Submit "+this.docname+"?");
|
||||
var me = this;
|
||||
if(answer) {
|
||||
this.save('Submit', function(r) {
|
||||
wn.confirm("Permanently Submit "+this.docname+"?", function() {
|
||||
me.save('Submit', function(r) {
|
||||
if(!r.exc && me.cscript.on_submit) {
|
||||
me.runclientscript('on_submit', me.doctype, me.docname);
|
||||
}
|
||||
}, btn);
|
||||
}
|
||||
}, 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() {
|
||||
me.save('Cancel', null, btn);
|
||||
});
|
||||
}
|
||||
|
||||
// delete the record
|
||||
|
|
|
|||
|
|
@ -643,4 +643,4 @@ $.extend(_p, {
|
|||
row.cells[1].className = 'datainputcell';
|
||||
return row;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -64,7 +64,11 @@ wn.assets = {
|
|||
// localstorage
|
||||
add: function(src, txt) {
|
||||
if('localStorage' in window) {
|
||||
localStorage.setItem(src, txt);
|
||||
try {
|
||||
localStorage.setItem(src, txt);
|
||||
} catch(e) {
|
||||
console.log("Local Storage quota exceeded?")
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -84,16 +84,24 @@ $.extend(wn.perm, {
|
|||
if(!name) return true;
|
||||
var out =false;
|
||||
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
|
||||
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
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} else if(!locals[doctype][name][p.match]) { // blanks are true
|
||||
} else if(!locals[doctype][name][document_key]) { // blanks are true
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -102,11 +102,15 @@ wn.print.Table = Class.extend({
|
|||
var df = wn.meta.docfield_map[me.tabletype][fieldname];
|
||||
var label = df ? df.label : fieldname;
|
||||
}
|
||||
$("<td>").html(label)
|
||||
var td = $("<td>").html(label)
|
||||
.appendTo(headrow)
|
||||
.css(me.head_cell_style)
|
||||
.css({"width": me.widths[ci] + "%"});
|
||||
})
|
||||
|
||||
if(ci==0) {
|
||||
td.css({"min-width": "30px"});
|
||||
}
|
||||
});
|
||||
|
||||
$.each(data, function(ri, row) {
|
||||
var allow = true;
|
||||
|
|
@ -118,7 +122,7 @@ wn.print.Table = Class.extend({
|
|||
|
||||
$.each(me.columns, function(ci, fieldname) {
|
||||
if(ci==0)
|
||||
var value = ri + 1;
|
||||
var value = row.idx;
|
||||
else
|
||||
var value = row[fieldname];
|
||||
|
||||
|
|
@ -144,7 +148,7 @@ wn.print.Table = Class.extend({
|
|||
this.widths = $.map(this.columns, function(fieldname, ci) {
|
||||
df = wn.meta.docfield_map[me.tabletype][fieldname];
|
||||
return df && df.width ||
|
||||
(fieldname=="Sr" ? 20 : 80);
|
||||
(fieldname=="Sr" ? 30 : 80);
|
||||
})
|
||||
}
|
||||
var sum = 0;
|
||||
|
|
|
|||
|
|
@ -362,7 +362,10 @@ wn.views.ReportView = wn.ui.Listing.extend({
|
|||
})
|
||||
},
|
||||
callback: function(r) {
|
||||
if(r.exc) return;
|
||||
if(r.exc) {
|
||||
msgprint("Report was not saved (there were errors)");
|
||||
return;
|
||||
}
|
||||
if(r.message != me.docname)
|
||||
wn.set_route('Report2', me.doctype, r.message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -522,14 +522,17 @@ class Document:
|
|||
|
||||
if has_perm and match and match != -1:
|
||||
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
|
||||
break # permission found! break
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,8 @@ class ModelWrapper:
|
|||
Raises exception if permission is not valid
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ class Profile:
|
|||
res = webnotes.conn.sql("""select defkey, defvalue
|
||||
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:
|
||||
if not self.defaults.has_key(rec[0]):
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ def run_custom_query(data):
|
|||
query = data['query']
|
||||
if '%(key)s' in query:
|
||||
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():
|
||||
"""load all doctypes and roles"""
|
||||
|
|
@ -193,9 +193,15 @@ def build_match_conditions(data, conditions):
|
|||
if d.doctype == 'DocPerm' and d.parent == data['doctype']:
|
||||
if d.role in roles:
|
||||
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'],
|
||||
d.match, v))
|
||||
document_key, v))
|
||||
|
||||
elif d.read == 1 and d.permlevel == 0:
|
||||
# don't restrict if another read permission at level 0
|
||||
# exists without a match restriction
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue